Merge tag 'xtensa-for-next-20141021-2' of git://github.com/jcmvbkbc/linux-xtensa...
[cascardo/linux.git] / drivers / staging / iio / iio_simple_dummy.h
1 /**
2  * Copyright (c) 2011 Jonathan Cameron
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 2 as published by
6  * the Free Software Foundation.
7  *
8  * Join together the various functionality of iio_simple_dummy driver
9  */
10
11 #ifndef _IIO_SIMPLE_DUMMY_H_
12 #define _IIO_SIMPLE_DUMMY_H_
13 #include <linux/kernel.h>
14
15 struct iio_dummy_accel_calibscale;
16
17 /**
18  * struct iio_dummy_state - device instance specific state.
19  * @dac_val:                    cache for dac value
20  * @single_ended_adc_val:       cache for single ended adc value
21  * @differential_adc_val:       cache for differential adc value
22  * @accel_val:                  cache for acceleration value
23  * @accel_calibbias:            cache for acceleration calibbias
24  * @accel_calibscale:           cache for acceleration calibscale
25  * @lock:                       lock to ensure state is consistent
26  * @event_irq:                  irq number for event line (faked)
27  * @event_val:                  cache for event theshold value
28  * @event_en:                   cache of whether event is enabled
29  */
30 struct iio_dummy_state {
31         int dac_val;
32         int single_ended_adc_val;
33         int differential_adc_val[2];
34         int accel_val;
35         int accel_calibbias;
36         const struct iio_dummy_accel_calibscale *accel_calibscale;
37         struct mutex lock;
38 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
39         int event_irq;
40         int event_val;
41         bool event_en;
42 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS */
43 };
44
45 #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
46
47 struct iio_dev;
48
49 int iio_simple_dummy_read_event_config(struct iio_dev *indio_dev,
50                                        const struct iio_chan_spec *chan,
51                                        enum iio_event_type type,
52                                        enum iio_event_direction dir);
53
54 int iio_simple_dummy_write_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                                         int state);
59
60 int iio_simple_dummy_read_event_value(struct iio_dev *indio_dev,
61                                       const struct iio_chan_spec *chan,
62                                       enum iio_event_type type,
63                                       enum iio_event_direction dir,
64                                       enum iio_event_info info, int *val,
65                                       int *val2);
66
67 int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
68                                        const struct iio_chan_spec *chan,
69                                        enum iio_event_type type,
70                                        enum iio_event_direction dir,
71                                        enum iio_event_info info, int val,
72                                        int val2);
73
74 int iio_simple_dummy_events_register(struct iio_dev *indio_dev);
75 int iio_simple_dummy_events_unregister(struct iio_dev *indio_dev);
76
77 #else /* Stubs for when events are disabled at compile time */
78
79 static inline int
80 iio_simple_dummy_events_register(struct iio_dev *indio_dev)
81 {
82         return 0;
83 };
84
85 static inline int
86 iio_simple_dummy_events_unregister(struct iio_dev *indio_dev)
87 {
88         return 0;
89 };
90
91 #endif /* CONFIG_IIO_SIMPLE_DUMMY_EVENTS*/
92
93 /**
94  * enum iio_simple_dummy_scan_elements - scan index enum
95  * @voltage0:           the single ended voltage channel
96  * @diffvoltage1m2:     first differential channel
97  * @diffvoltage3m4:     second differenial channel
98  * @accelx:             acceleration channel
99  *
100  * Enum provides convenient numbering for the scan index.
101  */
102 enum iio_simple_dummy_scan_elements {
103         voltage0,
104         diffvoltage1m2,
105         diffvoltage3m4,
106         accelx,
107 };
108
109 #ifdef CONFIG_IIO_SIMPLE_DUMMY_BUFFER
110 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
111         const struct iio_chan_spec *channels, unsigned int num_channels);
112 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev);
113 #else
114 static inline int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev,
115         const struct iio_chan_spec *channels, unsigned int num_channels)
116 {
117         return 0;
118 };
119 static inline
120 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev)
121 {};
122
123 #endif /* CONFIG_IIO_SIMPLE_DUMMY_BUFFER */
124 #endif /* _IIO_SIMPLE_DUMMY_H_ */