aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorpender01 <peter.enderborg@stericsson.com>2013-01-11 08:12:59 -0500
committerAnton Vorontsov <anton@enomsg.org>2013-01-15 20:44:34 -0500
commit6eaf8740dad8820ea708e83f14134401de1cff6e (patch)
tree516db30c051b2084590e1a528584ea9966ab54ae /drivers/power
parent74a8e349b1c882e34419877207ae850ed87dddf7 (diff)
ab8500_fg: Round capacity output
Round the capacity values for better enduser experience. Signed-off-by: Lee Jones <lee.jones@linaro.org> Signed-off-by: pender01 <peter.enderborg@stericsson.com> Reviewed-by: Jonas ABERG <jonas.aberg@stericsson.com> Tested-by: Marcus COOPER <marcus.xm.cooper@stericsson.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/ab8500_fg.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/drivers/power/ab8500_fg.c b/drivers/power/ab8500_fg.c
index d2d14ea681a4..af0374620681 100644
--- a/drivers/power/ab8500_fg.c
+++ b/drivers/power/ab8500_fg.c
@@ -32,6 +32,7 @@
32#include <linux/mfd/abx500/ab8500.h> 32#include <linux/mfd/abx500/ab8500.h>
33#include <linux/mfd/abx500/ab8500-bm.h> 33#include <linux/mfd/abx500/ab8500-bm.h>
34#include <linux/mfd/abx500/ab8500-gpadc.h> 34#include <linux/mfd/abx500/ab8500-gpadc.h>
35#include <linux/kernel.h>
35 36
36#define MILLI_TO_MICRO 1000 37#define MILLI_TO_MICRO 1000
37#define FG_LSB_IN_MA 1627 38#define FG_LSB_IN_MA 1627
@@ -1158,7 +1159,7 @@ static int ab8500_fg_capacity_level(struct ab8500_fg *di)
1158{ 1159{
1159 int ret, percent; 1160 int ret, percent;
1160 1161
1161 percent = di->bat_cap.permille / 10; 1162 percent = DIV_ROUND_CLOSEST(di->bat_cap.permille, 10);
1162 1163
1163 if (percent <= di->bm->cap_levels->critical || 1164 if (percent <= di->bm->cap_levels->critical ||
1164 di->flags.low_bat) 1165 di->flags.low_bat)
@@ -1279,6 +1280,7 @@ static void ab8500_fg_update_cap_scalers(struct ab8500_fg *di)
1279static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init) 1280static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1280{ 1281{
1281 bool changed = false; 1282 bool changed = false;
1283 int percent = DIV_ROUND_CLOSEST(di->bat_cap.permille, 10);
1282 1284
1283 di->bat_cap.level = ab8500_fg_capacity_level(di); 1285 di->bat_cap.level = ab8500_fg_capacity_level(di);
1284 1286
@@ -1310,6 +1312,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1310 dev_dbg(di->dev, "Battery low, set capacity to 0\n"); 1312 dev_dbg(di->dev, "Battery low, set capacity to 0\n");
1311 di->bat_cap.prev_percent = 0; 1313 di->bat_cap.prev_percent = 0;
1312 di->bat_cap.permille = 0; 1314 di->bat_cap.permille = 0;
1315 percent = 0;
1313 di->bat_cap.prev_mah = 0; 1316 di->bat_cap.prev_mah = 0;
1314 di->bat_cap.mah = 0; 1317 di->bat_cap.mah = 0;
1315 changed = true; 1318 changed = true;
@@ -1319,7 +1322,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1319 * and show 100% during maintenance charging (scaling). 1322 * and show 100% during maintenance charging (scaling).
1320 */ 1323 */
1321 if (di->flags.force_full) { 1324 if (di->flags.force_full) {
1322 di->bat_cap.prev_percent = di->bat_cap.permille / 10; 1325 di->bat_cap.prev_percent = percent;
1323 di->bat_cap.prev_mah = di->bat_cap.mah; 1326 di->bat_cap.prev_mah = di->bat_cap.mah;
1324 1327
1325 changed = true; 1328 changed = true;
@@ -1332,19 +1335,18 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1332 di->bat_cap.prev_percent; 1335 di->bat_cap.prev_percent;
1333 di->bat_cap.cap_scale.disable_cap_level = 100; 1336 di->bat_cap.cap_scale.disable_cap_level = 100;
1334 } 1337 }
1335 } else if ( di->bat_cap.prev_percent != 1338 } else if (di->bat_cap.prev_percent != percent) {
1336 (di->bat_cap.permille) / 10) {
1337 dev_dbg(di->dev, 1339 dev_dbg(di->dev,
1338 "battery reported full " 1340 "battery reported full "
1339 "but capacity dropping: %d\n", 1341 "but capacity dropping: %d\n",
1340 di->bat_cap.permille / 10); 1342 percent);
1341 di->bat_cap.prev_percent = di->bat_cap.permille / 10; 1343 di->bat_cap.prev_percent = percent;
1342 di->bat_cap.prev_mah = di->bat_cap.mah; 1344 di->bat_cap.prev_mah = di->bat_cap.mah;
1343 1345
1344 changed = true; 1346 changed = true;
1345 } 1347 }
1346 } else if (di->bat_cap.prev_percent != di->bat_cap.permille / 10) { 1348 } else if (di->bat_cap.prev_percent != percent) {
1347 if (di->bat_cap.permille / 10 == 0) { 1349 if (percent == 0) {
1348 /* 1350 /*
1349 * We will not report 0% unless we've got 1351 * We will not report 0% unless we've got
1350 * the LOW_BAT IRQ, no matter what the FG 1352 * 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)
1354 di->bat_cap.permille = 1; 1356 di->bat_cap.permille = 1;
1355 di->bat_cap.prev_mah = 1; 1357 di->bat_cap.prev_mah = 1;
1356 di->bat_cap.mah = 1; 1358 di->bat_cap.mah = 1;
1359 percent = 1;
1357 1360
1358 changed = true; 1361 changed = true;
1359 } else if (!(!di->flags.charging && 1362 } else if (!(!di->flags.charging &&
1360 (di->bat_cap.permille / 10) > 1363 percent > di->bat_cap.prev_percent) || init) {
1361 di->bat_cap.prev_percent) || init) {
1362 /* 1364 /*
1363 * We do not allow reported capacity to go up 1365 * We do not allow reported capacity to go up
1364 * unless we're charging or if we're in init 1366 * 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)
1366 dev_dbg(di->dev, 1368 dev_dbg(di->dev,
1367 "capacity changed from %d to %d (%d)\n", 1369 "capacity changed from %d to %d (%d)\n",
1368 di->bat_cap.prev_percent, 1370 di->bat_cap.prev_percent,
1369 di->bat_cap.permille / 10, 1371 percent,
1370 di->bat_cap.permille); 1372 di->bat_cap.permille);
1371 di->bat_cap.prev_percent = di->bat_cap.permille / 10; 1373 di->bat_cap.prev_percent = percent;
1372 di->bat_cap.prev_mah = di->bat_cap.mah; 1374 di->bat_cap.prev_mah = di->bat_cap.mah;
1373 1375
1374 changed = true; 1376 changed = true;
@@ -1376,7 +1378,7 @@ static void ab8500_fg_check_capacity_limits(struct ab8500_fg *di, bool init)
1376 dev_dbg(di->dev, "capacity not allowed to go up since " 1378 dev_dbg(di->dev, "capacity not allowed to go up since "
1377 "no charger is connected: %d to %d (%d)\n", 1379 "no charger is connected: %d to %d (%d)\n",
1378 di->bat_cap.prev_percent, 1380 di->bat_cap.prev_percent,
1379 di->bat_cap.permille / 10, 1381 percent,
1380 di->bat_cap.permille); 1382 di->bat_cap.permille);
1381 } 1383 }
1382 } 1384 }