staging: iio: Remove long dead function definitions from headers
[pandora-kernel.git] / drivers / staging / iio / sysfs.h
1 /* The industrial I/O core
2  *
3  *Copyright (c) 2008 Jonathan Cameron
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 as published by
7  * the Free Software Foundation.
8  *
9  * General attributes
10  */
11
12 #ifndef _INDUSTRIAL_IO_SYSFS_H_
13 #define _INDUSTRIAL_IO_SYSFS_H_
14
15 #include "iio.h"
16
17 /**
18  * struct iio_event_attr - event control attribute
19  * @dev_attr:   underlying device attribute
20  * @mask:       mask for the event when detecting
21  * @listel:     list header to allow addition to list of event handlers
22 */
23 struct iio_event_attr {
24         struct device_attribute dev_attr;
25         int mask;
26         struct iio_event_handler_list *listel;
27 };
28
29 #define to_iio_event_attr(_dev_attr) \
30         container_of(_dev_attr, struct iio_event_attr, dev_attr)
31
32 /**
33  * struct iio_dev_attr - iio specific device attribute
34  * @dev_attr:   underlying device attribute
35  * @address:    associated register address
36  * @val2:       secondary attribute value
37  */
38 struct iio_dev_attr {
39         struct device_attribute dev_attr;
40         int address;
41         int val2;
42 };
43
44 #define to_iio_dev_attr(_dev_attr)                              \
45         container_of(_dev_attr, struct iio_dev_attr, dev_attr)
46
47 ssize_t iio_read_const_attr(struct device *dev,
48                             struct device_attribute *attr,
49                             char *len);
50
51 /**
52  * struct iio_const_attr - constant device specific attribute
53  *                         often used for things like available modes
54  * @string:     attribute string
55  * @dev_attr:   underlying device attribute
56  */
57 struct iio_const_attr {
58         const char *string;
59         struct device_attribute dev_attr;
60 };
61
62 #define to_iio_const_attr(_dev_attr) \
63         container_of(_dev_attr, struct iio_const_attr, dev_attr)
64
65 /* Some attributes will be hard coded (device dependent) and not require an
66    address, in these cases pass a negative */
67 #define IIO_ATTR(_name, _mode, _show, _store, _addr)            \
68         { .dev_attr = __ATTR(_name, _mode, _show, _store),      \
69           .address = _addr }
70
71 #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr)     \
72         struct iio_dev_attr iio_dev_attr_##_name                \
73         = IIO_ATTR(_name, _mode, _show, _store, _addr)
74
75 #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
76         struct iio_dev_attr iio_dev_attr_##_vname                       \
77         = IIO_ATTR(_name, _mode, _show, _store, _addr)
78
79 #define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2)    \
80         struct iio_dev_attr iio_dev_attr_##_name                        \
81         = IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2)
82
83 #define IIO_CONST_ATTR(_name, _string)                                  \
84         struct iio_const_attr iio_const_attr_##_name                    \
85         = { .string = _string,                                          \
86             .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
87
88 /* Generic attributes of onetype or another */
89
90 /**
91  * IIO_DEV_ATTR_REV - revision number for the device
92  * @_show: output method for the attribute
93  *
94  * Very much device dependent.
95  **/
96 #define IIO_DEV_ATTR_REV(_show)                 \
97         IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
98
99 /**
100  * IIO_DEV_ATTR_NAME - chip type dependent identifier
101  * @_show: output method for the attribute
102  **/
103 #define IIO_DEV_ATTR_NAME(_show)                                \
104         IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
105
106 /**
107  * IIO_CONST_ATTR_NAME - constant identifier
108  * @_string: the name
109  **/
110 #define IIO_CONST_ATTR_NAME(_string)                            \
111         IIO_CONST_ATTR(name, _string)
112
113 /**
114  * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
115  * @_mode: sysfs file mode/permissions
116  * @_show: output method for the attribute
117  * @_store: input method for the attribute
118  **/
119 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store)                    \
120         IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
121
122 /**
123  * IIO_DEV_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
124  * @_show: output method for the attribute
125  *
126  * May be mode dependent on some devices
127  **/
128 /* Deprecated */
129 #define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show)                             \
130         IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
131
132 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show)                             \
133         IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
134 /**
135  * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
136  * @_string: frequency string for the attribute
137  *
138  * Constant version
139  **/
140 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string)                 \
141         IIO_CONST_ATTR(sampling_frequency_available, _string)
142
143 /**
144  * IIO_DEV_ATTR_SW_RING_ENABLE - enable software ring buffer
145  * @_show: output method for the attribute
146  * @_store: input method for the attribute
147  *
148  * Success may be dependent on attachment of trigger previously.
149  **/
150 #define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store)                      \
151         IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
152
153 /**
154  * IIO_DEV_ATTR_HW_RING_ENABLE - enable hardware ring buffer
155  * @_show: output method for the attribute
156  * @_store: input method for the attribute
157  *
158  * This is a different attribute from the software one as one can envision
159  * schemes where a combination of the two may be used.
160  **/
161 #define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store)                      \
162         IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
163
164 /**
165  * IIO_DEV_ATTR_TEMP - many sensors have auxiliary temperature sensors
166  * @_show: output method for the attribute
167  **/
168 #define IIO_DEV_ATTR_TEMP(_show)                        \
169         IIO_DEVICE_ATTR(temp, S_IRUGO, _show, NULL, 0)
170
171 #define IIO_DEV_ATTR_TEMP_RAW(_show)                    \
172         IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
173
174 #define IIO_CONST_ATTR_TEMP_OFFSET(_string)             \
175         IIO_CONST_ATTR(temp_offset, _string)
176
177 #define IIO_CONST_ATTR_TEMP_SCALE(_string)              \
178         IIO_CONST_ATTR(temp_scale, _string)
179
180 /**
181  * IIO_EVENT_SH - generic shared event handler
182  * @_name: event name
183  * @_handler: handler function to be called
184  *
185  * This is used in cases where more than one event may result from a single
186  * handler.  Often the case that some alarm register must be read and multiple
187  * alarms may have been triggered.
188  **/
189 #define IIO_EVENT_SH(_name, _handler)                                   \
190         static struct iio_event_handler_list                            \
191         iio_event_##_name = {                                           \
192                 .handler = _handler,                                    \
193                 .refcount = 0,                                          \
194                 .exist_lock = __MUTEX_INITIALIZER(iio_event_##_name     \
195                                                   .exist_lock),         \
196                 .list = {                                               \
197                         .next = &iio_event_##_name.list,                \
198                         .prev = &iio_event_##_name.list,                \
199                 },                                                      \
200         };
201
202 /**
203  * IIO_EVENT_ATTR_SH - generic shared event attribute
204  * @_name: event name
205  * @_ev_list: event handler list
206  * @_show: output method for the attribute
207  * @_store: input method for the attribute
208  * @_mask: mask used when detecting the event
209  *
210  * An attribute with an associated IIO_EVENT_SH
211  **/
212 #define IIO_EVENT_ATTR_SH(_name, _ev_list, _show, _store, _mask)        \
213         static struct iio_event_attr                                    \
214         iio_event_attr_##_name                                          \
215         = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
216                                _show, _store),                          \
217             .mask = _mask,                                              \
218             .listel = &_ev_list };
219
220 #define IIO_EVENT_ATTR_NAMED_SH(_vname, _name, _ev_list, _show, _store, _mask) \
221         static struct iio_event_attr                                    \
222         iio_event_attr_##_vname                                         \
223         = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
224                                _show, _store),                          \
225             .mask = _mask,                                              \
226             .listel = &_ev_list };
227
228 /**
229  * IIO_EVENT_ATTR - non-shared event attribute
230  * @_name: event name
231  * @_show: output method for the attribute
232  * @_store: input method for the attribute
233  * @_mask: mask used when detecting the event
234  * @_handler: handler function to be called
235  **/
236 #define IIO_EVENT_ATTR(_name, _show, _store, _mask, _handler)           \
237         IIO_EVENT_SH(_name, _handler);                                  \
238         static struct                                                   \
239         iio_event_attr                                                  \
240         iio_event_attr_##_name                                          \
241         = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
242                                _show, _store),                          \
243             .mask = _mask,                                              \
244             .listel = &iio_event_##_name };                             \
245
246 /**
247  * IIO_EVENT_ATTR_DATA_RDY - event driven by data ready signal
248  * @_show: output method for the attribute
249  * @_store: input method for the attribute
250  * @_mask: mask used when detecting the event
251  * @_handler: handler function to be called
252  *
253  * Not typically implemented in devices where full triggering support
254  * has been implemented.
255  **/
256 #define IIO_EVENT_ATTR_DATA_RDY(_show, _store, _mask, _handler) \
257         IIO_EVENT_ATTR(data_rdy, _show, _store, _mask, _handler)
258
259 #define IIO_EVENT_CODE_DATA_RDY         100
260 #define IIO_EVENT_CODE_RING_BASE        200
261 #define IIO_EVENT_CODE_ACCEL_BASE       300
262 #define IIO_EVENT_CODE_GYRO_BASE        400
263 #define IIO_EVENT_CODE_ADC_BASE         500
264 #define IIO_EVENT_CODE_MISC_BASE        600
265 #define IIO_EVENT_CODE_LIGHT_BASE       700
266
267 #define IIO_EVENT_CODE_DEVICE_SPECIFIC  1000
268
269 /**
270  * IIO_EVENT_ATTR_RING_50_FULL - ring buffer event to indicate 50% full
271  * @_show: output method for the attribute
272  * @_store: input method for the attribute
273  * @_mask: mask used when detecting the event
274  * @_handler: handler function to be called
275  **/
276 #define IIO_EVENT_ATTR_RING_50_FULL(_show, _store, _mask, _handler)     \
277         IIO_EVENT_ATTR(ring_50_full, _show, _store, _mask, _handler)
278
279 /**
280  * IIO_EVENT_ATTR_RING_50_FULL_SH - shared ring event to indicate 50% full
281  * @_evlist: event handler list
282  * @_show: output method for the attribute
283  * @_store: input method for the attribute
284  * @_mask: mask used when detecting the event
285  **/
286 #define IIO_EVENT_ATTR_RING_50_FULL_SH(_evlist, _show, _store, _mask)   \
287         IIO_EVENT_ATTR_SH(ring_50_full, _evlist, _show, _store, _mask)
288
289 /**
290  * IIO_EVENT_ATTR_RING_75_FULL_SH - shared ring event to indicate 75% full
291  * @_evlist: event handler list
292  * @_show: output method for the attribute
293  * @_store: input method for the attribute
294  * @_mask: mask used when detecting the event
295  **/
296 #define IIO_EVENT_ATTR_RING_75_FULL_SH(_evlist, _show, _store, _mask)   \
297         IIO_EVENT_ATTR_SH(ring_75_full, _evlist, _show, _store, _mask)
298
299 #define IIO_EVENT_CODE_RING_50_FULL     IIO_EVENT_CODE_RING_BASE
300 #define IIO_EVENT_CODE_RING_75_FULL     (IIO_EVENT_CODE_RING_BASE + 1)
301 #define IIO_EVENT_CODE_RING_100_FULL    (IIO_EVENT_CODE_RING_BASE + 2)
302
303 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */