Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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_attribute - 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*/
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
57 */
58struct iio_dev_attr {
59 struct device_attribute dev_attr;
60 int address;
61 int val2;
62};
63
64#define to_iio_dev_attr(_dev_attr) \
65 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
66
67ssize_t iio_read_const_attr(struct device *dev,
68 struct device_attribute *attr,
69 char *len);
70
71/**
72 * struct iio_const_attr - constant device specific attribute
73 * often used for things like available modes
74 */
75struct iio_const_attr {
76 const char *string;
77 struct device_attribute dev_attr;
78};
79
80#define to_iio_const_attr(_dev_attr) \
81 container_of(_dev_attr, struct iio_const_attr, dev_attr)
82
83/* Some attributes will be hard coded (device dependant) and not require an
84 address, in these cases pass a negative */
85#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
86 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
87 .address = _addr }
88
89#define IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
90 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
91 .address = _addr, \
92 .val2 = _val2 }
93
94#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
95 struct iio_dev_attr iio_dev_attr_##_name \
96 = IIO_ATTR(_name, _mode, _show, _store, _addr)
97
98
99#define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
100 struct iio_dev_attr iio_dev_attr_##_name \
101 = IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2)
102
103#define IIO_CONST_ATTR(_name, _string) \
104 struct iio_const_attr iio_const_attr_##_name \
105 = { .string = _string, \
106 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
107
108/* Generic attributes of onetype or another */
109
110/**
111 * IIO_DEV_ATTR_REG: revision number for the device
112 *
113 * Very much device dependent.
114 **/
115#define IIO_DEV_ATTR_REV(_show) \
116 IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
117/**
118 * IIO_DEV_ATTR_NAME: chip type dependant identifier
119 **/
120#define IIO_DEV_ATTR_NAME(_show) \
121 IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
122
123/**
124 * IIO_DEV_ATTR_SAMP_FREQ: sets any internal clock frequency
125 **/
126#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
127 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
128
129/**
130 * IIO_DEV_ATTR_AVAIL_SAMP_FREQ: list available sampling frequencies.
131 *
132 * May be mode dependant on some devices
133 **/
134#define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show) \
135 IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
136
137/**
138 * IIO_DEV_ATTR_CONST_AVAIL_SAMP_FREQ: list available sampling frequencies.
139 *
140 * Constant version
141 **/
142#define IIO_CONST_ATTR_AVAIL_SAMP_FREQ(_string) \
143 IIO_CONST_ATTR(available_sampling_frequency, _string)
144/**
145 * IIO_DEV_ATTR_SCAN_MODE: select a scan mode
146 *
147 * This is used when only certain combinations of inputs may be read in one
148 * scan.
149 **/
150#define IIO_DEV_ATTR_SCAN_MODE(_mode, _show, _store) \
151 IIO_DEVICE_ATTR(scan_mode, _mode, _show, _store, 0)
152/**
153 * IIO_DEV_ATTR_AVAIL_SCAN_MODES: list available scan modes
154 **/
155#define IIO_DEV_ATTR_AVAIL_SCAN_MODES(_show) \
156 IIO_DEVICE_ATTR(available_scan_modes, S_IRUGO, _show, NULL, 0)
157
158/**
159 * IIO_DEV_ATTR_SCAN: result of scan of multiple channels
160 **/
161#define IIO_DEV_ATTR_SCAN(_show) \
162 IIO_DEVICE_ATTR(scan, S_IRUGO, _show, NULL, 0);
163
164/**
165 * IIO_DEV_ATTR_INPUT: direct read of a single input channel
166 **/
167#define IIO_DEV_ATTR_INPUT(_number, _show) \
168 IIO_DEVICE_ATTR(in##_number, S_IRUGO, _show, NULL, _number)
169
170
171/**
172 * IIO_DEV_ATTR_SW_RING_ENABLE: enable software ring buffer
173 *
174 * Success may be dependant on attachment of trigger previously
175 **/
176#define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store) \
177 IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
178
179/**
180 * IIO_DEV_ATTR_HW_RING_ENABLE: enable hardware ring buffer
181 *
182 * This is a different attribute from the software one as one can invision
183 * schemes where a combination of the two may be used.
184 **/
185#define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store) \
186 IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
187
188/**
189 * IIO_DEV_ATTR_BPSE: set number of bits per scan element
190 **/
191#define IIO_DEV_ATTR_BPSE(_mode, _show, _store) \
192 IIO_DEVICE_ATTR(bpse, _mode, _show, _store, 0)
193
194/**
195 * IIO_DEV_ATTR_BPSE_AVAILABLE: no of bits per scan element supported
196 **/
197#define IIO_DEV_ATTR_BPSE_AVAILABLE(_show) \
198 IIO_DEVICE_ATTR(bpse_available, S_IRUGO, _show, NULL, 0)
199
200/**
201 * IIO_DEV_ATTR_TEMP: many sensors have auxiliary temperature sensors
202 **/
203#define IIO_DEV_ATTR_TEMP(_show) \
204 IIO_DEVICE_ATTR(temp, S_IRUGO, _show, NULL, 0)
205/**
206 * IIO_EVENT_SH: generic shared event handler
207 *
208 * This is used in cases where more than one event may result from a single
209 * handler. Often the case that some alarm register must be read and multiple
210 * alarms may have been triggered.
211 **/
212#define IIO_EVENT_SH(_name, _handler) \
213 static struct iio_event_handler_list \
214 iio_event_##_name = { \
215 .handler = _handler, \
216 .refcount = 0, \
217 .exist_lock = __MUTEX_INITIALIZER(iio_event_##_name \
218 .exist_lock), \
219 .list = { \
220 .next = &iio_event_##_name.list, \
221 .prev = &iio_event_##_name.list, \
222 }, \
223 };
224/**
225 * IIO_EVENT_ATTR_SH: generic shared event attribute
226 *
227 * An attribute with an associated IIO_EVENT_SH
228 **/
229#define IIO_EVENT_ATTR_SH(_name, _ev_list, _show, _store, _mask) \
230 static struct iio_event_attr \
231 iio_event_attr_##_name \
232 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
233 _show, _store), \
234 .mask = _mask, \
235 .listel = &_ev_list };
236
237/**
238 * IIO_EVENT_ATTR: non shared event attribute
239 **/
240#define IIO_EVENT_ATTR(_name, _show, _store, _mask, _handler) \
241 static struct iio_event_handler_list \
242 iio_event_##_name = { \
243 .handler = _handler, \
244 }; \
245 static struct \
246 iio_event_attr \
247 iio_event_attr_##_name \
248 = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR, \
249 _show, _store), \
250 .mask = _mask, \
251 .listel = &iio_event_##_name }; \
252
253/**
254 * IIO_EVENT_ATTR_DATA_RDY: event driven by data ready signal
255 *
256 * Not typically implemented in devices where full triggering support
257 * has been implemented
258 **/
259#define IIO_EVENT_ATTR_DATA_RDY(_show, _store, _mask, _handler) \
260 IIO_EVENT_ATTR(data_rdy, _show, _store, _mask, _handler)
261
262#define IIO_EVENT_CODE_DATA_RDY 100
263#define IIO_EVENT_CODE_RING_BASE 200
264#define IIO_EVENT_CODE_ACCEL_BASE 300
265#define IIO_EVENT_CODE_GYRO_BASE 400
266#define IIO_EVENT_CODE_ADC_BASE 500
267#define IIO_EVENT_CODE_MISC_BASE 600
268
269#define IIO_EVENT_CODE_DEVICE_SPECIFIC 1000
270
271/**
272 * IIO_EVENT_ATTR_RING_50_FULL: ring buffer event to indicate 50% full
273 **/
274#define IIO_EVENT_ATTR_RING_50_FULL(_show, _store, _mask, _handler) \
275 IIO_EVENT_ATTR(ring_50_full, _show, _store, _mask, _handler)
276
277/**
278 * IIO_EVENT_ATTR_RING_50_FULL_SH: shared ring event to indicate 50% full
279 **/
280#define IIO_EVENT_ATTR_RING_50_FULL_SH(_evlist, _show, _store, _mask) \
281 IIO_EVENT_ATTR_SH(ring_50_full, _evlist, _show, _store, _mask)
282
283/**
284 * IIO_EVENT_ATTR_RING_75_FULL_SH: shared ring event to indicate 75% full
285 **/
286#define IIO_EVENT_ATTR_RING_75_FULL_SH(_evlist, _show, _store, _mask) \
287 IIO_EVENT_ATTR_SH(ring_75_full, _evlist, _show, _store, _mask)
288
289#define IIO_EVENT_CODE_RING_50_FULL IIO_EVENT_CODE_RING_BASE
290#define IIO_EVENT_CODE_RING_75_FULL (IIO_EVENT_CODE_RING_BASE + 1)
291#define IIO_EVENT_CODE_RING_100_FULL (IIO_EVENT_CODE_RING_BASE + 2)
292
293#endif /* _INDUSTRIAL_IO_SYSFS_H_ */