blob: b7a934b9431b57f5679dd6982dfc8df3a7ae7ec0 [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
Jonathan Cameron1d892712011-05-18 14:40:51 +010021 * @l: list head for maintaining list of dynamically created attrs.
Jonathan Cameron847ec802009-08-18 18:06:19 +010022 */
23struct iio_dev_attr {
24 struct device_attribute dev_attr;
Jonathan Camerone614a542011-09-02 17:14:41 +010025 u64 address;
Jonathan Cameron1d892712011-05-18 14:40:51 +010026 struct list_head l;
27 struct iio_chan_spec const *c;
Jonathan Cameron847ec802009-08-18 18:06:19 +010028};
29
30#define to_iio_dev_attr(_dev_attr) \
31 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
32
33ssize_t iio_read_const_attr(struct device *dev,
34 struct device_attribute *attr,
35 char *len);
36
37/**
38 * struct iio_const_attr - constant device specific attribute
39 * often used for things like available modes
Randy Dunlap4c572602009-10-04 19:34:02 -070040 * @string: attribute string
41 * @dev_attr: underlying device attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +010042 */
43struct iio_const_attr {
44 const char *string;
45 struct device_attribute dev_attr;
46};
47
48#define to_iio_const_attr(_dev_attr) \
49 container_of(_dev_attr, struct iio_const_attr, dev_attr)
50
Randy Dunlap4c572602009-10-04 19:34:02 -070051/* Some attributes will be hard coded (device dependent) and not require an
Jonathan Cameron847ec802009-08-18 18:06:19 +010052 address, in these cases pass a negative */
53#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
54 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
55 .address = _addr }
56
Jonathan Cameron847ec802009-08-18 18:06:19 +010057#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
58 struct iio_dev_attr iio_dev_attr_##_name \
59 = IIO_ATTR(_name, _mode, _show, _store, _addr)
60
Jonathan Cameronad313b12010-05-04 14:42:56 +010061#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
62 struct iio_dev_attr iio_dev_attr_##_vname \
63 = IIO_ATTR(_name, _mode, _show, _store, _addr)
Jonathan Cameron847ec802009-08-18 18:06:19 +010064
Jonathan Cameron847ec802009-08-18 18:06:19 +010065#define IIO_CONST_ATTR(_name, _string) \
66 struct iio_const_attr iio_const_attr_##_name \
67 = { .string = _string, \
68 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
69
Jonathan Cameronfc5d0e42010-10-08 12:14:08 +010070#define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
71 struct iio_const_attr iio_const_attr_##_vname \
72 = { .string = _string, \
73 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
Jonathan Cameron355e25c2011-08-12 17:08:51 +010074
Jonathan Cameron847ec802009-08-18 18:06:19 +010075/* Generic attributes of onetype or another */
Jonathan Cameron847ec802009-08-18 18:06:19 +010076/**
Barry Song4f0cd862010-10-27 21:44:03 -040077 * IIO_DEV_ATTR_RESET: resets the device
78 **/
79#define IIO_DEV_ATTR_RESET(_store) \
Greg Kroah-Hartman983bbfd2010-12-10 10:56:18 -080080 IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0)
Barry Song4f0cd862010-10-27 21:44:03 -040081
82/**
Randy Dunlap4c572602009-10-04 19:34:02 -070083 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
84 * @_mode: sysfs file mode/permissions
85 * @_show: output method for the attribute
86 * @_store: input method for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +010087 **/
88#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
89 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
90
91/**
Jonathan Cameron355e25c2011-08-12 17:08:51 +010092 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -070093 * @_show: output method for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +010094 *
Randy Dunlap4c572602009-10-04 19:34:02 -070095 * May be mode dependent on some devices
Jonathan Cameron847ec802009-08-18 18:06:19 +010096 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +010097#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
98 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
Jonathan Cameron847ec802009-08-18 18:06:19 +010099/**
Peter Meerwaldb90406f2012-06-18 20:33:02 +0200100 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
Randy Dunlap4c572602009-10-04 19:34:02 -0700101 * @_string: frequency string for the attribute
Jonathan Cameron847ec802009-08-18 18:06:19 +0100102 *
103 * Constant version
104 **/
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100105#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
106 IIO_CONST_ATTR(sampling_frequency_available, _string)
107
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100108#define IIO_DEV_ATTR_TEMP_RAW(_show) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100109 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
Jonathan Cameronff7723e2010-05-04 14:42:57 +0100110
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200111#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100112 IIO_CONST_ATTR(in_temp_offset, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200113
114#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
Jonathan Cameron322c9562011-09-14 13:01:23 +0100115 IIO_CONST_ATTR(in_temp_scale, _string)
Manuel Stahl51a0a5b2010-08-31 11:32:54 +0200116
Jonathan Cameron847ec802009-08-18 18:06:19 +0100117#endif /* _INDUSTRIAL_IO_SYSFS_H_ */