]>
Commit | Line | Data |
---|---|---|
e27d75d7 JC |
1 | /* |
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_ | |
88238fef | 11 | #define _IIO_INKERN_CONSUMER_H_ |
06458e27 | 12 | #include <linux/iio/types.h> |
e27d75d7 JC |
13 | |
14 | struct iio_dev; | |
15 | struct 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. | |
0464415d | 21 | * @data: Data about the channel used by consumer. |
e27d75d7 JC |
22 | */ |
23 | struct iio_channel { | |
24 | struct iio_dev *indio_dev; | |
25 | const struct iio_chan_spec *channel; | |
0464415d | 26 | void *data; |
e27d75d7 JC |
27 | }; |
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 | */ | |
314be14b JC |
38 | struct iio_channel *iio_channel_get(const char *name, |
39 | const char *consumer_channel); | |
e27d75d7 JC |
40 | |
41 | /** | |
314be14b | 42 | * iio_channel_release() - release channels obtained via iio_channel_get |
e27d75d7 JC |
43 | * @chan: The channel to be released. |
44 | */ | |
314be14b | 45 | void iio_channel_release(struct iio_channel *chan); |
e27d75d7 JC |
46 | |
47 | /** | |
314be14b | 48 | * iio_channel_get_all() - get all channels associated with a client |
e27d75d7 JC |
49 | * @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 | */ | |
314be14b | 56 | struct iio_channel *iio_channel_get_all(const char *name); |
e27d75d7 JC |
57 | |
58 | /** | |
314be14b | 59 | * iio_channel_release_all() - reverse iio_channel_get_all |
e27d75d7 JC |
60 | * @chan: Array of channels to be released. |
61 | */ | |
314be14b | 62 | void iio_channel_release_all(struct iio_channel *chan); |
e27d75d7 JC |
63 | |
64 | /** | |
314be14b | 65 | * iio_read_channel_raw() - read from a given channel |
45f010ba | 66 | * @chan: The channel being queried. |
e27d75d7 JC |
67 | * @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 | */ | |
314be14b JC |
72 | int iio_read_channel_raw(struct iio_channel *chan, |
73 | int *val); | |
e27d75d7 | 74 | |
48e44ce0 LPC |
75 | /** |
76 | * 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 | */ | |
88 | int iio_read_channel_processed(struct iio_channel *chan, int *val); | |
89 | ||
e27d75d7 | 90 | /** |
314be14b | 91 | * iio_get_channel_type() - get the type of a channel |
e27d75d7 JC |
92 | * @channel: The channel being queried. |
93 | * @type: The type of the channel. | |
94 | * | |
95 | * returns the enum iio_chan_type of the channel | |
96 | */ | |
314be14b JC |
97 | int iio_get_channel_type(struct iio_channel *channel, |
98 | enum iio_chan_type *type); | |
e27d75d7 JC |
99 | |
100 | /** | |
314be14b | 101 | * iio_read_channel_scale() - read the scale value for a channel |
45f010ba | 102 | * @chan: The channel being queried. |
e27d75d7 JC |
103 | * @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 | */ | |
314be14b JC |
110 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
111 | int *val2); | |
e27d75d7 | 112 | |
48e44ce0 LPC |
113 | /** |
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 | */ | |
133 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, | |
134 | int *processed, unsigned int scale); | |
135 | ||
e27d75d7 | 136 | #endif |