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