spi: Make GPIO CSs honour the SPI_NO_CS flag
authorPhil Elwell <phil@raspberrypi.org>
Tue, 3 Jul 2018 13:23:47 +0000 (14:23 +0100)
committerpopcornmix <popcornmix@gmail.com>
Mon, 13 May 2019 23:08:04 +0000 (00:08 +0100)
The SPI configuration state includes an SPI_NO_CS flag that disables
all CS line manipulation, for applications that want to manage their
own chip selects. However, this flag is ignored by the GPIO CS code
in the SPI framework.

Correct this omission with a trivial patch.

See: https://github.com/raspberrypi/linux/issues/2169

Signed-off-by: Phil Elwell <phil@raspberrypi.org>
drivers/spi/spi.c

index 9da0bc5..f611024 100644 (file)
@@ -733,7 +733,9 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
                enable = !enable;
 
        if (gpio_is_valid(spi->cs_gpio)) {
-               gpio_set_value(spi->cs_gpio, !enable);
+               /* Honour the SPI_NO_CS flag */
+               if (!(spi->mode & SPI_NO_CS))
+                       gpio_set_value(spi->cs_gpio, !enable);
                /* Some SPI masters need both GPIO CS & slave_select */
                if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
                    spi->controller->set_cs)