Skip to contentSkip to conversation

hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups

PATCH Applied Zev Weiss 3 participants 19 messages Sep 28, 2021 – Oct 8, 2021

Subsystems (3)
lore
Share & tools
lore

Zev Weiss

author
#0 lore raw

cover hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups

Hello,

I'm working with a board that uses LM25066s with sense resistor values significantly different than the 1mOhm assumed by the coefficients provided in the datasheet; the power and current readings produced by the existing driver are thus fairly inaccurate.

This patch series started out as merely adding support for a shunt-resistor-micro-ohms DT property as found in the adm1275 driver, but along the way I noticed a number of other minor bits in the lm25066 driver that looked like they could use some fixes, so I've included those as well.

Patches 1 and 2 bring the m/b/R coefficients in line with what's in the relevant datasheets, patches 3 through 5 are fairly generic (minor) code cleanups, and patches 6 through 8 add the desired OF support for the driver.

Thanks,
Zev

Zev Weiss (8):
hwmon: (pmbus/lm25066) Add offset coefficients
hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa
hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id
hwmon: (pmbus/lm25066) Let compiler determine outer dimension of

    lm25066_coeff

hwmon: (pmbus/lm25066) Mark lm25066_coeff array const
hwmon: (pmbus/lm25066) Add OF device ID table
hwmon: (pmbus/lm25066) Support configurable sense resistor values
dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC

 .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++
 Documentation/hwmon/lm25066.rst               |  2 +
 drivers/hwmon/pmbus/lm25066.c                 | 90 +++++++++++++++----
 3 files changed, 128 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
Signature · 1 line
2.33.0
author
#1 lore raw

PATCH 1/8 hwmon: (pmbus/lm25066) Add offset coefficients

With the exception of the lm5066i, all the devices handled by this driver had been missing their offset ('b') coefficients for direct format readings.

---
 drivers/hwmon/pmbus/lm25066.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/hwmon/pmbus/lm25066.c +23 -0
index d209e0afc2ca..1a660c4cd19f 100644
@@ -55,22 +55,27 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
+			.b = 1343,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 13797,
+			.b = -1833,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 6726,
+			.b = -537,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 5501,
+			.b = -2908,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 26882,
+			.b = -5646,
 			.R = -4,
 		},
 		[PSC_TEMPERATURE] = {
@@ -82,26 +87,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm25066] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 22070,
+			.b = -1800,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 22070,
+			.b = -1800,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 13661,
+			.b = -5200,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 6852,
+			.b = -3100,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 736,
+			.b = -3300,
 			.R = -2,
 		},
 		[PSC_POWER_L] = {
 			.m = 369,
+			.b = -1900,
 			.R = -2,
 		},
 		[PSC_TEMPERATURE] = {
@@ -111,26 +122,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm5064] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 4611,
+			.b = -642,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 4621,
+			.b = 423,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 10742,
+			.b = 1552,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 5456,
+			.b = 2118,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 1204,
+			.b = 8524,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 612,
+			.b = 11202,
 			.R = -3,
 		},
 		[PSC_TEMPERATURE] = {
@@ -140,26 +157,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm5066] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 4587,
+			.b = -1200,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 4587,
+			.b = -2400,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 10753,
+			.b = -1200,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 5405,
+			.b = -600,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 1204,
+			.b = -6000,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 605,
+			.b = -8000,
 			.R = -3,
 		},
 		[PSC_TEMPERATURE] = {
Signature · 1 line
2.33.0
maintainer Applied
#2 lore raw

Re: [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients

Quoted 5 lines · Zev Weiss

With the exception of the lm5066i, all the devices handled by this driver had been missing their offset ('b') coefficients for direct format readings.

Applied.

Thanks,
Guenter

Quoted 135 lines
---
 drivers/hwmon/pmbus/lm25066.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
drivers/hwmon/pmbus/lm25066.c +23 -0
index d209e0afc2ca..1a660c4cd19f 100644
@@ -55,22 +55,27 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
+			.b = 1343,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 13797,
+			.b = -1833,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 6726,
+			.b = -537,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 5501,
+			.b = -2908,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 26882,
+			.b = -5646,
 			.R = -4,
 		},
 		[PSC_TEMPERATURE] = {
@@ -82,26 +87,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm25066] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 22070,
+			.b = -1800,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 22070,
+			.b = -1800,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 13661,
+			.b = -5200,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 6852,
+			.b = -3100,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 736,
+			.b = -3300,
 			.R = -2,
 		},
 		[PSC_POWER_L] = {
 			.m = 369,
+			.b = -1900,
 			.R = -2,
 		},
 		[PSC_TEMPERATURE] = {
@@ -111,26 +122,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm5064] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 4611,
+			.b = -642,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 4621,
+			.b = 423,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 10742,
+			.b = 1552,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 5456,
+			.b = 2118,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 1204,
+			.b = 8524,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 612,
+			.b = 11202,
 			.R = -3,
 		},
 		[PSC_TEMPERATURE] = {
@@ -140,26 +157,32 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 	[lm5066] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 4587,
+			.b = -1200,
 			.R = -2,
 		},
 		[PSC_VOLTAGE_OUT] = {
 			.m = 4587,
+			.b = -2400,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN] = {
 			.m = 10753,
+			.b = -1200,
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
 			.m = 5405,
+			.b = -600,
 			.R = -2,
 		},
 		[PSC_POWER] = {
 			.m = 1204,
+			.b = -6000,
 			.R = -3,
 		},
 		[PSC_POWER_L] = {
 			.m = 605,
+			.b = -8000,
 			.R = -3,
 		},
 		[PSC_TEMPERATURE] = {
author
#3 lore raw

PATCH 2/8 hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa

In reply to Zev Weiss

At least as of Revision J, the datasheet has a slightly different value than what we'd had in the driver.

---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/lm25066.c +1 -1
index 1a660c4cd19f..3616705aafde 100644
@@ -101,7 +101,7 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
-			.m = 6852,
+			.m = 6854,
 			.b = -3100,
 			.R = -2,
 		},
Signature · 1 line
2.33.0
maintainer Applied
#4 lore raw

Re: [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa

Quoted 3 lines · Zev Weiss

At least as of Revision J, the datasheet has a slightly different value than what we'd had in the driver.

Indeeed, it does.

Quoted 1 line

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/lm25066.c +1 -1
index 1a660c4cd19f..3616705aafde 100644
@@ -101,7 +101,7 @@ static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
 			.R = -2,
 		},
 		[PSC_CURRENT_IN_L] = {
-			.m = 6852,
+			.m = 6854,
 			.b = -3100,
 			.R = -2,
 		},
author
#5 lore raw

PATCH 3/8 hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id

In reply to Zev Weiss

Reordering things to put the table before the probe function eliminates the need for it.

---
 drivers/hwmon/pmbus/lm25066.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/hwmon/pmbus/lm25066.c +10 -13
index 3616705aafde..4dc003ff859e 100644
@@ -234,8 +234,6 @@ struct lm25066_data {
 
 #define to_lm25066_data(x)  container_of(x, struct lm25066_data, info)
 
-static const struct i2c_device_id lm25066_id[];
-
 static int lm25066_read_word_data(struct i2c_client *client, int page,
 				  int phase, int reg)
 {
@@ -436,6 +434,16 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 	return ret;
 }
 
+static const struct i2c_device_id lm25066_id[] = {
+	{"lm25056", lm25056},
+	{"lm25066", lm25066},
+	{"lm5064", lm5064},
+	{"lm5066", lm5066},
+	{"lm5066i", lm5066i},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, lm25066_id);
+
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
@@ -509,17 +517,6 @@ static int lm25066_probe(struct i2c_client *client)
 	return pmbus_do_probe(client, info);
 }
 
-static const struct i2c_device_id lm25066_id[] = {
-	{"lm25056", lm25056},
-	{"lm25066", lm25066},
-	{"lm5064", lm5064},
-	{"lm5066", lm5066},
-	{"lm5066i", lm5066i},
-	{ }
-};
-
-MODULE_DEVICE_TABLE(i2c, lm25066_id);
-
 /* This is the driver that will be inserted */
 static struct i2c_driver lm25066_driver = {
 	.driver = {
Signature · 1 line
2.33.0
maintainer Applied
#6 lore raw

Re: [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id

Quoted 4 lines · Zev Weiss

Reordering things to put the table before the probe function eliminates the need for it.

Applied.

Thanks,
Guenter

Quoted 52 lines
---
 drivers/hwmon/pmbus/lm25066.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)
drivers/hwmon/pmbus/lm25066.c +10 -13
index 3616705aafde..4dc003ff859e 100644
@@ -234,8 +234,6 @@ struct lm25066_data {
 
 #define to_lm25066_data(x)  container_of(x, struct lm25066_data, info)
 
-static const struct i2c_device_id lm25066_id[];
-
 static int lm25066_read_word_data(struct i2c_client *client, int page,
 				  int phase, int reg)
 {
@@ -436,6 +434,16 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
 	return ret;
 }
 
+static const struct i2c_device_id lm25066_id[] = {
+	{"lm25056", lm25056},
+	{"lm25066", lm25066},
+	{"lm5064", lm5064},
+	{"lm5066", lm5066},
+	{"lm5066i", lm5066i},
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, lm25066_id);
+
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
@@ -509,17 +517,6 @@ static int lm25066_probe(struct i2c_client *client)
 	return pmbus_do_probe(client, info);
 }
 
-static const struct i2c_device_id lm25066_id[] = {
-	{"lm25056", lm25056},
-	{"lm25066", lm25066},
-	{"lm5064", lm5064},
-	{"lm5066", lm5066},
-	{"lm5066i", lm5066i},
-	{ }
-};
-
-MODULE_DEVICE_TABLE(i2c, lm25066_id);
-
 /* This is the driver that will be inserted */
 static struct i2c_driver lm25066_driver = {
 	.driver = {
author
#7 lore raw

PATCH 4/8 hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff

In reply to Zev Weiss

Maintaining this manually is error prone (there are currently only five chips supported, not six); gcc can do it for us automatically.

Fixes 666c14906b49 ("hwmon: (pmbus/lm25066) Drop support for LM25063")
---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/lm25066.c +1 -1
index 4dc003ff859e..1ff5407b6977 100644
@@ -51,7 +51,7 @@ struct __coeff {
 #define PSC_CURRENT_IN_L	(PSC_NUM_CLASSES)
 #define PSC_POWER_L		(PSC_NUM_CLASSES + 1)
 
-static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
+static struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
Signature · 1 line
2.33.0
maintainer Applied
#8 lore raw

Re: [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff

Quoted 5 lines · Zev Weiss

Maintaining this manually is error prone (there are currently only five chips supported, not six); gcc can do it for us automatically.

Fixes 666c14906b49 ("hwmon: (pmbus/lm25066) Drop support for LM25063")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/pmbus/lm25066.c +1 -1
index 4dc003ff859e..1ff5407b6977 100644
@@ -51,7 +51,7 @@ struct __coeff {
 #define PSC_CURRENT_IN_L	(PSC_NUM_CLASSES)
 #define PSC_POWER_L		(PSC_NUM_CLASSES + 1)
 
-static struct __coeff lm25066_coeff[6][PSC_NUM_CLASSES + 2] = {
+static struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
author
#9 lore raw

PATCH 5/8 hwmon: (pmbus/lm25066) Mark lm25066_coeff array const

In reply to Zev Weiss
---
 drivers/hwmon/pmbus/lm25066.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/lm25066.c +2 -2
index 1ff5407b6977..dbbf8571c437 100644
@@ -51,7 +51,7 @@ struct __coeff {
 #define PSC_CURRENT_IN_L	(PSC_NUM_CLASSES)
 #define PSC_POWER_L		(PSC_NUM_CLASSES + 1)
 
-static struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
+static const struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
@@ -449,7 +449,7 @@ static int lm25066_probe(struct i2c_client *client)
 	int config;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
-	struct __coeff *coeff;
+	const struct __coeff *coeff;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA))
Signature · 1 line
2.33.0
maintainer Applied
#10 lore raw

Re: [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const

On Tue, Sep 28, 2021 at 02:22:39AM -0700, Zev Weiss wrote:

Commit description goes here.

Quoted 1 line

Applied.

Thanks,
Guenter

Quoted 26 lines
---
 drivers/hwmon/pmbus/lm25066.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/lm25066.c +2 -2
index 1ff5407b6977..dbbf8571c437 100644
@@ -51,7 +51,7 @@ struct __coeff {
 #define PSC_CURRENT_IN_L	(PSC_NUM_CLASSES)
 #define PSC_POWER_L		(PSC_NUM_CLASSES + 1)
 
-static struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
+static const struct __coeff lm25066_coeff[][PSC_NUM_CLASSES + 2] = {
 	[lm25056] = {
 		[PSC_VOLTAGE_IN] = {
 			.m = 16296,
@@ -449,7 +449,7 @@ static int lm25066_probe(struct i2c_client *client)
 	int config;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
-	struct __coeff *coeff;
+	const struct __coeff *coeff;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA))
author
#11 lore raw

PATCH 6/8 hwmon: (pmbus/lm25066) Add OF device ID table

In reply to Zev Weiss

See commit 8881a19187e4 ("hwmon: (ucd9000) Add OF device ID table") for reasoning.

---
 drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/lm25066.c +24 -2
index dbbf8571c437..18d5a76f346d 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/log2.h>
+#include <linux/of_device.h>
 #include "pmbus.h"
 
 enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };
@@ -444,12 +445,24 @@ static const struct i2c_device_id lm25066_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, lm25066_id);
 
+static const struct of_device_id __maybe_unused lm25066_of_match[] = {
+	{ .compatible = "ti,lm25056", .data = (void*)lm25056, },
+	{ .compatible = "ti,lm25066", .data = (void*)lm25066, },
+	{ .compatible = "ti,lm5064",  .data = (void*)lm5064,  },
+	{ .compatible = "ti,lm5066",  .data = (void*)lm5066,  },
+	{ .compatible = "ti,lm5066i", .data = (void*)lm5066i, },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, lm25066_of_match);
+
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
 	const struct __coeff *coeff;
+	const struct of_device_id *of_id;
+	const struct i2c_device_id *i2c_id;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA))
@@ -464,7 +477,15 @@ static int lm25066_probe(struct i2c_client *client)
 	if (config < 0)
 		return config;
 
-	data->id = i2c_match_id(lm25066_id, client)->driver_data;
+	i2c_id = i2c_match_id(lm25066_id, client);
+
+	of_id = of_match_device(lm25066_of_match, &client->dev);
+	if (of_id && (enum chips)of_id->data != i2c_id->driver_data)
+		dev_notice(&client->dev,
+		           "Device mismatch: %s in device tree, %s detected\n",
+		           of_id->name, i2c_id->name);
+
+	data->id = i2c_id->driver_data;
 	info = &data->info;
 
 	info->pages = 1;
@@ -521,7 +542,8 @@ static int lm25066_probe(struct i2c_client *client)
 static struct i2c_driver lm25066_driver = {
 	.driver = {
 		   .name = "lm25066",
-		   },
+		   .of_match_table = of_match_ptr(lm25066_of_match),
+	},
 	.probe_new = lm25066_probe,
 	.id_table = lm25066_id,
 };
Signature · 1 line
2.33.0
maintainer Applied
#12 lore raw

Re: [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table

Quoted 3 lines · Zev Weiss

See commit 8881a19187e4 ("hwmon: (ucd9000) Add OF device ID table") for reasoning.

The actual reasoning should be provided here, not a reference to another commit. Never mind, I did that.

Quoted 1 line

Applied.

Thanks,
Guenter

Quoted 68 lines
---
 drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/lm25066.c +24 -2
index dbbf8571c437..18d5a76f346d 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/log2.h>
+#include <linux/of_device.h>
 #include "pmbus.h"
 
 enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };
@@ -444,12 +445,24 @@ static const struct i2c_device_id lm25066_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, lm25066_id);
 
+static const struct of_device_id __maybe_unused lm25066_of_match[] = {
+	{ .compatible = "ti,lm25056", .data = (void*)lm25056, },
+	{ .compatible = "ti,lm25066", .data = (void*)lm25066, },
+	{ .compatible = "ti,lm5064",  .data = (void*)lm5064,  },
+	{ .compatible = "ti,lm5066",  .data = (void*)lm5066,  },
+	{ .compatible = "ti,lm5066i", .data = (void*)lm5066i, },
+	{ },
+};
+MODULE_DEVICE_TABLE(of, lm25066_of_match);
+
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
 	const struct __coeff *coeff;
+	const struct of_device_id *of_id;
+	const struct i2c_device_id *i2c_id;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA))
@@ -464,7 +477,15 @@ static int lm25066_probe(struct i2c_client *client)
 	if (config < 0)
 		return config;
 
-	data->id = i2c_match_id(lm25066_id, client)->driver_data;
+	i2c_id = i2c_match_id(lm25066_id, client);
+
+	of_id = of_match_device(lm25066_of_match, &client->dev);
+	if (of_id && (enum chips)of_id->data != i2c_id->driver_data)
+		dev_notice(&client->dev,
+		           "Device mismatch: %s in device tree, %s detected\n",
+		           of_id->name, i2c_id->name);
+
+	data->id = i2c_id->driver_data;
 	info = &data->info;
 
 	info->pages = 1;
@@ -521,7 +542,8 @@ static int lm25066_probe(struct i2c_client *client)
 static struct i2c_driver lm25066_driver = {
 	.driver = {
 		   .name = "lm25066",
-		   },
+		   .of_match_table = of_match_ptr(lm25066_of_match),
+	},
 	.probe_new = lm25066_probe,
 	.id_table = lm25066_id,
 };
maintainer
#13 lore raw

Re: [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table

In reply to Zev Weiss
Quoted 21 lines · Zev Weiss

See commit 8881a19187e4 ("hwmon: (ucd9000) Add OF device ID table") for reasoning.

---
 drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)
drivers/hwmon/pmbus/lm25066.c +1 -0
index dbbf8571c437..18d5a76f346d 100644
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/log2.h>
+#include <linux/of_device.h>
 #include "pmbus.h"
 
 enum chips { lm25056, lm25066, lm5064, lm5066, lm5066i };

drivers/hwmon/pmbus/lm25066.c static const struct i2c_device_id lm25066_id[] = { · line 453

Quoted 9 lines
drivers/hwmon/pmbus/lm25066.c +6 -0
@@ -444,12 +445,24 @@ static const struct i2c_device_id lm25066_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, lm25066_id);
 
+static const struct of_device_id __maybe_unused lm25066_of_match[] = {
+	{ .compatible = "ti,lm25056", .data = (void*)lm25056, },
+	{ .compatible = "ti,lm25066", .data = (void*)lm25066, },
+	{ .compatible = "ti,lm5064",  .data = (void*)lm5064,  },
+	{ .compatible = "ti,lm5066",  .data = (void*)lm5066,  },
+	{ .compatible = "ti,lm5066i", .data = (void*)lm5066i, },

On a side note, you got lazy here. Should be "void *".

Quoted 17 lines
drivers/hwmon/pmbus/lm25066.c +6 -0
+	{ },
+};
+MODULE_DEVICE_TABLE(of, lm25066_of_match);
+
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
 	const struct __coeff *coeff;
+	const struct of_device_id *of_id;
+	const struct i2c_device_id *i2c_id;
 
 	if (!i2c_check_functionality(client->adapter,
 				     I2C_FUNC_SMBUS_READ_BYTE_DATA))
@@ -464,7 +477,15 @@ static int lm25066_probe(struct i2c_client *client)
 	if (config < 0)

drivers/hwmon/pmbus/lm25066.c static int lm25066_probe(struct i2c_client *client) · line 486

Quoted 10 lines
drivers/hwmon/pmbus/lm25066.c +7 -1
 		return config;
 
-	data->id = i2c_match_id(lm25066_id, client)->driver_data;
+	i2c_id = i2c_match_id(lm25066_id, client);
+
+	of_id = of_match_device(lm25066_of_match, &client->dev);
+	if (of_id && (enum chips)of_id->data != i2c_id->driver_data)
+		dev_notice(&client->dev,
+		           "Device mismatch: %s in device tree, %s detected\n",
+		           of_id->name, i2c_id->name);

Also, this used spaces instead of tabs for indentation.

Never mind, I fixed it up. But please run checkpatch on your patches.

Guenter

Quoted 15 lines
drivers/hwmon/pmbus/lm25066.c +4 -1
+
+	data->id = i2c_id->driver_data;
 	info = &data->info;
 
 	info->pages = 1;
@@ -521,7 +542,8 @@ static int lm25066_probe(struct i2c_client *client)
 static struct i2c_driver lm25066_driver = {
 	.driver = {
 		   .name = "lm25066",
-		   },
+		   .of_match_table = of_match_ptr(lm25066_of_match),
+	},
 	.probe_new = lm25066_probe,
 	.id_table = lm25066_id,
 };
author
#14 lore raw

PATCH 7/8 hwmon: (pmbus/lm25066) Support configurable sense resistor values

In reply to Zev Weiss

The appropriate mantissa values for the lm25066 family's direct-format current and power readings are a function of the sense resistor employed between the SENSE and VIN pins of the chip. Instead of assuming that resistance is always the same 1mOhm as used in the datasheet, allow it to be configured via a device-tree property ("shunt-resistor-micro-ohms").

---
 Documentation/hwmon/lm25066.rst |  2 ++
 drivers/hwmon/pmbus/lm25066.c   | 12 ++++++++++++
 2 files changed, 14 insertions(+)
Documentation/hwmon/lm25066.rst +2 -0
index 9f1d7e4d3ca1..a2098eb24090 100644
@@ -79,6 +79,8 @@ This driver does not auto-detect devices. You will have to instantiate the
 devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
 details.
 
+The shunt (sense) resistor value can be configured by a device tree property;
+see Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml for details.
 
 Platform data support
 ---------------------
drivers/hwmon/pmbus/lm25066.c +12 -0
index 18d5a76f346d..29e848bcd436 100644
@@ -458,6 +458,7 @@ MODULE_DEVICE_TABLE(of, lm25066_of_match);
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
+	u32 shunt;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
 	const struct __coeff *coeff;
@@ -535,6 +536,17 @@ static int lm25066_probe(struct i2c_client *client)
 		info->b[PSC_POWER] = coeff[PSC_POWER].b;
 	}
 
+	/*
+	 * Values in the TI datasheets are normalized for a 1mOhm sense
+	 * resistor; assume that unless DT specifies a value explicitly.
+	 */
+	if (of_property_read_u32(client->dev.of_node,
+	                         "shunt-resistor-micro-ohms", &shunt))
+		shunt = 1000;
+
+	info->m[PSC_CURRENT_IN] = info->m[PSC_CURRENT_IN] * shunt / 1000;
+	info->m[PSC_POWER] = info->m[PSC_POWER] * shunt / 1000;
+
 	return pmbus_do_probe(client, info);
 }
 
Signature · 1 line
2.33.0
maintainer
#15 lore raw

Re: [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values

Quoted 39 lines · Zev Weiss

The appropriate mantissa values for the lm25066 family's direct-format current and power readings are a function of the sense resistor employed between the SENSE and VIN pins of the chip. Instead of assuming that resistance is always the same 1mOhm as used in the datasheet, allow it to be configured via a device-tree property ("shunt-resistor-micro-ohms").

---
 Documentation/hwmon/lm25066.rst |  2 ++
 drivers/hwmon/pmbus/lm25066.c   | 12 ++++++++++++
 2 files changed, 14 insertions(+)
Documentation/hwmon/lm25066.rst +2 -0
index 9f1d7e4d3ca1..a2098eb24090 100644
@@ -79,6 +79,8 @@ This driver does not auto-detect devices. You will have to instantiate the
 devices explicitly. Please see Documentation/i2c/instantiating-devices.rst for
 details.
 
+The shunt (sense) resistor value can be configured by a device tree property;
+see Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml for details.
 
 Platform data support
 ---------------------
drivers/hwmon/pmbus/lm25066.c +1 -0
index 18d5a76f346d..29e848bcd436 100644
@@ -458,6 +458,7 @@ MODULE_DEVICE_TABLE(of, lm25066_of_match);
 static int lm25066_probe(struct i2c_client *client)
 {
 	int config;
+	u32 shunt;
 	struct lm25066_data *data;
 	struct pmbus_driver_info *info;
 	const struct __coeff *coeff;

drivers/hwmon/pmbus/lm25066.c static int lm25066_probe(struct i2c_client *client) · line 544

Quoted 9 lines
drivers/hwmon/pmbus/lm25066.c +6 -0
@@ -535,6 +536,17 @@ static int lm25066_probe(struct i2c_client *client)
 		info->b[PSC_POWER] = coeff[PSC_POWER].b;
 	}
 
+	/*
+	 * Values in the TI datasheets are normalized for a 1mOhm sense
+	 * resistor; assume that unless DT specifies a value explicitly.
+	 */
+	if (of_property_read_u32(client->dev.of_node,
+	                         "shunt-resistor-micro-ohms", &shunt))

Space vs. tabs again. Never mind, fixed up and applied.

Thanks,
Guenter

Quoted 8 lines
drivers/hwmon/pmbus/lm25066.c +5 -0
+		shunt = 1000;
+
+	info->m[PSC_CURRENT_IN] = info->m[PSC_CURRENT_IN] * shunt / 1000;
+	info->m[PSC_POWER] = info->m[PSC_POWER] * shunt / 1000;
+
 	return pmbus_do_probe(client, info);
 }
 
author
#16 lore raw

PATCH 8/8 dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC

In reply to Zev Weiss
---
 .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml new file +54 -0
new file mode 100644
index 000000000000..da8292bc32f5
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/pmbus/ti,lm25066.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: National Semiconductor/Texas Instruments LM250x6/LM506x power-management ICs
+
+maintainers:
+  - Zev Weiss <[email protected]>
+
+description: |
+  The LM25066 family of power-management ICs (a.k.a. hot-swap
+  controllers or eFuses in various contexts) are PMBus devices that
+  offer temperature, current, voltage, and power monitoring.
+
+  Datasheet: https://www.ti.com/lit/ds/symlink/lm25066.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,lm25056
+      - ti,lm25066
+      - ti,lm5064
+      - ti,lm5066
+      - ti,lm5066i
+
+  reg:
+    maxItems: 1
+
+  shunt-resistor-micro-ohms:
+    description:
+      Shunt (sense) resistor value in micro-Ohms
+    default: 1000
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@40 {
+            compatible = "ti,lm25066";
+            reg = <0x40>;
+            shunt-resistor-micro-ohms = <675>;
+        };
+    };
Signature · 1 line
2.33.0
maintainer Reviewed-by on v1 8/8
#17 lore raw

Re: [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC

Quoted 6 lines · Zev Weiss
---
 .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
maintainer Applied
#18 lore raw

Re: [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC

In reply to Zev Weiss
Quoted 2 lines · Zev Weiss

Applied.

Thanks,
Guenter

Quoted 65 lines
---
 .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml new file +54 -0
new file mode 100644
index 000000000000..da8292bc32f5
@@ -0,0 +1,54 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+
+$id: http://devicetree.org/schemas/hwmon/pmbus/ti,lm25066.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: National Semiconductor/Texas Instruments LM250x6/LM506x power-management ICs
+
+maintainers:
+  - Zev Weiss <[email protected]>
+
+description: |
+  The LM25066 family of power-management ICs (a.k.a. hot-swap
+  controllers or eFuses in various contexts) are PMBus devices that
+  offer temperature, current, voltage, and power monitoring.
+
+  Datasheet: https://www.ti.com/lit/ds/symlink/lm25066.pdf
+
+properties:
+  compatible:
+    enum:
+      - ti,lm25056
+      - ti,lm25066
+      - ti,lm5064
+      - ti,lm5066
+      - ti,lm5066i
+
+  reg:
+    maxItems: 1
+
+  shunt-resistor-micro-ohms:
+    description:
+      Shunt (sense) resistor value in micro-Ohms
+    default: 1000
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pmic@40 {
+            compatible = "ti,lm25066";
+            reg = <0x40>;
+            shunt-resistor-micro-ohms = <675>;
+        };
+    };