linux-hwmon.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zev Weiss <zev@bewilderbeest.net>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Zev Weiss <zev@bewilderbeest.net>,
	Jean Delvare <jdelvare@suse.com>,
	Jonathan Corbet <corbet@lwn.net>,
	linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values
Date: Tue, 28 Sep 2021 02:22:41 -0700	[thread overview]
Message-ID: <20210928092242.30036-8-zev@bewilderbeest.net> (raw)
In-Reply-To: <20210928092242.30036-1-zev@bewilderbeest.net>

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


  parent reply	other threads:[~2021-09-28  9:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Zev Weiss [this message]
2021-10-08 14:03   ` [PATCH 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210928092242.30036-8-zev@bewilderbeest.net \
    --to=zev@bewilderbeest.net \
    --cc=corbet@lwn.net \
    --cc=jdelvare@suse.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).