Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
847ec80b JC |
2 | /* The industrial I/O core |
3 | * | |
4 | *Copyright (c) 2008 Jonathan Cameron | |
5 | * | |
847ec80b JC |
6 | * General attributes |
7 | */ | |
8 | ||
9 | #ifndef _INDUSTRIAL_IO_SYSFS_H_ | |
10 | #define _INDUSTRIAL_IO_SYSFS_H_ | |
11 | ||
3e3d11b2 | 12 | struct iio_buffer; |
4bfd5421 | 13 | struct iio_chan_spec; |
847ec80b | 14 | |
847ec80b JC |
15 | /** |
16 | * struct iio_dev_attr - iio specific device attribute | |
17 | * @dev_attr: underlying device attribute | |
18 | * @address: associated register address | |
2854c098 CO |
19 | * @l: list head for maintaining list of dynamically created attrs |
20 | * @c: specification for the underlying channel | |
3e3d11b2 | 21 | * @buffer: the IIO buffer to which this attribute belongs to (if any) |
847ec80b JC |
22 | */ |
23 | struct iio_dev_attr { | |
24 | struct device_attribute dev_attr; | |
e614a54b | 25 | u64 address; |
1d892719 JC |
26 | struct list_head l; |
27 | struct iio_chan_spec const *c; | |
3e3d11b2 | 28 | struct iio_buffer *buffer; |
847ec80b JC |
29 | }; |
30 | ||
31 | #define to_iio_dev_attr(_dev_attr) \ | |
32 | container_of(_dev_attr, struct iio_dev_attr, dev_attr) | |
33 | ||
34 | ssize_t iio_read_const_attr(struct device *dev, | |
35 | struct device_attribute *attr, | |
36 | char *len); | |
37 | ||
38 | /** | |
39 | * struct iio_const_attr - constant device specific attribute | |
40 | * often used for things like available modes | |
4c572605 RD |
41 | * @string: attribute string |
42 | * @dev_attr: underlying device attribute | |
847ec80b JC |
43 | */ |
44 | struct iio_const_attr { | |
45 | const char *string; | |
46 | struct device_attribute dev_attr; | |
47 | }; | |
48 | ||
49 | #define to_iio_const_attr(_dev_attr) \ | |
50 | container_of(_dev_attr, struct iio_const_attr, dev_attr) | |
51 | ||
4c572605 | 52 | /* Some attributes will be hard coded (device dependent) and not require an |
847ec80b JC |
53 | address, in these cases pass a negative */ |
54 | #define IIO_ATTR(_name, _mode, _show, _store, _addr) \ | |
55 | { .dev_attr = __ATTR(_name, _mode, _show, _store), \ | |
56 | .address = _addr } | |
57 | ||
f3b0deea BM |
58 | #define IIO_ATTR_RO(_name, _addr) \ |
59 | { .dev_attr = __ATTR_RO(_name), \ | |
60 | .address = _addr } | |
61 | ||
62 | #define IIO_ATTR_WO(_name, _addr) \ | |
63 | { .dev_attr = __ATTR_WO(_name), \ | |
64 | .address = _addr } | |
65 | ||
66 | #define IIO_ATTR_RW(_name, _addr) \ | |
67 | { .dev_attr = __ATTR_RW(_name), \ | |
68 | .address = _addr } | |
69 | ||
847ec80b JC |
70 | #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \ |
71 | struct iio_dev_attr iio_dev_attr_##_name \ | |
72 | = IIO_ATTR(_name, _mode, _show, _store, _addr) | |
73 | ||
f3b0deea BM |
74 | #define IIO_DEVICE_ATTR_RO(_name, _addr) \ |
75 | struct iio_dev_attr iio_dev_attr_##_name \ | |
76 | = IIO_ATTR_RO(_name, _addr) | |
77 | ||
78 | #define IIO_DEVICE_ATTR_WO(_name, _addr) \ | |
79 | struct iio_dev_attr iio_dev_attr_##_name \ | |
80 | = IIO_ATTR_WO(_name, _addr) | |
81 | ||
82 | #define IIO_DEVICE_ATTR_RW(_name, _addr) \ | |
83 | struct iio_dev_attr iio_dev_attr_##_name \ | |
84 | = IIO_ATTR_RW(_name, _addr) | |
85 | ||
ad313b10 JC |
86 | #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \ |
87 | struct iio_dev_attr iio_dev_attr_##_vname \ | |
88 | = IIO_ATTR(_name, _mode, _show, _store, _addr) | |
847ec80b | 89 | |
847ec80b JC |
90 | #define IIO_CONST_ATTR(_name, _string) \ |
91 | struct iio_const_attr iio_const_attr_##_name \ | |
92 | = { .string = _string, \ | |
93 | .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} | |
94 | ||
fc5d0e42 JC |
95 | #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \ |
96 | struct iio_const_attr iio_const_attr_##_vname \ | |
97 | = { .string = _string, \ | |
98 | .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} | |
4c572605 | 99 | |
2cc64a23 MV |
100 | #define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string) \ |
101 | static ssize_t iio_const_dev_attr_show_##_name( \ | |
102 | struct device *dev, \ | |
103 | struct device_attribute *attr, \ | |
104 | char *buf) \ | |
105 | { \ | |
106 | return sysfs_emit(buf, "%s\n", _string); \ | |
107 | } \ | |
108 | static IIO_DEVICE_ATTR(_name, 0444, \ | |
109 | iio_const_dev_attr_show_##_name, NULL, 0) | |
110 | ||
355e25c1 | 111 | /* Generic attributes of onetype or another */ |
4f0cd86d | 112 | |
847ec80b | 113 | /** |
4c572605 RD |
114 | * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency |
115 | * @_mode: sysfs file mode/permissions | |
116 | * @_show: output method for the attribute | |
117 | * @_store: input method for the attribute | |
847ec80b JC |
118 | **/ |
119 | #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \ | |
120 | IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0) | |
121 | ||
122 | /** | |
355e25c1 | 123 | * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies |
4c572605 | 124 | * @_show: output method for the attribute |
847ec80b | 125 | * |
4c572605 | 126 | * May be mode dependent on some devices |
847ec80b | 127 | **/ |
ff7723e2 JC |
128 | #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \ |
129 | IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0) | |
847ec80b | 130 | /** |
b90406f1 | 131 | * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies |
4c572605 | 132 | * @_string: frequency string for the attribute |
847ec80b JC |
133 | * |
134 | * Constant version | |
135 | **/ | |
ff7723e2 JC |
136 | #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ |
137 | IIO_CONST_ATTR(sampling_frequency_available, _string) | |
138 | ||
899d90bd PM |
139 | /** |
140 | * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times | |
141 | * @_show: output method for the attribute | |
142 | **/ | |
143 | #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \ | |
144 | IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0) | |
145 | /** | |
146 | * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times | |
147 | * @_string: frequency string for the attribute | |
148 | * | |
149 | * Constant version | |
150 | **/ | |
151 | #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \ | |
152 | IIO_CONST_ATTR(integration_time_available, _string) | |
153 | ||
ff7723e2 | 154 | #define IIO_DEV_ATTR_TEMP_RAW(_show) \ |
322c9563 | 155 | IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) |
ff7723e2 | 156 | |
51a0a5b0 | 157 | #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \ |
322c9563 | 158 | IIO_CONST_ATTR(in_temp_offset, _string) |
51a0a5b0 MS |
159 | |
160 | #define IIO_CONST_ATTR_TEMP_SCALE(_string) \ | |
322c9563 | 161 | IIO_CONST_ATTR(in_temp_scale, _string) |
51a0a5b0 | 162 | |
847ec80b | 163 | #endif /* _INDUSTRIAL_IO_SYSFS_H_ */ |