From patchwork Thu Dec 13 15:21:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13554 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 DB1E223E2A for ; Thu, 13 Dec 2012 15:22:26 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 8C072A185E5 for ; Thu, 13 Dec 2012 15:22:26 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so4139935ieb.11 for ; Thu, 13 Dec 2012 07:22:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf: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=s+xYysXJ5lKGk98YmR2aBLunHJqD0wx/FZIqW+llXN0=; b=jveB9EbNccleiLwmFIbCgbFSi69vbrhGxky3jC5JS2fmg2PgEifqR6+V2k6+0y46/A RweaOubYu8AViM54cmi1KyHfcybFmBXClawqxA2or0PqQQI7HbKbkL0aNpuM0LTNhe50 5FyBpPiMIs6f5eFBYoT5mbF8RHOM+zNThPPPOhh8OcKLO+64aF7LLQdnstFBGXfbxFqm iXvVAcEY2z2FaAFRXBfTHAfAfsyTwe3wRNJVn3gh5d4U2APHGrMu1GFnxNhGYBAfi72x z4suPWPpZcG9+1ZL+sqaT2emtGvFJ1dkxZf7xEsZz7Ts7MM9uu4gfljV5MH809NSGZZL MqVA== Received: by 10.50.187.197 with SMTP id fu5mr1872467igc.70.1355412146048; Thu, 13 Dec 2012 07:22:26 -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.50.67.148 with SMTP id n20csp16284igt; Thu, 13 Dec 2012 07:22:25 -0800 (PST) Received: by 10.180.78.161 with SMTP id c1mr4049138wix.4.1355412145028; Thu, 13 Dec 2012 07:22:25 -0800 (PST) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by mx.google.com with ESMTPS id az6si12609178wjc.30.2012.12.13.07.22.24 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:25 -0800 (PST) Received-SPF: neutral (google.com: 74.125.82.45 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=74.125.82.45; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.45 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-wg0-f45.google.com with SMTP id dq12so848551wgb.0 for ; Thu, 13 Dec 2012 07:22:24 -0800 (PST) Received: by 10.180.98.8 with SMTP id ee8mr29803493wib.4.1355412144546; Thu, 13 Dec 2012 07:22:24 -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 i6sm8200894wix.5.2012.12.13.07.22.22 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:23 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: cbou@mail.ru, Paer-Olof Haakansson , Lee Jones , =?UTF-8?q?Henrik=20S=C3=B6lver?= Subject: [PATCH 18/18] Power: ab8500_fg: Overflow in current calculation Date: Thu, 13 Dec 2012 15:21:41 +0000 Message-Id: <1355412102-14265-19-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> References: <1355412102-14265-1-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQn9mYQupMESJ5G1t4tlHZ/BgGkocrg0KBTeqC4ktCk6Zu5GvoDCZkxAyFz5YmY0ofyooHfW 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 ec122d0..ba1a087 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -804,12 +804,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)); @@ -820,6 +817,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,