Re: [PATCH v3 5/6] spi: spi-engine-ex: Add support for multi-CS devices
From: Andy Shevchenko
Date: Tue Aug 18 2026 - 03:02:48 EST
On Mon, Aug 17, 2026 at 08:33:26PM -0300, Jonathan Santos wrote:
> The SPI Engine controller only handled the first chip select when
> asserting CS lines and configuring CS polarity inversion, ignoring
> additional CS indices present in cs_index_mask.
>
> Update spi_engine_gen_cs() to iterate over all set bits in
> cs_index_mask and toggle each corresponding CS line in the assert mask.
> Update spi_engine_setup() likewise so that SPI_CS_HIGH polarity is
> applied to every active CS index rather than only index 0.
>
> Set SPI_CONTROLLER_MULTI_CS in the controller flags to reflect the
> capability to the SPI core.
...
> + for_each_set_bit(cs_bit, &cs_index_mask, SPI_ENGINE_MAX_CS)
> + mask ^= BIT(spi_get_chipselect(spi, cs_bit));
> + for_each_set_bit(cs_bit, &cs_index_mask, SPI_ENGINE_MAX_CS) {
> + if (device->mode & SPI_CS_HIGH)
> + spi_engine->cs_inv |= BIT(spi_get_chipselect(device, cs_bit));
> + else
> + spi_engine->cs_inv &= ~BIT(spi_get_chipselect(device, cs_bit));
> + }
Looking at these two I would rather see a helper
unsigned long spi_get_chipselect_bits(..., unsigned long index_mask)
With that the above becomes for-loop free.
mask ^= spi_get_chipselect_bits(spi, cs_index_mask);
and
if (device->mode & SPI_CS_HIGH)
spi_engine->cs_inv |= spi_get_chipselect_bits(device, cs_index_mask));
else
spi_engine->cs_inv &= ~spi_get_chipselect_bits(device, cs_index_mask));
respectively.
--
With Best Regards,
Andy Shevchenko