Re: [PATCH v4 5/9] spi: expand device name to include enabled CS lines for multi-CS devices
From: Jonathan Cameron
Date: Sun Oct 25 2026 - 22:13:22 EST
On Tue, 20 Oct 2026 22:57:44 -0300
Jonathan Santos <Jonathan.Santos@xxxxxxxxxx> wrote:
> The device name for SPI devices was formatted as <controller>.<cs0>,
> always using only the first chip-select index, ignoring the remaining CS
> lines.
>
> Change the naming format to <controller>.<cs0>-<csN> for multi-cs
> devices so that the range of active chip-selects is reflected in the
> device name. Since we are not expecting sparse values for logical CS
> values, adopt the range format.
change that to not supporting rather than expecting.
I'm not sure that's a good idea - and Andy's request to check for
existing ones is a good start. However, if you do it, consistency
through the patch set is important.
>
> Signed-off-by: Jonathan Santos <Jonathan.Santos@xxxxxxxxxx>
> ---
> Changes in v4:
> * Opted for the range format, since we decide to limit logical CS values
> to a contiguous sequence.
>
> Changes in v3:
> * replaced `int idx = 1` by `unsigned int idx = 1` in the for loop.
>
> Changes in v2:
> * New patch.
> ---
> drivers/spi/spi.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 2b2eeaa4c15d..53d6ab4ce8a3 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -782,6 +782,7 @@ static void spi_dev_set_name(struct spi_device *spi)
> {
> struct device *dev = &spi->dev;
> struct fwnode_handle *fwnode = dev_fwnode(dev);
> + u8 num_enabled_cs = hweight32(spi->cs_index_mask);
>
> if (is_acpi_device_node(fwnode)) {
> dev_set_name(dev, "spi-%s", acpi_dev_name(to_acpi_device_node(fwnode)));
> @@ -793,6 +794,19 @@ static void spi_dev_set_name(struct spi_device *spi)
> return;
> }
>
> + /*
> + * In multi-CS arrangements, use num_enabled_cs (derived from
> + * cs_index_mask) to determine which CS lines the device is actively
> + * using. num_chipselect only reflects how many CS lines are assigned
> + * to the device, not how many are actually enabled.
> + */
> + if (num_enabled_cs > 1) {
> + dev_set_name(&spi->dev, "%s.%u-%u", dev_name(&spi->controller->dev),
> + spi_get_chipselect(spi, 0),
> + spi_get_chipselect(spi, num_enabled_cs - 1));
> + return;
> + }
> +
> dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev),
> spi_get_chipselect(spi, 0));
> }