]>
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 JC |
50 | |
51 | /** | |
314be14b | 52 | * iio_channel_get_all() - get all channels associated with a client |
ca7d98db | 53 | * @dev: Pointer to consumer device. |
e27d75d7 JC |
54 | * |
55 | * Returns an array of iio_channel structures terminated with one with | |
56 | * null iio_dev pointer. | |
57 | * This function is used by fairly generic consumers to get all the | |
58 | * channels registered as having this consumer. | |
59 | */ | |
ca7d98db | 60 | struct iio_channel *iio_channel_get_all(struct device *dev); |
e27d75d7 JC |
61 | |
62 | /** | |
314be14b | 63 | * iio_channel_release_all() - reverse iio_channel_get_all |
e27d75d7 JC |
64 | * @chan: Array of channels to be released. |
65 | */ | |
314be14b | 66 | void iio_channel_release_all(struct iio_channel *chan); |
e27d75d7 | 67 | |
92d1079b JC |
68 | struct iio_cb_buffer; |
69 | /** | |
70 | * iio_channel_get_all_cb() - register callback for triggered capture | |
ca7d98db | 71 | * @dev: Pointer to client device. |
92d1079b JC |
72 | * @cb: Callback function. |
73 | * @private: Private data passed to callback. | |
74 | * | |
75 | * NB right now we have no ability to mux data from multiple devices. | |
76 | * So if the channels requested come from different devices this will | |
77 | * fail. | |
78 | */ | |
ca7d98db | 79 | struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, |
5d65d920 | 80 | int (*cb)(const void *data, |
92d1079b JC |
81 | void *private), |
82 | void *private); | |
83 | /** | |
84 | * iio_channel_release_all_cb() - release and unregister the callback. | |
85 | * @cb_buffer: The callback buffer that was allocated. | |
86 | */ | |
87 | void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer); | |
88 | ||
89 | /** | |
90 | * iio_channel_start_all_cb() - start the flow of data through callback. | |
91 | * @cb_buff: The callback buffer we are starting. | |
92 | */ | |
93 | int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff); | |
94 | ||
95 | /** | |
96 | * iio_channel_stop_all_cb() - stop the flow of data through the callback. | |
97 | * @cb_buff: The callback buffer we are stopping. | |
98 | */ | |
99 | void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff); | |
100 | ||
101 | /** | |
102 | * iio_channel_cb_get_channels() - get access to the underlying channels. | |
e52e9519 | 103 | * @cb_buffer: The callback buffer from whom we want the channel |
92d1079b JC |
104 | * information. |
105 | * | |
106 | * This function allows one to obtain information about the channels. | |
107 | * Whilst this may allow direct reading if all buffers are disabled, the | |
108 | * primary aim is to allow drivers that are consuming a channel to query | |
109 | * things like scaling of the channel. | |
110 | */ | |
111 | struct iio_channel | |
112 | *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer); | |
113 | ||
e27d75d7 | 114 | /** |
314be14b | 115 | * iio_read_channel_raw() - read from a given channel |
45f010ba | 116 | * @chan: The channel being queried. |
e27d75d7 JC |
117 | * @val: Value read back. |
118 | * | |
119 | * Note raw reads from iio channels are in adc counts and hence | |
120 | * scale will need to be applied if standard units required. | |
121 | */ | |
314be14b JC |
122 | int iio_read_channel_raw(struct iio_channel *chan, |
123 | int *val); | |
e27d75d7 | 124 | |
476d4af2 SR |
125 | /** |
126 | * iio_read_channel_average_raw() - read from a given channel | |
127 | * @chan: The channel being queried. | |
128 | * @val: Value read back. | |
129 | * | |
130 | * Note raw reads from iio channels are in adc counts and hence | |
131 | * scale will need to be applied if standard units required. | |
132 | * | |
133 | * In opposit to the normal iio_read_channel_raw this function | |
134 | * returns the average of multiple reads. | |
135 | */ | |
136 | int iio_read_channel_average_raw(struct iio_channel *chan, int *val); | |
137 | ||
48e44ce0 LPC |
138 | /** |
139 | * iio_read_channel_processed() - read processed value from a given channel | |
140 | * @chan: The channel being queried. | |
141 | * @val: Value read back. | |
142 | * | |
143 | * Returns an error code or 0. | |
144 | * | |
145 | * This function will read a processed value from a channel. A processed value | |
146 | * means that this value will have the correct unit and not some device internal | |
147 | * representation. If the device does not support reporting a processed value | |
148 | * the function will query the raw value and the channels scale and offset and | |
149 | * do the appropriate transformation. | |
150 | */ | |
151 | int iio_read_channel_processed(struct iio_channel *chan, int *val); | |
152 | ||
f9380e71 DES |
153 | /** |
154 | * iio_write_channel_raw() - write to a given channel | |
155 | * @chan: The channel being queried. | |
156 | * @val: Value being written. | |
157 | * | |
158 | * Note raw writes to iio channels are in dac counts and hence | |
159 | * scale will need to be applied if standard units required. | |
160 | */ | |
161 | int iio_write_channel_raw(struct iio_channel *chan, int val); | |
162 | ||
e27d75d7 | 163 | /** |
314be14b | 164 | * iio_get_channel_type() - get the type of a channel |
e27d75d7 JC |
165 | * @channel: The channel being queried. |
166 | * @type: The type of the channel. | |
167 | * | |
168 | * returns the enum iio_chan_type of the channel | |
169 | */ | |
314be14b JC |
170 | int iio_get_channel_type(struct iio_channel *channel, |
171 | enum iio_chan_type *type); | |
e27d75d7 JC |
172 | |
173 | /** | |
314be14b | 174 | * iio_read_channel_scale() - read the scale value for a channel |
45f010ba | 175 | * @chan: The channel being queried. |
e27d75d7 JC |
176 | * @val: First part of value read back. |
177 | * @val2: Second part of value read back. | |
178 | * | |
179 | * Note returns a description of what is in val and val2, such | |
180 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val | |
181 | * + val2/1e6 | |
182 | */ | |
314be14b JC |
183 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
184 | int *val2); | |
e27d75d7 | 185 | |
48e44ce0 LPC |
186 | /** |
187 | * iio_convert_raw_to_processed() - Converts a raw value to a processed value | |
188 | * @chan: The channel being queried | |
189 | * @raw: The raw IIO to convert | |
190 | * @processed: The result of the conversion | |
191 | * @scale: Scale factor to apply during the conversion | |
192 | * | |
193 | * Returns an error code or 0. | |
194 | * | |
195 | * This function converts a raw value to processed value for a specific channel. | |
196 | * A raw value is the device internal representation of a sample and the value | |
197 | * returned by iio_read_channel_raw, so the unit of that value is device | |
198 | * depended. A processed value on the other hand is value has a normed unit | |
199 | * according with the IIO specification. | |
200 | * | |
201 | * The scale factor allows to increase the precession of the returned value. For | |
202 | * a scale factor of 1 the function will return the result in the normal IIO | |
203 | * unit for the channel type. E.g. millivolt for voltage channels, if you want | |
09546a30 | 204 | * nanovolts instead pass 1000000 as the scale factor. |
48e44ce0 LPC |
205 | */ |
206 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, | |
207 | int *processed, unsigned int scale); | |
208 | ||
e27d75d7 | 209 | #endif |