spi: Add Flag to Enable Slave Select with GPIO Chip Select.
authorThor Thayer <tthayer@opensource.altera.com>
Mon, 10 Oct 2016 14:25:24 +0000 (09:25 -0500)
committerMark Brown <broonie@kernel.org>
Fri, 21 Oct 2016 11:09:30 +0000 (12:09 +0100)
Some SPI masters require slave selection before the transfer
can begin [1]. The SPI framework currently selects the chip using
either 1) the internal CS mechanism or 2) the GPIO CS, but not both.

This patch adds a new master->flags define to indicate both the GPIO
CS and the internal chip select mechanism should be used.

Tested On:
    Altera CycloneV development kit
    Compile tested for build errors on x86_64 (allyesconfigs)

[1] DesignWare dw_apb_ssi Databook, Version 3.20a (page 39)

Signed-off-by: Thor Thayer <tthayer@opensource.altera.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c
include/linux/spi/spi.h

index 5787b723b593f79bb5e55f3b68abcb2f19d4b5cb..cbe15ab5f8a8c9a6d78363c3988fac6d79cd6e78 100644 (file)
@@ -697,10 +697,15 @@ static void spi_set_cs(struct spi_device *spi, bool enable)
        if (spi->mode & SPI_CS_HIGH)
                enable = !enable;
 
-       if (gpio_is_valid(spi->cs_gpio))
+       if (gpio_is_valid(spi->cs_gpio)) {
                gpio_set_value(spi->cs_gpio, !enable);
-       else if (spi->master->set_cs)
+               /* Some SPI masters need both GPIO CS & slave_select */
+               if ((spi->master->flags & SPI_MASTER_GPIO_SS) &&
+                   spi->master->set_cs)
+                       spi->master->set_cs(spi, !enable);
+       } else if (spi->master->set_cs) {
                spi->master->set_cs(spi, !enable);
+       }
 }
 
 #ifdef CONFIG_HAS_DMA
index 4b743ac3539623889b6e2d8cc008df062e0f2b34..75c6bd0ac605b2024509985214cdc3d451c6ab53 100644 (file)
@@ -442,6 +442,7 @@ struct spi_master {
 #define SPI_MASTER_NO_TX       BIT(2)          /* can't do buffer write */
 #define SPI_MASTER_MUST_RX      BIT(3)         /* requires rx */
 #define SPI_MASTER_MUST_TX      BIT(4)         /* requires tx */
+#define SPI_MASTER_GPIO_SS      BIT(5)         /* GPIO CS must select slave */
 
        /*
         * on some hardware transfer / message size may be constrained