blob: b532c875bc241b0b2dfe890f5d8af6337c0d9b0f [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jonathan Cameron847ec802009-08-18 18:06:19 +01002/* The industrial I/O core
3 *
4 *Copyright (c) 2008 Jonathan Cameron
5 *
Jonathan Cameron847ec802009-08-18 18:06:19 +01006 * General attributes
7 */
8
9#ifndef _INDUSTRIAL_IO_SYSFS_H_
10#define _INDUSTRIAL_IO_SYSFS_H_
11
Jonathan Cameron4bfd5422011-08-12 17:56:05 +010012struct iio_chan_spec;
Jonathan Cameron847ec802009-08-18 18:06:19 +010013
14/**
Jonathan Cameron847ec802009-08-18 18:06:19 +010015 * struct iio_dev_attr - iio specific device attribute
16 * @dev_attr: underlying device attribute
17 * @address: associated register address
Cristina Opriceana2854c092015-07-24 16:26:09 +030018 * @l: list head for maintaining list of dynamically created attrs
19 * @c: specification for the underlying channel
Jonathan Cameron847ec802009-08-18 18:06:19 +010020 */
21struct iio_dev_attr {
22 struct device_attribute dev_attr;
Jonathan Camerone614a542011-09-02 17:14:41 +010023 u64 address;
Jonathan Cameron1d892712011-05-18 14:40:51 +010024 struct list_head l;
25 struct iio_chan_spec const *c;
Jonathan Cameron847ec802009-08-18 18:06:19 +010026};
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
Randy Dunlap4c572602009-10-04 19:34:02 -070038 * @string: attribute string
39 * @dev_attr: underlying device attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +010040 */
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
Randy Dunlap4c572602009-10-04 19:34:02 -070049/* Some attributes will be hard coded (device dependent) and not require an
Jonathan Cameron847ec802009-08-18 18:06:19 +010050 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 Masneyf3b0dee2016-09-26 20:20:16 -040055#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 Cameron847ec802009-08-18 18:06:19 +010067#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 Masneyf3b0dee2016-09-26 20:20:16 -040071#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 Cameronad313b12010-05-04 14:42:56 +010083#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 Cameron847ec802009-08-18 18:06:19 +010086
Jonathan Cameron847ec802009-08-18 18:06:19 +010087#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 Cameronfc5d0e42010-10-08 12:14:08 +010092#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 Cameron355e25c2011-08-12 17:08:51 +010096
Jonathan Cameron847ec802009-08-18 18:06:19 +010097/* Generic attributes of onetype or another */
Barry Song4f0cd862010-10-27 21:44:03 -040098
99/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700100 * 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 Cameron847ec802009-08-18 18:06:19 +0100104 **/
105#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
106 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
107
108/**
Jonathan Cameron355e25c2011-08-12 17:08:51 +0100109 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -0700110 * @_show: output method for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100111 *
Randy Dunlap4c572602009-10-04 19:34:02 -0700112 * May be mode dependent on some devices
Jonathan Cameron847ec802009-08-18 18:06:19 +0100113 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100114#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
115 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100116/**
Peter Meerwaldb90406f2012-06-18 20:33:02 +0200117 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -0700118 * @_string: frequency string for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100119 *
120 * Constant version
121 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100122#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
123 IIO_CONST_ATTR(sampling_frequency_available, _string)
124
Peter Meerwald899d90b2013-09-08 16:20:00 +0100125/**
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 Cameronff7723e2010-05-04 14:42:57 +0100140#define IIO_DEV_ATTR_TEMP_RAW(_show) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100141 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100142
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200143#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100144 IIO_CONST_ATTR(in_temp_offset, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200145
146#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100147 IIO_CONST_ATTR(in_temp_scale, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200148
Jonathan Cameron847ec802009-08-18 18:06:19 +0100149#endif /* _INDUSTRIAL_IO_SYSFS_H_ */