2 * Industrial I/O in kernel consumer interface
4 * Copyright (c) 2011 Jonathan Cameron
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.
10 #ifndef _IIO_INKERN_CONSUMER_H_
11 #define _IIO_INKERN_CONSUMER_H_
12 #include <linux/iio/types.h>
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 * @data: Data about the channel used by consumer.
24 struct iio_dev *indio_dev;
25 const struct iio_chan_spec *channel;
30 * iio_channel_get() - get description of all that is needed to access channel.
31 * @name: Unique name of the device as provided in the iio_map
32 * with which the desired provider to consumer mapping
34 * @consumer_channel: Unique name to identify the channel on the consumer
35 * side. This typically describes the channels use within
36 * the consumer. E.g. 'battery_voltage'
38 struct iio_channel *iio_channel_get(const char *name,
39 const char *consumer_channel);
42 * iio_channel_release() - release channels obtained via iio_channel_get
43 * @chan: The channel to be released.
45 void iio_channel_release(struct iio_channel *chan);
48 * iio_channel_get_all() - get all channels associated with a client
49 * @name: name of consumer device.
51 * Returns an array of iio_channel structures terminated with one with
52 * null iio_dev pointer.
53 * This function is used by fairly generic consumers to get all the
54 * channels registered as having this consumer.
56 struct iio_channel *iio_channel_get_all(const char *name);
59 * iio_channel_release_all() - reverse iio_channel_get_all
60 * @chan: Array of channels to be released.
62 void iio_channel_release_all(struct iio_channel *chan);
66 * iio_channel_get_all_cb() - register callback for triggered capture
67 * @name: Name of client device.
68 * @cb: Callback function.
69 * @private: Private data passed to callback.
71 * NB right now we have no ability to mux data from multiple devices.
72 * So if the channels requested come from different devices this will
75 struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
80 * iio_channel_release_all_cb() - release and unregister the callback.
81 * @cb_buffer: The callback buffer that was allocated.
83 void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
86 * iio_channel_start_all_cb() - start the flow of data through callback.
87 * @cb_buff: The callback buffer we are starting.
89 int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
92 * iio_channel_stop_all_cb() - stop the flow of data through the callback.
93 * @cb_buff: The callback buffer we are stopping.
95 void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
98 * iio_channel_cb_get_channels() - get access to the underlying channels.
99 * @cb_buff: The callback buffer from whom we want the channel
102 * This function allows one to obtain information about the channels.
103 * Whilst this may allow direct reading if all buffers are disabled, the
104 * primary aim is to allow drivers that are consuming a channel to query
105 * things like scaling of the channel.
108 *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
111 * iio_read_channel_raw() - read from a given channel
112 * @chan: The channel being queried.
113 * @val: Value read back.
115 * Note raw reads from iio channels are in adc counts and hence
116 * scale will need to be applied if standard units required.
118 int iio_read_channel_raw(struct iio_channel *chan,
122 * iio_read_channel_processed() - read processed value from a given channel
123 * @chan: The channel being queried.
124 * @val: Value read back.
126 * Returns an error code or 0.
128 * This function will read a processed value from a channel. A processed value
129 * means that this value will have the correct unit and not some device internal
130 * representation. If the device does not support reporting a processed value
131 * the function will query the raw value and the channels scale and offset and
132 * do the appropriate transformation.
134 int iio_read_channel_processed(struct iio_channel *chan, int *val);
137 * iio_get_channel_type() - get the type of a channel
138 * @channel: The channel being queried.
139 * @type: The type of the channel.
141 * returns the enum iio_chan_type of the channel
143 int iio_get_channel_type(struct iio_channel *channel,
144 enum iio_chan_type *type);
147 * iio_read_channel_scale() - read the scale value for a channel
148 * @chan: The channel being queried.
149 * @val: First part of value read back.
150 * @val2: Second part of value read back.
152 * Note returns a description of what is in val and val2, such
153 * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
156 int iio_read_channel_scale(struct iio_channel *chan, int *val,
160 * iio_convert_raw_to_processed() - Converts a raw value to a processed value
161 * @chan: The channel being queried
162 * @raw: The raw IIO to convert
163 * @processed: The result of the conversion
164 * @scale: Scale factor to apply during the conversion
166 * Returns an error code or 0.
168 * This function converts a raw value to processed value for a specific channel.
169 * A raw value is the device internal representation of a sample and the value
170 * returned by iio_read_channel_raw, so the unit of that value is device
171 * depended. A processed value on the other hand is value has a normed unit
172 * according with the IIO specification.
174 * The scale factor allows to increase the precession of the returned value. For
175 * a scale factor of 1 the function will return the result in the normal IIO
176 * unit for the channel type. E.g. millivolt for voltage channels, if you want
177 * nanovolts instead pass 1000 as the scale factor.
179 int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
180 int *processed, unsigned int scale);