openbmc.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups
@ 2021-10-18 23:17 Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

Hi Joel,

This patch series is now on its way upstream via Guenter Roeck's
hwmon-next tree; until the OpenBMC kernel gets rebased onto an
upstream release that includes them it'd be great if they could be in
the OpenBMC kernel too.

https://lore.kernel.org/linux-hwmon/20210928092242.30036-1-zev@bewilderbeest.net/T/


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                 | 88 +++++++++++++++----
 3 files changed, 126 insertions(+), 18 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml

-- 
2.33.1


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

* [PATCH linux dev-5.14 1/8] hwmon: (pmbus/lm25066) Add offset coefficients
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

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

Fixes: 58615a94f6a1 ("hwmon: (pmbus/lm25066) Add support for LM25056")
Fixes: e53e6497fc9f ("hwmon: (pmbus/lm25066) Refactor device specific coefficients")
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20210928092242.30036-2-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.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.1


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

* [PATCH linux dev-5.14 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

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>
Link: https://lore.kernel.org/r/20210928092242.30036-3-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.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.1


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

* [PATCH linux dev-5.14 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

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

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20210928092242.30036-4-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.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.1


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

* [PATCH linux dev-5.14 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (2 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

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")
Link: https://lore.kernel.org/r/20210928092242.30036-5-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.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 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.1


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

* [PATCH linux dev-5.14 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (3 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

lm25066_coeff is read-only. Mark it as such.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20210928092242.30036-6-zev@bewilderbeest.net
[groeck: Added description]
Signed-off-by: Guenter Roeck <linux@roeck-us.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.1


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

* [PATCH linux dev-5.14 6/8] hwmon: (pmbus/lm25066) Add OF device ID table
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (4 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

The driver doesn't have a struct of_device_id table but supported devices
are registered via Device Trees. This is working on the assumption that a
I2C device registered via OF will always match a legacy I2C device ID and
that the MODALIAS reported will always be of the form i2c:<device>.

But this could change in the future so the correct approach is to have an
OF device ID table if the devices are registered via OF.

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Link: https://lore.kernel.org/r/20210928092242.30036-7-zev@bewilderbeest.net
[groeck: Replaced reference to reasoning with reasoning, fixed checkpatch
 warnings, fixed compile warning comparing of_id->data w/ i2c_id->driver_data]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/pmbus/lm25066.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/pmbus/lm25066.c b/drivers/hwmon/pmbus/lm25066.c
index dbbf8571c437..7dc5ffeab77d 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,14 @@ 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 && (unsigned long)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 +541,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.1


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

* [PATCH linux dev-5.14 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (5 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:17 ` [PATCH linux dev-5.14 8/8] dt-bindings: hwmon/pmbus: Add ti, lm25066 power-management IC Zev Weiss
  2021-10-18 23:33 ` [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Joel Stanley
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

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>
Link: https://lore.kernel.org/r/20210928092242.30036-8-zev@bewilderbeest.net
[groeck: Fixed checkpatch warnings]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 Documentation/hwmon/lm25066.rst |  2 ++
 drivers/hwmon/pmbus/lm25066.c   | 11 +++++++++++
 2 files changed, 13 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 7dc5ffeab77d..8402b41520eb 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;
@@ -534,6 +535,16 @@ 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.1


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

* [PATCH linux dev-5.14 8/8] dt-bindings: hwmon/pmbus: Add ti, lm25066 power-management IC
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (6 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
@ 2021-10-18 23:17 ` Zev Weiss
  2021-10-18 23:33 ` [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Joel Stanley
  8 siblings, 0 replies; 10+ messages in thread
From: Zev Weiss @ 2021-10-18 23:17 UTC (permalink / raw)
  To: openbmc, joel

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Reviewed-by: Rob Herring <robh@kernel.org>
Link: https://lore.kernel.org/r/20210928092242.30036-9-zev@bewilderbeest.net
Signed-off-by: Guenter Roeck <linux@roeck-us.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.1


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

* Re: [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups
  2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
                   ` (7 preceding siblings ...)
  2021-10-18 23:17 ` [PATCH linux dev-5.14 8/8] dt-bindings: hwmon/pmbus: Add ti, lm25066 power-management IC Zev Weiss
@ 2021-10-18 23:33 ` Joel Stanley
  8 siblings, 0 replies; 10+ messages in thread
From: Joel Stanley @ 2021-10-18 23:33 UTC (permalink / raw)
  To: Zev Weiss; +Cc: OpenBMC Maillist

On Mon, 18 Oct 2021 at 23:17, Zev Weiss <zev@bewilderbeest.net> wrote:
>
> Hi Joel,
>
> This patch series is now on its way upstream via Guenter Roeck's
> hwmon-next tree; until the OpenBMC kernel gets rebased onto an
> upstream release that includes them it'd be great if they could be in
> the OpenBMC kernel too.
>
> https://lore.kernel.org/linux-hwmon/20210928092242.30036-1-zev@bewilderbeest.net/T/

Great work Zev. Happily applied to dev-5.14.

Cheers,

Joel

>
>
> 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                 | 88 +++++++++++++++----
>  3 files changed, 126 insertions(+), 18 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/ti,lm25066.yaml
>
> --
> 2.33.1
>

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

end of thread, other threads:[~2021-10-18 23:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-18 23:17 [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 1/8] hwmon: (pmbus/lm25066) Add offset coefficients Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 2/8] hwmon: (pmbus/lm25066) Adjust lm25066 PSC_CURRENT_IN_L mantissa Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 3/8] hwmon: (pmbus/lm25066) Avoid forward declaration of lm25066_id Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 4/8] hwmon: (pmbus/lm25066) Let compiler determine outer dimension of lm25066_coeff Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 5/8] hwmon: (pmbus/lm25066) Mark lm25066_coeff array const Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 6/8] hwmon: (pmbus/lm25066) Add OF device ID table Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Zev Weiss
2021-10-18 23:17 ` [PATCH linux dev-5.14 8/8] dt-bindings: hwmon/pmbus: Add ti, lm25066 power-management IC Zev Weiss
2021-10-18 23:33 ` [PATCH linux dev-5.14 0/8] hwmon: (pmbus/lm25066) Configurable sense resistor, other cleanups Joel Stanley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).