Merge branch 'x86-pat-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / staging / iio / sysfs.h
CommitLineData
847ec80b
JC
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/**
4c572605 18 * struct iio_event_attr - event control attribute
847ec80b
JC
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*/
23struct 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_chrdev_minor_attr - simple attribute to allow reading of chrdev
34 * minor number
35 * @dev_attr: underlying device attribute
36 * @minor: the minor number
37 */
38struct iio_chrdev_minor_attr {
39 struct device_attribute dev_attr;
40 int minor;
41};
42
43void
44__init_iio_chrdev_minor_attr(struct iio_chrdev_minor_attr *minor_attr,
45 const char *name,
46 struct module *owner,
47 int id);
48
49
50#define to_iio_chrdev_minor_attr(_dev_attr) \
51 container_of(_dev_attr, struct iio_chrdev_minor_attr, dev_attr);
52
53/**
54 * struct iio_dev_attr - iio specific device attribute
55 * @dev_attr: underlying device attribute
56 * @address: associated register address
4c572605 57 * @val2: secondary attribute value
847ec80b
JC
58 */
59struct iio_dev_attr {
60 struct device_attribute dev_attr;
61 int address;
62 int val2;
63};
64
65#define to_iio_dev_attr(_dev_attr) \
66 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
67
68ssize_t iio_read_const_attr(struct device *dev,
69 struct device_attribute *attr,
70 char *len);
71
72/**
73 * struct iio_const_attr - constant device specific attribute
74 * often used for things like available modes
4c572605
RD
75 * @string: attribute string
76 * @dev_attr: underlying device attribute
847ec80b
JC
77 */
78struct iio_const_attr {
79 const char *string;
80 struct device_attribute dev_attr;
81};
82
83#define to_iio_const_attr(_dev_attr) \
84 container_of(_dev_attr, struct iio_const_attr, dev_attr)
85
4c572605 86/* Some attributes will be hard coded (device dependent) and not require an
847ec80b
JC
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 }
91
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 }
96
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)
100
101
102#define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
103 struct iio_dev_attr iio_dev_attr_##_name \
104 = IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2)
105
106#define IIO_CONST_ATTR(_name, _string) \
107 struct iio_const_attr iio_const_attr_##_name \
108 = { .string = _string, \
109 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
110
111/* Generic attributes of onetype or another */
112
113/**
4c572605
RD
114 * IIO_DEV_ATTR_REV - revision number for the device
115 * @_show: output method for the attribute
847ec80b
JC
116 *
117 * Very much device dependent.
118 **/
119#define IIO_DEV_ATTR_REV(_show) \
120 IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
4c572605 121
847ec80b 122/**
4c572605
RD
123 * IIO_DEV_ATTR_NAME - chip type dependent identifier
124 * @_show: output method for the attribute
847ec80b
JC
125 **/
126#define IIO_DEV_ATTR_NAME(_show) \
127 IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
128
129/**
4c572605
RD
130 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
131 * @_mode: sysfs file mode/permissions
132 * @_show: output method for the attribute
133 * @_store: input method for the attribute
847ec80b
JC
134 **/
135#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
136 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
137
138/**
4c572605
RD
139 * IIO_DEV_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
140 * @_show: output method for the attribute
847ec80b 141 *
4c572605 142 * May be mode dependent on some devices
847ec80b
JC
143 **/
144#define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show) \
145 IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
146
147/**
4c572605
RD
148 * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
149 * @_string: frequency string for the attribute
847ec80b
JC
150 *
151 * Constant version
152 **/
153#define IIO_CONST_ATTR_AVAIL_SAMP_FREQ(_string) \
154 IIO_CONST_ATTR(available_sampling_frequency, _string)
4c572605 155
847ec80b 156/**
4c572605
RD
157 * IIO_DEV_ATTR_SCAN_MODE - select a scan mode
158 * @_mode: sysfs file mode/permissions
159 * @_show: output method for the attribute
160 * @_store: input method for the attribute
847ec80b
JC
161 *
162 * This is used when only certain combinations of inputs may be read in one
163 * scan.
164 **/
165#define IIO_DEV_ATTR_SCAN_MODE(_mode, _show, _store) \
166 IIO_DEVICE_ATTR(scan_mode, _mode, _show, _store, 0)
4c572605 167
847ec80b 168/**
4c572605
RD
169 * IIO_DEV_ATTR_AVAIL_SCAN_MODES - list available scan modes
170 * @_show: output method for the attribute
847ec80b
JC
171 **/
172#define IIO_DEV_ATTR_AVAIL_SCAN_MODES(_show) \
173 IIO_DEVICE_ATTR(available_scan_modes, S_IRUGO, _show, NULL, 0)
174
175/**
4c572605
RD
176 * IIO_DEV_ATTR_SCAN - result of scan of multiple channels
177 * @_show: output method for the attribute
847ec80b
JC
178 **/
179#define IIO_DEV_ATTR_SCAN(_show) \
180 IIO_DEVICE_ATTR(scan, S_IRUGO, _show, NULL, 0);
181
182/**
4c572605
RD
183 * IIO_DEV_ATTR_INPUT - direct read of a single input channel
184 * @_number: input channel number
185 * @_show: output method for the attribute
847ec80b
JC
186 **/
187#define IIO_DEV_ATTR_INPUT(_number, _show) \
188 IIO_DEVICE_ATTR(in##_number, S_IRUGO, _show, NULL, _number)
189
847ec80b 190/**
4c572605
RD
191 * IIO_DEV_ATTR_SW_RING_ENABLE - enable software ring buffer
192 * @_show: output method for the attribute
193 * @_store: input method for the attribute
847ec80b 194 *
4c572605 195 * Success may be dependent on attachment of trigger previously.
847ec80b
JC
196 **/
197#define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store) \
198 IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
199
200/**
4c572605
RD
201 * IIO_DEV_ATTR_HW_RING_ENABLE - enable hardware ring buffer
202 * @_show: output method for the attribute
203 * @_store: input method for the attribute
847ec80b 204 *
4c572605 205 * This is a different attribute from the software one as one can envision
847ec80b
JC
206 * schemes where a combination of the two may be used.
207 **/
208#define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store) \
209 IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
210
211/**
4c572605
RD
212 * IIO_DEV_ATTR_BPSE - set number of bits per scan element
213 * @_mode: sysfs file mode/permissions
214 * @_show: output method for the attribute
215 * @_store: input method for the attribute
847ec80b
JC
216 **/
217#define IIO_DEV_ATTR_BPSE(_mode, _show, _store) \
218 IIO_DEVICE_ATTR(bpse, _mode, _show, _store, 0)
219
220/**
4c572605
RD
221 * IIO_DEV_ATTR_BPSE_AVAILABLE - number of bits per scan element supported
222 * @_show: output method for the attribute
847ec80b
JC
223 **/
224#define IIO_DEV_ATTR_BPSE_AVAILABLE(_show) \
225 IIO_DEVICE_ATTR(bpse_available, S_IRUGO, _show, NULL, 0)
226
227/**
4c572605
RD
228 * IIO_DEV_ATTR_TEMP - many sensors have auxiliary temperature sensors
229 * @_show: output method for the attribute
847ec80b
JC
230 **/
231#define IIO_DEV_ATTR_TEMP(_show) \
232 IIO_DEVICE_ATTR(temp, S_IRUGO, _show, NULL, 0)
4c572605 233
847ec80b 234/**
4c572605
RD
235 * IIO_EVENT_SH - generic shared event handler
236 * @_name: event name
237 * @_handler: handler function to be called
847ec80b
JC
238 *
239 * This is used in cases where more than one event may result from a single
240 * handler. Often the case that some alarm register must be read and multiple
241 * alarms may have been triggered.
242 **/
243#define IIO_EVENT_SH(_name, _handler) \
244 static struct iio_event_handler_list \
245 iio_event_##_name = { \
246 .handler = _handler, \
247 .refcount = 0, \
248 .exist_lock = __MUTEX_INITIALIZER(iio_event_##_name \
249 .exist_lock), \
250 .list = { \
251 .next = &iio_event_##_name.list, \
252 .prev = &iio_event_##_name.list, \
253 }, \
254 };
4c572605 255
847ec80b 256/**
4c572605
RD
257 * IIO_EVENT_ATTR_SH - generic shared event attribute
258 * @_name: event name
259 * @_ev_list: event handler list
260 * @_show: output method for the attribute
261 * @_store: input method for the attribute
262 * @_mask: mask used when detecting the event
847ec80b
JC
263 *
264 * An attribute with an associated IIO_EVENT_SH
265 **/
266#define IIO_EVENT_ATTR_SH(_name, _ev_list, _show, _store, _mask) \
267 static struct iio_event_attr \
268 iio_event_attr_##_name \
269 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
270 _show, _store), \
271 .mask = _mask, \
272 .listel = &_ev_list };
273
274/**
4c572605
RD
275 * IIO_EVENT_ATTR - non-shared event attribute
276 * @_name: event name
277 * @_show: output method for the attribute
278 * @_store: input method for the attribute
279 * @_mask: mask used when detecting the event
280 * @_handler: handler function to be called
847ec80b
JC
281 **/
282#define IIO_EVENT_ATTR(_name, _show, _store, _mask, _handler) \
283 static struct iio_event_handler_list \
284 iio_event_##_name = { \
285 .handler = _handler, \
286 }; \
287 static struct \
288 iio_event_attr \
289 iio_event_attr_##_name \
290 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
291 _show, _store), \
292 .mask = _mask, \
293 .listel = &iio_event_##_name }; \
294
295/**
4c572605
RD
296 * IIO_EVENT_ATTR_DATA_RDY - event driven by data ready signal
297 * @_show: output method for the attribute
298 * @_store: input method for the attribute
299 * @_mask: mask used when detecting the event
300 * @_handler: handler function to be called
847ec80b
JC
301 *
302 * Not typically implemented in devices where full triggering support
4c572605 303 * has been implemented.
847ec80b
JC
304 **/
305#define IIO_EVENT_ATTR_DATA_RDY(_show, _store, _mask, _handler) \
306 IIO_EVENT_ATTR(data_rdy, _show, _store, _mask, _handler)
307
308#define IIO_EVENT_CODE_DATA_RDY 100
309#define IIO_EVENT_CODE_RING_BASE 200
310#define IIO_EVENT_CODE_ACCEL_BASE 300
311#define IIO_EVENT_CODE_GYRO_BASE 400
312#define IIO_EVENT_CODE_ADC_BASE 500
313#define IIO_EVENT_CODE_MISC_BASE 600
314
315#define IIO_EVENT_CODE_DEVICE_SPECIFIC 1000
316
317/**
4c572605
RD
318 * IIO_EVENT_ATTR_RING_50_FULL - ring buffer event to indicate 50% full
319 * @_show: output method for the attribute
320 * @_store: input method for the attribute
321 * @_mask: mask used when detecting the event
322 * @_handler: handler function to be called
847ec80b
JC
323 **/
324#define IIO_EVENT_ATTR_RING_50_FULL(_show, _store, _mask, _handler) \
325 IIO_EVENT_ATTR(ring_50_full, _show, _store, _mask, _handler)
326
327/**
4c572605
RD
328 * IIO_EVENT_ATTR_RING_50_FULL_SH - shared ring event to indicate 50% full
329 * @_evlist: event handler list
330 * @_show: output method for the attribute
331 * @_store: input method for the attribute
332 * @_mask: mask used when detecting the event
847ec80b
JC
333 **/
334#define IIO_EVENT_ATTR_RING_50_FULL_SH(_evlist, _show, _store, _mask) \
335 IIO_EVENT_ATTR_SH(ring_50_full, _evlist, _show, _store, _mask)
336
337/**
4c572605
RD
338 * IIO_EVENT_ATTR_RING_75_FULL_SH - shared ring event to indicate 75% full
339 * @_evlist: event handler list
340 * @_show: output method for the attribute
341 * @_store: input method for the attribute
342 * @_mask: mask used when detecting the event
847ec80b
JC
343 **/
344#define IIO_EVENT_ATTR_RING_75_FULL_SH(_evlist, _show, _store, _mask) \
345 IIO_EVENT_ATTR_SH(ring_75_full, _evlist, _show, _store, _mask)
346
347#define IIO_EVENT_CODE_RING_50_FULL IIO_EVENT_CODE_RING_BASE
348#define IIO_EVENT_CODE_RING_75_FULL (IIO_EVENT_CODE_RING_BASE + 1)
349#define IIO_EVENT_CODE_RING_100_FULL (IIO_EVENT_CODE_RING_BASE + 2)
350
351#endif /* _INDUSTRIAL_IO_SYSFS_H_ */