Skip to contentSkip to conversation

spi: Fix incorrect cs_setup delay handling

PATCH Superseded Hector Martin 2 participants 4 messages Dec 10, 2021 SPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: Fix incorrect cs_setup delay handling

We need to wait *after* asserting CS and before the transfer, not before asserting CS which isn't very useful.

Fixes 25093bdeb6bc ("spi: implement SW control for CS times")
---
 drivers/spi/spi.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/spi/spi.c +6 -7
index b23e675953e1..cfb708d928b5 100644
@@ -947,12 +947,9 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 	spi->controller->last_cs_enable = enable;
 	spi->controller->last_cs_mode_high = spi->mode & SPI_CS_HIGH;
 
-	if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio) ||
-	    !spi->controller->set_cs_timing) {
-		if (activate)
-			spi_delay_exec(&spi->cs_setup, NULL);
-		else
-			spi_delay_exec(&spi->cs_hold, NULL);
+	if ((spi->cs_gpiod || gpio_is_valid(spi->cs_gpio) ||
+	    !spi->controller->set_cs_timing) && !activate) {
+		spi_delay_exec(&spi->cs_hold, NULL);
 	}
 
 	if (spi->mode & SPI_CS_HIGH)
@@ -994,7 +991,9 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
 
 	if (spi->cs_gpiod || gpio_is_valid(spi->cs_gpio) ||
 	    !spi->controller->set_cs_timing) {
-		if (!activate)
+		if (activate)
+			spi_delay_exec(&spi->cs_setup, NULL);
+		else
 			spi_delay_exec(&spi->cs_inactive, NULL);
 	}
 }
Signature · 1 line
2.33.0
maintainer
#1 lore raw
Quoted 2 lines · Hector Martin

We need to wait *after* asserting CS and before the transfer, not before asserting CS which isn't very useful.

This needs a better changelog, there's multiple delays being handled here and it's not clear from this which are affected here or what the problem is.

#2 lore raw
Quoted 8 lines · Mark Brown
Quoted 2 lines · Hector Martin

We need to wait *after* asserting CS and before the transfer, not before asserting CS which isn't very useful.

This needs a better changelog, there's multiple delays being handled here and it's not clear from this which are affected here or what the problem is.

cs_setup is affected, I thought at least that was clear from the patch summary :-)

From spi.h:

* @cs_setup: delay to be introduced by the controller after CS is asserted

So clearly that delay has to happen at the end of spi_set_cs, *after* the assertion, not at the beginning before it.

If you prefer, I can resend it with a reference to the spi.h comment.

Signature · 2 lines
Hector Martin ([email protected])
Public Key: https://mrcn.st/pub
maintainer
#3 lore raw
Quoted 8 lines · Hector Martin
Quoted 3 lines · Mark Brown

This needs a better changelog, there's multiple delays being handled here and it's not clear from this which are affected here or what the problem is.

cs_setup is affected, I thought at least that was clear from the patch summary :-)

This should be in the commit message, the subject line of the e-mail isn't super visible when people are reviewing - basically, the body of the commit message should make sense standalone.

Quoted 1 line

If you prefer, I can resend it with a reference to the spi.h comment.

Yes, please resend with a clear commit message.