diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-09-21 14:48:47 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-09-24 10:56:50 -0700 |
commit | 8b592052cea122105996f13a8cb2e44ea22449fc (patch) | |
tree | 10f1bcdb051a403141f1c072f37ce72e8049d8b4 /common/charger_bq24725.c | |
parent | 3c4f66648d74fea0937478042c26c4e729d47e58 (diff) | |
download | chrome-ec-8b592052cea122105996f13a8cb2e44ea22449fc.tar.gz |
Only ask the charger for current steps it can supply
This reduces oscillations in the charging algorithm. This change also adds
more debug output so it's easier to see what the charging state machine is
doing.
BUG=chrome-os-partner:9572
BRANCH=link
TEST=discharge battery; charge battery; note infrequent but useful debug output
Change-Id: I4c8609c2ca8a6cab3eae151ecf2bb1520103fece
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/33811
Reviewed-by: Rong Chang <rongchang@chromium.org>
Diffstat (limited to 'common/charger_bq24725.c')
-rw-r--r-- | common/charger_bq24725.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/common/charger_bq24725.c b/common/charger_bq24725.c index 84dc8897a2..11077301a7 100644 --- a/common/charger_bq24725.c +++ b/common/charger_bq24725.c @@ -134,17 +134,28 @@ int charger_get_current(int *current) return EC_SUCCESS; } -int charger_set_current(int current) +int charger_closest_current(int current) { - const struct charger_info *info = charger_get_info(); + const struct charger_info * const info = charger_get_info(); - /* Clip the charge current to the range the charger can supply. This - * is a temporary workaround for the battery requesting a very small - * current for trickle-charging. See crosbug.com/p/8662. */ + /* + * If the requested current is non-zero but below our minimum, + * return the minimum. See crosbug.com/p/8662. + */ if (current > 0 && current < info->current_min) - current = info->current_min; + return info->current_min; + + /* Clip to max */ if (current > info->current_max) - current = info->current_max; + return info->current_max; + + /* Otherwise round down to nearest current step */ + return current - (current % info->current_step); +} + +int charger_set_current(int current) +{ + current = charger_closest_current(current); return sbc_write(SB_CHARGING_CURRENT, CURRENT_TO_REG(current, R_SNS)); } |