[PATCH v4 3/9] spi: support simultaneous assertion of multiple CS
From: Jonathan Santos
Date: Tue Oct 20 2026 - 21:57:55 EST
Some SPI controllers allow multiple CS lines to be toggled at the same
time. The existing code always used CS index 0 when tracking the last
active CS in spi_set_cs(), and unconditionally set cs_index_mask to
BIT(0) when parsing DT, both forcing the single CS usage.
Modify spi_set_cs() to iterate last_cs[] using each logical CS index
instead of always reading index 0. Modify of_spi_parse_dt() to build
cs_index_mask from all parsed CS entries when 'spi-cs-composite' is set,
so the controller identifies which CS lines belong to a device when
asserting them simultaneously as a composite device.
Board info, ACPI, and ancillary device paths are not updated here.
Board info would require an API change to accept an array of CS values
and is left for a follow-up when we have a use case for this. Ancillary
devices are by design single-CS, so multi-CS is not a current use case for
them. ACPI represents the CS as a 64-bit integer with no established
convention for encoding multiple CS indices yet, so any extension there
would require a separate specification effort.
Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
---
Changes in v4:
* use spi-cs-composite to determine whether to assert all CS lines
together, rather than always asserting them together.
* Replaced the for-loop to assign the spi->cs_index_mask with
"GENMASK(spi->num_chipselect - 1, 0)".
Changes in v3:
* None.
Changes in v2:
* Include Summary describing why the other SPI paths were not addressed
here.
---
drivers/spi/spi.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 5b5b3bc5f0d8..7a0406ec200e 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1278,7 +1278,7 @@ static void spi_set_cs(struct spi_device *spi, bool enable, bool force)
spi->controller->last_cs_index_mask = spi->cs_index_mask;
for (idx = 0; idx < SPI_DEVICE_CS_CNT_MAX; idx++) {
if (enable && idx < spi->num_chipselect)
- spi->controller->last_cs[idx] = spi_get_chipselect(spi, 0);
+ spi->controller->last_cs[idx] = spi_get_chipselect(spi, idx);
else
spi->controller->last_cs[idx] = SPI_INVALID_CS;
}
@@ -2794,8 +2794,19 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi,
/*
* By default spi->chip_select[0] will hold the physical CS number,
* so set bit 0 in spi->cs_index_mask.
+ *
+ * If "spi-cs-composite" is present, assert all CS lines at once
+ * so the device acts as a single composite target.
*/
- spi->cs_index_mask = BIT(0);
+ if (of_property_read_bool(nc, "spi-cs-composite")) {
+ if (!(ctlr->flags & SPI_CONTROLLER_MULTI_CS)) {
+ dev_err(&ctlr->dev, "SPI controller doesn't support multi CS\n");
+ return -EINVAL;
+ }
+ spi->cs_index_mask = GENMASK(spi->num_chipselect - 1, 0);
+ } else {
+ spi->cs_index_mask = BIT(0);
+ }
/* Device speed */
if (!of_property_read_u32(nc, "spi-max-frequency", &value))
--
2.34.1