summaryrefslogtreecommitdiff
path: root/drivers/iio/industrialio-buffer.c
diff options
context:
space:
mode:
authorMatt Fornero <matt.fornero@mathworks.com>2017-12-06 22:43:30 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-01-08 18:03:41 +0300
commit350f6c75f6933d5d58548d68f9336543c56b4a02 (patch)
tree056a75fe99ad2653d510bc2892574f5e6e1d3c70 /drivers/iio/industrialio-buffer.c
parent80e3f0103e126060721d96074ec6c1d252af23b9 (diff)
downloadlinux-350f6c75f6933d5d58548d68f9336543c56b4a02.tar.xz
iio: buffer: Expose data available
Add a sysfs attribute that exposes buffer data available to userspace. This attribute can be checked at runtime to determine the overall buffer fill level (across all allocated buffers). Signed-off-by: Matt Fornero <matt.fornero@mathworks.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/iio/industrialio-buffer.c')
-rw-r--r--drivers/iio/industrialio-buffer.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index d2b465140a6b..eda2a0f1658f 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1198,6 +1198,18 @@ out:
return ret ? ret : len;
}
+static ssize_t iio_dma_show_data_available(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct iio_dev *indio_dev = dev_to_iio_dev(dev);
+ size_t bytes;
+
+ bytes = iio_buffer_data_available(indio_dev->buffer);
+
+ return sprintf(buf, "%zu\n", bytes);
+}
+
static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length,
iio_buffer_write_length);
static struct device_attribute dev_attr_length_ro = __ATTR(length,
@@ -1208,11 +1220,14 @@ static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR,
iio_buffer_show_watermark, iio_buffer_store_watermark);
static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark,
S_IRUGO, iio_buffer_show_watermark, NULL);
+static DEVICE_ATTR(data_available, S_IRUGO,
+ iio_dma_show_data_available, NULL);
static struct attribute *iio_buffer_attrs[] = {
&dev_attr_length.attr,
&dev_attr_enable.attr,
&dev_attr_watermark.attr,
+ &dev_attr_data_available.attr,
};
int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)