blob: 16c35ac045bd7a1ff9ff40fe0e4e41cc3cacb1da [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;
18
19/**
20 * struct iio_channel - everything needed for a consumer to use a channel
21 * @indio_dev: Device on which the channel exists.
22 * @channel: Full description of the channel.
Jonathan Cameron04644152012-06-30 20:06:00 +010023 * @data: Data about the channel used by consumer.
Jonathan Camerone27d75d2012-02-15 19:48:01 +000024 */
25struct iio_channel {
26 struct iio_dev *indio_dev;
27 const struct iio_chan_spec *channel;
Jonathan Cameron04644152012-06-30 20:06:00 +010028 void *data;
Jonathan Camerone27d75d2012-02-15 19:48:01 +000029};
30
31/**
32 * iio_channel_get() - get description of all that is needed to access channel.
33 * @name: Unique name of the device as provided in the iio_map
34 * with which the desired provider to consumer mapping
35 * was registered.
36 * @consumer_channel: Unique name to identify the channel on the consumer
37 * side. This typically describes the channels use within
38 * the consumer. E.g. 'battery_voltage'
39 */
Jonathan Cameron314be142012-05-01 21:04:24 +010040struct iio_channel *iio_channel_get(const char *name,
41 const char *consumer_channel);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000042
43/**
Jonathan Cameron314be142012-05-01 21:04:24 +010044 * iio_channel_release() - release channels obtained via iio_channel_get
Jonathan Camerone27d75d2012-02-15 19:48:01 +000045 * @chan: The channel to be released.
46 */
Jonathan Cameron314be142012-05-01 21:04:24 +010047void iio_channel_release(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000048
49/**
Jonathan Cameron314be142012-05-01 21:04:24 +010050 * iio_channel_get_all() - get all channels associated with a client
Jonathan Camerone27d75d2012-02-15 19:48:01 +000051 * @name: name of consumer device.
52 *
53 * Returns an array of iio_channel structures terminated with one with
54 * null iio_dev pointer.
55 * This function is used by fairly generic consumers to get all the
56 * channels registered as having this consumer.
57 */
Jonathan Cameron314be142012-05-01 21:04:24 +010058struct iio_channel *iio_channel_get_all(const char *name);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000059
60/**
Jonathan Cameron314be142012-05-01 21:04:24 +010061 * iio_channel_release_all() - reverse iio_channel_get_all
Jonathan Camerone27d75d2012-02-15 19:48:01 +000062 * @chan: Array of channels to be released.
63 */
Jonathan Cameron314be142012-05-01 21:04:24 +010064void iio_channel_release_all(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000065
Jonathan Cameron92d10792012-06-30 20:06:00 +010066struct iio_cb_buffer;
67/**
68 * iio_channel_get_all_cb() - register callback for triggered capture
69 * @name: Name of client device.
70 * @cb: Callback function.
71 * @private: Private data passed to callback.
72 *
73 * NB right now we have no ability to mux data from multiple devices.
74 * So if the channels requested come from different devices this will
75 * fail.
76 */
77struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
78 int (*cb)(u8 *data,
79 void *private),
80 void *private);
81/**
82 * iio_channel_release_all_cb() - release and unregister the callback.
83 * @cb_buffer: The callback buffer that was allocated.
84 */
85void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
86
87/**
88 * iio_channel_start_all_cb() - start the flow of data through callback.
89 * @cb_buff: The callback buffer we are starting.
90 */
91int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
92
93/**
94 * iio_channel_stop_all_cb() - stop the flow of data through the callback.
95 * @cb_buff: The callback buffer we are stopping.
96 */
97void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
98
99/**
100 * iio_channel_cb_get_channels() - get access to the underlying channels.
101 * @cb_buff: The callback buffer from whom we want the channel
102 * information.
103 *
104 * This function allows one to obtain information about the channels.
105 * Whilst this may allow direct reading if all buffers are disabled, the
106 * primary aim is to allow drivers that are consuming a channel to query
107 * things like scaling of the channel.
108 */
109struct iio_channel
110*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
111
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000112/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100113 * iio_read_channel_raw() - read from a given channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100114 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000115 * @val: Value read back.
116 *
117 * Note raw reads from iio channels are in adc counts and hence
118 * scale will need to be applied if standard units required.
119 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100120int iio_read_channel_raw(struct iio_channel *chan,
121 int *val);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000122
123/**
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100124 * iio_read_channel_processed() - read processed value from a given channel
125 * @chan: The channel being queried.
126 * @val: Value read back.
127 *
128 * Returns an error code or 0.
129 *
130 * This function will read a processed value from a channel. A processed value
131 * means that this value will have the correct unit and not some device internal
132 * representation. If the device does not support reporting a processed value
133 * the function will query the raw value and the channels scale and offset and
134 * do the appropriate transformation.
135 */
136int iio_read_channel_processed(struct iio_channel *chan, int *val);
137
138/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100139 * iio_get_channel_type() - get the type of a channel
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000140 * @channel: The channel being queried.
141 * @type: The type of the channel.
142 *
143 * returns the enum iio_chan_type of the channel
144 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100145int iio_get_channel_type(struct iio_channel *channel,
146 enum iio_chan_type *type);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000147
148/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100149 * iio_read_channel_scale() - read the scale value for a channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100150 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000151 * @val: First part of value read back.
152 * @val2: Second part of value read back.
153 *
154 * Note returns a description of what is in val and val2, such
155 * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
156 * + val2/1e6
157 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100158int iio_read_channel_scale(struct iio_channel *chan, int *val,
159 int *val2);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000160
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100161/**
162 * iio_convert_raw_to_processed() - Converts a raw value to a processed value
163 * @chan: The channel being queried
164 * @raw: The raw IIO to convert
165 * @processed: The result of the conversion
166 * @scale: Scale factor to apply during the conversion
167 *
168 * Returns an error code or 0.
169 *
170 * This function converts a raw value to processed value for a specific channel.
171 * A raw value is the device internal representation of a sample and the value
172 * returned by iio_read_channel_raw, so the unit of that value is device
173 * depended. A processed value on the other hand is value has a normed unit
174 * according with the IIO specification.
175 *
176 * The scale factor allows to increase the precession of the returned value. For
177 * a scale factor of 1 the function will return the result in the normal IIO
178 * unit for the channel type. E.g. millivolt for voltage channels, if you want
179 * nanovolts instead pass 1000 as the scale factor.
180 */
181int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
182 int *processed, unsigned int scale);
183
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000184#endif