[PATCH v2 1/5] spi: support simultaneous assertion of multiple CS
Jonathan Santos <[email protected]> Mon, 3 Aug 2026 00:01:48 -0300
| Newsgroups | org.kernel.vger.linux-spi,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <545ce92de534e90123af6fa1c75768b9482eb686.1785725359.git.Jonathan.Santos@analog.com> |
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 rather than hardcoding BIT(0), so the controller correctly identifies which CS lines belong to a device when asserting them simultaneously. 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. Acked-by: Nuno Sá <[email protected]> Signed-off-by: Jonathan Santos <[email protected]> --- Changes in v2: * Include Summary describind why the other SPI paths were not addressed here. --- drivers/spi/spi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index d9e6b4b87c89..55fb96fea243 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1090,7 +1090,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; } @@ -2594,10 +2594,11 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, spi_set_chipselect(spi, idx, cs[idx]); /* - * By default spi->chip_select[0] will hold the physical CS number, - * so set bit 0 in spi->cs_index_mask. + * Set cs_index_mask to indicate which logical CS indices are active. + * Each bit corresponds to a logical CS index in the spi->chip_select array. */ - spi->cs_index_mask = BIT(0); + for (idx = 0; idx < rc; idx++) + spi->cs_index_mask |= BIT(idx); /* Device speed */ if (!of_property_read_u32(nc, "spi-max-frequency", &value)) -- 2.34.1