blob: a85787ac66abd1cbcdfa874aa26dd4f7eb279d7f [file] [log] [blame]
Jonathan Camerone27d75d2012-02-15 19:48:01 +00001/*
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_
Lars-Peter Clausen88238fe2012-08-17 16:57:00 +010011#define _IIO_INKERN_CONSUMER_H_
Greg Kroah-Hartman9f488ba2012-11-13 10:46:33 -080012
13#include <linux/types.h>
Jonathan Cameron06458e22012-04-25 15:54:58 +010014#include <linux/iio/types.h>
Jonathan Camerone27d75d2012-02-15 19:48:01 +000015
16struct iio_dev;
17struct iio_chan_spec;
Guenter Roeckca7d98d2013-01-31 21:43:00 +000018struct device;
Jonathan Camerone27d75d2012-02-15 19:48:01 +000019
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.
Jonathan Cameron04644152012-06-30 20:06:00 +010024 * @data: Data about the channel used by consumer.
Jonathan Camerone27d75d2012-02-15 19:48:01 +000025 */
26struct iio_channel {
27 struct iio_dev *indio_dev;
28 const struct iio_chan_spec *channel;
Jonathan Cameron04644152012-06-30 20:06:00 +010029 void *data;
Jonathan Camerone27d75d2012-02-15 19:48:01 +000030};
31
32/**
33 * iio_channel_get() - get description of all that is needed to access channel.
34 * @name: Unique name of the device as provided in the iio_map
35 * with which the desired provider to consumer mapping
36 * was registered.
37 * @consumer_channel: Unique name to identify the channel on the consumer
38 * side. This typically describes the channels use within
39 * the consumer. E.g. 'battery_voltage'
40 */
Jonathan Cameron314be142012-05-01 21:04:24 +010041struct iio_channel *iio_channel_get(const char *name,
42 const char *consumer_channel);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000043
44/**
Jonathan Cameron314be142012-05-01 21:04:24 +010045 * iio_channel_release() - release channels obtained via iio_channel_get
Jonathan Camerone27d75d2012-02-15 19:48:01 +000046 * @chan: The channel to be released.
47 */
Jonathan Cameron314be142012-05-01 21:04:24 +010048void iio_channel_release(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000049
50/**
Jonathan Cameron314be142012-05-01 21:04:24 +010051 * iio_channel_get_all() - get all channels associated with a client
Guenter Roeckca7d98d2013-01-31 21:43:00 +000052 * @dev: Pointer to consumer device.
Jonathan Camerone27d75d2012-02-15 19:48:01 +000053 *
54 * Returns an array of iio_channel structures terminated with one with
55 * null iio_dev pointer.
56 * This function is used by fairly generic consumers to get all the
57 * channels registered as having this consumer.
58 */
Guenter Roeckca7d98d2013-01-31 21:43:00 +000059struct iio_channel *iio_channel_get_all(struct device *dev);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000060
61/**
Jonathan Cameron314be142012-05-01 21:04:24 +010062 * iio_channel_release_all() - reverse iio_channel_get_all
Jonathan Camerone27d75d2012-02-15 19:48:01 +000063 * @chan: Array of channels to be released.
64 */
Jonathan Cameron314be142012-05-01 21:04:24 +010065void iio_channel_release_all(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000066
Jonathan Cameron92d10792012-06-30 20:06:00 +010067struct iio_cb_buffer;
68/**
69 * iio_channel_get_all_cb() - register callback for triggered capture
Guenter Roeckca7d98d2013-01-31 21:43:00 +000070 * @dev: Pointer to client device.
Jonathan Cameron92d10792012-06-30 20:06:00 +010071 * @cb: Callback function.
72 * @private: Private data passed to callback.
73 *
74 * NB right now we have no ability to mux data from multiple devices.
75 * So if the channels requested come from different devices this will
76 * fail.
77 */
Guenter Roeckca7d98d2013-01-31 21:43:00 +000078struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev,
Jonathan Cameron92d10792012-06-30 20:06:00 +010079 int (*cb)(u8 *data,
80 void *private),
81 void *private);
82/**
83 * iio_channel_release_all_cb() - release and unregister the callback.
84 * @cb_buffer: The callback buffer that was allocated.
85 */
86void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
87
88/**
89 * iio_channel_start_all_cb() - start the flow of data through callback.
90 * @cb_buff: The callback buffer we are starting.
91 */
92int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
93
94/**
95 * iio_channel_stop_all_cb() - stop the flow of data through the callback.
96 * @cb_buff: The callback buffer we are stopping.
97 */
98void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
99
100/**
101 * iio_channel_cb_get_channels() - get access to the underlying channels.
102 * @cb_buff: The callback buffer from whom we want the channel
103 * information.
104 *
105 * This function allows one to obtain information about the channels.
106 * Whilst this may allow direct reading if all buffers are disabled, the
107 * primary aim is to allow drivers that are consuming a channel to query
108 * things like scaling of the channel.
109 */
110struct iio_channel
111*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
112
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000113/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100114 * iio_read_channel_raw() - read from a given channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100115 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000116 * @val: Value read back.
117 *
118 * Note raw reads from iio channels are in adc counts and hence
119 * scale will need to be applied if standard units required.
120 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100121int iio_read_channel_raw(struct iio_channel *chan,
122 int *val);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000123
124/**
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100125 * iio_read_channel_processed() - read processed value from a given channel
126 * @chan: The channel being queried.
127 * @val: Value read back.
128 *
129 * Returns an error code or 0.
130 *
131 * This function will read a processed value from a channel. A processed value
132 * means that this value will have the correct unit and not some device internal
133 * representation. If the device does not support reporting a processed value
134 * the function will query the raw value and the channels scale and offset and
135 * do the appropriate transformation.
136 */
137int iio_read_channel_processed(struct iio_channel *chan, int *val);
138
139/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100140 * iio_get_channel_type() - get the type of a channel
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000141 * @channel: The channel being queried.
142 * @type: The type of the channel.
143 *
144 * returns the enum iio_chan_type of the channel
145 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100146int iio_get_channel_type(struct iio_channel *channel,
147 enum iio_chan_type *type);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000148
149/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100150 * iio_read_channel_scale() - read the scale value for a channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100151 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000152 * @val: First part of value read back.
153 * @val2: Second part of value read back.
154 *
155 * Note returns a description of what is in val and val2, such
156 * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
157 * + val2/1e6
158 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100159int iio_read_channel_scale(struct iio_channel *chan, int *val,
160 int *val2);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000161
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100162/**
163 * iio_convert_raw_to_processed() - Converts a raw value to a processed value
164 * @chan: The channel being queried
165 * @raw: The raw IIO to convert
166 * @processed: The result of the conversion
167 * @scale: Scale factor to apply during the conversion
168 *
169 * Returns an error code or 0.
170 *
171 * This function converts a raw value to processed value for a specific channel.
172 * A raw value is the device internal representation of a sample and the value
173 * returned by iio_read_channel_raw, so the unit of that value is device
174 * depended. A processed value on the other hand is value has a normed unit
175 * according with the IIO specification.
176 *
177 * The scale factor allows to increase the precession of the returned value. For
178 * a scale factor of 1 the function will return the result in the normal IIO
179 * unit for the channel type. E.g. millivolt for voltage channels, if you want
180 * nanovolts instead pass 1000 as the scale factor.
181 */
182int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
183 int *processed, unsigned int scale);
184
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000185#endif