staging:iio:events: use IIO_<TYPE> and IIO_MOD_<> instead of IIO_EV_CLASS_<TYPE> etc
[linux-block.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
847ec80b
JC
17/**
18 * struct iio_dev_attr - iio specific device attribute
19 * @dev_attr: underlying device attribute
20 * @address: associated register address
1d892719 21 * @l: list head for maintaining list of dynamically created attrs.
847ec80b
JC
22 */
23struct iio_dev_attr {
24 struct device_attribute dev_attr;
25 int address;
1d892719
JC
26 struct list_head l;
27 struct iio_chan_spec const *c;
847ec80b
JC
28};
29
30#define to_iio_dev_attr(_dev_attr) \
31 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
32
33ssize_t iio_read_const_attr(struct device *dev,
34 struct device_attribute *attr,
35 char *len);
36
37/**
38 * struct iio_const_attr - constant device specific attribute
39 * often used for things like available modes
4c572605
RD
40 * @string: attribute string
41 * @dev_attr: underlying device attribute
847ec80b
JC
42 */
43struct iio_const_attr {
44 const char *string;
45 struct device_attribute dev_attr;
46};
47
48#define to_iio_const_attr(_dev_attr) \
49 container_of(_dev_attr, struct iio_const_attr, dev_attr)
50
4c572605 51/* Some attributes will be hard coded (device dependent) and not require an
847ec80b
JC
52 address, in these cases pass a negative */
53#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
54 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
55 .address = _addr }
56
847ec80b
JC
57#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
58 struct iio_dev_attr iio_dev_attr_##_name \
59 = IIO_ATTR(_name, _mode, _show, _store, _addr)
60
ad313b10
JC
61#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
62 struct iio_dev_attr iio_dev_attr_##_vname \
63 = IIO_ATTR(_name, _mode, _show, _store, _addr)
847ec80b 64
847ec80b
JC
65#define IIO_CONST_ATTR(_name, _string) \
66 struct iio_const_attr iio_const_attr_##_name \
67 = { .string = _string, \
68 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
69
fc5d0e42
JC
70#define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
71 struct iio_const_attr iio_const_attr_##_vname \
72 = { .string = _string, \
73 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
4c572605 74
355e25c1 75/* Generic attributes of onetype or another */
4f0cd86d
BS
76/**
77 * IIO_DEV_ATTR_RESET: resets the device
78 **/
79#define IIO_DEV_ATTR_RESET(_store) \
983bbfd0 80 IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0)
4f0cd86d 81
847ec80b 82/**
4c572605
RD
83 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
84 * @_mode: sysfs file mode/permissions
85 * @_show: output method for the attribute
86 * @_store: input method for the attribute
847ec80b
JC
87 **/
88#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
89 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
90
91/**
355e25c1 92 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
4c572605 93 * @_show: output method for the attribute
847ec80b 94 *
4c572605 95 * May be mode dependent on some devices
847ec80b 96 **/
ff7723e2
JC
97#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
98 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
847ec80b 99/**
4c572605
RD
100 * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
101 * @_string: frequency string for the attribute
847ec80b
JC
102 *
103 * Constant version
104 **/
ff7723e2
JC
105#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
106 IIO_CONST_ATTR(sampling_frequency_available, _string)
107
ff7723e2
JC
108#define IIO_DEV_ATTR_TEMP_RAW(_show) \
109 IIO_DEVICE_ATTR(temp_raw, S_IRUGO, _show, NULL, 0)
110
51a0a5b0
MS
111#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
112 IIO_CONST_ATTR(temp_offset, _string)
113
114#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
115 IIO_CONST_ATTR(temp_scale, _string)
116
f4704d77
JC
117#define IIO_EV_TYPE_THRESH 0
118#define IIO_EV_TYPE_MAG 1
119#define IIO_EV_TYPE_ROC 2
120
121#define IIO_EV_DIR_EITHER 0
122#define IIO_EV_DIR_RISING 1
123#define IIO_EV_DIR_FALLING 2
124
1d892719
JC
125#define IIO_EV_TYPE_MAX 8
126#define IIO_EV_BIT(type, direction) \
127 (1 << (type*IIO_EV_TYPE_MAX + direction))
128
f4704d77
JC
129#define IIO_EVENT_CODE(channelclass, orient_bit, number, \
130 modifier, type, direction) \
131 (channelclass | (orient_bit << 8) | ((number) << 9) | \
132 ((modifier) << 13) | ((type) << 16) | ((direction) << 24))
133
134#define IIO_MOD_EVENT_CODE(channelclass, number, modifier, \
135 type, direction) \
136 IIO_EVENT_CODE(channelclass, 1, number, modifier, type, direction)
137
138#define IIO_UNMOD_EVENT_CODE(channelclass, number, type, direction) \
139 IIO_EVENT_CODE(channelclass, 0, number, 0, type, direction)
140
1d892719
JC
141#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 24) & 0xf)
142
143/* Event code number extraction depends on which type of event we have.
144 * Perhaps review this function in the future*/
145#define IIO_EVENT_CODE_EXTRACT_NUM(mask) ((mask >> 9) & 0x0f)
146
147#define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 13) & 0x7)
148
847ec80b 149#endif /* _INDUSTRIAL_IO_SYSFS_H_ */