linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3 1/2] spi: Add Flag to Enable Slave Select with GPIO Chip Select.
@ 2016-10-10 14:25 tthayer
  2016-10-10 14:25 ` [PATCHv3 2/2] spi: dw: Set GPIO_SS flag to toggle Slave Select on GPIO CS tthayer
       [not found] ` <1476109525-21213-1-git-send-email-tthayer-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org>
  0 siblings, 2 replies; 4+ messages in thread
From: tthayer @ 2016-10-10 14:25 UTC (permalink / raw)
  To: broonie
  Cc: andriy.shevchenko, jarkko.nikula, jszhang, michael, kernel,
	linux-spi, linux-kernel, tthayer

From: Thor Thayer <tthayer@opensource.altera.com>

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>
---
v2  Move changes to SPI framework based on maintainer comments
    Add a new SPI master boolean variable.
v3  Change boolean variable to master->flags based on comments
---
 drivers/spi/spi.c       |    9 +++++++--
 include/linux/spi/spi.h |    1 +
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5787b72..cbe15ab 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -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
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 4b743ac..75c6bd0 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -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
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-10-11 10:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-10 14:25 [PATCHv3 1/2] spi: Add Flag to Enable Slave Select with GPIO Chip Select tthayer
2016-10-10 14:25 ` [PATCHv3 2/2] spi: dw: Set GPIO_SS flag to toggle Slave Select on GPIO CS tthayer
     [not found]   ` <1476109525-21213-2-git-send-email-tthayer-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org>
2016-10-11 10:30     ` Applied "spi: dw: Set GPIO_SS flag to toggle Slave Select on GPIO CS" to the spi tree Mark Brown
     [not found] ` <1476109525-21213-1-git-send-email-tthayer-yzvPICuk2ABMcg4IHK0kFoH6Mc4MB0Vx@public.gmane.org>
2016-10-11 10:30   ` Applied "spi: Add Flag to Enable Slave Select with GPIO Chip Select." " Mark Brown

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 NNTP newsgroup(s).