Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: David Lechner <dlechner@baylibre.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Matt Ranostay" <mranostay@gmail.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: adc: ti-adc161s626: use DMA-safe memory for spi_read()
Date: Mon, 16 Mar 2026 18:31:17 +0000	[thread overview]
Message-ID: <20260316183117.4dde7386@jic23-huawei> (raw)
In-Reply-To: <20260314-iio-adc-ti-adc161s626-fix-scan-buf-v1-2-56243b11e87b@baylibre.com>

On Sat, 14 Mar 2026 18:13:32 -0500
David Lechner <dlechner@baylibre.com> wrote:

> Add a DMA-safe buffer and use it for spi_read() instead of a stack
> memory. All SPI buffers must be DMA-safe.
> 
> Since we only need up to 3 bytes, we just use a u8[] instead of __be16
> and __be32 and change the conversion functions appropriately.
> 
> Fixes: 4d671b71beef ("iio: adc: ti-adc161s626: add support for TI 1-channel differential ADCs")
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
>  drivers/iio/adc/ti-adc161s626.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/iio/adc/ti-adc161s626.c b/drivers/iio/adc/ti-adc161s626.c
> index 1d427548e0b3..6416d6a7ada0 100644
> --- a/drivers/iio/adc/ti-adc161s626.c
> +++ b/drivers/iio/adc/ti-adc161s626.c
> @@ -70,6 +70,7 @@ struct ti_adc_data {
>  
>  	u8 read_size;
>  	u8 shift;
> +	u8 buf[3] __aligned(IIO_DMA_MINALIGN);
On this. There is new generic infrastructure for marking these.
https://elixir.bootlin.com/linux/v7.0-rc3/source/include/linux/dma-mapping.h#L720
https://lore.kernel.org/all/01ea88055ded4d70cac70ba557680fd5fa7d9ff5.1767601130.git.mst@redhat.com/

Would look like
	__dma_from_device_group_begin();
	u8 buf[3];
	__dma_from_device_group_end();

Do you think we should adopt them rather than doing our own thing?
Slowly though I don't want the noise of a mass conversion.

As normal, advantage of standard infrastructure is cutting down
in subsystem specific magic.

I 'think' result is the same (though it also forces the trailing padding if anything
comes after this and needs it).


>  };
>  
>  static int ti_adc_read_measurement(struct ti_adc_data *data,
> @@ -78,26 +79,20 @@ static int ti_adc_read_measurement(struct ti_adc_data *data,
>  	int ret;
>  
>  	switch (data->read_size) {
> -	case 2: {
> -		__be16 buf;
> -
> -		ret = spi_read(data->spi, (void *) &buf, 2);
> +	case 2:
> +		ret = spi_read(data->spi, data->buf, 2);
>  		if (ret)
>  			return ret;
>  
> -		*val = be16_to_cpu(buf);
> +		*val = get_unaligned_be16(data->buf);
>  		break;
> -	}
> -	case 3: {
> -		__be32 buf;
> -
> -		ret = spi_read(data->spi, (void *) &buf, 3);
> +	case 3:
> +		ret = spi_read(data->spi, data->buf, 3);
>  		if (ret)
>  			return ret;
>  
> -		*val = be32_to_cpu(buf) >> 8;
> +		*val = get_unaligned_be24(data->buf);
>  		break;
> -	}
>  	default:
>  		return -EINVAL;
>  	}
> 


  parent reply	other threads:[~2026-03-16 18:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 23:13 [PATCH 0/2] iio: adc: ti-adc161s626: fix scan buffer handling David Lechner
2026-03-14 23:13 ` [PATCH 1/2] iio: adc: ti-adc161s626: fix buffer read on big-endian David Lechner
2026-03-16 13:56   ` Andy Shevchenko
2026-03-21 20:42     ` Jonathan Cameron
2026-03-14 23:13 ` [PATCH 2/2] iio: adc: ti-adc161s626: use DMA-safe memory for spi_read() David Lechner
2026-03-16 14:05   ` Andy Shevchenko
2026-03-21 20:45     ` Jonathan Cameron
2026-03-16 18:31   ` Jonathan Cameron [this message]
2026-03-16 19:53     ` Andy Shevchenko
2026-03-21 19:40       ` David Lechner
2026-03-21 20:54         ` Jonathan Cameron
2026-03-21 20:18       ` Jonathan Cameron
2026-03-21 19:27     ` David Lechner
2026-03-21 20:21       ` Jonathan Cameron
2026-03-27  9:13   ` kernel test robot
2026-03-27  9:44     ` Andy Shevchenko
2026-03-27 13:54       ` David Lechner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260316183117.4dde7386@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mranostay@gmail.com \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox