blob: 57efee63a6daa9074bd8a5d3f5c64128a8899e05 [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
64/**
Jonathan Cameron314be142012-05-01 21:04:24 +010065 * iio_read_channel_raw() - read from a given channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +010066 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +000067 * @val: Value read back.
68 *
69 * Note raw reads from iio channels are in adc counts and hence
70 * scale will need to be applied if standard units required.
71 */
Jonathan Cameron314be142012-05-01 21:04:24 +010072int iio_read_channel_raw(struct iio_channel *chan,
73 int *val);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000074
75/**
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +010076 * iio_read_channel_processed() - read processed value from a given channel
77 * @chan: The channel being queried.
78 * @val: Value read back.
79 *
80 * Returns an error code or 0.
81 *
82 * This function will read a processed value from a channel. A processed value
83 * means that this value will have the correct unit and not some device internal
84 * representation. If the device does not support reporting a processed value
85 * the function will query the raw value and the channels scale and offset and
86 * do the appropriate transformation.
87 */
88int iio_read_channel_processed(struct iio_channel *chan, int *val);
89
90/**
Jonathan Cameron314be142012-05-01 21:04:24 +010091 * iio_get_channel_type() - get the type of a channel
Jonathan Camerone27d75d2012-02-15 19:48:01 +000092 * @channel: The channel being queried.
93 * @type: The type of the channel.
94 *
95 * returns the enum iio_chan_type of the channel
96 */
Jonathan Cameron314be142012-05-01 21:04:24 +010097int iio_get_channel_type(struct iio_channel *channel,
98 enum iio_chan_type *type);
Jonathan Camerone27d75d2012-02-15 19:48:01 +000099
100/**
Jonathan Cameron314be142012-05-01 21:04:24 +0100101 * iio_read_channel_scale() - read the scale value for a channel
Lars-Peter Clausen45f010b2012-09-17 13:17:00 +0100102 * @chan: The channel being queried.
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000103 * @val: First part of value read back.
104 * @val2: Second part of value read back.
105 *
106 * Note returns a description of what is in val and val2, such
107 * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
108 * + val2/1e6
109 */
Jonathan Cameron314be142012-05-01 21:04:24 +0100110int iio_read_channel_scale(struct iio_channel *chan, int *val,
111 int *val2);
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000112
Lars-Peter Clausen48e44ce2012-09-17 13:17:00 +0100113/**
114 * iio_convert_raw_to_processed() - Converts a raw value to a processed value
115 * @chan: The channel being queried
116 * @raw: The raw IIO to convert
117 * @processed: The result of the conversion
118 * @scale: Scale factor to apply during the conversion
119 *
120 * Returns an error code or 0.
121 *
122 * This function converts a raw value to processed value for a specific channel.
123 * A raw value is the device internal representation of a sample and the value
124 * returned by iio_read_channel_raw, so the unit of that value is device
125 * depended. A processed value on the other hand is value has a normed unit
126 * according with the IIO specification.
127 *
128 * The scale factor allows to increase the precession of the returned value. For
129 * a scale factor of 1 the function will return the result in the normal IIO
130 * unit for the channel type. E.g. millivolt for voltage channels, if you want
131 * nanovolts instead pass 1000 as the scale factor.
132 */
133int iio_convert_raw_to_processed(struct iio_channel *chan, int raw,
134 int *processed, unsigned int scale);
135
Jonathan Camerone27d75d2012-02-15 19:48:01 +0000136#endif