diff mbox series

[01/10] iio: buffer: add helper for setting direction

Message ID 20240328-iio-backend-axi-dac-v1-1-afc808b3fde3@analog.com (mailing list archive)
State Changes Requested
Headers show
Series iio: dac: support IIO backends on the output direction | expand

Commit Message

Nuno Sa via B4 Relay March 28, 2024, 1:22 p.m. UTC
From: Nuno Sa <nuno.sa@analog.com>

Simple helper for setting the buffer direction when it's allocated using
iio_dmaengine_buffer_alloc().

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
---
 drivers/iio/industrialio-buffer.c | 7 +++++++
 include/linux/iio/buffer.h        | 3 +++
 2 files changed, 10 insertions(+)

Comments

Jonathan Cameron March 28, 2024, 2:36 p.m. UTC | #1
On Thu, 28 Mar 2024 14:22:25 +0100
Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:

> From: Nuno Sa <nuno.sa@analog.com>
> 
> Simple helper for setting the buffer direction when it's allocated using
> iio_dmaengine_buffer_alloc().
> 
> Signed-off-by: Nuno Sa <nuno.sa@analog.com>
I wonder if we should align with the approach for triggered-buffers with and _ext
form of the registration function that takes a direction.  It seems odd to allocate
one then change the direction.

Jonathan

> ---
>  drivers/iio/industrialio-buffer.c | 7 +++++++
>  include/linux/iio/buffer.h        | 3 +++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 1d950a3e153b..4b1ca6ad86ee 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1956,6 +1956,13 @@ void iio_buffer_put(struct iio_buffer *buffer)
>  }
>  EXPORT_SYMBOL_GPL(iio_buffer_put);
>  
> +void iio_buffer_set_dir(struct iio_buffer *buffer,
> +			enum iio_buffer_direction dir)
> +{
> +	buffer->direction = dir;
> +}
> +EXPORT_SYMBOL_GPL(iio_buffer_set_dir);
> +
>  /**
>   * iio_device_attach_buffer - Attach a buffer to a IIO device
>   * @indio_dev: The device the buffer should be attached to
> diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
> index 418b1307d3f2..7e70bb5adc01 100644
> --- a/include/linux/iio/buffer.h
> +++ b/include/linux/iio/buffer.h
> @@ -55,4 +55,7 @@ bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
>  int iio_device_attach_buffer(struct iio_dev *indio_dev,
>  			     struct iio_buffer *buffer);
>  
> +void iio_buffer_set_dir(struct iio_buffer *buffer,
> +			enum iio_buffer_direction dir);
> +
>  #endif /* _IIO_BUFFER_GENERIC_H_ */
>
Nuno Sá March 28, 2024, 3:18 p.m. UTC | #2
On Thu, 2024-03-28 at 14:36 +0000, Jonathan Cameron wrote:
> On Thu, 28 Mar 2024 14:22:25 +0100
> Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
> 
> > From: Nuno Sa <nuno.sa@analog.com>
> > 
> > Simple helper for setting the buffer direction when it's allocated using
> > iio_dmaengine_buffer_alloc().
> > 
> > Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> I wonder if we should align with the approach for triggered-buffers with and _ext
> form of the registration function that takes a direction.  It seems odd to allocate
> one then change the direction.
> 

I agree it feels odd but I did not wanted to include buffer_impl.h in places that
should not have it :)

This patchseries adds the direction to devm_iio_dmaengine_buffer_setup(). Maybe what
we need is to have a non devm variant iio_dmaengine_buffer_setup() and turn
iio_dmaengine_buffer_alloc() static again. Maybe that would make things a bit more
consistent. In fact looking closer into that file, I would get rid of:

devm_iio_dmaengine_buffer_alloc() and __devm_iio_dmaengine_buffer_free() 

and have:

devm_iio_dmaengine_buffer_setup() and iio_dmaengine_buffer_setup() that make use of
iio_dmaengine_buffer_free() and iio_dmaengine_buffer_alloc(). 

I think it would make more sense like the above. Thoughts?

- Nuno Sá
Jonathan Cameron March 28, 2024, 3:54 p.m. UTC | #3
On Thu, 28 Mar 2024 16:18:04 +0100
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Thu, 2024-03-28 at 14:36 +0000, Jonathan Cameron wrote:
> > On Thu, 28 Mar 2024 14:22:25 +0100
> > Nuno Sa via B4 Relay <devnull+nuno.sa.analog.com@kernel.org> wrote:
> >   
> > > From: Nuno Sa <nuno.sa@analog.com>
> > > 
> > > Simple helper for setting the buffer direction when it's allocated using
> > > iio_dmaengine_buffer_alloc().
> > > 
> > > Signed-off-by: Nuno Sa <nuno.sa@analog.com>  
> > I wonder if we should align with the approach for triggered-buffers with and _ext
> > form of the registration function that takes a direction.  It seems odd to allocate
> > one then change the direction.
> >   
> 
> I agree it feels odd but I did not wanted to include buffer_impl.h in places that
> should not have it :)
> 
> This patchseries adds the direction to devm_iio_dmaengine_buffer_setup(). Maybe what
> we need is to have a non devm variant iio_dmaengine_buffer_setup() and turn
> iio_dmaengine_buffer_alloc() static again. Maybe that would make things a bit more
> consistent. In fact looking closer into that file, I would get rid of:
> 
> devm_iio_dmaengine_buffer_alloc() and __devm_iio_dmaengine_buffer_free() 
> 
> and have:
> 
> devm_iio_dmaengine_buffer_setup() and iio_dmaengine_buffer_setup() that make use of
> iio_dmaengine_buffer_free() and iio_dmaengine_buffer_alloc(). 
> 
> I think it would make more sense like the above. Thoughts?

Sounds reasonable to me

Jonathan

> 
> - Nuno Sá
>
diff mbox series

Patch

diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index 1d950a3e153b..4b1ca6ad86ee 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -1956,6 +1956,13 @@  void iio_buffer_put(struct iio_buffer *buffer)
 }
 EXPORT_SYMBOL_GPL(iio_buffer_put);
 
+void iio_buffer_set_dir(struct iio_buffer *buffer,
+			enum iio_buffer_direction dir)
+{
+	buffer->direction = dir;
+}
+EXPORT_SYMBOL_GPL(iio_buffer_set_dir);
+
 /**
  * iio_device_attach_buffer - Attach a buffer to a IIO device
  * @indio_dev: The device the buffer should be attached to
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h
index 418b1307d3f2..7e70bb5adc01 100644
--- a/include/linux/iio/buffer.h
+++ b/include/linux/iio/buffer.h
@@ -55,4 +55,7 @@  bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
 int iio_device_attach_buffer(struct iio_dev *indio_dev,
 			     struct iio_buffer *buffer);
 
+void iio_buffer_set_dir(struct iio_buffer *buffer,
+			enum iio_buffer_direction dir);
+
 #endif /* _IIO_BUFFER_GENERIC_H_ */