aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/iio
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/iio')
-rw-r--r--include/linux/iio/buffer.h191
-rw-r--r--include/linux/iio/consumer.h96
-rw-r--r--include/linux/iio/driver.h34
-rw-r--r--include/linux/iio/events.h105
-rw-r--r--include/linux/iio/iio.h492
-rw-r--r--include/linux/iio/kfifo_buf.h8
-rw-r--r--include/linux/iio/machine.h24
-rw-r--r--include/linux/iio/sysfs.h117
-rw-r--r--include/linux/iio/trigger.h119
-rw-r--r--include/linux/iio/trigger_consumer.h52
-rw-r--r--include/linux/iio/types.h55
11 files changed, 1293 insertions, 0 deletions
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
new file mode 100644
index 000000000000..fb0fe46fd659
--- /dev/null
+++ b/include/linux/iio/buffer.h
@@ -0,0 +1,191 @@
1/* The industrial I/O core - generic buffer interfaces.
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#ifndef _IIO_BUFFER_GENERIC_H_
11#define _IIO_BUFFER_GENERIC_H_
12#include <linux/sysfs.h>
13#include <linux/iio/iio.h>
14
15#ifdef CONFIG_IIO_BUFFER
16
17struct iio_buffer;
18
19/**
20 * struct iio_buffer_access_funcs - access functions for buffers.
21 * @store_to: actually store stuff to the buffer
22 * @read_first_n: try to get a specified number of bytes (must exist)
23 * @request_update: if a parameter change has been marked, update underlying
24 * storage.
25 * @get_bytes_per_datum:get current bytes per datum
26 * @set_bytes_per_datum:set number of bytes per datum
27 * @get_length: get number of datums in buffer
28 * @set_length: set number of datums in buffer
29 *
30 * The purpose of this structure is to make the buffer element
31 * modular as event for a given driver, different usecases may require
32 * different buffer designs (space efficiency vs speed for example).
33 *
34 * It is worth noting that a given buffer implementation may only support a
35 * small proportion of these functions. The core code 'should' cope fine with
36 * any of them not existing.
37 **/
38struct iio_buffer_access_funcs {
39 int (*store_to)(struct iio_buffer *buffer, u8 *data, s64 timestamp);
40 int (*read_first_n)(struct iio_buffer *buffer,
41 size_t n,
42 char __user *buf);
43
44 int (*request_update)(struct iio_buffer *buffer);
45
46 int (*get_bytes_per_datum)(struct iio_buffer *buffer);
47 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd);
48 int (*get_length)(struct iio_buffer *buffer);
49 int (*set_length)(struct iio_buffer *buffer, int length);
50};
51
52/**
53 * struct iio_buffer - general buffer structure
54 * @length: [DEVICE] number of datums in buffer
55 * @bytes_per_datum: [DEVICE] size of individual datum including timestamp
56 * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode
57 * control method is used
58 * @scan_mask: [INTERN] bitmask used in masking scan mode elements
59 * @scan_timestamp: [INTERN] does the scan mode include a timestamp
60 * @access: [DRIVER] buffer access functions associated with the
61 * implementation.
62 * @scan_el_dev_attr_list:[INTERN] list of scan element related attributes.
63 * @scan_el_group: [DRIVER] attribute group for those attributes not
64 * created from the iio_chan_info array.
65 * @pollq: [INTERN] wait queue to allow for polling on the buffer.
66 * @stufftoread: [INTERN] flag to indicate new data.
67 * @demux_list: [INTERN] list of operations required to demux the scan.
68 * @demux_bounce: [INTERN] buffer for doing gather from incoming scan.
69 **/
70struct iio_buffer {
71 int length;
72 int bytes_per_datum;
73 struct attribute_group *scan_el_attrs;
74 long *scan_mask;
75 bool scan_timestamp;
76 const struct iio_buffer_access_funcs *access;
77 struct list_head scan_el_dev_attr_list;
78 struct attribute_group scan_el_group;
79 wait_queue_head_t pollq;
80 bool stufftoread;
81 const struct attribute_group *attrs;
82 struct list_head demux_list;
83 unsigned char *demux_bounce;
84};
85
86/**
87 * iio_buffer_init() - Initialize the buffer structure
88 * @buffer: buffer to be initialized
89 **/
90void iio_buffer_init(struct iio_buffer *buffer);
91
92/**
93 * __iio_update_buffer() - update common elements of buffers
94 * @buffer: buffer that is the event source
95 * @bytes_per_datum: size of individual datum including timestamp
96 * @length: number of datums in buffer
97 **/
98static inline void __iio_update_buffer(struct iio_buffer *buffer,
99 int bytes_per_datum, int length)
100{
101 buffer->bytes_per_datum = bytes_per_datum;
102 buffer->length = length;
103}
104
105int iio_scan_mask_query(struct iio_dev *indio_dev,
106 struct iio_buffer *buffer, int bit);
107
108/**
109 * iio_scan_mask_set() - set particular bit in the scan mask
110 * @buffer: the buffer whose scan mask we are interested in
111 * @bit: the bit to be set.
112 **/
113int iio_scan_mask_set(struct iio_dev *indio_dev,
114 struct iio_buffer *buffer, int bit);
115
116/**
117 * iio_push_to_buffer() - push to a registered buffer.
118 * @buffer: IIO buffer structure for device
119 * @scan: Full scan.
120 * @timestamp:
121 */
122int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data,
123 s64 timestamp);
124
125int iio_update_demux(struct iio_dev *indio_dev);
126
127/**
128 * iio_buffer_register() - register the buffer with IIO core
129 * @indio_dev: device with the buffer to be registered
130 **/
131int iio_buffer_register(struct iio_dev *indio_dev,
132 const struct iio_chan_spec *channels,
133 int num_channels);
134
135/**
136 * iio_buffer_unregister() - unregister the buffer from IIO core
137 * @indio_dev: the device with the buffer to be unregistered
138 **/
139void iio_buffer_unregister(struct iio_dev *indio_dev);
140
141/**
142 * iio_buffer_read_length() - attr func to get number of datums in the buffer
143 **/
144ssize_t iio_buffer_read_length(struct device *dev,
145 struct device_attribute *attr,
146 char *buf);
147/**
148 * iio_buffer_write_length() - attr func to set number of datums in the buffer
149 **/
150ssize_t iio_buffer_write_length(struct device *dev,
151 struct device_attribute *attr,
152 const char *buf,
153 size_t len);
154/**
155 * iio_buffer_store_enable() - attr to turn the buffer on
156 **/
157ssize_t iio_buffer_store_enable(struct device *dev,
158 struct device_attribute *attr,
159 const char *buf,
160 size_t len);
161/**
162 * iio_buffer_show_enable() - attr to see if the buffer is on
163 **/
164ssize_t iio_buffer_show_enable(struct device *dev,
165 struct device_attribute *attr,
166 char *buf);
167#define IIO_BUFFER_LENGTH_ATTR DEVICE_ATTR(length, S_IRUGO | S_IWUSR, \
168 iio_buffer_read_length, \
169 iio_buffer_write_length)
170
171#define IIO_BUFFER_ENABLE_ATTR DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, \
172 iio_buffer_show_enable, \
173 iio_buffer_store_enable)
174
175int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
176
177#else /* CONFIG_IIO_BUFFER */
178
179static inline int iio_buffer_register(struct iio_dev *indio_dev,
180 struct iio_chan_spec *channels,
181 int num_channels)
182{
183 return 0;
184}
185
186static inline void iio_buffer_unregister(struct iio_dev *indio_dev)
187{};
188
189#endif /* CONFIG_IIO_BUFFER */
190
191#endif /* _IIO_BUFFER_GENERIC_H_ */
diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h
new file mode 100644
index 000000000000..1a15e560a5a1
--- /dev/null
+++ b/include/linux/iio/consumer.h
@@ -0,0 +1,96 @@
1/*
2 * Industrial I/O in kernel consumer interface
3 *
4 * Copyright (c) 2011 Jonathan Cameron
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#ifndef _IIO_INKERN_CONSUMER_H_
11#define _IIO_INKERN_CONSUMER_H
12#include <linux/iio/types.h>
13
14struct iio_dev;
15struct iio_chan_spec;
16
17/**
18 * struct iio_channel - everything needed for a consumer to use a channel
19 * @indio_dev: Device on which the channel exists.
20 * @channel: Full description of the channel.
21 */
22struct iio_channel {
23 struct iio_dev *indio_dev;
24 const struct iio_chan_spec *channel;
25};
26
27/**
28 * iio_channel_get() - get description of all that is needed to access channel.
29 * @name: Unique name of the device as provided in the iio_map
30 * with which the desired provider to consumer mapping
31 * was registered.
32 * @consumer_channel: Unique name to identify the channel on the consumer
33 * side. This typically describes the channels use within
34 * the consumer. E.g. 'battery_voltage'
35 */
36struct iio_channel *iio_st_channel_get(const char *name,
37 const char *consumer_channel);
38
39/**
40 * iio_st_channel_release() - release channels obtained via iio_st_channel_get
41 * @chan: The channel to be released.
42 */
43void iio_st_channel_release(struct iio_channel *chan);
44
45/**
46 * iio_st_channel_get_all() - get all channels associated with a client
47 * @name: name of consumer device.
48 *
49 * Returns an array of iio_channel structures terminated with one with
50 * null iio_dev pointer.
51 * This function is used by fairly generic consumers to get all the
52 * channels registered as having this consumer.
53 */
54struct iio_channel *iio_st_channel_get_all(const char *name);
55
56/**
57 * iio_st_channel_release_all() - reverse iio_st_get_all
58 * @chan: Array of channels to be released.
59 */
60void iio_st_channel_release_all(struct iio_channel *chan);
61
62/**
63 * iio_st_read_channel_raw() - read from a given channel
64 * @channel: The channel being queried.
65 * @val: Value read back.
66 *
67 * Note raw reads from iio channels are in adc counts and hence
68 * scale will need to be applied if standard units required.
69 */
70int iio_st_read_channel_raw(struct iio_channel *chan,
71 int *val);
72
73/**
74 * iio_st_get_channel_type() - get the type of a channel
75 * @channel: The channel being queried.
76 * @type: The type of the channel.
77 *
78 * returns the enum iio_chan_type of the channel
79 */
80int iio_st_get_channel_type(struct iio_channel *channel,
81 enum iio_chan_type *type);
82
83/**
84 * iio_st_read_channel_scale() - read the scale value for a channel
85 * @channel: The channel being queried.
86 * @val: First part of value read back.
87 * @val2: Second part of value read back.
88 *
89 * Note returns a description of what is in val and val2, such
90 * as IIO_VAL_INT_PLUS_MICRO telling us we have a value of val
91 * + val2/1e6
92 */
93int iio_st_read_channel_scale(struct iio_channel *chan, int *val,
94 int *val2);
95
96#endif
diff --git a/include/linux/iio/driver.h b/include/linux/iio/driver.h
new file mode 100644
index 000000000000..a4f8b2e05af5
--- /dev/null
+++ b/include/linux/iio/driver.h
@@ -0,0 +1,34 @@
1/*
2 * Industrial I/O in kernel access map interface.
3 *
4 * Copyright (c) 2011 Jonathan Cameron
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#ifndef _IIO_INKERN_H_
12#define _IIO_INKERN_H_
13
14struct iio_map;
15
16/**
17 * iio_map_array_register() - tell the core about inkernel consumers
18 * @indio_dev: provider device
19 * @map: array of mappings specifying association of channel with client
20 */
21int iio_map_array_register(struct iio_dev *indio_dev,
22 struct iio_map *map);
23
24/**
25 * iio_map_array_unregister() - tell the core to remove consumer mappings
26 * @indio_dev: provider device
27 * @map: array of mappings to remove. Note these must have same memory
28 * addresses as those originally added not just equal parameter
29 * values.
30 */
31int iio_map_array_unregister(struct iio_dev *indio_dev,
32 struct iio_map *map);
33
34#endif
diff --git a/include/linux/iio/events.h b/include/linux/iio/events.h
new file mode 100644
index 000000000000..b5acbf93c5da
--- /dev/null
+++ b/include/linux/iio/events.h
@@ -0,0 +1,105 @@
1/* The industrial I/O - event passing to userspace
2 *
3 * Copyright (c) 2008-2011 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9#ifndef _IIO_EVENTS_H_
10#define _IIO_EVENTS_H_
11
12#include <linux/ioctl.h>
13#include <linux/types.h>
14#include <linux/iio/types.h>
15
16/**
17 * struct iio_event_data - The actual event being pushed to userspace
18 * @id: event identifier
19 * @timestamp: best estimate of time of event occurrence (often from
20 * the interrupt handler)
21 */
22struct iio_event_data {
23 __u64 id;
24 __s64 timestamp;
25};
26
27#define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
28
29enum iio_event_type {
30 IIO_EV_TYPE_THRESH,
31 IIO_EV_TYPE_MAG,
32 IIO_EV_TYPE_ROC,
33 IIO_EV_TYPE_THRESH_ADAPTIVE,
34 IIO_EV_TYPE_MAG_ADAPTIVE,
35};
36
37enum iio_event_direction {
38 IIO_EV_DIR_EITHER,
39 IIO_EV_DIR_RISING,
40 IIO_EV_DIR_FALLING,
41};
42
43/**
44 * IIO_EVENT_CODE() - create event identifier
45 * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
46 * @diff: Whether the event is for an differential channel or not.
47 * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
48 * @direction: Direction of the event. One of enum iio_event_direction.
49 * @type: Type of the event. Should be one enum iio_event_type.
50 * @chan: Channel number for non-differential channels.
51 * @chan1: First channel number for differential channels.
52 * @chan2: Second channel number for differential channels.
53 */
54
55#define IIO_EVENT_CODE(chan_type, diff, modifier, direction, \
56 type, chan, chan1, chan2) \
57 (((u64)type << 56) | ((u64)diff << 55) | \
58 ((u64)direction << 48) | ((u64)modifier << 40) | \
59 ((u64)chan_type << 32) | (((u16)chan2) << 16) | ((u16)chan1) | \
60 ((u16)chan))
61
62
63#define IIO_EV_DIR_MAX 4
64#define IIO_EV_BIT(type, direction) \
65 (1 << (type*IIO_EV_DIR_MAX + direction))
66
67/**
68 * IIO_MOD_EVENT_CODE() - create event identifier for modified channels
69 * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
70 * @number: Channel number.
71 * @modifier: Modifier for the channel. Should be one of enum iio_modifier.
72 * @type: Type of the event. Should be one enum iio_event_type.
73 * @direction: Direction of the event. One of enum iio_event_direction.
74 */
75
76#define IIO_MOD_EVENT_CODE(chan_type, number, modifier, \
77 type, direction) \
78 IIO_EVENT_CODE(chan_type, 0, modifier, direction, type, number, 0, 0)
79
80/**
81 * IIO_UNMOD_EVENT_CODE() - create event identifier for unmodified channels
82 * @chan_type: Type of the channel. Should be one of enum iio_chan_type.
83 * @number: Channel number.
84 * @type: Type of the event. Should be one enum iio_event_type.
85 * @direction: Direction of the event. One of enum iio_event_direction.
86 */
87
88#define IIO_UNMOD_EVENT_CODE(chan_type, number, type, direction) \
89 IIO_EVENT_CODE(chan_type, 0, 0, direction, type, number, 0, 0)
90
91#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
92
93#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF)
94
95#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
96
97/* Event code number extraction depends on which type of event we have.
98 * Perhaps review this function in the future*/
99#define IIO_EVENT_CODE_EXTRACT_CHAN(mask) ((__s16)(mask & 0xFFFF))
100#define IIO_EVENT_CODE_EXTRACT_CHAN2(mask) ((__s16)(((mask) >> 16) & 0xFFFF))
101
102#define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
103#define IIO_EVENT_CODE_EXTRACT_DIFF(mask) (((mask) >> 55) & 0x1)
104
105#endif
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
new file mode 100644
index 000000000000..3a4f6a3ab80d
--- /dev/null
+++ b/include/linux/iio/iio.h
@@ -0,0 +1,492 @@
1
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 */
10#ifndef _INDUSTRIAL_IO_H_
11#define _INDUSTRIAL_IO_H_
12
13#include <linux/device.h>
14#include <linux/cdev.h>
15#include <linux/iio/types.h>
16/* IIO TODO LIST */
17/*
18 * Provide means of adjusting timer accuracy.
19 * Currently assumes nano seconds.
20 */
21
22enum iio_chan_info_enum {
23 IIO_CHAN_INFO_RAW = 0,
24 IIO_CHAN_INFO_PROCESSED,
25 IIO_CHAN_INFO_SCALE,
26 IIO_CHAN_INFO_OFFSET,
27 IIO_CHAN_INFO_CALIBSCALE,
28 IIO_CHAN_INFO_CALIBBIAS,
29 IIO_CHAN_INFO_PEAK,
30 IIO_CHAN_INFO_PEAK_SCALE,
31 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW,
32 IIO_CHAN_INFO_AVERAGE_RAW,
33 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY,
34 IIO_CHAN_INFO_SAMP_FREQ,
35 IIO_CHAN_INFO_FREQUENCY,
36 IIO_CHAN_INFO_PHASE,
37 IIO_CHAN_INFO_HARDWAREGAIN,
38};
39
40#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_RAW_SEPARATE_BIT \
44 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_RAW)
45#define IIO_CHAN_INFO_PROCESSED_SEPARATE_BIT \
46 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PROCESSED)
47#define IIO_CHAN_INFO_SCALE_SEPARATE_BIT \
48 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SCALE)
49#define IIO_CHAN_INFO_SCALE_SHARED_BIT \
50 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SCALE)
51#define IIO_CHAN_INFO_OFFSET_SEPARATE_BIT \
52 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_OFFSET)
53#define IIO_CHAN_INFO_OFFSET_SHARED_BIT \
54 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_OFFSET)
55#define IIO_CHAN_INFO_CALIBSCALE_SEPARATE_BIT \
56 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBSCALE)
57#define IIO_CHAN_INFO_CALIBSCALE_SHARED_BIT \
58 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBSCALE)
59#define IIO_CHAN_INFO_CALIBBIAS_SEPARATE_BIT \
60 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_CALIBBIAS)
61#define IIO_CHAN_INFO_CALIBBIAS_SHARED_BIT \
62 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_CALIBBIAS)
63#define IIO_CHAN_INFO_PEAK_SEPARATE_BIT \
64 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAK)
65#define IIO_CHAN_INFO_PEAK_SHARED_BIT \
66 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAK)
67#define IIO_CHAN_INFO_PEAKSCALE_SEPARATE_BIT \
68 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PEAKSCALE)
69#define IIO_CHAN_INFO_PEAKSCALE_SHARED_BIT \
70 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PEAKSCALE)
71#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SEPARATE_BIT \
72 IIO_CHAN_INFO_SEPARATE_BIT( \
73 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
74#define IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW_SHARED_BIT \
75 IIO_CHAN_INFO_SHARED_BIT( \
76 IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW)
77#define IIO_CHAN_INFO_AVERAGE_RAW_SEPARATE_BIT \
78 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
79#define IIO_CHAN_INFO_AVERAGE_RAW_SHARED_BIT \
80 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_AVERAGE_RAW)
81#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SHARED_BIT \
82 IIO_CHAN_INFO_SHARED_BIT( \
83 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY)
84#define IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY_SEPARATE_BIT \
85 IIO_CHAN_INFO_SEPARATE_BIT( \
86 IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY)
87#define IIO_CHAN_INFO_SAMP_FREQ_SEPARATE_BIT \
88 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_SAMP_FREQ)
89#define IIO_CHAN_INFO_SAMP_FREQ_SHARED_BIT \
90 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_SAMP_FREQ)
91#define IIO_CHAN_INFO_FREQUENCY_SEPARATE_BIT \
92 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_FREQUENCY)
93#define IIO_CHAN_INFO_FREQUENCY_SHARED_BIT \
94 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_FREQUENCY)
95#define IIO_CHAN_INFO_PHASE_SEPARATE_BIT \
96 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_PHASE)
97#define IIO_CHAN_INFO_PHASE_SHARED_BIT \
98 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_PHASE)
99#define IIO_CHAN_INFO_HARDWAREGAIN_SEPARATE_BIT \
100 IIO_CHAN_INFO_SEPARATE_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
101#define IIO_CHAN_INFO_HARDWAREGAIN_SHARED_BIT \
102 IIO_CHAN_INFO_SHARED_BIT(IIO_CHAN_INFO_HARDWAREGAIN)
103
104enum iio_endian {
105 IIO_CPU,
106 IIO_BE,
107 IIO_LE,
108};
109
110struct iio_chan_spec;
111struct iio_dev;
112
113/**
114 * struct iio_chan_spec_ext_info - Extended channel info attribute
115 * @name: Info attribute name
116 * @shared: Whether this attribute is shared between all channels.
117 * @read: Read callback for this info attribute, may be NULL.
118 * @write: Write callback for this info attribute, may be NULL.
119 * @private: Data private to the driver.
120 */
121struct iio_chan_spec_ext_info {
122 const char *name;
123 bool shared;
124 ssize_t (*read)(struct iio_dev *, uintptr_t private,
125 struct iio_chan_spec const *, char *buf);
126 ssize_t (*write)(struct iio_dev *, uintptr_t private,
127 struct iio_chan_spec const *, const char *buf,
128 size_t len);
129 uintptr_t private;
130};
131
132/**
133 * struct iio_chan_spec - specification of a single channel
134 * @type: What type of measurement is the channel making.
135 * @channel: What number or name do we wish to assign the channel.
136 * @channel2: If there is a second number for a differential
137 * channel then this is it. If modified is set then the
138 * value here specifies the modifier.
139 * @address: Driver specific identifier.
140 * @scan_index: Monotonic index to give ordering in scans when read
141 * from a buffer.
142 * @scan_type: Sign: 's' or 'u' to specify signed or unsigned
143 * realbits: Number of valid bits of data
144 * storage_bits: Realbits + padding
145 * shift: Shift right by this before masking out
146 * realbits.
147 * endianness: little or big endian
148 * @info_mask: What information is to be exported about this channel.
149 * This includes calibbias, scale etc.
150 * @event_mask: What events can this channel produce.
151 * @ext_info: Array of extended info attributes for this channel.
152 * The array is NULL terminated, the last element should
153 * have it's name field set to NULL.
154 * @extend_name: Allows labeling of channel attributes with an
155 * informative name. Note this has no effect codes etc,
156 * unlike modifiers.
157 * @datasheet_name: A name used in in kernel mapping of channels. It should
158 * correspond to the first name that the channel is referred
159 * to by in the datasheet (e.g. IND), or the nearest
160 * possible compound name (e.g. IND-INC).
161 * @modified: Does a modifier apply to this channel. What these are
162 * depends on the channel type. Modifier is set in
163 * channel2. Examples are IIO_MOD_X for axial sensors about
164 * the 'x' axis.
165 * @indexed: Specify the channel has a numerical index. If not,
166 * the value in channel will be suppressed for attribute
167 * but not for event codes. Typically set it to 0 when
168 * the index is false.
169 * @differential: Channel is differential.
170 */
171struct iio_chan_spec {
172 enum iio_chan_type type;
173 int channel;
174 int channel2;
175 unsigned long address;
176 int scan_index;
177 struct {
178 char sign;
179 u8 realbits;
180 u8 storagebits;
181 u8 shift;
182 enum iio_endian endianness;
183 } scan_type;
184 long info_mask;
185 long event_mask;
186 const struct iio_chan_spec_ext_info *ext_info;
187 const char *extend_name;
188 const char *datasheet_name;
189 unsigned modified:1;
190 unsigned indexed:1;
191 unsigned output:1;
192 unsigned differential:1;
193};
194
195#define IIO_ST(si, rb, sb, sh) \
196 { .sign = si, .realbits = rb, .storagebits = sb, .shift = sh }
197
198#define IIO_CHAN_SOFT_TIMESTAMP(_si) \
199 { .type = IIO_TIMESTAMP, .channel = -1, \
200 .scan_index = _si, .scan_type = IIO_ST('s', 64, 64, 0) }
201
202/**
203 * iio_get_time_ns() - utility function to get a time stamp for events etc
204 **/
205static inline s64 iio_get_time_ns(void)
206{
207 struct timespec ts;
208 /*
209 * calls getnstimeofday.
210 * If hrtimers then up to ns accurate, if not microsecond.
211 */
212 ktime_get_real_ts(&ts);
213
214 return timespec_to_ns(&ts);
215}
216
217/* Device operating modes */
218#define INDIO_DIRECT_MODE 0x01
219#define INDIO_BUFFER_TRIGGERED 0x02
220#define INDIO_BUFFER_HARDWARE 0x08
221
222#define INDIO_ALL_BUFFER_MODES \
223 (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE)
224
225struct iio_trigger; /* forward declaration */
226struct iio_dev;
227
228/**
229 * struct iio_info - constant information about device
230 * @driver_module: module structure used to ensure correct
231 * ownership of chrdevs etc
232 * @event_attrs: event control attributes
233 * @attrs: general purpose device attributes
234 * @read_raw: function to request a value from the device.
235 * mask specifies which value. Note 0 means a reading of
236 * the channel in question. Return value will specify the
237 * type of value returned by the device. val and val2 will
238 * contain the elements making up the returned value.
239 * @write_raw: function to write a value to the device.
240 * Parameters are the same as for read_raw.
241 * @write_raw_get_fmt: callback function to query the expected
242 * format/precision. If not set by the driver, write_raw
243 * returns IIO_VAL_INT_PLUS_MICRO.
244 * @read_event_config: find out if the event is enabled.
245 * @write_event_config: set if the event is enabled.
246 * @read_event_value: read a value associated with the event. Meaning
247 * is event dependant. event_code specifies which event.
248 * @write_event_value: write the value associated with the event.
249 * Meaning is event dependent.
250 * @validate_trigger: function to validate the trigger when the
251 * current trigger gets changed.
252 **/
253struct iio_info {
254 struct module *driver_module;
255 struct attribute_group *event_attrs;
256 const struct attribute_group *attrs;
257
258 int (*read_raw)(struct iio_dev *indio_dev,
259 struct iio_chan_spec const *chan,
260 int *val,
261 int *val2,
262 long mask);
263
264 int (*write_raw)(struct iio_dev *indio_dev,
265 struct iio_chan_spec const *chan,
266 int val,
267 int val2,
268 long mask);
269
270 int (*write_raw_get_fmt)(struct iio_dev *indio_dev,
271 struct iio_chan_spec const *chan,
272 long mask);
273
274 int (*read_event_config)(struct iio_dev *indio_dev,
275 u64 event_code);
276
277 int (*write_event_config)(struct iio_dev *indio_dev,
278 u64 event_code,
279 int state);
280
281 int (*read_event_value)(struct iio_dev *indio_dev,
282 u64 event_code,
283 int *val);
284 int (*write_event_value)(struct iio_dev *indio_dev,
285 u64 event_code,
286 int val);
287 int (*validate_trigger)(struct iio_dev *indio_dev,
288 struct iio_trigger *trig);
289 int (*update_scan_mode)(struct iio_dev *indio_dev,
290 const unsigned long *scan_mask);
291 int (*debugfs_reg_access)(struct iio_dev *indio_dev,
292 unsigned reg, unsigned writeval,
293 unsigned *readval);
294};
295
296/**
297 * struct iio_buffer_setup_ops - buffer setup related callbacks
298 * @preenable: [DRIVER] function to run prior to marking buffer enabled
299 * @postenable: [DRIVER] function to run after marking buffer enabled
300 * @predisable: [DRIVER] function to run prior to marking buffer
301 * disabled
302 * @postdisable: [DRIVER] function to run after marking buffer disabled
303 */
304struct iio_buffer_setup_ops {
305 int (*preenable)(struct iio_dev *);
306 int (*postenable)(struct iio_dev *);
307 int (*predisable)(struct iio_dev *);
308 int (*postdisable)(struct iio_dev *);
309};
310
311/**
312 * struct iio_dev - industrial I/O device
313 * @id: [INTERN] used to identify device internally
314 * @modes: [DRIVER] operating modes supported by device
315 * @currentmode: [DRIVER] current operating mode
316 * @dev: [DRIVER] device structure, should be assigned a parent
317 * and owner
318 * @event_interface: [INTERN] event chrdevs associated with interrupt lines
319 * @buffer: [DRIVER] any buffer present
320 * @scan_bytes: [INTERN] num bytes captured to be fed to buffer demux
321 * @mlock: [INTERN] lock used to prevent simultaneous device state
322 * changes
323 * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
324 * @masklength: [INTERN] the length of the mask established from
325 * channels
326 * @active_scan_mask: [INTERN] union of all scan masks requested by buffers
327 * @scan_timestamp: [INTERN] set if any buffers have requested timestamp
328 * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
329 * @trig: [INTERN] current device trigger (buffer modes)
330 * @pollfunc: [DRIVER] function run on trigger being received
331 * @channels: [DRIVER] channel specification structure table
332 * @num_channels: [DRIVER] number of chanels specified in @channels.
333 * @channel_attr_list: [INTERN] keep track of automatically created channel
334 * attributes
335 * @chan_attr_group: [INTERN] group for all attrs in base directory
336 * @name: [DRIVER] name of the device.
337 * @info: [DRIVER] callbacks and constant info from driver
338 * @info_exist_lock: [INTERN] lock to prevent use during removal
339 * @setup_ops: [DRIVER] callbacks to call before and after buffer
340 * enable/disable
341 * @chrdev: [INTERN] associated character device
342 * @groups: [INTERN] attribute groups
343 * @groupcounter: [INTERN] index of next attribute group
344 * @flags: [INTERN] file ops related flags including busy flag.
345 * @debugfs_dentry: [INTERN] device specific debugfs dentry.
346 * @cached_reg_addr: [INTERN] cached register address for debugfs reads.
347 */
348struct iio_dev {
349 int id;
350
351 int modes;
352 int currentmode;
353 struct device dev;
354
355 struct iio_event_interface *event_interface;
356
357 struct iio_buffer *buffer;
358 int scan_bytes;
359 struct mutex mlock;
360
361 const unsigned long *available_scan_masks;
362 unsigned masklength;
363 const unsigned long *active_scan_mask;
364 bool scan_timestamp;
365 unsigned scan_index_timestamp;
366 struct iio_trigger *trig;
367 struct iio_poll_func *pollfunc;
368
369 struct iio_chan_spec const *channels;
370 int num_channels;
371
372 struct list_head channel_attr_list;
373 struct attribute_group chan_attr_group;
374 const char *name;
375 const struct iio_info *info;
376 struct mutex info_exist_lock;
377 const struct iio_buffer_setup_ops *setup_ops;
378 struct cdev chrdev;
379#define IIO_MAX_GROUPS 6
380 const struct attribute_group *groups[IIO_MAX_GROUPS + 1];
381 int groupcounter;
382
383 unsigned long flags;
384#if defined(CONFIG_DEBUG_FS)
385 struct dentry *debugfs_dentry;
386 unsigned cached_reg_addr;
387#endif
388};
389
390/**
391 * iio_find_channel_from_si() - get channel from its scan index
392 * @indio_dev: device
393 * @si: scan index to match
394 */
395const struct iio_chan_spec
396*iio_find_channel_from_si(struct iio_dev *indio_dev, int si);
397
398/**
399 * iio_device_register() - register a device with the IIO subsystem
400 * @indio_dev: Device structure filled by the device driver
401 **/
402int iio_device_register(struct iio_dev *indio_dev);
403
404/**
405 * iio_device_unregister() - unregister a device from the IIO subsystem
406 * @indio_dev: Device structure representing the device.
407 **/
408void iio_device_unregister(struct iio_dev *indio_dev);
409
410/**
411 * iio_push_event() - try to add event to the list for userspace reading
412 * @indio_dev: IIO device structure
413 * @ev_code: What event
414 * @timestamp: When the event occurred
415 **/
416int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp);
417
418extern struct bus_type iio_bus_type;
419
420/**
421 * iio_device_put() - reference counted deallocation of struct device
422 * @dev: the iio_device containing the device
423 **/
424static inline void iio_device_put(struct iio_dev *indio_dev)
425{
426 if (indio_dev)
427 put_device(&indio_dev->dev);
428};
429
430/**
431 * dev_to_iio_dev() - Get IIO device struct from a device struct
432 * @dev: The device embedded in the IIO device
433 *
434 * Note: The device must be a IIO device, otherwise the result is undefined.
435 */
436static inline struct iio_dev *dev_to_iio_dev(struct device *dev)
437{
438 return container_of(dev, struct iio_dev, dev);
439}
440
441/* Can we make this smaller? */
442#define IIO_ALIGN L1_CACHE_BYTES
443/**
444 * iio_device_alloc() - allocate an iio_dev from a driver
445 * @sizeof_priv: Space to allocate for private structure.
446 **/
447struct iio_dev *iio_device_alloc(int sizeof_priv);
448
449static inline void *iio_priv(const struct iio_dev *indio_dev)
450{
451 return (char *)indio_dev + ALIGN(sizeof(struct iio_dev), IIO_ALIGN);
452}
453
454static inline struct iio_dev *iio_priv_to_dev(void *priv)
455{
456 return (struct iio_dev *)((char *)priv -
457 ALIGN(sizeof(struct iio_dev), IIO_ALIGN));
458}
459
460/**
461 * iio_device_free() - free an iio_dev from a driver
462 * @dev: the iio_dev associated with the device
463 **/
464void iio_device_free(struct iio_dev *indio_dev);
465
466/**
467 * iio_buffer_enabled() - helper function to test if the buffer is enabled
468 * @indio_dev: IIO device info structure for device
469 **/
470static inline bool iio_buffer_enabled(struct iio_dev *indio_dev)
471{
472 return indio_dev->currentmode
473 & (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE);
474};
475
476/**
477 * iio_get_debugfs_dentry() - helper function to get the debugfs_dentry
478 * @indio_dev: IIO device info structure for device
479 **/
480#if defined(CONFIG_DEBUG_FS)
481static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
482{
483 return indio_dev->debugfs_dentry;
484};
485#else
486static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
487{
488 return NULL;
489};
490#endif
491
492#endif /* _INDUSTRIAL_IO_H_ */
diff --git a/include/linux/iio/kfifo_buf.h b/include/linux/iio/kfifo_buf.h
new file mode 100644
index 000000000000..014d5a13b32b
--- /dev/null
+++ b/include/linux/iio/kfifo_buf.h
@@ -0,0 +1,8 @@
1
2#include <linux/kfifo.h>
3#include <linux/iio/iio.h>
4#include <linux/iio/buffer.h>
5
6struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev);
7void iio_kfifo_free(struct iio_buffer *r);
8
diff --git a/include/linux/iio/machine.h b/include/linux/iio/machine.h
new file mode 100644
index 000000000000..0b1f19bfdc44
--- /dev/null
+++ b/include/linux/iio/machine.h
@@ -0,0 +1,24 @@
1/*
2 * Industrial I/O in kernel access map definitions for board files.
3 *
4 * Copyright (c) 2011 Jonathan Cameron
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11/**
12 * struct iio_map - description of link between consumer and device channels
13 * @adc_channel_label: Label used to identify the channel on the provider.
14 * This is matched against the datasheet_name element
15 * of struct iio_chan_spec.
16 * @consumer_dev_name: Name to uniquely identify the consumer device.
17 * @consumer_channel: Unique name used to idenitify the channel on the
18 * consumer side.
19 */
20struct iio_map {
21 const char *adc_channel_label;
22 const char *consumer_dev_name;
23 const char *consumer_channel;
24};
diff --git a/include/linux/iio/sysfs.h b/include/linux/iio/sysfs.h
new file mode 100644
index 000000000000..bfedb73b850e
--- /dev/null
+++ b/include/linux/iio/sysfs.h
@@ -0,0 +1,117 @@
1/* The industrial I/O core
2 *
3 *Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * General attributes
10 */
11
12#ifndef _INDUSTRIAL_IO_SYSFS_H_
13#define _INDUSTRIAL_IO_SYSFS_H_
14
15struct iio_chan_spec;
16
17/**
18 * struct iio_dev_attr - iio specific device attribute
19 * @dev_attr: underlying device attribute
20 * @address: associated register address
21 * @l: list head for maintaining list of dynamically created attrs.
22 */
23struct iio_dev_attr {
24 struct device_attribute dev_attr;
25 u64 address;
26 struct list_head l;
27 struct iio_chan_spec const *c;
28};
29
30#define to_iio_dev_attr(_dev_attr) \
31 container_of(_dev_attr, struct iio_dev_attr, dev_attr)
32
33ssize_t iio_read_const_attr(struct device *dev,
34 struct device_attribute *attr,
35 char *len);
36
37/**
38 * struct iio_const_attr - constant device specific attribute
39 * often used for things like available modes
40 * @string: attribute string
41 * @dev_attr: underlying device attribute
42 */
43struct iio_const_attr {
44 const char *string;
45 struct device_attribute dev_attr;
46};
47
48#define to_iio_const_attr(_dev_attr) \
49 container_of(_dev_attr, struct iio_const_attr, dev_attr)
50
51/* Some attributes will be hard coded (device dependent) and not require an
52 address, in these cases pass a negative */
53#define IIO_ATTR(_name, _mode, _show, _store, _addr) \
54 { .dev_attr = __ATTR(_name, _mode, _show, _store), \
55 .address = _addr }
56
57#define IIO_DEVICE_ATTR(_name, _mode, _show, _store, _addr) \
58 struct iio_dev_attr iio_dev_attr_##_name \
59 = IIO_ATTR(_name, _mode, _show, _store, _addr)
60
61#define IIO_DEVICE_ATTR_NAMED(_vname, _name, _mode, _show, _store, _addr) \
62 struct iio_dev_attr iio_dev_attr_##_vname \
63 = IIO_ATTR(_name, _mode, _show, _store, _addr)
64
65#define IIO_CONST_ATTR(_name, _string) \
66 struct iio_const_attr iio_const_attr_##_name \
67 = { .string = _string, \
68 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
69
70#define IIO_CONST_ATTR_NAMED(_vname, _name, _string) \
71 struct iio_const_attr iio_const_attr_##_vname \
72 = { .string = _string, \
73 .dev_attr = __ATTR(_name, S_IRUGO, iio_read_const_attr, NULL)}
74
75/* Generic attributes of onetype or another */
76/**
77 * IIO_DEV_ATTR_RESET: resets the device
78 **/
79#define IIO_DEV_ATTR_RESET(_store) \
80 IIO_DEVICE_ATTR(reset, S_IWUSR, NULL, _store, 0)
81
82/**
83 * IIO_DEV_ATTR_SAMP_FREQ - sets any internal clock frequency
84 * @_mode: sysfs file mode/permissions
85 * @_show: output method for the attribute
86 * @_store: input method for the attribute
87 **/
88#define IIO_DEV_ATTR_SAMP_FREQ(_mode, _show, _store) \
89 IIO_DEVICE_ATTR(sampling_frequency, _mode, _show, _store, 0)
90
91/**
92 * IIO_DEV_ATTR_SAMP_FREQ_AVAIL - list available sampling frequencies
93 * @_show: output method for the attribute
94 *
95 * May be mode dependent on some devices
96 **/
97#define IIO_DEV_ATTR_SAMP_FREQ_AVAIL(_show) \
98 IIO_DEVICE_ATTR(sampling_frequency_available, S_IRUGO, _show, NULL, 0)
99/**
100 * IIO_CONST_ATTR_AVAIL_SAMP_FREQ - list available sampling frequencies
101 * @_string: frequency string for the attribute
102 *
103 * Constant version
104 **/
105#define IIO_CONST_ATTR_SAMP_FREQ_AVAIL(_string) \
106 IIO_CONST_ATTR(sampling_frequency_available, _string)
107
108#define IIO_DEV_ATTR_TEMP_RAW(_show) \
109 IIO_DEVICE_ATTR(in_temp_raw, S_IRUGO, _show, NULL, 0)
110
111#define IIO_CONST_ATTR_TEMP_OFFSET(_string) \
112 IIO_CONST_ATTR(in_temp_offset, _string)
113
114#define IIO_CONST_ATTR_TEMP_SCALE(_string) \
115 IIO_CONST_ATTR(in_temp_scale, _string)
116
117#endif /* _INDUSTRIAL_IO_SYSFS_H_ */
diff --git a/include/linux/iio/trigger.h b/include/linux/iio/trigger.h
new file mode 100644
index 000000000000..a9819940a84c
--- /dev/null
+++ b/include/linux/iio/trigger.h
@@ -0,0 +1,119 @@
1/* The industrial I/O core, trigger handling functions
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9#include <linux/irq.h>
10#include <linux/module.h>
11
12#ifndef _IIO_TRIGGER_H_
13#define _IIO_TRIGGER_H_
14
15struct iio_subirq {
16 bool enabled;
17};
18
19/**
20 * struct iio_trigger_ops - operations structure for an iio_trigger.
21 * @owner: used to monitor usage count of the trigger.
22 * @set_trigger_state: switch on/off the trigger on demand
23 * @try_reenable: function to reenable the trigger when the
24 * use count is zero (may be NULL)
25 * @validate_device: function to validate the device when the
26 * current trigger gets changed.
27 *
28 * This is typically static const within a driver and shared by
29 * instances of a given device.
30 **/
31struct iio_trigger_ops {
32 struct module *owner;
33 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
34 int (*try_reenable)(struct iio_trigger *trig);
35 int (*validate_device)(struct iio_trigger *trig,
36 struct iio_dev *indio_dev);
37};
38
39
40/**
41 * struct iio_trigger - industrial I/O trigger device
42 *
43 * @id: [INTERN] unique id number
44 * @name: [DRIVER] unique name
45 * @dev: [DRIVER] associated device (if relevant)
46 * @private_data: [DRIVER] device specific data
47 * @list: [INTERN] used in maintenance of global trigger list
48 * @alloc_list: [DRIVER] used for driver specific trigger list
49 * @use_count: use count for the trigger
50 * @subirq_chip: [INTERN] associate 'virtual' irq chip.
51 * @subirq_base: [INTERN] base number for irqs provided by trigger.
52 * @subirqs: [INTERN] information about the 'child' irqs.
53 * @pool: [INTERN] bitmap of irqs currently in use.
54 * @pool_lock: [INTERN] protection of the irq pool.
55 **/
56struct iio_trigger {
57 const struct iio_trigger_ops *ops;
58 int id;
59 const char *name;
60 struct device dev;
61
62 void *private_data;
63 struct list_head list;
64 struct list_head alloc_list;
65 int use_count;
66
67 struct irq_chip subirq_chip;
68 int subirq_base;
69
70 struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
71 unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
72 struct mutex pool_lock;
73};
74
75
76static inline struct iio_trigger *to_iio_trigger(struct device *d)
77{
78 return container_of(d, struct iio_trigger, dev);
79};
80
81static inline void iio_trigger_put(struct iio_trigger *trig)
82{
83 module_put(trig->ops->owner);
84 put_device(&trig->dev);
85};
86
87static inline void iio_trigger_get(struct iio_trigger *trig)
88{
89 get_device(&trig->dev);
90 __module_get(trig->ops->owner);
91};
92
93/**
94 * iio_trigger_register() - register a trigger with the IIO core
95 * @trig_info: trigger to be registered
96 **/
97int iio_trigger_register(struct iio_trigger *trig_info);
98
99/**
100 * iio_trigger_unregister() - unregister a trigger from the core
101 * @trig_info: trigger to be unregistered
102 **/
103void iio_trigger_unregister(struct iio_trigger *trig_info);
104
105/**
106 * iio_trigger_poll() - called on a trigger occurring
107 * @trig: trigger which occurred
108 *
109 * Typically called in relevant hardware interrupt handler.
110 **/
111void iio_trigger_poll(struct iio_trigger *trig, s64 time);
112void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
113
114irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
115
116__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
117void iio_trigger_free(struct iio_trigger *trig);
118
119#endif /* _IIO_TRIGGER_H_ */
diff --git a/include/linux/iio/trigger_consumer.h b/include/linux/iio/trigger_consumer.h
new file mode 100644
index 000000000000..60d64b356945
--- /dev/null
+++ b/include/linux/iio/trigger_consumer.h
@@ -0,0 +1,52 @@
1/* The industrial I/O core, trigger consumer functions
2 *
3 * Copyright (c) 2008-2011 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10/**
11 * struct iio_poll_func - poll function pair
12 *
13 * @indio_dev: data specific to device (passed into poll func)
14 * @h: the function that is actually run on trigger
15 * @thread: threaded interrupt part
16 * @type: the type of interrupt (basically if oneshot)
17 * @name: name used to identify the trigger consumer.
18 * @irq: the corresponding irq as allocated from the
19 * trigger pool
20 * @timestamp: some devices need a timestamp grabbed as soon
21 * as possible after the trigger - hence handler
22 * passes it via here.
23 **/
24struct iio_poll_func {
25 struct iio_dev *indio_dev;
26 irqreturn_t (*h)(int irq, void *p);
27 irqreturn_t (*thread)(int irq, void *p);
28 int type;
29 char *name;
30 int irq;
31 s64 timestamp;
32};
33
34
35struct iio_poll_func
36*iio_alloc_pollfunc(irqreturn_t (*h)(int irq, void *p),
37 irqreturn_t (*thread)(int irq, void *p),
38 int type,
39 struct iio_dev *indio_dev,
40 const char *fmt,
41 ...);
42void iio_dealloc_pollfunc(struct iio_poll_func *pf);
43irqreturn_t iio_pollfunc_store_time(int irq, void *p);
44
45void iio_trigger_notify_done(struct iio_trigger *trig);
46
47/*
48 * Two functions for common case where all that happens is a pollfunc
49 * is attached and detached from a trigger
50 */
51int iio_triggered_buffer_postenable(struct iio_dev *indio_dev);
52int iio_triggered_buffer_predisable(struct iio_dev *indio_dev);
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
new file mode 100644
index 000000000000..1b073b1cc7c2
--- /dev/null
+++ b/include/linux/iio/types.h
@@ -0,0 +1,55 @@
1/* industrial I/O data types needed both in and out of kernel
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#ifndef _IIO_TYPES_H_
11#define _IIO_TYPES_H_
12
13enum iio_chan_type {
14 /* real channel types */
15 IIO_VOLTAGE,
16 IIO_CURRENT,
17 IIO_POWER,
18 IIO_ACCEL,
19 IIO_ANGL_VEL,
20 IIO_MAGN,
21 IIO_LIGHT,
22 IIO_INTENSITY,
23 IIO_PROXIMITY,
24 IIO_TEMP,
25 IIO_INCLI,
26 IIO_ROT,
27 IIO_ANGL,
28 IIO_TIMESTAMP,
29 IIO_CAPACITANCE,
30 IIO_ALTVOLTAGE,
31};
32
33enum iio_modifier {
34 IIO_NO_MOD,
35 IIO_MOD_X,
36 IIO_MOD_Y,
37 IIO_MOD_Z,
38 IIO_MOD_X_AND_Y,
39 IIO_MOD_X_AND_Z,
40 IIO_MOD_Y_AND_Z,
41 IIO_MOD_X_AND_Y_AND_Z,
42 IIO_MOD_X_OR_Y,
43 IIO_MOD_X_OR_Z,
44 IIO_MOD_Y_OR_Z,
45 IIO_MOD_X_OR_Y_OR_Z,
46 IIO_MOD_LIGHT_BOTH,
47 IIO_MOD_LIGHT_IR,
48};
49
50#define IIO_VAL_INT 1
51#define IIO_VAL_INT_PLUS_MICRO 2
52#define IIO_VAL_INT_PLUS_NANO 3
53#define IIO_VAL_INT_PLUS_MICRO_DB 4
54
55#endif /* _IIO_TYPES_H_ */