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