at master 2.6 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* The industrial I/O core - generic buffer interfaces. 3 * 4 * Copyright (c) 2008 Jonathan Cameron 5 */ 6 7#ifndef _IIO_BUFFER_GENERIC_H_ 8#define _IIO_BUFFER_GENERIC_H_ 9#include <linux/sysfs.h> 10#include <linux/iio/iio.h> 11 12struct iio_buffer; 13 14enum iio_buffer_direction { 15 IIO_BUFFER_DIRECTION_IN, 16 IIO_BUFFER_DIRECTION_OUT, 17}; 18 19int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data); 20 21int iio_pop_from_buffer(struct iio_buffer *buffer, void *data); 22 23/** 24 * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers 25 * @indio_dev: iio_dev structure for device. 26 * @data: sample data 27 * @timestamp: timestamp for the sample data 28 * 29 * DEPRECATED: Use iio_push_to_buffers_with_ts() instead. 30 * 31 * Returns 0 on success, a negative error code otherwise. 32 */ 33static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, 34 void *data, int64_t timestamp) 35{ 36 if (ACCESS_PRIVATE(indio_dev, scan_timestamp)) { 37 size_t ts_offset = indio_dev->scan_bytes / sizeof(int64_t) - 1; 38 ((int64_t *)data)[ts_offset] = timestamp; 39 } 40 41 return iio_push_to_buffers(indio_dev, data); 42} 43 44/** 45 * iio_push_to_buffers_with_ts() - push data and timestamp to buffers 46 * @indio_dev: iio_dev structure for device. 47 * @data: Pointer to sample data buffer. 48 * @data_total_len: The size of @data in bytes. 49 * @timestamp: Timestamp for the sample data. 50 * 51 * Pushes data to the IIO device's buffers. If timestamps are enabled for the 52 * device the function will store the supplied timestamp as the last element in 53 * the sample data buffer before pushing it to the device buffers. The sample 54 * data buffer needs to be large enough to hold the additional timestamp 55 * (usually the buffer should be at least indio->scan_bytes bytes large). 56 * 57 * Context: Any context. 58 * Return: 0 on success, a negative error code otherwise. 59 */ 60static inline int iio_push_to_buffers_with_ts(struct iio_dev *indio_dev, 61 void *data, size_t data_total_len, 62 s64 timestamp) 63{ 64 if (unlikely(data_total_len < indio_dev->scan_bytes)) { 65 dev_err(&indio_dev->dev, "Undersized storage pushed to buffer\n"); 66 return -ENOSPC; 67 } 68 69 return iio_push_to_buffers_with_timestamp(indio_dev, data, timestamp); 70} 71 72int iio_push_to_buffers_with_ts_unaligned(struct iio_dev *indio_dev, 73 const void *data, size_t data_sz, 74 int64_t timestamp); 75 76bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, 77 const unsigned long *mask); 78 79int iio_device_attach_buffer(struct iio_dev *indio_dev, 80 struct iio_buffer *buffer); 81 82#endif /* _IIO_BUFFER_GENERIC_H_ */