From patchwork Thu Dec 13 15:21:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 13547 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 D0C9123E2A for ; Thu, 13 Dec 2012 15:22:14 +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 61991A18A3A for ; Thu, 13 Dec 2012 15:22:14 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so4139491ieb.11 for ; Thu, 13 Dec 2012 07:22:13 -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 :x-gm-message-state; bh=kN6tevu06pFV6GafnKPmIm5UFDLCnTXwSyQR5h9kIMc=; b=o3PArMeATxB5XLfKmZmvumY8QU63CKtyJYiDq9yC4EG5VTyLrMSIoq9le2zctp8DzU NuSG2klO9P6QJqMgl9Xtuj4sUEEYpiAMnvqA/1ARpR1FM0Wls2sXMzOHTA9cCS7/Bcrm XpRVDKoxW0kriBF/wyuy8iHeAhOqVtvJGNNF3CVO45i7DAhKcnNMQ8/FXZ5/88mx/2RW kswJBmU1U2CFN130/7R/wCj8F/ZR8r+wLkeey0A35oVPEcF2Oa0u+9yZSbod2koVvrEs SEw88KZIRWjb+9qUonZFdnzXDKSMFHT6buqTtPgLt4qflUwhGe4YCXVk3A7bQNm5g3si PEtA== Received: by 10.50.36.164 with SMTP id r4mr1908613igj.57.1355412133707; Thu, 13 Dec 2012 07:22:13 -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 n20csp16264igt; Thu, 13 Dec 2012 07:22:13 -0800 (PST) Received: by 10.180.87.39 with SMTP id u7mr29703134wiz.6.1355412132582; Thu, 13 Dec 2012 07:22:12 -0800 (PST) Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com [209.85.212.175]) by mx.google.com with ESMTPS id gg4si12607899wjb.40.2012.12.13.07.22.12 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:12 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.175 is neither permitted nor denied by best guess record for domain of lee.jones@linaro.org) client-ip=209.85.212.175; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.175 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-wi0-f175.google.com with SMTP id hm11so4006280wib.2 for ; Thu, 13 Dec 2012 07:22:12 -0800 (PST) Received: by 10.194.9.201 with SMTP id c9mr9076137wjb.38.1355412132119; Thu, 13 Dec 2012 07:22:12 -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.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 13 Dec 2012 07:22:11 -0800 (PST) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: cbou@mail.ru, pender01 , Lee Jones Subject: [PATCH 11/18] power: ab8500_fg: Round capacity output Date: Thu, 13 Dec 2012 15:21:34 +0000 Message-Id: <1355412102-14265-12-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> X-Gm-Message-State: ALoCoQkR6VwnwMEny5vUhZWS1OO5brwk4hS2fGYXphIeiVWNygKmP49XcexzUB0DXR+zLpd501Uq From: pender01 Round the capacity values for better enduser experience. Signed-off-by: Lee Jones Signed-off-by: pender01 Reviewed-by: Jonas ABERG Tested-by: Marcus COOPER --- drivers/power/ab8500_fg.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c index c24dba1..5aa981e 100644 --- a/drivers/power/ab8500_fg.c +++ b/drivers/power/ab8500_fg.c @@ -32,6 +32,7 @@ #include #include #include +#include #define MILLI_TO_MICRO 1000 #define FG_LSB_IN_MA 1627 @@ -1158,7 +1159,7 @@ static int ab8500_fg_capacity_level(struct ab8500_fg *di) { int ret, percent; - percent = di->bat_cap.permille / 10; + percent = DIV_ROUND_CLOSEST(di->bat_cap.permille, 10); if (percent <= di->bm->cap_levels->critical || di->flags.low_bat) @@ -1279,6 +1280,7 @@ static void ab8500_fg_update_cap_scalers(struct ab8500_fg *di) static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) { bool changed = false; + int percent = DIV_ROUND_CLOSEST(di->bat_cap.permille, 10); di->bat_cap.level = ab8500_fg_capacity_level(di); @@ -1310,6 +1312,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) dev_dbg(di->dev, "Battery low, set capacity to 0\n"); di->bat_cap.prev_percent = 0; di->bat_cap.permille = 0; + percent = 0; di->bat_cap.prev_mah = 0; di->bat_cap.mah = 0; changed = true; @@ -1319,7 +1322,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) * and show 100% during maintenance charging (scaling). */ if (di->flags.force_full) { - di->bat_cap.prev_percent = di->bat_cap.permille / 10; + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true; @@ -1332,19 +1335,18 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) di->bat_cap.prev_percent; di->bat_cap.cap_scale.disable_cap_level = 100; } - } else if ( di->bat_cap.prev_percent != - (di->bat_cap.permille) / 10) { + } else if (di->bat_cap.prev_percent != percent) { dev_dbg(di->dev, "battery reported full " "but capacity dropping: %d\n", - di->bat_cap.permille / 10); - di->bat_cap.prev_percent = di->bat_cap.permille / 10; + percent); + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true; } - } else if (di->bat_cap.prev_percent != di->bat_cap.permille / 10) { - if (di->bat_cap.permille / 10 == 0) { + } else if (di->bat_cap.prev_percent != percent) { + if (percent == 0) { /* * We will not report 0% unless we've got * the LOW_BAT IRQ, no matter what the FG @@ -1354,11 +1356,11 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) di->bat_cap.permille = 1; di->bat_cap.prev_mah = 1; di->bat_cap.mah = 1; + percent = 1; changed = true; } else if (!(!di->flags.charging && - (di->bat_cap.permille / 10) > - di->bat_cap.prev_percent) || init) { + percent > di->bat_cap.prev_percent) || init) { /* * We do not allow reported capacity to go up * unless we're charging or if we're in init @@ -1366,9 +1368,9 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) dev_dbg(di->dev, "capacity changed from %d to %d (%d)\n", di->bat_cap.prev_percent, - di->bat_cap.permille / 10, + percent, di->bat_cap.permille); - di->bat_cap.prev_percent = di->bat_cap.permille / 10; + di->bat_cap.prev_percent = percent; di->bat_cap.prev_mah = di->bat_cap.mah; changed = true; @@ -1376,7 +1378,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) dev_dbg(di->dev, "capacity not allowed to go up since " "no charger is connected: %d to %d (%d)\n", di->bat_cap.prev_percent, - di->bat_cap.permille / 10, + percent, di->bat_cap.permille); } }