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_ |
Lars-Peter Clausen | 88238fe | 2012-08-17 16:57:00 +0100 | [diff] [blame] | 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. |
Jonathan Cameron | 0464415 | 2012-06-30 20:06:00 +0100 | [diff] [blame^] | 21 | * @data: Data about the channel used by consumer. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 22 | */ |
| 23 | struct iio_channel { |
| 24 | struct iio_dev *indio_dev; |
| 25 | const struct iio_chan_spec *channel; |
Jonathan Cameron | 0464415 | 2012-06-30 20:06:00 +0100 | [diff] [blame^] | 26 | void *data; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * iio_channel_get() - get description of all that is needed to access channel. |
| 31 | * @name: Unique name of the device as provided in the iio_map |
| 32 | * with which the desired provider to consumer mapping |
| 33 | * was registered. |
| 34 | * @consumer_channel: Unique name to identify the channel on the consumer |
| 35 | * side. This typically describes the channels use within |
| 36 | * the consumer. E.g. 'battery_voltage' |
| 37 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 38 | struct iio_channel *iio_channel_get(const char *name, |
| 39 | const char *consumer_channel); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 40 | |
| 41 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 42 | * iio_channel_release() - release channels obtained via iio_channel_get |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 43 | * @chan: The channel to be released. |
| 44 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 45 | void iio_channel_release(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 46 | |
| 47 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 48 | * iio_channel_get_all() - get all channels associated with a client |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 49 | * @name: name of consumer device. |
| 50 | * |
| 51 | * Returns an array of iio_channel structures terminated with one with |
| 52 | * null iio_dev pointer. |
| 53 | * This function is used by fairly generic consumers to get all the |
| 54 | * channels registered as having this consumer. |
| 55 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 56 | struct iio_channel *iio_channel_get_all(const char *name); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 57 | |
| 58 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 59 | * iio_channel_release_all() - reverse iio_channel_get_all |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 60 | * @chan: Array of channels to be released. |
| 61 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 62 | void iio_channel_release_all(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 63 | |
| 64 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 65 | * iio_read_channel_raw() - read from a given channel |
Lars-Peter Clausen | 45f010b | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 66 | * @chan: The channel being queried. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 67 | * @val: Value read back. |
| 68 | * |
| 69 | * Note raw reads from iio channels are in adc counts and hence |
| 70 | * scale will need to be applied if standard units required. |
| 71 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 72 | int iio_read_channel_raw(struct iio_channel *chan, |
| 73 | int *val); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 74 | |
| 75 | /** |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 76 | * iio_read_channel_processed() - read processed value from a given channel |
| 77 | * @chan: The channel being queried. |
| 78 | * @val: Value read back. |
| 79 | * |
| 80 | * Returns an error code or 0. |
| 81 | * |
| 82 | * This function will read a processed value from a channel. A processed value |
| 83 | * means that this value will have the correct unit and not some device internal |
| 84 | * representation. If the device does not support reporting a processed value |
| 85 | * the function will query the raw value and the channels scale and offset and |
| 86 | * do the appropriate transformation. |
| 87 | */ |
| 88 | int iio_read_channel_processed(struct iio_channel *chan, int *val); |
| 89 | |
| 90 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 91 | * iio_get_channel_type() - get the type of a channel |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 92 | * @channel: The channel being queried. |
| 93 | * @type: The type of the channel. |
| 94 | * |
| 95 | * returns the enum iio_chan_type of the channel |
| 96 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 97 | int iio_get_channel_type(struct iio_channel *channel, |
| 98 | enum iio_chan_type *type); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 99 | |
| 100 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 101 | * iio_read_channel_scale() - read the scale value for a channel |
Lars-Peter Clausen | 45f010b | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 102 | * @chan: The channel being queried. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 103 | * @val: First part of value read back. |
| 104 | * @val2: Second part of value read back. |
| 105 | * |
| 106 | * Note returns a description of what is in val and val2, such |
| 107 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val |
| 108 | * + val2/1e6 |
| 109 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 110 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
| 111 | int *val2); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 112 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 113 | /** |
| 114 | * iio_convert_raw_to_processed() - Converts a raw value to a processed value |
| 115 | * @chan: The channel being queried |
| 116 | * @raw: The raw IIO to convert |
| 117 | * @processed: The result of the conversion |
| 118 | * @scale: Scale factor to apply during the conversion |
| 119 | * |
| 120 | * Returns an error code or 0. |
| 121 | * |
| 122 | * This function converts a raw value to processed value for a specific channel. |
| 123 | * A raw value is the device internal representation of a sample and the value |
| 124 | * returned by iio_read_channel_raw, so the unit of that value is device |
| 125 | * depended. A processed value on the other hand is value has a normed unit |
| 126 | * according with the IIO specification. |
| 127 | * |
| 128 | * The scale factor allows to increase the precession of the returned value. For |
| 129 | * a scale factor of 1 the function will return the result in the normal IIO |
| 130 | * unit for the channel type. E.g. millivolt for voltage channels, if you want |
| 131 | * nanovolts instead pass 1000 as the scale factor. |
| 132 | */ |
| 133 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, |
| 134 | int *processed, unsigned int scale); |
| 135 | |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 136 | #endif |