[PATCH 3.16 030/148] spi: atmel: fix handling of cs_change set on non-last xfer

From: Ben Hutchings
Date: Sat Feb 08 2020 - 13:38:20 EST


3.16.82-rc1 review patch. If anyone has any objections, please let me know.

------------------

From: Mans Rullgard <mans@xxxxxxxxx>

commit fed8d8c7a6dc2a76d7764842853d81c770b0788e upstream.

The driver does the wrong thing when cs_change is set on a non-last
xfer in a message. When cs_change is set, the driver deactivates the
CS and leaves it off until a later xfer again has cs_change set whereas
it should be briefly toggling CS off and on again.

This patch brings the behaviour of the driver back in line with the
documentation and common sense. The delay of 10 us is the same as is
used by the default spi_transfer_one_message() function in spi.c.
[gregory: rebased on for-5.5 from spi tree]
Fixes: 8090d6d1a415 ("spi: atmel: Refactor spi-atmel to use SPI framework queue")
Signed-off-by: Mans Rullgard <mans@xxxxxxxxx>
Acked-by: Nicolas Ferre <nicolas.ferre@xxxxxxxxx>
Signed-off-by: Gregory CLEMENT <gregory.clement@xxxxxxxxxxx>
Link: https://lore.kernel.org/r/20191018153504.4249-1-gregory.clement@xxxxxxxxxxx
Signed-off-by: Mark Brown <broonie@xxxxxxxxxx>
[bwhh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@xxxxxxxxxxxxxxx>
---
drivers/spi/spi-atmel.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

--- a/drivers/spi/spi-atmel.c
+++ b/drivers/spi/spi-atmel.c
@@ -242,7 +242,6 @@ struct atmel_spi {
struct atmel_spi_dma dma;

bool keep_cs;
- bool cs_active;
};

/* Controller-specific per-slave state */
@@ -1190,11 +1189,9 @@ static int atmel_spi_one_transfer(struct
&msg->transfers)) {
as->keep_cs = true;
} else {
- as->cs_active = !as->cs_active;
- if (as->cs_active)
- cs_activate(as, msg->spi);
- else
- cs_deactivate(as, msg->spi);
+ cs_deactivate(as, msg->spi);
+ udelay(10);
+ cs_activate(as, msg->spi);
}
}

@@ -1217,7 +1214,6 @@ static int atmel_spi_transfer_one_messag
atmel_spi_lock(as);
cs_activate(as, spi);

- as->cs_active = true;
as->keep_cs = false;

msg->status = 0;