blob: b9cd454f69e2bbea397882570856037693563f13 [file] [log] [blame]
Jonathan Cameron7d438172011-08-12 17:47:53 +01001
Jonathan Cameron847ec802009-08-18 18:06:19 +01002/* 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 Cameron847ec802009-08-18 18:06:19 +010010#ifndef _INDUSTRIAL_IO_H_
11#define _INDUSTRIAL_IO_H_
12
13#include <linux/device.h>
14#include <linux/cdev.h>
Jonathan Cameronaf5046a2011-10-26 17:41:32 +010015#include "types.h"
Jonathan Cameron847ec802009-08-18 18:06:19 +010016/* IIO TODO LIST */
Jonathan Cameron751a3702010-06-26 12:54:19 +010017/*
Jonathan Cameron847ec802009-08-18 18:06:19 +010018 * Provide means of adjusting timer accuracy.
19 * Currently assumes nano seconds.
20 */
21
Jonathan Cameron1e8dfcc2011-08-30 12:41:11 +010022enum iio_data_type {
23 IIO_RAW,
24 IIO_PROCESSED,
25};
26
Jonathan Cameron1d892712011-05-18 14:40:51 +010027/* Could add the raw attributes as well - allowing buffer only devices */
28enum iio_chan_info_enum {
Justin P. Mattock4abf6f82012-02-29 22:00:38 -080029 /* 0 is reserved for raw attributes */
Jonathan Cameronc8a9f802011-10-26 17:41:36 +010030 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 Camerondf94aba2011-11-27 11:39:12 +000038 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
Jonathan Cameron1d892712011-05-18 14:40:51 +010039};
40
Jonathan Cameronc8a9f802011-10-26 17:41:36 +010041#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 Camerondf94aba2011-11-27 11:39:12 +000078#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 Cameronc8a9f802011-10-26 17:41:36 +010084
Jonathan Cameron8310b862011-09-02 17:14:36 +010085enum iio_endian {
86 IIO_CPU,
87 IIO_BE,
88 IIO_LE,
89};
90
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +010091struct iio_chan_spec;
92struct iio_dev;
93
94/**
95 * struct iio_chan_spec_ext_info - Extended channel info attribute
96 * @name: Info attribute name
97 * @shared: Whether this attribute is shared between all channels.
98 * @read: Read callback for this info attribute, may be NULL.
99 * @write: Write callback for this info attribute, may be NULL.
100 */
101struct iio_chan_spec_ext_info {
102 const char *name;
103 bool shared;
104 ssize_t (*read)(struct iio_dev *, struct iio_chan_spec const *,
105 char *buf);
106 ssize_t (*write)(struct iio_dev *, struct iio_chan_spec const *,
107 const char *buf, size_t len);
108};
109
Jonathan Cameron1d892712011-05-18 14:40:51 +0100110/**
111 * struct iio_chan_spec - specification of a single channel
112 * @type: What type of measurement is the channel making.
Justin P. Mattock4abf6f82012-02-29 22:00:38 -0800113 * @channel: What number or name do we wish to assign the channel.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100114 * @channel2: If there is a second number for a differential
115 * channel then this is it. If modified is set then the
116 * value here specifies the modifier.
117 * @address: Driver specific identifier.
118 * @scan_index: Monotonic index to give ordering in scans when read
119 * from a buffer.
120 * @scan_type: Sign: 's' or 'u' to specify signed or unsigned
121 * realbits: Number of valid bits of data
122 * storage_bits: Realbits + padding
123 * shift: Shift right by this before masking out
124 * realbits.
Jonathan Cameron8310b862011-09-02 17:14:36 +0100125 * endianness: little or big endian
Jonathan Cameron1d892712011-05-18 14:40:51 +0100126 * @info_mask: What information is to be exported about this channel.
127 * This includes calibbias, scale etc.
128 * @event_mask: What events can this channel produce.
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100129 * @ext_info: Array of extended info attributes for this channel.
130 * The array is NULL terminated, the last element should
131 * have it's name field set to NULL.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100132 * @extend_name: Allows labeling of channel attributes with an
133 * informative name. Note this has no effect codes etc,
134 * unlike modifiers.
Jonathan Cameron6c63dde2011-12-05 21:56:00 +0000135 * @datasheet_name: A name used in in kernel mapping of channels. It should
Justin P. Mattock4abf6f82012-02-29 22:00:38 -0800136 * correspond to the first name that the channel is referred
Jonathan Cameron6c63dde2011-12-05 21:56:00 +0000137 * to by in the datasheet (e.g. IND), or the nearest
138 * possible compound name (e.g. IND-INC).
Jonathan Cameron1d892712011-05-18 14:40:51 +0100139 * @processed_val: Flag to specify the data access attribute should be
140 * *_input rather than *_raw.
141 * @modified: Does a modifier apply to this channel. What these are
142 * depends on the channel type. Modifier is set in
143 * channel2. Examples are IIO_MOD_X for axial sensors about
144 * the 'x' axis.
145 * @indexed: Specify the channel has a numerical index. If not,
146 * the value in channel will be suppressed for attribute
147 * but not for event codes. Typically set it to 0 when
148 * the index is false.
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100149 * @differential: Channel is differential.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100150 */
151struct iio_chan_spec {
152 enum iio_chan_type type;
153 int channel;
154 int channel2;
155 unsigned long address;
156 int scan_index;
157 struct {
158 char sign;
159 u8 realbits;
160 u8 storagebits;
161 u8 shift;
Jonathan Cameron8310b862011-09-02 17:14:36 +0100162 enum iio_endian endianness;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100163 } scan_type;
Michael Hennerich1c5e6a32011-07-20 15:03:07 +0200164 long info_mask;
165 long event_mask;
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100166 const struct iio_chan_spec_ext_info *ext_info;
Michael Hennerich1c5e6a32011-07-20 15:03:07 +0200167 char *extend_name;
Jonathan Cameron6c63dde2011-12-05 21:56:00 +0000168 const char *datasheet_name;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100169 unsigned processed_val:1;
170 unsigned modified:1;
171 unsigned indexed:1;
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100172 unsigned output:1;
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100173 unsigned differential:1;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100174};
Jonathan Camerondf9c1c42011-08-12 17:56:03 +0100175
Jonathan Cameron1d892712011-05-18 14:40:51 +0100176#define IIO_ST(si, rb, sb, sh) \
177 { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh }
178
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100179/* Macro assumes input channels */
180#define IIO_CHAN(_type, _mod, _indexed, _proc, _name, _chan, _chan2, \
Jonathan Cameronaaf370d2011-05-18 14:41:16 +0100181 _inf_mask, _address, _si, _stype, _event_mask) \
Jonathan Cameron1d892712011-05-18 14:40:51 +0100182 { .type = _type, \
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100183 .output = 0, \
Jonathan Cameron1d892712011-05-18 14:40:51 +0100184 .modified = _mod, \
185 .indexed = _indexed, \
186 .processed_val = _proc, \
187 .extend_name = _name, \
188 .channel = _chan, \
189 .channel2 = _chan2, \
190 .info_mask = _inf_mask, \
191 .address = _address, \
192 .scan_index = _si, \
193 .scan_type = _stype, \
Jonathan Cameronaaf370d2011-05-18 14:41:16 +0100194 .event_mask = _event_mask }
Jonathan Cameron1d892712011-05-18 14:40:51 +0100195
196#define IIO_CHAN_SOFT_TIMESTAMP(_si) \
197 { .type = IIO_TIMESTAMP, .channel = -1, \
198 .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) }
199
Jonathan Cameron847ec802009-08-18 18:06:19 +0100200/**
201 * iio_get_time_ns() - utility function to get a time stamp for events etc
202 **/
203static inline s64 iio_get_time_ns(void)
204{
205 struct timespec ts;
206 /*
207 * calls getnstimeofday.
208 * If hrtimers then up to ns accurate, if not microsecond.
209 */
210 ktime_get_real_ts(&ts);
211
212 return timespec_to_ns(&ts);
213}
214
Jonathan Cameron847ec802009-08-18 18:06:19 +0100215/* Device operating modes */
216#define INDIO_DIRECT_MODE 0x01
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100217#define INDIO_BUFFER_TRIGGERED 0x02
218#define INDIO_BUFFER_HARDWARE 0x08
Jonathan Cameron847ec802009-08-18 18:06:19 +0100219
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100220#define INDIO_ALL_BUFFER_MODES \
221 (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100222
Michael Hennerich43a43602011-06-27 13:07:09 +0100223struct iio_trigger; /* forward declaration */
Jonathan Cameron7ae8cf62011-08-30 12:32:44 +0100224struct iio_dev;
Michael Hennerich43a43602011-06-27 13:07:09 +0100225
Jonathan Cameron847ec802009-08-18 18:06:19 +0100226/**
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100227 * struct iio_info - constant information about device
228 * @driver_module: module structure used to ensure correct
Jonathan Cameron847ec802009-08-18 18:06:19 +0100229 * ownership of chrdevs etc
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100230 * @event_attrs: event control attributes
231 * @attrs: general purpose device attributes
232 * @read_raw: function to request a value from the device.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100233 * mask specifies which value. Note 0 means a reading of
234 * the channel in question. Return value will specify the
235 * type of value returned by the device. val and val2 will
236 * contain the elements making up the returned value.
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100237 * @write_raw: function to write a value to the device.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100238 * Parameters are the same as for read_raw.
Michael Hennerich5c04af02011-06-27 13:07:10 +0100239 * @write_raw_get_fmt: callback function to query the expected
240 * format/precision. If not set by the driver, write_raw
241 * returns IIO_VAL_INT_PLUS_MICRO.
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100242 * @read_event_config: find out if the event is enabled.
243 * @write_event_config: set if the event is enabled.
244 * @read_event_value: read a value associated with the event. Meaning
Jonathan Cameron1d892712011-05-18 14:40:51 +0100245 * is event dependant. event_code specifies which event.
Justin P. Mattock4abf6f82012-02-29 22:00:38 -0800246 * @write_event_value: write the value associated with the event.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100247 * Meaning is event dependent.
Michael Hennerich43a43602011-06-27 13:07:09 +0100248 * @validate_trigger: function to validate the trigger when the
249 * current trigger gets changed.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100250 **/
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100251struct iio_info {
Jonathan Cameron847ec802009-08-18 18:06:19 +0100252 struct module *driver_module;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100253 struct attribute_group *event_attrs;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100254 const struct attribute_group *attrs;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100255
Jonathan Cameron1d892712011-05-18 14:40:51 +0100256 int (*read_raw)(struct iio_dev *indio_dev,
257 struct iio_chan_spec const *chan,
258 int *val,
259 int *val2,
260 long mask);
261
262 int (*write_raw)(struct iio_dev *indio_dev,
263 struct iio_chan_spec const *chan,
264 int val,
265 int val2,
266 long mask);
267
Michael Hennerich5c04af02011-06-27 13:07:10 +0100268 int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
269 struct iio_chan_spec const *chan,
270 long mask);
271
Jonathan Cameron1d892712011-05-18 14:40:51 +0100272 int (*read_event_config)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100273 u64 event_code);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100274
275 int (*write_event_config)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100276 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100277 int state);
278
279 int (*read_event_value)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100280 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100281 int *val);
282 int (*write_event_value)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100283 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100284 int val);
Michael Hennerich43a43602011-06-27 13:07:09 +0100285 int (*validate_trigger)(struct iio_dev *indio_dev,
286 struct iio_trigger *trig);
Jonathan Cameron4d5f8d32011-12-05 21:37:12 +0000287 int (*update_scan_mode)(struct iio_dev *indio_dev,
288 const unsigned long *scan_mask);
Michael Henneriche553f182012-03-01 10:51:03 +0100289 int (*debugfs_reg_access)(struct iio_dev *indio_dev,
290 unsigned reg, unsigned writeval,
291 unsigned *readval);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100292};
293
Jonathan Cameron847ec802009-08-18 18:06:19 +0100294/**
Jonathan Cameron16122442011-12-05 22:18:14 +0000295 * struct iio_buffer_setup_ops - buffer setup related callbacks
296 * @preenable: [DRIVER] function to run prior to marking buffer enabled
297 * @postenable: [DRIVER] function to run after marking buffer enabled
298 * @predisable: [DRIVER] function to run prior to marking buffer
299 * disabled
300 * @postdisable: [DRIVER] function to run after marking buffer disabled
301 */
302struct iio_buffer_setup_ops {
303 int (*preenable)(struct iio_dev *);
304 int (*postenable)(struct iio_dev *);
305 int (*predisable)(struct iio_dev *);
306 int (*postdisable)(struct iio_dev *);
307};
308
309/**
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100310 * struct iio_dev - industrial I/O device
311 * @id: [INTERN] used to identify device internally
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100312 * @modes: [DRIVER] operating modes supported by device
313 * @currentmode: [DRIVER] current operating mode
314 * @dev: [DRIVER] device structure, should be assigned a parent
315 * and owner
Jonathan Cameron5aa96182011-08-30 12:41:06 +0100316 * @event_interface: [INTERN] event chrdevs associated with interrupt lines
Jonathan Cameron14555b12011-09-21 11:15:57 +0100317 * @buffer: [DRIVER] any buffer present
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100318 * @mlock: [INTERN] lock used to prevent simultaneous device state
319 * changes
320 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
Jonathan Cameron32b5eec2011-09-02 17:14:38 +0100321 * @masklength: [INTERN] the length of the mask established from
322 * channels
Jonathan Cameron959d2952011-12-05 21:37:13 +0000323 * @active_scan_mask: [INTERN] union of all scan masks requested by buffers
Jonathan Cameron14555b12011-09-21 11:15:57 +0100324 * @trig: [INTERN] current device trigger (buffer modes)
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100325 * @pollfunc: [DRIVER] function run on trigger being received
326 * @channels: [DRIVER] channel specification structure table
327 * @num_channels: [DRIVER] number of chanels specified in @channels.
328 * @channel_attr_list: [INTERN] keep track of automatically created channel
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100329 * attributes
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100330 * @chan_attr_group: [INTERN] group for all attrs in base directory
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100331 * @name: [DRIVER] name of the device.
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100332 * @info: [DRIVER] callbacks and constant info from driver
Jonathan Cameronac917a82012-02-15 19:48:00 +0000333 * @info_exist_lock: [INTERN] lock to prevent use during removal
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100334 * @chrdev: [INTERN] associated character device
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100335 * @groups: [INTERN] attribute groups
336 * @groupcounter: [INTERN] index of next attribute group
Lars-Peter Clausenbb014432011-12-19 15:23:45 +0100337 * @flags: [INTERN] file ops related flags including busy flag.
Michael Henneriche553f182012-03-01 10:51:03 +0100338 * @debugfs_dentry: [INTERN] device specific debugfs dentry.
339 * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
340 */
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100341struct iio_dev {
342 int id;
Jonathan Cameron4024bc72011-08-12 17:08:53 +0100343
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100344 int modes;
345 int currentmode;
346 struct device dev;
347
Jonathan Cameron5aa96182011-08-30 12:41:06 +0100348 struct iio_event_interface *event_interface;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100349
Jonathan Cameron14555b12011-09-21 11:15:57 +0100350 struct iio_buffer *buffer;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100351 struct mutex mlock;
352
Michael Hennerichcd4361c2012-02-22 13:16:49 +0100353 const unsigned long *available_scan_masks;
Jonathan Cameron32b5eec2011-09-02 17:14:38 +0100354 unsigned masklength;
Michael Hennerichcd4361c2012-02-22 13:16:49 +0100355 const unsigned long *active_scan_mask;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100356 struct iio_trigger *trig;
357 struct iio_poll_func *pollfunc;
358
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100359 struct iio_chan_spec const *channels;
360 int num_channels;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100361
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100362 struct list_head channel_attr_list;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100363 struct attribute_group chan_attr_group;
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100364 const char *name;
365 const struct iio_info *info;
Jonathan Cameronac917a82012-02-15 19:48:00 +0000366 struct mutex info_exist_lock;
Jonathan Cameron16122442011-12-05 22:18:14 +0000367 const struct iio_buffer_setup_ops *setup_ops;
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100368 struct cdev chrdev;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100369#define IIO_MAX_GROUPS 6
370 const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
371 int groupcounter;
Lars-Peter Clausenbb014432011-12-19 15:23:45 +0100372
373 unsigned long flags;
Michael Henneriche553f182012-03-01 10:51:03 +0100374#if defined(CONFIG_DEBUG_FS)
375 struct dentry *debugfs_dentry;
376 unsigned cached_reg_addr;
377#endif
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100378};
379
380/**
Jonathan Cameron5fb21c82011-12-05 21:37:10 +0000381 * iio_find_channel_from_si() - get channel from its scan index
382 * @indio_dev: device
383 * @si: scan index to match
384 */
385const struct iio_chan_spec
386*iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
387
388/**
Jonathan Cameron847ec802009-08-18 18:06:19 +0100389 * iio_device_register() - register a device with the IIO subsystem
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100390 * @indio_dev: Device structure filled by the device driver
Jonathan Cameron847ec802009-08-18 18:06:19 +0100391 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100392int iio_device_register(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100393
394/**
395 * iio_device_unregister() - unregister a device from the IIO subsystem
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100396 * @indio_dev: Device structure representing the device.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100397 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100398void iio_device_unregister(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100399
400/**
Jonathan Cameron847ec802009-08-18 18:06:19 +0100401 * iio_push_event() - try to add event to the list for userspace reading
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100402 * @indio_dev: IIO device structure
Jonathan Cameron847ec802009-08-18 18:06:19 +0100403 * @ev_code: What event
Randy Dunlap4c572602009-10-04 19:34:02 -0700404 * @timestamp: When the event occurred
Jonathan Cameron847ec802009-08-18 18:06:19 +0100405 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100406int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100407
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100408extern struct bus_type iio_bus_type;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100409
410/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700411 * iio_put_device() - reference counted deallocation of struct device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100412 * @dev: the iio_device containing the device
413 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100414static inline void iio_put_device(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100415{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100416 if (indio_dev)
417 put_device(&indio_dev->dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100418};
419
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100420/* Can we make this smaller? */
421#define IIO_ALIGN L1_CACHE_BYTES
Jonathan Cameron847ec802009-08-18 18:06:19 +0100422/**
423 * iio_allocate_device() - allocate an iio_dev from a driver
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100424 * @sizeof_priv: Space to allocate for private structure.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100425 **/
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100426struct iio_dev *iio_allocate_device(int sizeof_priv);
427
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100428static inline void *iio_priv(const struct iio_dev *indio_dev)
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100429{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100430 return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100431}
432
433static inline struct iio_dev *iio_priv_to_dev(void *priv)
434{
435 return (struct iio_dev *)((char *)priv -
436 ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
437}
Jonathan Cameron847ec802009-08-18 18:06:19 +0100438
439/**
440 * iio_free_device() - free an iio_dev from a driver
Randy Dunlap4c572602009-10-04 19:34:02 -0700441 * @dev: the iio_dev associated with the device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100442 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100443void iio_free_device(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100444
445/**
Jonathan Cameron14555b12011-09-21 11:15:57 +0100446 * iio_buffer_enabled() - helper function to test if the buffer is enabled
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100447 * @indio_dev: IIO device info structure for device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100448 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100449static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100450{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100451 return indio_dev->currentmode
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100452 & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100453};
454
Michael Henneriche553f182012-03-01 10:51:03 +0100455/**
456 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
457 * @indio_dev: IIO device info structure for device
458 **/
459#if defined(CONFIG_DEBUG_FS)
460static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
461{
462 return indio_dev->debugfs_dentry;
463};
464#else
465static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
466{
467 return NULL;
468};
469#endif
470
Jonathan Cameron847ec802009-08-18 18:06:19 +0100471#endif /* _INDUSTRIAL_IO_H_ */