From patchwork Fri Jan 11 13:13:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 1966101 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id 2FC003FF0F for ; Fri, 11 Jan 2013 13:25:50 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TteXy-0006ef-Oe; Fri, 11 Jan 2013 13:21:23 +0000 Received: from mail-wg0-f47.google.com ([74.125.82.47]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1TteQj-0001W6-Ki for linux-arm-kernel@lists.infradead.org; Fri, 11 Jan 2013 13:13:56 +0000 Received: by mail-wg0-f47.google.com with SMTP id dq11so832764wgb.14 for ; Fri, 11 Jan 2013 05:13:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=BlY74/Il1JvM0Q2lM1h7A7Luq/mOhoJexQK57JEySYw=; b=aAws4+ihct/bicJaCgWxpukLP94V51AANtpv4ecQODEUxoR0sMggxTXNdxC2yKeGb7 vNSEovv1F+q0HQWzRQgoonNGmYJzjBpP+KNzjLpmfw8hzI64VQ19VxeHE5OLKM4/9zXN 0ad+nYqHFXeEBaQaUGYqnQmgXHxL4e8/qXV3K65IJqXnOtmJFLZKEYlZOB4o0B1qVIX5 +3oWczxfckL7TJ9TDiJ1RvD5MGDTse5t2jHuFgUW2ZCt4lql2szM7uD645Kw6REvUN8R NmQvCO+hTn4yHbd3VFe5gwZWKXmOwmb9phPp78TFJqRgVnZMRxkV+uYTpt3GOH7Y2fq2 3BVA== X-Received: by 10.180.19.136 with SMTP id f8mr15440797wie.0.1357910032084; Fri, 11 Jan 2013 05:13:52 -0800 (PST) Received: from localhost.localdomain (cpc1-aztw13-0-0-cust473.18-1.cable.virginmedia.com. [77.102.241.218]) by mx.google.com with ESMTPS id p2sm7204515wic.7.2013.01.11.05.13.50 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 05:13:51 -0800 (PST) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/18] Power: ab8500_fg: Overflow in current calculation Date: Fri, 11 Jan 2013 13:13:05 +0000 Message-Id: <1357909986-9262-18-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357909986-9262-1-git-send-email-lee.jones@linaro.org> References: <1357909986-9262-1-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlG0RajN0p1lSasHmgp1DdMjFI+l9CuuLobZD20AOhGVUWH0PrB6rbosvB4q3W5nDbZOW7p X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130111_081354_199919_83C3D0AC X-CRM114-Status: GOOD ( 11.03 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [74.125.82.47 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linus.walleij@stericsson.com, arnd@arndb.de, cbouatmailru@gmail.com, =?UTF-8?q?Henrik=20S=C3=B6lver?= , Paer-Olof Haakansson , Lee Jones X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Paer-Olof Haakansson When calculating the average current the nominator will overflow when the charging current is high. Signed-off-by: Lee Jones Signed-off-by: Henrik Sölver Reviewed-by: Par-Olof HAKANSSON Reviewed-by: Jonas ABERG Tested-by: Par-Olof HAKANSSON --- drivers/power/ab8500_fg.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 845e64f..4bc2c2d 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -805,12 +805,9 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) /* * Convert to unit value in mA - * Full scale input voltage is - * 66.660mV => LSB = 66.660mV/(4096*res) = 1.627mA - * Given a 250ms conversion cycle time the LSB corresponds - * to 112.9 nAh. Convert to current by dividing by the conversion + * by dividing by the conversion * time in hours (= samples / (3600 * 4)h) - * 112.9nAh assumes 10mOhm, but fg_res is in 0.1mOhm + * and multiply with 1000 */ di->avg_curr = (val * QLSB_NANO_AMP_HOURS_X10 * 36) / (1000 * di->bm->fg_res * (di->fg_samples / 4)); @@ -821,6 +818,8 @@ static void ab8500_fg_acc_cur_work(struct work_struct *work) queue_work(di->fg_wq, &di->fg_work); + dev_dbg(di->dev, "fg_res: %d, fg_samples: %d, gasg: %d, accu_charge: %d \n", + di->bm->fg_res, di->fg_samples, val, di->accu_charge); return; exit: dev_err(di->dev,