diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2017-12-22 15:57:06 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-01-04 21:52:01 -0800 |
commit | 6bbb5adab171d473f38f1ad9f8f0a1dafff30146 (patch) | |
tree | 35d1930249e0a5f147db152220a35d733b3181d8 /common/charge_state_v2.c | |
parent | 41af1bf27c0e983523a055d2567bc15e7814e289 (diff) | |
download | chrome-ec-6bbb5adab171d473f38f1ad9f8f0a1dafff30146.tar.gz |
charge_state_v2: Add charge_set_output_current_limit function
This function sets up and enables "OTG" mode on the charger chip
(i.e. use the charger to provide power from the battery).
It also records the output current in curr.output_current, to
make sure that the charger loop is aware that current is provided
externally.
We also add a CONFIG_CHARGER_OTG to remove these functions on
boards that do not require it.
BRANCH=none
BUG=b:65697962
TEST=On wand, when discharging, battery status is updated every
5 seconds (and not every 60 seconds).
Change-Id: Ibf93933436f3eb24552a8e1eb9d97522fca2ce79
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/842743
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r-- | common/charge_state_v2.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index c68351e4aa..4ecc48fbcd 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -442,6 +442,9 @@ static void dump_charge_state(void) cflush(); DUMP(requested_voltage, "%dmV"); DUMP(requested_current, "%dmA"); +#ifdef CONFIG_CHARGER_OTG + DUMP(output_current, "%dmA"); +#endif ccprintf("chg_ctl_mode = %d\n", chg_ctl_mode); ccprintf("manual_mode = %d\n", manual_mode); ccprintf("user_current_limit = %dmA\n", user_current_limit); @@ -1092,9 +1095,18 @@ wait_for_it: if (!curr.ac && (curr.state == ST_IDLE || curr.state == ST_DISCHARGE)) { - /* If AP is off, we can sleep a long time */ +#ifdef CONFIG_CHARGER_OTG + int output_current = curr.output_current; +#else + int output_current = 0; +#endif + /* + * If AP is off and we do not provide power, we + * can sleep a long time. + */ if (chipset_in_state(CHIPSET_STATE_ANY_OFF | - CHIPSET_STATE_ANY_SUSPEND)) + CHIPSET_STATE_ANY_SUSPEND) + && output_current == 0) sleep_usec = CHARGE_POLL_PERIOD_VERY_LONG; else @@ -1281,6 +1293,28 @@ int charge_is_consuming_full_input_current(void) return chg_pct > 2 && chg_pct < 95; } +#ifdef CONFIG_CHARGER_OTG +int charge_set_output_current_limit(int ma, int mv) +{ + int ret; + int enable = ma > 0; + + if (enable) { + ret = charger_set_otg_current_voltage(ma, mv); + if (ret != EC_SUCCESS) + return ret; + } + + ret = charger_enable_otg_power(enable); + if (ret != EC_SUCCESS) + return ret; + + curr.output_current = ma; + + return EC_SUCCESS; +} +#endif + int charge_set_input_current_limit(int ma, int mv) { /* |