From patchwork Fri Sep 28 19:58:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kun Yi X-Patchwork-Id: 10620309 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BB3366CB for ; Fri, 28 Sep 2018 19:59:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A432A2C261 for ; Fri, 28 Sep 2018 19:59:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96C292C274; Fri, 28 Sep 2018 19:59:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26C2C2C261 for ; Fri, 28 Sep 2018 19:59:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726473AbeI2CZQ (ORCPT ); Fri, 28 Sep 2018 22:25:16 -0400 Received: from mail-pg1-f202.google.com ([209.85.215.202]:45876 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbeI2CZQ (ORCPT ); Fri, 28 Sep 2018 22:25:16 -0400 Received: by mail-pg1-f202.google.com with SMTP id 186-v6so7736090pgc.12 for ; Fri, 28 Sep 2018 12:59:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=bW7QQ6sb4fiATo7jTyTuAURvccUcKVFvs6VrcThzwa0=; b=nbWCR7X3pMP+mqCFDJraweqQ7ScFgV3Xhpn6BMQ5UezwqCki3HCAdv8Dh9f/1vqVgr Lahg6919xYHawE/79CtkpEdxUF06rWvM7PY1EP7VwfMKbAZH3J71/4WFO28GUcq0jy3i TNOqN1D+g0hQeeQEQp1oVFfJhqa5J8HUqU/bJ61BnBUzQgVA8jNUzgTvt/wv6BtXZqy5 Cp4ieLf0Xy0YY5TADnvzEYT1Ow4FqzP1L3ZdwRy+rPhs3e7AjahFUJ4phHdy5nnosUBg Bj3qSXhsA1iLbVslp2wF5/PWOdbyPBMWk6lbPH6+XfnqKV8jfmZnnjzAexdo/nRT5Rnf dnSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=bW7QQ6sb4fiATo7jTyTuAURvccUcKVFvs6VrcThzwa0=; b=SBc+AcbmFkTftZQ5UYbCrD9y2iyxWPtph+QaP25y8U4a0WAJ9B6ExwOaD2fVDd4R2g Hvg9tLoEBb0o/uD6g0+jqdbUWDEP377LAIDURbSf5eh/leBmL38PQvW1QWVLk3iG3Qfe jrnOpaq9GTZ2Nh55POO7+eLvBp9YcM86u8SYKwPxgmra9K8Wd+iKi+jTA7BFcpbKH0cr pap0TFzdIHiDdmhb4qRT6teEMCLtipQ+gV/Xznc+EbjNttwqRsT5Ty4DYUdc19NAOFGD ihN1BzkLA91jDnW41QkEJrrY3CNOeWR/bcecvxf9G7NuDhvzrWRw0KsAGKSlwXGNLuZc nyXA== X-Gm-Message-State: ABuFfohXbNWAcbAzRmr+rozDxCBjFYiLSchGIFui8c385mtQB3td/bbw FI3sDe/N2IFAMyJ2+71WWHRoyts2DQ== X-Google-Smtp-Source: ACcGV60jIBF2iVuxBbv6mMW+jEDS1DEi7z/XVs0L8Dbz2GmxaIho0nqos5RWOuYbrw2R40lau65oi3E1XQ== X-Received: by 2002:a65:5048:: with SMTP id k8-v6mr64933pgo.17.1538164796696; Fri, 28 Sep 2018 12:59:56 -0700 (PDT) Date: Fri, 28 Sep 2018 12:58:00 -0700 Message-Id: <20180928195800.153914-1-kunyi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog Subject: [PATCH v2] hwmon: (adm1275): Add device tree param for shunt resistor From: Kun Yi To: linux@roeck-us.net, linux-hwmon@vger.kernel.org, jdelvare@suse.com, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org Cc: rlippert@google.com, benjaminfair@google.com, openbmc@lists.ozlabs.org, Kun Yi Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ADM series of hotswap controllers support extending the current measurement range by using a sensing resistor value other than the typical 1 mOhm. For example, using a 0.5 mOhm sensing resistor doubles the maximal current can be measured. Current driver assumes a shunt resistor value of 1 mOhm in calculation, meaning for other resistor values, hwmon will report scaled current/power measurements. This patch adds a device tree parameter so that individual boards can configure its shunt resistor value. Signed-off-by: Kun Yi --- .../devicetree/bindings/hwmon/adm1275.txt | 25 +++++++++++++++++++ Documentation/hwmon/adm1275 | 3 +++ drivers/hwmon/pmbus/adm1275.c | 15 +++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/adm1275.txt diff --git a/Documentation/devicetree/bindings/hwmon/adm1275.txt b/Documentation/devicetree/bindings/hwmon/adm1275.txt new file mode 100644 index 000000000000..1ecd03f3da4d --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/adm1275.txt @@ -0,0 +1,25 @@ +adm1275 properties + +Required properties: +- compatible: Must be one of the supported compatible strings: + - "adi,adm1075" for adm1075 + - "adi,adm1272" for adm1272 + - "adi,adm1275" for adm1275 + - "adi,adm1276" for adm1276 + - "adi,adm1278" for adm1278 + - "adi,adm1293" for adm1293 + - "adi,adm1294" for adm1294 +- reg: I2C address + +Optional properties: + +- shunt-resistor-micro-ohms + Shunt resistor value in micro-Ohm + +Example: + +adm1272@10 { + compatible = "adi,adm1272"; + reg = <0x10>; + shunt-resistor-micro-ohms = <500>; +}; diff --git a/Documentation/hwmon/adm1275 b/Documentation/hwmon/adm1275 index 39033538eb03..5e277b0d91ce 100644 --- a/Documentation/hwmon/adm1275 +++ b/Documentation/hwmon/adm1275 @@ -58,6 +58,9 @@ The ADM1075, unlike many other PMBus devices, does not support internal voltage or current scaling. Reported voltages, currents, and power are raw measurements, and will typically have to be scaled. +The shunt value in micro-ohms can be set via device tree at compile-time. Please +refer to the Documentation/devicetree/bindings/hwmon/adm1275.txt for bindings +if the device tree is used. Platform data support --------------------- diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c index 13600fa79e7f..f569372c9204 100644 --- a/drivers/hwmon/pmbus/adm1275.c +++ b/drivers/hwmon/pmbus/adm1275.c @@ -373,6 +373,7 @@ static int adm1275_probe(struct i2c_client *client, const struct coefficients *coefficients; int vindex = -1, voindex = -1, cindex = -1, pindex = -1; int tindex = -1; + u32 shunt; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA @@ -421,6 +422,13 @@ static int adm1275_probe(struct i2c_client *client, if (!data) return -ENOMEM; + if (of_property_read_u32(client->dev.of_node, + "shunt-resistor-micro-ohms", &shunt)) + shunt = 1000; /* 1 mOhm if not set via DT */ + + if (shunt == 0) + return -EINVAL; + data->id = mid->driver_data; info = &data->info; @@ -654,12 +662,15 @@ static int adm1275_probe(struct i2c_client *client, info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R; } if (cindex >= 0) { - info->m[PSC_CURRENT_OUT] = coefficients[cindex].m; + /* Scale current with sense resistor value */ + info->m[PSC_CURRENT_OUT] = + coefficients[cindex].m * shunt / 1000; info->b[PSC_CURRENT_OUT] = coefficients[cindex].b; info->R[PSC_CURRENT_OUT] = coefficients[cindex].R; } if (pindex >= 0) { - info->m[PSC_POWER] = coefficients[pindex].m; + info->m[PSC_POWER] = + coefficients[pindex].m * shunt / 1000; info->b[PSC_POWER] = coefficients[pindex].b; info->R[PSC_POWER] = coefficients[pindex].R; }