Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
buffer.h
Go to the documentation of this file.
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 
17 struct iio_buffer;
18 
38 struct iio_buffer_access_funcs {
39  int (*store_to)(struct iio_buffer *buffer, u8 *data);
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 
70 struct 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 
90 void iio_buffer_init(struct iio_buffer *buffer);
91 
98 static 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 
105 int iio_scan_mask_query(struct iio_dev *indio_dev,
106  struct iio_buffer *buffer, int bit);
107 
114 int iio_scan_mask_set(struct iio_dev *indio_dev,
115  struct iio_buffer *buffer, int bit);
116 
122 int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data);
123 
124 int iio_update_demux(struct iio_dev *indio_dev);
125 
132 int iio_buffer_register(struct iio_dev *indio_dev,
133  const struct iio_chan_spec *channels,
134  int num_channels);
135 
140 void iio_buffer_unregister(struct iio_dev *indio_dev);
141 
146  struct device_attribute *attr,
147  char *buf);
152  struct device_attribute *attr,
153  const char *buf,
154  size_t len);
159  struct device_attribute *attr,
160  const char *buf,
161  size_t len);
166  struct device_attribute *attr,
167  char *buf);
168 #define IIO_BUFFER_LENGTH_ATTR DEVICE_ATTR(length, S_IRUGO | S_IWUSR, \
169  iio_buffer_read_length, \
170  iio_buffer_write_length)
171 
172 #define IIO_BUFFER_ENABLE_ATTR DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, \
173  iio_buffer_show_enable, \
174  iio_buffer_store_enable)
175 
176 int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
177 
178 bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
179  const unsigned long *mask);
180 
181 #else /* CONFIG_IIO_BUFFER */
182 
183 static inline int iio_buffer_register(struct iio_dev *indio_dev,
184  struct iio_chan_spec *channels,
185  int num_channels)
186 {
187  return 0;
188 }
189 
190 static inline void iio_buffer_unregister(struct iio_dev *indio_dev)
191 {}
192 
193 #endif /* CONFIG_IIO_BUFFER */
194 
195 #endif /* _IIO_BUFFER_GENERIC_H_ */