blob: ce9426c507fd1807cd5852055e0d9cff4aa6ef5b [file] [log] [blame]
Jonathan Cameron847ec802009-08-18 18:06:19 +01001/* The industrial I/O core
2 *
3 *Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * General attributes
10 */
11
12#ifndef _INDUSTRIAL_IO_SYSFS_H_
13#define _INDUSTRIAL_IO_SYSFS_H_
14
Jonathan Cameron4bfd5422011-08-12 17:56:05 +010015struct iio_chan_spec;
Jonathan Cameron847ec802009-08-18 18:06:19 +010016
17/**
Jonathan Cameron847ec802009-08-18 18:06:19 +010018 * struct iio_dev_attr - iio specific device attribute
19 * @dev_attr: underlying device attribute
20 * @address: associated register address
Cristina Opriceana2854c092015-07-24 16:26:09 +030021 * @l: list head for maintaining list of dynamically created attrs
22 * @c: specification for the underlying channel
Jonathan Cameron847ec802009-08-18 18:06:19 +010023 */
24struct iio_dev_attr {
25 struct device_attribute dev_attr;
Jonathan Camerone614a542011-09-02 17:14:41 +010026 u64 address;
Jonathan Cameron1d892712011-05-18 14:40:51 +010027 struct list_head l;
28 struct iio_chan_spec const *c;
Jonathan Cameron847ec802009-08-18 18:06:19 +010029};
30
31#define to_iio_dev_attr(_dev_attr) \
32 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
33
34ssize_t iio_read_const_attr(struct device *dev,
35 struct device_attribute *attr,
36 char *len);
37
38/**
39 * struct iio_const_attr - constant device specific attribute
40 * often used for things like available modes
Randy Dunlap4c572602009-10-04 19:34:02 -070041 * @string: attribute string
42 * @dev_attr: underlying device attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +010043 */
44struct iio_const_attr {
45 const char *string;
46 struct device_attribute dev_attr;
47};
48
49#define to_iio_const_attr(_dev_attr) \
50 container_of(_dev_attr, struct iio_const_attr, dev_attr)
51
Randy Dunlap4c572602009-10-04 19:34:02 -070052/* Some attributes will be hard coded (device dependent) and not require an
Jonathan Cameron847ec802009-08-18 18:06:19 +010053 address, in these cases pass a negative */
54#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
55 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
56 .address = _addr }
57
Brian Masneyf3b0dee2016-09-26 20:20:16 -040058#define IIO_ATTR_RO(_name, _addr) \
59 { .dev_attr = __ATTR_RO(_name), \
60 .address = _addr }
61
62#define IIO_ATTR_WO(_name, _addr) \
63 { .dev_attr = __ATTR_WO(_name), \
64 .address = _addr }
65
66#define IIO_ATTR_RW(_name, _addr) \
67 { .dev_attr = __ATTR_RW(_name), \
68 .address = _addr }
69
Jonathan Cameron847ec802009-08-18 18:06:19 +010070#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
71 struct iio_dev_attr iio_dev_attr_##_name \
72 = IIO_ATTR(_name, _mode, _show, _store, _addr)
73
Brian Masneyf3b0dee2016-09-26 20:20:16 -040074#define IIO_DEVICE_ATTR_RO(_name, _addr) \
75 struct iio_dev_attr iio_dev_attr_##_name \
76 = IIO_ATTR_RO(_name, _addr)
77
78#define IIO_DEVICE_ATTR_WO(_name, _addr) \
79 struct iio_dev_attr iio_dev_attr_##_name \
80 = IIO_ATTR_WO(_name, _addr)
81
82#define IIO_DEVICE_ATTR_RW(_name, _addr) \
83 struct iio_dev_attr iio_dev_attr_##_name \
84 = IIO_ATTR_RW(_name, _addr)
85
Jonathan Cameronad313b12010-05-04 14:42:56 +010086#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
87 struct iio_dev_attr iio_dev_attr_##_vname \
88 = IIO_ATTR(_name, _mode, _show, _store, _addr)
Jonathan Cameron847ec802009-08-18 18:06:19 +010089
Jonathan Cameron847ec802009-08-18 18:06:19 +010090#define IIO_CONST_ATTR(_name, _string) \
91 struct iio_const_attr iio_const_attr_##_name \
92 = { .string = _string, \
93 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
94
Jonathan Cameronfc5d0e42010-10-08 12:14:08 +010095#define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
96 struct iio_const_attr iio_const_attr_##_vname \
97 = { .string = _string, \
98 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
Jonathan Cameron355e25c2011-08-12 17:08:51 +010099
Jonathan Cameron847ec802009-08-18 18:06:19 +0100100/* Generic attributes of onetype or another */
Barry Song4f0cd862010-10-27 21:44:03 -0400101
102/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700103 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
104 * @_mode: sysfs file mode/permissions
105 * @_show: output method for the attribute
106 * @_store: input method for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100107 **/
108#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
109 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
110
111/**
Jonathan Cameron355e25c2011-08-12 17:08:51 +0100112 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -0700113 * @_show: output method for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100114 *
Randy Dunlap4c572602009-10-04 19:34:02 -0700115 * May be mode dependent on some devices
Jonathan Cameron847ec802009-08-18 18:06:19 +0100116 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100117#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
118 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100119/**
Peter Meerwaldb90406f2012-06-18 20:33:02 +0200120 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -0700121 * @_string: frequency string for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100122 *
123 * Constant version
124 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100125#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
126 IIO_CONST_ATTR(sampling_frequency_available, _string)
127
Peter Meerwald899d90b2013-09-08 16:20:00 +0100128/**
129 * IIO_DEV_ATTR_INT_TIME_AVAIL - list available integration times
130 * @_show: output method for the attribute
131 **/
132#define IIO_DEV_ATTR_INT_TIME_AVAIL(_show) \
133 IIO_DEVICE_ATTR(integration_time_available, S_IRUGO, _show, NULL, 0)
134/**
135 * IIO_CONST_ATTR_INT_TIME_AVAIL - list available integration times
136 * @_string: frequency string for the attribute
137 *
138 * Constant version
139 **/
140#define IIO_CONST_ATTR_INT_TIME_AVAIL(_string) \
141 IIO_CONST_ATTR(integration_time_available, _string)
142
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100143#define IIO_DEV_ATTR_TEMP_RAW(_show) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100144 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100145
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200146#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100147 IIO_CONST_ATTR(in_temp_offset, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200148
149#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100150 IIO_CONST_ATTR(in_temp_scale, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200151
Jonathan Cameron847ec802009-08-18 18:06:19 +0100152#endif /* _INDUSTRIAL_IO_SYSFS_H_ */