1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 206458e27SJonathan Cameron /* The industrial I/O core 306458e27SJonathan Cameron * 406458e27SJonathan Cameron *Copyright (c) 2008 Jonathan Cameron 506458e27SJonathan Cameron * 606458e27SJonathan Cameron * General attributes 706458e27SJonathan Cameron */ 806458e27SJonathan Cameron 906458e27SJonathan Cameron #ifndef _INDUSTRIAL_IO_SYSFS_H_ 1006458e27SJonathan Cameron #define _INDUSTRIAL_IO_SYSFS_H_ 1106458e27SJonathan Cameron 123e3d11b2SAlexandru Ardelean struct iio_buffer; 1306458e27SJonathan Cameron struct iio_chan_spec; 1406458e27SJonathan Cameron 1506458e27SJonathan Cameron /** 1606458e27SJonathan Cameron * struct iio_dev_attr - iio specific device attribute 1706458e27SJonathan Cameron * @dev_attr: underlying device attribute 1806458e27SJonathan Cameron * @address: associated register address 192854c098SCristina Opriceana * @l: list head for maintaining list of dynamically created attrs 202854c098SCristina Opriceana * @c: specification for the underlying channel 213e3d11b2SAlexandru Ardelean * @buffer: the IIO buffer to which this attribute belongs to (if any) 2206458e27SJonathan Cameron */ 2306458e27SJonathan Cameron struct iio_dev_attr { 2406458e27SJonathan Cameron struct device_attribute dev_attr; 2506458e27SJonathan Cameron u64 address; 2606458e27SJonathan Cameron struct list_head l; 2706458e27SJonathan Cameron struct iio_chan_spec const *c; 283e3d11b2SAlexandru Ardelean struct iio_buffer *buffer; 2906458e27SJonathan Cameron }; 3006458e27SJonathan Cameron 3106458e27SJonathan Cameron #define to_iio_dev_attr(_dev_attr) \ 3206458e27SJonathan Cameron container_of(_dev_attr, struct iio_dev_attr, dev_attr) 3306458e27SJonathan Cameron 3406458e27SJonathan Cameron ssize_t iio_read_const_attr(struct device *dev, 3506458e27SJonathan Cameron struct device_attribute *attr, 3606458e27SJonathan Cameron char *len); 3706458e27SJonathan Cameron 3806458e27SJonathan Cameron /** 3906458e27SJonathan Cameron * struct iio_const_attr - constant device specific attribute 4006458e27SJonathan Cameron * often used for things like available modes 4106458e27SJonathan Cameron * @string: attribute string 4206458e27SJonathan Cameron * @dev_attr: underlying device attribute 4306458e27SJonathan Cameron */ 4406458e27SJonathan Cameron struct iio_const_attr { 4506458e27SJonathan Cameron const char *string; 4606458e27SJonathan Cameron struct device_attribute dev_attr; 4706458e27SJonathan Cameron }; 4806458e27SJonathan Cameron 4906458e27SJonathan Cameron #define to_iio_const_attr(_dev_attr) \ 5006458e27SJonathan Cameron container_of(_dev_attr, struct iio_const_attr, dev_attr) 5106458e27SJonathan Cameron 5206458e27SJonathan Cameron /* Some attributes will be hard coded (device dependent) and not require an 5306458e27SJonathan Cameron address, in these cases pass a negative */ 5406458e27SJonathan Cameron #define IIO_ATTR(_name, _mode, _show, _store, _addr) \ 5506458e27SJonathan Cameron { .dev_attr = __ATTR(_name, _mode, _show, _store), \ 5606458e27SJonathan Cameron .address = _addr } 5706458e27SJonathan Cameron 58f3b0deeaSBrian Masney #define IIO_ATTR_RO(_name, _addr) \ 59f3b0deeaSBrian Masney { .dev_attr = __ATTR_RO(_name), \ 60f3b0deeaSBrian Masney .address = _addr } 61f3b0deeaSBrian Masney 62f3b0deeaSBrian Masney #define IIO_ATTR_WO(_name, _addr) \ 63f3b0deeaSBrian Masney { .dev_attr = __ATTR_WO(_name), \ 64f3b0deeaSBrian Masney .address = _addr } 65f3b0deeaSBrian Masney 66f3b0deeaSBrian Masney #define IIO_ATTR_RW(_name, _addr) \ 67f3b0deeaSBrian Masney { .dev_attr = __ATTR_RW(_name), \ 68f3b0deeaSBrian Masney .address = _addr } 69f3b0deeaSBrian Masney 7006458e27SJonathan Cameron #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \ 7106458e27SJonathan Cameron struct iio_dev_attr iio_dev_attr_##_name \ 7206458e27SJonathan Cameron = IIO_ATTR(_name, _mode, _show, _store, _addr) 7306458e27SJonathan Cameron 74f3b0deeaSBrian Masney #define IIO_DEVICE_ATTR_RO(_name, _addr) \ 75f3b0deeaSBrian Masney struct iio_dev_attr iio_dev_attr_##_name \ 76f3b0deeaSBrian Masney = IIO_ATTR_RO(_name, _addr) 77f3b0deeaSBrian Masney 78f3b0deeaSBrian Masney #define IIO_DEVICE_ATTR_WO(_name, _addr) \ 79f3b0deeaSBrian Masney struct iio_dev_attr iio_dev_attr_##_name \ 80f3b0deeaSBrian Masney = IIO_ATTR_WO(_name, _addr) 81f3b0deeaSBrian Masney 82f3b0deeaSBrian Masney #define IIO_DEVICE_ATTR_RW(_name, _addr) \ 83f3b0deeaSBrian Masney struct iio_dev_attr iio_dev_attr_##_name \ 84f3b0deeaSBrian Masney = IIO_ATTR_RW(_name, _addr) 85f3b0deeaSBrian Masney 8606458e27SJonathan Cameron #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \ 8706458e27SJonathan Cameron struct iio_dev_attr iio_dev_attr_##_vname \ 8806458e27SJonathan Cameron = IIO_ATTR(_name, _mode, _show, _store, _addr) 8906458e27SJonathan Cameron 9006458e27SJonathan Cameron #define IIO_CONST_ATTR(_name, _string) \ 9106458e27SJonathan Cameron struct iio_const_attr iio_const_attr_##_name \ 9206458e27SJonathan Cameron = { .string = _string, \ 9306458e27SJonathan Cameron .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} 9406458e27SJonathan Cameron 9506458e27SJonathan Cameron #define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \ 9606458e27SJonathan Cameron struct iio_const_attr iio_const_attr_##_vname \ 9706458e27SJonathan Cameron = { .string = _string, \ 9806458e27SJonathan Cameron .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)} 9906458e27SJonathan Cameron 100*2cc64a23SMatti Vaittinen #define IIO_STATIC_CONST_DEVICE_ATTR(_name, _string) \ 101*2cc64a23SMatti Vaittinen static ssize_t iio_const_dev_attr_show_##_name( \ 102*2cc64a23SMatti Vaittinen struct device *dev, \ 103*2cc64a23SMatti Vaittinen struct device_attribute *attr, \ 104*2cc64a23SMatti Vaittinen char *buf) \ 105*2cc64a23SMatti Vaittinen { \ 106*2cc64a23SMatti Vaittinen return sysfs_emit(buf, "%s\n", _string); \ 107*2cc64a23SMatti Vaittinen } \ 108*2cc64a23SMatti Vaittinen static IIO_DEVICE_ATTR(_name, 0444, \ 109*2cc64a23SMatti Vaittinen iio_const_dev_attr_show_##_name, NULL, 0) 110*2cc64a23SMatti Vaittinen 11106458e27SJonathan Cameron /* Generic attributes of onetype or another */ 11206458e27SJonathan Cameron 11306458e27SJonathan Cameron /** 11406458e27SJonathan Cameron * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency 11506458e27SJonathan Cameron * @_mode: sysfs file mode/permissions 11606458e27SJonathan Cameron * @_show: output method for the attribute 11706458e27SJonathan Cameron * @_store: input method for the attribute 11806458e27SJonathan Cameron **/ 11906458e27SJonathan Cameron #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \ 12006458e27SJonathan Cameron IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0) 12106458e27SJonathan Cameron 12206458e27SJonathan Cameron /** 12306458e27SJonathan Cameron * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies 12406458e27SJonathan Cameron * @_show: output method for the attribute 12506458e27SJonathan Cameron * 12606458e27SJonathan Cameron * May be mode dependent on some devices 12706458e27SJonathan Cameron **/ 12806458e27SJonathan Cameron #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \ 12906458e27SJonathan Cameron IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0) 13006458e27SJonathan Cameron /** 131b90406f1SPeter Meerwald * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies 13206458e27SJonathan Cameron * @_string: frequency string for the attribute 13306458e27SJonathan Cameron * 13406458e27SJonathan Cameron * Constant version 13506458e27SJonathan Cameron **/ 13606458e27SJonathan Cameron #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ 13706458e27SJonathan Cameron IIO_CONST_ATTR(sampling_frequency_available, _string) 13806458e27SJonathan Cameron 139899d90bdSPeter Meerwald /** 140899d90bdSPeter Meerwald * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times 141899d90bdSPeter Meerwald * @_show: output method for the attribute 142899d90bdSPeter Meerwald **/ 143899d90bdSPeter Meerwald #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \ 144899d90bdSPeter Meerwald IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0) 145899d90bdSPeter Meerwald /** 146899d90bdSPeter Meerwald * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times 147899d90bdSPeter Meerwald * @_string: frequency string for the attribute 148899d90bdSPeter Meerwald * 149899d90bdSPeter Meerwald * Constant version 150899d90bdSPeter Meerwald **/ 151899d90bdSPeter Meerwald #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \ 152899d90bdSPeter Meerwald IIO_CONST_ATTR(integration_time_available, _string) 153899d90bdSPeter Meerwald 15406458e27SJonathan Cameron #define IIO_DEV_ATTR_TEMP_RAW(_show) \ 15506458e27SJonathan Cameron IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) 15606458e27SJonathan Cameron 15706458e27SJonathan Cameron #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \ 15806458e27SJonathan Cameron IIO_CONST_ATTR(in_temp_offset, _string) 15906458e27SJonathan Cameron 16006458e27SJonathan Cameron #define IIO_CONST_ATTR_TEMP_SCALE(_string) \ 16106458e27SJonathan Cameron IIO_CONST_ATTR(in_temp_scale, _string) 16206458e27SJonathan Cameron 16306458e27SJonathan Cameron #endif /* _INDUSTRIAL_IO_SYSFS_H_ */ 164