Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3848898imd; Mon, 29 Oct 2018 13:22:28 -0700 (PDT) X-Google-Smtp-Source: AJdET5fHriG0Mhpnqlws+YsgbfGQNT0YXX/wMFyKNww1h+W70MFOtTfj0Hjl2DgF0eTd7afBjwrt X-Received: by 2002:a62:1a92:: with SMTP id a140-v6mr16495003pfa.219.1540844548328; Mon, 29 Oct 2018 13:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540844548; cv=none; d=google.com; s=arc-20160816; b=aSspmh/WkXenj3QcKe1czWel7FJMXCysELquelz6ArzZNsbuS5zbfAWBuFHj9qk1+A Fdhe+suhubz9NPjD692LgfCcjfBABG6BGyAPhK+JFvs3kJfg8xTEs8dqCx0jgOLBMXa/ 40A6yUxluj371nuOF0MuuyKBmjDY3BqrC4EOz8t5eVfeTR2K9TaEeK0O5GQ+JnzipaPf xJnImBwSX88lIKH/HfJR4Ph+DzBx27o0RAA7hulP5dNj1Zt10DWdclSKP00A7Q53m2rG 4mgzsrkqBy7jJdDCTZYkeclt/JS2pyDEn3QI48tEuWnmCWJVLhN8fR7dQliKMpGqtADz ukMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+VGpz0pPFr/WjkfyRARlME8X0Ya2Wf3uXpp6ohQfnPM=; b=DzqdZJsgQ5nHIsFZGNOU1aeImv9cShMAeUL+iW+5K4AZ/6RywHuxPnvutYr+L+Wr+T o7/K+M5FdiBcdgHEqKtAWFg8cfjoT/umooecxFRLkjSbppUodBmIBy/WJ0QdTBhq3aMx RvasrJ7S9rZ6MAocQoLJ8eU6hq+CEOpYOYgzkRdKQ0c/bulZWRkitCYAAJF/fbrC0D4l m7wVORmNawMUwudJaQqt7JUe5BaCu6mOxLyZBDkT1hIfYR0J8x/NSiqujmOk9Sss1zBB /P3W6kejGtvsOB/95DWJgPw/5bWkqlBd+YvhVGfpoJ5Q9Hwt81iBcubmvOG5/vEgtrbX bc1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=W4c37Lrj; 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 p14-v6si20972815plo.7.2018.10.29.13.22.11; Mon, 29 Oct 2018 13:22:28 -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=W4c37Lrj; 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 S1729611AbeJ3FMG (ORCPT + 99 others); Tue, 30 Oct 2018 01:12:06 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:42683 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728735AbeJ3FMG (ORCPT ); Tue, 30 Oct 2018 01:12:06 -0400 Received: by mail-io1-f67.google.com with SMTP id n18-v6so5832472ioa.9 for ; Mon, 29 Oct 2018 13:21:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+VGpz0pPFr/WjkfyRARlME8X0Ya2Wf3uXpp6ohQfnPM=; b=W4c37LrjNvPQCgQYilDFzG0O8oLm+JNHQCGNUf8pQKD6BP+6x7Qi7GyK454ucjv/Nk qywsNQFrgkrWMESCt6lboRCNRNKkmS1Z8cJrZTbFJd+OHwGWPj3SJiLJUcZS0sqrtegH yAgQMXwkbhnPlwSP/gJIb8p6ShXmNux73yYHBSc/bstl3lSU6SNeqHmxv1b1xUMFC0HR igHFSyQOZ4VfFfjwnCI57ctWiNvRFqHVSElsBzwvZUtdCThRlRq8mozuPBucNFZ89RYp hcExpb3r2wwEnvpj0EPpyuFlyD7Z4GrDDYP22dnP6keOSECo56cpt4oMxP2RppBzDzbf ttfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=+VGpz0pPFr/WjkfyRARlME8X0Ya2Wf3uXpp6ohQfnPM=; b=k4fWOqSFZDbF/tuxmwwDqtj3wGfIdFtGj/edppqJrGt6oIJW3Krvodek85MGkaLKEm 65vGh8i29wBtsO1ehzu+Ju3Pmudl4Lo37WtLbha5YTYMa25AuOqbH9zP8EKC9Es7kVIr J2YgmafU0WHJFF1kGBDUyiBCi7TL7a4XYOE54fDUQcm8XdZloj2LgtumDA0iepYIlp1i QJ/zZ2iXLmOlFHvFNH38vTcz5ZGfHDOGdN9mxGvkTotE+5m9uB0+wVdRFHitmoeDcmc9 TsLR2ZHsGZqEmb9dxEga1sp2ICLk84aJ5I+2kToPZInADS1Gqw/TEykxwvEqM9hQMJzl FnCQ== X-Gm-Message-State: AGRZ1gK8RSGw2GEf0Ll6v6CyEkcMjFkX2KgBA3INOo91Cget4K4c9MPv gOlRFECvG+Ha8ETUCJLtov8VvxhXmXLMX/gwfQi+lQ== X-Received: by 2002:a6b:9046:: with SMTP id s67-v6mr8927335iod.295.1540844509710; Mon, 29 Oct 2018 13:21:49 -0700 (PDT) MIME-Version: 1.0 References: <20181017222639.254434-1-kunyi@google.com> <20181027172833.GA25052@roeck-us.net> In-Reply-To: <20181027172833.GA25052@roeck-us.net> From: Kun Yi Date: Mon, 29 Oct 2018 13:21:23 -0700 Message-ID: Subject: Re: [PATCH v3 1/2] hwmon: (adm1275): Allow setting shunt reg value To: Guenter Roeck Cc: OpenBMC Maillist , jdelvare@suse.com, corbet@lwn.net, linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 27, 2018 at 10:28 AM Guenter Roeck wrote: > > On Wed, Oct 17, 2018 at 03:26:39PM -0700, Kun Yi wrote: > > 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 > > Applied to hwmon-next. > > Thanks, > Guenter > > > --- > > 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; > > } Thanks! -- Regards, Kun