Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 1 | /* The industrial I/O core in kernel channel mapping |
| 2 | * |
| 3 | * Copyright (c) 2011 Jonathan Cameron |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | */ |
| 9 | #include <linux/err.h> |
| 10 | #include <linux/export.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/mutex.h> |
| 13 | |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 14 | #include <linux/iio/iio.h> |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 15 | #include "iio_core.h" |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 16 | #include <linux/iio/machine.h> |
| 17 | #include <linux/iio/driver.h> |
| 18 | #include <linux/iio/consumer.h> |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 19 | |
| 20 | struct iio_map_internal { |
| 21 | struct iio_dev *indio_dev; |
| 22 | struct iio_map *map; |
| 23 | struct list_head l; |
| 24 | }; |
| 25 | |
| 26 | static LIST_HEAD(iio_map_list); |
| 27 | static DEFINE_MUTEX(iio_map_list_lock); |
| 28 | |
| 29 | int iio_map_array_register(struct iio_dev *indio_dev, struct iio_map *maps) |
| 30 | { |
| 31 | int i = 0, ret = 0; |
| 32 | struct iio_map_internal *mapi; |
| 33 | |
| 34 | if (maps == NULL) |
| 35 | return 0; |
| 36 | |
| 37 | mutex_lock(&iio_map_list_lock); |
| 38 | while (maps[i].consumer_dev_name != NULL) { |
| 39 | mapi = kzalloc(sizeof(*mapi), GFP_KERNEL); |
| 40 | if (mapi == NULL) { |
| 41 | ret = -ENOMEM; |
| 42 | goto error_ret; |
| 43 | } |
| 44 | mapi->map = &maps[i]; |
| 45 | mapi->indio_dev = indio_dev; |
| 46 | list_add(&mapi->l, &iio_map_list); |
| 47 | i++; |
| 48 | } |
| 49 | error_ret: |
| 50 | mutex_unlock(&iio_map_list_lock); |
| 51 | |
| 52 | return ret; |
| 53 | } |
| 54 | EXPORT_SYMBOL_GPL(iio_map_array_register); |
| 55 | |
| 56 | |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 57 | /* |
| 58 | * Remove all map entries associated with the given iio device |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 59 | */ |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 60 | int iio_map_array_unregister(struct iio_dev *indio_dev) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 61 | { |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 62 | int ret = -ENODEV; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 63 | struct iio_map_internal *mapi; |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 64 | struct list_head *pos, *tmp; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 65 | |
| 66 | mutex_lock(&iio_map_list_lock); |
Guenter Roeck | 6cb2afd | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 67 | list_for_each_safe(pos, tmp, &iio_map_list) { |
| 68 | mapi = list_entry(pos, struct iio_map_internal, l); |
| 69 | if (indio_dev == mapi->indio_dev) { |
| 70 | list_del(&mapi->l); |
| 71 | kfree(mapi); |
| 72 | ret = 0; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 73 | } |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 74 | } |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 75 | mutex_unlock(&iio_map_list_lock); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 76 | return ret; |
| 77 | } |
| 78 | EXPORT_SYMBOL_GPL(iio_map_array_unregister); |
| 79 | |
| 80 | static const struct iio_chan_spec |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 81 | *iio_chan_spec_from_name(const struct iio_dev *indio_dev, const char *name) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 82 | { |
| 83 | int i; |
| 84 | const struct iio_chan_spec *chan = NULL; |
| 85 | |
| 86 | for (i = 0; i < indio_dev->num_channels; i++) |
| 87 | if (indio_dev->channels[i].datasheet_name && |
| 88 | strcmp(name, indio_dev->channels[i].datasheet_name) == 0) { |
| 89 | chan = &indio_dev->channels[i]; |
| 90 | break; |
| 91 | } |
| 92 | return chan; |
| 93 | } |
| 94 | |
| 95 | |
Guenter Roeck | 5aa57f0 | 2013-02-04 20:26:00 +0000 | [diff] [blame^] | 96 | static struct iio_channel *iio_channel_get_sys(const char *name, |
| 97 | const char *channel_name) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 98 | { |
| 99 | struct iio_map_internal *c_i = NULL, *c = NULL; |
| 100 | struct iio_channel *channel; |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 101 | int err; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 102 | |
| 103 | if (name == NULL && channel_name == NULL) |
| 104 | return ERR_PTR(-ENODEV); |
| 105 | |
| 106 | /* first find matching entry the channel map */ |
| 107 | mutex_lock(&iio_map_list_lock); |
| 108 | list_for_each_entry(c_i, &iio_map_list, l) { |
| 109 | if ((name && strcmp(name, c_i->map->consumer_dev_name) != 0) || |
| 110 | (channel_name && |
| 111 | strcmp(channel_name, c_i->map->consumer_channel) != 0)) |
| 112 | continue; |
| 113 | c = c_i; |
Lars-Peter Clausen | 1875ffd | 2012-06-04 10:50:03 +0200 | [diff] [blame] | 114 | iio_device_get(c->indio_dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | mutex_unlock(&iio_map_list_lock); |
| 118 | if (c == NULL) |
| 119 | return ERR_PTR(-ENODEV); |
| 120 | |
Kim, Milo | 2cc412b | 2012-09-14 02:24:00 +0100 | [diff] [blame] | 121 | channel = kzalloc(sizeof(*channel), GFP_KERNEL); |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 122 | if (channel == NULL) { |
| 123 | err = -ENOMEM; |
Kim, Milo | 801c4b5 | 2012-09-18 05:55:00 +0100 | [diff] [blame] | 124 | goto error_no_mem; |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 125 | } |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 126 | |
| 127 | channel->indio_dev = c->indio_dev; |
| 128 | |
Kim, Milo | b2b79ff | 2012-09-17 09:44:00 +0100 | [diff] [blame] | 129 | if (c->map->adc_channel_label) { |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 130 | channel->channel = |
| 131 | iio_chan_spec_from_name(channel->indio_dev, |
| 132 | c->map->adc_channel_label); |
| 133 | |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 134 | if (channel->channel == NULL) { |
| 135 | err = -EINVAL; |
Kim, Milo | b2b79ff | 2012-09-17 09:44:00 +0100 | [diff] [blame] | 136 | goto error_no_chan; |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 137 | } |
Kim, Milo | b2b79ff | 2012-09-17 09:44:00 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 140 | return channel; |
Kim, Milo | b2b79ff | 2012-09-17 09:44:00 +0100 | [diff] [blame] | 141 | |
| 142 | error_no_chan: |
Kim, Milo | b2b79ff | 2012-09-17 09:44:00 +0100 | [diff] [blame] | 143 | kfree(channel); |
Kim, Milo | 801c4b5 | 2012-09-18 05:55:00 +0100 | [diff] [blame] | 144 | error_no_mem: |
| 145 | iio_device_put(c->indio_dev); |
Kim, Milo | 3183bac | 2012-09-18 05:56:00 +0100 | [diff] [blame] | 146 | return ERR_PTR(err); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 147 | } |
Guenter Roeck | 5aa57f0 | 2013-02-04 20:26:00 +0000 | [diff] [blame^] | 148 | |
| 149 | struct iio_channel *iio_channel_get(struct device *dev, |
| 150 | const char *channel_name) |
| 151 | { |
| 152 | const char *name = dev ? dev_name(dev) : NULL; |
| 153 | |
| 154 | return iio_channel_get_sys(name, channel_name); |
| 155 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 156 | EXPORT_SYMBOL_GPL(iio_channel_get); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 157 | |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 158 | void iio_channel_release(struct iio_channel *channel) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 159 | { |
Lars-Peter Clausen | 1875ffd | 2012-06-04 10:50:03 +0200 | [diff] [blame] | 160 | iio_device_put(channel->indio_dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 161 | kfree(channel); |
| 162 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 163 | EXPORT_SYMBOL_GPL(iio_channel_release); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 164 | |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 165 | struct iio_channel *iio_channel_get_all(struct device *dev) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 166 | { |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 167 | const char *name; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 168 | struct iio_channel *chans; |
| 169 | struct iio_map_internal *c = NULL; |
| 170 | int nummaps = 0; |
| 171 | int mapind = 0; |
| 172 | int i, ret; |
| 173 | |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 174 | if (dev == NULL) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 175 | return ERR_PTR(-EINVAL); |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 176 | name = dev_name(dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 177 | |
| 178 | mutex_lock(&iio_map_list_lock); |
| 179 | /* first count the matching maps */ |
| 180 | list_for_each_entry(c, &iio_map_list, l) |
| 181 | if (name && strcmp(name, c->map->consumer_dev_name) != 0) |
| 182 | continue; |
| 183 | else |
| 184 | nummaps++; |
| 185 | |
| 186 | if (nummaps == 0) { |
| 187 | ret = -ENODEV; |
| 188 | goto error_ret; |
| 189 | } |
| 190 | |
| 191 | /* NULL terminated array to save passing size */ |
| 192 | chans = kzalloc(sizeof(*chans)*(nummaps + 1), GFP_KERNEL); |
| 193 | if (chans == NULL) { |
| 194 | ret = -ENOMEM; |
| 195 | goto error_ret; |
| 196 | } |
| 197 | |
| 198 | /* for each map fill in the chans element */ |
| 199 | list_for_each_entry(c, &iio_map_list, l) { |
| 200 | if (name && strcmp(name, c->map->consumer_dev_name) != 0) |
| 201 | continue; |
| 202 | chans[mapind].indio_dev = c->indio_dev; |
Jonathan Cameron | 0464415 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 203 | chans[mapind].data = c->map->consumer_data; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 204 | chans[mapind].channel = |
| 205 | iio_chan_spec_from_name(chans[mapind].indio_dev, |
| 206 | c->map->adc_channel_label); |
| 207 | if (chans[mapind].channel == NULL) { |
| 208 | ret = -EINVAL; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 209 | goto error_free_chans; |
| 210 | } |
Lars-Peter Clausen | 1875ffd | 2012-06-04 10:50:03 +0200 | [diff] [blame] | 211 | iio_device_get(chans[mapind].indio_dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 212 | mapind++; |
| 213 | } |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 214 | if (mapind == 0) { |
| 215 | ret = -ENODEV; |
| 216 | goto error_free_chans; |
| 217 | } |
Dan Carpenter | e59b9af | 2012-07-11 07:34:00 +0100 | [diff] [blame] | 218 | mutex_unlock(&iio_map_list_lock); |
| 219 | |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 220 | return chans; |
| 221 | |
| 222 | error_free_chans: |
| 223 | for (i = 0; i < nummaps; i++) |
Lars-Peter Clausen | 1875ffd | 2012-06-04 10:50:03 +0200 | [diff] [blame] | 224 | iio_device_put(chans[i].indio_dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 225 | kfree(chans); |
| 226 | error_ret: |
| 227 | mutex_unlock(&iio_map_list_lock); |
| 228 | |
| 229 | return ERR_PTR(ret); |
| 230 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 231 | EXPORT_SYMBOL_GPL(iio_channel_get_all); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 232 | |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 233 | void iio_channel_release_all(struct iio_channel *channels) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 234 | { |
| 235 | struct iio_channel *chan = &channels[0]; |
| 236 | |
| 237 | while (chan->indio_dev) { |
Lars-Peter Clausen | 1875ffd | 2012-06-04 10:50:03 +0200 | [diff] [blame] | 238 | iio_device_put(chan->indio_dev); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 239 | chan++; |
| 240 | } |
| 241 | kfree(channels); |
| 242 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 243 | EXPORT_SYMBOL_GPL(iio_channel_release_all); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 244 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 245 | static int iio_channel_read(struct iio_channel *chan, int *val, int *val2, |
| 246 | enum iio_chan_info_enum info) |
| 247 | { |
| 248 | int unused; |
| 249 | |
| 250 | if (val2 == NULL) |
| 251 | val2 = &unused; |
| 252 | |
| 253 | return chan->indio_dev->info->read_raw(chan->indio_dev, chan->channel, |
| 254 | val, val2, info); |
| 255 | } |
| 256 | |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 257 | int iio_read_channel_raw(struct iio_channel *chan, int *val) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 258 | { |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 259 | int ret; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 260 | |
| 261 | mutex_lock(&chan->indio_dev->info_exist_lock); |
| 262 | if (chan->indio_dev->info == NULL) { |
| 263 | ret = -ENODEV; |
| 264 | goto err_unlock; |
| 265 | } |
| 266 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 267 | ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 268 | err_unlock: |
| 269 | mutex_unlock(&chan->indio_dev->info_exist_lock); |
| 270 | |
| 271 | return ret; |
| 272 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 273 | EXPORT_SYMBOL_GPL(iio_read_channel_raw); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 274 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 275 | static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, |
| 276 | int raw, int *processed, unsigned int scale) |
| 277 | { |
| 278 | int scale_type, scale_val, scale_val2, offset; |
| 279 | s64 raw64 = raw; |
| 280 | int ret; |
| 281 | |
| 282 | ret = iio_channel_read(chan, &offset, NULL, IIO_CHAN_INFO_SCALE); |
| 283 | if (ret == 0) |
| 284 | raw64 += offset; |
| 285 | |
| 286 | scale_type = iio_channel_read(chan, &scale_val, &scale_val2, |
| 287 | IIO_CHAN_INFO_SCALE); |
| 288 | if (scale_type < 0) |
| 289 | return scale_type; |
| 290 | |
| 291 | switch (scale_type) { |
| 292 | case IIO_VAL_INT: |
| 293 | *processed = raw64 * scale_val; |
| 294 | break; |
| 295 | case IIO_VAL_INT_PLUS_MICRO: |
| 296 | if (scale_val2 < 0) |
| 297 | *processed = -raw64 * scale_val; |
| 298 | else |
| 299 | *processed = raw64 * scale_val; |
| 300 | *processed += div_s64(raw64 * (s64)scale_val2 * scale, |
| 301 | 1000000LL); |
| 302 | break; |
| 303 | case IIO_VAL_INT_PLUS_NANO: |
| 304 | if (scale_val2 < 0) |
| 305 | *processed = -raw64 * scale_val; |
| 306 | else |
| 307 | *processed = raw64 * scale_val; |
| 308 | *processed += div_s64(raw64 * (s64)scale_val2 * scale, |
| 309 | 1000000000LL); |
| 310 | break; |
| 311 | case IIO_VAL_FRACTIONAL: |
| 312 | *processed = div_s64(raw64 * (s64)scale_val * scale, |
| 313 | scale_val2); |
| 314 | break; |
Lars-Peter Clausen | 103d9fb | 2012-10-16 17:29:00 +0100 | [diff] [blame] | 315 | case IIO_VAL_FRACTIONAL_LOG2: |
| 316 | *processed = (raw64 * (s64)scale_val * scale) >> scale_val2; |
| 317 | break; |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 318 | default: |
| 319 | return -EINVAL; |
| 320 | } |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, |
| 326 | int *processed, unsigned int scale) |
| 327 | { |
| 328 | int ret; |
| 329 | |
| 330 | mutex_lock(&chan->indio_dev->info_exist_lock); |
| 331 | if (chan->indio_dev->info == NULL) { |
| 332 | ret = -ENODEV; |
| 333 | goto err_unlock; |
| 334 | } |
| 335 | |
| 336 | ret = iio_convert_raw_to_processed_unlocked(chan, raw, processed, |
| 337 | scale); |
| 338 | err_unlock: |
| 339 | mutex_unlock(&chan->indio_dev->info_exist_lock); |
| 340 | |
| 341 | return ret; |
| 342 | } |
| 343 | EXPORT_SYMBOL_GPL(iio_convert_raw_to_processed); |
| 344 | |
| 345 | int iio_read_channel_processed(struct iio_channel *chan, int *val) |
| 346 | { |
| 347 | int ret; |
| 348 | |
| 349 | mutex_lock(&chan->indio_dev->info_exist_lock); |
| 350 | if (chan->indio_dev->info == NULL) { |
| 351 | ret = -ENODEV; |
| 352 | goto err_unlock; |
| 353 | } |
| 354 | |
| 355 | if (iio_channel_has_info(chan->channel, IIO_CHAN_INFO_PROCESSED)) { |
| 356 | ret = iio_channel_read(chan, val, NULL, |
| 357 | IIO_CHAN_INFO_PROCESSED); |
| 358 | } else { |
| 359 | ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_RAW); |
| 360 | if (ret < 0) |
| 361 | goto err_unlock; |
| 362 | ret = iio_convert_raw_to_processed_unlocked(chan, *val, val, 1); |
| 363 | } |
| 364 | |
| 365 | err_unlock: |
| 366 | mutex_unlock(&chan->indio_dev->info_exist_lock); |
| 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | EXPORT_SYMBOL_GPL(iio_read_channel_processed); |
| 371 | |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 372 | int iio_read_channel_scale(struct iio_channel *chan, int *val, int *val2) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 373 | { |
| 374 | int ret; |
| 375 | |
| 376 | mutex_lock(&chan->indio_dev->info_exist_lock); |
| 377 | if (chan->indio_dev->info == NULL) { |
| 378 | ret = -ENODEV; |
| 379 | goto err_unlock; |
| 380 | } |
| 381 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 382 | ret = iio_channel_read(chan, val, val2, IIO_CHAN_INFO_SCALE); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 383 | err_unlock: |
| 384 | mutex_unlock(&chan->indio_dev->info_exist_lock); |
| 385 | |
| 386 | return ret; |
| 387 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 388 | EXPORT_SYMBOL_GPL(iio_read_channel_scale); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 389 | |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 390 | int iio_get_channel_type(struct iio_channel *chan, enum iio_chan_type *type) |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 391 | { |
| 392 | int ret = 0; |
| 393 | /* Need to verify underlying driver has not gone away */ |
| 394 | |
| 395 | mutex_lock(&chan->indio_dev->info_exist_lock); |
| 396 | if (chan->indio_dev->info == NULL) { |
| 397 | ret = -ENODEV; |
| 398 | goto err_unlock; |
| 399 | } |
| 400 | |
| 401 | *type = chan->channel->type; |
| 402 | err_unlock: |
| 403 | mutex_unlock(&chan->indio_dev->info_exist_lock); |
| 404 | |
| 405 | return ret; |
| 406 | } |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 407 | EXPORT_SYMBOL_GPL(iio_get_channel_type); |