Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1205278imm; Wed, 17 Oct 2018 15:27:48 -0700 (PDT) X-Google-Smtp-Source: ACcGV625jo1azo/4sNLcOa2gT23nh9RW03GsXaIvvSlVWdjTJv6fxpYTJL4aY5SX2lBc09+fxsyC X-Received: by 2002:a17:902:6848:: with SMTP id f8-v6mr27899853pln.27.1539815268110; Wed, 17 Oct 2018 15:27:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539815268; cv=none; d=google.com; s=arc-20160816; b=fT59dHeCKBx6oKoDlQPEulY001VpzBIbDPLxeaM5FPQvZNfVie8BAAeCgJ8qeC8t4r jF4G/ssJkxGJG8k1Hof+/buIOol8smbPrPyHxP39E8yglvkpq9iCPUQA7XzPXEf0KIBK hPOjXXJKZRdmZStLRJB7p8ul4g31tV77T876+8Ti0JDGz+ksxtmmBVFpjZiLrLYfj/Xy e7yAjy2I9u+y2WruTW6sLJc2qCIL1tvld+dUV/rzwOZOjDIaToS4SQIo1lcHr+P5f9hV i0aWbkCxUbzYpXqOCMTXXrhwsv/5Yzm5KKl/wlXPOw13JkaA/vCyhg1815aB3mFgUXwd Guxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:cc:from:subject:mime-version :message-id:date:dkim-signature; bh=p8DLWVPHFdDh+XLJZJQGOyjP3fo46ff91OpQ4glEXl4=; b=IxpGjgBatTq6EnU40YOgviFR5ENa2dIYLmzMqr8n7s7FhBZSVcWtXvzRTN9oK2AQTx GctLCUavMyfMCFdwxSYnXZJpXGlGm6621F6QicCcnp/m5QCCy+CJjLVRc9uL2KSrDjrJ dP8sSkj9lS0O0/7Xx8KLuwXJHblGKzPXV8m/THTomuP5zH8wUP5/+LnH+nGx4VOqEeZW +a/5BR5864X874m6mMgYKTifEaXxWrhy9TfFNmQfyq4cWvP/pnc3gBXpqXx+r/ANAd/0 3/b0AtTMqGtKHdxrXQ54/L7bgHfLQLIWEZxGTzRoexhqoYFly7w+DopwpaLcsjwuVlBI eEFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bfWeciy/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q1-v6si19868485pfb.258.2018.10.17.15.27.32; Wed, 17 Oct 2018 15:27:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bfWeciy/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727442AbeJRGYh (ORCPT + 99 others); Thu, 18 Oct 2018 02:24:37 -0400 Received: from mail-it1-f202.google.com ([209.85.166.202]:36638 "EHLO mail-it1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727392AbeJRGYg (ORCPT ); Thu, 18 Oct 2018 02:24:36 -0400 Received: by mail-it1-f202.google.com with SMTP id p125-v6so3965187itg.1 for ; Wed, 17 Oct 2018 15:26:51 -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:cc; bh=p8DLWVPHFdDh+XLJZJQGOyjP3fo46ff91OpQ4glEXl4=; b=bfWeciy/6udWJikIHpD/LgP+JWGKXe0ZOriVFNXcXy4bAFPQ3KXUm3Uv+fp6p+LDiq ZTqPEvrS/7/S+YJn/oKBkQhKENmairZrPOsrCvTv1yxY24upudsrd/eBy9yMpGdifLm9 d87MC0BlpB27xSQTMBqK452DLHIFglVSSyWap0TvThozxiBhnVPeeRNlPdfLMtQET0Xh sGkC0jiPFqqd6nVHfdKQev2bjuC46Oi7BS4SpntJxmEM9Bn6UkxvxXg/oRY2ijBLLKO9 8g7rLl9+zh6SOqG1Gj44E9X3PqZZSecBL8gyRg7OP+akcCVSlXFjhjmP+HrkazA4WJbs ydPw== 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:cc; bh=p8DLWVPHFdDh+XLJZJQGOyjP3fo46ff91OpQ4glEXl4=; b=oR1yNVEPjY3MbwwRjNmK1bONb/UwMJxGjGCYqBhN5VE1STx6AiK9Mv3iEm+uut6ggf QRv+TlCUIkunJhig5+zd/Un+5+r3F8Jt2t416Qhe08iCiCHNZdEtk+KLb1GcXMzlgFo6 EkjBHFaJpEVCz0ugyF+iBml+REtEygGM5hLEUCB5rdbe49sBkrj+DgwcOkI97broSN+H KXZIQGGFiV5uHsUNxYSWqnm3L/1eNxwFflG+uhLvPAxP1AzBwaRKZJtNT6JCM3oqvHgw u703FXRFFAkH/62n0QGL0FHl7VdQ/m9ZCe3we9I3/GfiZ49CCXLi2PBwHGlU+UYldqyy mIvw== X-Gm-Message-State: ABuFfohxMiyjPLNeSkcnv1tvqcsiu90tRupMwsc7XFuRwiTLpvcWfciv URwj4ZHh+99KlfKlWNaUmTj90Uf2wQ== X-Received: by 2002:a05:660c:310:: with SMTP id u16mr3422596itj.1.1539815210606; Wed, 17 Oct 2018 15:26:50 -0700 (PDT) Date: Wed, 17 Oct 2018 15:26:39 -0700 Message-Id: <20181017222639.254434-1-kunyi@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.331.ge82ca0e54c-goog Subject: [PATCH v3 1/2] hwmon: (adm1275): Allow setting shunt reg value From: Kun Yi Cc: openbmc@lists.ozlabs.org, kunyi@google.com, Guenter Roeck , Jean Delvare , Jonathan Corbet , linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 parses device tree parameter "shunt-resistor-micro-ohms", if there is one. Signed-off-by: Kun Yi --- Changes in v3: - splitted hwmon and device tree binding patches Documentation/hwmon/adm1275 | 3 +++ drivers/hwmon/pmbus/adm1275.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) 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; } -- 2.19.1.331.ge82ca0e54c-goog