sysfs.h 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* The industrial I/O core
 *
 *Copyright (c) 2008 Jonathan Cameron
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published by
 * the Free Software Foundation.
 *
 * General attributes
 */

#ifndef _INDUSTRIAL_IO_SYSFS_H_
#define _INDUSTRIAL_IO_SYSFS_H_

15
struct iio_chan_spec;
16 17 18 19 20

/**
 * struct iio_dev_attr - iio specific device attribute
 * @dev_attr:	underlying device attribute
 * @address:	associated register address
21
 * @l:		list head for maintaining list of dynamically created attrs.
22 23 24
 */
struct iio_dev_attr {
	struct device_attribute dev_attr;
25
	u64 address;
26 27
	struct list_head l;
	struct iio_chan_spec const *c;
28 29 30 31 32 33 34 35 36 37 38 39
};

#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
R
Randy Dunlap 已提交
40 41
 * @string:	attribute string
 * @dev_attr:	underlying device attribute
42 43 44 45 46 47 48 49 50
 */
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)

R
Randy Dunlap 已提交
51
/* Some attributes will be hard coded (device dependent) and not require an
52 53 54 55 56 57 58 59 60
   address, in these cases pass a negative */
#define IIO_ATTR(_name, _mode, _show, _store, _addr)		\
	{ .dev_attr = __ATTR(_name, _mode, _show, _store),	\
	  .address = _addr }

#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr)	\
	struct iio_dev_attr iio_dev_attr_##_name		\
	= IIO_ATTR(_name, _mode, _show, _store, _addr)

61 62 63
#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)
64 65 66 67 68 69

#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)}

70 71 72 73
#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)}
R
Randy Dunlap 已提交
74

75
/* Generic attributes of onetype or another */
76

77
/**
R
Randy Dunlap 已提交
78 79 80 81
 * 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
82 83 84 85 86
 **/
#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store)			\
	IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)

/**
87
 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
R
Randy Dunlap 已提交
88
 * @_show: output method for the attribute
89
 *
R
Randy Dunlap 已提交
90
 * May be mode dependent on some devices
91
 **/
92 93
#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show)				\
	IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
94
/**
95
 * IIO_CONST_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
R
Randy Dunlap 已提交
96
 * @_string: frequency string for the attribute
97 98 99
 *
 * Constant version
 **/
100 101 102
#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string)			\
	IIO_CONST_ATTR(sampling_frequency_available, _string)

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
/**
 * 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)

118
#define IIO_DEV_ATTR_TEMP_RAW(_show)			\
119
	IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
120

121
#define IIO_CONST_ATTR_TEMP_OFFSET(_string)		\
122
	IIO_CONST_ATTR(in_temp_offset, _string)
123 124

#define IIO_CONST_ATTR_TEMP_SCALE(_string)		\
125
	IIO_CONST_ATTR(in_temp_scale, _string)
126

127
#endif /* _INDUSTRIAL_IO_SYSFS_H_ */