Merge branch 'drm-intel-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/keith...
[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_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.
23  */
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;
30 };
31
32 #define to_iio_dev_attr(_dev_attr)                              \
33         container_of(_dev_attr, struct iio_dev_attr, dev_attr)
34
35 ssize_t iio_read_const_attr(struct device *dev,
36                             struct device_attribute *attr,
37                             char *len);
38
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
44  */
45 struct iio_const_attr {
46         const char *string;
47         struct device_attribute dev_attr;
48 };
49
50 #define to_iio_const_attr(_dev_attr) \
51         container_of(_dev_attr, struct iio_const_attr, dev_attr)
52
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 }
58
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)
62
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)
66
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)
70
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)}
75
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 */
81
82 /**
83  * IIO_DEV_ATTR_REV - revision number for the device
84  * @_show: output method for the attribute
85  *
86  * Very much device dependent.
87  **/
88 #define IIO_DEV_ATTR_REV(_show)                 \
89         IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
90
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)
96
97 /**
98  * IIO_CONST_ATTR_NAME - constant identifier
99  * @_string: the name
100  **/
101 #define IIO_CONST_ATTR_NAME(_string)                            \
102         IIO_CONST_ATTR(name, _string)
103
104 /**
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
109  **/
110 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store)                    \
111         IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
112
113 /**
114  * IIO_DEV_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
115  * @_show: output method for the attribute
116  *
117  * May be mode dependent on some devices
118  **/
119 /* Deprecated */
120 #define IIO_DEV_ATTR_AVAIL_SAMP_FREQ(_show)                             \
121         IIO_DEVICE_ATTR(available_sampling_frequency, S_IRUGO, _show, NULL, 0)
122
123 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show)                             \
124         IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
125 /**
126  * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
127  * @_string: frequency string for the attribute
128  *
129  * Constant version
130  **/
131 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string)                 \
132         IIO_CONST_ATTR(sampling_frequency_available, _string)
133
134 /**
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
138  *
139  * Success may be dependent on attachment of trigger previously.
140  **/
141 #define IIO_DEV_ATTR_SW_RING_ENABLE(_show, _store)                      \
142         IIO_DEVICE_ATTR(sw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
143
144 /**
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
148  *
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.
151  **/
152 #define IIO_DEV_ATTR_HW_RING_ENABLE(_show, _store)                      \
153         IIO_DEVICE_ATTR(hw_ring_enable, S_IRUGO | S_IWUSR, _show, _store, 0)
154
155 #define IIO_DEV_ATTR_TEMP_RAW(_show)                    \
156         IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
157
158 #define IIO_CONST_ATTR_TEMP_OFFSET(_string)             \
159         IIO_CONST_ATTR(temp_offset, _string)
160
161 #define IIO_CONST_ATTR_TEMP_SCALE(_string)              \
162         IIO_CONST_ATTR(temp_scale, _string)
163
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
173
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
185
186 #define IIO_EV_TYPE_THRESH              0
187 #define IIO_EV_TYPE_MAG                 1
188 #define IIO_EV_TYPE_ROC                 2
189
190 #define IIO_EV_DIR_EITHER               0
191 #define IIO_EV_DIR_RISING               1
192 #define IIO_EV_DIR_FALLING              2
193
194 #define IIO_EV_TYPE_MAX 8
195 #define IIO_EV_BIT(type, direction)                     \
196         (1 << (type*IIO_EV_TYPE_MAX + direction))
197
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))
202
203 #define IIO_MOD_EVENT_CODE(channelclass, number, modifier,              \
204                            type, direction)                             \
205         IIO_EVENT_CODE(channelclass, 1, number, modifier, type, direction)
206
207 #define IIO_UNMOD_EVENT_CODE(channelclass, number, type, direction)     \
208         IIO_EVENT_CODE(channelclass, 0, number, 0, type, direction)
209
210
211 #define IIO_BUFFER_EVENT_CODE(code)             \
212         (IIO_EV_CLASS_BUFFER | (code << 8))
213
214 #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 24) & 0xf)
215
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)
219
220 #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 13) & 0x7)
221
222 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */