10 #include <linux/export.h>
11 #include <linux/slab.h>
38 while (maps[i].consumer_dev_name !=
NULL) {
46 list_add(&mapi->
l, &iio_map_list);
72 while (maps[i].consumer_dev_name !=
NULL) {
75 if (&maps[i] == mapi->
map) {
81 if (found_it ==
false) {
95 *iio_chan_spec_from_name(
const struct iio_dev *indio_dev,
const char *
name)
101 if (indio_dev->
channels[i].datasheet_name &&
116 if (name ==
NULL && channel_name ==
NULL)
122 if ((name &&
strcmp(name, c_i->
map->consumer_dev_name) != 0) ||
124 strcmp(channel_name, c_i->
map->consumer_channel) != 0))
127 iio_device_get(c->indio_dev);
134 channel = kzalloc(
sizeof(*channel),
GFP_KERNEL);
135 if (channel ==
NULL) {
142 if (c->map->adc_channel_label) {
144 iio_chan_spec_from_name(channel->
indio_dev,
145 c->map->adc_channel_label);
158 iio_device_put(c->indio_dev);
184 if (name &&
strcmp(name, c->
map->consumer_dev_name) != 0)
195 chans = kzalloc(
sizeof(*chans)*(nummaps + 1),
GFP_KERNEL);
203 if (name &&
strcmp(name, c->
map->consumer_dev_name) != 0)
207 iio_chan_spec_from_name(chans[mapind].indio_dev,
208 c->
map->adc_channel_label);
211 goto error_free_chans;
213 iio_device_get(chans[mapind].indio_dev);
218 goto error_free_chans;
225 for (i = 0; i < nummaps; i++)
226 iio_device_put(chans[i].indio_dev);
247 static int iio_channel_read(
struct iio_channel *chan,
int *
val,
int *val2,
277 static int iio_convert_raw_to_processed_unlocked(
struct iio_channel *chan,
278 int raw,
int *processed,
unsigned int scale)
280 int scale_type, scale_val, scale_val2,
offset;
288 scale_type = iio_channel_read(chan, &scale_val, &scale_val2,
293 switch (scale_type) {
295 *processed = raw64 * scale_val;
299 *processed = -raw64 * scale_val;
301 *processed = raw64 * scale_val;
302 *processed += div_s64(raw64 * (
s64)scale_val2 * scale,
307 *processed = -raw64 * scale_val;
309 *processed = raw64 * scale_val;
310 *processed += div_s64(raw64 * (
s64)scale_val2 * scale,
314 *processed = div_s64(raw64 * (
s64)scale_val * scale,
325 int *processed,
unsigned int scale)
335 ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed,
355 ret = iio_channel_read(chan, val,
NULL,
361 ret = iio_convert_raw_to_processed_unlocked(chan, *val, val, 1);