at v5.2 4.7 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* The industrial I/O core 3 * 4 *Copyright (c) 2008 Jonathan Cameron 5 * 6 * General attributes 7 */ 8 9#ifndef _INDUSTRIAL_IO_SYSFS_H_ 10#define _INDUSTRIAL_IO_SYSFS_H_ 11 12struct iio_chan_spec; 13 14/** 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 20 */ 21struct iio_dev_attr { 22 struct device_attribute dev_attr; 23 u64 address; 24 struct list_head l; 25 struct iio_chan_spec const *c; 26}; 27 28#define to_iio_dev_attr(_dev_attr) \ 29 container_of(_dev_attr, struct iio_dev_attr, dev_attr) 30 31ssize_t iio_read_const_attr(struct device *dev, 32 struct device_attribute *attr, 33 char *len); 34 35/** 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 40 */ 41struct iio_const_attr { 42 const char *string; 43 struct device_attribute dev_attr; 44}; 45 46#define to_iio_const_attr(_dev_attr) \ 47 container_of(_dev_attr, struct iio_const_attr, dev_attr) 48 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), \ 53 .address = _addr } 54 55#define IIO_ATTR_RO(_name, _addr) \ 56 { .dev_attr = __ATTR_RO(_name), \ 57 .address = _addr } 58 59#define IIO_ATTR_WO(_name, _addr) \ 60 { .dev_attr = __ATTR_WO(_name), \ 61 .address = _addr } 62 63#define IIO_ATTR_RW(_name, _addr) \ 64 { .dev_attr = __ATTR_RW(_name), \ 65 .address = _addr } 66 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) 70 71#define IIO_DEVICE_ATTR_RO(_name, _addr) \ 72 struct iio_dev_attr iio_dev_attr_##_name \ 73 = IIO_ATTR_RO(_name, _addr) 74 75#define IIO_DEVICE_ATTR_WO(_name, _addr) \ 76 struct iio_dev_attr iio_dev_attr_##_name \ 77 = IIO_ATTR_WO(_name, _addr) 78 79#define IIO_DEVICE_ATTR_RW(_name, _addr) \ 80 struct iio_dev_attr iio_dev_attr_##_name \ 81 = IIO_ATTR_RW(_name, _addr) 82 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) 86 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)} 91 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)} 96 97/* Generic attributes of onetype or another */ 98 99/** 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 104 **/ 105#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \ 106 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0) 107 108/** 109 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies 110 * @_show: output method for the attribute 111 * 112 * May be mode dependent on some devices 113 **/ 114#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \ 115 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0) 116/** 117 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies 118 * @_string: frequency string for the attribute 119 * 120 * Constant version 121 **/ 122#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ 123 IIO_CONST_ATTR(sampling_frequency_available, _string) 124 125/** 126 * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times 127 * @_show: output method for the attribute 128 **/ 129#define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \ 130 IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0) 131/** 132 * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times 133 * @_string: frequency string for the attribute 134 * 135 * Constant version 136 **/ 137#define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \ 138 IIO_CONST_ATTR(integration_time_available, _string) 139 140#define IIO_DEV_ATTR_TEMP_RAW(_show) \ 141 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) 142 143#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \ 144 IIO_CONST_ATTR(in_temp_offset, _string) 145 146#define IIO_CONST_ATTR_TEMP_SCALE(_string) \ 147 IIO_CONST_ATTR(in_temp_scale, _string) 148 149#endif /* _INDUSTRIAL_IO_SYSFS_H_ */