]>
Commit | Line | Data |
---|---|---|
e27d75d7 JC |
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_ | |
88238fef | 11 | #define _IIO_INKERN_CONSUMER_H_ |
9f488ba8 GKH |
12 | |
13 | #include <linux/types.h> | |
06458e27 | 14 | #include <linux/iio/types.h> |
e27d75d7 JC |
15 | |
16 | struct iio_dev; | |
17 | struct iio_chan_spec; | |
ca7d98db | 18 | struct device; |
e27d75d7 JC |
19 | |
20 | /** | |
21 | * struct iio_channel - everything needed for a consumer to use a channel | |
22 | * @indio_dev: Device on which the channel exists. | |
23 | * @channel: Full description of the channel. | |
0464415d | 24 | * @data: Data about the channel used by consumer. |
e27d75d7 JC |
25 | */ |
26 | struct iio_channel { | |
27 | struct iio_dev *indio_dev; | |
28 | const struct iio_chan_spec *channel; | |
0464415d | 29 | void *data; |
e27d75d7 JC |
30 | }; |
31 | ||
32 | /** | |
33 | * iio_channel_get() - get description of all that is needed to access channel. | |
5aa57f0a GR |
34 | * @dev: Pointer to consumer device. Device name must match |
35 | * the name of the device as provided in the iio_map | |
e27d75d7 JC |
36 | * with which the desired provider to consumer mapping |
37 | * was registered. | |
38 | * @consumer_channel: Unique name to identify the channel on the consumer | |
39 | * side. This typically describes the channels use within | |
40 | * the consumer. E.g. 'battery_voltage' | |
41 | */ | |
5aa57f0a | 42 | struct iio_channel *iio_channel_get(struct device *dev, |
314be14b | 43 | const char *consumer_channel); |
e27d75d7 JC |
44 | |
45 | /** | |
314be14b | 46 | * iio_channel_release() - release channels obtained via iio_channel_get |
e27d75d7 JC |
47 | * @chan: The channel to be released. |
48 | */ | |
314be14b | 49 | void iio_channel_release(struct iio_channel *chan); |
e27d75d7 | 50 | |
8bf872d8 LD |
51 | /** |
52 | * devm_iio_channel_get() - Resource managed version of iio_channel_get(). | |
53 | * @dev: Pointer to consumer device. Device name must match | |
54 | * the name of the device as provided in the iio_map | |
55 | * with which the desired provider to consumer mapping | |
56 | * was registered. | |
57 | * @consumer_channel: Unique name to identify the channel on the consumer | |
58 | * side. This typically describes the channels use within | |
59 | * the consumer. E.g. 'battery_voltage' | |
60 | * | |
61 | * Returns a pointer to negative errno if it is not able to get the iio channel | |
62 | * otherwise returns valid pointer for iio channel. | |
63 | * | |
64 | * The allocated iio channel is automatically released when the device is | |
65 | * unbound. | |
66 | */ | |
67 | struct iio_channel *devm_iio_channel_get(struct device *dev, | |
68 | const char *consumer_channel); | |
69 | /** | |
70 | * devm_iio_channel_release() - Resource managed version of | |
71 | * iio_channel_release(). | |
72 | * @dev: Pointer to consumer device for which resource | |
73 | * is allocared. | |
74 | * @chan: The channel to be released. | |
75 | */ | |
76 | void devm_iio_channel_release(struct device *dev, struct iio_channel *chan); | |
77 | ||
e27d75d7 | 78 | /** |
314be14b | 79 | * iio_channel_get_all() - get all channels associated with a client |
ca7d98db | 80 | * @dev: Pointer to consumer device. |
e27d75d7 JC |
81 | * |
82 | * Returns an array of iio_channel structures terminated with one with | |
83 | * null iio_dev pointer. | |
84 | * This function is used by fairly generic consumers to get all the | |
85 | * channels registered as having this consumer. | |
86 | */ | |
ca7d98db | 87 | struct iio_channel *iio_channel_get_all(struct device *dev); |
e27d75d7 JC |
88 | |
89 | /** | |
314be14b | 90 | * iio_channel_release_all() - reverse iio_channel_get_all |
e27d75d7 JC |
91 | * @chan: Array of channels to be released. |
92 | */ | |
314be14b | 93 | void iio_channel_release_all(struct iio_channel *chan); |
e27d75d7 | 94 | |
efc2c013 LD |
95 | /** |
96 | * devm_iio_channel_get_all() - Resource managed version of | |
97 | * iio_channel_get_all(). | |
98 | * @dev: Pointer to consumer device. | |
99 | * | |
100 | * Returns a pointer to negative errno if it is not able to get the iio channel | |
101 | * otherwise returns an array of iio_channel structures terminated with one with | |
102 | * null iio_dev pointer. | |
103 | * | |
104 | * This function is used by fairly generic consumers to get all the | |
105 | * channels registered as having this consumer. | |
106 | * | |
107 | * The allocated iio channels are automatically released when the device is | |
108 | * unbounded. | |
109 | */ | |
110 | struct iio_channel *devm_iio_channel_get_all(struct device *dev); | |
111 | ||
112 | /** | |
113 | * devm_iio_channel_release_all() - Resource managed version of | |
114 | * iio_channel_release_all(). | |
115 | * @dev: Pointer to consumer device for which resource | |
116 | * is allocared. | |
117 | * @chan: Array channel to be released. | |
118 | */ | |
119 | void devm_iio_channel_release_all(struct device *dev, struct iio_channel *chan); | |
120 | ||
92d1079b JC |
121 | struct iio_cb_buffer; |
122 | /** | |
123 | * iio_channel_get_all_cb() - register callback for triggered capture | |
ca7d98db | 124 | * @dev: Pointer to client device. |
92d1079b JC |
125 | * @cb: Callback function. |
126 | * @private: Private data passed to callback. | |
127 | * | |
128 | * NB right now we have no ability to mux data from multiple devices. | |
129 | * So if the channels requested come from different devices this will | |
130 | * fail. | |
131 | */ | |
ca7d98db | 132 | struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, |
5d65d920 | 133 | int (*cb)(const void *data, |
92d1079b JC |
134 | void *private), |
135 | void *private); | |
16cbca06 AP |
136 | /** |
137 | * iio_channel_cb_set_buffer_watermark() - set the buffer watermark. | |
138 | * @cb_buffer: The callback buffer from whom we want the channel | |
139 | * information. | |
140 | * @watermark: buffer watermark in bytes. | |
141 | * | |
142 | * This function allows to configure the buffer watermark. | |
143 | */ | |
144 | int iio_channel_cb_set_buffer_watermark(struct iio_cb_buffer *cb_buffer, | |
145 | size_t watermark); | |
146 | ||
92d1079b JC |
147 | /** |
148 | * iio_channel_release_all_cb() - release and unregister the callback. | |
149 | * @cb_buffer: The callback buffer that was allocated. | |
150 | */ | |
151 | void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer); | |
152 | ||
153 | /** | |
154 | * iio_channel_start_all_cb() - start the flow of data through callback. | |
155 | * @cb_buff: The callback buffer we are starting. | |
156 | */ | |
157 | int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff); | |
158 | ||
159 | /** | |
160 | * iio_channel_stop_all_cb() - stop the flow of data through the callback. | |
161 | * @cb_buff: The callback buffer we are stopping. | |
162 | */ | |
163 | void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff); | |
164 | ||
165 | /** | |
166 | * iio_channel_cb_get_channels() - get access to the underlying channels. | |
e52e9519 | 167 | * @cb_buffer: The callback buffer from whom we want the channel |
92d1079b JC |
168 | * information. |
169 | * | |
170 | * This function allows one to obtain information about the channels. | |
171 | * Whilst this may allow direct reading if all buffers are disabled, the | |
172 | * primary aim is to allow drivers that are consuming a channel to query | |
173 | * things like scaling of the channel. | |
174 | */ | |
175 | struct iio_channel | |
176 | *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer); | |
177 | ||
adca058b MR |
178 | /** |
179 | * iio_channel_cb_get_iio_dev() - get access to the underlying device. | |
180 | * @cb_buffer: The callback buffer from whom we want the device | |
181 | * information. | |
182 | * | |
183 | * This function allows one to obtain information about the device. | |
184 | * The primary aim is to allow drivers that are consuming a device to query | |
185 | * things like current trigger. | |
186 | */ | |
187 | struct iio_dev | |
188 | *iio_channel_cb_get_iio_dev(const struct iio_cb_buffer *cb_buffer); | |
189 | ||
e27d75d7 | 190 | /** |
314be14b | 191 | * iio_read_channel_raw() - read from a given channel |
45f010ba | 192 | * @chan: The channel being queried. |
e27d75d7 JC |
193 | * @val: Value read back. |
194 | * | |
195 | * Note raw reads from iio channels are in adc counts and hence | |
196 | * scale will need to be applied if standard units required. | |
197 | */ | |
314be14b JC |
198 | int iio_read_channel_raw(struct iio_channel *chan, |
199 | int *val); | |
e27d75d7 | 200 | |
476d4af2 SR |
201 | /** |
202 | * iio_read_channel_average_raw() - read from a given channel | |
203 | * @chan: The channel being queried. | |
204 | * @val: Value read back. | |
205 | * | |
206 | * Note raw reads from iio channels are in adc counts and hence | |
207 | * scale will need to be applied if standard units required. | |
208 | * | |
209 | * In opposit to the normal iio_read_channel_raw this function | |
210 | * returns the average of multiple reads. | |
211 | */ | |
212 | int iio_read_channel_average_raw(struct iio_channel *chan, int *val); | |
213 | ||
48e44ce0 LPC |
214 | /** |
215 | * iio_read_channel_processed() - read processed value from a given channel | |
216 | * @chan: The channel being queried. | |
217 | * @val: Value read back. | |
218 | * | |
219 | * Returns an error code or 0. | |
220 | * | |
221 | * This function will read a processed value from a channel. A processed value | |
222 | * means that this value will have the correct unit and not some device internal | |
223 | * representation. If the device does not support reporting a processed value | |
224 | * the function will query the raw value and the channels scale and offset and | |
225 | * do the appropriate transformation. | |
226 | */ | |
227 | int iio_read_channel_processed(struct iio_channel *chan, int *val); | |
228 | ||
34739a21 AP |
229 | /** |
230 | * iio_write_channel_attribute() - Write values to the device attribute. | |
231 | * @chan: The channel being queried. | |
232 | * @val: Value being written. | |
233 | * @val2: Value being written.val2 use depends on attribute type. | |
234 | * @attribute: info attribute to be read. | |
235 | * | |
236 | * Returns an error code or 0. | |
237 | */ | |
238 | int iio_write_channel_attribute(struct iio_channel *chan, int val, | |
239 | int val2, enum iio_chan_info_enum attribute); | |
240 | ||
241 | /** | |
242 | * iio_read_channel_attribute() - Read values from the device attribute. | |
243 | * @chan: The channel being queried. | |
244 | * @val: Value being written. | |
245 | * @val2: Value being written.Val2 use depends on attribute type. | |
246 | * @attribute: info attribute to be written. | |
247 | * | |
248 | * Returns an error code if failed. Else returns a description of what is in val | |
249 | * and val2, such as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val | |
250 | * + val2/1e6 | |
251 | */ | |
252 | int iio_read_channel_attribute(struct iio_channel *chan, int *val, | |
253 | int *val2, enum iio_chan_info_enum attribute); | |
254 | ||
f9380e71 DB |
255 | /** |
256 | * iio_write_channel_raw() - write to a given channel | |
257 | * @chan: The channel being queried. | |
258 | * @val: Value being written. | |
259 | * | |
260 | * Note raw writes to iio channels are in dac counts and hence | |
261 | * scale will need to be applied if standard units required. | |
262 | */ | |
263 | int iio_write_channel_raw(struct iio_channel *chan, int val); | |
264 | ||
00c5f80c PR |
265 | /** |
266 | * iio_read_max_channel_raw() - read maximum available raw value from a given | |
267 | * channel, i.e. the maximum possible value. | |
268 | * @chan: The channel being queried. | |
269 | * @val: Value read back. | |
270 | * | |
271 | * Note raw reads from iio channels are in adc counts and hence | |
272 | * scale will need to be applied if standard units are required. | |
273 | */ | |
274 | int iio_read_max_channel_raw(struct iio_channel *chan, int *val); | |
275 | ||
276 | /** | |
277 | * iio_read_avail_channel_raw() - read available raw values from a given channel | |
278 | * @chan: The channel being queried. | |
279 | * @vals: Available values read back. | |
280 | * @length: Number of entries in vals. | |
281 | * | |
282 | * Returns an error code, IIO_AVAIL_RANGE or IIO_AVAIL_LIST. | |
283 | * | |
284 | * For ranges, three vals are always returned; min, step and max. | |
285 | * For lists, all the possible values are enumerated. | |
286 | * | |
287 | * Note raw available values from iio channels are in adc counts and | |
288 | * hence scale will need to be applied if standard units are required. | |
289 | */ | |
290 | int iio_read_avail_channel_raw(struct iio_channel *chan, | |
291 | const int **vals, int *length); | |
292 | ||
e27d75d7 | 293 | /** |
314be14b | 294 | * iio_get_channel_type() - get the type of a channel |
e27d75d7 JC |
295 | * @channel: The channel being queried. |
296 | * @type: The type of the channel. | |
297 | * | |
298 | * returns the enum iio_chan_type of the channel | |
299 | */ | |
314be14b JC |
300 | int iio_get_channel_type(struct iio_channel *channel, |
301 | enum iio_chan_type *type); | |
e27d75d7 | 302 | |
0023e67d MR |
303 | /** |
304 | * iio_read_channel_offset() - read the offset value for a channel | |
305 | * @chan: The channel being queried. | |
306 | * @val: First part of value read back. | |
307 | * @val2: Second part of value read back. | |
308 | * | |
309 | * Note returns a description of what is in val and val2, such | |
310 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val | |
311 | * + val2/1e6 | |
312 | */ | |
313 | int iio_read_channel_offset(struct iio_channel *chan, int *val, | |
314 | int *val2); | |
315 | ||
e27d75d7 | 316 | /** |
314be14b | 317 | * iio_read_channel_scale() - read the scale value for a channel |
45f010ba | 318 | * @chan: The channel being queried. |
e27d75d7 JC |
319 | * @val: First part of value read back. |
320 | * @val2: Second part of value read back. | |
321 | * | |
322 | * Note returns a description of what is in val and val2, such | |
323 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val | |
324 | * + val2/1e6 | |
325 | */ | |
314be14b JC |
326 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
327 | int *val2); | |
e27d75d7 | 328 | |
48e44ce0 LPC |
329 | /** |
330 | * iio_convert_raw_to_processed() - Converts a raw value to a processed value | |
331 | * @chan: The channel being queried | |
332 | * @raw: The raw IIO to convert | |
333 | * @processed: The result of the conversion | |
334 | * @scale: Scale factor to apply during the conversion | |
335 | * | |
336 | * Returns an error code or 0. | |
337 | * | |
338 | * This function converts a raw value to processed value for a specific channel. | |
339 | * A raw value is the device internal representation of a sample and the value | |
340 | * returned by iio_read_channel_raw, so the unit of that value is device | |
341 | * depended. A processed value on the other hand is value has a normed unit | |
342 | * according with the IIO specification. | |
343 | * | |
344 | * The scale factor allows to increase the precession of the returned value. For | |
345 | * a scale factor of 1 the function will return the result in the normal IIO | |
346 | * unit for the channel type. E.g. millivolt for voltage channels, if you want | |
09546a30 | 347 | * nanovolts instead pass 1000000 as the scale factor. |
48e44ce0 LPC |
348 | */ |
349 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, | |
350 | int *processed, unsigned int scale); | |
351 | ||
8a848e75 PR |
352 | /** |
353 | * iio_get_channel_ext_info_count() - get number of ext_info attributes | |
354 | * connected to the channel. | |
355 | * @chan: The channel being queried | |
356 | * | |
357 | * Returns the number of ext_info attributes | |
358 | */ | |
359 | unsigned int iio_get_channel_ext_info_count(struct iio_channel *chan); | |
360 | ||
361 | /** | |
362 | * iio_read_channel_ext_info() - read ext_info attribute from a given channel | |
363 | * @chan: The channel being queried. | |
364 | * @attr: The ext_info attribute to read. | |
365 | * @buf: Where to store the attribute value. Assumed to hold | |
366 | * at least PAGE_SIZE bytes. | |
367 | * | |
368 | * Returns the number of bytes written to buf (perhaps w/o zero termination; | |
369 | * it need not even be a string), or an error code. | |
370 | */ | |
371 | ssize_t iio_read_channel_ext_info(struct iio_channel *chan, | |
372 | const char *attr, char *buf); | |
373 | ||
374 | /** | |
375 | * iio_write_channel_ext_info() - write ext_info attribute from a given channel | |
376 | * @chan: The channel being queried. | |
377 | * @attr: The ext_info attribute to read. | |
378 | * @buf: The new attribute value. Strings needs to be zero- | |
379 | * terminated, but the terminator should not be included | |
380 | * in the below len. | |
381 | * @len: The size of the new attribute value. | |
382 | * | |
383 | * Returns the number of accepted bytes, which should be the same as len. | |
384 | * An error code can also be returned. | |
385 | */ | |
386 | ssize_t iio_write_channel_ext_info(struct iio_channel *chan, const char *attr, | |
387 | const char *buf, size_t len); | |
388 | ||
e27d75d7 | 389 | #endif |