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_ |
Greg Kroah-Hartman | 9f488ba | 2012-11-13 10:46:33 -0800 | [diff] [blame] | 12 | |
| 13 | #include <linux/types.h> |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 14 | #include <linux/iio/types.h> |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 15 | |
| 16 | struct iio_dev; |
| 17 | struct iio_chan_spec; |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 18 | struct device; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * struct iio_channel - everything needed for a consumer to use a channel |
| 22 | * @indio_dev: Device on which the channel exists. |
| 23 | * @channel: Full description of the channel. |
Jonathan Cameron | 0464415 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 24 | * @data: Data about the channel used by consumer. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 25 | */ |
| 26 | struct iio_channel { |
| 27 | struct iio_dev *indio_dev; |
| 28 | const struct iio_chan_spec *channel; |
Jonathan Cameron | 0464415 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 29 | void *data; |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | /** |
| 33 | * iio_channel_get() - get description of all that is needed to access channel. |
Guenter Roeck | 5aa57f0 | 2013-02-04 20:26:00 +0000 | [diff] [blame] | 34 | * @dev: Pointer to consumer device. Device name must match |
| 35 | * the name of the device as provided in the iio_map |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 36 | * with which the desired provider to consumer mapping |
| 37 | * was registered. |
| 38 | * @consumer_channel: Unique name to identify the channel on the consumer |
| 39 | * side. This typically describes the channels use within |
| 40 | * the consumer. E.g. 'battery_voltage' |
| 41 | */ |
Guenter Roeck | 5aa57f0 | 2013-02-04 20:26:00 +0000 | [diff] [blame] | 42 | struct iio_channel *iio_channel_get(struct device *dev, |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 43 | const char *consumer_channel); |
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_release() - release channels obtained via iio_channel_get |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 47 | * @chan: The channel to be released. |
| 48 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 49 | void iio_channel_release(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 50 | |
| 51 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 52 | * iio_channel_get_all() - get all channels associated with a client |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 53 | * @dev: Pointer to consumer device. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 54 | * |
| 55 | * Returns an array of iio_channel structures terminated with one with |
| 56 | * null iio_dev pointer. |
| 57 | * This function is used by fairly generic consumers to get all the |
| 58 | * channels registered as having this consumer. |
| 59 | */ |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 60 | struct iio_channel *iio_channel_get_all(struct device *dev); |
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_channel_release_all() - reverse iio_channel_get_all |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 64 | * @chan: Array of channels to be released. |
| 65 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 66 | void iio_channel_release_all(struct iio_channel *chan); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 67 | |
Jonathan Cameron | 92d1079 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 68 | struct iio_cb_buffer; |
| 69 | /** |
| 70 | * iio_channel_get_all_cb() - register callback for triggered capture |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 71 | * @dev: Pointer to client device. |
Jonathan Cameron | 92d1079 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 72 | * @cb: Callback function. |
| 73 | * @private: Private data passed to callback. |
| 74 | * |
| 75 | * NB right now we have no ability to mux data from multiple devices. |
| 76 | * So if the channels requested come from different devices this will |
| 77 | * fail. |
| 78 | */ |
Guenter Roeck | ca7d98d | 2013-01-31 21:43:00 +0000 | [diff] [blame] | 79 | struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, |
Jonathan Cameron | 92d1079 | 2012-06-30 20:06:00 +0100 | [diff] [blame] | 80 | int (*cb)(u8 *data, |
| 81 | void *private), |
| 82 | void *private); |
| 83 | /** |
| 84 | * iio_channel_release_all_cb() - release and unregister the callback. |
| 85 | * @cb_buffer: The callback buffer that was allocated. |
| 86 | */ |
| 87 | void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buffer); |
| 88 | |
| 89 | /** |
| 90 | * iio_channel_start_all_cb() - start the flow of data through callback. |
| 91 | * @cb_buff: The callback buffer we are starting. |
| 92 | */ |
| 93 | int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff); |
| 94 | |
| 95 | /** |
| 96 | * iio_channel_stop_all_cb() - stop the flow of data through the callback. |
| 97 | * @cb_buff: The callback buffer we are stopping. |
| 98 | */ |
| 99 | void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff); |
| 100 | |
| 101 | /** |
| 102 | * iio_channel_cb_get_channels() - get access to the underlying channels. |
| 103 | * @cb_buff: The callback buffer from whom we want the channel |
| 104 | * information. |
| 105 | * |
| 106 | * This function allows one to obtain information about the channels. |
| 107 | * Whilst this may allow direct reading if all buffers are disabled, the |
| 108 | * primary aim is to allow drivers that are consuming a channel to query |
| 109 | * things like scaling of the channel. |
| 110 | */ |
| 111 | struct iio_channel |
| 112 | *iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer); |
| 113 | |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 114 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 115 | * iio_read_channel_raw() - read from a given channel |
Lars-Peter Clausen | 45f010b | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 116 | * @chan: The channel being queried. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 117 | * @val: Value read back. |
| 118 | * |
| 119 | * Note raw reads from iio channels are in adc counts and hence |
| 120 | * scale will need to be applied if standard units required. |
| 121 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 122 | int iio_read_channel_raw(struct iio_channel *chan, |
| 123 | int *val); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 124 | |
| 125 | /** |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 126 | * iio_read_channel_processed() - read processed value from a given channel |
| 127 | * @chan: The channel being queried. |
| 128 | * @val: Value read back. |
| 129 | * |
| 130 | * Returns an error code or 0. |
| 131 | * |
| 132 | * This function will read a processed value from a channel. A processed value |
| 133 | * means that this value will have the correct unit and not some device internal |
| 134 | * representation. If the device does not support reporting a processed value |
| 135 | * the function will query the raw value and the channels scale and offset and |
| 136 | * do the appropriate transformation. |
| 137 | */ |
| 138 | int iio_read_channel_processed(struct iio_channel *chan, int *val); |
| 139 | |
| 140 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 141 | * iio_get_channel_type() - get the type of a channel |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 142 | * @channel: The channel being queried. |
| 143 | * @type: The type of the channel. |
| 144 | * |
| 145 | * returns the enum iio_chan_type of the channel |
| 146 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 147 | int iio_get_channel_type(struct iio_channel *channel, |
| 148 | enum iio_chan_type *type); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 149 | |
| 150 | /** |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 151 | * iio_read_channel_scale() - read the scale value for a channel |
Lars-Peter Clausen | 45f010b | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 152 | * @chan: The channel being queried. |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 153 | * @val: First part of value read back. |
| 154 | * @val2: Second part of value read back. |
| 155 | * |
| 156 | * Note returns a description of what is in val and val2, such |
| 157 | * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val |
| 158 | * + val2/1e6 |
| 159 | */ |
Jonathan Cameron | 314be14 | 2012-05-01 21:04:24 +0100 | [diff] [blame] | 160 | int iio_read_channel_scale(struct iio_channel *chan, int *val, |
| 161 | int *val2); |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 162 | |
Lars-Peter Clausen | 48e44ce | 2012-09-17 13:17:00 +0100 | [diff] [blame] | 163 | /** |
| 164 | * iio_convert_raw_to_processed() - Converts a raw value to a processed value |
| 165 | * @chan: The channel being queried |
| 166 | * @raw: The raw IIO to convert |
| 167 | * @processed: The result of the conversion |
| 168 | * @scale: Scale factor to apply during the conversion |
| 169 | * |
| 170 | * Returns an error code or 0. |
| 171 | * |
| 172 | * This function converts a raw value to processed value for a specific channel. |
| 173 | * A raw value is the device internal representation of a sample and the value |
| 174 | * returned by iio_read_channel_raw, so the unit of that value is device |
| 175 | * depended. A processed value on the other hand is value has a normed unit |
| 176 | * according with the IIO specification. |
| 177 | * |
| 178 | * The scale factor allows to increase the precession of the returned value. For |
| 179 | * a scale factor of 1 the function will return the result in the normal IIO |
| 180 | * unit for the channel type. E.g. millivolt for voltage channels, if you want |
| 181 | * nanovolts instead pass 1000 as the scale factor. |
| 182 | */ |
| 183 | int iio_convert_raw_to_processed(struct iio_channel *chan, int raw, |
| 184 | int *processed, unsigned int scale); |
| 185 | |
Jonathan Cameron | e27d75d | 2012-02-15 19:48:01 +0000 | [diff] [blame] | 186 | #endif |