Re: [PATCH 1/6] spi: support simultaneous assertion of multiple CS

From: Nuno Sá

Date: Tue Jul 14 2026 - 05:09:49 EST


On Tue, Jul 14, 2026 at 02:55:48AM -0300, Jonathan Santos wrote:
> 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.
>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
> ---

LGTM,

Acked-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

> 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
>