Skip to contentSkip to conversation

i2c: designware: platdrv: Set class based on dmi

PATCH Superseded Ricardo Ribalda 3 participants 4 messages Jun 24, 2020 – Jun 25, 2020

Subsystems (3)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: designware: platdrv: Set class based on dmi

Current AMD's zen-based APUs use this core for some of its i2c-buses.

With this patch we re-enable autodetection of hwmon-alike devices, so lm-sensors will be able to work automatically.

It does not affect the boot-time of embedded devices, as the class is set based on the dmi information.

---
v2:
Changes by Andy Shevchenko <[email protected]>:
- CodeStyle
Changes by kernel test robot <[email protected]>
- Include dmi header to fix build error on arc
- check if dmi_get_system_info returned NULL

 drivers/i2c/busses/i2c-designware-platdrv.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-platdrv.c +15 -1
index c2efaaaac252..5892fdba9c25 100644
@@ -12,6 +12,7 @@
 #include <linux/clk-provider.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/dmi.h>
 #include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/i2c.h>
@@ -173,6 +174,19 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
 		pm_runtime_put_noidle(dev->dev);
 }
 
+static bool dw_i2c_hwmon_bus(void)
+{
+	const char *product_name = dmi_get_system_info(DMI_PRODUCT_NAME);
+
+	if (!product_name)
+		return false;
+
+	if (strstr(product_name, "QT5222"))
+		return true;
+
+	return false;
+}
+
 static int dw_i2c_plat_request_regs(struct dw_i2c_dev *dev)
 {
 	struct platform_device *pdev = to_platform_device(dev->dev);
@@ -267,7 +281,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev)
 
 	adap = &dev->adapter;
 	adap->owner = THIS_MODULE;
-	adap->class = I2C_CLASS_DEPRECATED;
+	adap->class = dw_i2c_hwmon_bus() ? I2C_CLASS_HWMON : I2C_CLASS_DEPRECATED;
 	ACPI_COMPANION_SET(&adap->dev, ACPI_COMPANION(&pdev->dev));
 	adap->dev.of_node = pdev->dev.of_node;
 	adap->nr = -1;
Signature · 1 line
2.27.0
#1 lore raw
Quoted 7 lines · Ricardo Ribalda

Current AMD's zen-based APUs use this core for some of its i2c-buses.

With this patch we re-enable autodetection of hwmon-alike devices, so lm-sensors will be able to work automatically.

It does not affect the boot-time of embedded devices, as the class is set based on the dmi information.

I think it misses Fixes tag. And...

...

drivers/i2c/busses/i2c-designware-platdrv.c static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) · line 179

Quoted 4 lines
drivers/i2c/busses/i2c-designware-platdrv.c +3 -0
+static bool dw_i2c_hwmon_bus(void)
+{
 
+	const char *product_name = dmi_get_system_info(DMI_PRODUCT_NAME);

Split this, so the assignment will be attached to the check below.

drivers/i2c/busses/i2c-designware-platdrv.c static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) · line 185

Quoted 6 lines
drivers/i2c/busses/i2c-designware-platdrv.c +5 -0
+	if (!product_name)
+		return false;
+
 
+	if (strstr(product_name, "QT5222"))
+		return true;

I don't like this part at all. Why do you need strstr()? Can you provide in the commit message relevant fields from dmidecode (or sysfs)?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return false;
+}

In general it's not how we do DMI based quirks, rather using table and call match function. In that case you can take class as a driver_data. Much more flexible in case we need to extend.

...

drivers/i2c/busses/i2c-designware-platdrv.c static int dw_i2c_plat_probe(struct platform_device *pdev) · line 284

Quoted 2 lines
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
-	adap->class = I2C_CLASS_DEPRECATED;
+	adap->class = dw_i2c_hwmon_bus() ? I2C_CLASS_HWMON : I2C_CLASS_DEPRECATED;

...since the patch has it unconditionally, I would go unconditionally. But if Wolfram insists, then see above.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 11 lines · Andy Shevchenko
Quoted 7 lines · Ricardo Ribalda

Current AMD's zen-based APUs use this core for some of its i2c-buses.

With this patch we re-enable autodetection of hwmon-alike devices, so lm-sensors will be able to work automatically.

It does not affect the boot-time of embedded devices, as the class is set based on the dmi information.

I think it misses Fixes tag. And...

I don't think we have regression here. Commit 70fba8302ade ("i2c: i2c-designware-platdrv: Drop class based scanning to improve bootup time") was done before any of those AMD ACPI IDs were added.

Signature · 1 line
Jarkko
#3 lore raw
In reply to Ricardo Ribalda
Quoted 38 lines · Ricardo Ribalda

Current AMD's zen-based APUs use this core for some of its i2c-buses.

With this patch we re-enable autodetection of hwmon-alike devices, so lm-sensors will be able to work automatically.

It does not affect the boot-time of embedded devices, as the class is set based on the dmi information.

---
v2:
Changes by Andy Shevchenko <[email protected]>:
- CodeStyle
Changes by kernel test robot <[email protected]>
- Include dmi header to fix build error on arc
- check if dmi_get_system_info returned NULL

  drivers/i2c/busses/i2c-designware-platdrv.c | 16 +++++++++++++++-
  1 file changed, 15 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-platdrv.c +4 -0
index c2efaaaac252..5892fdba9c25 100644
@@ -12,6 +12,7 @@
  #include <linux/clk-provider.h>
  #include <linux/clk.h>
  #include <linux/delay.h>
+#include <linux/dmi.h>
  #include <linux/err.h>
  #include <linux/errno.h>
  #include <linux/i2c.h>
@@ -173,6 +174,19 @@ static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev)
  		pm_runtime_put_noidle(dev->dev);
  }
 
+static bool dw_i2c_hwmon_bus(void)
+{
+	const char *product_name = dmi_get_system_info(DMI_PRODUCT_NAME);

drivers/i2c/busses/i2c-designware-platdrv.c static void dw_i2c_plat_pm_cleanup(struct dw_i2c_dev *dev) · line 189

Quoted 10 lines
drivers/i2c/busses/i2c-designware-platdrv.c +10 -0
+
+	if (!product_name)
+		return false;
+
+	if (strstr(product_name, "QT5222"))
+		return true;
+
+	return false;
+}
+

I'm not too familiar with the DMI stuff but is the more usual way to have struct dmi_system_id table and match it with dmi_check_system()? Perhaps scales better than individual dmi_get_system_info() and string comparison calls.

Andy and I were pondering offline is there any info in ACPI table that tells which bus have these sensors or can it be hardcoded with the DMI match so that there is no need probe all buses for these sensors on that product. But that can be another optimization patch I guess.

Signature · 1 line
Jarkko