Merge tag 'armsoc-defconfig' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-microblaze.git] / drivers / iio / dummy / iio_simple_dummy.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /**
3  * Copyright (c) 2011 Jonathan Cameron
4  *
5  * Join together the various functionality of iio_simple_dummy driver
6  */
7
8 #ifndef _IIO_SIMPLE_DUMMY_H_
9 #define _IIO_SIMPLE_DUMMY_H_
10 #include <linux/kernel.h>
11
12 struct iio_dummy_accel_calibscale;
13 struct iio_dummy_regs;
14
15 /**
16  * struct iio_dummy_state - device instance specific state.
17  * @dac_val:                    cache for dac value
18  * @single_ended_adc_val:       cache for single ended adc value
19  * @differential_adc_val:       cache for differential adc value
20  * @accel_val:                  cache for acceleration value
21  * @accel_calibbias:            cache for acceleration calibbias
22  * @accel_calibscale:           cache for acceleration calibscale
23  * @lock:                       lock to ensure state is consistent
24  * @event_irq:                  irq number for event line (faked)
25  * @event_val:                  cache for event threshold value
26  * @event_en:                   cache of whether event is enabled
27  */
28 struct iio_dummy_state {
29         int dac_val;
30         int single_ended_adc_val;
31         int differential_adc_val[2];
32         int accel_val;
33         int accel_calibbias;
34         int activity_running;
35         int activity_walking;
36         const struct iio_dummy_accel_calibscale *accel_calibscale;
37         struct mutex lock;
38         struct iio_dummy_regs *regs;
39         int steps_enabled;
40         int steps;
41         int height;
42 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
43         int event_irq;
44         int event_val;
45         bool event_en;
46         s64 event_timestamp;
47 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
48 };
49
50 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
51
52 struct iio_dev;
53
54 int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
55                                        const struct iio_chan_spec *chan,
56                                        enum iio_event_type type,
57                                        enum iio_event_direction dir);
58
59 int iio_simple_dummy_write_event_config(struct iio_dev *indio_dev,
60                                         const struct iio_chan_spec *chan,
61                                         enum iio_event_type type,
62                                         enum iio_event_direction dir,
63                                         int state);
64
65 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
66                                       const struct iio_chan_spec *chan,
67                                       enum iio_event_type type,
68                                       enum iio_event_direction dir,
69                                       enum iio_event_info info, int *val,
70                                       int *val2);
71
72 int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
73                                        const struct iio_chan_spec *chan,
74                                        enum iio_event_type type,
75                                        enum iio_event_direction dir,
76                                        enum iio_event_info info, int val,
77                                        int val2);
78
79 int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
80 void iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
81
82 #else /* Stubs for when events are disabled at compile time */
83
84 static inline int
85 iio_simple_dummy_events_register(struct iio_dev *indio_dev)
86 {
87         return 0;
88 }
89
90 static inline void
91 iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
92 {}
93
94 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
95
96 /**
97  * enum iio_simple_dummy_scan_elements - scan index enum
98  * @DUMMY_INDEX_VOLTAGE_0:         the single ended voltage channel
99  * @DUMMY_INDEX_DIFFVOLTAGE_1M2:   first differential channel
100  * @DUMMY_INDEX_DIFFVOLTAGE_3M4:   second differential channel
101  * @DUMMY_INDEX_ACCELX:            acceleration channel
102  *
103  * Enum provides convenient numbering for the scan index.
104  */
105 enum iio_simple_dummy_scan_elements {
106         DUMMY_INDEX_VOLTAGE_0,
107         DUMMY_INDEX_DIFFVOLTAGE_1M2,
108         DUMMY_INDEX_DIFFVOLTAGE_3M4,
109         DUMMY_INDEX_ACCELX,
110 };
111
112 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
113 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev);
114 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
115 #else
116 static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
117 {
118         return 0;
119 }
120
121 static inline
122 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
123 {}
124
125 #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
126 #endif /* _IIO_SIMPLE_DUMMY_H_ */