Re: [PATCH 2/6] spi: add per-transfer CS mask

From: Andy Shevchenko

Date: Tue Jul 14 2026 - 05:24:10 EST


On Tue, Jul 14, 2026 at 02:56:02AM -0300, Jonathan Santos wrote:
> Multi-CS devices assert all their chip selects simultaneously by default
> via cs_index_mask. Some use cases require selecting a subset of those CS
> lines per transfer (e.g. routing data to one of several subdevices sharing
> the bus).
>
> Add a cs_select_mask field to spi_transfer. When the mask is set and the
> controller has SPI_CONTROLLER_MULTI_CS, spi_set_cs() builds a temporary
> spi_device whose chip_select[] and cs_gpiod[] arrays contain only the lines
> indicated by the mask, then delegates to the renamed _spi_set_cs().
> When cs_select_mask is 0 or the controller does not support multi-CS,
> the device default (cs_index_mask) is used unchanged.
>
> Update spi_transfer_one_message() to pass the relevant spi_transfer to
> every spi_set_cs() call so CS transitions between transfers with
> different masks are handled correctly.

...

> + /*
> + * Handle multi-CS controller path.
> + * For multi-CS controllers, we need to create a temporary spi_device
> + * structure that reflects the transfer's CS selection

Missing period at the end. Always follow English grammar and punctuation in
multi-line comments.

> + */

...

> + struct spi_transfer *next_xfer = list_next_entry(xfer, transfer_list);

Define it in the top of the respective scope.

...

> + if (ret != 0 || !keep_cs) {
> + /* Use the last transfer's CS configuration for proper cleanup */
> + struct spi_transfer *last_xfer = list_last_entry(&msg->transfers,
> + struct spi_transfer,
> + transfer_list);

This style is hard to follow, just split assignment and definition.

struct spi_transfer *last_xfer;

last_xfer = list_last_entry(&msg->transfers, struct spi_transfer, transfer_list);

> + spi_set_cs(msg->spi, last_xfer, false, false);
> + }

...

> unsigned dummy_data:1;
> unsigned cs_off:1;
> unsigned cs_change:1;
> + unsigned cs_select_mask:8;
> unsigned tx_nbits:4;
> unsigned rx_nbits:4;

Be careful with these. Have you run `pahole` to check if there is no boundaries
break that makes some unneeded gaps?

--
With Best Regards,
Andy Shevchenko