Skip to contentSkip to conversation

hwmon: (lm77) Provide of_match_table to allow module auto loading

PATCH In review Lukasz Majewski 3 participants 3 messages Nov 13 – Nov 14 Hardware monitoring

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hwmon: (lm77) Provide of_match_table to allow module auto loading

When lm77 is built as a module and it is properly described in the board's DTS file (i.e. with proper compatible) it is required to have the in-driver compatible definition as well to allow automatic loading of it.

Up till now the lm77 used I2C discovery fallback routine to bind it with its name.

---
 drivers/hwmon/lm77.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/hwmon/lm77.c +7 -0
index 1f8402be599c..440dd91de39d 100644
@@ -336,6 +336,12 @@ static int lm77_probe(struct i2c_client *client)
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
+static const struct of_device_id lm77_of_match[] = {
+	{ .compatible = "national,lm77" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lm77_of_match);
+
 static const struct i2c_device_id lm77_id[] = {
 	{ .name = "lm77" },
 	{ }
@@ -347,6 +353,7 @@ static struct i2c_driver lm77_driver = {
 	.class		= I2C_CLASS_HWMON,
 	.driver = {
 		.name	= "lm77",
+		.of_match_table = lm77_of_match,
 	},
 	.probe		= lm77_probe,
 	.id_table	= lm77_id,
Signature · 1 line
2.47.3
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] hwmon: (lm77) Undocumented DT compatible string national,lm77 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] hwmon: (lm77) Undocumented DT compatible string national,lm77 --

commit 9ee0f69ba3227a960f104981995c86d2458362e9
Author: Lukasz Majewski <[email protected]>

hwmon: (lm77) Provide of_match_table to allow module auto loading

This commit adds an OF match table for "national,lm77" to the lm77 I2C driver to enable automatic module loading on Devicetree systems.

drivers/hwmon/lm77.c static int lm77_probe(struct i2c_client *client) · line 342

Quoted 12 lines
drivers/hwmon/lm77.c +4 -0
index 51bbc84d74844..e64dabfcda09e 100644
@@ -336,6 +336,12 @@ static int lm77_probe(struct i2c_client *client)
 	return PTR_ERR_OR_ZERO(hwmon_dev);
 }
 
+static const struct of_device_id lm77_of_match[] = {
+	{ .compatible = "national,lm77" },
+	{ }
+};

[Severity: Low]
Is "national,lm77" documented in the Devicetree bindings? It does not appear in Documentation/devicetree/bindings/ (such as in Documentation/devicetree/bindings/trivial-devices.yaml alongside other National Semiconductor I2C sensors), which causes checkpatch.pl to warn about an undocumented DT compatible string and dtbs_check to fail on nodes using it.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#2 lore raw
In reply to Lukasz Majewski
Quoted 18 lines · Lukasz Majewski

When lm77 is built as a module and it is properly described in the board's DTS file (i.e. with proper compatible) it is required to have the in-driver compatible definition as well to allow automatic loading of it.

Up till now the lm77 used I2C discovery fallback routine to bind it with its name.

---
  drivers/hwmon/lm77.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/hwmon/lm77.c +0 -0
index 1f8402be599c..440dd91de39d 100644

drivers/hwmon/lm77.c static int lm77_probe(struct i2c_client *client) · line 339

Quoted 4 lines
drivers/hwmon/lm77.c +1 -0
@@ -336,6 +336,12 @@ static int lm77_probe(struct i2c_client *client)
  	return PTR_ERR_OR_ZERO(hwmon_dev);
  }
 
+static const struct of_device_id lm77_of_match[] = {

Requires "#include linux/mod_devicetable.h"

Guenter

Quoted 16 lines
drivers/hwmon/lm77.c +6 -0
+	{ .compatible = "national,lm77" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lm77_of_match);
+
  static const struct i2c_device_id lm77_id[] = {
  	{ .name = "lm77" },
  	{ }
@@ -347,6 +353,7 @@ static struct i2c_driver lm77_driver = {
  	.class		= I2C_CLASS_HWMON,
  	.driver = {
  		.name	= "lm77",
+		.of_match_table = lm77_of_match,
  	},
  	.probe		= lm77_probe,
  	.id_table	= lm77_id,