GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / staging / iio / sysfs.h
blob60834162eb320a7a3b529324fc2844220c2d0ace
1 /* The industrial I/O core
3 *Copyright (c) 2008 Jonathan Cameron
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.
9 * General attributes
12 #ifndef _INDUSTRIAL_IO_SYSFS_H_
13 #define _INDUSTRIAL_IO_SYSFS_H_
15 #include "iio.h"
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
23 struct iio_event_attr {
24 struct device_attribute dev_attr;
25 int mask;
26 struct iio_event_handler_list *listel;
29 #define to_iio_event_attr(_dev_attr) \
30 container_of(_dev_attr, struct iio_event_attr, dev_attr)
32 /**
33 * struct iio_chrdev_minor_attr - simple attribute to allow reading of chrdev
34 * minor number
35 * @dev_attr: underlying device attribute
36 * @minor: the minor number
38 struct iio_chrdev_minor_attr {
39 struct device_attribute dev_attr;
40 int minor;
43 void
44 __init_iio_chrdev_minor_attr(struct iio_chrdev_minor_attr *minor_attr,
45 const char *name,
46 struct module *owner,
47 int id);
50 #define to_iio_chrdev_minor_attr(_dev_attr) \
51 container_of(_dev_attr, struct iio_chrdev_minor_attr, dev_attr);
53 /**
54 * struct iio_dev_attr - iio specific device attribute
55 * @dev_attr: underlying device attribute
56 * @address: associated register address
57 * @val2: secondary attribute value
59 struct iio_dev_attr {
60 struct device_attribute dev_attr;
61 int address;
62 int val2;
65 #define to_iio_dev_attr(_dev_attr) \
66 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
68 ssize_t iio_read_const_attr(struct device *dev,
69 struct device_attribute *attr,
70 char *len);
72 /**
73 * struct iio_const_attr - constant device specific attribute
74 * often used for things like available modes
75 * @string: attribute string
76 * @dev_attr: underlying device attribute
78 struct iio_const_attr {
79 const char *string;
80 struct device_attribute dev_attr;
83 #define to_iio_const_attr(_dev_attr) \
84 container_of(_dev_attr, struct iio_const_attr, dev_attr)
86 /* Some attributes will be hard coded (device dependent) and not require an
87 address, in these cases pass a negative */
88 #define IIO_ATTR(_name, _mode, _show, _store, _addr) \
89 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
90 .address = _addr }
92 #define IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
93 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
94 .address = _addr, \
95 .val2 = _val2 }
97 #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
98 struct iio_dev_attr iio_dev_attr_##_name \
99 = IIO_ATTR(_name, _mode, _show, _store, _addr)
101 #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
102 struct iio_dev_attr iio_dev_attr_##_vname \
103 = IIO_ATTR(_name, _mode, _show, _store, _addr)
105 #define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
106 struct iio_dev_attr iio_dev_attr_##_name \
107 = IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2)
109 #define IIO_CONST_ATTR(_name, _string) \
110 struct iio_const_attr iio_const_attr_##_name \
111 = { .string = _string, \
112 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
114 /* Generic attributes of onetype or another */
117 * IIO_DEV_ATTR_REV - revision number for the device
118 * @_show: output method for the attribute
120 * Very much device dependent.
122 #define IIO_DEV_ATTR_REV(_show) \
123 IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
126 * IIO_DEV_ATTR_NAME - chip type dependent identifier
127 * @_show: output method for the attribute
129 #define IIO_DEV_ATTR_NAME(_show) \
130 IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
133 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
134 * @_mode: sysfs file mode/permissions
135 * @_show: output method for the attribute
136 * @_store: input method for the attribute
138 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
139 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
142 * IIO_DEV_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
143 * @_show: output method for the attribute
145 * May be mode dependent on some devices
147 /* Deprecated */
148 #define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show) \
149 IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
151 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
152 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
154 * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
155 * @_string: frequency string for the attribute
157 * Constant version
159 /* Deprecated */
160 #define IIO_CONST_ATTR_AVAIL_SAMP_FREQ(_string) \
161 IIO_CONST_ATTR(available_sampling_frequency, _string)
163 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
164 IIO_CONST_ATTR(sampling_frequency_available, _string)
167 * IIO_DEV_ATTR_SCAN_MODE - select a scan mode
168 * @_mode: sysfs file mode/permissions
169 * @_show: output method for the attribute
170 * @_store: input method for the attribute
172 * This is used when only certain combinations of inputs may be read in one
173 * scan.
175 #define IIO_DEV_ATTR_SCAN_MODE(_mode, _show, _store) \
176 IIO_DEVICE_ATTR(scan_mode, _mode, _show, _store, 0)
179 * IIO_DEV_ATTR_AVAIL_SCAN_MODES - list available scan modes
180 * @_show: output method for the attribute
182 #define IIO_DEV_ATTR_AVAIL_SCAN_MODES(_show) \
183 IIO_DEVICE_ATTR(available_scan_modes, S_IRUGO, _show, NULL, 0)
186 * IIO_DEV_ATTR_SCAN - result of scan of multiple channels
187 * @_show: output method for the attribute
189 #define IIO_DEV_ATTR_SCAN(_show) \
190 IIO_DEVICE_ATTR(scan, S_IRUGO, _show, NULL, 0);
193 * IIO_DEV_ATTR_INPUT - direct read of a single input channel
194 * @_number: input channel number
195 * @_show: output method for the attribute
197 #define IIO_DEV_ATTR_INPUT(_number, _show) \
198 IIO_DEVICE_ATTR(in##_number, S_IRUGO, _show, NULL, _number)
201 * IIO_DEV_ATTR_SW_RING_ENABLE - enable software ring buffer
202 * @_show: output method for the attribute
203 * @_store: input method for the attribute
205 * Success may be dependent on attachment of trigger previously.
207 #define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store) \
208 IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
211 * IIO_DEV_ATTR_HW_RING_ENABLE - enable hardware ring buffer
212 * @_show: output method for the attribute
213 * @_store: input method for the attribute
215 * This is a different attribute from the software one as one can envision
216 * schemes where a combination of the two may be used.
218 #define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store) \
219 IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
222 * IIO_DEV_ATTR_BPSE - set number of bits per scan element
223 * @_mode: sysfs file mode/permissions
224 * @_show: output method for the attribute
225 * @_store: input method for the attribute
227 #define IIO_DEV_ATTR_BPSE(_mode, _show, _store) \
228 IIO_DEVICE_ATTR(bpse, _mode, _show, _store, 0)
231 * IIO_DEV_ATTR_BPSE_AVAILABLE - number of bits per scan element supported
232 * @_show: output method for the attribute
234 #define IIO_DEV_ATTR_BPSE_AVAILABLE(_show) \
235 IIO_DEVICE_ATTR(bpse_available, S_IRUGO, _show, NULL, 0)
238 * IIO_DEV_ATTR_TEMP - many sensors have auxiliary temperature sensors
239 * @_show: output method for the attribute
241 #define IIO_DEV_ATTR_TEMP(_show) \
242 IIO_DEVICE_ATTR(temp, S_IRUGO, _show, NULL, 0)
244 #define IIO_DEV_ATTR_TEMP_RAW(_show) \
245 IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
248 * IIO_EVENT_SH - generic shared event handler
249 * @_name: event name
250 * @_handler: handler function to be called
252 * This is used in cases where more than one event may result from a single
253 * handler. Often the case that some alarm register must be read and multiple
254 * alarms may have been triggered.
256 #define IIO_EVENT_SH(_name, _handler) \
257 static struct iio_event_handler_list \
258 iio_event_##_name = { \
259 .handler = _handler, \
260 .refcount = 0, \
261 .exist_lock = __MUTEX_INITIALIZER(iio_event_##_name \
262 .exist_lock), \
263 .list = { \
264 .next = &iio_event_##_name.list, \
265 .prev = &iio_event_##_name.list, \
266 }, \
270 * IIO_EVENT_ATTR_SH - generic shared event attribute
271 * @_name: event name
272 * @_ev_list: event handler list
273 * @_show: output method for the attribute
274 * @_store: input method for the attribute
275 * @_mask: mask used when detecting the event
277 * An attribute with an associated IIO_EVENT_SH
279 #define IIO_EVENT_ATTR_SH(_name, _ev_list, _show, _store, _mask) \
280 static struct iio_event_attr \
281 iio_event_attr_##_name \
282 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
283 _show, _store), \
284 .mask = _mask, \
285 .listel = &_ev_list };
287 #define IIO_EVENT_ATTR_NAMED_SH(_vname, _name, _ev_list, _show, _store, _mask) \
288 static struct iio_event_attr \
289 iio_event_attr_##_vname \
290 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
291 _show, _store), \
292 .mask = _mask, \
293 .listel = &_ev_list };
296 * IIO_EVENT_ATTR - non-shared event attribute
297 * @_name: event name
298 * @_show: output method for the attribute
299 * @_store: input method for the attribute
300 * @_mask: mask used when detecting the event
301 * @_handler: handler function to be called
303 #define IIO_EVENT_ATTR(_name, _show, _store, _mask, _handler) \
304 IIO_EVENT_SH(_name, _handler); \
305 static struct \
306 iio_event_attr \
307 iio_event_attr_##_name \
308 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
309 _show, _store), \
310 .mask = _mask, \
311 .listel = &iio_event_##_name }; \
314 * IIO_EVENT_ATTR_DATA_RDY - event driven by data ready signal
315 * @_show: output method for the attribute
316 * @_store: input method for the attribute
317 * @_mask: mask used when detecting the event
318 * @_handler: handler function to be called
320 * Not typically implemented in devices where full triggering support
321 * has been implemented.
323 #define IIO_EVENT_ATTR_DATA_RDY(_show, _store, _mask, _handler) \
324 IIO_EVENT_ATTR(data_rdy, _show, _store, _mask, _handler)
326 #define IIO_EVENT_CODE_DATA_RDY 100
327 #define IIO_EVENT_CODE_RING_BASE 200
328 #define IIO_EVENT_CODE_ACCEL_BASE 300
329 #define IIO_EVENT_CODE_GYRO_BASE 400
330 #define IIO_EVENT_CODE_ADC_BASE 500
331 #define IIO_EVENT_CODE_MISC_BASE 600
332 #define IIO_EVENT_CODE_LIGHT_BASE 700
334 #define IIO_EVENT_CODE_DEVICE_SPECIFIC 1000
337 * IIO_EVENT_ATTR_RING_50_FULL - ring buffer event to indicate 50% full
338 * @_show: output method for the attribute
339 * @_store: input method for the attribute
340 * @_mask: mask used when detecting the event
341 * @_handler: handler function to be called
343 #define IIO_EVENT_ATTR_RING_50_FULL(_show, _store, _mask, _handler) \
344 IIO_EVENT_ATTR(ring_50_full, _show, _store, _mask, _handler)
347 * IIO_EVENT_ATTR_RING_50_FULL_SH - shared ring event to indicate 50% full
348 * @_evlist: event handler list
349 * @_show: output method for the attribute
350 * @_store: input method for the attribute
351 * @_mask: mask used when detecting the event
353 #define IIO_EVENT_ATTR_RING_50_FULL_SH(_evlist, _show, _store, _mask) \
354 IIO_EVENT_ATTR_SH(ring_50_full, _evlist, _show, _store, _mask)
357 * IIO_EVENT_ATTR_RING_75_FULL_SH - shared ring event to indicate 75% full
358 * @_evlist: event handler list
359 * @_show: output method for the attribute
360 * @_store: input method for the attribute
361 * @_mask: mask used when detecting the event
363 #define IIO_EVENT_ATTR_RING_75_FULL_SH(_evlist, _show, _store, _mask) \
364 IIO_EVENT_ATTR_SH(ring_75_full, _evlist, _show, _store, _mask)
366 #define IIO_EVENT_CODE_RING_50_FULL IIO_EVENT_CODE_RING_BASE
367 #define IIO_EVENT_CODE_RING_75_FULL (IIO_EVENT_CODE_RING_BASE + 1)
368 #define IIO_EVENT_CODE_RING_100_FULL (IIO_EVENT_CODE_RING_BASE + 2)
370 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */