spi: spi-fsl-dspi: Halt the module after a new message transfer

The XSPI mode implementation in this driver still uses the EOQ flag to
signal the last word in a transmission and deassert the PCS signal.
However, at speeds lower than ~200kHZ, the PCS signal seems to remain
asserted even when SR[EOQF] = 1 indicates the end of a transmission.
This is a problem for target devices which require the deassertation of
the PCS signal between transfers.

Hence, this commit 'forces' the deassertation of the PCS by stopping the
module through MCR[HALT] after completing a new transfer. According to
the reference manual, the module stops or transitions from the Running
state to the Stopped state after the current frame, when any one of the
following conditions exist:
- The value of SR[EOQF] = 1.
- The chip is in Debug mode and the value of MCR[FRZ] = 1.
- The value of MCR[HALT] = 1.

This shouldn't be done if the last transfer in the message has cs_change
set.

Fixes: ea93ed4c181b ("spi: spi-fsl-dspi: Use EOQ for last word in buffer even for XSPI mode")
Signed-off-by: Bogdan-Gabriel Roman <bogdan-gabriel.roman@nxp.com>
Signed-off-by: Larisa Grigore <larisa.grigore@nxp.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Link: https://patch.msgid.link/20250522-james-nxp-spi-v2-2-bea884630cfb@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by Bogdan-Gabriel Roman and committed by Mark Brown 8a30a6d3 283ae0c6

Changed files
+24
drivers
+24
drivers/spi/spi-fsl-dspi.c
··· 62 62 #define SPI_SR_TFIWF BIT(18) 63 63 #define SPI_SR_RFDF BIT(17) 64 64 #define SPI_SR_CMDFFF BIT(16) 65 + #define SPI_SR_TXRXS BIT(30) 65 66 #define SPI_SR_CLEAR (SPI_SR_TCFQF | \ 66 67 SPI_SR_TFUF | SPI_SR_TFFF | \ 67 68 SPI_SR_CMDTCF | SPI_SR_SPEF | \ ··· 922 921 struct spi_transfer *transfer; 923 922 bool cs = false; 924 923 int status = 0; 924 + u32 val = 0; 925 + bool cs_change = false; 925 926 926 927 message->actual_length = 0; 928 + 929 + /* Put DSPI in running mode if halted. */ 930 + regmap_read(dspi->regmap, SPI_MCR, &val); 931 + if (val & SPI_MCR_HALT) { 932 + regmap_update_bits(dspi->regmap, SPI_MCR, SPI_MCR_HALT, 0); 933 + while (regmap_read(dspi->regmap, SPI_SR, &val) >= 0 && 934 + !(val & SPI_SR_TXRXS)) 935 + ; 936 + } 927 937 928 938 list_for_each_entry(transfer, &message->transfers, transfer_list) { 929 939 dspi->cur_transfer = transfer; ··· 965 953 dspi->tx_cmd |= SPI_PUSHR_CMD_CONT; 966 954 } 967 955 956 + cs_change = transfer->cs_change; 968 957 dspi->tx = transfer->tx_buf; 969 958 dspi->rx = transfer->rx_buf; 970 959 dspi->len = transfer->len; ··· 999 986 1000 987 if (!(dspi->tx_cmd & SPI_PUSHR_CMD_CONT)) 1001 988 dspi_deassert_cs(spi, &cs); 989 + } 990 + 991 + if (status || !cs_change) { 992 + /* Put DSPI in stop mode */ 993 + regmap_update_bits(dspi->regmap, SPI_MCR, 994 + SPI_MCR_HALT, SPI_MCR_HALT); 995 + while (regmap_read(dspi->regmap, SPI_SR, &val) >= 0 && 996 + val & SPI_SR_TXRXS) 997 + ; 1002 998 } 1003 999 1004 1000 message->status = status; ··· 1266 1244 mcr |= SPI_MCR_XSPI; 1267 1245 if (!spi_controller_is_target(dspi->ctlr)) 1268 1246 mcr |= SPI_MCR_HOST; 1247 + 1248 + mcr |= SPI_MCR_HALT; 1269 1249 1270 1250 regmap_write(dspi->regmap, SPI_MCR, mcr); 1271 1251 regmap_write(dspi->regmap, SPI_SR, SPI_SR_CLEAR);