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