2019-06-04 16:11:33 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2009-08-19 01:06:19 +08:00
|
|
|
/* The industrial I/O core
|
|
|
|
*
|
|
|
|
*Copyright (c) 2008 Jonathan Cameron
|
|
|
|
*
|
|
|
|
* General attributes
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _INDUSTRIAL_IO_SYSFS_H_
|
|
|
|
#define _INDUSTRIAL_IO_SYSFS_H_
|
|
|
|
|
2021-02-15 18:40:32 +08:00
|
|
|
struct iio_buffer;
|
2011-08-13 00:56:05 +08:00
|
|
|
struct iio_chan_spec;
|
2009-08-19 01:06:19 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct iio_dev_attr - iio specific device attribute
|
|
|
|
* @dev_attr: underlying device attribute
|
|
|
|
* @address: associated register address
|
2015-07-24 21:26:09 +08:00
|
|
|
* @l: list head for maintaining list of dynamically created attrs
|
|
|
|
* @c: specification for the underlying channel
|
2021-02-15 18:40:32 +08:00
|
|
|
* @buffer: the IIO buffer to which this attribute belongs to (if any)
|
2009-08-19 01:06:19 +08:00
|
|
|
*/
|
|
|
|
struct iio_dev_attr {
|
|
|
|
struct device_attribute dev_attr;
|
2011-09-03 00:14:41 +08:00
|
|
|
u64 address;
|
2011-05-18 21:40:51 +08:00
|
|
|
struct list_head l;
|
|
|
|
struct iio_chan_spec const *c;
|
2021-02-15 18:40:32 +08:00
|
|
|
struct iio_buffer *buffer;
|
2009-08-19 01:06:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define to_iio_dev_attr(_dev_attr) \
|
|
|
|
container_of(_dev_attr, struct iio_dev_attr, dev_attr)
|
|
|
|
|
|
|
|
ssize_t iio_read_const_attr(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *len);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct iio_const_attr - constant device specific attribute
|
|
|
|
* often used for things like available modes
|
2009-10-05 10:34:02 +08:00
|
|
|
* @string: attribute string
|
|
|
|
* @dev_attr: underlying device attribute
|
2009-08-19 01:06:19 +08:00
|
|
|
*/
|
|
|
|
struct iio_const_attr {
|
|
|
|
const char *string;
|
|
|
|
struct device_attribute dev_attr;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define to_iio_const_attr(_dev_attr) \
|
|
|
|
container_of(_dev_attr, struct iio_const_attr, dev_attr)
|
|
|
|
|
2009-10-05 10:34:02 +08:00
|
|
|
/* Some attributes will be hard coded (device dependent) and not require an
|
2009-08-19 01:06:19 +08:00
|
|
|
address, in these cases pass a negative */
|
|
|
|
#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
|
|
|
|
{ .dev_attr = __ATTR(_name, _mode, _show, _store), \
|
|
|
|
.address = _addr }
|
|
|
|
|
include: linux: iio: add IIO_ATTR_{RO, WO, RW} and IIO_DEVICE_ATTR_{RO, WO, RW} macros
Add new macros: IIO_ATTR_RO, IIO_ATTR_WO, IIO_ATTR_RW,
IIO_DEVICE_ATTR_RO, IIO_DEVICE_ATTR_WO and IIO_DEVICE_ATTR_RW to reduce
the amount of boiler plate code that is needed for creating new
attributes. This mimics the *_RO, *_WO, and *_RW macros that are found
in include/linux/device.h and include/linux/sysfs.h.
Signed-off-by: Brian Masney <masneyb@onstation.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-27 08:20:16 +08:00
|
|
|
#define IIO_ATTR_RO(_name, _addr) \
|
|
|
|
{ .dev_attr = __ATTR_RO(_name), \
|
|
|
|
.address = _addr }
|
|
|
|
|
|
|
|
#define IIO_ATTR_WO(_name, _addr) \
|
|
|
|
{ .dev_attr = __ATTR_WO(_name), \
|
|
|
|
.address = _addr }
|
|
|
|
|
|
|
|
#define IIO_ATTR_RW(_name, _addr) \
|
|
|
|
{ .dev_attr = __ATTR_RW(_name), \
|
|
|
|
.address = _addr }
|
|
|
|
|
2009-08-19 01:06:19 +08:00
|
|
|
#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
|
|
|
|
struct iio_dev_attr iio_dev_attr_##_name \
|
|
|
|
= IIO_ATTR(_name, _mode, _show, _store, _addr)
|
|
|
|
|
include: linux: iio: add IIO_ATTR_{RO, WO, RW} and IIO_DEVICE_ATTR_{RO, WO, RW} macros
Add new macros: IIO_ATTR_RO, IIO_ATTR_WO, IIO_ATTR_RW,
IIO_DEVICE_ATTR_RO, IIO_DEVICE_ATTR_WO and IIO_DEVICE_ATTR_RW to reduce
the amount of boiler plate code that is needed for creating new
attributes. This mimics the *_RO, *_WO, and *_RW macros that are found
in include/linux/device.h and include/linux/sysfs.h.
Signed-off-by: Brian Masney <masneyb@onstation.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-09-27 08:20:16 +08:00
|
|
|
#define IIO_DEVICE_ATTR_RO(_name, _addr) \
|
|
|
|
struct iio_dev_attr iio_dev_attr_##_name \
|
|
|
|
= IIO_ATTR_RO(_name, _addr)
|
|
|
|
|
|
|
|
#define IIO_DEVICE_ATTR_WO(_name, _addr) \
|
|
|
|
struct iio_dev_attr iio_dev_attr_##_name \
|
|
|
|
= IIO_ATTR_WO(_name, _addr)
|
|
|
|
|
|
|
|
#define IIO_DEVICE_ATTR_RW(_name, _addr) \
|
|
|
|
struct iio_dev_attr iio_dev_attr_##_name \
|
|
|
|
= IIO_ATTR_RW(_name, _addr)
|
|
|
|
|
2010-05-04 21:42:56 +08:00
|
|
|
#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
|
|
|
|
struct iio_dev_attr iio_dev_attr_##_vname \
|
|
|
|
= IIO_ATTR(_name, _mode, _show, _store, _addr)
|
2009-08-19 01:06:19 +08:00
|
|
|
|
|
|
|
#define IIO_CONST_ATTR(_name, _string) \
|
|
|
|
struct iio_const_attr iio_const_attr_##_name \
|
|
|
|
= { .string = _string, \
|
|
|
|
.dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
|
|
|
|
|
2010-10-08 19:14:08 +08:00
|
|
|
#define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
|
|
|
|
struct iio_const_attr iio_const_attr_##_vname \
|
|
|
|
= { .string = _string, \
|
|
|
|
.dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
|
2009-10-05 10:34:02 +08:00
|
|
|
|
2011-08-13 00:08:51 +08:00
|
|
|
/* Generic attributes of onetype or another */
|
2010-10-28 09:44:03 +08:00
|
|
|
|
2009-08-19 01:06:19 +08:00
|
|
|
/**
|
2009-10-05 10:34:02 +08:00
|
|
|
* IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
|
|
|
|
* @_mode: sysfs file mode/permissions
|
|
|
|
* @_show: output method for the attribute
|
|
|
|
* @_store: input method for the attribute
|
2009-08-19 01:06:19 +08:00
|
|
|
**/
|
|
|
|
#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
|
|
|
|
IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
|
|
|
|
|
|
|
|
/**
|
2011-08-13 00:08:51 +08:00
|
|
|
* IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
|
2009-10-05 10:34:02 +08:00
|
|
|
* @_show: output method for the attribute
|
2009-08-19 01:06:19 +08:00
|
|
|
*
|
2009-10-05 10:34:02 +08:00
|
|
|
* May be mode dependent on some devices
|
2009-08-19 01:06:19 +08:00
|
|
|
**/
|
2010-05-04 21:42:57 +08:00
|
|
|
#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
|
|
|
|
IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
|
2009-08-19 01:06:19 +08:00
|
|
|
/**
|
2012-06-19 02:33:02 +08:00
|
|
|
* IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
|
2009-10-05 10:34:02 +08:00
|
|
|
* @_string: frequency string for the attribute
|
2009-08-19 01:06:19 +08:00
|
|
|
*
|
|
|
|
* Constant version
|
|
|
|
**/
|
2010-05-04 21:42:57 +08:00
|
|
|
#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
|
|
|
|
IIO_CONST_ATTR(sampling_frequency_available, _string)
|
|
|
|
|
2013-09-08 23:20:00 +08:00
|
|
|
/**
|
|
|
|
* IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
|
|
|
|
* @_show: output method for the attribute
|
|
|
|
**/
|
|
|
|
#define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \
|
|
|
|
IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
|
|
|
|
/**
|
|
|
|
* IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
|
|
|
|
* @_string: frequency string for the attribute
|
|
|
|
*
|
|
|
|
* Constant version
|
|
|
|
**/
|
|
|
|
#define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \
|
|
|
|
IIO_CONST_ATTR(integration_time_available, _string)
|
|
|
|
|
2010-05-04 21:42:57 +08:00
|
|
|
#define IIO_DEV_ATTR_TEMP_RAW(_show) \
|
2011-09-14 20:01:23 +08:00
|
|
|
IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
|
2010-05-04 21:42:57 +08:00
|
|
|
|
2010-08-31 17:32:54 +08:00
|
|
|
#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
|
2011-09-14 20:01:23 +08:00
|
|
|
IIO_CONST_ATTR(in_temp_offset, _string)
|
2010-08-31 17:32:54 +08:00
|
|
|
|
|
|
|
#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
|
2011-09-14 20:01:23 +08:00
|
|
|
IIO_CONST_ATTR(in_temp_scale, _string)
|
2010-08-31 17:32:54 +08:00
|
|
|
|
2009-08-19 01:06:19 +08:00
|
|
|
#endif /* _INDUSTRIAL_IO_SYSFS_H_ */
|