Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 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_ |
| 11 | #define _IIO_INKERN_CONSUMER_H |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 12 | #include <linux/iio/types.h> |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 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. |
| 21 | */ |
| 22 | struct iio_channel { |
| 23 | struct iio_dev *indio_dev; |
| 24 | const struct iio_chan_spec *channel; |
| 25 | }; |
| 26 | |
| 27 | /** |
| 28 | * iio_channel_get() - get description of all that is needed to access channel. |
| 29 | * @name: Unique name of the device as provided in the iio_map |
| 30 | * with which the desired provider to consumer mapping |
| 31 | * was registered. |
| 32 | * @consumer_channel: Unique name to identify the channel on the consumer |
| 33 | * side. This typically describes the channels use within |
| 34 | * the consumer. E.g. 'battery_voltage' |
| 35 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 36 | struct iio_channel *iio_channel_get(const char *name, |
| 37 | const char *consumer_channel); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 38 | |
| 39 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 40 | * iio_channel_release() - release channels obtained via iio_channel_get |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 41 | * @chan: The channel to be released. |
| 42 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 43 | void iio_channel_release(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 44 | |
| 45 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 46 | * iio_channel_get_all() - get all channels associated with a client |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 47 | * @name: name of consumer device. |
| 48 | * |
| 49 | * Returns an array of iio_channel structures terminated with one with |
| 50 | * null iio_dev pointer. |
| 51 | * This function is used by fairly generic consumers to get all the |
| 52 | * channels registered as having this consumer. |
| 53 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 54 | struct iio_channel *iio_channel_get_all(const char *name); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 57 | * iio_channel_release_all() - reverse iio_channel_get_all |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 58 | * @chan: Array of channels to be released. |
| 59 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 60 | void iio_channel_release_all(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 61 | |
| 62 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 63 | * iio_read_channel_raw() - read from a given channel |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 64 | * @channel: The channel being queried. |
| 65 | * @val: Value read back. |
| 66 | * |
| 67 | * Note raw reads from iio channels are in adc counts and hence |
| 68 | * scale will need to be applied if standard units required. |
| 69 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 70 | int iio_read_channel_raw(struct iio_channel *chan, |
| 71 | int *val); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 72 | |
| 73 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 74 | * iio_get_channel_type() - get the type of a channel |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 75 | * @channel: The channel being queried. |
| 76 | * @type: The type of the channel. |
| 77 | * |
| 78 | * returns the enum iio_chan_type of the channel |
| 79 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 80 | int iio_get_channel_type(struct iio_channel *channel, |
| 81 | enum iio_chan_type *type); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 82 | |
| 83 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 84 | * iio_read_channel_scale() - read the scale value for a channel |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 85 | * @channel: The channel being queried. |
| 86 | * @val: First part of value read back. |
| 87 | * @val2: Second part of value read back. |
| 88 | * |
| 89 | * Note returns a description of what is in val and val2, such |
| 90 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val |
| 91 | * + val2/1e6 |
| 92 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 93 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
| 94 | int *val2); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 95 | |
| 96 | #endif |