Skip to contentSkip to conversation

spi: Fix handling of cs_change in core implementation

PATCH In review Mark Brown 2 participants 3 messages Mar 30, 2014 – Mar 31, 2014 2 messages not in the archive SPI

lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/1 spi: Fix handling of cs_change in core implementation

From: Mark Brown <[email protected]>

The core implementation of cs_change didn't follow the documentation which says that cs_change in the middle of the transfer means to briefly deassert chip select, instead it followed buggy drivers which change the polarity of chip select. Use a delay of 10us between deassert and reassert simply from pulling numbers out of a hat.

---

Compile tested only.

 drivers/spi/spi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/spi.c +3 -3
index 121c43b..4eb9bf0 100644
@@ -754,7 +754,6 @@ static int spi_transfer_one_message(struct spi_master *master,
 				    struct spi_message *msg)
 {
 	struct spi_transfer *xfer;
-	bool cur_cs = true;
 	bool keep_cs = false;
 	int ret = 0;
 	int ms = 1;
@@ -800,8 +799,9 @@ static int spi_transfer_one_message(struct spi_master *master,
 					 &msg->transfers)) {
 				keep_cs = true;
 			} else {
-				cur_cs = !cur_cs;
-				spi_set_cs(msg->spi, cur_cs);
+				spi_set_cs(msg->spi, false);
+				udelay(10);
+				spi_set_cs(msg->spi, true);
 			}
 		}
 
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1396139265-28900-1-git-send-email-broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org

#2 lore raw
Quoted 11 lines · Mark Brown

From: Mark Brown <[email protected]>

The core implementation of cs_change didn't follow the documentation which says that cs_change in the middle of the transfer means to briefly deassert chip select, instead it followed buggy drivers which change the polarity of chip select. Use a delay of 10us between deassert and reassert simply from pulling numbers out of a hat.

The change looks good to me. The resulting behaviour now is what the documentation suggests (brief deassertion of the CS signal). The previous inversion was unexpected.

The delay between deassertion and re-assertion looks good, too. It allows for propagation of the change through the hardware. Those who need longer pauses still can construct individual messages. There's probably no need to change the boolean "cs_change" into a numerical "deassertion pause length" spec.

virtually yours
Gerhard Sittig

Signature · 7 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: [email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20140331074529.GE2775-kDjWylLy9wD0K7fsECOQyeGNnDKD8DIp@public.gmane.org

author
#4 lore raw
Quoted 5 lines · Gerhard Sittig

The delay between deassertion and re-assertion looks good, too. It allows for propagation of the change through the hardware. Those who need longer pauses still can construct individual messages. There's probably no need to change the boolean "cs_change" into a numerical "deassertion pause length" spec.

I'm more worried about board specific requirements to increase the delay there than I am about devices, or about devices that wish to lower the delay. But I do think it's likely to be OK in practice, someone who actually runs into problems can worry about enhancements.