diff mbox series

[2/3] spi: execute set_cs function before gpio cs is activated

Message ID 20221202094926.9113-1-edmund.berenson@emlix.com (mailing list archive)
State New, archived
Headers show
Series [1/3] spi: dw: select SS0 when gpio cs is used | expand

Commit Message

Edmund Berenson Dec. 2, 2022, 9:49 a.m. UTC
In some cases it is necessary to adjust the spi controller configuration
before gpio cs is set.
For example if spi devices requiring different cpol are used from the same
controller the adjustment to cpol has to be made before gpio is activated.
To achieve this set_cs should be executed before gpio cs and necessary
adjustments can be made inside of controller driver.

Suggested-by: Lukasz Zemla <Lukasz.Zemla@woodward.com>
Signed-off-by: Edmund Berenson <edmund.berenson@emlix.com>
---
 drivers/spi/spi.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5f9aedd1f0b6..bf2a67184969 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -976,6 +976,11 @@  static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 		enable = !enable;
 
 	if (spi->cs_gpiod) {
+		/* Some SPI masters need both GPIO CS & slave_select */
+		if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
+		    spi->controller->set_cs)
+			spi->controller->set_cs(spi, !enable);
+
 		if (!(spi->mode & SPI_NO_CS)) {
 			/*
 			 * Historically ACPI has no means of the GPIO polarity and
@@ -993,10 +998,6 @@  static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 				/* Polarity handled by GPIO library */
 				gpiod_set_value_cansleep(spi->cs_gpiod, activate);
 		}
-		/* Some SPI masters need both GPIO CS & slave_select */
-		if ((spi->controller->flags & SPI_MASTER_GPIO_SS) &&
-		    spi->controller->set_cs)
-			spi->controller->set_cs(spi, !enable);
 	} else if (spi->controller->set_cs) {
 		spi->controller->set_cs(spi, !enable);
 	}