blob: 66c2604c92c4e080c54377863162d2a0e89fc6cb [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 {
Lars-Peter Clausen924f8a22011-10-26 17:41:35 +010029 /* 0 is reserverd 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 Cameron1d892712011-05-18 14:40:51 +010038};
39
Jonathan Cameronc8a9f802011-10-26 17:41:36 +010040#define IIO_CHAN_INFO_SHARED_BIT(type) BIT(type*2)
41#define IIO_CHAN_INFO_SEPARATE_BIT(type) BIT(type*2 + 1)
42
43#define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \
44 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE)
45#define IIO_CHAN_INFO_SCALE_SHARED_BIT \
46 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SCALE)
47#define IIO_CHAN_INFO_OFFSET_SEPARATE_BIT \
48 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_OFFSET)
49#define IIO_CHAN_INFO_OFFSET_SHARED_BIT \
50 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_OFFSET)
51#define IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT \
52 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBSCALE)
53#define IIO_CHAN_INFO_CALIBSCALE_SHARED_BIT \
54 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBSCALE)
55#define IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT \
56 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBBIAS)
57#define IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT \
58 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBBIAS)
59#define IIO_CHAN_INFO_PEAK_SEPARATE_BIT \
60 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAK)
61#define IIO_CHAN_INFO_PEAK_SHARED_BIT \
62 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAK)
63#define IIO_CHAN_INFO_PEAKSCALE_SEPARATE_BIT \
64 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAKSCALE)
65#define IIO_CHAN_INFO_PEAKSCALE_SHARED_BIT \
66 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAKSCALE)
67#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT \
68 IIO_CHAN_INFO_SEPARATE_BIT( \
69 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
70#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED_BIT \
71 IIO_CHAN_INFO_SHARED_BIT( \
72 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
73#define IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT \
74 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
75#define IIO_CHAN_INFO_AVERAGE_RAW_SHARED_BIT \
76 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
77
Jonathan Cameron8310b862011-09-02 17:14:36 +010078enum iio_endian {
79 IIO_CPU,
80 IIO_BE,
81 IIO_LE,
82};
83
Jonathan Cameron1d892712011-05-18 14:40:51 +010084/**
85 * struct iio_chan_spec - specification of a single channel
86 * @type: What type of measurement is the channel making.
87 * @channel: What number or name do we wish to asign the channel.
88 * @channel2: If there is a second number for a differential
89 * channel then this is it. If modified is set then the
90 * value here specifies the modifier.
91 * @address: Driver specific identifier.
92 * @scan_index: Monotonic index to give ordering in scans when read
93 * from a buffer.
94 * @scan_type: Sign: 's' or 'u' to specify signed or unsigned
95 * realbits: Number of valid bits of data
96 * storage_bits: Realbits + padding
97 * shift: Shift right by this before masking out
98 * realbits.
Jonathan Cameron8310b862011-09-02 17:14:36 +010099 * endianness: little or big endian
Jonathan Cameron1d892712011-05-18 14:40:51 +0100100 * @info_mask: What information is to be exported about this channel.
101 * This includes calibbias, scale etc.
102 * @event_mask: What events can this channel produce.
103 * @extend_name: Allows labeling of channel attributes with an
104 * informative name. Note this has no effect codes etc,
105 * unlike modifiers.
106 * @processed_val: Flag to specify the data access attribute should be
107 * *_input rather than *_raw.
108 * @modified: Does a modifier apply to this channel. What these are
109 * depends on the channel type. Modifier is set in
110 * channel2. Examples are IIO_MOD_X for axial sensors about
111 * the 'x' axis.
112 * @indexed: Specify the channel has a numerical index. If not,
113 * the value in channel will be suppressed for attribute
114 * but not for event codes. Typically set it to 0 when
115 * the index is false.
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100116 * @differential: Channel is differential.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100117 */
118struct iio_chan_spec {
119 enum iio_chan_type type;
120 int channel;
121 int channel2;
122 unsigned long address;
123 int scan_index;
124 struct {
125 char sign;
126 u8 realbits;
127 u8 storagebits;
128 u8 shift;
Jonathan Cameron8310b862011-09-02 17:14:36 +0100129 enum iio_endian endianness;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100130 } scan_type;
Michael Hennerich1c5e6a32011-07-20 15:03:07 +0200131 long info_mask;
132 long event_mask;
133 char *extend_name;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100134 unsigned processed_val:1;
135 unsigned modified:1;
136 unsigned indexed:1;
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100137 unsigned output:1;
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100138 unsigned differential:1;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100139};
Jonathan Camerondf9c1c42011-08-12 17:56:03 +0100140
Jonathan Cameron1d892712011-05-18 14:40:51 +0100141#define IIO_ST(si, rb, sb, sh) \
142 { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh }
143
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100144/* Macro assumes input channels */
145#define IIO_CHAN(_type, _mod, _indexed, _proc, _name, _chan, _chan2, \
Jonathan Cameronaaf370d2011-05-18 14:41:16 +0100146 _inf_mask, _address, _si, _stype, _event_mask) \
Jonathan Cameron1d892712011-05-18 14:40:51 +0100147 { .type = _type, \
Jonathan Cameronc6fc8062011-09-02 17:14:34 +0100148 .output = 0, \
Jonathan Cameron1d892712011-05-18 14:40:51 +0100149 .modified = _mod, \
150 .indexed = _indexed, \
151 .processed_val = _proc, \
152 .extend_name = _name, \
153 .channel = _chan, \
154 .channel2 = _chan2, \
155 .info_mask = _inf_mask, \
156 .address = _address, \
157 .scan_index = _si, \
158 .scan_type = _stype, \
Jonathan Cameronaaf370d2011-05-18 14:41:16 +0100159 .event_mask = _event_mask }
Jonathan Cameron1d892712011-05-18 14:40:51 +0100160
161#define IIO_CHAN_SOFT_TIMESTAMP(_si) \
162 { .type = IIO_TIMESTAMP, .channel = -1, \
163 .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) }
164
Jonathan Cameron847ec802009-08-18 18:06:19 +0100165/**
166 * iio_get_time_ns() - utility function to get a time stamp for events etc
167 **/
168static inline s64 iio_get_time_ns(void)
169{
170 struct timespec ts;
171 /*
172 * calls getnstimeofday.
173 * If hrtimers then up to ns accurate, if not microsecond.
174 */
175 ktime_get_real_ts(&ts);
176
177 return timespec_to_ns(&ts);
178}
179
Jonathan Cameron847ec802009-08-18 18:06:19 +0100180/* Device operating modes */
181#define INDIO_DIRECT_MODE 0x01
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100182#define INDIO_BUFFER_TRIGGERED 0x02
183#define INDIO_BUFFER_HARDWARE 0x08
Jonathan Cameron847ec802009-08-18 18:06:19 +0100184
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100185#define INDIO_ALL_BUFFER_MODES \
186 (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100187
188/* Vast majority of this is set by the industrialio subsystem on a
189 * call to iio_device_register. */
Jonathan Cameron1d892712011-05-18 14:40:51 +0100190#define IIO_VAL_INT 1
191#define IIO_VAL_INT_PLUS_MICRO 2
Michael Hennerich71646e22011-06-27 13:07:07 +0100192#define IIO_VAL_INT_PLUS_NANO 3
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100193
Michael Hennerich43a43602011-06-27 13:07:09 +0100194struct iio_trigger; /* forward declaration */
Jonathan Cameron7ae8cf62011-08-30 12:32:44 +0100195struct iio_dev;
Michael Hennerich43a43602011-06-27 13:07:09 +0100196
Jonathan Cameron847ec802009-08-18 18:06:19 +0100197/**
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100198 * struct iio_info - constant information about device
199 * @driver_module: module structure used to ensure correct
Jonathan Cameron847ec802009-08-18 18:06:19 +0100200 * ownership of chrdevs etc
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100201 * @event_attrs: event control attributes
202 * @attrs: general purpose device attributes
203 * @read_raw: function to request a value from the device.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100204 * mask specifies which value. Note 0 means a reading of
205 * the channel in question. Return value will specify the
206 * type of value returned by the device. val and val2 will
207 * contain the elements making up the returned value.
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100208 * @write_raw: function to write a value to the device.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100209 * Parameters are the same as for read_raw.
Michael Hennerich5c04af02011-06-27 13:07:10 +0100210 * @write_raw_get_fmt: callback function to query the expected
211 * format/precision. If not set by the driver, write_raw
212 * returns IIO_VAL_INT_PLUS_MICRO.
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100213 * @read_event_config: find out if the event is enabled.
214 * @write_event_config: set if the event is enabled.
215 * @read_event_value: read a value associated with the event. Meaning
Jonathan Cameron1d892712011-05-18 14:40:51 +0100216 * is event dependant. event_code specifies which event.
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100217 * @write_event_value: write the value associate with the event.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100218 * Meaning is event dependent.
Michael Hennerich43a43602011-06-27 13:07:09 +0100219 * @validate_trigger: function to validate the trigger when the
220 * current trigger gets changed.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100221 **/
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100222struct iio_info {
Jonathan Cameron847ec802009-08-18 18:06:19 +0100223 struct module *driver_module;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100224 struct attribute_group *event_attrs;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100225 const struct attribute_group *attrs;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100226
Jonathan Cameron1d892712011-05-18 14:40:51 +0100227 int (*read_raw)(struct iio_dev *indio_dev,
228 struct iio_chan_spec const *chan,
229 int *val,
230 int *val2,
231 long mask);
232
233 int (*write_raw)(struct iio_dev *indio_dev,
234 struct iio_chan_spec const *chan,
235 int val,
236 int val2,
237 long mask);
238
Michael Hennerich5c04af02011-06-27 13:07:10 +0100239 int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
240 struct iio_chan_spec const *chan,
241 long mask);
242
Jonathan Cameron1d892712011-05-18 14:40:51 +0100243 int (*read_event_config)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100244 u64 event_code);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100245
246 int (*write_event_config)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100247 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100248 int state);
249
250 int (*read_event_value)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100251 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100252 int *val);
253 int (*write_event_value)(struct iio_dev *indio_dev,
Jonathan Cameron330c6c52011-09-02 17:14:39 +0100254 u64 event_code,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100255 int val);
Michael Hennerich43a43602011-06-27 13:07:09 +0100256 int (*validate_trigger)(struct iio_dev *indio_dev,
257 struct iio_trigger *trig);
258
Jonathan Cameron847ec802009-08-18 18:06:19 +0100259};
260
Jonathan Cameron847ec802009-08-18 18:06:19 +0100261/**
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100262 * struct iio_dev - industrial I/O device
263 * @id: [INTERN] used to identify device internally
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100264 * @modes: [DRIVER] operating modes supported by device
265 * @currentmode: [DRIVER] current operating mode
266 * @dev: [DRIVER] device structure, should be assigned a parent
267 * and owner
Jonathan Cameron5aa96182011-08-30 12:41:06 +0100268 * @event_interface: [INTERN] event chrdevs associated with interrupt lines
Jonathan Cameron14555b12011-09-21 11:15:57 +0100269 * @buffer: [DRIVER] any buffer present
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100270 * @mlock: [INTERN] lock used to prevent simultaneous device state
271 * changes
272 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
Jonathan Cameron32b5eec2011-09-02 17:14:38 +0100273 * @masklength: [INTERN] the length of the mask established from
274 * channels
Jonathan Cameron14555b12011-09-21 11:15:57 +0100275 * @trig: [INTERN] current device trigger (buffer modes)
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100276 * @pollfunc: [DRIVER] function run on trigger being received
277 * @channels: [DRIVER] channel specification structure table
278 * @num_channels: [DRIVER] number of chanels specified in @channels.
279 * @channel_attr_list: [INTERN] keep track of automatically created channel
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100280 * attributes
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100281 * @chan_attr_group: [INTERN] group for all attrs in base directory
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100282 * @name: [DRIVER] name of the device.
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100283 * @info: [DRIVER] callbacks and constant info from driver
284 * @chrdev: [INTERN] associated character device
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100285 * @groups: [INTERN] attribute groups
286 * @groupcounter: [INTERN] index of next attribute group
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100287 **/
288struct iio_dev {
289 int id;
Jonathan Cameron4024bc72011-08-12 17:08:53 +0100290
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100291 int modes;
292 int currentmode;
293 struct device dev;
294
Jonathan Cameron5aa96182011-08-30 12:41:06 +0100295 struct iio_event_interface *event_interface;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100296
Jonathan Cameron14555b12011-09-21 11:15:57 +0100297 struct iio_buffer *buffer;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100298 struct mutex mlock;
299
Jonathan Cameron32b5eec2011-09-02 17:14:38 +0100300 unsigned long *available_scan_masks;
301 unsigned masklength;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100302 struct iio_trigger *trig;
303 struct iio_poll_func *pollfunc;
304
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100305 struct iio_chan_spec const *channels;
306 int num_channels;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100307
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100308 struct list_head channel_attr_list;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100309 struct attribute_group chan_attr_group;
Jonathan Cameron1a25e592011-08-30 12:41:12 +0100310 const char *name;
311 const struct iio_info *info;
312 struct cdev chrdev;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100313#define IIO_MAX_GROUPS 6
314 const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
315 int groupcounter;
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100316};
317
318/**
Jonathan Cameron847ec802009-08-18 18:06:19 +0100319 * iio_device_register() - register a device with the IIO subsystem
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100320 * @indio_dev: Device structure filled by the device driver
Jonathan Cameron847ec802009-08-18 18:06:19 +0100321 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100322int iio_device_register(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100323
324/**
325 * iio_device_unregister() - unregister a device from the IIO subsystem
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100326 * @indio_dev: Device structure representing the device.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100327 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100328void iio_device_unregister(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100329
330/**
Jonathan Cameron847ec802009-08-18 18:06:19 +0100331 * iio_push_event() - try to add event to the list for userspace reading
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100332 * @indio_dev: IIO device structure
Jonathan Cameron847ec802009-08-18 18:06:19 +0100333 * @ev_code: What event
Randy Dunlap4c572602009-10-04 19:34:02 -0700334 * @timestamp: When the event occurred
Jonathan Cameron847ec802009-08-18 18:06:19 +0100335 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100336int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100337
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100338extern struct bus_type iio_bus_type;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100339
340/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700341 * iio_put_device() - reference counted deallocation of struct device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100342 * @dev: the iio_device containing the device
343 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100344static inline void iio_put_device(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100345{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100346 if (indio_dev)
347 put_device(&indio_dev->dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100348};
349
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100350/* Can we make this smaller? */
351#define IIO_ALIGN L1_CACHE_BYTES
Jonathan Cameron847ec802009-08-18 18:06:19 +0100352/**
353 * iio_allocate_device() - allocate an iio_dev from a driver
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100354 * @sizeof_priv: Space to allocate for private structure.
Jonathan Cameron847ec802009-08-18 18:06:19 +0100355 **/
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100356struct iio_dev *iio_allocate_device(int sizeof_priv);
357
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100358static inline void *iio_priv(const struct iio_dev *indio_dev)
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100359{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100360 return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100361}
362
363static inline struct iio_dev *iio_priv_to_dev(void *priv)
364{
365 return (struct iio_dev *)((char *)priv -
366 ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
367}
Jonathan Cameron847ec802009-08-18 18:06:19 +0100368
369/**
370 * iio_free_device() - free an iio_dev from a driver
Randy Dunlap4c572602009-10-04 19:34:02 -0700371 * @dev: the iio_dev associated with the device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100372 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100373void iio_free_device(struct iio_dev *indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100374
375/**
Jonathan Cameron14555b12011-09-21 11:15:57 +0100376 * iio_buffer_enabled() - helper function to test if the buffer is enabled
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100377 * @indio_dev: IIO device info structure for device
Jonathan Cameron847ec802009-08-18 18:06:19 +0100378 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100379static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100380{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100381 return indio_dev->currentmode
Jonathan Cameronec3afa42011-09-21 11:15:54 +0100382 & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100383};
384
Jonathan Cameron847ec802009-08-18 18:06:19 +0100385#endif /* _INDUSTRIAL_IO_H_ */