Skip to contentSkip to conversation

I2C and SPI dev_name change for ACPI enumerated slaves

RFC Superseded Jarkko Nikula 8 participants 42 messages Oct 25, 2013 – Nov 16, 2013 17 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover I2C and SPI dev_name change for ACPI enumerated slaves

Hi

We've run into problem of changing I2C device names while developing ALSA SoC drivers for x86 based systems. Changing device names makes more difficult to match devices by their name. Which is what we use within ASoC subsystem.

These changing names comes from changing adapter/bus numbering which could occur due variable amount of bus controllers, probe order, add-on cards or different BIOS settings.

Patches here try to solve the problem on ACPI 5 based systems by using stable ACPI device name with a "i2c-"/"spi-" prefix for I2C/SPI slave device names.

Both patches are independent from each other and can go through their own subsystems.

Jarkko Nikula (2):
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++----
 drivers/spi/spi.c      | 21 ++++++++++++++++++---
 2 files changed, 38 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.4.rc3

A message that is not in the archive (sent off-list or not yet received): 1382703540-3769-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

#2 lore raw

RFC 1/2 i2c: Use stable dev_name for ACPI enumerated I2C slaves

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

---
I'm not sure when would acpi_bus_get_device fail and how realistic is that here. I put minimalistic error handling here which just falls back to old adapter-addr naming scheme.

---
 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core.c +20 -4
index 111b2c6..8d6f3e5 100644
@@ -613,6 +613,25 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+#if IS_ENABLED(CONFIG_ACPI)
+	if (ACPI_HANDLE(&client->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&client->dev), &adev)) {
+			dev_set_name(&client->dev, "i2c-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+#endif
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -671,10 +690,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;
 	ACPI_HANDLE_SET(&client->dev, info->acpi_node.handle);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;
Signature · 1 line
1.8.4.rc3
#3 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 26 lines · Jarkko Nikula

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

---
I'm not sure when would acpi_bus_get_device fail and how realistic is that here. I put minimalistic error handling here which just falls back to old adapter-addr naming scheme.

---
 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core.c +0 -0
index 111b2c6..8d6f3e5 100644

drivers/i2c/i2c-core.c void i2c_unlock_adapter(struct i2c_adapter *adapter) · line 620

Quoted 8 lines
drivers/i2c/i2c-core.c +5 -0
@@ -613,6 +613,25 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+#if IS_ENABLED(CONFIG_ACPI)
+	if (ACPI_HANDLE(&client->dev)) {

ACPI_HANDLE() already contains an "is CONFIG_ACPI enabled?" check, so the #if around the if (ACPI_HANDLE()) {} is redundant.

Similarly for the SPI patch.

Quoted 20 lines
drivers/i2c/i2c-core.c +14 -0
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&client->dev), &adev)) {
+			dev_set_name(&client->dev, "i2c-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+#endif
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -671,10 +690,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;

drivers/i2c/i2c-core.c i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) · line 696

Quoted 10 lines
drivers/i2c/i2c-core.c +1 -4
 	ACPI_HANDLE_SET(&client->dev, info->acpi_node.handle);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#5 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Hi

Quoted 11 lines · Rafael J. Wysocki
drivers/i2c/i2c-core.c +5 -0
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+#if IS_ENABLED(CONFIG_ACPI)
+	if (ACPI_HANDLE(&client->dev)) {

ACPI_HANDLE() already contains an "is CONFIG_ACPI enabled?" check, so the #if around the if (ACPI_HANDLE()) {} is redundant.

Similarly for the SPI patch.

Well, acpi_bus_get_device() is not available for non-ACPI builds and at least the gcc I used for test build didn't optimize that block away.

Signature · 6 lines
Jarkko

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 526A6A41.6020909-VuQAYsv1563Yd54FQh9/[email protected]

#7 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 12 lines · Jarkko Nikula

Hi

Quoted 9 lines · Rafael J. Wysocki
drivers/i2c/i2c-core.c +5 -0
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+#if IS_ENABLED(CONFIG_ACPI)
+	if (ACPI_HANDLE(&client->dev)) {

ACPI_HANDLE() already contains an "is CONFIG_ACPI enabled?" check, so the #if around the if (ACPI_HANDLE()) {} is redundant.

Quoted 4 lines
Quoted 2 lines

Similarly for the SPI patch.

Well, acpi_bus_get_device() is not available for non-ACPI builds and at least the gcc I used for test build didn't optimize that block away.

Well, it should. ACPI_HANDLE() translates to (NULL) if CONFIG_ACPI is not defined and that causes the check to become "if (NULL)" which should always be dropped by the compiler.

Does providing a stub acpi_bus_get_device() for !CONFIG_ACPI actually help?

Rafael

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Jarkko Nikula

Well, acpi_bus_get_device() is not available for non-ACPI builds and at least the gcc I used for test build didn't optimize that block away.

Well, it should. ACPI_HANDLE() translates to (NULL) if CONFIG_ACPI is not defined and that causes the check to become "if (NULL)" which should always be dropped by the compiler.

My very vague memory says the same. I don't know is this gcc version or flag dependent behavior. I got the build error from both i386 build using gcc 4.8.1 and arm build by using make ARCH=arm omap2plus_defconfig and gcc-4.7-arm-linux-gnueabi 4.7.2-4.

Quoted 3 lines

Does providing a stub acpi_bus_get_device() for !CONFIG_ACPI actually help?

Hmm, not only. Referencing to dev field in struct acpi_device by dev_name(&adev->dev) here will fail too.

Signature · 1 line
Jarkko

A message that is not in the archive (sent off-list or not yet received): 526A726F.1030407-VuQAYsv1563Yd54FQh9/[email protected]

#10 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 13 lines · Jarkko Nikula
Quoted 8 lines · Rafael J. Wysocki
Quoted 3 lines · Jarkko Nikula

Well, acpi_bus_get_device() is not available for non-ACPI builds and at least the gcc I used for test build didn't optimize that block away.

Well, it should. ACPI_HANDLE() translates to (NULL) if CONFIG_ACPI is not defined and that causes the check to become "if (NULL)" which should always be dropped by the compiler.

My very vague memory says the same. I don't know is this gcc version or flag dependent behavior. I got the build error from both i386 build using gcc 4.8.1 and arm build by using make ARCH=arm omap2plus_defconfig and gcc-4.7-arm-linux-gnueabi 4.7.2-4.

Quoted 5 lines
Quoted 3 lines

Does providing a stub acpi_bus_get_device() for !CONFIG_ACPI actually help?

Hmm, not only. Referencing to dev field in struct acpi_device by dev_name(&adev->dev) here will fail too.

Well, something is not quite right here.

One of the *reasons* for having ACPI_HANDLE() defined this way is to avoid using explicit CONFIG_ACPI checks, so if that doesn't work, then all of that becomes a bit pointless.

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Hi Rafael

Quoted 11 lines · Rafael J. Wysocki
Quoted 3 lines · Jarkko Nikula
Quoted 1 line

Hmm, not only. Referencing to dev field in struct acpi_device by dev_name(&adev->dev) here will fail too.

Well, something is not quite right here.

One of the *reasons* for having ACPI_HANDLE() defined this way is to avoid using explicit CONFIG_ACPI checks, so if that doesn't work, then all of that becomes a bit pointless.

One possible thing to do is to let structure definitions to be available for non-ACPI builds. Then compiler won't fail on structure access which will be anyway optimized away by later compiler stages.

With a quick test below vmlinux section sizes don't change for couple non-ACPI build tests and allow to get rid off IS_ENABLED(CONFIG_ACPI) test in this patch. It's very minimal as it only moves the CONFIG_ACPI test just after the struct acpi_device definition and defines acpi_bus_get_device for non-ACPI case.

What I don't know how consistent it is as there are still couple structure definitions under CONFIG_ACPI, doesn't touch other acpi headers and requires to include acpi_bus.h in driver (or move acpi_bus.h include in linux/acpi.h currently under CONFIG_ACPI).

Signature · 1 line
Jarkko
include/acpi/acpi_bus.h +4 -2
index d901982..7ab7870 100644
@@ -66,8 +66,6 @@ bool acpi_ata_match(acpi_handle handle);
 bool acpi_bay_match(acpi_handle handle);
 bool acpi_dock_match(acpi_handle handle);
 
-#ifdef CONFIG_ACPI
-
 #include <linux/proc_fs.h>
 
 #define ACPI_BUS_FILE_ROOT    "acpi"
@@ -314,6 +312,8 @@ struct acpi_device {
     void (*remove)(struct acpi_device *);
 };
 
+#if IS_ENABLED(CONFIG_ACPI)
+
 static inline void *acpi_driver_data(struct acpi_device *d)
 {
     return d->driver_data;
@@ -531,6 +531,8 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 
 static inline int register_acpi_bus_type(void *bus) { return 0; }
 static inline int unregister_acpi_bus_type(void *bus) { return 0; }
+static inline int acpi_bus_get_device(acpi_handle handle,
+                      struct acpi_device **device) { return 0; }
 
 #endif                /* CONFIG_ACPI */
maintainer
#13 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 3 lines · Jarkko Nikula

One possible thing to do is to let structure definitions to be available for non-ACPI builds. Then compiler won't fail on structure access which will be anyway optimized away by later compiler stages.

You could also have inline accessor functions which can be stubbed out when not needed.

A message that is not in the archive (sent off-list or not yet received): 526E636D.3070005-VuQAYsv1563Yd54FQh9/[email protected]

#15 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 14 lines · Jarkko Nikula

Hi Rafael

Quoted 11 lines · Rafael J. Wysocki
Quoted 3 lines · Jarkko Nikula
Quoted 1 line

Hmm, not only. Referencing to dev field in struct acpi_device by dev_name(&adev->dev) here will fail too.

Well, something is not quite right here.

One of the *reasons* for having ACPI_HANDLE() defined this way is to avoid using explicit CONFIG_ACPI checks, so if that doesn't work, then all of that becomes a bit pointless.

Can you please send patches inline instead of using inline attachments, so that people don't have to paste your patches back to comment them?

Quoted 3 lines

One possible thing to do is to let structure definitions to be available for non-ACPI builds. Then compiler won't fail on structure access which will be anyway optimized away by later compiler stages.

Yes, we can do that, but as I said that means we're giving up on the "why ACPI_HANDLE() doesn't work as expected" front. For now, I'd like to understand what's up before making that change. Moreover ->

Quoted 42 lines

With a quick test below vmlinux section sizes don't change for couple non-ACPI build tests and allow to get rid off IS_ENABLED(CONFIG_ACPI) test in this patch. It's very minimal as it only moves the CONFIG_ACPI test just after the struct acpi_device definition and defines acpi_bus_get_device for non-ACPI case.

What I don't know how consistent it is as there are still couple structure definitions under CONFIG_ACPI, doesn't touch other acpi headers and requires to include acpi_bus.h in driver (or move acpi_bus.h include in linux/acpi.h currently under CONFIG_ACPI).

include/acpi/acpi_bus.h +0 -2
index d901982..7ab7870 100644
@@ -66,8 +66,6 @@ bool acpi_ata_match(acpi_handle handle);
 
  bool acpi_bay_match(acpi_handle handle);
  bool acpi_dock_match(acpi_handle handle);
 
-#ifdef CONFIG_ACPI
-
 
  #include <linux/proc_fs.h>
  
  #define ACPI_BUS_FILE_ROOT    "acpi"
include/acpi/acpi_bus.h +2 -0
@@ -314,6 +312,8 @@ struct acpi_device {
 
      void (*remove)(struct acpi_device *);
 
  };
 
+#if IS_ENABLED(CONFIG_ACPI)
+
 
  static inline void *acpi_driver_data(struct acpi_device *d)
  {
      return d->driver_data;

include/acpi/acpi_bus.h static inline bool acpi_device_can_poweroff(struct · line 537

Quoted 7 lines
include/acpi/acpi_bus.h +2 -0
@@ -531,6 +531,8 @@ static inline bool acpi_device_can_poweroff(struct
 acpi_device *adev)
 
  static inline int register_acpi_bus_type(void *bus) { return 0; }
  static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
+static inline int acpi_bus_get_device(acpi_handle handle,
+                      struct acpi_device **device) { return 0; }

This has to return an error code, because otherwise the caller can assume *device to be a valid pointer after it returns which may not be the case.

include/acpi/acpi_bus.h static inline bool acpi_device_can_poweroff(struct acpi_device *adev) · line 537

Quoted 2 lines
include/acpi/acpi_bus.h +0 -0
  #endif                /* CONFIG_ACPI */

Thanks!

Signature · 6 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [RFC 1/2] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 19 lines · Rafael J. Wysocki
Quoted 14 lines · Jarkko Nikula

Hi Rafael

Quoted 11 lines · Rafael J. Wysocki
Quoted 3 lines · Jarkko Nikula
Quoted 1 line

Hmm, not only. Referencing to dev field in struct acpi_device by dev_name(&adev->dev) here will fail too.

Well, something is not quite right here.

One of the *reasons* for having ACPI_HANDLE() defined this way is to avoid using explicit CONFIG_ACPI checks, so if that doesn't work, then all of that becomes a bit pointless.

Can you please send patches inline instead of using inline attachments, so that people don't have to paste your patches back to comment them?

Quoted 7 lines
Quoted 3 lines

One possible thing to do is to let structure definitions to be available for non-ACPI builds. Then compiler won't fail on structure access which will be anyway optimized away by later compiler stages.

Yes, we can do that, but as I said that means we're giving up on the "why ACPI_HANDLE() doesn't work as expected" front. For now, I'd like to understand what's up before making that change. Moreover ->

OK, so I *think* what happens is that the compiler checks if the particular symbols make sense before trying to optimize out the whole block.

So the patch below modulo the return value of the acpi_bus_get_device() stub would be fine by me.

Thanks!

Quoted 55 lines
Quoted 42 lines

With a quick test below vmlinux section sizes don't change for couple non-ACPI build tests and allow to get rid off IS_ENABLED(CONFIG_ACPI) test in this patch. It's very minimal as it only moves the CONFIG_ACPI test just after the struct acpi_device definition and defines acpi_bus_get_device for non-ACPI case.

What I don't know how consistent it is as there are still couple structure definitions under CONFIG_ACPI, doesn't touch other acpi headers and requires to include acpi_bus.h in driver (or move acpi_bus.h include in linux/acpi.h currently under CONFIG_ACPI).

include/acpi/acpi_bus.h +0 -2
index d901982..7ab7870 100644
@@ -66,8 +66,6 @@ bool acpi_ata_match(acpi_handle handle);
 
  bool acpi_bay_match(acpi_handle handle);
  bool acpi_dock_match(acpi_handle handle);
 
-#ifdef CONFIG_ACPI
-
 
  #include <linux/proc_fs.h>
  
  #define ACPI_BUS_FILE_ROOT    "acpi"
include/acpi/acpi_bus.h +2 -0
@@ -314,6 +312,8 @@ struct acpi_device {
 
      void (*remove)(struct acpi_device *);
 
  };
 
+#if IS_ENABLED(CONFIG_ACPI)
+
 
  static inline void *acpi_driver_data(struct acpi_device *d)
  {
      return d->driver_data;

include/acpi/acpi_bus.h static inline bool acpi_device_can_poweroff(struct · line 537

Quoted 7 lines
include/acpi/acpi_bus.h +2 -0
@@ -531,6 +531,8 @@ static inline bool acpi_device_can_poweroff(struct
 acpi_device *adev)
 
  static inline int register_acpi_bus_type(void *bus) { return 0; }
  static inline int unregister_acpi_bus_type(void *bus) { return 0; }
 
+static inline int acpi_bus_get_device(acpi_handle handle,
+                      struct acpi_device **device) { return 0; }

This has to return an error code, because otherwise the caller can assume *device to be a valid pointer after it returns which may not be the case.

Quoted 2 lines
include/acpi/acpi_bus.h +0 -0
  #endif                /* CONFIG_ACPI */
Signature · 6 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#18 lore raw

RFC 2/2 spi: Use stable dev_name for ACPI enumerated SPI slaves

In reply to a message not in the archive

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This can be problem in PC kind of platforms if there are changes in SPI bus configuration, amount of busses or probe order.

This patch addresses the problem by using the ACPI device name with "spi-" prefix for ACPI enumerated SPI slave. For them device name "spix.y" becomes "spi-INTABCD:ij".

---
"may not be" and "This can be problem" since I don't know how likely is to have changes in SPI bus configuration in PC kind of devices. I assume yes as this is already problem with I2C devices.

---
 drivers/spi/spi.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/spi/spi.c +18 -3
index 8d05acc..2ca997f 100644
@@ -345,6 +345,23 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+void spi_dev_set_name(struct spi_device *spi)
+{
+#if IS_ENABLED(CONFIG_ACPI)
+	if (ACPI_HANDLE(&spi->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&spi->dev), &adev)) {
+			dev_set_name(&spi->dev, "spi-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+#endif
+
+	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+		     spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -371,9 +388,7 @@ int spi_add_device(struct spi_device *spi)
 	}
 
 	/* Set the bus ID string */
-	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-			spi->chip_select);
-
+	spi_dev_set_name(spi);
 
 	/* We need to make sure there's no other device with this
 	 * chipselect **BEFORE** we call setup(), else we'll trash
Signature · 6 lines
1.8.4.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
maintainer
#19 lore raw

Re: [RFC 2/2] spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 3 lines · Jarkko Nikula

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

I'm happy with this from the SPI side modulo Raphael's comments - are folks happy from the ACPI side?

#20 lore raw

Re: [RFC 2/2] spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 7 lines · Mark Brown
Quoted 3 lines · Jarkko Nikula

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

I'm happy with this from the SPI side modulo Raphael's comments - are folks happy from the ACPI side?

I think yes in general, but I'd like to understand why the ACPI_HANDLE() thing doesn't work as expected.

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#21 lore raw

v2 cover I2C and SPI dev_name change for ACPI enumerated slaves

In reply to Jarkko Nikula

Hi

Second version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version adds patch to include/acpi/acpi_bus.h that allow us to remove #if IS_ENABLED(CONFIG_ACPI) checks that were added in the first version.

Set goes on top linux-pm/linux-next commit e56b4d2.

First version here:
http://mailman.alsa-project.org/pipermail/alsa-devel/2013-October/067737.html

Jarkko Nikula (3):
ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI
builds
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

 drivers/i2c/i2c-core.c  | 24 ++++++++++++++++++++----
 drivers/spi/spi.c       | 20 +++++++++++++++++---
 include/acpi/acpi_bus.h |  9 +++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.4.rc3

A message that is not in the archive (sent off-list or not yet received): 1383309356-25430-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

#23 lore raw

PATCH v2 1/3 ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

We may find use for struct acpi_device and acpi_bus_get_device() in generic code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn there.

Code can use ACPI_HANDLE() test to let compiler optimize out code blocks that are not used in !CONFIG_ACPI builds but structure definitions and function stubs must be available.

This patch moves CONFIG_ACPI test so that struct acpi_device definition is available for all builds that include acpi_bus.h and provides a stub for acpi_bus_get_device().

---
 include/acpi/acpi_bus.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
include/acpi/acpi_bus.h +7 -2
index 15100f6..232b37d3 100644
@@ -66,8 +66,6 @@ bool acpi_ata_match(acpi_handle handle);
 bool acpi_bay_match(acpi_handle handle);
 bool acpi_dock_match(acpi_handle handle);
 
-#ifdef CONFIG_ACPI
-
 #include <linux/proc_fs.h>
 
 #define ACPI_BUS_FILE_ROOT	"acpi"
@@ -315,6 +313,8 @@ struct acpi_device {
 	void (*remove)(struct acpi_device *);
 };
 
+#if IS_ENABLED(CONFIG_ACPI)
+
 static inline void *acpi_driver_data(struct acpi_device *d)
 {
 	return d->driver_data;
@@ -532,6 +532,11 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 
 static inline int register_acpi_bus_type(void *bus) { return 0; }
 static inline int unregister_acpi_bus_type(void *bus) { return 0; }
+static inline int acpi_bus_get_device(acpi_handle handle,
+				      struct acpi_device **device)
+{
+	return -ENODEV;
+}
 
 #endif				/* CONFIG_ACPI */
 
Signature · 6 lines
1.8.4.rc3

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#24 lore raw

Re: [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

Quoted 7 lines · Jarkko Nikula

We may find use for struct acpi_device and acpi_bus_get_device() in generic code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn there.

Code can use ACPI_HANDLE() test to let compiler optimize out code blocks that are not used in !CONFIG_ACPI builds but structure definitions and function stubs must be available.

Quoted 5 lines

This patch moves CONFIG_ACPI test so that struct acpi_device definition is available for all builds that include acpi_bus.h and provides a stub for acpi_bus_get_device().

This turns out the cause build problems to happen on some architectures.

I guess it's sufficient to simply define a stub struct acpi_device as

struct acpi_device {
	struct device dev;
};

for !CONFIG_ACPI instead.

Quoted 39 lines
---
 include/acpi/acpi_bus.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
include/acpi/acpi_bus.h +7 -2
index 15100f6..232b37d3 100644
@@ -66,8 +66,6 @@ bool acpi_ata_match(acpi_handle handle);
 bool acpi_bay_match(acpi_handle handle);
 bool acpi_dock_match(acpi_handle handle);
 
-#ifdef CONFIG_ACPI
-
 #include <linux/proc_fs.h>
 
 #define ACPI_BUS_FILE_ROOT	"acpi"
@@ -315,6 +313,8 @@ struct acpi_device {
 	void (*remove)(struct acpi_device *);
 };
 
+#if IS_ENABLED(CONFIG_ACPI)
+
 static inline void *acpi_driver_data(struct acpi_device *d)
 {
 	return d->driver_data;
@@ -532,6 +532,11 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
 
 static inline int register_acpi_bus_type(void *bus) { return 0; }
 static inline int unregister_acpi_bus_type(void *bus) { return 0; }
+static inline int acpi_bus_get_device(acpi_handle handle,
+				      struct acpi_device **device)
+{
+	return -ENODEV;
+}
 
 #endif				/* CONFIG_ACPI */
 
Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#26 lore raw

Re: [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

Quoted 16 lines · Rafael J. Wysocki
Quoted 7 lines · Jarkko Nikula

We may find use for struct acpi_device and acpi_bus_get_device() in generic code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn there.

Code can use ACPI_HANDLE() test to let compiler optimize out code blocks that are not used in !CONFIG_ACPI builds but structure definitions and function stubs must be available.

Quoted 5 lines

This patch moves CONFIG_ACPI test so that struct acpi_device definition is available for all builds that include acpi_bus.h and provides a stub for acpi_bus_get_device().

This turns out the cause build problems to happen on some architectures.

Quoted 7 lines

I guess it's sufficient to simply define a stub struct acpi_device as

struct acpi_device {
	struct device dev;
};

for !CONFIG_ACPI instead.

Generally, it is a bad idea to #include acpi_bus.h for !CONFIG_ACPI.

The appended patch works for me, sorry for stealing part of your changelog.

Thanks,
Rafael

---
From: Rafael J. Wysocki <[email protected]>
Subject: ACPI: Define struct acpi_device for CONFIG_ACPI unset

We may find use for struct acpi_device and acpi_bus_get_device() in generic code without wanting to add #if IS_ENABLED(CONFIG_ACPI) churn there.

Code can use ACPI_HANDLE() test to let compiler optimize out code blocks that are not used in !CONFIG_ACPI builds but structure definitions and function stubs must be available.

Define a stub struct acpi_device for CONFIG_ACPI unset containing dev as the only member and a stub acpi_bus_get_device() always returning an error code.

---
 include/linux/acpi.h |   10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/acpi.h +10 -0
Index: linux-pm/include/linux/acpi.h
===================================================================
@@ -472,7 +472,17 @@ static inline bool acpi_driver_match_dev
 }
 
 #define ACPI_PTR(_ptr)	(NULL)
+typedef void * acpi_handle;
 
+struct acpi_device {
+	struct device dev;
+};
+
+static inline int acpi_bus_get_device(acpi_handle handle,
+				      struct acpi_device **device)
+{
+	return -ENODEV;
+}
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#27 lore raw

Re: [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

This turns out the cause build problems to happen on some architectures.

I guess it's sufficient to simply define a stub struct acpi_device as

Quoted 8 lines
Quoted 5 lines
struct acpi_device {
	struct device dev;
};

for !CONFIG_ACPI instead.

Generally, it is a bad idea to #include acpi_bus.h for !CONFIG_ACPI.

Ouch, indeed.

Quoted 2 lines

The appended patch works for me, sorry for stealing part of your changelog.

No problem. Thanks for fixing this up.

Signature · 1 line
Jarkko
#28 lore raw

Re: [PATCHv2 1/3] ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI builds

Quoted 12 lines · Jarkko Nikula
Quoted 11 lines · Rafael J. Wysocki
Quoted 9 lines · Rafael J. Wysocki

This turns out the cause build problems to happen on some architectures.

I guess it's sufficient to simply define a stub struct acpi_device as

struct acpi_device {
	struct device dev;
};

for !CONFIG_ACPI instead.

Quoted 7 lines
Quoted 2 lines

Generally, it is a bad idea to #include acpi_bus.h for !CONFIG_ACPI.

Ouch, indeed.

Quoted 2 lines

The appended patch works for me, sorry for stealing part of your changelog.

No problem. Thanks for fixing this up.

Well, unfortunately, this breaks builds for allnoconfig, because <acpi/acpi.h> is included directly from some header files (not under a CONFIG_ACPI ifdef) and duplicates the acpi_handle typedef.

So, we'll need to go through the headers, see which ones do that and replace <acpi/acpi.h> with <linux/acpi.h> (along with adding the stub definitions for !CONFIG_ACPI).

I'm deferring the patchset for after 3.13-rc1 for this reason.

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#29 lore raw

PATCH v2 3/3 spi: Use stable dev_name for ACPI enumerated SPI slaves

In reply to a message not in the archive

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This can be problem in PC kind of platforms if there are changes in SPI bus configuration, amount of busses or probe order.

This patch addresses the problem by using the ACPI device name with "spi-" prefix for ACPI enumerated SPI slave. For them device name "spix.y" becomes "spi-INTABCD:ij".

---
 drivers/spi/spi.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
drivers/spi/spi.c +17 -3
index 740f9dd..4c0c801 100644
@@ -38,6 +38,7 @@
 #include <linux/kthread.h>
 #include <linux/ioport.h>
 #include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
 
 static void spidev_release(struct device *dev)
 {
@@ -352,6 +353,21 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+void spi_dev_set_name(struct spi_device *spi)
+{
+	if (ACPI_HANDLE(&spi->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&spi->dev), &adev)) {
+			dev_set_name(&spi->dev, "spi-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+
+	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+		     spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -378,9 +394,7 @@ int spi_add_device(struct spi_device *spi)
 	}
 
 	/* Set the bus ID string */
-	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-			spi->chip_select);
-
+	spi_dev_set_name(spi);
 
 	/* We need to make sure there's no other device with this
 	 * chipselect **BEFORE** we call setup(), else we'll trash
Signature · 1 line
1.8.4.rc3

A message that is not in the archive (sent off-list or not yet received): 1383309356-25430-4-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

Acked-by
#31 lore raw

Re: [PATCHv2 3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 3 lines · Jarkko Nikula

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

#32 lore raw
In reply to a message not in the archive
Quoted 26 lines · Jarkko Nikula

Hi

Second version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version adds patch to include/acpi/acpi_bus.h that allow us to remove #if IS_ENABLED(CONFIG_ACPI) checks that were added in the first version.

Set goes on top linux-pm/linux-next commit e56b4d2.

First version here:
http://mailman.alsa-project.org/pipermail/alsa-devel/2013-October/067737.html

Jarkko Nikula (3):
ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI
builds
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 4 lines
 drivers/i2c/i2c-core.c  | 24 ++++++++++++++++++++----
 drivers/spi/spi.c       | 20 +++++++++++++++++---
 include/acpi/acpi_bus.h |  9 +++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)

Looks good to me. If there are no objections, I can merge these through my tree.

Thanks!

Signature · 6 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): [email protected]

#34 lore raw
Quoted 27 lines · Rafael J. Wysocki
Quoted 26 lines · Jarkko Nikula

Hi

Second version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version adds patch to include/acpi/acpi_bus.h that allow us to remove #if IS_ENABLED(CONFIG_ACPI) checks that were added in the first version.

Set goes on top linux-pm/linux-next commit e56b4d2.

First version here:
http://mailman.alsa-project.org/pipermail/alsa-devel/2013-October/067737.html

Jarkko Nikula (3):
ACPI: Expose struct acpi_device and acpi_bus_get_device() to non-ACPI
builds
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 6 lines
Quoted 4 lines
 drivers/i2c/i2c-core.c  | 24 ++++++++++++++++++++----
 drivers/spi/spi.c       | 20 +++++++++++++++++---
 include/acpi/acpi_bus.h |  9 +++++++--
 3 files changed, 44 insertions(+), 9 deletions(-)

Looks good to me. If there are no objections, I can merge these through my tree.

Which is basically fine with me. Do you want to have it in 3.13 already? I mean renaming the devices could lead to regressions, so I'd rather be conservative and aim for 3.14.

#35 lore raw
Quoted 7 lines · Wolfram Sang
Quoted 2 lines · Rafael J. Wysocki

Looks good to me. If there are no objections, I can merge these through my tree.

Which is basically fine with me. Do you want to have it in 3.13 already? I mean renaming the devices could lead to regressions, so I'd rather be conservative and aim for 3.14.

Valid concern. Quick grep below doesn't reveal any obvious device name matching outside of sound/soc/ but of course it doesn't prove it to be impossible.

git grep '[0-9]\-00' |grep name
git grep 'spi[0-9].[0-9]' |grep name

Signature · 1 line
Jarkko
#36 lore raw
Quoted 8 lines · Jarkko Nikula
Quoted 7 lines · Wolfram Sang
Quoted 2 lines · Rafael J. Wysocki

Looks good to me. If there are no objections, I can merge these through my tree.

Which is basically fine with me. Do you want to have it in 3.13 already? I mean renaming the devices could lead to regressions, so I'd rather be conservative and aim for 3.14.

Quoted 6 lines

Valid concern. Quick grep below doesn't reveal any obvious device name matching outside of sound/soc/ but of course it doesn't prove it to be impossible.

git grep '[0-9]\-00' |grep name
git grep 'spi[0-9].[0-9]' |grep name

Well, if any breakage is caught in 3.13-rc, it should be easy enough to revert these changes and try again during the next cycle. I honestly don't see any benefit from waiting for the next cycle "just in case".

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#38 lore raw
Quoted 4 lines

Well, if any breakage is caught in 3.13-rc, it should be easy enough to revert these changes and try again during the next cycle. I honestly don't see any benefit from waiting for the next cycle "just in case".

OK.

#39 lore raw

v3 cover I2C and SPI dev_name change for ACPI enumerated slaves

In reply to a message not in the archive

Hi

Third version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version is actually a bit cleaner thanks to Rafael's "ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node" in git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Set goes on top of linux-pm/linux-next due dependency to 1/3. As we are now in merge-window I'm fine if 1/3 goes in first and I queue 2-3/3 later to i2c and spi trees.

Jarkko Nikula (3):
ACPI: Provide struct acpi_device stub for !CONFIG_ACPI builds
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

 drivers/i2c/i2c-core.c | 21 +++++++++++++++++----
 drivers/spi/spi.c      | 17 ++++++++++++++---
 include/linux/acpi.h   |  4 ++++
 3 files changed, 35 insertions(+), 7 deletions(-)
Signature · 6 lines
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1384419661-28293-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

#41 lore raw

PATCH v3 1/3 ACPI: Provide struct acpi_device stub for !CONFIG_ACPI builds

We have a few cases where we want to access struct device dev field in struct acpi_device from generic code that is build also without CONFIG_ACPI.

Provide here a minimal struct acpi_device stub that allows to build such a code without adding new #ifdef CONFIG_ACPI churn. This should not increase section sizes if code is protected by ACPI_COMPANION() runtime checks as those will be optimized out by later compiler stages in case CONFIG_ACPI is not set.

---
Rafael, instead of this we could also have an accessor but adev->dev looked better in actual code and size vmlinux didn't change for x86_64_defconfig with CONFIG_ACPI is not set nor for omap2plus_defconfig.

---
 include/linux/acpi.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/acpi.h +4 -0
index 0da49ed..df444e1 100644
@@ -414,6 +414,10 @@ static inline bool acpi_driver_match_device(struct device *dev,
 
 #else	/* !CONFIG_ACPI */
 
+struct acpi_device {
+	struct device dev;
+};
+
 #define acpi_disabled 1
 
 #define ACPI_COMPANION(dev)		(NULL)
Signature · 1 line
1.8.4.2
#42 lore raw

Re: [alsa-devel] [PATCHv3 1/3] ACPI: Provide struct acpi_device stub for !CONFIG_ACPI builds

At Thu, 14 Nov 2013 11:00:59 +0200,

Quoted 10 lines · Jarkko Nikula

We have a few cases where we want to access struct device dev field in struct acpi_device from generic code that is build also without CONFIG_ACPI.

Provide here a minimal struct acpi_device stub that allows to build such a code without adding new #ifdef CONFIG_ACPI churn. This should not increase section sizes if code is protected by ACPI_COMPANION() runtime checks as those will be optimized out by later compiler stages in case CONFIG_ACPI is not set.

Quoted 5 lines

---
Rafael, instead of this we could also have an accessor but adev->dev looked better in actual code and size vmlinux didn't change for x86_64_defconfig with CONFIG_ACPI is not set nor for omap2plus_defconfig.

This looks too hackish, IMO. Defining a different dummy struct often gives more headaches. Thinking of the potential risk by misuses, it'd be simpler and safer to define a macro like acpi_dev_name() instead.

BTW, is linux/device.h already included in !CONFIG_ACPI case?

Takashi

Quoted 27 lines
---
 include/linux/acpi.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/acpi.h +4 -0
index 0da49ed..df444e1 100644
@@ -414,6 +414,10 @@ static inline bool acpi_driver_match_device(struct device *dev,
 
 #else	/* !CONFIG_ACPI */
 
+struct acpi_device {
+	struct device dev;
+};
+
 #define acpi_disabled 1
 
 #define ACPI_COMPANION(dev)		(NULL)
Signature · 6 lines
1.8.4.2

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#43 lore raw

Re: [alsa-devel] [PATCHv3 1/3] ACPI: Provide struct acpi_device stub for !CONFIG_ACPI builds

Quoted 16 lines · Takashi Iwai

At Thu, 14 Nov 2013 11:00:59 +0200,

Quoted 9 lines · Jarkko Nikula

We have a few cases where we want to access struct device dev field in struct acpi_device from generic code that is build also without CONFIG_ACPI.

Provide here a minimal struct acpi_device stub that allows to build such a code without adding new #ifdef CONFIG_ACPI churn. This should not increase section sizes if code is protected by ACPI_COMPANION() runtime checks as those will be optimized out by later compiler stages in case CONFIG_ACPI is not set.

Quoted 5 lines

---
Rafael, instead of this we could also have an accessor but adev->dev looked better in actual code and size vmlinux didn't change for x86_64_defconfig with CONFIG_ACPI is not set nor for omap2plus_defconfig.

Quoted 6 lines

This looks too hackish, IMO. Defining a different dummy struct often gives more headaches. Thinking of the potential risk by misuses, it'd be simpler and safer to define a macro like acpi_dev_name() instead.

BTW, is linux/device.h already included in !CONFIG_ACPI case?

It is included unconditionally in include/linux/acpi.h.

Your acpi_dev_name() proposal may be good enough for now as adev->dev access in generic code (now under CONFIG_ACPI) seems to be anyway around dev_name, using only pointer to struct acpi_device or has more things that prevents immediate #ifdef CONFIG_ACPI removal there.

But one problem at time. I'll cook a version with acpi_dev_name.

Signature · 1 line
Jarkko
#44 lore raw

PATCH v3 2/3 i2c: Use stable dev_name for ACPI enumerated I2C slaves

In reply to a message not in the archive

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

---
 drivers/i2c/i2c-core.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core.c +17 -4
index f74af33..b8f2c32 100644
@@ -618,6 +618,22 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+	struct acpi_device *adev = ACPI_COMPANION(&client->dev);
+
+	if (adev) {
+		dev_set_name(&client->dev, "i2c-%s", dev_name(&adev->dev));
+		return;
+	}
+
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -676,10 +692,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;
 	ACPI_COMPANION_SET(&client->dev, info->acpi_node.companion);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;
Signature · 1 line
1.8.4.2
#45 lore raw

PATCH v3 3/3 spi: Use stable dev_name for ACPI enumerated SPI slaves

In reply to a message not in the archive

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This can be problem in PC kind of platforms if there are changes in SPI bus configuration, amount of busses or probe order.

This patch addresses the problem by using the ACPI device name with "spi-" prefix for ACPI enumerated SPI slave. For them device name "spix.y" becomes "spi-INTABCD:ij".

---
 drivers/spi/spi.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/spi/spi.c +14 -3
index af4f971..d9140bb 100644
@@ -352,6 +352,19 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+static void spi_dev_set_name(struct spi_device *spi)
+{
+	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
+
+	if (adev) {
+		dev_set_name(&spi->dev, "spi-%s", dev_name(&adev->dev));
+		return;
+	}
+
+	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+		     spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -378,9 +391,7 @@ int spi_add_device(struct spi_device *spi)
 	}
 
 	/* Set the bus ID string */
-	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-			spi->chip_select);
-
+	spi_dev_set_name(spi);
 
 	/* We need to make sure there's no other device with this
 	 * chipselect **BEFORE** we call setup(), else we'll trash
Signature · 6 lines
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1384419661-28293-4-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

Acked-by
#47 lore raw

Re: [PATCHv3 3/3] spi: Use stable dev_name for ACPI enumerated SPI slaves

Quoted 3 lines · Jarkko Nikula

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

#48 lore raw

v4 cover I2C and SPI dev_name change for ACPI enumerated slaves

In reply to a message not in the archive

v4:
This version adds and uses acpi_dev_name() accessor instead defining struct acpi_device stub for !CONFIG_ACPI

v3:
Third version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version is actually a bit cleaner thanks to Rafael's "ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node" in git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Set goes on top of linux-pm/linux-next due dependency to 1/3. As we are now in merge-window I'm fine if 1/3 goes in first and I queue 2-3/3 later to i2c and spi trees.

Jarkko Nikula (3):
ACPI: Provide acpi_dev_name accessor for struct acpi_device device
name
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

 drivers/i2c/i2c-core.c | 21 +++++++++++++++++----
 drivers/spi/spi.c      | 17 ++++++++++++++---
 include/linux/acpi.h   | 10 ++++++++++
 3 files changed, 41 insertions(+), 7 deletions(-)
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1384430633-23426-1-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

#50 lore raw

PATCH v4 1/3 ACPI: Provide acpi_dev_name accessor for struct acpi_device device name

struct acpi_device fields are only available when CONFIG_ACPI is set. We may find use for dev_name(&adev->dev) in generic code that is build also without CONFIG_ACPI is set but currently this requires #ifdef CONFIG_ACPI churn.

Provide here an accessor that returns dev_name of embedded struct device dev in struct acpi_device or NULL depending on CONFIG_ACPI setting.

---
 include/linux/acpi.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/linux/acpi.h +10 -0
index 0da49ed..844e7ff 100644
@@ -53,6 +53,11 @@ static inline acpi_handle acpi_device_handle(struct acpi_device *adev)
 #define ACPI_COMPANION_SET(dev, adev)	ACPI_COMPANION(dev) = (adev)
 #define ACPI_HANDLE(dev)		acpi_device_handle(ACPI_COMPANION(dev))
 
+static inline const char *acpi_dev_name(struct acpi_device *adev)
+{
+	return dev_name(&adev->dev);
+}
+
 enum acpi_irq_model_id {
 	ACPI_IRQ_MODEL_PIC = 0,
 	ACPI_IRQ_MODEL_IOAPIC,
@@ -420,6 +425,11 @@ static inline bool acpi_driver_match_device(struct device *dev,
 #define ACPI_COMPANION_SET(dev, adev)	do { } while (0)
 #define ACPI_HANDLE(dev)		(NULL)
 
+static inline const char *acpi_dev_name(struct acpi_device *adev)
+{
+	return NULL;
+}
+
 static inline void acpi_early_init(void) { }
 
 static inline int early_acpi_boot_init(void)
Signature · 1 line
1.8.4.2
#51 lore raw

PATCH v4 2/3 i2c: Use stable dev_name for ACPI enumerated I2C slaves

In reply to a message not in the archive

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

---
 drivers/i2c/i2c-core.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core.c +17 -4
index f74af33..bc9a294 100644
@@ -618,6 +618,22 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+	struct acpi_device *adev = ACPI_COMPANION(&client->dev);
+
+	if (adev) {
+		dev_set_name(&client->dev, "i2c-%s", acpi_dev_name(adev));
+		return;
+	}
+
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -676,10 +692,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;
 	ACPI_COMPANION_SET(&client->dev, info->acpi_node.companion);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1384430633-23426-3-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

Acked-by
#53 lore raw

Re: [PATCHv4 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 8 lines · Jarkko Nikula

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

Quoted 5 lines

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

#54 lore raw

PATCH v4 3/3 spi: Use stable dev_name for ACPI enumerated SPI slaves

In reply to a message not in the archive

Current spi bus_num.chip_select "spix.y" based device naming scheme may not be stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This can be problem in PC kind of platforms if there are changes in SPI bus configuration, amount of busses or probe order.

This patch addresses the problem by using the ACPI device name with "spi-" prefix for ACPI enumerated SPI slave. For them device name "spix.y" becomes "spi-INTABCD:ij".

---
Mark's ack added as diff between v3 and v4 is just:
- dev_set_name(&spi->dev, "spi-%s", dev_name(&adev->dev));
+ dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));

---
 drivers/spi/spi.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/spi/spi.c +14 -3
index af4f971..be619e0 100644
@@ -352,6 +352,19 @@ struct spi_device *spi_alloc_device(struct spi_master *master)
 }
 EXPORT_SYMBOL_GPL(spi_alloc_device);
 
+static void spi_dev_set_name(struct spi_device *spi)
+{
+	struct acpi_device *adev = ACPI_COMPANION(&spi->dev);
+
+	if (adev) {
+		dev_set_name(&spi->dev, "spi-%s", acpi_dev_name(adev));
+		return;
+	}
+
+	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
+		     spi->chip_select);
+}
+
 /**
  * spi_add_device - Add spi_device allocated with spi_alloc_device
  * @spi: spi_device to register
@@ -378,9 +391,7 @@ int spi_add_device(struct spi_device *spi)
 	}
 
 	/* Set the bus ID string */
-	dev_set_name(&spi->dev, "%s.%u", dev_name(&spi->master->dev),
-			spi->chip_select);
-
+	spi_dev_set_name(spi);
 
 	/* We need to make sure there's no other device with this
 	 * chipselect **BEFORE** we call setup(), else we'll trash
Signature · 6 lines
1.8.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#55 lore raw
In reply to Jarkko Nikula
Quoted 22 lines · Jarkko Nikula

v4:
This version adds and uses acpi_dev_name() accessor instead defining struct acpi_device stub for !CONFIG_ACPI

v3:
Third version of the set that changes I2C and SPI slave device names to be generated from stable ACPI device names on ACPI 5 based systems instead of using bus numbers which could change.

Slave device name change goes as

	"x-00yz" -> "i2c-INTABCD:ij"
	"spix.y" -> "spi-INTABCD:ij"

This version is actually a bit cleaner thanks to Rafael's "ACPI / driver core: Store an ACPI device pointer in struct acpi_dev_node" in git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

Set goes on top of linux-pm/linux-next due dependency to 1/3. As we are now in merge-window I'm fine if 1/3 goes in first and I queue 2-3/3 later to i2c and spi trees.

Quoted 5 lines

Jarkko Nikula (3):
ACPI: Provide acpi_dev_name accessor for struct acpi_device device
name
i2c: Use stable dev_name for ACPI enumerated I2C slaves
spi: Use stable dev_name for ACPI enumerated SPI slaves

All three queued up for the next ACPI pull request, thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#56 lore raw

PATCH v2 2/3 i2c: Use stable dev_name for ACPI enumerated I2C slaves

In reply to Jarkko Nikula

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.

---
 drivers/i2c/i2c-core.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/i2c/i2c-core.c +20 -4
index 75ba860..9126c2e 100644
@@ -48,6 +48,7 @@
 #include <linux/rwsem.h>
 #include <linux/pm_runtime.h>
 #include <linux/acpi.h>
+#include <acpi/acpi_bus.h>
 #include <asm/uaccess.h>
 
 #include "i2c-core.h"
@@ -618,6 +619,24 @@ void i2c_unlock_adapter(struct i2c_adapter *adapter)
 }
 EXPORT_SYMBOL_GPL(i2c_unlock_adapter);
 
+static void i2c_dev_set_name(struct i2c_adapter *adap,
+			     struct i2c_client *client)
+{
+	if (ACPI_HANDLE(&client->dev)) {
+		struct acpi_device *adev;
+		if (!acpi_bus_get_device(ACPI_HANDLE(&client->dev), &adev)) {
+			dev_set_name(&client->dev, "i2c-%s",
+				     dev_name(&adev->dev));
+			return;
+		}
+	}
+
+	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
+	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
+		     client->addr | ((client->flags & I2C_CLIENT_TEN)
+				     ? 0xa000 : 0));
+}
+
 /**
  * i2c_new_device - instantiate an i2c device
  * @adap: the adapter managing the device
@@ -676,10 +695,7 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
 	client->dev.of_node = info->of_node;
 	ACPI_HANDLE_SET(&client->dev, info->acpi_node.handle);
 
-	/* For 10-bit clients, add an arbitrary offset to avoid collisions */
-	dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
-		     client->addr | ((client->flags & I2C_CLIENT_TEN)
-				     ? 0xa000 : 0));
+	i2c_dev_set_name(adap, client);
 	status = device_register(&client->dev);
 	if (status)
 		goto out_err;
Signature · 1 line
1.8.4.rc3

A message that is not in the archive (sent off-list or not yet received): 1383309356-25430-3-git-send-email-jarkko.nikula-VuQAYsv1563Yd54FQh9/[email protected]

Acked-by
#58 lore raw

Re: [PATCHv2 2/3] i2c: Use stable dev_name for ACPI enumerated I2C slaves

Quoted 8 lines · Jarkko Nikula

Current I2C adapter id - client address "x-00yy" based device naming scheme is not always stable enough to be used in name based matching, for instance within ALSA SoC subsystem.

This is problematic in PC kind of platforms where I2C adapter numbers can change due variable amount of bus controllers, probe order, add-on cards or just because of BIOS settings.

Quoted 5 lines

This patch addresses the problem by using the ACPI device name with "i2c-" prefix for ACPI enumerated I2C slaves. For them device name "x-00yz" becomes "i2c-INTABCD:ij" after this patch.