diff mbox series

[v4,2/3] spi: Add a mechanism to use the fwnode name for the SPI device

Message ID 20240409132126.1117916-3-ckeepax@opensource.cirrus.com (mailing list archive)
State Superseded
Headers show
Series Add bridged amplifiers to cs42l43 | expand

Commit Message

Charles Keepax April 9, 2024, 1:21 p.m. UTC
Add a mechanism to force the use of the fwnode name for the name of the
SPI device itself. This is useful when devices need to be manually added
within the kernel.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Changes since v3:
 - Always name swnode SPI devices after the node name

Thanks,
Charles

 drivers/spi/spi.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Charles Keepax April 9, 2024, 2:46 p.m. UTC | #1
On Tue, Apr 09, 2024 at 02:21:25PM +0100, Charles Keepax wrote:
> Add a mechanism to force the use of the fwnode name for the name of the
> SPI device itself. This is useful when devices need to be manually added
> within the kernel.
> 
> Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
> ---

Apologies looking at this I really should have updated the commit
message as well. I will send a new rev soon if there are no new
comments.

Thanks,
Charles
Andy Shevchenko April 9, 2024, 6:06 p.m. UTC | #2
On Tue, Apr 09, 2024 at 02:21:25PM +0100, Charles Keepax wrote:
> Add a mechanism to force the use of the fwnode name for the name of the
> SPI device itself. This is useful when devices need to be manually added
> within the kernel.

Same comment, we don't need two ways to handle fwnode type
(and effectivelly code duplication to some extent).

...

>  	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);

>  	if (adev) {

Replace this to be is_acpi_device_node() check...

>  		dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));

...and derive adev from fwnode.

>  		return;
>  	}

> +	if (is_software_node(fwnode)) {
> +		dev_set_name(&spi->dev, "spi-%s", fwnode_get_name(fwnode));

While at this, you can also introduce

	struct device *dev = &spi->dev;

to make these dev_set_name() be shorter.

> +		return;
> +	}
Charles Keepax April 10, 2024, 8:42 a.m. UTC | #3
On Tue, Apr 09, 2024 at 09:06:56PM +0300, Andy Shevchenko wrote:
> On Tue, Apr 09, 2024 at 02:21:25PM +0100, Charles Keepax wrote:
> > Add a mechanism to force the use of the fwnode name for the name of the
> > SPI device itself. This is useful when devices need to be manually added
> > within the kernel.
> 
> Same comment, we don't need two ways to handle fwnode type
> (and effectivelly code duplication to some extent).
> 
> ...
> 
> >  	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
> 
> >  	if (adev) {
> 
> Replace this to be is_acpi_device_node() check...
> 
> >  		dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));
> 
> ...and derive adev from fwnode.
> 

I had been hoping to not modify the path I wasn't using but fair
enough if you are sure this is a fine substitution.

> >  		return;
> >  	}
> 
> > +	if (is_software_node(fwnode)) {
> > +		dev_set_name(&spi->dev, "spi-%s", fwnode_get_name(fwnode));
> 
> While at this, you can also introduce
> 
> 	struct device *dev = &spi->dev;
> 
> to make these dev_set_name() be shorter.
> 

Sure.

Thanks,
Charles
diff mbox series

Patch

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index a2f01116ba09..52c70705d179 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -598,12 +598,18 @@  EXPORT_SYMBOL_GPL(spi_alloc_device);
 static void spi_dev_set_name(struct spi_device *spi)
 {
 	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
+	struct fwnode_handle *fwnode = dev_fwnode(&spi->dev);
 
 	if (adev) {
 		dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));
 		return;
 	}
 
+	if (is_software_node(fwnode)) {
+		dev_set_name(&spi->dev, "spi-%s", fwnode_get_name(fwnode));
+		return;
+	}
+
 	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->controller->dev),
 		     spi_get_chipselect(spi, 0));
 }