Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: dummy: iio_simple_dummy_buffer: use triggered buffer core calls

The iio_simple_dummy_configure_buffer() function is essentially a
re-implementation of the iio_triggered_buffer_setup() function.

This change makes use of the iio_triggered_buffer_setup() function. The
reason is so that we don't have to modify the iio_device_attach_buffer()
function in this driver as well.

One minor drawback is that the pollfunc name may not be 100% identical
with the one in the original code, but since it's an example, it should be
a big problem.

This change does a minor re-arranging of the included iio headers, as a
minor tidy-up.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Link: https://lore.kernel.org/r/20210215104043.91251-19-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
738f6ba1 0224af85

+6 -62
+6 -62
drivers/iio/dummy/iio_simple_dummy_buffer.c
··· 16 16 #include <linux/bitmap.h> 17 17 18 18 #include <linux/iio/iio.h> 19 - #include <linux/iio/trigger_consumer.h> 20 19 #include <linux/iio/buffer.h> 21 - #include <linux/iio/kfifo_buf.h> 20 + #include <linux/iio/trigger_consumer.h> 21 + #include <linux/iio/triggered_buffer.h> 22 22 23 23 #include "iio_simple_dummy.h" 24 24 ··· 103 103 104 104 int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev) 105 105 { 106 - int ret; 107 - struct iio_buffer *buffer; 108 - 109 - /* Allocate a buffer to use - here a kfifo */ 110 - buffer = iio_kfifo_allocate(); 111 - if (!buffer) { 112 - ret = -ENOMEM; 113 - goto error_ret; 114 - } 115 - 116 - iio_device_attach_buffer(indio_dev, buffer); 117 - 118 - /* 119 - * Tell the core what device type specific functions should 120 - * be run on either side of buffer capture enable / disable. 121 - */ 122 - indio_dev->setup_ops = &iio_simple_dummy_buffer_setup_ops; 123 - 124 - /* 125 - * Configure a polling function. 126 - * When a trigger event with this polling function connected 127 - * occurs, this function is run. Typically this grabs data 128 - * from the device. 129 - * 130 - * NULL for the bottom half. This is normally implemented only if we 131 - * either want to ping a capture now pin (no sleeping) or grab 132 - * a timestamp as close as possible to a data ready trigger firing. 133 - * 134 - * IRQF_ONESHOT ensures irqs are masked such that only one instance 135 - * of the handler can run at a time. 136 - * 137 - * "iio_simple_dummy_consumer%d" formatting string for the irq 'name' 138 - * as seen under /proc/interrupts. Remaining parameters as per printk. 139 - */ 140 - indio_dev->pollfunc = iio_alloc_pollfunc(NULL, 141 - &iio_simple_dummy_trigger_h, 142 - IRQF_ONESHOT, 143 - indio_dev, 144 - "iio_simple_dummy_consumer%d", 145 - indio_dev->id); 146 - 147 - if (!indio_dev->pollfunc) { 148 - ret = -ENOMEM; 149 - goto error_free_buffer; 150 - } 151 - 152 - /* 153 - * Notify the core that this device is capable of buffered capture 154 - * driven by a trigger. 155 - */ 156 - indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 157 - 158 - return 0; 159 - 160 - error_free_buffer: 161 - iio_kfifo_free(indio_dev->buffer); 162 - error_ret: 163 - return ret; 106 + return iio_triggered_buffer_setup(indio_dev, NULL, 107 + iio_simple_dummy_trigger_h, 108 + &iio_simple_dummy_buffer_setup_ops); 164 109 } 165 110 166 111 /** ··· 114 169 */ 115 170 void iio_simple_dummy_unconfigure_buffer(struct iio_dev *indio_dev) 116 171 { 117 - iio_dealloc_pollfunc(indio_dev->pollfunc); 118 - iio_kfifo_free(indio_dev->buffer); 172 + iio_triggered_buffer_cleanup(indio_dev); 119 173 }