diff options
Diffstat (limited to 'include/linux/iio/buffer.h')
-rw-r--r-- | include/linux/iio/buffer.h | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index 2bac0eb8948d..15607b45221a 100644 --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h | |||
@@ -11,6 +11,7 @@ | |||
11 | #define _IIO_BUFFER_GENERIC_H_ | 11 | #define _IIO_BUFFER_GENERIC_H_ |
12 | #include <linux/sysfs.h> | 12 | #include <linux/sysfs.h> |
13 | #include <linux/iio/iio.h> | 13 | #include <linux/iio/iio.h> |
14 | #include <linux/kref.h> | ||
14 | 15 | ||
15 | #ifdef CONFIG_IIO_BUFFER | 16 | #ifdef CONFIG_IIO_BUFFER |
16 | 17 | ||
@@ -26,6 +27,8 @@ struct iio_buffer; | |||
26 | * @set_bytes_per_datum:set number of bytes per datum | 27 | * @set_bytes_per_datum:set number of bytes per datum |
27 | * @get_length: get number of datums in buffer | 28 | * @get_length: get number of datums in buffer |
28 | * @set_length: set number of datums in buffer | 29 | * @set_length: set number of datums in buffer |
30 | * @release: called when the last reference to the buffer is dropped, | ||
31 | * should free all resources allocated by the buffer. | ||
29 | * | 32 | * |
30 | * The purpose of this structure is to make the buffer element | 33 | * The purpose of this structure is to make the buffer element |
31 | * modular as event for a given driver, different usecases may require | 34 | * modular as event for a given driver, different usecases may require |
@@ -36,7 +39,7 @@ struct iio_buffer; | |||
36 | * any of them not existing. | 39 | * any of them not existing. |
37 | **/ | 40 | **/ |
38 | struct iio_buffer_access_funcs { | 41 | struct iio_buffer_access_funcs { |
39 | int (*store_to)(struct iio_buffer *buffer, u8 *data); | 42 | int (*store_to)(struct iio_buffer *buffer, const void *data); |
40 | int (*read_first_n)(struct iio_buffer *buffer, | 43 | int (*read_first_n)(struct iio_buffer *buffer, |
41 | size_t n, | 44 | size_t n, |
42 | char __user *buf); | 45 | char __user *buf); |
@@ -47,6 +50,8 @@ struct iio_buffer_access_funcs { | |||
47 | int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); | 50 | int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); |
48 | int (*get_length)(struct iio_buffer *buffer); | 51 | int (*get_length)(struct iio_buffer *buffer); |
49 | int (*set_length)(struct iio_buffer *buffer, int length); | 52 | int (*set_length)(struct iio_buffer *buffer, int length); |
53 | |||
54 | void (*release)(struct iio_buffer *buffer); | ||
50 | }; | 55 | }; |
51 | 56 | ||
52 | /** | 57 | /** |
@@ -67,6 +72,7 @@ struct iio_buffer_access_funcs { | |||
67 | * @demux_list: [INTERN] list of operations required to demux the scan. | 72 | * @demux_list: [INTERN] list of operations required to demux the scan. |
68 | * @demux_bounce: [INTERN] buffer for doing gather from incoming scan. | 73 | * @demux_bounce: [INTERN] buffer for doing gather from incoming scan. |
69 | * @buffer_list: [INTERN] entry in the devices list of current buffers. | 74 | * @buffer_list: [INTERN] entry in the devices list of current buffers. |
75 | * @ref: [INTERN] reference count of the buffer. | ||
70 | */ | 76 | */ |
71 | struct iio_buffer { | 77 | struct iio_buffer { |
72 | int length; | 78 | int length; |
@@ -81,8 +87,9 @@ struct iio_buffer { | |||
81 | bool stufftoread; | 87 | bool stufftoread; |
82 | const struct attribute_group *attrs; | 88 | const struct attribute_group *attrs; |
83 | struct list_head demux_list; | 89 | struct list_head demux_list; |
84 | unsigned char *demux_bounce; | 90 | void *demux_bounce; |
85 | struct list_head buffer_list; | 91 | struct list_head buffer_list; |
92 | struct kref ref; | ||
86 | }; | 93 | }; |
87 | 94 | ||
88 | /** | 95 | /** |
@@ -120,7 +127,32 @@ int iio_scan_mask_set(struct iio_dev *indio_dev, | |||
120 | * @indio_dev: iio_dev structure for device. | 127 | * @indio_dev: iio_dev structure for device. |
121 | * @data: Full scan. | 128 | * @data: Full scan. |
122 | */ | 129 | */ |
123 | int iio_push_to_buffers(struct iio_dev *indio_dev, unsigned char *data); | 130 | int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data); |
131 | |||
132 | /* | ||
133 | * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers | ||
134 | * @indio_dev: iio_dev structure for device. | ||
135 | * @data: sample data | ||
136 | * @timestamp: timestamp for the sample data | ||
137 | * | ||
138 | * Pushes data to the IIO device's buffers. If timestamps are enabled for the | ||
139 | * device the function will store the supplied timestamp as the last element in | ||
140 | * the sample data buffer before pushing it to the device buffers. The sample | ||
141 | * data buffer needs to be large enough to hold the additional timestamp | ||
142 | * (usually the buffer should be indio->scan_bytes bytes large). | ||
143 | * | ||
144 | * Returns 0 on success, a negative error code otherwise. | ||
145 | */ | ||
146 | static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, | ||
147 | void *data, int64_t timestamp) | ||
148 | { | ||
149 | if (indio_dev->scan_timestamp) { | ||
150 | size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1; | ||
151 | ((int64_t *)data)[ts_offset] = timestamp; | ||
152 | } | ||
153 | |||
154 | return iio_push_to_buffers(indio_dev, data); | ||
155 | } | ||
124 | 156 | ||
125 | int iio_update_demux(struct iio_dev *indio_dev); | 157 | int iio_update_demux(struct iio_dev *indio_dev); |
126 | 158 | ||
@@ -174,11 +206,27 @@ ssize_t iio_buffer_show_enable(struct device *dev, | |||
174 | iio_buffer_show_enable, \ | 206 | iio_buffer_show_enable, \ |
175 | iio_buffer_store_enable) | 207 | iio_buffer_store_enable) |
176 | 208 | ||
177 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev); | ||
178 | |||
179 | bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, | 209 | bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, |
180 | const unsigned long *mask); | 210 | const unsigned long *mask); |
181 | 211 | ||
212 | struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer); | ||
213 | void iio_buffer_put(struct iio_buffer *buffer); | ||
214 | |||
215 | /** | ||
216 | * iio_device_attach_buffer - Attach a buffer to a IIO device | ||
217 | * @indio_dev: The device the buffer should be attached to | ||
218 | * @buffer: The buffer to attach to the device | ||
219 | * | ||
220 | * This function attaches a buffer to a IIO device. The buffer stays attached to | ||
221 | * the device until the device is freed. The function should only be called at | ||
222 | * most once per device. | ||
223 | */ | ||
224 | static inline void iio_device_attach_buffer(struct iio_dev *indio_dev, | ||
225 | struct iio_buffer *buffer) | ||
226 | { | ||
227 | indio_dev->buffer = iio_buffer_get(buffer); | ||
228 | } | ||
229 | |||
182 | #else /* CONFIG_IIO_BUFFER */ | 230 | #else /* CONFIG_IIO_BUFFER */ |
183 | 231 | ||
184 | static inline int iio_buffer_register(struct iio_dev *indio_dev, | 232 | static inline int iio_buffer_register(struct iio_dev *indio_dev, |
@@ -191,6 +239,9 @@ static inline int iio_buffer_register(struct iio_dev *indio_dev, | |||
191 | static inline void iio_buffer_unregister(struct iio_dev *indio_dev) | 239 | static inline void iio_buffer_unregister(struct iio_dev *indio_dev) |
192 | {} | 240 | {} |
193 | 241 | ||
242 | static inline void iio_buffer_get(struct iio_buffer *buffer) {} | ||
243 | static inline void iio_buffer_put(struct iio_buffer *buffer) {} | ||
244 | |||
194 | #endif /* CONFIG_IIO_BUFFER */ | 245 | #endif /* CONFIG_IIO_BUFFER */ |
195 | 246 | ||
196 | #endif /* _IIO_BUFFER_GENERIC_H_ */ | 247 | #endif /* _IIO_BUFFER_GENERIC_H_ */ |