~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/staging/iio/sysfs.h

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "iio.h"
16
16
 
17
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
22
 
*/
23
 
struct 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
18
 * struct iio_dev_attr - iio specific device attribute
34
19
 * @dev_attr:   underlying device attribute
35
20
 * @address:    associated register address
36
21
 * @val2:       secondary attribute value
 
22
 * @l:          list head for maintaining list of dynamically created attrs.
37
23
 */
38
24
struct iio_dev_attr {
39
25
        struct device_attribute dev_attr;
40
26
        int address;
41
27
        int val2;
 
28
        struct list_head l;
 
29
        struct iio_chan_spec const *c;
42
30
};
43
31
 
44
32
#define to_iio_dev_attr(_dev_attr)                              \
101
89
        IIO_DEVICE_ATTR(revision, S_IRUGO, _show, NULL, 0)
102
90
 
103
91
/**
104
 
 * IIO_DEV_ATTR_NAME - chip type dependent identifier
105
 
 * @_show: output method for the attribute
106
 
 **/
107
 
#define IIO_DEV_ATTR_NAME(_show)                                \
108
 
        IIO_DEVICE_ATTR(name, S_IRUGO, _show, NULL, 0)
109
 
 
110
 
/**
111
92
 * IIO_DEV_ATTR_RESET: resets the device
112
93
 **/
113
94
#define IIO_DEV_ATTR_RESET(_store)                      \
180
161
#define IIO_CONST_ATTR_TEMP_SCALE(_string)              \
181
162
        IIO_CONST_ATTR(temp_scale, _string)
182
163
 
183
 
/**
184
 
 * IIO_EVENT_SH - generic shared event handler
185
 
 * @_name: event name
186
 
 * @_handler: handler function to be called
187
 
 *
188
 
 * This is used in cases where more than one event may result from a single
189
 
 * handler.  Often the case that some alarm register must be read and multiple
190
 
 * alarms may have been triggered.
191
 
 **/
192
 
#define IIO_EVENT_SH(_name, _handler)                                   \
193
 
        static struct iio_event_handler_list                            \
194
 
        iio_event_##_name = {                                           \
195
 
                .handler = _handler,                                    \
196
 
                .refcount = 0,                                          \
197
 
                .exist_lock = __MUTEX_INITIALIZER(iio_event_##_name     \
198
 
                                                  .exist_lock),         \
199
 
                .list = {                                               \
200
 
                        .next = &iio_event_##_name.list,                \
201
 
                        .prev = &iio_event_##_name.list,                \
202
 
                },                                                      \
203
 
        };
204
 
 
205
 
/**
206
 
 * IIO_EVENT_ATTR_SH - generic shared event attribute
207
 
 * @_name: event name
208
 
 * @_ev_list: event handler list
209
 
 * @_show: output method for the attribute
210
 
 * @_store: input method for the attribute
211
 
 * @_mask: mask used when detecting the event
212
 
 *
213
 
 * An attribute with an associated IIO_EVENT_SH
214
 
 **/
215
 
#define IIO_EVENT_ATTR_SH(_name, _ev_list, _show, _store, _mask)        \
216
 
        static struct iio_event_attr                                    \
217
 
        iio_event_attr_##_name                                          \
218
 
        = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
219
 
                               _show, _store),                          \
220
 
            .mask = _mask,                                              \
221
 
            .listel = &_ev_list };
222
 
 
223
 
#define IIO_EVENT_ATTR_NAMED_SH(_vname, _name, _ev_list, _show, _store, _mask) \
224
 
        static struct iio_event_attr                                    \
225
 
        iio_event_attr_##_vname                                         \
226
 
        = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
227
 
                               _show, _store),                          \
228
 
            .mask = _mask,                                              \
229
 
            .listel = &_ev_list };
230
 
 
231
 
/**
232
 
 * IIO_EVENT_ATTR - non-shared event attribute
233
 
 * @_name: event name
234
 
 * @_show: output method for the attribute
235
 
 * @_store: input method for the attribute
236
 
 * @_mask: mask used when detecting the event
237
 
 * @_handler: handler function to be called
238
 
 **/
239
 
#define IIO_EVENT_ATTR(_name, _show, _store, _mask, _handler)           \
240
 
        IIO_EVENT_SH(_name, _handler);                                  \
241
 
        static struct                                                   \
242
 
        iio_event_attr                                                  \
243
 
        iio_event_attr_##_name                                          \
244
 
        = { .dev_attr = __ATTR(_name, S_IRUGO | S_IWUSR,                \
245
 
                               _show, _store),                          \
246
 
            .mask = _mask,                                              \
247
 
            .listel = &iio_event_##_name };                             \
248
 
 
249
 
/**
250
 
 * IIO_EVENT_ATTR_DATA_RDY - event driven by data ready signal
251
 
 * @_show: output method for the attribute
252
 
 * @_store: input method for the attribute
253
 
 * @_mask: mask used when detecting the event
254
 
 * @_handler: handler function to be called
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_EV_CLASS_BUFFER             0
263
 
#define IIO_EV_CLASS_IN                 1
264
 
#define IIO_EV_CLASS_ACCEL              2
265
 
#define IIO_EV_CLASS_GYRO               3
266
 
#define IIO_EV_CLASS_MAGN               4
267
 
#define IIO_EV_CLASS_LIGHT              5
268
 
#define IIO_EV_CLASS_PROXIMITY          6
269
 
 
270
 
#define IIO_EV_MOD_X                    0
271
 
#define IIO_EV_MOD_Y                    1
272
 
#define IIO_EV_MOD_Z                    2
273
 
#define IIO_EV_MOD_X_AND_Y              3
274
 
#define IIO_EV_MOD_X_ANX_Z              4
275
 
#define IIO_EV_MOD_Y_AND_Z              5
276
 
#define IIO_EV_MOD_X_AND_Y_AND_Z        6
277
 
#define IIO_EV_MOD_X_OR_Y               7
278
 
#define IIO_EV_MOD_X_OR_Z               8
279
 
#define IIO_EV_MOD_Y_OR_Z               9
280
 
#define IIO_EV_MOD_X_OR_Y_OR_Z          10
 
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
281
185
 
282
186
#define IIO_EV_TYPE_THRESH              0
283
187
#define IIO_EV_TYPE_MAG                 1
287
191
#define IIO_EV_DIR_RISING               1
288
192
#define IIO_EV_DIR_FALLING              2
289
193
 
 
194
#define IIO_EV_TYPE_MAX 8
 
195
#define IIO_EV_BIT(type, direction)                     \
 
196
        (1 << (type*IIO_EV_TYPE_MAX + direction))
 
197
 
290
198
#define IIO_EVENT_CODE(channelclass, orient_bit, number,                \
291
199
                       modifier, type, direction)                       \
292
200
        (channelclass | (orient_bit << 8) | ((number) << 9) |           \
303
211
#define IIO_BUFFER_EVENT_CODE(code)             \
304
212
        (IIO_EV_CLASS_BUFFER | (code << 8))
305
213
 
306
 
/**
307
 
 * IIO_EVENT_ATTR_RING_50_FULL - ring buffer event to indicate 50% full
308
 
 * @_show: output method for the attribute
309
 
 * @_store: input method for the attribute
310
 
 * @_mask: mask used when detecting the event
311
 
 * @_handler: handler function to be called
312
 
 **/
313
 
#define IIO_EVENT_ATTR_RING_50_FULL(_show, _store, _mask, _handler)     \
314
 
        IIO_EVENT_ATTR(ring_50_full, _show, _store, _mask, _handler)
315
 
 
316
 
/**
317
 
 * IIO_EVENT_ATTR_RING_50_FULL_SH - shared ring event to indicate 50% full
318
 
 * @_evlist: event handler list
319
 
 * @_show: output method for the attribute
320
 
 * @_store: input method for the attribute
321
 
 * @_mask: mask used when detecting the event
322
 
 **/
323
 
#define IIO_EVENT_ATTR_RING_50_FULL_SH(_evlist, _show, _store, _mask)   \
324
 
        IIO_EVENT_ATTR_SH(ring_50_full, _evlist, _show, _store, _mask)
325
 
 
326
 
/**
327
 
 * IIO_EVENT_ATTR_RING_75_FULL_SH - shared ring event to indicate 75% full
328
 
 * @_evlist: event handler list
329
 
 * @_show: output method for the attribute
330
 
 * @_store: input method for the attribute
331
 
 * @_mask: mask used when detecting the event
332
 
 **/
333
 
#define IIO_EVENT_ATTR_RING_75_FULL_SH(_evlist, _show, _store, _mask)   \
334
 
        IIO_EVENT_ATTR_SH(ring_75_full, _evlist, _show, _store, _mask)
335
 
 
336
 
#define IIO_EVENT_CODE_RING_50_FULL     IIO_BUFFER_EVENT_CODE(0)
337
 
#define IIO_EVENT_CODE_RING_75_FULL     IIO_BUFFER_EVENT_CODE(1)
338
 
#define IIO_EVENT_CODE_RING_100_FULL    IIO_BUFFER_EVENT_CODE(2)
 
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)
339
221
 
340
222
#endif /* _INDUSTRIAL_IO_SYSFS_H_ */