[PATCH] spi-fsl-spi: Align CS behaviour for last SPI msg

From: Joakim Tjernlund
Date: Wed Aug 16 2017 - 07:09:22 EST


According to spi.h cs_change can be used to leave the CS
active until next SPI transfer(paragraph ii).
Adjust driver to comply with (ii).

Signed-off-by: Joakim Tjernlund <joakim.tjernlund@xxxxxxxxxxxx>
---
drivers/spi/spi-fsl-spi.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 061c1f38bf46..9a6cb26680a9 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -358,6 +358,7 @@ static int fsl_spi_do_one_msg(struct spi_master *master,
{
struct spi_device *spi = m->spi;
struct spi_transfer *t, *first;
+ bool keep_cs = false;
unsigned int cs_change;
const int nsecs = 50;
int status;
@@ -401,16 +402,21 @@ static int fsl_spi_do_one_msg(struct spi_master *master,
udelay(t->delay_usecs);

if (cs_change) {
- ndelay(nsecs);
- fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE);
- ndelay(nsecs);
+ if (list_is_last(&t->transfer_list,
+ &m->transfers)) {
+ keep_cs = true;
+ } else {
+ ndelay(nsecs);
+ fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE);
+ ndelay(nsecs);
+ }
}
}

m->status = status;
spi_finalize_current_message(master);

- if (status || !cs_change) {
+ if (status || !keep_cs) {
ndelay(nsecs);
fsl_spi_chipselect(spi, BITBANG_CS_INACTIVE);
}
--
2.13.0