Skip to content

Commit 1a81799

Browse files
dlechnunojsa
authored andcommitted
iio: buffer-dmaengine: add devm_iio_dmaengine_buffer_setup_with_handle()
Add a new devm_iio_dmaengine_buffer_setup_with_handle() function to handle cases where the DMA channel is managed by the caller rather than being requested and released by the iio_dmaengine module. Reviewed-by: Nuno Sa <nuno.sa@analog.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250207-dlech-mainline-spi-engine-offload-2-v8-9-e48a489be48c@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 60d1a5d commit 1a81799

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

drivers/iio/buffer/industrialio-buffer-dmaengine.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,44 @@ int devm_iio_dmaengine_buffer_setup_with_ops(struct device *dev,
491491
}
492492
EXPORT_SYMBOL_NS_GPL(devm_iio_dmaengine_buffer_setup_with_ops, IIO_DMAENGINE_BUFFER);
493493

494+
static void devm_iio_dmaengine_buffer_free(void *buffer)
495+
{
496+
iio_dmaengine_buffer_free(buffer);
497+
}
498+
499+
/**
500+
* devm_iio_dmaengine_buffer_setup_with_handle() - Setup a DMA buffer for an
501+
* IIO device
502+
* @dev: Device for devm ownership
503+
* @indio_dev: IIO device to which to attach this buffer.
504+
* @chan: DMA channel
505+
* @dir: Direction of buffer (in or out)
506+
*
507+
* This allocates a new IIO buffer with devm_iio_dmaengine_buffer_alloc()
508+
* and attaches it to an IIO device with iio_device_attach_buffer().
509+
* It also appends the INDIO_BUFFER_HARDWARE mode to the supported modes of the
510+
* IIO device.
511+
*
512+
* This is the same as devm_iio_dmaengine_buffer_setup_ext() except that the
513+
* caller manages requesting and releasing the DMA channel handle.
514+
*/
515+
int devm_iio_dmaengine_buffer_setup_with_handle(struct device *dev,
516+
struct iio_dev *indio_dev,
517+
struct dma_chan *chan,
518+
enum iio_buffer_direction dir)
519+
{
520+
struct iio_buffer *buffer;
521+
522+
buffer = __iio_dmaengine_buffer_setup_ext(indio_dev, chan, dir, NULL, NULL);
523+
if (IS_ERR(buffer))
524+
return PTR_ERR(buffer);
525+
526+
return devm_add_action_or_reset(dev, devm_iio_dmaengine_buffer_free,
527+
buffer);
528+
}
529+
EXPORT_SYMBOL_NS_GPL(devm_iio_dmaengine_buffer_setup_with_handle,
530+
IIO_DMAENGINE_BUFFER);
531+
494532
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
495533
MODULE_DESCRIPTION("DMA buffer for the IIO framework");
496534
MODULE_LICENSE("GPL");

include/linux/iio/buffer-dmaengine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
struct iio_dev;
1313
struct device;
14+
struct dma_chan;
1415
struct iio_buffer;
1516
struct iio_dma_buffer_ops;
1617
struct iio_dma_buffer_block;
@@ -34,6 +35,10 @@ int devm_iio_dmaengine_buffer_setup_ext(struct device *dev,
3435
struct iio_dev *indio_dev,
3536
const char *channel,
3637
enum iio_buffer_direction dir);
38+
int devm_iio_dmaengine_buffer_setup_with_handle(struct device *dev,
39+
struct iio_dev *indio_dev,
40+
struct dma_chan *chan,
41+
enum iio_buffer_direction dir);
3742

3843
#define devm_iio_dmaengine_buffer_setup(dev, indio_dev, channel) \
3944
devm_iio_dmaengine_buffer_setup_ext(dev, indio_dev, channel, \

0 commit comments

Comments
 (0)