Re: [PATCH] iio: adc: ad9467: use DMA safe buffer for spi

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 6, 2024 at 9:55 AM Nuno Sa via B4 Relay
<devnull+nuno.sa.analog.com@xxxxxxxxxx> wrote:
>
> From: Nuno Sa <nuno.sa@xxxxxxxxxx>
>
> 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@xxxxxxxxxx>
> ---
>  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];
>  }
>





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux