Jonathan Cameron | 7d43817 | 2011-08-12 17:47:53 +0100 | [diff] [blame] | 1 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 2 | /* The industrial I/O core |
| 3 | * |
| 4 | * Copyright (c) 2008 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 | */ |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 10 | #ifndef _INDUSTRIAL_IO_H_ |
| 11 | #define _INDUSTRIAL_IO_H_ |
| 12 | |
| 13 | #include <linux/device.h> |
| 14 | #include <linux/cdev.h> |
Jonathan Cameron | af5046a | 2011-10-26 17:41:32 +0100 | [diff] [blame] | 15 | #include "types.h" |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 16 | /* IIO TODO LIST */ |
Jonathan Cameron | 751a370 | 2010-06-26 12:54:19 +0100 | [diff] [blame] | 17 | /* |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 18 | * Provide means of adjusting timer accuracy. |
| 19 | * Currently assumes nano seconds. |
| 20 | */ |
| 21 | |
Jonathan Cameron | 1e8dfcc | 2011-08-30 12:41:11 +0100 | [diff] [blame] | 22 | enum iio_data_type { |
| 23 | IIO_RAW, |
| 24 | IIO_PROCESSED, |
| 25 | }; |
| 26 | |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 27 | /* Could add the raw attributes as well - allowing buffer only devices */ |
| 28 | enum iio_chan_info_enum { |
Lars-Peter Clausen | 924f8a2 | 2011-10-26 17:41:35 +0100 | [diff] [blame] | 29 | /* 0 is reserverd for raw attributes */ |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 30 | IIO_CHAN_INFO_SCALE = 1, |
| 31 | IIO_CHAN_INFO_OFFSET, |
| 32 | IIO_CHAN_INFO_CALIBSCALE, |
| 33 | IIO_CHAN_INFO_CALIBBIAS, |
| 34 | IIO_CHAN_INFO_PEAK, |
| 35 | IIO_CHAN_INFO_PEAK_SCALE, |
| 36 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW, |
| 37 | IIO_CHAN_INFO_AVERAGE_RAW, |
Jonathan Cameron | df94aba | 2011-11-27 11:39:12 +0000 | [diff] [blame^] | 38 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY, |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 39 | }; |
| 40 | |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 41 | #define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2) |
| 42 | #define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1) |
| 43 | |
| 44 | #define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \ |
| 45 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE) |
| 46 | #define IIO_CHAN_INFO_SCALE_SHARED_BIT \ |
| 47 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SCALE) |
| 48 | #define IIO_CHAN_INFO_OFFSET_SEPARATE_BIT \ |
| 49 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_OFFSET) |
| 50 | #define IIO_CHAN_INFO_OFFSET_SHARED_BIT \ |
| 51 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_OFFSET) |
| 52 | #define IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT \ |
| 53 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBSCALE) |
| 54 | #define IIO_CHAN_INFO_CALIBSCALE_SHARED_BIT \ |
| 55 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBSCALE) |
| 56 | #define IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT \ |
| 57 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBBIAS) |
| 58 | #define IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT \ |
| 59 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBBIAS) |
| 60 | #define IIO_CHAN_INFO_PEAK_SEPARATE_BIT \ |
| 61 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAK) |
| 62 | #define IIO_CHAN_INFO_PEAK_SHARED_BIT \ |
| 63 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAK) |
| 64 | #define IIO_CHAN_INFO_PEAKSCALE_SEPARATE_BIT \ |
| 65 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAKSCALE) |
| 66 | #define IIO_CHAN_INFO_PEAKSCALE_SHARED_BIT \ |
| 67 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAKSCALE) |
| 68 | #define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT \ |
| 69 | IIO_CHAN_INFO_SEPARATE_BIT( \ |
| 70 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW) |
| 71 | #define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED_BIT \ |
| 72 | IIO_CHAN_INFO_SHARED_BIT( \ |
| 73 | IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW) |
| 74 | #define IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT \ |
| 75 | IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
| 76 | #define IIO_CHAN_INFO_AVERAGE_RAW_SHARED_BIT \ |
| 77 | IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_AVERAGE_RAW) |
Jonathan Cameron | df94aba | 2011-11-27 11:39:12 +0000 | [diff] [blame^] | 78 | #define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT \ |
| 79 | IIO_CHAN_INFO_SHARED_BIT( \ |
| 80 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |
| 81 | #define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \ |
| 82 | IIO_CHAN_INFO_SEPARATE_BIT( \ |
| 83 | IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) |
Jonathan Cameron | c8a9f80 | 2011-10-26 17:41:36 +0100 | [diff] [blame] | 84 | |
Jonathan Cameron | 8310b86 | 2011-09-02 17:14:36 +0100 | [diff] [blame] | 85 | enum iio_endian { |
| 86 | IIO_CPU, |
| 87 | IIO_BE, |
| 88 | IIO_LE, |
| 89 | }; |
| 90 | |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 91 | /** |
| 92 | * struct iio_chan_spec - specification of a single channel |
| 93 | * @type: What type of measurement is the channel making. |
| 94 | * @channel: What number or name do we wish to asign the channel. |
| 95 | * @channel2: If there is a second number for a differential |
| 96 | * channel then this is it. If modified is set then the |
| 97 | * value here specifies the modifier. |
| 98 | * @address: Driver specific identifier. |
| 99 | * @scan_index: Monotonic index to give ordering in scans when read |
| 100 | * from a buffer. |
| 101 | * @scan_type: Sign: 's' or 'u' to specify signed or unsigned |
| 102 | * realbits: Number of valid bits of data |
| 103 | * storage_bits: Realbits + padding |
| 104 | * shift: Shift right by this before masking out |
| 105 | * realbits. |
Jonathan Cameron | 8310b86 | 2011-09-02 17:14:36 +0100 | [diff] [blame] | 106 | * endianness: little or big endian |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 107 | * @info_mask: What information is to be exported about this channel. |
| 108 | * This includes calibbias, scale etc. |
| 109 | * @event_mask: What events can this channel produce. |
| 110 | * @extend_name: Allows labeling of channel attributes with an |
| 111 | * informative name. Note this has no effect codes etc, |
| 112 | * unlike modifiers. |
| 113 | * @processed_val: Flag to specify the data access attribute should be |
| 114 | * *_input rather than *_raw. |
| 115 | * @modified: Does a modifier apply to this channel. What these are |
| 116 | * depends on the channel type. Modifier is set in |
| 117 | * channel2. Examples are IIO_MOD_X for axial sensors about |
| 118 | * the 'x' axis. |
| 119 | * @indexed: Specify the channel has a numerical index. If not, |
| 120 | * the value in channel will be suppressed for attribute |
| 121 | * but not for event codes. Typically set it to 0 when |
| 122 | * the index is false. |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 123 | * @differential: Channel is differential. |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 124 | */ |
| 125 | struct iio_chan_spec { |
| 126 | enum iio_chan_type type; |
| 127 | int channel; |
| 128 | int channel2; |
| 129 | unsigned long address; |
| 130 | int scan_index; |
| 131 | struct { |
| 132 | char sign; |
| 133 | u8 realbits; |
| 134 | u8 storagebits; |
| 135 | u8 shift; |
Jonathan Cameron | 8310b86 | 2011-09-02 17:14:36 +0100 | [diff] [blame] | 136 | enum iio_endian endianness; |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 137 | } scan_type; |
Michael Hennerich | 1c5e6a3 | 2011-07-20 15:03:07 +0200 | [diff] [blame] | 138 | long info_mask; |
| 139 | long event_mask; |
| 140 | char *extend_name; |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 141 | unsigned processed_val:1; |
| 142 | unsigned modified:1; |
| 143 | unsigned indexed:1; |
Jonathan Cameron | c6fc806 | 2011-09-02 17:14:34 +0100 | [diff] [blame] | 144 | unsigned output:1; |
Jonathan Cameron | ade7ef7 | 2011-09-02 17:14:45 +0100 | [diff] [blame] | 145 | unsigned differential:1; |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 146 | }; |
Jonathan Cameron | df9c1c4 | 2011-08-12 17:56:03 +0100 | [diff] [blame] | 147 | |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 148 | #define IIO_ST(si, rb, sb, sh) \ |
| 149 | { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh } |
| 150 | |
Jonathan Cameron | c6fc806 | 2011-09-02 17:14:34 +0100 | [diff] [blame] | 151 | /* Macro assumes input channels */ |
| 152 | #define IIO_CHAN(_type, _mod, _indexed, _proc, _name, _chan, _chan2, \ |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 153 | _inf_mask, _address, _si, _stype, _event_mask) \ |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 154 | { .type = _type, \ |
Jonathan Cameron | c6fc806 | 2011-09-02 17:14:34 +0100 | [diff] [blame] | 155 | .output = 0, \ |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 156 | .modified = _mod, \ |
| 157 | .indexed = _indexed, \ |
| 158 | .processed_val = _proc, \ |
| 159 | .extend_name = _name, \ |
| 160 | .channel = _chan, \ |
| 161 | .channel2 = _chan2, \ |
| 162 | .info_mask = _inf_mask, \ |
| 163 | .address = _address, \ |
| 164 | .scan_index = _si, \ |
| 165 | .scan_type = _stype, \ |
Jonathan Cameron | aaf370d | 2011-05-18 14:41:16 +0100 | [diff] [blame] | 166 | .event_mask = _event_mask } |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 167 | |
| 168 | #define IIO_CHAN_SOFT_TIMESTAMP(_si) \ |
| 169 | { .type = IIO_TIMESTAMP, .channel = -1, \ |
| 170 | .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) } |
| 171 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 172 | /** |
| 173 | * iio_get_time_ns() - utility function to get a time stamp for events etc |
| 174 | **/ |
| 175 | static inline s64 iio_get_time_ns(void) |
| 176 | { |
| 177 | struct timespec ts; |
| 178 | /* |
| 179 | * calls getnstimeofday. |
| 180 | * If hrtimers then up to ns accurate, if not microsecond. |
| 181 | */ |
| 182 | ktime_get_real_ts(&ts); |
| 183 | |
| 184 | return timespec_to_ns(&ts); |
| 185 | } |
| 186 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 187 | /* Device operating modes */ |
| 188 | #define INDIO_DIRECT_MODE 0x01 |
Jonathan Cameron | ec3afa4 | 2011-09-21 11:15:54 +0100 | [diff] [blame] | 189 | #define INDIO_BUFFER_TRIGGERED 0x02 |
| 190 | #define INDIO_BUFFER_HARDWARE 0x08 |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 191 | |
Jonathan Cameron | ec3afa4 | 2011-09-21 11:15:54 +0100 | [diff] [blame] | 192 | #define INDIO_ALL_BUFFER_MODES \ |
| 193 | (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE) |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 194 | |
| 195 | /* Vast majority of this is set by the industrialio subsystem on a |
| 196 | * call to iio_device_register. */ |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 197 | #define IIO_VAL_INT 1 |
| 198 | #define IIO_VAL_INT_PLUS_MICRO 2 |
Michael Hennerich | 71646e2 | 2011-06-27 13:07:07 +0100 | [diff] [blame] | 199 | #define IIO_VAL_INT_PLUS_NANO 3 |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 200 | |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 201 | struct iio_trigger; /* forward declaration */ |
Jonathan Cameron | 7ae8cf6 | 2011-08-30 12:32:44 +0100 | [diff] [blame] | 202 | struct iio_dev; |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 203 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 204 | /** |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 205 | * struct iio_info - constant information about device |
| 206 | * @driver_module: module structure used to ensure correct |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 207 | * ownership of chrdevs etc |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 208 | * @event_attrs: event control attributes |
| 209 | * @attrs: general purpose device attributes |
| 210 | * @read_raw: function to request a value from the device. |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 211 | * mask specifies which value. Note 0 means a reading of |
| 212 | * the channel in question. Return value will specify the |
| 213 | * type of value returned by the device. val and val2 will |
| 214 | * contain the elements making up the returned value. |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 215 | * @write_raw: function to write a value to the device. |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 216 | * Parameters are the same as for read_raw. |
Michael Hennerich | 5c04af0 | 2011-06-27 13:07:10 +0100 | [diff] [blame] | 217 | * @write_raw_get_fmt: callback function to query the expected |
| 218 | * format/precision. If not set by the driver, write_raw |
| 219 | * returns IIO_VAL_INT_PLUS_MICRO. |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 220 | * @read_event_config: find out if the event is enabled. |
| 221 | * @write_event_config: set if the event is enabled. |
| 222 | * @read_event_value: read a value associated with the event. Meaning |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 223 | * is event dependant. event_code specifies which event. |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 224 | * @write_event_value: write the value associate with the event. |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 225 | * Meaning is event dependent. |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 226 | * @validate_trigger: function to validate the trigger when the |
| 227 | * current trigger gets changed. |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 228 | **/ |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 229 | struct iio_info { |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 230 | struct module *driver_module; |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 231 | struct attribute_group *event_attrs; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 232 | const struct attribute_group *attrs; |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 233 | |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 234 | int (*read_raw)(struct iio_dev *indio_dev, |
| 235 | struct iio_chan_spec const *chan, |
| 236 | int *val, |
| 237 | int *val2, |
| 238 | long mask); |
| 239 | |
| 240 | int (*write_raw)(struct iio_dev *indio_dev, |
| 241 | struct iio_chan_spec const *chan, |
| 242 | int val, |
| 243 | int val2, |
| 244 | long mask); |
| 245 | |
Michael Hennerich | 5c04af0 | 2011-06-27 13:07:10 +0100 | [diff] [blame] | 246 | int (*write_raw_get_fmt)(struct iio_dev *indio_dev, |
| 247 | struct iio_chan_spec const *chan, |
| 248 | long mask); |
| 249 | |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 250 | int (*read_event_config)(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 251 | u64 event_code); |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 252 | |
| 253 | int (*write_event_config)(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 254 | u64 event_code, |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 255 | int state); |
| 256 | |
| 257 | int (*read_event_value)(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 258 | u64 event_code, |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 259 | int *val); |
| 260 | int (*write_event_value)(struct iio_dev *indio_dev, |
Jonathan Cameron | 330c6c5 | 2011-09-02 17:14:39 +0100 | [diff] [blame] | 261 | u64 event_code, |
Jonathan Cameron | 1d89271 | 2011-05-18 14:40:51 +0100 | [diff] [blame] | 262 | int val); |
Michael Hennerich | 43a4360 | 2011-06-27 13:07:09 +0100 | [diff] [blame] | 263 | int (*validate_trigger)(struct iio_dev *indio_dev, |
| 264 | struct iio_trigger *trig); |
| 265 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 266 | }; |
| 267 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 268 | /** |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 269 | * struct iio_dev - industrial I/O device |
| 270 | * @id: [INTERN] used to identify device internally |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 271 | * @modes: [DRIVER] operating modes supported by device |
| 272 | * @currentmode: [DRIVER] current operating mode |
| 273 | * @dev: [DRIVER] device structure, should be assigned a parent |
| 274 | * and owner |
Jonathan Cameron | 5aa9618 | 2011-08-30 12:41:06 +0100 | [diff] [blame] | 275 | * @event_interface: [INTERN] event chrdevs associated with interrupt lines |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 276 | * @buffer: [DRIVER] any buffer present |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 277 | * @mlock: [INTERN] lock used to prevent simultaneous device state |
| 278 | * changes |
| 279 | * @available_scan_masks: [DRIVER] optional array of allowed bitmasks |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 280 | * @masklength: [INTERN] the length of the mask established from |
| 281 | * channels |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 282 | * @trig: [INTERN] current device trigger (buffer modes) |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 283 | * @pollfunc: [DRIVER] function run on trigger being received |
| 284 | * @channels: [DRIVER] channel specification structure table |
| 285 | * @num_channels: [DRIVER] number of chanels specified in @channels. |
| 286 | * @channel_attr_list: [INTERN] keep track of automatically created channel |
Jonathan Cameron | 1a25e59 | 2011-08-30 12:41:12 +0100 | [diff] [blame] | 287 | * attributes |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 288 | * @chan_attr_group: [INTERN] group for all attrs in base directory |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 289 | * @name: [DRIVER] name of the device. |
Jonathan Cameron | 1a25e59 | 2011-08-30 12:41:12 +0100 | [diff] [blame] | 290 | * @info: [DRIVER] callbacks and constant info from driver |
| 291 | * @chrdev: [INTERN] associated character device |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 292 | * @groups: [INTERN] attribute groups |
| 293 | * @groupcounter: [INTERN] index of next attribute group |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 294 | **/ |
| 295 | struct iio_dev { |
| 296 | int id; |
Jonathan Cameron | 4024bc7 | 2011-08-12 17:08:53 +0100 | [diff] [blame] | 297 | |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 298 | int modes; |
| 299 | int currentmode; |
| 300 | struct device dev; |
| 301 | |
Jonathan Cameron | 5aa9618 | 2011-08-30 12:41:06 +0100 | [diff] [blame] | 302 | struct iio_event_interface *event_interface; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 303 | |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 304 | struct iio_buffer *buffer; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 305 | struct mutex mlock; |
| 306 | |
Jonathan Cameron | 32b5eec | 2011-09-02 17:14:38 +0100 | [diff] [blame] | 307 | unsigned long *available_scan_masks; |
| 308 | unsigned masklength; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 309 | struct iio_trigger *trig; |
| 310 | struct iio_poll_func *pollfunc; |
| 311 | |
Jonathan Cameron | 1a25e59 | 2011-08-30 12:41:12 +0100 | [diff] [blame] | 312 | struct iio_chan_spec const *channels; |
| 313 | int num_channels; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 314 | |
Jonathan Cameron | 1a25e59 | 2011-08-30 12:41:12 +0100 | [diff] [blame] | 315 | struct list_head channel_attr_list; |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 316 | struct attribute_group chan_attr_group; |
Jonathan Cameron | 1a25e59 | 2011-08-30 12:41:12 +0100 | [diff] [blame] | 317 | const char *name; |
| 318 | const struct iio_info *info; |
| 319 | struct cdev chrdev; |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 320 | #define IIO_MAX_GROUPS 6 |
| 321 | const struct attribute_group *groups[IIO_MAX_GROUPS + 1]; |
| 322 | int groupcounter; |
Jonathan Cameron | 6fe8135 | 2011-05-18 14:42:37 +0100 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | /** |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 326 | * iio_device_register() - register a device with the IIO subsystem |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 327 | * @indio_dev: Device structure filled by the device driver |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 328 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 329 | int iio_device_register(struct iio_dev *indio_dev); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * iio_device_unregister() - unregister a device from the IIO subsystem |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 333 | * @indio_dev: Device structure representing the device. |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 334 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 335 | void iio_device_unregister(struct iio_dev *indio_dev); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 336 | |
| 337 | /** |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 338 | * iio_push_event() - try to add event to the list for userspace reading |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 339 | * @indio_dev: IIO device structure |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 340 | * @ev_code: What event |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 341 | * @timestamp: When the event occurred |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 342 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 343 | int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 344 | |
Jonathan Cameron | 5aaaeba | 2010-05-04 14:43:00 +0100 | [diff] [blame] | 345 | extern struct bus_type iio_bus_type; |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 346 | |
| 347 | /** |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 348 | * iio_put_device() - reference counted deallocation of struct device |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 349 | * @dev: the iio_device containing the device |
| 350 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 351 | static inline void iio_put_device(struct iio_dev *indio_dev) |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 352 | { |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 353 | if (indio_dev) |
| 354 | put_device(&indio_dev->dev); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 355 | }; |
| 356 | |
Jonathan Cameron | 6f7c8ee | 2011-04-15 18:55:56 +0100 | [diff] [blame] | 357 | /* Can we make this smaller? */ |
| 358 | #define IIO_ALIGN L1_CACHE_BYTES |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 359 | /** |
| 360 | * iio_allocate_device() - allocate an iio_dev from a driver |
Jonathan Cameron | 6f7c8ee | 2011-04-15 18:55:56 +0100 | [diff] [blame] | 361 | * @sizeof_priv: Space to allocate for private structure. |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 362 | **/ |
Jonathan Cameron | 6f7c8ee | 2011-04-15 18:55:56 +0100 | [diff] [blame] | 363 | struct iio_dev *iio_allocate_device(int sizeof_priv); |
| 364 | |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 365 | static inline void *iio_priv(const struct iio_dev *indio_dev) |
Jonathan Cameron | 6f7c8ee | 2011-04-15 18:55:56 +0100 | [diff] [blame] | 366 | { |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 367 | return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN); |
Jonathan Cameron | 6f7c8ee | 2011-04-15 18:55:56 +0100 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | static inline struct iio_dev *iio_priv_to_dev(void *priv) |
| 371 | { |
| 372 | return (struct iio_dev *)((char *)priv - |
| 373 | ALIGN(sizeof(struct iio_dev), IIO_ALIGN)); |
| 374 | } |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 375 | |
| 376 | /** |
| 377 | * iio_free_device() - free an iio_dev from a driver |
Randy Dunlap | 4c57260 | 2009-10-04 19:34:02 -0700 | [diff] [blame] | 378 | * @dev: the iio_dev associated with the device |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 379 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 380 | void iio_free_device(struct iio_dev *indio_dev); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 381 | |
| 382 | /** |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 383 | * iio_buffer_enabled() - helper function to test if the buffer is enabled |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 384 | * @indio_dev: IIO device info structure for device |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 385 | **/ |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 386 | static inline bool iio_buffer_enabled(struct iio_dev *indio_dev) |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 387 | { |
Jonathan Cameron | f8c6f4e | 2011-10-06 17:14:35 +0100 | [diff] [blame] | 388 | return indio_dev->currentmode |
Jonathan Cameron | ec3afa4 | 2011-09-21 11:15:54 +0100 | [diff] [blame] | 389 | & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE); |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 390 | }; |
| 391 | |
Jonathan Cameron | 847ec80 | 2009-08-18 18:06:19 +0100 | [diff] [blame] | 392 | #endif /* _INDUSTRIAL_IO_H_ */ |