blob: 126c0a9375f26cd949afb14ac2fae7e3938a7744 [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_
Jonathan Cameron06458e22012-04-25 15:54:58 +010012#include <linux/iio/types.h>
Jonathan Camerone27d75d2012-02-15 19:48:01 +000013
14struct iio_dev;
15struct iio_chan_spec;
16
17/**
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.
Jonathan Cameron04644152012-06-30 20:06:00 +010021 * @data: Data about the channel used by consumer.
Jonathan Camerone27d75d2012-02-15 19:48:01 +000022 */
23struct iio_channel {
24 struct iio_dev *indio_dev;
25 const struct iio_chan_spec *channel;
Jonathan Cameron04644152012-06-30 20:06:00 +010026 void *data;
Jonathan Camerone27d75d2012-02-15 19:48:01 +000027};
28
29/**
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
33 * was registered.
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'
37 */
Jonathan Cameron314be142012-05-01 21:04:24 +010038struct iio_channel *iio_channel_get(const char *name,
39 const char *consumer_channel);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000040
41/**
Jonathan Cameron314be142012-05-01 21:04:24 +010042 * iio_channel_release() - release channels obtained via iio_channel_get
Jonathan Camerone27d75d2012-02-15 19:48:01 +000043 * @chan: The channel to be released.
44 */
Jonathan Cameron314be142012-05-01 21:04:24 +010045void iio_channel_release(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000046
47/**
Jonathan Cameron314be142012-05-01 21:04:24 +010048 * iio_channel_get_all() - get all channels associated with a client
Jonathan Camerone27d75d2012-02-15 19:48:01 +000049 * @name: name of consumer device.
50 *
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.
55 */
Jonathan Cameron314be142012-05-01 21:04:24 +010056struct iio_channel *iio_channel_get_all(const char *name);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000057
58/**
Jonathan Cameron314be142012-05-01 21:04:24 +010059 * iio_channel_release_all() - reverse iio_channel_get_all
Jonathan Camerone27d75d2012-02-15 19:48:01 +000060 * @chan: Array of channels to be released.
61 */
Jonathan Cameron314be142012-05-01 21:04:24 +010062void iio_channel_release_all(struct iio_channel *chan);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000063
Jonathan Cameron92d10792012-06-30 20:06:00 +010064struct iio_cb_buffer;
65/**
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.
70 *
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
73 * fail.
74 */
75struct iio_cb_buffer *iio_channel_get_all_cb(const char *name,
76 int (*cb)(u8 *data,
77 void *private),
78 void *private);
79/**
80 * iio_channel_release_all_cb() - release and unregister the callback.
81 * @cb_buffer: The callback buffer that was allocated.
82 */
83void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer);
84
85/**
86 * iio_channel_start_all_cb() - start the flow of data through callback.
87 * @cb_buff: The callback buffer we are starting.
88 */
89int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff);
90
91/**
92 * iio_channel_stop_all_cb() - stop the flow of data through the callback.
93 * @cb_buff: The callback buffer we are stopping.
94 */
95void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff);
96
97/**
98 * iio_channel_cb_get_channels() - get access to the underlying channels.
99 * @cb_buff: The callback buffer from whom we want the channel
100 * information.
101 *
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.
106 */
107struct iio_channel
108*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer);
109
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000110/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100111 * iio_read_channel_raw() - read from a given channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100112 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000113 * @val: Value read back.
114 *
115 * Note raw reads from iio channels are in adc counts and hence
116 * scale will need to be applied if standard units required.
117 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100118int iio_read_channel_raw(struct iio_channel *chan,
119 int *val);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000120
121/**
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100122 * iio_read_channel_processed() - read processed value from a given channel
123 * @chan: The channel being queried.
124 * @val: Value read back.
125 *
126 * Returns an error code or 0.
127 *
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.
133 */
134int iio_read_channel_processed(struct iio_channel *chan, int *val);
135
136/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100137 * iio_get_channel_type() - get the type of a channel
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000138 * @channel: The channel being queried.
139 * @type: The type of the channel.
140 *
141 * returns the enum iio_chan_type of the channel
142 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100143int iio_get_channel_type(struct iio_channel *channel,
144 enum iio_chan_type *type);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000145
146/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100147 * iio_read_channel_scale() - read the scale value for a channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100148 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000149 * @val: First part of value read back.
150 * @val2: Second part of value read back.
151 *
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
154 * + val2/1e6
155 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100156int iio_read_channel_scale(struct iio_channel *chan, int *val,
157 int *val2);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000158
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100159/**
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
165 *
166 * Returns an error code or 0.
167 *
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.
173 *
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.
178 */
179int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
180 int *processed, unsigned int scale);
181
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000182#endif