From patchwork Thu Sep 27 20:08:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11794 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 76D5F24140 for ; Thu, 27 Sep 2012 20:09:48 +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 20ABDA18351 for ; Thu, 27 Sep 2012 20:09:48 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5234855iej.11 for ; Thu, 27 Sep 2012 13:09:47 -0700 (PDT) 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 :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=cffYvuuxQ81jgNtVbn5aR9CbfRBJo2kwYknrq+Ov38Q=; b=AFhu0lK+VtyuW7eSRCPEt5uQ6nWHgDjkIz2448kGwZaX1LTPT4uIMYpzoxsx52eJ9j zBO0XGlf4Wd7DwIhT2KYL/RBBN3oU1A8fwIWs7u5zC4NhTRK36YceSRSy2YvwDP71cci bGq3axhbVAE47QdiB5DfzmxLDQo1QMnkXVCE59HfDVQaQCz+taxVPw0Cp9CF/aL5bOw6 xnnM4Kfw8GHrjWUR3jifU69oaKrucJlo/ns+qaF6NZYgbJ0Z43arFMOWniQSfz4mO5Dh 7pGGGIr1jtD6yWqGHcfLX6PA1+pBH4SkebmxACRME49UCvFKpxdZUvvdxjY3lUF2D7C6 CIeA== Received: by 10.50.7.212 with SMTP id l20mr4641536iga.43.1348776587863; Thu, 27 Sep 2012 13:09:47 -0700 (PDT) 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.184.232 with SMTP id ex8csp436308igc; Thu, 27 Sep 2012 13:09:47 -0700 (PDT) Received: by 10.68.227.162 with SMTP id sb2mr14945247pbc.4.1348776587251; Thu, 27 Sep 2012 13:09:47 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pi9si5467641pbb.12.2012.09.27.13.09.47 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:47 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of mathieu.poirier@linaro.org) smtp.mail=mathieu.poirier@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md4so1686045pbc.37 for ; Thu, 27 Sep 2012 13:09:47 -0700 (PDT) Received: by 10.68.130.67 with SMTP id oc3mr14572150pbb.18.1348776586936; Thu, 27 Sep 2012 13:09:46 -0700 (PDT) Received: from localhost.localdomain (S0106002369de4dac.cg.shawcable.net. [70.73.24.112]) by mx.google.com with ESMTPS id sa2sm1587890pbc.4.2012.09.27.13.09.45 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 27 Sep 2012 13:09:46 -0700 (PDT) From: mathieu.poirier@linaro.org To: patches@linaro.org Subject: [PATCH 21/57] power: Overflow in current calculation Date: Thu, 27 Sep 2012 14:08:38 -0600 Message-Id: <1348776554-10019-22-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> References: <1348776554-10019-1-git-send-email-mathieu.poirier@linaro.org> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlPT2gt0uo9Xd0MQD98DkYmnJkOZCu9dbe+VBLkVGtNscjyrxkobQaF+O6ua0JPGZLwedT3 From: Paer-Olof Haakansson When calculating the average current the nominator will overflow when the charging current is high. Signed-off-by: Henrik Sölver Signed-off-by: Mathieu Poirier Reviewed-by: Par-Olof HAKANSSON Reviewed-by: Jonas ABERG --- drivers/power/ab8500_fg.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index 46010ec..7c42150 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -805,15 +805,13 @@ 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->bat->fg_res * (di->fg_samples / 4)); + + di->avg_curr = (di->accu_charge * 36) / + ((di->fg_samples / 4) * 10); di->flags.conv_done = true; @@ -821,6 +819,9 @@ 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->bat->fg_res, di->fg_samples, val, di->accu_charge); return; exit: dev_err(di->dev,