Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 2 | /* The industrial I/O core |
| 3 | * |
| 4 | *Copyright (c) 2008 Jonathan Cameron |
| 5 | * |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 6 | * General attributes |
| 7 | */ |
| 8 | |
| 9 | #ifndef _INDUSTRIAL_IO_SYSFS_H_ |
| 10 | #define _INDUSTRIAL_IO_SYSFS_H_ |
| 11 | |
Jonathan Cameron | 4bfd542 | 2011-08-12 17:56:05 +0100 | [diff] [blame] | 12 | struct iio_chan_spec; |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 13 | |
| 14 | /** |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 15 | * struct iio_dev_attr - iio specific device attribute |
| 16 | * @dev_attr: underlying device attribute |
| 17 | * @address: associated register address |
Cristina Opriceana | 2854c09 | 2015-07-24 16:26:09 +0300 | [diff] [blame] | 18 | * @l: list head for maintaining list of dynamically created attrs |
| 19 | * @c: specification for the underlying channel |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 20 | */ |
| 21 | struct iio_dev_attr { |
| 22 | struct device_attribute dev_attr; |
Jonathan Cameron | e614a54 | 2011-09-02 17:14:41 +0100 | [diff] [blame] | 23 | u64 address; |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 24 | struct list_head l; |
| 25 | struct iio_chan_spec const *c; |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | #define to_iio_dev_attr(_dev_attr) \ |
| 29 | container_of(_dev_attr, struct iio_dev_attr, dev_attr) |
| 30 | |
| 31 | ssize_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 |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 38 | * @string: attribute string |
| 39 | * @dev_attr: underlying device attribute |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 40 | */ |
| 41 | struct 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 | |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 49 | /* Some attributes will be hard coded (device dependent) and not require an |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 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 | |
Brian Masney | f3b0dee | 2016-09-26 20:20:16 -0400 | [diff] [blame] | 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 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 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 | |
Brian Masney | f3b0dee | 2016-09-26 20:20:16 -0400 | [diff] [blame] | 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 | |
Jonathan Cameron | ad313b1 | 2010-05-04 14:42:56 +0100 | [diff] [blame] | 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) |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 86 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 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 | |
Jonathan Cameron | fc5d0e4 | 2010-10-08 12:14:08 +0100 | [diff] [blame] | 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)} |
Jonathan Cameron | 355e25c | 2011-08-12 17:08:51 +0100 | [diff] [blame] | 96 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 97 | /* Generic attributes of onetype or another */ |
Barry Song | 4f0cd86 | 2010-10-27 21:44:03 -0400 | [diff] [blame] | 98 | |
| 99 | /** |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 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 |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 104 | **/ |
| 105 | #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \ |
| 106 | IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0) |
| 107 | |
| 108 | /** |
Jonathan Cameron | 355e25c | 2011-08-12 17:08:51 +0100 | [diff] [blame] | 109 | * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 110 | * @_show: output method for the attribute |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 111 | * |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 112 | * May be mode dependent on some devices |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 113 | **/ |
Jonathan Cameron | ff7723e | 2010-05-04 14:42:57 +0100 | [diff] [blame] | 114 | #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \ |
| 115 | IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0) |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 116 | /** |
Peter Meerwald | b90406f | 2012-06-18 20:33:02 +0200 | [diff] [blame] | 117 | * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 118 | * @_string: frequency string for the attribute |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 119 | * |
| 120 | * Constant version |
| 121 | **/ |
Jonathan Cameron | ff7723e | 2010-05-04 14:42:57 +0100 | [diff] [blame] | 122 | #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ |
| 123 | IIO_CONST_ATTR(sampling_frequency_available, _string) |
| 124 | |
Peter Meerwald | 899d90b | 2013-09-08 16:20:00 +0100 | [diff] [blame] | 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 | |
Jonathan Cameron | ff7723e | 2010-05-04 14:42:57 +0100 | [diff] [blame] | 140 | #define IIO_DEV_ATTR_TEMP_RAW(_show) \ |
Jonathan Cameron | 322c956 | 2011-09-14 13:01:23 +0100 | [diff] [blame] | 141 | IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) |
Jonathan Cameron | ff7723e | 2010-05-04 14:42:57 +0100 | [diff] [blame] | 142 | |
Manuel Stahl | 51a0a5b | 2010-08-31 11:32:54 +0200 | [diff] [blame] | 143 | #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \ |
Jonathan Cameron | 322c956 | 2011-09-14 13:01:23 +0100 | [diff] [blame] | 144 | IIO_CONST_ATTR(in_temp_offset, _string) |
Manuel Stahl | 51a0a5b | 2010-08-31 11:32:54 +0200 | [diff] [blame] | 145 | |
| 146 | #define IIO_CONST_ATTR_TEMP_SCALE(_string) \ |
Jonathan Cameron | 322c956 | 2011-09-14 13:01:23 +0100 | [diff] [blame] | 147 | IIO_CONST_ATTR(in_temp_scale, _string) |
Manuel Stahl | 51a0a5b | 2010-08-31 11:32:54 +0200 | [diff] [blame] | 148 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 149 | #endif /* _INDUSTRIAL_IO_SYSFS_H_ */ |