1
2
3
4
5
6
7
8
9
10#ifndef _IIO_RING_GENERIC_H_
11#define _IIO_RING_GENERIC_H_
12#include "iio.h"
13
14struct iio_handler;
15struct iio_ring_buffer;
16struct iio_dev;
17
18
19
20
21
22
23
24int iio_push_ring_event(struct iio_ring_buffer *ring_buf,
25 int event_code,
26 s64 timestamp);
27
28
29
30
31
32
33
34int iio_push_or_escallate_ring_event(struct iio_ring_buffer *ring_buf,
35 int event_code,
36 s64 timestamp);
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69struct iio_ring_access_funcs {
70 void (*mark_in_use)(struct iio_ring_buffer *ring);
71 void (*unmark_in_use)(struct iio_ring_buffer *ring);
72
73 int (*store_to)(struct iio_ring_buffer *ring, u8 *data, s64 timestamp);
74 int (*read_last)(struct iio_ring_buffer *ring, u8 *data);
75 int (*rip_lots)(struct iio_ring_buffer *ring,
76 size_t count,
77 u8 **data,
78 int *dead_offset);
79
80 int (*mark_param_change)(struct iio_ring_buffer *ring);
81 int (*request_update)(struct iio_ring_buffer *ring);
82
83 int (*get_bpd)(struct iio_ring_buffer *ring);
84 int (*set_bpd)(struct iio_ring_buffer *ring, size_t bpd);
85 int (*get_length)(struct iio_ring_buffer *ring);
86 int (*set_length)(struct iio_ring_buffer *ring, int length);
87
88 int (*is_enabled)(struct iio_ring_buffer *ring);
89 int (*enable)(struct iio_ring_buffer *ring);
90};
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112struct iio_ring_buffer {
113 struct device dev;
114 struct device access_dev;
115 struct iio_dev *indio_dev;
116 struct module *owner;
117 int id;
118 int access_id;
119 int length;
120 int bpd;
121 int loopcount;
122 struct iio_handler access_handler;
123 struct iio_event_interface ev_int;
124 struct iio_shared_ev_pointer shared_ev_pointer;
125 struct iio_ring_access_funcs access;
126 int (*preenable)(struct iio_dev *);
127 int (*postenable)(struct iio_dev *);
128 int (*predisable)(struct iio_dev *);
129 int (*postdisable)(struct iio_dev *);
130
131};
132void iio_ring_buffer_init(struct iio_ring_buffer *ring,
133 struct iio_dev *dev_info);
134
135
136
137
138static inline void __iio_init_ring_buffer(struct iio_ring_buffer *ring,
139 int bytes_per_datum, int length)
140{
141 ring->bpd = bytes_per_datum;
142 ring->length = length;
143 ring->loopcount = 0;
144 ring->shared_ev_pointer.ev_p = 0;
145 ring->shared_ev_pointer.lock =
146 __SPIN_LOCK_UNLOCKED(ring->shared_ev_pointer->loc);
147}
148
149
150
151
152
153
154
155
156
157
158
159struct iio_scan_el {
160 struct device_attribute dev_attr;
161 unsigned int number;
162 int bit_count;
163 unsigned int label;
164
165 int (*set_state)(struct iio_scan_el *scanel,
166 struct iio_dev *dev_info,
167 bool state);
168};
169
170#define to_iio_scan_el(_dev_attr) \
171 container_of(_dev_attr, struct iio_scan_el, dev_attr);
172
173
174
175
176
177
178
179
180
181
182
183ssize_t iio_scan_el_store(struct device *dev, struct device_attribute *attr,
184 const char *buf, size_t len);
185
186
187
188
189ssize_t iio_scan_el_show(struct device *dev, struct device_attribute *attr,
190 char *buf);
191
192
193
194
195
196
197
198
199
200#define IIO_SCAN_EL(_name, _number, _bits, _label) \
201 struct iio_scan_el iio_scan_el_##_name = { \
202 .dev_attr = __ATTR(scan_en_##_name, \
203 S_IRUGO | S_IWUSR, \
204 iio_scan_el_show, \
205 iio_scan_el_store), \
206 .mask = (1 << _number), \
207 .bit_count = _bits, \
208 .label = _label, \
209 }
210
211ssize_t iio_scan_el_ts_store(struct device *dev, struct device_attribute *attr,
212 const char *buf, size_t len);
213
214ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
215 char *buf);
216
217
218
219
220
221#define IIO_SCAN_EL_C(_name, _number, _bits, _label, _controlfunc) \
222 struct iio_scan_el iio_scan_el_##_name = { \
223 .dev_attr = __ATTR(scan_en_##_name, \
224 S_IRUGO | S_IWUSR, \
225 iio_scan_el_show, \
226 iio_scan_el_store), \
227 .number = _number, \
228 .bit_count = _bits, \
229 .label = _label, \
230 .set_state = _controlfunc, \
231 }
232
233
234
235
236
237#define IIO_SCAN_EL_TIMESTAMP \
238 struct iio_scan_el iio_scan_el_timestamp = { \
239 .dev_attr = __ATTR(scan_en_timestamp, \
240 S_IRUGO | S_IWUSR, \
241 iio_scan_el_ts_show, \
242 iio_scan_el_ts_store), \
243 }
244
245static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring)
246{
247 put_device(&ring->dev);
248};
249
250#define to_iio_ring_buffer(d) \
251 container_of(d, struct iio_ring_buffer, dev)
252#define access_dev_to_iio_ring_buffer(d) \
253 container_of(d, struct iio_ring_buffer, access_dev)
254int iio_ring_buffer_register(struct iio_ring_buffer *ring);
255void iio_ring_buffer_unregister(struct iio_ring_buffer *ring);
256
257ssize_t iio_read_ring_length(struct device *dev,
258 struct device_attribute *attr,
259 char *buf);
260ssize_t iio_write_ring_length(struct device *dev,
261 struct device_attribute *attr,
262 const char *buf,
263 size_t len);
264ssize_t iio_read_ring_bps(struct device *dev,
265 struct device_attribute *attr,
266 char *buf);
267ssize_t iio_store_ring_enable(struct device *dev,
268 struct device_attribute *attr,
269 const char *buf,
270 size_t len);
271ssize_t iio_show_ring_enable(struct device *dev,
272 struct device_attribute *attr,
273 char *buf);
274#define IIO_RING_LENGTH_ATTR DEVICE_ATTR(length, S_IRUGO | S_IWUSR, \
275 iio_read_ring_length, \
276 iio_write_ring_length)
277#define IIO_RING_BPS_ATTR DEVICE_ATTR(bps, S_IRUGO | S_IWUSR, \
278 iio_read_ring_bps, NULL)
279#define IIO_RING_ENABLE_ATTR DEVICE_ATTR(ring_enable, S_IRUGO | S_IWUSR, \
280 iio_show_ring_enable, \
281 iio_store_ring_enable)
282
283#endif
284