Re: [PATCH v3 5/6] spi: spi-engine-ex: Add support for multi-CS devices

Andy Shevchenko <[email protected]>
Newsgroups org.kernel.vger.linux-spi,org.kernel.vger.linux-kernel
Organization Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.