[PATCH v3 3/6] spi: expand device name to include all CS lines for multi-CS devices
Jonathan Santos <[email protected]>
| Newsgroups | org.kernel.vger.linux-spi,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <5719698587a0a7658a3980168eef0731a5e7506a.1786973376.git.Jonathan.Santos@analog.com> |
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>+<cs1>+... so that all active chip-selects are reflected in the device name. Single-CS devices are not affected since the loop only appends extra indices when num_chipselect is greater than one. Signed-off-by: Jonathan Santos <[email protected]> --- 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 55fb96fea243..9ccfa5be557b 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -594,6 +594,8 @@ static void spi_dev_set_name(struct spi_device *spi) { struct device *dev = &spi->dev; struct fwnode_handle *fwnode = dev_fwnode(dev); + char cs_str[32]; + int cs_len; if (is_acpi_device_node(fwnode)) { dev_set_name(dev, "spi-%s", acpi_dev_name(to_acpi_device_node(fwnode))); @@ -605,8 +607,12 @@ static void spi_dev_set_name(struct spi_device *spi) return; } - dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev), - spi_get_chipselect(spi, 0)); + cs_len = scnprintf(cs_str, sizeof(cs_str), "%u", spi_get_chipselect(spi, 0)); + for (unsigned int idx = 1; idx < spi->num_chipselect; idx++) + cs_len += scnprintf(cs_str + cs_len, sizeof(cs_str) - cs_len, + "+%u", spi_get_chipselect(spi, idx)); + + dev_set_name(&spi->dev, "%s.%s", dev_name(&spi->controller->dev), cs_str); } /* -- 2.34.1