Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37A8AC433EF for ; Mon, 18 Oct 2021 23:22:13 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2F8F60EE5 for ; Mon, 18 Oct 2021 23:22:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B2F8F60EE5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bewilderbeest.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.ozlabs.org Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4HYCZW2ywPz3cDf for ; Tue, 19 Oct 2021 10:22:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=GKsf1G7U; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=bewilderbeest.net (client-ip=71.19.156.171; helo=thorn.bewilderbeest.net; envelope-from=zev@bewilderbeest.net; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=GKsf1G7U; dkim-atps=neutral Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [71.19.156.171]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4HYCT74wMjz3c4g for ; Tue, 19 Oct 2021 10:17:31 +1100 (AEDT) Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id C5245C10; Mon, 18 Oct 2021 16:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1634599044; bh=08x8zUaEg/e6pgv47UAY8VcUVQlEju7qoIXPBgdH4qA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GKsf1G7U1t/k5Z+SSp0xi+tUo+bwBjA6XmCbPeqXi+AYRCmxT7C+5zCM9pBSXszu9 4+FYqhtQ9KFNwTi7GjbAaBOT1C0rdqvgV01krCAETI6PC3qw4jJNgrNhbr2cpN4PZz aTN8f3OrMGbozBedsCLUC4KtmjvfZBWaLrB6v9x0= From: Zev Weiss To: openbmc@lists.ozlabs.org, joel@jms.id.au Subject: [PATCH linux dev-5.14 7/8] hwmon: (pmbus/lm25066) Support configurable sense resistor values Date: Mon, 18 Oct 2021 16:17:13 -0700 Message-Id: <20211018231714.19054-8-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211018231714.19054-1-zev@bewilderbeest.net> References: <20211018231714.19054-1-zev@bewilderbeest.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: openbmc@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development list for OpenBMC List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openbmc-bounces+openbmc=archiver.kernel.org@lists.ozlabs.org Sender: "openbmc" 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 Link: https://lore.kernel.org/r/20210928092242.30036-8-zev@bewilderbeest.net [groeck: Fixed checkpatch warnings] Signed-off-by: Guenter Roeck --- 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