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: 13990 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 3A3BF23E27 for ; Fri, 11 Jan 2013 13:13:54 +0000 (UTC) Received: from mail-vb0-f43.google.com (mail-vb0-f43.google.com [209.85.212.43]) by fiordland.canonical.com (Postfix) with ESMTP id EA66BA18C70 for ; Fri, 11 Jan 2013 13:13:53 +0000 (UTC) Received: by mail-vb0-f43.google.com with SMTP id fs19so1396078vbb.2 for ; Fri, 11 Jan 2013 05:13:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf: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=LJozln2PatuHfzOm/KXad8QyrE+59nRsA8fg3qssSL0LrMuvRDS3xUABGGUDwXul0d A4uihOqfMTgAo6PEKi9266TYYdIQdyQIzox1KJbA2onQsG6yUa7bt6SBkz7m5A+7/q1r YkYasp5Ab9S6CDuu/AICsZuVQmaTUFupSxvEQHGjK52ACh5HhH7xuREqJbVoUgkHMWd4 mPKHcsbCTMEzVmONSFk1M8TjdcSZoy6pvAFjh+PByi44l0E4jKheCdA9XAmiZCaqegH7 9+lke4gAvXNnultJ14Cf73MSQM3YiXpGvEvs2yOzAGnPrL9MHyzo/0QxJRZinn0MdtCf r+tA== X-Received: by 10.52.88.168 with SMTP id bh8mr80223393vdb.51.1357910033481; Fri, 11 Jan 2013 05:13:53 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp111258veb; Fri, 11 Jan 2013 05:13:52 -0800 (PST) X-Received: by 10.180.78.137 with SMTP id b9mr15213693wix.30.1357910032460; Fri, 11 Jan 2013 05:13:52 -0800 (PST) Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id l1si8664083wjr.64.2013.01.11.05.13.52 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 05:13:52 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.178 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) smtp.mail=lee.jones@linaro.org Received: by mail-we0-f178.google.com with SMTP id x43so824225wey.37 for ; Fri, 11 Jan 2013 05:13:52 -0800 (PST) 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 Cc: arnd@arndb.de, linus.walleij@stericsson.com, cbouatmailru@gmail.com, Paer-Olof Haakansson , Lee Jones , =?UTF-8?q?Henrik=20S=C3=B6lver?= 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: ALoCoQnRCCpj7uG7x4WWYMw1OcVaJm9pTqYEOaX2lhCpHAKhpo698MCeLoWB7SFhwiBGtKR65MEC 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,