blob: 671e9fd44b94d85ecbbe4c716bb0c96a087ebe76 [file] [log] [blame]
Jonathan Cameron7026ea42009-08-18 18:06:24 +01001/* The industrial I/O core - generic ring 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_RING_GENERIC_H_
11#define _IIO_RING_GENERIC_H_
12#include "iio.h"
13
Jonathan Cameron26620512010-07-11 16:39:14 +010014#ifdef CONFIG_IIO_RING_BUFFER
15
Jonathan Cameron7026ea42009-08-18 18:06:24 +010016struct iio_ring_buffer;
Jonathan Cameron7026ea42009-08-18 18:06:24 +010017
18/**
Jonathan Cameron7026ea42009-08-18 18:06:24 +010019 * struct iio_ring_access_funcs - access functions for ring buffers.
Jonathan Cameron7026ea42009-08-18 18:06:24 +010020 * @mark_in_use: reference counting, typically to prevent module removal
21 * @unmark_in_use: reduce reference count when no longer using ring buffer
22 * @store_to: actually store stuff to the ring buffer
23 * @read_last: get the last element stored
Jonathan Cameronb4281732011-04-15 18:55:55 +010024 * @read_first_n: try to get a specified number of elements (must exist)
Jonathan Cameron7026ea42009-08-18 18:06:24 +010025 * @mark_param_change: notify ring that some relevant parameter has changed
26 * Often this means the underlying storage may need to
27 * change.
28 * @request_update: if a parameter change has been marked, update underlying
29 * storage.
Jonathan Cameronc3e5d412010-09-04 17:54:45 +010030 * @get_bytes_per_datum:get current bytes per datum
31 * @set_bytes_per_datum:set number of bytes per datum
Jonathan Cameron7026ea42009-08-18 18:06:24 +010032 * @get_length: get number of datums in ring
33 * @set_length: set number of datums in ring
34 * @is_enabled: query if ring is currently being used
35 * @enable: enable the ring
36 *
37 * The purpose of this structure is to make the ring buffer element
38 * modular as event for a given driver, different usecases may require
Randy Dunlap4c572602009-10-04 19:34:02 -070039 * different ring designs (space efficiency vs speed for example).
Jonathan Cameron7026ea42009-08-18 18:06:24 +010040 *
41 * It is worth noting that a given ring implementation may only support a small
42 * proportion of these functions. The core code 'should' cope fine with any of
43 * them not existing.
44 **/
45struct iio_ring_access_funcs {
46 void (*mark_in_use)(struct iio_ring_buffer *ring);
47 void (*unmark_in_use)(struct iio_ring_buffer *ring);
48
49 int (*store_to)(struct iio_ring_buffer *ring, u8 *data, s64 timestamp);
50 int (*read_last)(struct iio_ring_buffer *ring, u8 *data);
Jonathan Cameronb4281732011-04-15 18:55:55 +010051 int (*read_first_n)(struct iio_ring_buffer *ring,
52 size_t n,
Jonathan Cameronb26a2182011-05-18 14:41:02 +010053 char __user *buf);
Jonathan Cameron7026ea42009-08-18 18:06:24 +010054
55 int (*mark_param_change)(struct iio_ring_buffer *ring);
56 int (*request_update)(struct iio_ring_buffer *ring);
57
Manuel Stahlffcab072010-08-31 11:32:50 +020058 int (*get_bytes_per_datum)(struct iio_ring_buffer *ring);
59 int (*set_bytes_per_datum)(struct iio_ring_buffer *ring, size_t bpd);
Jonathan Cameron7026ea42009-08-18 18:06:24 +010060 int (*get_length)(struct iio_ring_buffer *ring);
61 int (*set_length)(struct iio_ring_buffer *ring, int length);
62
63 int (*is_enabled)(struct iio_ring_buffer *ring);
64 int (*enable)(struct iio_ring_buffer *ring);
65};
66
67/**
68 * struct iio_ring_buffer - general ring buffer structure
Randy Dunlap4c572602009-10-04 19:34:02 -070069 * @dev: ring buffer device struct
Randy Dunlap4c572602009-10-04 19:34:02 -070070 * @indio_dev: industrial I/O device structure
71 * @owner: module that owns the ring buffer (for ref counting)
72 * @id: unique id number
Randy Dunlap4c572602009-10-04 19:34:02 -070073 * @length: [DEVICE] number of datums in ring
Jonathan Cameronc3e5d412010-09-04 17:54:45 +010074 * @bytes_per_datum: [DEVICE] size of individual datum including timestamp
Barry Songad577f82010-07-11 16:39:16 +010075 * @bpe: [DEVICE] size of individual channel value
Randy Dunlap4c572602009-10-04 19:34:02 -070076 * @loopcount: [INTERN] number of times the ring has looped
Manuel Stahlbf329632010-08-31 11:32:52 +020077 * @scan_el_attrs: [DRIVER] control of scan elements if that scan mode
78 * control method is used
79 * @scan_count: [INTERN] the number of elements in the current scan mode
80 * @scan_mask: [INTERN] bitmask used in masking scan mode elements
81 * @scan_timestamp: [INTERN] does the scan mode include a timestamp
Randy Dunlap4c572602009-10-04 19:34:02 -070082 * @access_handler: [INTERN] chrdev access handling
Randy Dunlap4c572602009-10-04 19:34:02 -070083 * @access: [DRIVER] ring access functions associated with the
Jonathan Cameron7026ea42009-08-18 18:06:24 +010084 * implementation.
Randy Dunlap4c572602009-10-04 19:34:02 -070085 * @preenable: [DRIVER] function to run prior to marking ring enabled
86 * @postenable: [DRIVER] function to run after marking ring enabled
87 * @predisable: [DRIVER] function to run prior to marking ring disabled
88 * @postdisable: [DRIVER] function to run after marking ring disabled
Jonathan Cameron7026ea42009-08-18 18:06:24 +010089 **/
90struct iio_ring_buffer {
91 struct device dev;
Jonathan Cameron7026ea42009-08-18 18:06:24 +010092 struct iio_dev *indio_dev;
93 struct module *owner;
94 int id;
Jonathan Cameron7026ea42009-08-18 18:06:24 +010095 int length;
Manuel Stahlffcab072010-08-31 11:32:50 +020096 int bytes_per_datum;
Barry Songad577f82010-07-11 16:39:16 +010097 int bpe;
Jonathan Cameron7026ea42009-08-18 18:06:24 +010098 int loopcount;
Manuel Stahlbf329632010-08-31 11:32:52 +020099 struct attribute_group *scan_el_attrs;
100 int scan_count;
101 u32 scan_mask;
102 bool scan_timestamp;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100103 struct iio_handler access_handler;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100104 struct iio_ring_access_funcs access;
105 int (*preenable)(struct iio_dev *);
106 int (*postenable)(struct iio_dev *);
107 int (*predisable)(struct iio_dev *);
108 int (*postdisable)(struct iio_dev *);
109
Jonathan Cameron1d892712011-05-18 14:40:51 +0100110 struct list_head scan_el_dev_attr_list;
111 struct list_head scan_el_en_attr_list;
Jonathan Camerona7348342011-05-18 14:40:55 +0100112
113 wait_queue_head_t pollq;
114 bool stufftoread;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100115};
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100116
117/**
118 * iio_ring_buffer_init() - Initialize the buffer structure
119 * @ring: buffer to be initialized
120 * @dev_info: the iio device the buffer is assocated with
121 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100122void iio_ring_buffer_init(struct iio_ring_buffer *ring,
123 struct iio_dev *dev_info);
124
125/**
Jonathan Cameron6f2dfb32010-03-02 13:35:35 +0000126 * __iio_update_ring_buffer() - update common elements of ring buffers
Randy Dunlap4c572602009-10-04 19:34:02 -0700127 * @ring: ring buffer that is the event source
128 * @bytes_per_datum: size of individual datum including timestamp
129 * @length: number of datums in ring
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100130 **/
Jonathan Cameron6f2dfb32010-03-02 13:35:35 +0000131static inline void __iio_update_ring_buffer(struct iio_ring_buffer *ring,
132 int bytes_per_datum, int length)
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100133{
Manuel Stahlffcab072010-08-31 11:32:50 +0200134 ring->bytes_per_datum = bytes_per_datum;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100135 ring->length = length;
136 ring->loopcount = 0;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100137}
138
139/**
140 * struct iio_scan_el - an individual element of a scan
141 * @dev_attr: control attribute (if directly controllable)
142 * @number: unique identifier of element (used for bit mask)
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100143 * @label: useful data for the scan el (often reg address)
144 * @set_state: for some devices datardy signals are generated
145 * for any enabled lines. This allows unwanted lines
146 * to be disabled and hence not get in the way.
147 **/
148struct iio_scan_el {
149 struct device_attribute dev_attr;
150 unsigned int number;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100151 unsigned int label;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100152 struct list_head l;
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100153
154 int (*set_state)(struct iio_scan_el *scanel,
155 struct iio_dev *dev_info,
156 bool state);
157};
158
159#define to_iio_scan_el(_dev_attr) \
160 container_of(_dev_attr, struct iio_scan_el, dev_attr);
161
162/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700163 * iio_scan_el_store() - sysfs scan element selection interface
164 * @dev: the target device
165 * @attr: the device attribute that is being processed
166 * @buf: input from userspace
167 * @len: length of input
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100168 *
169 * A generic function used to enable various scan elements. In some
170 * devices explicit read commands for each channel mean this is merely
171 * a software switch. In others this must actively disable the channel.
172 * Complexities occur when this interacts with data ready type triggers
173 * which may not reset unless every channel that is enabled is explicitly
174 * read.
175 **/
176ssize_t iio_scan_el_store(struct device *dev, struct device_attribute *attr,
177 const char *buf, size_t len);
178/**
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100179 * iio_scan_el_show() - sysfs interface to query whether a scan element
Randy Dunlap4c572602009-10-04 19:34:02 -0700180 * is enabled or not
181 * @dev: the target device
182 * @attr: the device attribute that is being processed
183 * @buf: output buffer
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100184 **/
185ssize_t iio_scan_el_show(struct device *dev, struct device_attribute *attr,
186 char *buf);
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100187
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100188/**
189 * iio_scan_el_ts_store() - sysfs interface to set whether a timestamp is included
190 * in the scan.
191 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100192ssize_t iio_scan_el_ts_store(struct device *dev, struct device_attribute *attr,
193 const char *buf, size_t len);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100194/**
195 * iio_scan_el_ts_show() - sysfs interface to query if a timestamp is included
196 * in the scan.
197 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100198ssize_t iio_scan_el_ts_show(struct device *dev, struct device_attribute *attr,
199 char *buf);
200/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700201 * IIO_SCAN_EL_C - declare and initialize a scan element with a control func
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100202 *
Randy Dunlap4c572602009-10-04 19:34:02 -0700203 * @_name: identifying name. Resulting struct is iio_scan_el_##_name,
Jonathan Cameron17227622010-05-04 14:43:02 +0100204 * sysfs element, _name##_en.
Randy Dunlap4c572602009-10-04 19:34:02 -0700205 * @_number: unique id number for the scan element.
Randy Dunlap4c572602009-10-04 19:34:02 -0700206 * length devices).
207 * @_label: indentification variable used by drivers. Often a reg address.
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100208 * @_controlfunc: function used to notify hardware of whether state changes
209 **/
Jonathan Cameron44f270d2010-09-21 14:40:56 +0100210#define __IIO_SCAN_EL_C(_name, _number, _label, _controlfunc) \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100211 struct iio_scan_el iio_scan_el_##_name = { \
Jonathan Cameron3215e312010-09-21 14:41:07 +0100212 .dev_attr = __ATTR(_name##_en, \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100213 S_IRUGO | S_IWUSR, \
214 iio_scan_el_show, \
215 iio_scan_el_store), \
216 .number = _number, \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100217 .label = _label, \
218 .set_state = _controlfunc, \
Jonathan Cameronfc89b382010-09-21 14:40:57 +0100219 }; \
220 static IIO_CONST_ATTR(_name##_index, #_number)
Jonathan Cameron17227622010-05-04 14:43:02 +0100221
Jonathan Cameron44f270d2010-09-21 14:40:56 +0100222#define IIO_SCAN_EL_C(_name, _number, _label, _controlfunc) \
223 __IIO_SCAN_EL_C(_name, _number, _label, _controlfunc)
Jonathan Cameron69584bd2010-07-11 16:39:15 +0100224
Jonathan Cameronfc89b382010-09-21 14:40:57 +0100225#define __IIO_SCAN_NAMED_EL_C(_name, _string, _number, _label, _cf) \
Jonathan Cameron17227622010-05-04 14:43:02 +0100226 struct iio_scan_el iio_scan_el_##_name = { \
Jonathan Cameron3215e312010-09-21 14:41:07 +0100227 .dev_attr = __ATTR(_string##_en, \
Jonathan Cameron17227622010-05-04 14:43:02 +0100228 S_IRUGO | S_IWUSR, \
229 iio_scan_el_show, \
230 iio_scan_el_store), \
231 .number = _number, \
Jonathan Cameron17227622010-05-04 14:43:02 +0100232 .label = _label, \
233 .set_state = _cf, \
Jonathan Cameronfc89b382010-09-21 14:40:57 +0100234 }; \
235 static struct iio_const_attr iio_const_attr_##_name##_index = { \
236 .string = #_number, \
237 .dev_attr = __ATTR(_string##_index, \
238 S_IRUGO, iio_read_const_attr, NULL) \
Jonathan Cameron17227622010-05-04 14:43:02 +0100239 }
Jonathan Cameronfc89b382010-09-21 14:40:57 +0100240
241
Jonathan Cameron44f270d2010-09-21 14:40:56 +0100242#define IIO_SCAN_NAMED_EL_C(_name, _string, _number, _label, _cf) \
243 __IIO_SCAN_NAMED_EL_C(_name, _string, _number, _label, _cf)
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100244/**
Randy Dunlap4c572602009-10-04 19:34:02 -0700245 * IIO_SCAN_EL_TIMESTAMP - declare a special scan element for timestamps
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100246 * @number: specify where in the scan order this is stored.
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100247 *
248 * Odd one out. Handled slightly differently from other scan elements.
249 **/
Jonathan Cameronf3fb0012010-05-04 14:42:58 +0100250#define IIO_SCAN_EL_TIMESTAMP(number) \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100251 struct iio_scan_el iio_scan_el_timestamp = { \
Jonathan Cameron09864522010-10-07 13:10:19 +0100252 .dev_attr = __ATTR(timestamp_en, \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100253 S_IRUGO | S_IWUSR, \
254 iio_scan_el_ts_show, \
255 iio_scan_el_ts_store), \
Jonathan Cameronfc89b382010-09-21 14:40:57 +0100256 }; \
257 static IIO_CONST_ATTR(timestamp_index, #number)
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100258
Jonathan Cameron6a36e612010-09-21 14:40:47 +0100259/**
260 * IIO_CONST_ATTR_SCAN_EL_TYPE - attr to specify the data format of a scan el
261 * @name: the scan el name (may be more general and cover a set of scan elements
262 * @_sign: either s or u for signed or unsigned
263 * @_bits: number of actual bits occuplied by the value
264 * @_storagebits: number of bits _bits is padded to when read out of buffer
265 **/
266#define IIO_CONST_ATTR_SCAN_EL_TYPE(_name, _sign, _bits, _storagebits) \
267 IIO_CONST_ATTR(_name##_type, #_sign#_bits"/"#_storagebits);
Michael Henneriche968d092010-10-07 14:24:33 +0200268
269/**
270 * IIO_CONST_ATTR_SCAN_EL_TYPE_WITH_SHIFT - attr to specify the data format of a scan el
271 * @name: the scan el name (may be more general and cover a set of scan elements
272 * @_sign: either s or u for signed or unsigned
273 * @_bits: number of actual bits occuplied by the value
274 * @_storagebits: number of bits _bits is padded to when read out of buffer
275 * @_shiftbits: number of bits _shiftbits the result must be shifted
276 **/
277#define IIO_CONST_ATTR_SCAN_EL_TYPE_WITH_SHIFT(_name, _sign, _bits, \
278 _storagebits, _shiftbits) \
279 IIO_CONST_ATTR(_name##_type, #_sign#_bits"/"#_storagebits \
280 ">>"#_shiftbits);
281
282#define IIO_SCAN_EL_TYPE_SIGNED 's'
283#define IIO_SCAN_EL_TYPE_UNSIGNED 'u'
284
Manuel Stahlbf329632010-08-31 11:32:52 +0200285/*
286 * These are mainly provided to allow for a change of implementation if a device
287 * has a large number of scan elements
288 */
289#define IIO_MAX_SCAN_LENGTH 31
290
291/* note 0 used as error indicator as it doesn't make sense. */
292static inline u32 iio_scan_mask_match(u32 *av_masks, u32 mask)
293{
294 while (*av_masks) {
295 if (!(~*av_masks & mask))
296 return *av_masks;
297 av_masks++;
298 }
299 return 0;
300}
301
302static inline int iio_scan_mask_query(struct iio_ring_buffer *ring, int bit)
303{
304 struct iio_dev *dev_info = ring->indio_dev;
305 u32 mask;
306
307 if (bit > IIO_MAX_SCAN_LENGTH)
308 return -EINVAL;
309
310 if (!ring->scan_mask)
311 return 0;
312
313 if (dev_info->available_scan_masks)
314 mask = iio_scan_mask_match(dev_info->available_scan_masks,
315 ring->scan_mask);
316 else
317 mask = ring->scan_mask;
318
319 if (!mask)
320 return -EINVAL;
321
322 return !!(mask & (1 << bit));
323};
324
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100325/**
326 * iio_scan_mask_set() - set particular bit in the scan mask
327 * @ring: the ring buffer whose scan mask we are interested in
328 * @bit: the bit to be set.
329 **/
Manuel Stahlbf329632010-08-31 11:32:52 +0200330static inline int iio_scan_mask_set(struct iio_ring_buffer *ring, int bit)
331{
332 struct iio_dev *dev_info = ring->indio_dev;
333 u32 mask;
334 u32 trialmask = ring->scan_mask | (1 << bit);
335
336 if (bit > IIO_MAX_SCAN_LENGTH)
337 return -EINVAL;
338 if (dev_info->available_scan_masks) {
339 mask = iio_scan_mask_match(dev_info->available_scan_masks,
340 trialmask);
341 if (!mask)
342 return -EINVAL;
343 }
344 ring->scan_mask = trialmask;
345 ring->scan_count++;
346
347 return 0;
348};
349
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100350/**
351 * iio_scan_mask_clear() - clear a particular element from the scan mask
352 * @ring: the ring buffer whose scan mask we are interested in
353 * @bit: the bit to clear
354 **/
Manuel Stahlbf329632010-08-31 11:32:52 +0200355static inline int iio_scan_mask_clear(struct iio_ring_buffer *ring, int bit)
356{
357 if (bit > IIO_MAX_SCAN_LENGTH)
358 return -EINVAL;
359 ring->scan_mask &= ~(1 << bit);
360 ring->scan_count--;
361 return 0;
362};
363
364/**
365 * iio_scan_mask_count_to_right() - how many scan elements occur before here
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100366 * @ring: the ring buffer whose scan mask we interested in
Manuel Stahlbf329632010-08-31 11:32:52 +0200367 * @bit: which number scan element is this
368 **/
369static inline int iio_scan_mask_count_to_right(struct iio_ring_buffer *ring,
370 int bit)
371{
372 int count = 0;
373 int mask = (1 << bit);
374 if (bit > IIO_MAX_SCAN_LENGTH)
375 return -EINVAL;
376 while (mask) {
377 mask >>= 1;
378 if (mask & ring->scan_mask)
379 count++;
380 }
381
382 return count;
383}
384
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100385/**
386 * iio_put_ring_buffer() - notify done with buffer
387 * @ring: the buffer we are done with.
388 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100389static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring)
390{
391 put_device(&ring->dev);
392};
393
394#define to_iio_ring_buffer(d) \
395 container_of(d, struct iio_ring_buffer, dev)
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100396
397/**
398 * iio_ring_buffer_register() - register the buffer with IIO core
399 * @ring: the buffer to be registered
400 * @id: the id of the buffer (typically 0)
401 **/
Jonathan Cameron758d9882010-05-04 14:43:08 +0100402int iio_ring_buffer_register(struct iio_ring_buffer *ring, int id);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100403
Jonathan Cameron1d892712011-05-18 14:40:51 +0100404/** iio_ring_buffer_register_ex() - register the buffer with IIO core
405 * @ring: the buffer to be registered
406 * @id: the id of the buffer (typically 0)
407 **/
408int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
409 const struct iio_chan_spec *channels,
410 int num_channels);
411
Jonathan Cameron3feb0792011-05-18 14:40:57 +0100412void iio_ring_access_release(struct device *dev);
413
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100414/**
415 * iio_ring_buffer_unregister() - unregister the buffer from IIO core
416 * @ring: the buffer to be unregistered
417 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100418void iio_ring_buffer_unregister(struct iio_ring_buffer *ring);
419
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100420/**
421 * iio_read_ring_length() - attr func to get number of datums in the buffer
422 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100423ssize_t iio_read_ring_length(struct device *dev,
424 struct device_attribute *attr,
425 char *buf);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100426/**
427 * iio_write_ring_length() - attr func to set number of datums in the buffer
428 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100429ssize_t iio_write_ring_length(struct device *dev,
430 struct device_attribute *attr,
431 const char *buf,
432 size_t len);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100433/**
434 * iio_read_ring_bytes_per_datum() - attr for number of bytes in whole datum
435 **/
Manuel Stahlffcab072010-08-31 11:32:50 +0200436ssize_t iio_read_ring_bytes_per_datum(struct device *dev,
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100437 struct device_attribute *attr,
438 char *buf);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100439/**
440 * iio_store_ring_enable() - attr to turn the buffer on
441 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100442ssize_t iio_store_ring_enable(struct device *dev,
443 struct device_attribute *attr,
444 const char *buf,
445 size_t len);
Jonathan Cameronc3e5d412010-09-04 17:54:45 +0100446/**
447 * iio_show_ring_enable() - attr to see if the buffer is on
448 **/
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100449ssize_t iio_show_ring_enable(struct device *dev,
450 struct device_attribute *attr,
451 char *buf);
452#define IIO_RING_LENGTH_ATTR DEVICE_ATTR(length, S_IRUGO | S_IWUSR, \
453 iio_read_ring_length, \
454 iio_write_ring_length)
Manuel Stahlffcab072010-08-31 11:32:50 +0200455#define IIO_RING_BYTES_PER_DATUM_ATTR DEVICE_ATTR(bytes_per_datum, S_IRUGO | S_IWUSR, \
456 iio_read_ring_bytes_per_datum, NULL)
457#define IIO_RING_ENABLE_ATTR DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, \
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100458 iio_show_ring_enable, \
459 iio_store_ring_enable)
Jonathan Cameron26620512010-07-11 16:39:14 +0100460#else /* CONFIG_IIO_RING_BUFFER */
461static inline int iio_ring_buffer_register(struct iio_ring_buffer *ring, int id)
462{
463 return 0;
464};
Jonathan Cameron1d892712011-05-18 14:40:51 +0100465
466static inline int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring,
467 int id,
468 struct iio_chan_spec *channels,
469 int num_channels)
470{
471 return 0;
472}
473
Jonathan Cameron26620512010-07-11 16:39:14 +0100474static inline void iio_ring_buffer_unregister(struct iio_ring_buffer *ring)
475{};
476
477#endif /* CONFIG_IIO_RING_BUFFER */
Jonathan Cameron7026ea42009-08-18 18:06:24 +0100478
479#endif /* _IIO_RING_GENERIC_H_ */