Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 2 | /* The industrial I/O core - generic buffer interfaces. |
Jonathan Cameron | 7026ea4 | 2009-08-18 18:06:24 +0100 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2008 Jonathan Cameron |
Jonathan Cameron | 7026ea4 | 2009-08-18 18:06:24 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Jonathan Cameron | 3811cd6 | 2011-09-21 11:15:56 +0100 | [diff] [blame] | 7 | #ifndef _IIO_BUFFER_GENERIC_H_ |
| 8 | #define _IIO_BUFFER_GENERIC_H_ |
Jonathan Cameron | 26d25ae | 2011-09-02 17:14:40 +0100 | [diff] [blame] | 9 | #include <linux/sysfs.h> |
Jonathan Cameron | 06458e2 | 2012-04-25 15:54:58 +0100 | [diff] [blame] | 10 | #include <linux/iio/iio.h> |
Jonathan Cameron | 2662051 | 2010-07-11 16:39:14 +0100 | [diff] [blame] | 11 | |
Jonathan Cameron | 14555b1 | 2011-09-21 11:15:57 +0100 | [diff] [blame] | 12 | struct iio_buffer; |
Jonathan Cameron | 7026ea4 | 2009-08-18 18:06:24 +0100 | [diff] [blame] | 13 | |
Jonathan Cameron | 9f46677 | 2017-01-02 19:28:26 +0000 | [diff] [blame] | 14 | void iio_buffer_set_attrs(struct iio_buffer *buffer, |
| 15 | const struct attribute **attrs); |
Jonathan Cameron | 7026ea4 | 2009-08-18 18:06:24 +0100 | [diff] [blame] | 16 | |
Lars-Peter Clausen | 5d65d92 | 2013-09-15 17:50:00 +0100 | [diff] [blame] | 17 | int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data); |
Jonathan Cameron | 5ada4ea | 2011-12-05 21:37:14 +0000 | [diff] [blame] | 18 | |
Jonathan Cameron | d4ad4f4 | 2017-01-02 19:28:29 +0000 | [diff] [blame] | 19 | /** |
Lars-Peter Clausen | d2c3d07 | 2013-09-19 13:59:00 +0100 | [diff] [blame] | 20 | * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers |
| 21 | * @indio_dev: iio_dev structure for device. |
| 22 | * @data: sample data |
| 23 | * @timestamp: timestamp for the sample data |
| 24 | * |
| 25 | * Pushes data to the IIO device's buffers. If timestamps are enabled for the |
| 26 | * device the function will store the supplied timestamp as the last element in |
| 27 | * the sample data buffer before pushing it to the device buffers. The sample |
| 28 | * data buffer needs to be large enough to hold the additional timestamp |
| 29 | * (usually the buffer should be indio->scan_bytes bytes large). |
| 30 | * |
| 31 | * Returns 0 on success, a negative error code otherwise. |
| 32 | */ |
| 33 | static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev, |
| 34 | void *data, int64_t timestamp) |
| 35 | { |
| 36 | if (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 | |
Lars-Peter Clausen | 8163663 | 2012-07-09 10:00:00 +0100 | [diff] [blame] | 44 | bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, |
Jonathan Cameron | 33dd94c | 2017-01-02 19:28:34 +0000 | [diff] [blame] | 45 | const unsigned long *mask); |
Lars-Peter Clausen | 9e69c93 | 2013-10-04 12:06:00 +0100 | [diff] [blame] | 46 | |
Jonathan Cameron | 2b827ad | 2017-01-02 19:28:32 +0000 | [diff] [blame] | 47 | void iio_device_attach_buffer(struct iio_dev *indio_dev, |
| 48 | struct iio_buffer *buffer); |
Lars-Peter Clausen | 9e69c93 | 2013-10-04 12:06:00 +0100 | [diff] [blame] | 49 | |
Jonathan Cameron | 3811cd6 | 2011-09-21 11:15:56 +0100 | [diff] [blame] | 50 | #endif /* _IIO_BUFFER_GENERIC_H_ */ |