From patchwork Tue Apr 18 12:15:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Schaack X-Patchwork-Id: 9685457 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 1C3C560375 for ; Tue, 18 Apr 2017 12:24:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0BFE2283F4 for ; Tue, 18 Apr 2017 12:24:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3804283FB; Tue, 18 Apr 2017 12:24:51 +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 28868283F4 for ; Tue, 18 Apr 2017 12:24:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755523AbdDRMYu (ORCPT ); Tue, 18 Apr 2017 08:24:50 -0400 Received: from xes-mad.com ([216.165.139.220]:44976 "EHLO mail.xes-mad.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753150AbdDRMYu (ORCPT ); Tue, 18 Apr 2017 08:24:50 -0400 X-Greylist: delayed 541 seconds by postgrey-1.27 at vger.kernel.org; Tue, 18 Apr 2017 08:24:50 EDT Received: from jschaack-VirtualBox.xes-mad.com (jschaack-virtualbox [10.52.22.175]) by mail.xes-mad.com (Postfix) with ESMTP id AE4CF20379; Tue, 18 Apr 2017 07:15:48 -0500 (CDT) From: Joe Schaack To: linux-hwmon@vger.kernel.org Cc: jdelvare@suse.com, linux@roeck-us.net, asierra@xes-inc.com, jschaack@xes-inc.com Subject: [PATCH] hwmon: ina209: Handled signed registers Date: Tue, 18 Apr 2017 07:15:50 -0500 Message-Id: <1492517750-20701-1-git-send-email-jschaack@xes-inc.com> X-Mailer: git-send-email 1.9.1 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 shunt voltage and current registers are signed 16-bit values so handle them as such. Signed-off-by: Joe Schaack Reviewed-by: Aaron Sierra --- drivers/hwmon/ina209.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/ina209.c b/drivers/hwmon/ina209.c index 5378fde..9fa975d 100644 --- a/drivers/hwmon/ina209.c +++ b/drivers/hwmon/ina209.c @@ -117,7 +117,7 @@ static long ina209_from_reg(const u8 reg, const u16 val) case INA209_SHUNT_VOLTAGE_POS_WARN: case INA209_SHUNT_VOLTAGE_NEG_WARN: /* LSB=10 uV. Convert to mV. */ - return DIV_ROUND_CLOSEST(val, 100); + return DIV_ROUND_CLOSEST((s16)val, 100); case INA209_BUS_VOLTAGE: case INA209_BUS_VOLTAGE_MAX_PEAK: @@ -146,7 +146,7 @@ static long ina209_from_reg(const u8 reg, const u16 val) case INA209_CURRENT: /* LSB=1 mA (selected). Is in mA */ - return val; + return (s16)val; } /* programmer goofed */