1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /* The industrial I/O core
4 *Copyright (c) 2008 Jonathan Cameron
9 #ifndef _INDUSTRIAL_IO_SYSFS_H_
10 #define _INDUSTRIAL_IO_SYSFS_H_
15 * struct iio_dev_attr - iio specific device attribute
16 * @dev_attr: underlying device attribute
17 * @address: associated register address
18 * @l: list head for maintaining list of dynamically created attrs
19 * @c: specification for the underlying channel
22 struct device_attribute dev_attr
;
25 struct iio_chan_spec
const *c
;
28 #define to_iio_dev_attr(_dev_attr) \
29 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
31 ssize_t
iio_read_const_attr(struct device
*dev
,
32 struct device_attribute
*attr
,
36 * struct iio_const_attr - constant device specific attribute
37 * often used for things like available modes
38 * @string: attribute string
39 * @dev_attr: underlying device attribute
41 struct iio_const_attr
{
43 struct device_attribute dev_attr
;
46 #define to_iio_const_attr(_dev_attr) \
47 container_of(_dev_attr, struct iio_const_attr, dev_attr)
49 /* Some attributes will be hard coded (device dependent) and not require an
50 address, in these cases pass a negative */
51 #define IIO_ATTR(_name, _mode, _show, _store, _addr) \
52 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
55 #define IIO_ATTR_RO(_name, _addr) \
56 { .dev_attr = __ATTR_RO(_name), \
59 #define IIO_ATTR_WO(_name, _addr) \
60 { .dev_attr = __ATTR_WO(_name), \
63 #define IIO_ATTR_RW(_name, _addr) \
64 { .dev_attr = __ATTR_RW(_name), \
67 #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
68 struct iio_dev_attr iio_dev_attr_##_name \
69 = IIO_ATTR(_name, _mode, _show, _store, _addr)
71 #define IIO_DEVICE_ATTR_RO(_name, _addr) \
72 struct iio_dev_attr iio_dev_attr_##_name \
73 = IIO_ATTR_RO(_name, _addr)
75 #define IIO_DEVICE_ATTR_WO(_name, _addr) \
76 struct iio_dev_attr iio_dev_attr_##_name \
77 = IIO_ATTR_WO(_name, _addr)
79 #define IIO_DEVICE_ATTR_RW(_name, _addr) \
80 struct iio_dev_attr iio_dev_attr_##_name \
81 = IIO_ATTR_RW(_name, _addr)
83 #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
84 struct iio_dev_attr iio_dev_attr_##_vname \
85 = IIO_ATTR(_name, _mode, _show, _store, _addr)
87 #define IIO_CONST_ATTR(_name, _string) \
88 struct iio_const_attr iio_const_attr_##_name \
89 = { .string = _string, \
90 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
92 #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
93 struct iio_const_attr iio_const_attr_##_vname \
94 = { .string = _string, \
95 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
97 /* Generic attributes of onetype or another */
100 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
101 * @_mode: sysfs file mode/permissions
102 * @_show: output method for the attribute
103 * @_store: input method for the attribute
105 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
106 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
109 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
110 * @_show: output method for the attribute
112 * May be mode dependent on some devices
114 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
115 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
117 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
118 * @_string: frequency string for the attribute
122 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
123 IIO_CONST_ATTR(sampling_frequency_available, _string)
126 * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
127 * @_show: output method for the attribute
129 #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \
130 IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
132 * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
133 * @_string: frequency string for the attribute
137 #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \
138 IIO_CONST_ATTR(integration_time_available, _string)
140 #define IIO_DEV_ATTR_TEMP_RAW(_show) \
141 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
143 #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
144 IIO_CONST_ATTR(in_temp_offset, _string)
146 #define IIO_CONST_ATTR_TEMP_SCALE(_string) \
147 IIO_CONST_ATTR(in_temp_scale, _string)
149 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */