tcp: Change possible SYN flooding messages
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / iio / sysfs.h
blobdd79b58442123ebba25a7a337c64b25380f7ad2f
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_dev_attr - iio specific device attribute
19 * @dev_attr: underlying device attribute
20 * @address: associated register address
21 * @val2: secondary attribute value
22 * @l: list head for maintaining list of dynamically created attrs.
24 struct iio_dev_attr {
25 struct device_attribute dev_attr;
26 int address;
27 int val2;
28 struct list_head l;
29 struct iio_chan_spec const *c;
32 #define to_iio_dev_attr(_dev_attr) \
33 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
35 ssize_t iio_read_const_attr(struct device *dev,
36 struct device_attribute *attr,
37 char *len);
39 /**
40 * struct iio_const_attr - constant device specific attribute
41 * often used for things like available modes
42 * @string: attribute string
43 * @dev_attr: underlying device attribute
45 struct iio_const_attr {
46 const char *string;
47 struct device_attribute dev_attr;
50 #define to_iio_const_attr(_dev_attr) \
51 container_of(_dev_attr, struct iio_const_attr, dev_attr)
53 /* Some attributes will be hard coded (device dependent) and not require an
54 address, in these cases pass a negative */
55 #define IIO_ATTR(_name, _mode, _show, _store, _addr) \
56 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
57 .address = _addr }
59 #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
60 struct iio_dev_attr iio_dev_attr_##_name \
61 = IIO_ATTR(_name, _mode, _show, _store, _addr)
63 #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
64 struct iio_dev_attr iio_dev_attr_##_vname \
65 = IIO_ATTR(_name, _mode, _show, _store, _addr)
67 #define IIO_DEVICE_ATTR_2(_name, _mode, _show, _store, _addr, _val2) \
68 struct iio_dev_attr iio_dev_attr_##_name \
69 = IIO_ATTR_2(_name, _mode, _show, _store, _addr, _val2)
71 #define IIO_CONST_ATTR(_name, _string) \
72 struct iio_const_attr iio_const_attr_##_name \
73 = { .string = _string, \
74 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
76 #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
77 struct iio_const_attr iio_const_attr_##_vname \
78 = { .string = _string, \
79 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
80 /* Generic attributes of onetype or another */
82 /**
83 * IIO_DEV_ATTR_REV - revision number for the device
84 * @_show: output method for the attribute
86 * Very much device dependent.
87 **/
88 #define IIO_DEV_ATTR_REV(_show) \
89 IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
91 /**
92 * IIO_DEV_ATTR_RESET: resets the device
93 **/
94 #define IIO_DEV_ATTR_RESET(_store) \
95 IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0)
97 /**
98 * IIO_CONST_ATTR_NAME - constant identifier
99 * @_string: the name
101 #define IIO_CONST_ATTR_NAME(_string) \
102 IIO_CONST_ATTR(name, _string)
105 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
106 * @_mode: sysfs file mode/permissions
107 * @_show: output method for the attribute
108 * @_store: input method for the attribute
110 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
111 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
114 * IIO_DEV_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
115 * @_show: output method for the attribute
117 * May be mode dependent on some devices
119 /* Deprecated */
120 #define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show) \
121 IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
123 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
124 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
126 * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
127 * @_string: frequency string for the attribute
129 * Constant version
131 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
132 IIO_CONST_ATTR(sampling_frequency_available, _string)
135 * IIO_DEV_ATTR_SW_RING_ENABLE - enable software ring buffer
136 * @_show: output method for the attribute
137 * @_store: input method for the attribute
139 * Success may be dependent on attachment of trigger previously.
141 #define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store) \
142 IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
145 * IIO_DEV_ATTR_HW_RING_ENABLE - enable hardware ring buffer
146 * @_show: output method for the attribute
147 * @_store: input method for the attribute
149 * This is a different attribute from the software one as one can envision
150 * schemes where a combination of the two may be used.
152 #define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store) \
153 IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
155 #define IIO_DEV_ATTR_TEMP_RAW(_show) \
156 IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
158 #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
159 IIO_CONST_ATTR(temp_offset, _string)
161 #define IIO_CONST_ATTR_TEMP_SCALE(_string) \
162 IIO_CONST_ATTR(temp_scale, _string)
164 /* must match our channel defs */
165 #define IIO_EV_CLASS_IN IIO_IN
166 #define IIO_EV_CLASS_IN_DIFF IIO_IN_DIFF
167 #define IIO_EV_CLASS_ACCEL IIO_ACCEL
168 #define IIO_EV_CLASS_GYRO IIO_GYRO
169 #define IIO_EV_CLASS_MAGN IIO_MAGN
170 #define IIO_EV_CLASS_LIGHT IIO_LIGHT
171 #define IIO_EV_CLASS_PROXIMITY IIO_PROXIMITY
172 #define IIO_EV_CLASS_TEMP IIO_TEMP
174 #define IIO_EV_MOD_X IIO_MOD_X
175 #define IIO_EV_MOD_Y IIO_MOD_Y
176 #define IIO_EV_MOD_Z IIO_MOD_Z
177 #define IIO_EV_MOD_X_AND_Y IIO_MOD_X_AND_Y
178 #define IIO_EV_MOD_X_ANX_Z IIO_MOD_X_AND_Z
179 #define IIO_EV_MOD_Y_AND_Z IIO_MOD_Y_AND_Z
180 #define IIO_EV_MOD_X_AND_Y_AND_Z IIO_MOD_X_AND_Y_AND_Z
181 #define IIO_EV_MOD_X_OR_Y IIO_MOD_X_OR_Y
182 #define IIO_EV_MOD_X_OR_Z IIO_MOD_X_OR_Z
183 #define IIO_EV_MOD_Y_OR_Z IIO_MOD_Y_OR_Z
184 #define IIO_EV_MOD_X_OR_Y_OR_Z IIO_MOD_X_OR_Y_OR_Z
186 #define IIO_EV_TYPE_THRESH 0
187 #define IIO_EV_TYPE_MAG 1
188 #define IIO_EV_TYPE_ROC 2
190 #define IIO_EV_DIR_EITHER 0
191 #define IIO_EV_DIR_RISING 1
192 #define IIO_EV_DIR_FALLING 2
194 #define IIO_EV_TYPE_MAX 8
195 #define IIO_EV_BIT(type, direction) \
196 (1 << (type*IIO_EV_TYPE_MAX + direction))
198 #define IIO_EVENT_CODE(channelclass, orient_bit, number, \
199 modifier, type, direction) \
200 (channelclass | (orient_bit << 8) | ((number) << 9) | \
201 ((modifier) << 13) | ((type) << 16) | ((direction) << 24))
203 #define IIO_MOD_EVENT_CODE(channelclass, number, modifier, \
204 type, direction) \
205 IIO_EVENT_CODE(channelclass, 1, number, modifier, type, direction)
207 #define IIO_UNMOD_EVENT_CODE(channelclass, number, type, direction) \
208 IIO_EVENT_CODE(channelclass, 0, number, 0, type, direction)
211 #define IIO_BUFFER_EVENT_CODE(code) \
212 (IIO_EV_CLASS_BUFFER | (code << 8))
214 #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 24) & 0xf)
216 /* Event code number extraction depends on which type of event we have.
217 * Perhaps review this function in the future*/
218 #define IIO_EVENT_CODE_EXTRACT_NUM(mask) ((mask >> 9) & 0x0f)
220 #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 13) & 0x7)
222 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */