diff options
author | Jonathan Cameron <jic23@kernel.org> | 2012-04-25 10:54:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-25 14:01:43 -0400 |
commit | 06458e277eac2b8761b0a04d3c808d57be281a2e (patch) | |
tree | cba55bcbdd101a3ab84bfe27fccdb9efd18d757e /include/linux/iio | |
parent | 68284a12923f9f8f2741efca10c045e179f2e753 (diff) |
IIO: Move core headers to include/linux/iio
Step 1 in moving the IIO core out of staging.
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/iio')
-rw-r--r-- | include/linux/iio/buffer.h | 191 | ||||
-rw-r--r-- | include/linux/iio/consumer.h | 96 | ||||
-rw-r--r-- | include/linux/iio/driver.h | 34 | ||||
-rw-r--r-- | include/linux/iio/events.h | 105 | ||||
-rw-r--r-- | include/linux/iio/iio.h | 463 | ||||
-rw-r--r-- | include/linux/iio/kfifo_buf.h | 8 | ||||
-rw-r--r-- | include/linux/iio/machine.h | 24 | ||||
-rw-r--r-- | include/linux/iio/sysfs.h | 117 | ||||
-rw-r--r-- | include/linux/iio/trigger.h | 119 | ||||
-rw-r--r-- | include/linux/iio/trigger_consumer.h | 52 | ||||
-rw-r--r-- | include/linux/iio/types.h | 53 |
11 files changed, 1262 insertions, 0 deletions
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h new file mode 100644 index 000000000000..fb0fe46fd659 --- /dev/null +++ b/include/linux/iio/buffer.h | |||
@@ -0,0 +1,191 @@ | |||
1 | /* The industrial I/O core - generic buffer interfaces. | ||
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 | |||
10 | #ifndef _IIO_BUFFER_GENERIC_H_ | ||
11 | #define _IIO_BUFFER_GENERIC_H_ | ||
12 | #include <linux/sysfs.h> | ||
13 | #include <linux/iio/iio.h> | ||
14 | |||
15 | #ifdef CONFIG_IIO_BUFFER | ||
16 | |||
17 | struct iio_buffer; | ||
18 | |||
19 | /** | ||
20 | * struct iio_buffer_access_funcs - access functions for buffers. | ||
21 | * @store_to: actually store stuff to the buffer | ||
22 | * @read_first_n: try to get a specified number of bytes (must exist) | ||
23 | * @request_update: if a parameter change has been marked, update underlying | ||
24 | * storage. | ||
25 | * @get_bytes_per_datum:get current bytes per datum | ||
26 | * @set_bytes_per_datum:set number of bytes per datum | ||
27 | * @get_length: get number of datums in buffer | ||
28 | * @set_length: set number of datums in buffer | ||
29 | * | ||
30 | * The purpose of this structure is to make the buffer element | ||
31 | * modular as event for a given driver, different usecases may require | ||
32 | * different buffer designs (space efficiency vs speed for example). | ||
33 | * | ||
34 | * It is worth noting that a given buffer implementation may only support a | ||
35 | * small proportion of these functions. The core code 'should' cope fine with | ||
36 | * any of them not existing. | ||
37 | **/ | ||
38 | struct iio_buffer_access_funcs { | ||
39 | int (*store_to)(struct iio_buffer *buffer, u8 *data, s64 timestamp); | ||
40 | int (*read_first_n)(struct iio_buffer *buffer, | ||
41 | size_t n, | ||
42 | char __user *buf); | ||
43 | |||
44 | int (*request_update)(struct iio_buffer *buffer); | ||
45 | |||
46 | int (*get_bytes_per_datum)(struct iio_buffer *buffer); | ||
47 | int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); | ||
48 | int (*get_length)(struct iio_buffer *buffer); | ||
49 | int (*set_length)(struct iio_buffer *buffer, int length); | ||
50 | }; | ||
51 | |||
52 | /** | ||
53 | * struct iio_buffer - general buffer structure | ||
54 | * @length: [DEVICE] number of datums in buffer | ||
55 | * @bytes_per_datum: [DEVICE] size of individual datum including timestamp | ||
56 | * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode | ||
57 | * control method is used | ||
58 | * @scan_mask: [INTERN] bitmask used in masking scan mode elements | ||
59 | * @scan_timestamp: [INTERN] does the scan mode include a timestamp | ||
60 | * @access: [DRIVER] buffer access functions associated with the | ||
61 | * implementation. | ||
62 | * @scan_el_dev_attr_list:[INTERN] list of scan element related attributes. | ||
63 | * @scan_el_group: [DRIVER] attribute group for those attributes not | ||
64 | * created from the iio_chan_info array. | ||
65 | * @pollq: [INTERN] wait queue to allow for polling on the buffer. | ||
66 | * @stufftoread: [INTERN] flag to indicate new data. | ||
67 | * @demux_list: [INTERN] list of operations required to demux the scan. | ||
68 | * @demux_bounce: [INTERN] buffer for doing gather from incoming scan. | ||
69 | **/ | ||
70 | struct iio_buffer { | ||
71 | int length; | ||
72 | int bytes_per_datum; | ||
73 | struct attribute_group *scan_el_attrs; | ||
74 | long *scan_mask; | ||
75 | bool scan_timestamp; | ||
76 | const struct iio_buffer_access_funcs *access; | ||
77 | struct list_head scan_el_dev_attr_list; | ||
78 | struct attribute_group scan_el_group; | ||
79 | wait_queue_head_t pollq; | ||
80 | bool stufftoread; | ||
81 | const struct attribute_group *attrs; | ||
82 | struct list_head demux_list; | ||
83 | unsigned char *demux_bounce; | ||
84 | }; | ||
85 | |||
86 | /** | ||
87 | * iio_buffer_init() - Initialize the buffer structure | ||
88 | * @buffer: buffer to be initialized | ||
89 | **/ | ||
90 | void iio_buffer_init(struct iio_buffer *buffer); | ||
91 | |||
92 | /** | ||
93 | * __iio_update_buffer() - update common elements of buffers | ||
94 | * @buffer: buffer that is the event source | ||
95 | * @bytes_per_datum: size of individual datum including timestamp | ||
96 | * @length: number of datums in buffer | ||
97 | **/ | ||
98 | static inline void __iio_update_buffer(struct iio_buffer *buffer, | ||
99 | int bytes_per_datum, int length) | ||
100 | { | ||
101 | buffer->bytes_per_datum = bytes_per_datum; | ||
102 | buffer->length = length; | ||
103 | } | ||
104 | |||
105 | int iio_scan_mask_query(struct iio_dev *indio_dev, | ||
106 | struct iio_buffer *buffer, int bit); | ||
107 | |||
108 | /** | ||
109 | * iio_scan_mask_set() - set particular bit in the scan mask | ||
110 | * @buffer: the buffer whose scan mask we are interested in | ||
111 | * @bit: the bit to be set. | ||
112 | **/ | ||
113 | int iio_scan_mask_set(struct iio_dev *indio_dev, | ||
114 | struct iio_buffer *buffer, int bit); | ||
115 | |||
116 | /** | ||
117 | * iio_push_to_buffer() - push to a registered buffer. | ||
118 | * @buffer: IIO buffer structure for device | ||
119 | * @scan: Full scan. | ||
120 | * @timestamp: | ||
121 | */ | ||
122 | int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data, | ||
123 | s64 timestamp); | ||
124 | |||
125 | int iio_update_demux(struct iio_dev *indio_dev); | ||
126 | |||
127 | /** | ||
128 | * iio_buffer_register() - register the buffer with IIO core | ||
129 | * @indio_dev: device with the buffer to be registered | ||
130 | **/ | ||
131 | int iio_buffer_register(struct iio_dev *indio_dev, | ||
132 | const struct iio_chan_spec *channels, | ||
133 | int num_channels); | ||
134 | |||
135 | /** | ||
136 | * iio_buffer_unregister() - unregister the buffer from IIO core | ||
137 | * @indio_dev: the device with the buffer to be unregistered | ||
138 | **/ | ||
139 | void iio_buffer_unregister(struct iio_dev *indio_dev); | ||
140 | |||
141 | /** | ||
142 | * iio_buffer_read_length() - attr func to get number of datums in the buffer | ||
143 | **/ | ||
144 | ssize_t iio_buffer_read_length(struct device *dev, | ||
145 | struct device_attribute *attr, | ||
146 | char *buf); | ||
147 | /** | ||
148 | * iio_buffer_write_length() - attr func to set number of datums in the buffer | ||
149 | **/ | ||
150 | ssize_t iio_buffer_write_length(struct device *dev, | ||
151 | struct device_attribute *attr, | ||
152 | const char *buf, | ||
153 | size_t len); | ||
154 | /** | ||
155 | * iio_buffer_store_enable() - attr to turn the buffer on | ||
156 | **/ | ||
157 | ssize_t iio_buffer_store_enable(struct device *dev, | ||
158 | struct device_attribute *attr, | ||
159 | const char *buf, | ||
160 | size_t len); | ||
161 | /** | ||
162 | * iio_buffer_show_enable() - attr to see if the buffer is on | ||
163 | **/ | ||
164 | ssize_t iio_buffer_show_enable(struct device *dev, | ||
165 | struct device_attribute *attr, | ||
166 | char *buf); | ||
167 | #define IIO_BUFFER_LENGTH_ATTR DEVICE_ATTR(length, S_IRUGO | S_IWUSR, \ | ||
168 | iio_buffer_read_length, \ | ||
169 | iio_buffer_write_length) | ||
170 | |||
171 | #define IIO_BUFFER_ENABLE_ATTR DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, \ | ||
172 | iio_buffer_show_enable, \ | ||
173 | iio_buffer_store_enable) | ||
174 | |||
175 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev); | ||
176 | |||
177 | #else /* CONFIG_IIO_BUFFER */ | ||
178 | |||
179 | static inline int iio_buffer_register(struct iio_dev *indio_dev, | ||
180 | struct iio_chan_spec *channels, | ||
181 | int num_channels) | ||
182 | { | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | static inline void iio_buffer_unregister(struct iio_dev *indio_dev) | ||
187 | {}; | ||
188 | |||
189 | #endif /* CONFIG_IIO_BUFFER */ | ||
190 | |||
191 | #endif /* _IIO_BUFFER_GENERIC_H_ */ | ||
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h new file mode 100644 index 000000000000..1a15e560a5a1 --- /dev/null +++ b/include/linux/iio/consumer.h | |||
@@ -0,0 +1,96 @@ | |||
1 | /* | ||
2 | * Industrial I/O in kernel consumer interface | ||
3 | * | ||
4 | * Copyright (c) 2011 Jonathan Cameron | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef _IIO_INKERN_CONSUMER_H_ | ||
11 | #define _IIO_INKERN_CONSUMER_H | ||
12 | #include <linux/iio/types.h> | ||
13 | |||
14 | struct iio_dev; | ||
15 | struct iio_chan_spec; | ||
16 | |||
17 | /** | ||
18 | * struct iio_channel - everything needed for a consumer to use a channel | ||
19 | * @indio_dev: Device on which the channel exists. | ||
20 | * @channel: Full description of the channel. | ||
21 | */ | ||
22 | struct iio_channel { | ||
23 | struct iio_dev *indio_dev; | ||
24 | const struct iio_chan_spec *channel; | ||
25 | }; | ||
26 | |||
27 | /** | ||
28 | * iio_channel_get() - get description of all that is needed to access channel. | ||
29 | * @name: Unique name of the device as provided in the iio_map | ||
30 | * with which the desired provider to consumer mapping | ||
31 | * was registered. | ||
32 | * @consumer_channel: Unique name to identify the channel on the consumer | ||
33 | * side. This typically describes the channels use within | ||
34 | * the consumer. E.g. 'battery_voltage' | ||
35 | */ | ||
36 | struct iio_channel *iio_st_channel_get(const char *name, | ||
37 | const char *consumer_channel); | ||
38 | |||
39 | /** | ||
40 | * iio_st_channel_release() - release channels obtained via iio_st_channel_get | ||
41 | * @chan: The channel to be released. | ||
42 | */ | ||
43 | void iio_st_channel_release(struct iio_channel *chan); | ||
44 | |||
45 | /** | ||
46 | * iio_st_channel_get_all() - get all channels associated with a client | ||
47 | * @name: name of consumer device. | ||
48 | * | ||
49 | * Returns an array of iio_channel structures terminated with one with | ||
50 | * null iio_dev pointer. | ||
51 | * This function is used by fairly generic consumers to get all the | ||
52 | * channels registered as having this consumer. | ||
53 | */ | ||
54 | struct iio_channel *iio_st_channel_get_all(const char *name); | ||
55 | |||
56 | /** | ||
57 | * iio_st_channel_release_all() - reverse iio_st_get_all | ||
58 | * @chan: Array of channels to be released. | ||
59 | */ | ||
60 | void iio_st_channel_release_all(struct iio_channel *chan); | ||
61 | |||
62 | /** | ||
63 | * iio_st_read_channel_raw() - read from a given channel | ||
64 | * @channel: The channel being queried. | ||
65 | * @val: Value read back. | ||
66 | * | ||
67 | * Note raw reads from iio channels are in adc counts and hence | ||
68 | * scale will need to be applied if standard units required. | ||
69 | */ | ||
70 | int iio_st_read_channel_raw(struct iio_channel *chan, | ||
71 | int *val); | ||
72 | |||
73 | /** | ||
74 | * iio_st_get_channel_type() - get the type of a channel | ||
75 | * @channel: The channel being queried. | ||
76 | * @type: The type of the channel. | ||
77 | * | ||
78 | * returns the enum iio_chan_type of the channel | ||
79 | */ | ||
80 | int iio_st_get_channel_type(struct iio_channel *channel, | ||
81 | enum iio_chan_type *type); | ||
82 | |||
83 | /** | ||
84 | * iio_st_read_channel_scale() - read the scale value for a channel | ||
85 | * @channel: The channel being queried. | ||
86 | * @val: First part of value read back. | ||
87 | * @val2: Second part of value read back. | ||
88 | * | ||
89 | * Note returns a description of what is in val and val2, such | ||
90 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val | ||
91 | * + val2/1e6 | ||
92 | */ | ||
93 | int iio_st_read_channel_scale(struct iio_channel *chan, int *val, | ||
94 | int *val2); | ||
95 | |||
96 | #endif | ||
diff --git a/include/linux/iio/driver.h b/include/linux/iio/driver.h new file mode 100644 index 000000000000..a4f8b2e05af5 --- /dev/null +++ b/include/linux/iio/driver.h | |||
@@ -0,0 +1,34 @@ | |||
1 | /* | ||
2 | * Industrial I/O in kernel access map interface. | ||
3 | * | ||
4 | * Copyright (c) 2011 Jonathan Cameron | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | #ifndef _IIO_INKERN_H_ | ||
12 | #define _IIO_INKERN_H_ | ||
13 | |||
14 | struct iio_map; | ||
15 | |||
16 | /** | ||
17 | * iio_map_array_register() - tell the core about inkernel consumers | ||
18 | * @indio_dev: provider device | ||
19 | * @map: array of mappings specifying association of channel with client | ||
20 | */ | ||
21 | int iio_map_array_register(struct iio_dev *indio_dev, | ||
22 | struct iio_map *map); | ||
23 | |||
24 | /** | ||
25 | * iio_map_array_unregister() - tell the core to remove consumer mappings | ||
26 | * @indio_dev: provider device | ||
27 | * @map: array of mappings to remove. Note these must have same memory | ||
28 | * addresses as those originally added not just equal parameter | ||
29 | * values. | ||
30 | */ | ||
31 | int iio_map_array_unregister(struct iio_dev *indio_dev, | ||
32 | struct iio_map *map); | ||
33 | |||
34 | #endif | ||
diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h new file mode 100644 index 000000000000..b5acbf93c5da --- /dev/null +++ b/include/linux/iio/events.h | |||
@@ -0,0 +1,105 @@ | |||
1 | /* The industrial I/O - event passing to userspace | ||
2 | * | ||
3 | * Copyright (c) 2008-2011 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 | #ifndef _IIO_EVENTS_H_ | ||
10 | #define _IIO_EVENTS_H_ | ||
11 | |||
12 | #include <linux/ioctl.h> | ||
13 | #include <linux/types.h> | ||
14 | #include <linux/iio/types.h> | ||
15 | |||
16 | /** | ||
17 | * struct iio_event_data - The actual event being pushed to userspace | ||
18 | * @id: event identifier | ||
19 | * @timestamp: best estimate of time of event occurrence (often from | ||
20 | * the interrupt handler) | ||
21 | */ | ||
22 | struct iio_event_data { | ||
23 | __u64 id; | ||
24 | __s64 timestamp; | ||
25 | }; | ||
26 | |||
27 | #define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int) | ||
28 | |||
29 | enum iio_event_type { | ||
30 | IIO_EV_TYPE_THRESH, | ||
31 | IIO_EV_TYPE_MAG, | ||
32 | IIO_EV_TYPE_ROC, | ||
33 | IIO_EV_TYPE_THRESH_ADAPTIVE, | ||
34 | IIO_EV_TYPE_MAG_ADAPTIVE, | ||
35 | }; | ||
36 | |||
37 | enum iio_event_direction { | ||
38 | IIO_EV_DIR_EITHER, | ||
39 | IIO_EV_DIR_RISING, | ||
40 | IIO_EV_DIR_FALLING, | ||
41 | }; | ||
42 | |||
43 | /** | ||
44 | * IIO_EVENT_CODE() - create event identifier | ||
45 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | ||
46 | * @diff: Whether the event is for an differential channel or not. | ||
47 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. | ||
48 | * @direction: Direction of the event. One of enum iio_event_direction. | ||
49 | * @type: Type of the event. Should be one enum iio_event_type. | ||
50 | * @chan: Channel number for non-differential channels. | ||
51 | * @chan1: First channel number for differential channels. | ||
52 | * @chan2: Second channel number for differential channels. | ||
53 | */ | ||
54 | |||
55 | #define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \ | ||
56 | type, chan, chan1, chan2) \ | ||
57 | (((u64)type << 56) | ((u64)diff << 55) | \ | ||
58 | ((u64)direction << 48) | ((u64)modifier << 40) | \ | ||
59 | ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \ | ||
60 | ((u16)chan)) | ||
61 | |||
62 | |||
63 | #define IIO_EV_DIR_MAX 4 | ||
64 | #define IIO_EV_BIT(type, direction) \ | ||
65 | (1 << (type*IIO_EV_DIR_MAX + direction)) | ||
66 | |||
67 | /** | ||
68 | * IIO_MOD_EVENT_CODE() - create event identifier for modified channels | ||
69 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | ||
70 | * @number: Channel number. | ||
71 | * @modifier: Modifier for the channel. Should be one of enum iio_modifier. | ||
72 | * @type: Type of the event. Should be one enum iio_event_type. | ||
73 | * @direction: Direction of the event. One of enum iio_event_direction. | ||
74 | */ | ||
75 | |||
76 | #define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \ | ||
77 | type, direction) \ | ||
78 | IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0) | ||
79 | |||
80 | /** | ||
81 | * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels | ||
82 | * @chan_type: Type of the channel. Should be one of enum iio_chan_type. | ||
83 | * @number: Channel number. | ||
84 | * @type: Type of the event. Should be one enum iio_event_type. | ||
85 | * @direction: Direction of the event. One of enum iio_event_direction. | ||
86 | */ | ||
87 | |||
88 | #define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \ | ||
89 | IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0) | ||
90 | |||
91 | #define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF) | ||
92 | |||
93 | #define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF) | ||
94 | |||
95 | #define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF) | ||
96 | |||
97 | /* Event code number extraction depends on which type of event we have. | ||
98 | * Perhaps review this function in the future*/ | ||
99 | #define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF)) | ||
100 | #define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF)) | ||
101 | |||
102 | #define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF) | ||
103 | #define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1) | ||
104 | |||
105 | #endif | ||
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h new file mode 100644 index 000000000000..9c0908a70466 --- /dev/null +++ b/include/linux/iio/iio.h | |||
@@ -0,0 +1,463 @@ | |||
1 | |||
2 | /* The industrial I/O core | ||
3 | * | ||
4 | * Copyright (c) 2008 Jonathan Cameron | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | */ | ||
10 | #ifndef _INDUSTRIAL_IO_H_ | ||
11 | #define _INDUSTRIAL_IO_H_ | ||
12 | |||
13 | #include <linux/device.h> | ||
14 | #include <linux/cdev.h> | ||
15 | #include <linux/iio/types.h> | ||
16 | /* IIO TODO LIST */ | ||
17 | /* | ||
18 | * Provide means of adjusting timer accuracy. | ||
19 | * Currently assumes nano seconds. | ||
20 | */ | ||
21 | |||
22 | enum iio_chan_info_enum { | ||
23 | IIO_CHAN_INFO_RAW = 0, | ||
24 | IIO_CHAN_INFO_PROCESSED, | ||
25 | IIO_CHAN_INFO_SCALE, | ||
26 | IIO_CHAN_INFO_OFFSET, | ||
27 | IIO_CHAN_INFO_CALIBSCALE, | ||
28 | IIO_CHAN_INFO_CALIBBIAS, | ||
29 | IIO_CHAN_INFO_PEAK, | ||
30 | IIO_CHAN_INFO_PEAK_SCALE, | ||
31 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW, | ||
32 | IIO_CHAN_INFO_AVERAGE_RAW, | ||
33 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY, | ||
34 | IIO_CHAN_INFO_SAMP_FREQ, | ||
35 | }; | ||
36 | |||
37 | #define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2) | ||
38 | #define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1) | ||
39 | |||
40 | #define IIO_CHAN_INFO_RAW_SEPARATE_BIT \ | ||
41 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_RAW) | ||
42 | #define IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT \ | ||
43 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PROCESSED) | ||
44 | #define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \ | ||
45 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE) | ||
46 | #define IIO_CHAN_INFO_SCALE_SHARED_BIT \ | ||
47 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SCALE) | ||
48 | #define IIO_CHAN_INFO_OFFSET_SEPARATE_BIT \ | ||
49 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_OFFSET) | ||
50 | #define IIO_CHAN_INFO_OFFSET_SHARED_BIT \ | ||
51 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_OFFSET) | ||
52 | #define IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT \ | ||
53 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBSCALE) | ||
54 | #define IIO_CHAN_INFO_CALIBSCALE_SHARED_BIT \ | ||
55 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBSCALE) | ||
56 | #define IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT \ | ||
57 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBBIAS) | ||
58 | #define IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT \ | ||
59 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBBIAS) | ||
60 | #define IIO_CHAN_INFO_PEAK_SEPARATE_BIT \ | ||
61 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAK) | ||
62 | #define IIO_CHAN_INFO_PEAK_SHARED_BIT \ | ||
63 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAK) | ||
64 | #define IIO_CHAN_INFO_PEAKSCALE_SEPARATE_BIT \ | ||
65 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAKSCALE) | ||
66 | #define IIO_CHAN_INFO_PEAKSCALE_SHARED_BIT \ | ||
67 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAKSCALE) | ||
68 | #define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT \ | ||
69 | IIO_CHAN_INFO_SEPARATE_BIT( \ | ||
70 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW) | ||
71 | #define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED_BIT \ | ||
72 | IIO_CHAN_INFO_SHARED_BIT( \ | ||
73 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW) | ||
74 | #define IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT \ | ||
75 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_AVERAGE_RAW) | ||
76 | #define IIO_CHAN_INFO_AVERAGE_RAW_SHARED_BIT \ | ||
77 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_AVERAGE_RAW) | ||
78 | #define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT \ | ||
79 | IIO_CHAN_INFO_SHARED_BIT( \ | ||
80 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | ||
81 | #define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \ | ||
82 | IIO_CHAN_INFO_SEPARATE_BIT( \ | ||
83 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | ||
84 | #define IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT \ | ||
85 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SAMP_FREQ) | ||
86 | #define IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT \ | ||
87 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SAMP_FREQ) | ||
88 | |||
89 | enum iio_endian { | ||
90 | IIO_CPU, | ||
91 | IIO_BE, | ||
92 | IIO_LE, | ||
93 | }; | ||
94 | |||
95 | struct iio_chan_spec; | ||
96 | struct iio_dev; | ||
97 | |||
98 | /** | ||
99 | * struct iio_chan_spec_ext_info - Extended channel info attribute | ||
100 | * @name: Info attribute name | ||
101 | * @shared: Whether this attribute is shared between all channels. | ||
102 | * @read: Read callback for this info attribute, may be NULL. | ||
103 | * @write: Write callback for this info attribute, may be NULL. | ||
104 | */ | ||
105 | struct iio_chan_spec_ext_info { | ||
106 | const char *name; | ||
107 | bool shared; | ||
108 | ssize_t (*read)(struct iio_dev *, struct iio_chan_spec const *, | ||
109 | char *buf); | ||
110 | ssize_t (*write)(struct iio_dev *, struct iio_chan_spec const *, | ||
111 | const char *buf, size_t len); | ||
112 | }; | ||
113 | |||
114 | /** | ||
115 | * struct iio_chan_spec - specification of a single channel | ||
116 | * @type: What type of measurement is the channel making. | ||
117 | * @channel: What number or name do we wish to assign the channel. | ||
118 | * @channel2: If there is a second number for a differential | ||
119 | * channel then this is it. If modified is set then the | ||
120 | * value here specifies the modifier. | ||
121 | * @address: Driver specific identifier. | ||
122 | * @scan_index: Monotonic index to give ordering in scans when read | ||
123 | * from a buffer. | ||
124 | * @scan_type: Sign: 's' or 'u' to specify signed or unsigned | ||
125 | * realbits: Number of valid bits of data | ||
126 | * storage_bits: Realbits + padding | ||
127 | * shift: Shift right by this before masking out | ||
128 | * realbits. | ||
129 | * endianness: little or big endian | ||
130 | * @info_mask: What information is to be exported about this channel. | ||
131 | * This includes calibbias, scale etc. | ||
132 | * @event_mask: What events can this channel produce. | ||
133 | * @ext_info: Array of extended info attributes for this channel. | ||
134 | * The array is NULL terminated, the last element should | ||
135 | * have it's name field set to NULL. | ||
136 | * @extend_name: Allows labeling of channel attributes with an | ||
137 | * informative name. Note this has no effect codes etc, | ||
138 | * unlike modifiers. | ||
139 | * @datasheet_name: A name used in in kernel mapping of channels. It should | ||
140 | * correspond to the first name that the channel is referred | ||
141 | * to by in the datasheet (e.g. IND), or the nearest | ||
142 | * possible compound name (e.g. IND-INC). | ||
143 | * @modified: Does a modifier apply to this channel. What these are | ||
144 | * depends on the channel type. Modifier is set in | ||
145 | * channel2. Examples are IIO_MOD_X for axial sensors about | ||
146 | * the 'x' axis. | ||
147 | * @indexed: Specify the channel has a numerical index. If not, | ||
148 | * the value in channel will be suppressed for attribute | ||
149 | * but not for event codes. Typically set it to 0 when | ||
150 | * the index is false. | ||
151 | * @differential: Channel is differential. | ||
152 | */ | ||
153 | struct iio_chan_spec { | ||
154 | enum iio_chan_type type; | ||
155 | int channel; | ||
156 | int channel2; | ||
157 | unsigned long address; | ||
158 | int scan_index; | ||
159 | struct { | ||
160 | char sign; | ||
161 | u8 realbits; | ||
162 | u8 storagebits; | ||
163 | u8 shift; | ||
164 | enum iio_endian endianness; | ||
165 | } scan_type; | ||
166 | long info_mask; | ||
167 | long event_mask; | ||
168 | const struct iio_chan_spec_ext_info *ext_info; | ||
169 | const char *extend_name; | ||
170 | const char *datasheet_name; | ||
171 | unsigned modified:1; | ||
172 | unsigned indexed:1; | ||
173 | unsigned output:1; | ||
174 | unsigned differential:1; | ||
175 | }; | ||
176 | |||
177 | #define IIO_ST(si, rb, sb, sh) \ | ||
178 | { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh } | ||
179 | |||
180 | #define IIO_CHAN_SOFT_TIMESTAMP(_si) \ | ||
181 | { .type = IIO_TIMESTAMP, .channel = -1, \ | ||
182 | .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) } | ||
183 | |||
184 | /** | ||
185 | * iio_get_time_ns() - utility function to get a time stamp for events etc | ||
186 | **/ | ||
187 | static inline s64 iio_get_time_ns(void) | ||
188 | { | ||
189 | struct timespec ts; | ||
190 | /* | ||
191 | * calls getnstimeofday. | ||
192 | * If hrtimers then up to ns accurate, if not microsecond. | ||
193 | */ | ||
194 | ktime_get_real_ts(&ts); | ||
195 | |||
196 | return timespec_to_ns(&ts); | ||
197 | } | ||
198 | |||
199 | /* Device operating modes */ | ||
200 | #define INDIO_DIRECT_MODE 0x01 | ||
201 | #define INDIO_BUFFER_TRIGGERED 0x02 | ||
202 | #define INDIO_BUFFER_HARDWARE 0x08 | ||
203 | |||
204 | #define INDIO_ALL_BUFFER_MODES \ | ||
205 | (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE) | ||
206 | |||
207 | struct iio_trigger; /* forward declaration */ | ||
208 | struct iio_dev; | ||
209 | |||
210 | /** | ||
211 | * struct iio_info - constant information about device | ||
212 | * @driver_module: module structure used to ensure correct | ||
213 | * ownership of chrdevs etc | ||
214 | * @event_attrs: event control attributes | ||
215 | * @attrs: general purpose device attributes | ||
216 | * @read_raw: function to request a value from the device. | ||
217 | * mask specifies which value. Note 0 means a reading of | ||
218 | * the channel in question. Return value will specify the | ||
219 | * type of value returned by the device. val and val2 will | ||
220 | * contain the elements making up the returned value. | ||
221 | * @write_raw: function to write a value to the device. | ||
222 | * Parameters are the same as for read_raw. | ||
223 | * @write_raw_get_fmt: callback function to query the expected | ||
224 | * format/precision. If not set by the driver, write_raw | ||
225 | * returns IIO_VAL_INT_PLUS_MICRO. | ||
226 | * @read_event_config: find out if the event is enabled. | ||
227 | * @write_event_config: set if the event is enabled. | ||
228 | * @read_event_value: read a value associated with the event. Meaning | ||
229 | * is event dependant. event_code specifies which event. | ||
230 | * @write_event_value: write the value associated with the event. | ||
231 | * Meaning is event dependent. | ||
232 | * @validate_trigger: function to validate the trigger when the | ||
233 | * current trigger gets changed. | ||
234 | **/ | ||
235 | struct iio_info { | ||
236 | struct module *driver_module; | ||
237 | struct attribute_group *event_attrs; | ||
238 | const struct attribute_group *attrs; | ||
239 | |||
240 | int (*read_raw)(struct iio_dev *indio_dev, | ||
241 | struct iio_chan_spec const *chan, | ||
242 | int *val, | ||
243 | int *val2, | ||
244 | long mask); | ||
245 | |||
246 | int (*write_raw)(struct iio_dev *indio_dev, | ||
247 | struct iio_chan_spec const *chan, | ||
248 | int val, | ||
249 | int val2, | ||
250 | long mask); | ||
251 | |||
252 | int (*write_raw_get_fmt)(struct iio_dev *indio_dev, | ||
253 | struct iio_chan_spec const *chan, | ||
254 | long mask); | ||
255 | |||
256 | int (*read_event_config)(struct iio_dev *indio_dev, | ||
257 | u64 event_code); | ||
258 | |||
259 | int (*write_event_config)(struct iio_dev *indio_dev, | ||
260 | u64 event_code, | ||
261 | int state); | ||
262 | |||
263 | int (*read_event_value)(struct iio_dev *indio_dev, | ||
264 | u64 event_code, | ||
265 | int *val); | ||
266 | int (*write_event_value)(struct iio_dev *indio_dev, | ||
267 | u64 event_code, | ||
268 | int val); | ||
269 | int (*validate_trigger)(struct iio_dev *indio_dev, | ||
270 | struct iio_trigger *trig); | ||
271 | int (*update_scan_mode)(struct iio_dev *indio_dev, | ||
272 | const unsigned long *scan_mask); | ||
273 | int (*debugfs_reg_access)(struct iio_dev *indio_dev, | ||
274 | unsigned reg, unsigned writeval, | ||
275 | unsigned *readval); | ||
276 | }; | ||
277 | |||
278 | /** | ||
279 | * struct iio_buffer_setup_ops - buffer setup related callbacks | ||
280 | * @preenable: [DRIVER] function to run prior to marking buffer enabled | ||
281 | * @postenable: [DRIVER] function to run after marking buffer enabled | ||
282 | * @predisable: [DRIVER] function to run prior to marking buffer | ||
283 | * disabled | ||
284 | * @postdisable: [DRIVER] function to run after marking buffer disabled | ||
285 | */ | ||
286 | struct iio_buffer_setup_ops { | ||
287 | int (*preenable)(struct iio_dev *); | ||
288 | int (*postenable)(struct iio_dev *); | ||
289 | int (*predisable)(struct iio_dev *); | ||
290 | int (*postdisable)(struct iio_dev *); | ||
291 | }; | ||
292 | |||
293 | /** | ||
294 | * struct iio_dev - industrial I/O device | ||
295 | * @id: [INTERN] used to identify device internally | ||
296 | * @modes: [DRIVER] operating modes supported by device | ||
297 | * @currentmode: [DRIVER] current operating mode | ||
298 | * @dev: [DRIVER] device structure, should be assigned a parent | ||
299 | * and owner | ||
300 | * @event_interface: [INTERN] event chrdevs associated with interrupt lines | ||
301 | * @buffer: [DRIVER] any buffer present | ||
302 | * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux | ||
303 | * @mlock: [INTERN] lock used to prevent simultaneous device state | ||
304 | * changes | ||
305 | * @available_scan_masks: [DRIVER] optional array of allowed bitmasks | ||
306 | * @masklength: [INTERN] the length of the mask established from | ||
307 | * channels | ||
308 | * @active_scan_mask: [INTERN] union of all scan masks requested by buffers | ||
309 | * @scan_timestamp: [INTERN] set if any buffers have requested timestamp | ||
310 | * @scan_index_timestamp:[INTERN] cache of the index to the timestamp | ||
311 | * @trig: [INTERN] current device trigger (buffer modes) | ||
312 | * @pollfunc: [DRIVER] function run on trigger being received | ||
313 | * @channels: [DRIVER] channel specification structure table | ||
314 | * @num_channels: [DRIVER] number of chanels specified in @channels. | ||
315 | * @channel_attr_list: [INTERN] keep track of automatically created channel | ||
316 | * attributes | ||
317 | * @chan_attr_group: [INTERN] group for all attrs in base directory | ||
318 | * @name: [DRIVER] name of the device. | ||
319 | * @info: [DRIVER] callbacks and constant info from driver | ||
320 | * @info_exist_lock: [INTERN] lock to prevent use during removal | ||
321 | * @setup_ops: [DRIVER] callbacks to call before and after buffer | ||
322 | * enable/disable | ||
323 | * @chrdev: [INTERN] associated character device | ||
324 | * @groups: [INTERN] attribute groups | ||
325 | * @groupcounter: [INTERN] index of next attribute group | ||
326 | * @flags: [INTERN] file ops related flags including busy flag. | ||
327 | * @debugfs_dentry: [INTERN] device specific debugfs dentry. | ||
328 | * @cached_reg_addr: [INTERN] cached register address for debugfs reads. | ||
329 | */ | ||
330 | struct iio_dev { | ||
331 | int id; | ||
332 | |||
333 | int modes; | ||
334 | int currentmode; | ||
335 | struct device dev; | ||
336 | |||
337 | struct iio_event_interface *event_interface; | ||
338 | |||
339 | struct iio_buffer *buffer; | ||
340 | int scan_bytes; | ||
341 | struct mutex mlock; | ||
342 | |||
343 | const unsigned long *available_scan_masks; | ||
344 | unsigned masklength; | ||
345 | const unsigned long *active_scan_mask; | ||
346 | bool scan_timestamp; | ||
347 | unsigned scan_index_timestamp; | ||
348 | struct iio_trigger *trig; | ||
349 | struct iio_poll_func *pollfunc; | ||
350 | |||
351 | struct iio_chan_spec const *channels; | ||
352 | int num_channels; | ||
353 | |||
354 | struct list_head channel_attr_list; | ||
355 | struct attribute_group chan_attr_group; | ||
356 | const char *name; | ||
357 | const struct iio_info *info; | ||
358 | struct mutex info_exist_lock; | ||
359 | const struct iio_buffer_setup_ops *setup_ops; | ||
360 | struct cdev chrdev; | ||
361 | #define IIO_MAX_GROUPS 6 | ||
362 | const struct attribute_group *groups[IIO_MAX_GROUPS + 1]; | ||
363 | int groupcounter; | ||
364 | |||
365 | unsigned long flags; | ||
366 | #if defined(CONFIG_DEBUG_FS) | ||
367 | struct dentry *debugfs_dentry; | ||
368 | unsigned cached_reg_addr; | ||
369 | #endif | ||
370 | }; | ||
371 | |||
372 | /** | ||
373 | * iio_find_channel_from_si() - get channel from its scan index | ||
374 | * @indio_dev: device | ||
375 | * @si: scan index to match | ||
376 | */ | ||
377 | const struct iio_chan_spec | ||
378 | *iio_find_channel_from_si(struct iio_dev *indio_dev, int si); | ||
379 | |||
380 | /** | ||
381 | * iio_device_register() - register a device with the IIO subsystem | ||
382 | * @indio_dev: Device structure filled by the device driver | ||
383 | **/ | ||
384 | int iio_device_register(struct iio_dev *indio_dev); | ||
385 | |||
386 | /** | ||
387 | * iio_device_unregister() - unregister a device from the IIO subsystem | ||
388 | * @indio_dev: Device structure representing the device. | ||
389 | **/ | ||
390 | void iio_device_unregister(struct iio_dev *indio_dev); | ||
391 | |||
392 | /** | ||
393 | * iio_push_event() - try to add event to the list for userspace reading | ||
394 | * @indio_dev: IIO device structure | ||
395 | * @ev_code: What event | ||
396 | * @timestamp: When the event occurred | ||
397 | **/ | ||
398 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); | ||
399 | |||
400 | extern struct bus_type iio_bus_type; | ||
401 | |||
402 | /** | ||
403 | * iio_put_device() - reference counted deallocation of struct device | ||
404 | * @dev: the iio_device containing the device | ||
405 | **/ | ||
406 | static inline void iio_put_device(struct iio_dev *indio_dev) | ||
407 | { | ||
408 | if (indio_dev) | ||
409 | put_device(&indio_dev->dev); | ||
410 | }; | ||
411 | |||
412 | /* Can we make this smaller? */ | ||
413 | #define IIO_ALIGN L1_CACHE_BYTES | ||
414 | /** | ||
415 | * iio_allocate_device() - allocate an iio_dev from a driver | ||
416 | * @sizeof_priv: Space to allocate for private structure. | ||
417 | **/ | ||
418 | struct iio_dev *iio_allocate_device(int sizeof_priv); | ||
419 | |||
420 | static inline void *iio_priv(const struct iio_dev *indio_dev) | ||
421 | { | ||
422 | return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN); | ||
423 | } | ||
424 | |||
425 | static inline struct iio_dev *iio_priv_to_dev(void *priv) | ||
426 | { | ||
427 | return (struct iio_dev *)((char *)priv - | ||
428 | ALIGN(sizeof(struct iio_dev), IIO_ALIGN)); | ||
429 | } | ||
430 | |||
431 | /** | ||
432 | * iio_free_device() - free an iio_dev from a driver | ||
433 | * @dev: the iio_dev associated with the device | ||
434 | **/ | ||
435 | void iio_free_device(struct iio_dev *indio_dev); | ||
436 | |||
437 | /** | ||
438 | * iio_buffer_enabled() - helper function to test if the buffer is enabled | ||
439 | * @indio_dev: IIO device info structure for device | ||
440 | **/ | ||
441 | static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) | ||
442 | { | ||
443 | return indio_dev->currentmode | ||
444 | & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE); | ||
445 | }; | ||
446 | |||
447 | /** | ||
448 | * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry | ||
449 | * @indio_dev: IIO device info structure for device | ||
450 | **/ | ||
451 | #if defined(CONFIG_DEBUG_FS) | ||
452 | static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) | ||
453 | { | ||
454 | return indio_dev->debugfs_dentry; | ||
455 | }; | ||
456 | #else | ||
457 | static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) | ||
458 | { | ||
459 | return NULL; | ||
460 | }; | ||
461 | #endif | ||
462 | |||
463 | #endif /* _INDUSTRIAL_IO_H_ */ | ||
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h new file mode 100644 index 000000000000..014d5a13b32b --- /dev/null +++ b/include/linux/iio/kfifo_buf.h | |||
@@ -0,0 +1,8 @@ | |||
1 | |||
2 | #include <linux/kfifo.h> | ||
3 | #include <linux/iio/iio.h> | ||
4 | #include <linux/iio/buffer.h> | ||
5 | |||
6 | struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev); | ||
7 | void iio_kfifo_free(struct iio_buffer *r); | ||
8 | |||
diff --git a/include/linux/iio/machine.h b/include/linux/iio/machine.h new file mode 100644 index 000000000000..0b1f19bfdc44 --- /dev/null +++ b/include/linux/iio/machine.h | |||
@@ -0,0 +1,24 @@ | |||
1 | /* | ||
2 | * Industrial I/O in kernel access map definitions for board files. | ||
3 | * | ||
4 | * Copyright (c) 2011 Jonathan Cameron | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License version 2 as published by | ||
8 | * the Free Software Foundation. | ||
9 | */ | ||
10 | |||
11 | /** | ||
12 | * struct iio_map - description of link between consumer and device channels | ||
13 | * @adc_channel_label: Label used to identify the channel on the provider. | ||
14 | * This is matched against the datasheet_name element | ||
15 | * of struct iio_chan_spec. | ||
16 | * @consumer_dev_name: Name to uniquely identify the consumer device. | ||
17 | * @consumer_channel: Unique name used to idenitify the channel on the | ||
18 | * consumer side. | ||
19 | */ | ||
20 | struct iio_map { | ||
21 | const char *adc_channel_label; | ||
22 | const char *consumer_dev_name; | ||
23 | const char *consumer_channel; | ||
24 | }; | ||
diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h new file mode 100644 index 000000000000..bfedb73b850e --- /dev/null +++ b/include/linux/iio/sysfs.h | |||
@@ -0,0 +1,117 @@ | |||
1 | /* 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 | |||
15 | struct iio_chan_spec; | ||
16 | |||
17 | /** | ||
18 | * struct iio_dev_attr - iio specific device attribute | ||
19 | * @dev_attr: underlying device attribute | ||
20 | * @address: associated register address | ||
21 | * @l: list head for maintaining list of dynamically created attrs. | ||
22 | */ | ||
23 | struct iio_dev_attr { | ||
24 | struct device_attribute dev_attr; | ||
25 | u64 address; | ||
26 | struct list_head l; | ||
27 | struct iio_chan_spec const *c; | ||
28 | }; | ||
29 | |||
30 | #define to_iio_dev_attr(_dev_attr) \ | ||
31 | container_of(_dev_attr, struct iio_dev_attr, dev_attr) | ||
32 | |||
33 | ssize_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 | ||
40 | * @string: attribute string | ||
41 | * @dev_attr: underlying device attribute | ||
42 | */ | ||
43 | struct 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 | |||
51 | /* Some attributes will be hard coded (device dependent) and not require an | ||
52 | 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 | |||
57 | #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 | |||
61 | #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) | ||
64 | |||
65 | #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 | |||
70 | #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)} | ||
74 | |||
75 | /* Generic attributes of onetype or another */ | ||
76 | /** | ||
77 | * IIO_DEV_ATTR_RESET: resets the device | ||
78 | **/ | ||
79 | #define IIO_DEV_ATTR_RESET(_store) \ | ||
80 | IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0) | ||
81 | |||
82 | /** | ||
83 | * 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 | ||
87 | **/ | ||
88 | #define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \ | ||
89 | IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0) | ||
90 | |||
91 | /** | ||
92 | * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies | ||
93 | * @_show: output method for the attribute | ||
94 | * | ||
95 | * May be mode dependent on some devices | ||
96 | **/ | ||
97 | #define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \ | ||
98 | IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0) | ||
99 | /** | ||
100 | * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies | ||
101 | * @_string: frequency string for the attribute | ||
102 | * | ||
103 | * Constant version | ||
104 | **/ | ||
105 | #define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \ | ||
106 | IIO_CONST_ATTR(sampling_frequency_available, _string) | ||
107 | |||
108 | #define IIO_DEV_ATTR_TEMP_RAW(_show) \ | ||
109 | IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0) | ||
110 | |||
111 | #define IIO_CONST_ATTR_TEMP_OFFSET(_string) \ | ||
112 | IIO_CONST_ATTR(in_temp_offset, _string) | ||
113 | |||
114 | #define IIO_CONST_ATTR_TEMP_SCALE(_string) \ | ||
115 | IIO_CONST_ATTR(in_temp_scale, _string) | ||
116 | |||
117 | #endif /* _INDUSTRIAL_IO_SYSFS_H_ */ | ||
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h new file mode 100644 index 000000000000..1cfca231db8f --- /dev/null +++ b/include/linux/iio/trigger.h | |||
@@ -0,0 +1,119 @@ | |||
1 | /* The industrial I/O core, trigger handling functions | ||
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 | #include <linux/irq.h> | ||
10 | #include <linux/module.h> | ||
11 | |||
12 | #ifndef _IIO_TRIGGER_H_ | ||
13 | #define _IIO_TRIGGER_H_ | ||
14 | |||
15 | struct iio_subirq { | ||
16 | bool enabled; | ||
17 | }; | ||
18 | |||
19 | /** | ||
20 | * struct iio_trigger_ops - operations structure for an iio_trigger. | ||
21 | * @owner: used to monitor usage count of the trigger. | ||
22 | * @set_trigger_state: switch on/off the trigger on demand | ||
23 | * @try_reenable: function to reenable the trigger when the | ||
24 | * use count is zero (may be NULL) | ||
25 | * @validate_device: function to validate the device when the | ||
26 | * current trigger gets changed. | ||
27 | * | ||
28 | * This is typically static const within a driver and shared by | ||
29 | * instances of a given device. | ||
30 | **/ | ||
31 | struct iio_trigger_ops { | ||
32 | struct module *owner; | ||
33 | int (*set_trigger_state)(struct iio_trigger *trig, bool state); | ||
34 | int (*try_reenable)(struct iio_trigger *trig); | ||
35 | int (*validate_device)(struct iio_trigger *trig, | ||
36 | struct iio_dev *indio_dev); | ||
37 | }; | ||
38 | |||
39 | |||
40 | /** | ||
41 | * struct iio_trigger - industrial I/O trigger device | ||
42 | * | ||
43 | * @id: [INTERN] unique id number | ||
44 | * @name: [DRIVER] unique name | ||
45 | * @dev: [DRIVER] associated device (if relevant) | ||
46 | * @private_data: [DRIVER] device specific data | ||
47 | * @list: [INTERN] used in maintenance of global trigger list | ||
48 | * @alloc_list: [DRIVER] used for driver specific trigger list | ||
49 | * @use_count: use count for the trigger | ||
50 | * @subirq_chip: [INTERN] associate 'virtual' irq chip. | ||
51 | * @subirq_base: [INTERN] base number for irqs provided by trigger. | ||
52 | * @subirqs: [INTERN] information about the 'child' irqs. | ||
53 | * @pool: [INTERN] bitmap of irqs currently in use. | ||
54 | * @pool_lock: [INTERN] protection of the irq pool. | ||
55 | **/ | ||
56 | struct iio_trigger { | ||
57 | const struct iio_trigger_ops *ops; | ||
58 | int id; | ||
59 | const char *name; | ||
60 | struct device dev; | ||
61 | |||
62 | void *private_data; | ||
63 | struct list_head list; | ||
64 | struct list_head alloc_list; | ||
65 | int use_count; | ||
66 | |||
67 | struct irq_chip subirq_chip; | ||
68 | int subirq_base; | ||
69 | |||
70 | struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER]; | ||
71 | unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)]; | ||
72 | struct mutex pool_lock; | ||
73 | }; | ||
74 | |||
75 | |||
76 | static inline struct iio_trigger *to_iio_trigger(struct device *d) | ||
77 | { | ||
78 | return container_of(d, struct iio_trigger, dev); | ||
79 | }; | ||
80 | |||
81 | static inline void iio_put_trigger(struct iio_trigger *trig) | ||
82 | { | ||
83 | module_put(trig->ops->owner); | ||
84 | put_device(&trig->dev); | ||
85 | }; | ||
86 | |||
87 | static inline void iio_get_trigger(struct iio_trigger *trig) | ||
88 | { | ||
89 | get_device(&trig->dev); | ||
90 | __module_get(trig->ops->owner); | ||
91 | }; | ||
92 | |||
93 | /** | ||
94 | * iio_trigger_register() - register a trigger with the IIO core | ||
95 | * @trig_info: trigger to be registered | ||
96 | **/ | ||
97 | int iio_trigger_register(struct iio_trigger *trig_info); | ||
98 | |||
99 | /** | ||
100 | * iio_trigger_unregister() - unregister a trigger from the core | ||
101 | * @trig_info: trigger to be unregistered | ||
102 | **/ | ||
103 | void iio_trigger_unregister(struct iio_trigger *trig_info); | ||
104 | |||
105 | /** | ||
106 | * iio_trigger_poll() - called on a trigger occurring | ||
107 | * @trig: trigger which occurred | ||
108 | * | ||
109 | * Typically called in relevant hardware interrupt handler. | ||
110 | **/ | ||
111 | void iio_trigger_poll(struct iio_trigger *trig, s64 time); | ||
112 | void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time); | ||
113 | |||
114 | irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); | ||
115 | |||
116 | __printf(1, 2) struct iio_trigger *iio_allocate_trigger(const char *fmt, ...); | ||
117 | void iio_free_trigger(struct iio_trigger *trig); | ||
118 | |||
119 | #endif /* _IIO_TRIGGER_H_ */ | ||
diff --git a/include/linux/iio/trigger_consumer.h b/include/linux/iio/trigger_consumer.h new file mode 100644 index 000000000000..60d64b356945 --- /dev/null +++ b/include/linux/iio/trigger_consumer.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* The industrial I/O core, trigger consumer functions | ||
2 | * | ||
3 | * Copyright (c) 2008-2011 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 | |||
10 | /** | ||
11 | * struct iio_poll_func - poll function pair | ||
12 | * | ||
13 | * @indio_dev: data specific to device (passed into poll func) | ||
14 | * @h: the function that is actually run on trigger | ||
15 | * @thread: threaded interrupt part | ||
16 | * @type: the type of interrupt (basically if oneshot) | ||
17 | * @name: name used to identify the trigger consumer. | ||
18 | * @irq: the corresponding irq as allocated from the | ||
19 | * trigger pool | ||
20 | * @timestamp: some devices need a timestamp grabbed as soon | ||
21 | * as possible after the trigger - hence handler | ||
22 | * passes it via here. | ||
23 | **/ | ||
24 | struct iio_poll_func { | ||
25 | struct iio_dev *indio_dev; | ||
26 | irqreturn_t (*h)(int irq, void *p); | ||
27 | irqreturn_t (*thread)(int irq, void *p); | ||
28 | int type; | ||
29 | char *name; | ||
30 | int irq; | ||
31 | s64 timestamp; | ||
32 | }; | ||
33 | |||
34 | |||
35 | struct iio_poll_func | ||
36 | *iio_alloc_pollfunc(irqreturn_t (*h)(int irq, void *p), | ||
37 | irqreturn_t (*thread)(int irq, void *p), | ||
38 | int type, | ||
39 | struct iio_dev *indio_dev, | ||
40 | const char *fmt, | ||
41 | ...); | ||
42 | void iio_dealloc_pollfunc(struct iio_poll_func *pf); | ||
43 | irqreturn_t iio_pollfunc_store_time(int irq, void *p); | ||
44 | |||
45 | void iio_trigger_notify_done(struct iio_trigger *trig); | ||
46 | |||
47 | /* | ||
48 | * Two functions for common case where all that happens is a pollfunc | ||
49 | * is attached and detached from a trigger | ||
50 | */ | ||
51 | int iio_triggered_buffer_postenable(struct iio_dev *indio_dev); | ||
52 | int iio_triggered_buffer_predisable(struct iio_dev *indio_dev); | ||
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h new file mode 100644 index 000000000000..0c3213666901 --- /dev/null +++ b/include/linux/iio/types.h | |||
@@ -0,0 +1,53 @@ | |||
1 | /* industrial I/O data types needed both in and out of kernel | ||
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 | |||
10 | #ifndef _IIO_TYPES_H_ | ||
11 | #define _IIO_TYPES_H_ | ||
12 | |||
13 | enum iio_chan_type { | ||
14 | /* real channel types */ | ||
15 | IIO_VOLTAGE, | ||
16 | IIO_CURRENT, | ||
17 | IIO_POWER, | ||
18 | IIO_ACCEL, | ||
19 | IIO_ANGL_VEL, | ||
20 | IIO_MAGN, | ||
21 | IIO_LIGHT, | ||
22 | IIO_INTENSITY, | ||
23 | IIO_PROXIMITY, | ||
24 | IIO_TEMP, | ||
25 | IIO_INCLI, | ||
26 | IIO_ROT, | ||
27 | IIO_ANGL, | ||
28 | IIO_TIMESTAMP, | ||
29 | IIO_CAPACITANCE, | ||
30 | }; | ||
31 | |||
32 | enum iio_modifier { | ||
33 | IIO_NO_MOD, | ||
34 | IIO_MOD_X, | ||
35 | IIO_MOD_Y, | ||
36 | IIO_MOD_Z, | ||
37 | IIO_MOD_X_AND_Y, | ||
38 | IIO_MOD_X_AND_Z, | ||
39 | IIO_MOD_Y_AND_Z, | ||
40 | IIO_MOD_X_AND_Y_AND_Z, | ||
41 | IIO_MOD_X_OR_Y, | ||
42 | IIO_MOD_X_OR_Z, | ||
43 | IIO_MOD_Y_OR_Z, | ||
44 | IIO_MOD_X_OR_Y_OR_Z, | ||
45 | IIO_MOD_LIGHT_BOTH, | ||
46 | IIO_MOD_LIGHT_IR, | ||
47 | }; | ||
48 | |||
49 | #define IIO_VAL_INT 1 | ||
50 | #define IIO_VAL_INT_PLUS_MICRO 2 | ||
51 | #define IIO_VAL_INT_PLUS_NANO 3 | ||
52 | |||
53 | #endif /* _IIO_TYPES_H_ */ | ||