Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: nuno.sa@analog.com
Cc: linux-iio@vger.kernel.org, Lars-Peter Clausen <lars@metafoo.de>,
	 Michael Hennerich <Michael.Hennerich@analog.com>,
	Jonathan Cameron <jic23@kernel.org>
Subject: Re: [PATCH] iio: adc: ad9467: use DMA safe buffer for spi
Date: Tue, 7 May 2024 16:43:18 -0500	[thread overview]
Message-ID: <CAMknhBHf5f_z9iG89sfHOZ5F_q+Ho+zKDXA0M10U3BBMuSUh0w@mail.gmail.com> (raw)
In-Reply-To: <20240506-dev-ad9467-dma-v1-1-e5c31b464e8f@analog.com>

On Mon, May 6, 2024 at 9:55 AM Nuno Sa via B4 Relay
<devnull+nuno.sa.analog.com@kernel.org> wrote:
>
> From: Nuno Sa <nuno.sa@analog.com>
>
> Make sure we use a DMA safe buffer (IIO_DMA_MINALIGN) for all the spi
> transfers.
>
> Note that as we noe use a shared buffer, lock guards had to be added

s/noe/now

> accordingly.
>
> Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC")
> Signed-off-by: Nuno Sa <nuno.sa@analog.com>
> ---
>  drivers/iio/adc/ad9467.c | 87 ++++++++++++++++++++++++------------------------
>  1 file changed, 44 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/iio/adc/ad9467.c b/drivers/iio/adc/ad9467.c
> index e85b763b9ffcb..368546b032891 100644
> --- a/drivers/iio/adc/ad9467.c
> +++ b/drivers/iio/adc/ad9467.c
> @@ -141,55 +141,55 @@ struct ad9467_state {
>         struct gpio_desc                *pwrdown_gpio;
>         /* ensure consistent state obtained on multiple related accesses */
>         struct mutex                    lock;
> +       union {
> +               u8 buf[3];
> +               u8 tbuf[2];
> +               u8 rbuf[1];
> +       } __aligned(IIO_DMA_MINALIGN);
>  };
>
> -static int ad9467_spi_read(struct spi_device *spi, unsigned int reg)
> +static int ad9467_spi_read(struct ad9467_state *st, unsigned int reg)
>  {
> -       unsigned char tbuf[2], rbuf[1];
>         int ret;
>
> -       tbuf[0] = 0x80 | (reg >> 8);
> -       tbuf[1] = reg & 0xFF;
> +       st->tbuf[0] = 0x80 | (reg >> 8);
> +       st->tbuf[1] = reg & 0xFF;
>
> -       ret = spi_write_then_read(spi,
> -                                 tbuf, ARRAY_SIZE(tbuf),
> -                                 rbuf, ARRAY_SIZE(rbuf));
> +       ret = spi_write_then_read(st->spi, st->tbuf, ARRAY_SIZE(st->tbuf),
> +                                 st->rbuf, ARRAY_SIZE(st->rbuf));

spi_write_then_read() copies the buffers, so technically we don't need
to change this one.

>
>         if (ret < 0)
>                 return ret;
>
> -       return rbuf[0];
> +       return st->rbuf[0];
>  }
>

      reply	other threads:[~2024-05-07 21:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 14:55 [PATCH] iio: adc: ad9467: use DMA safe buffer for spi Nuno Sa via B4 Relay
2024-05-07 21:43 ` David Lechner [this message]

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=CAMknhBHf5f_z9iG89sfHOZ5F_q+Ho+zKDXA0M10U3BBMuSUh0w@mail.gmail.com \
    --to=dlechner@baylibre.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).