From patchwork Sun Jul 24 20:26:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 9245047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B6E32607FD for ; Sun, 24 Jul 2016 20:44:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A6A8020499 for ; Sun, 24 Jul 2016 20:44:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B4F8212D7; Sun, 24 Jul 2016 20:44:49 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 1045F20499 for ; Sun, 24 Jul 2016 20:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752508AbcGXUos (ORCPT ); Sun, 24 Jul 2016 16:44:48 -0400 Received: from fudo.makrotopia.org ([185.142.180.71]:39365 "EHLO fudo.makrotopia.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752503AbcGXUor (ORCPT ); Sun, 24 Jul 2016 16:44:47 -0400 X-Greylist: delayed 1094 seconds by postgrey-1.27 at vger.kernel.org; Sun, 24 Jul 2016 16:44:47 EDT Received: from local by fudo.makrotopia.org with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1bRPyl-0008G4-3w; Sun, 24 Jul 2016 22:26:27 +0200 Date: Sun, 24 Jul 2016 22:26:25 +0200 From: Daniel Golle To: linux-hwmon@vger.kernel.org Cc: devicetree@vger.kernel.org, Axel Lin , Guenter Roeck , Per =?iso-8859-1?Q?Dal=E9n?= Subject: [PATCH] hwmon: (ltc4151) Make shunt-resistor configurable Message-ID: <20160724202620.GA30245@makrotopia.org> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.6.2 (2016-07-01) 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 Allow to specify the resistance of the attached shunt via DT by adding the shunt-resistor property. Fall-back to the previous default (1 mOhm) if unset. Signed-off-by: Daniel Golle --- drivers/hwmon/ltc4151.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ltc4151.c b/drivers/hwmon/ltc4151.c index c86a184..f856e44 100644 --- a/drivers/hwmon/ltc4151.c +++ b/drivers/hwmon/ltc4151.c @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include #include @@ -52,6 +54,7 @@ struct ltc4151_data { struct mutex update_lock; bool valid; unsigned long last_updated; /* in jiffies */ + unsigned int shunt; /* in micro ohms */ /* Registers */ u8 regs[6]; @@ -111,9 +114,9 @@ static int ltc4151_get_value(struct ltc4151_data *data, u8 reg) case LTC4151_SENSE_H: /* * 20uV resolution. Convert to current as measured with - * an 1 mOhm sense resistor, in mA. + * a given sense resistor, in mA. */ - val = val * 20; + val = val * 20 * 1000 / data->shunt; break; case LTC4151_VIN_H: /* 25 mV per increment */ @@ -176,6 +179,7 @@ static int ltc4151_probe(struct i2c_client *client, struct device *dev = &client->dev; struct ltc4151_data *data; struct device *hwmon_dev; + u32 shunt; if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) return -ENODEV; @@ -184,6 +188,14 @@ static int ltc4151_probe(struct i2c_client *client, if (!data) return -ENOMEM; +#ifdef CONFIG_OF + if (!of_property_read_u32(client->dev.of_node, "shunt-resistor", &shunt) + && shunt > 0 ) + data->shunt = shunt; + else +#endif + data->shunt = 1000; /* 1 mOhm if not set */ + data->client = client; mutex_init(&data->update_lock); @@ -199,10 +211,20 @@ static const struct i2c_device_id ltc4151_id[] = { }; MODULE_DEVICE_TABLE(i2c, ltc4151_id); +#ifdef CONFIG_OF +static const struct of_device_id ltc4151_match[] = { + { .compatible = "lltc,ltc4151" }, + {}, +}; +#endif + /* This is the driver that will be inserted */ static struct i2c_driver ltc4151_driver = { + .class = I2C_CLASS_HWMON, .driver = { .name = "ltc4151", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(ltc4151_match), }, .probe = ltc4151_probe, .id_table = ltc4151_id,