diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-09-17 08:17:00 -0400 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-09-17 16:48:51 -0400 |
commit | 48e44ce0f8810b530fc83a4f5eb67149280d9b82 (patch) | |
tree | ce32b7a0917edb95fe5b4c3de1edd33e8d0f7ed6 /include/linux/iio/consumer.h | |
parent | 45f010baa0292c367168b1f62d5494965b905b5d (diff) |
iio:inkern: Add function to read the processed value
Add a function to read a processed value from a channel. The function will first
attempt to read the IIO_CHAN_INFO_PROCESSED attribute. If that fails it will
read the IIO_CHAN_INFO_RAW attribute and convert the result from a raw value to
a processed value.
The patch also introduces a function to convert raw value to a processed value
and exports it, in case a user needs or wants to do the conversion by itself.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'include/linux/iio/consumer.h')
-rw-r--r-- | include/linux/iio/consumer.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h index 62118dd707d7..e875bcf0478f 100644 --- a/include/linux/iio/consumer.h +++ b/include/linux/iio/consumer.h | |||
@@ -71,6 +71,21 @@ int iio_read_channel_raw(struct iio_channel *chan, | |||
71 | int *val); | 71 | int *val); |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * iio_read_channel_processed() - read processed value from a given channel | ||
75 | * @chan: The channel being queried. | ||
76 | * @val: Value read back. | ||
77 | * | ||
78 | * Returns an error code or 0. | ||
79 | * | ||
80 | * This function will read a processed value from a channel. A processed value | ||
81 | * means that this value will have the correct unit and not some device internal | ||
82 | * representation. If the device does not support reporting a processed value | ||
83 | * the function will query the raw value and the channels scale and offset and | ||
84 | * do the appropriate transformation. | ||
85 | */ | ||
86 | int iio_read_channel_processed(struct iio_channel *chan, int *val); | ||
87 | |||
88 | /** | ||
74 | * iio_get_channel_type() - get the type of a channel | 89 | * iio_get_channel_type() - get the type of a channel |
75 | * @channel: The channel being queried. | 90 | * @channel: The channel being queried. |
76 | * @type: The type of the channel. | 91 | * @type: The type of the channel. |
@@ -93,4 +108,27 @@ int iio_get_channel_type(struct iio_channel *channel, | |||
93 | int iio_read_channel_scale(struct iio_channel *chan, int *val, | 108 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
94 | int *val2); | 109 | int *val2); |
95 | 110 | ||
111 | /** | ||
112 | * iio_convert_raw_to_processed() - Converts a raw value to a processed value | ||
113 | * @chan: The channel being queried | ||
114 | * @raw: The raw IIO to convert | ||
115 | * @processed: The result of the conversion | ||
116 | * @scale: Scale factor to apply during the conversion | ||
117 | * | ||
118 | * Returns an error code or 0. | ||
119 | * | ||
120 | * This function converts a raw value to processed value for a specific channel. | ||
121 | * A raw value is the device internal representation of a sample and the value | ||
122 | * returned by iio_read_channel_raw, so the unit of that value is device | ||
123 | * depended. A processed value on the other hand is value has a normed unit | ||
124 | * according with the IIO specification. | ||
125 | * | ||
126 | * The scale factor allows to increase the precession of the returned value. For | ||
127 | * a scale factor of 1 the function will return the result in the normal IIO | ||
128 | * unit for the channel type. E.g. millivolt for voltage channels, if you want | ||
129 | * nanovolts instead pass 1000 as the scale factor. | ||
130 | */ | ||
131 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, | ||
132 | int *processed, unsigned int scale); | ||
133 | |||
96 | #endif | 134 | #endif |