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

iio: triggered-buffer: add {devm_}iio_triggered_buffer_setup_ext variants

This change adds a parameter to the {devm_}iio_triggered_buffer_setup()
functions to assign the extra sysfs buffer attributes that are typically
assigned via iio_buffer_set_attrs().

The functions also get renamed to iio_triggered_buffer_setup_ext() &
devm_iio_triggered_buffer_setup_ext().
For backwards compatibility the old {devm_}iio_triggered_buffer_setup()
functions are now macros wrap the new (renamed) functions with NULL for the
buffer attrs.

The aim is to remove iio_buffer_set_attrs(), so in the
iio_triggered_buffer_setup_ext() function the attributes are assigned
directly to 'buffer->attrs'.

When adding multiple IIO buffers per IIO device, it can be pretty
cumbersome to first allocate a set of buffers, then to dig them out of IIO
to assign extra attributes (with iio_buffer_set_attrs()).

Naturally, the best way would be to provide them at allocation time, which
is what this change does.

At this moment, buffers allocated with {devm_}iio_triggered_buffer_setup()
are the only ones in mainline IIO to call iio_buffer_set_attrs().

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20200929125949.69934-4-alexandru.ardelean@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
5164c788 789976ac

+35 -19
+19 -12
drivers/iio/buffer/industrialio-triggered-buffer.c
··· 9 9 #include <linux/module.h> 10 10 #include <linux/iio/iio.h> 11 11 #include <linux/iio/buffer.h> 12 + #include <linux/iio/buffer_impl.h> 12 13 #include <linux/iio/kfifo_buf.h> 13 14 #include <linux/iio/triggered_buffer.h> 14 15 #include <linux/iio/trigger_consumer.h> 15 16 16 17 /** 17 - * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc 18 + * iio_triggered_buffer_setup_ext() - Setup triggered buffer and pollfunc 18 19 * @indio_dev: IIO device structure 19 20 * @h: Function which will be used as pollfunc top half 20 21 * @thread: Function which will be used as pollfunc bottom half 21 22 * @setup_ops: Buffer setup functions to use for this device. 22 23 * If NULL the default setup functions for triggered 23 24 * buffers will be used. 25 + * @buffer_attrs: Extra sysfs buffer attributes for this IIO buffer 24 26 * 25 27 * This function combines some common tasks which will normally be performed 26 28 * when setting up a triggered buffer. It will allocate the buffer and the ··· 35 33 * To free the resources allocated by this function call 36 34 * iio_triggered_buffer_cleanup(). 37 35 */ 38 - int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 36 + int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev, 39 37 irqreturn_t (*h)(int irq, void *p), 40 38 irqreturn_t (*thread)(int irq, void *p), 41 - const struct iio_buffer_setup_ops *setup_ops) 39 + const struct iio_buffer_setup_ops *setup_ops, 40 + const struct attribute **buffer_attrs) 42 41 { 43 42 struct iio_buffer *buffer; 44 43 int ret; ··· 70 67 /* Flag that polled ring buffering is possible */ 71 68 indio_dev->modes |= INDIO_BUFFER_TRIGGERED; 72 69 70 + buffer->attrs = buffer_attrs; 71 + 73 72 return 0; 74 73 75 74 error_kfifo_free: ··· 79 74 error_ret: 80 75 return ret; 81 76 } 82 - EXPORT_SYMBOL(iio_triggered_buffer_setup); 77 + EXPORT_SYMBOL(iio_triggered_buffer_setup_ext); 83 78 84 79 /** 85 - * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup() 80 + * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup_ext() 86 81 * @indio_dev: IIO device structure 87 82 */ 88 83 void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) ··· 97 92 iio_triggered_buffer_cleanup(*(struct iio_dev **)res); 98 93 } 99 94 100 - int devm_iio_triggered_buffer_setup(struct device *dev, 101 - struct iio_dev *indio_dev, 102 - irqreturn_t (*h)(int irq, void *p), 103 - irqreturn_t (*thread)(int irq, void *p), 104 - const struct iio_buffer_setup_ops *ops) 95 + int devm_iio_triggered_buffer_setup_ext(struct device *dev, 96 + struct iio_dev *indio_dev, 97 + irqreturn_t (*h)(int irq, void *p), 98 + irqreturn_t (*thread)(int irq, void *p), 99 + const struct iio_buffer_setup_ops *ops, 100 + const struct attribute **buffer_attrs) 105 101 { 106 102 struct iio_dev **ptr; 107 103 int ret; ··· 114 108 115 109 *ptr = indio_dev; 116 110 117 - ret = iio_triggered_buffer_setup(indio_dev, h, thread, ops); 111 + ret = iio_triggered_buffer_setup_ext(indio_dev, h, thread, ops, 112 + buffer_attrs); 118 113 if (!ret) 119 114 devres_add(dev, ptr); 120 115 else ··· 123 116 124 117 return ret; 125 118 } 126 - EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup); 119 + EXPORT_SYMBOL_GPL(devm_iio_triggered_buffer_setup_ext); 127 120 128 121 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 129 122 MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
+16 -7
include/linux/iio/triggered_buffer.h
··· 4 4 5 5 #include <linux/interrupt.h> 6 6 7 + struct attribute; 7 8 struct iio_dev; 8 9 struct iio_buffer_setup_ops; 9 10 10 - int iio_triggered_buffer_setup(struct iio_dev *indio_dev, 11 + int iio_triggered_buffer_setup_ext(struct iio_dev *indio_dev, 11 12 irqreturn_t (*h)(int irq, void *p), 12 13 irqreturn_t (*thread)(int irq, void *p), 13 - const struct iio_buffer_setup_ops *setup_ops); 14 + const struct iio_buffer_setup_ops *setup_ops, 15 + const struct attribute **buffer_attrs); 14 16 void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev); 15 17 16 - int devm_iio_triggered_buffer_setup(struct device *dev, 17 - struct iio_dev *indio_dev, 18 - irqreturn_t (*h)(int irq, void *p), 19 - irqreturn_t (*thread)(int irq, void *p), 20 - const struct iio_buffer_setup_ops *ops); 18 + #define iio_triggered_buffer_setup(indio_dev, h, thread, setup_ops) \ 19 + iio_triggered_buffer_setup_ext((indio_dev), (h), (thread), (setup_ops), NULL) 20 + 21 + int devm_iio_triggered_buffer_setup_ext(struct device *dev, 22 + struct iio_dev *indio_dev, 23 + irqreturn_t (*h)(int irq, void *p), 24 + irqreturn_t (*thread)(int irq, void *p), 25 + const struct iio_buffer_setup_ops *ops, 26 + const struct attribute **buffer_attrs); 27 + 28 + #define devm_iio_triggered_buffer_setup(dev, indio_dev, h, thread, setup_ops) \ 29 + devm_iio_triggered_buffer_setup_ext((dev), (indio_dev), (h), (thread), (setup_ops), NULL) 21 30 22 31 #endif