Re: [PATCH 1/4] spi: core: Allow both TX and RX transfers in 3WIRE

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

 



Hi Linus,

On Mon, Sep 3, 2018 at 11:51 PM Linus Walleij <linus.walleij@xxxxxxxxxx> wrote:
> The SPI message validation code in __spi_validate() is too
> restrictive on 3WIRE transfers: the core bitbanging code,
> for example, will gladly switch direction of the line
> inbetween transfers.

Thanks for your patch!

> Allow 3WIRE messages even if there is both TX and RX
> transfers in the message.

OK.

> Transfers with TX and RX at the same time will not work
> however (just one wire after all), so be sure to disallow
> those.

Unless SPI_LOOP is also set ;-)

> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -2841,10 +2841,17 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message)
>                 list_for_each_entry(xfer, &message->transfers, transfer_list) {
>                         if (xfer->rx_buf && xfer->tx_buf)
>                                 return -EINVAL;

Or:

        if (spi->mode & SPI_3WIRE)
                continue;

> -                       if ((flags & SPI_CONTROLLER_NO_TX) && xfer->tx_buf)
> -                               return -EINVAL;
> -                       if ((flags & SPI_CONTROLLER_NO_RX) && xfer->rx_buf)
> -                               return -EINVAL;
> +                       /*
> +                        * 3WIRE can indeed do a write message followed by a
> +                        * read message, the direction of the line will be
> +                        * switched between the two messages.
> +                        */
> +                       if (spi->mode & SPI_CONTROLLER_HALF_DUPLEX) {
> +                               if ((flags & SPI_CONTROLLER_NO_TX) && xfer->tx_buf)
> +                                       return -EINVAL;
> +                               if ((flags & SPI_CONTROLLER_NO_RX) && xfer->rx_buf)
> +                                       return -EINVAL;
> +                       }
>                 }
>         }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds



[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux