All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups
@ 2021-09-28  9:22 Zev Weiss
  2021-09-28  9:22 ` [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
                   ` (7 more replies)
  0 siblings, 8 replies; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel,
	Jonathan Corbet, linux-doc, Rob Herring, devicetree

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

-- 
2.33.0


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:37   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/hwmon/pmbus/lm25066.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index d209e0afc2ca..1a660c4cd19f 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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] = {
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
  2021-09-28  9:22 ` [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:46   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
                   ` (5 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 1a660c4cd19f..3616705aafde 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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,
 		},
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
  2021-09-28  9:22 ` [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
  2021-09-28  9:22 ` [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:47   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/hwmon/pmbus/lm25066.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 3616705aafde..4dc003ff859e 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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 = {
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (2 preceding siblings ...)
  2021-09-28  9:22 ` [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:47   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Fixes: 666c14906b49 ("hwmon: (pmbus/lm25066) Drop support for LM25063")
---
 drivers/hwmon/pmbus/lm25066.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 4dc003ff859e..1ff5407b6977 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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,
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (3 preceding siblings ...)
  2021-09-28  9:22 ` [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:49   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/hwmon/pmbus/lm25066.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 1ff5407b6977..dbbf8571c437 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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))
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (4 preceding siblings ...)
  2021-09-28  9:22 ` [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 13:52   ` Guenter Roeck
  2021-10-08 13:59   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
  2021-09-28  9:22 ` [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC Zev Weiss
  7 siblings, 2 replies; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Zev Weiss, Jean Delvare, linux-hwmon, linux-kernel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index dbbf8571c437..18d5a76f346d 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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,
 };
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (5 preceding siblings ...)
  2021-09-28  9:22 ` [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-08 14:03   ` Guenter Roeck
  2021-09-28  9:22 ` [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC Zev Weiss
  7 siblings, 1 reply; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Zev Weiss, Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc,
	linux-kernel

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").

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 Documentation/hwmon/lm25066.rst |  2 ++
 drivers/hwmon/pmbus/lm25066.c   | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/Documentation/hwmon/lm25066.rst b/Documentation/hwmon/lm25066.rst
index 9f1d7e4d3ca1..a2098eb24090 100644
--- a/Documentation/hwmon/lm25066.rst
+++ b/Documentation/hwmon/lm25066.rst
@@ -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
 ---------------------
diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index 18d5a76f346d..29e848bcd436 100644
--- a/drivers/hwmon/pmbus/lm25066.c
+++ b/drivers/hwmon/pmbus/lm25066.c
@@ -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);
 }
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC
  2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (6 preceding siblings ...)
  2021-09-28  9:22 ` [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
@ 2021-09-28  9:22 ` Zev Weiss
  2021-10-04 18:28   ` Rob Herring
  2021-10-08 14:05   ` Guenter Roeck
  7 siblings, 2 replies; 19+ messages in thread
From: Zev Weiss @ 2021-09-28  9:22 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Zev Weiss, Jean Delvare, Rob Herring, linux-hwmon, devicetree,
	linux-kernel

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml

diff --git a/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml b/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
new file mode 100644
index 000000000000..da8292bc32f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
@@ -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 <zev@bewilderbeest.net>
+
+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>;
+        };
+    };
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC
  2021-09-28  9:22 ` [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC Zev Weiss
@ 2021-10-04 18:28   ` Rob Herring
  2021-10-08 14:05   ` Guenter Roeck
  1 sibling, 0 replies; 19+ messages in thread
From: Rob Herring @ 2021-10-04 18:28 UTC (permalink / raw)
  To: Zev Weiss
  Cc: Rob Herring, devicetree, linux-kernel, Guenter Roeck,
	linux-hwmon, Jean Delvare

On Tue, 28 Sep 2021 02:22:42 -0700, Zev Weiss wrote:
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> ---
>  .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
>  1 file changed, 54 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
> 

Reviewed-by: Rob Herring <robh@kernel.org>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients
  2021-09-28  9:22 ` [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
@ 2021-10-08 13:37   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:37 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:35AM -0700, Zev Weiss wrote:
> With the exception of the lm5066i, all the devices handled by this
> driver had been missing their offset ('b') coefficients for direct
> format readings.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index d209e0afc2ca..1a660c4cd19f 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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] = {

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa
  2021-09-28  9:22 ` [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
@ 2021-10-08 13:46   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:46 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:36AM -0700, Zev Weiss wrote:
> At least as of Revision J, the datasheet has a slightly different
> value than what we'd had in the driver.
> 
Indeeed, it does.

> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index 1a660c4cd19f..3616705aafde 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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,
>  		},

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id
  2021-09-28  9:22 ` [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
@ 2021-10-08 13:47   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:47 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:37AM -0700, Zev Weiss wrote:
> Reordering things to put the table before the probe function
> eliminates the need for it.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 23 ++++++++++-------------
>  1 file changed, 10 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index 3616705aafde..4dc003ff859e 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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 = {

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff
  2021-09-28  9:22 ` [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
@ 2021-10-08 13:47   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:47 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:38AM -0700, Zev Weiss wrote:
> Maintaining this manually is error prone (there are currently only
> five chips supported, not six); gcc can do it for us automatically.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> Fixes: 666c14906b49 ("hwmon: (pmbus/lm25066) Drop support for LM25063")

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index 4dc003ff859e..1ff5407b6977 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const
  2021-09-28  9:22 ` [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
@ 2021-10-08 13:49   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:49 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

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

Commit description goes here.

> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Applied. 

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index 1ff5407b6977..dbbf8571c437 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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))

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table
  2021-09-28  9:22 ` [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
@ 2021-10-08 13:52   ` Guenter Roeck
  2021-10-08 13:59   ` Guenter Roeck
  1 sibling, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:52 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:40AM -0700, Zev Weiss wrote:
> 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.

> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>

Applied.

Thanks,
Guenter

> ---
>  drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index dbbf8571c437..18d5a76f346d 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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,
>  };

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table
  2021-09-28  9:22 ` [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
  2021-10-08 13:52   ` Guenter Roeck
@ 2021-10-08 13:59   ` Guenter Roeck
  1 sibling, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 13:59 UTC (permalink / raw)
  To: Zev Weiss; +Cc: Jean Delvare, linux-hwmon, linux-kernel

On Tue, Sep 28, 2021 at 02:22:40AM -0700, Zev Weiss wrote:
> See commit 8881a19187e4 ("hwmon: (ucd9000) Add OF device ID table")
> for reasoning.
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> ---
>  drivers/hwmon/pmbus/lm25066.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index dbbf8571c437..18d5a76f346d 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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, },

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

> +	{ },
> +};
> +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);

Also, this used spaces instead of tabs for indentation.

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

Guenter

> +
> +	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,
>  };

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values
  2021-09-28  9:22 ` [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
@ 2021-10-08 14:03   ` Guenter Roeck
  0 siblings, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 14:03 UTC (permalink / raw)
  To: Zev Weiss
  Cc: Jean Delvare, Jonathan Corbet, linux-hwmon, linux-doc, linux-kernel

On Tue, Sep 28, 2021 at 02:22:41AM -0700, Zev Weiss wrote:
> 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").
> 
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> ---
>  Documentation/hwmon/lm25066.rst |  2 ++
>  drivers/hwmon/pmbus/lm25066.c   | 12 ++++++++++++
>  2 files changed, 14 insertions(+)
> 
> diff --git a/Documentation/hwmon/lm25066.rst b/Documentation/hwmon/lm25066.rst
> index 9f1d7e4d3ca1..a2098eb24090 100644
> --- a/Documentation/hwmon/lm25066.rst
> +++ b/Documentation/hwmon/lm25066.rst
> @@ -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
>  ---------------------
> diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
> index 18d5a76f346d..29e848bcd436 100644
> --- a/drivers/hwmon/pmbus/lm25066.c
> +++ b/drivers/hwmon/pmbus/lm25066.c
> @@ -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))

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

Thanks,
Guenter

> +		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);
>  }
>  

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC
  2021-09-28  9:22 ` [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC Zev Weiss
  2021-10-04 18:28   ` Rob Herring
@ 2021-10-08 14:05   ` Guenter Roeck
  1 sibling, 0 replies; 19+ messages in thread
From: Guenter Roeck @ 2021-10-08 14:05 UTC (permalink / raw)
  To: Zev Weiss
  Cc: Jean Delvare, Rob Herring, linux-hwmon, devicetree, linux-kernel

On Tue, Sep 28, 2021 at 02:22:42AM -0700, Zev Weiss wrote:
> Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
> Reviewed-by: Rob Herring <robh@kernel.org>

Applied.

Thanks,
Guenter

> ---
>  .../bindings/hwmon/pmbus/ti,lm25066.yaml      | 54 +++++++++++++++++++
>  1 file changed, 54 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
> 
> diff --git a/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml b/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
> new file mode 100644
> index 000000000000..da8292bc32f5
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
> @@ -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 <zev@bewilderbeest.net>
> +
> +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>;
> +        };
> +    };

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2021-10-08 14:05 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28  9:22 [PATCH 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
2021-09-28  9:22 ` [PATCH 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
2021-10-08 13:37   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
2021-10-08 13:46   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
2021-10-08 13:47   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
2021-10-08 13:47   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
2021-10-08 13:49   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
2021-10-08 13:52   ` Guenter Roeck
2021-10-08 13:59   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
2021-10-08 14:03   ` Guenter Roeck
2021-09-28  9:22 ` [PATCH 8/8] dt-bindings: hwmon/pmbus: Add ti,lm25066 power-management IC Zev Weiss
2021-10-04 18:28   ` Rob Herring
2021-10-08 14:05   ` Guenter Roeck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.