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

iio: buffer-dma,adi-axi-adc: introduce devm_iio_dmaengine_buffer_setup()

This change does a conversion of the devm_iio_dmaengine_buffer_alloc() to
devm_iio_dmaengine_buffer_setup(). This will allocate an IIO DMA buffer and
attach it to the IIO device, similar to devm_iio_triggered_buffer_setup()
(though the underlying code is different, the final logic is the same).

Since the only user of the devm_iio_dmaengine_buffer_alloc() was the
adi-axi-adc driver, this change does the replacement in a single go in the
driver.

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

authored by

Alexandru Ardelean and committed by
Jonathan Cameron
a02c09e4 99f6e821

+38 -15
+1
Documentation/driver-api/driver-model/devres.rst
··· 285 285 IIO 286 286 devm_iio_device_alloc() 287 287 devm_iio_device_register() 288 + devm_iio_dmaengine_buffer_setup() 288 289 devm_iio_kfifo_buffer_setup() 289 290 devm_iio_triggered_buffer_setup() 290 291 devm_iio_trigger_alloc()
+2 -10
drivers/iio/adc/adi-axi-adc.c
··· 104 104 static int adi_axi_adc_config_dma_buffer(struct device *dev, 105 105 struct iio_dev *indio_dev) 106 106 { 107 - struct iio_buffer *buffer; 108 107 const char *dma_name; 109 108 110 109 if (!device_property_present(dev, "dmas")) ··· 112 113 if (device_property_read_string(dev, "dma-names", &dma_name)) 113 114 dma_name = "rx"; 114 115 115 - buffer = devm_iio_dmaengine_buffer_alloc(indio_dev->dev.parent, 116 - dma_name); 117 - if (IS_ERR(buffer)) 118 - return PTR_ERR(buffer); 119 - 120 - indio_dev->modes |= INDIO_BUFFER_HARDWARE; 121 - iio_device_attach_buffer(indio_dev, buffer); 122 - 123 - return 0; 116 + return devm_iio_dmaengine_buffer_setup(indio_dev->dev.parent, 117 + indio_dev, dma_name); 124 118 } 125 119 126 120 static int adi_axi_adc_read_raw(struct iio_dev *indio_dev,
+31 -2
drivers/iio/buffer/industrialio-buffer-dmaengine.c
··· 244 244 * 245 245 * The buffer will be automatically de-allocated once the device gets destroyed. 246 246 */ 247 - struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, 247 + static struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, 248 248 const char *channel) 249 249 { 250 250 struct iio_buffer **bufferp, *buffer; ··· 265 265 266 266 return buffer; 267 267 } 268 - EXPORT_SYMBOL_GPL(devm_iio_dmaengine_buffer_alloc); 268 + 269 + /** 270 + * devm_iio_dmaengine_buffer_setup() - Setup a DMA buffer for an IIO device 271 + * @dev: Parent device for the buffer 272 + * @indio_dev: IIO device to which to attach this buffer. 273 + * @channel: DMA channel name, typically "rx". 274 + * 275 + * This allocates a new IIO buffer with devm_iio_dmaengine_buffer_alloc() 276 + * and attaches it to an IIO device with iio_device_attach_buffer(). 277 + * It also appends the INDIO_BUFFER_HARDWARE mode to the supported modes of the 278 + * IIO device. 279 + */ 280 + int devm_iio_dmaengine_buffer_setup(struct device *dev, 281 + struct iio_dev *indio_dev, 282 + const char *channel) 283 + { 284 + struct iio_buffer *buffer; 285 + 286 + buffer = devm_iio_dmaengine_buffer_alloc(indio_dev->dev.parent, 287 + channel); 288 + if (IS_ERR(buffer)) 289 + return PTR_ERR(buffer); 290 + 291 + indio_dev->modes |= INDIO_BUFFER_HARDWARE; 292 + 293 + iio_device_attach_buffer(indio_dev, buffer); 294 + 295 + return 0; 296 + } 297 + EXPORT_SYMBOL_GPL(devm_iio_dmaengine_buffer_setup); 269 298 270 299 MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); 271 300 MODULE_DESCRIPTION("DMA buffer for the IIO framework");
+4 -3
include/linux/iio/buffer-dmaengine.h
··· 7 7 #ifndef __IIO_DMAENGINE_H__ 8 8 #define __IIO_DMAENGINE_H__ 9 9 10 - struct iio_buffer; 10 + struct iio_dev; 11 11 struct device; 12 12 13 - struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, 14 - const char *channel); 13 + int devm_iio_dmaengine_buffer_setup(struct device *dev, 14 + struct iio_dev *indio_dev, 15 + const char *channel); 15 16 16 17 #endif