Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /* The industrial I/O core
0003  *
0004  *Copyright (c) 2008 Jonathan Cameron
0005  *
0006  * General attributes
0007  */
0008 
0009 #ifndef _INDUSTRIAL_IO_SYSFS_H_
0010 #define _INDUSTRIAL_IO_SYSFS_H_
0011 
0012 struct iio_buffer;
0013 struct iio_chan_spec;
0014 
0015 /**
0016  * struct iio_dev_attr - iio specific device attribute
0017  * @dev_attr:   underlying device attribute
0018  * @address:    associated register address
0019  * @l:      list head for maintaining list of dynamically created attrs
0020  * @c:      specification for the underlying channel
0021  * @buffer: the IIO buffer to which this attribute belongs to (if any)
0022  */
0023 struct iio_dev_attr {
0024     struct device_attribute dev_attr;
0025     u64 address;
0026     struct list_head l;
0027     struct iio_chan_spec const *c;
0028     struct iio_buffer *buffer;
0029 };
0030 
0031 #define to_iio_dev_attr(_dev_attr)              \
0032     container_of(_dev_attr, struct iio_dev_attr, dev_attr)
0033 
0034 ssize_t iio_read_const_attr(struct device *dev,
0035                 struct device_attribute *attr,
0036                 char *len);
0037 
0038 /**
0039  * struct iio_const_attr - constant device specific attribute
0040  *                         often used for things like available modes
0041  * @string: attribute string
0042  * @dev_attr:   underlying device attribute
0043  */
0044 struct iio_const_attr {
0045     const char *string;
0046     struct device_attribute dev_attr;
0047 };
0048 
0049 #define to_iio_const_attr(_dev_attr) \
0050     container_of(_dev_attr, struct iio_const_attr, dev_attr)
0051 
0052 /* Some attributes will be hard coded (device dependent) and not require an
0053    address, in these cases pass a negative */
0054 #define IIO_ATTR(_name, _mode, _show, _store, _addr)        \
0055     { .dev_attr = __ATTR(_name, _mode, _show, _store),  \
0056       .address = _addr }
0057 
0058 #define IIO_ATTR_RO(_name, _addr)       \
0059     { .dev_attr = __ATTR_RO(_name), \
0060       .address = _addr }
0061 
0062 #define IIO_ATTR_WO(_name, _addr)       \
0063     { .dev_attr = __ATTR_WO(_name), \
0064       .address = _addr }
0065 
0066 #define IIO_ATTR_RW(_name, _addr)       \
0067     { .dev_attr = __ATTR_RW(_name), \
0068       .address = _addr }
0069 
0070 #define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
0071     struct iio_dev_attr iio_dev_attr_##_name        \
0072     = IIO_ATTR(_name, _mode, _show, _store, _addr)
0073 
0074 #define IIO_DEVICE_ATTR_RO(_name, _addr)                       \
0075     struct iio_dev_attr iio_dev_attr_##_name                \
0076     = IIO_ATTR_RO(_name, _addr)
0077 
0078 #define IIO_DEVICE_ATTR_WO(_name, _addr)                       \
0079     struct iio_dev_attr iio_dev_attr_##_name                \
0080     = IIO_ATTR_WO(_name, _addr)
0081 
0082 #define IIO_DEVICE_ATTR_RW(_name, _addr)                                   \
0083     struct iio_dev_attr iio_dev_attr_##_name                            \
0084     = IIO_ATTR_RW(_name, _addr)
0085 
0086 #define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
0087     struct iio_dev_attr iio_dev_attr_##_vname           \
0088     = IIO_ATTR(_name, _mode, _show, _store, _addr)
0089 
0090 #define IIO_CONST_ATTR(_name, _string)                  \
0091     struct iio_const_attr iio_const_attr_##_name            \
0092     = { .string = _string,                      \
0093         .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
0094 
0095 #define IIO_CONST_ATTR_NAMED(_vname, _name, _string)            \
0096     struct iio_const_attr iio_const_attr_##_vname           \
0097     = { .string = _string,                      \
0098         .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
0099 
0100 /* Generic attributes of onetype or another */
0101 
0102 /**
0103  * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
0104  * @_mode: sysfs file mode/permissions
0105  * @_show: output method for the attribute
0106  * @_store: input method for the attribute
0107  **/
0108 #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store)            \
0109     IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
0110 
0111 /**
0112  * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
0113  * @_show: output method for the attribute
0114  *
0115  * May be mode dependent on some devices
0116  **/
0117 #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show)             \
0118     IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
0119 /**
0120  * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
0121  * @_string: frequency string for the attribute
0122  *
0123  * Constant version
0124  **/
0125 #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string)         \
0126     IIO_CONST_ATTR(sampling_frequency_available, _string)
0127 
0128 /**
0129  * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
0130  * @_show: output method for the attribute
0131  **/
0132 #define IIO_DEV_ATTR_INT_TIME_AVAIL(_show)      \
0133     IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
0134 /**
0135  * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
0136  * @_string: frequency string for the attribute
0137  *
0138  * Constant version
0139  **/
0140 #define IIO_CONST_ATTR_INT_TIME_AVAIL(_string)      \
0141     IIO_CONST_ATTR(integration_time_available, _string)
0142 
0143 #define IIO_DEV_ATTR_TEMP_RAW(_show)            \
0144     IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
0145 
0146 #define IIO_CONST_ATTR_TEMP_OFFSET(_string)     \
0147     IIO_CONST_ATTR(in_temp_offset, _string)
0148 
0149 #define IIO_CONST_ATTR_TEMP_SCALE(_string)      \
0150     IIO_CONST_ATTR(in_temp_scale, _string)
0151 
0152 #endif /* _INDUSTRIAL_IO_SYSFS_H_ */