[PATCH 2/3] spi: amlogic: spisg: Fix the incorrect keep_ss of the last descriptor
From: Xianwei Zhao via B4 Relay
Date: Fri Jul 17 2026 - 03:54:45 EST
From: Sunny Luo <sunny.luo@xxxxxxxxxxx>
The driver currently unconditionally clears CFG_KEEP_SS on the last
descriptor, causing the last transfer's cs_change setting to be ignored.
Record the cs_change value of the last SPI transfer and use it to
program CFG_KEEP_SS on the final descriptor. When a null descriptor is
inserted to implement the cs-hold delay, keep CFG_KEEP_SS set on the
preceding transfer descriptor and apply the recorded value to the final
descriptor instead.
This ensures the controller handles chip select correctly for the last
transfer regardless of whether a cs-hold delay is required.
Fixes: cef9991e04ae ("spi: Add Amlogic SPISG driver")
Signed-off-by: Sunny Luo <sunny.luo@xxxxxxxxxxx>
Signed-off-by: Xianwei Zhao <xianwei.zhao@xxxxxxxxxxx>
---
drivers/spi/spi-amlogic-spisg.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-amlogic-spisg.c b/drivers/spi/spi-amlogic-spisg.c
index afc8af04638d..0f026d3e43e0 100644
--- a/drivers/spi/spi-amlogic-spisg.c
+++ b/drivers/spi/spi-amlogic-spisg.c
@@ -489,6 +489,7 @@ static int aml_spisg_transfer_one_message(struct spi_controller *ctlr,
struct spisg_descriptor_extra *exdescs, *exdesc;
dma_addr_t descs_paddr;
int desc_num = 1, descs_len;
+ bool last_xfer_keep_ss = false;
u32 cs_hold_in_sclk = 0;
int ret = -EIO;
@@ -529,9 +530,11 @@ static int aml_spisg_transfer_one_message(struct spi_controller *ctlr,
spi_delay_to_sclk(xfer->effective_speed_hz, &msg->spi->cs_setup));
/* calculate cs-hold delay with the last xfer speed */
- if (list_is_last(&xfer->transfer_list, &msg->transfers))
+ if (list_is_last(&xfer->transfer_list, &msg->transfers)) {
cs_hold_in_sclk =
spi_delay_to_sclk(xfer->effective_speed_hz, &msg->spi->cs_hold);
+ last_xfer_keep_ss = xfer->cs_change;
+ }
desc++;
exdesc++;
@@ -539,13 +542,17 @@ static int aml_spisg_transfer_one_message(struct spi_controller *ctlr,
xfer->effective_speed_hz);
}
- if (cs_hold_in_sclk)
+ if (cs_hold_in_sclk) {
/* additional null-descriptor to achieve the cs-hold delay */
aml_spisg_setup_null_desc(spisg, desc, cs_hold_in_sclk);
- else
desc--;
+ desc->cfg_bus |= FIELD_PREP(CFG_KEEP_SS, 1);
+ desc++;
+ } else {
+ desc--;
+ }
- desc->cfg_bus |= FIELD_PREP(CFG_KEEP_SS, 0);
+ FIELD_MODIFY(CFG_KEEP_SS, &desc->cfg_bus, last_xfer_keep_ss);
desc->cfg_start |= FIELD_PREP(CFG_EOC, 1);
/* some tolerances */
--
2.52.0