diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-06-10 10:54:24 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-06-25 01:21:31 +0000 |
commit | 0c6820b6fb2f8f2f4fdfe0f2612cb0c766059644 (patch) | |
tree | f651fba0a93f605723fd72745f264596a79f7497 | |
parent | 52e914fa8e674f61b9602f124e998a74adbc2b61 (diff) | |
download | chrome-ec-0c6820b6fb2f8f2f4fdfe0f2612cb0c766059644.tar.gz |
chg_sw_ramp: Don't set charge limit if ramping is stable
Currently, the charge limit is set repeatedly even when the ramping is
stable.
This patch makes chg_ramp_task sleep until
chg_ramp_charge_supplier_change and skip board_set_charge_limit if
ramping is stable.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/131284131,b/36468002
BRANCH=none
TEST=buildall
Change-Id: I701ffaf149627582bf7bcb4660420d4f9438ad94
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1650217
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Yilun Lin <yllin@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Sean Abraham <seanabraham@chromium.org>
-rw-r--r-- | common/charge_ramp_sw.c | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/common/charge_ramp_sw.c b/common/charge_ramp_sw.c index d572115043..1e1289654e 100644 --- a/common/charge_ramp_sw.c +++ b/common/charge_ramp_sw.c @@ -152,19 +152,23 @@ void chg_ramp_task(void *u) uint64_t detect_end_time_us = 0, time_us; int last_active_port = CHARGE_PORT_NONE; - /* - * Static initializer so that we don't clobber early calls to this - * module. - */ - static enum chg_ramp_state ramp_st_prev = CHG_RAMP_DISCONNECTED, + enum chg_ramp_state ramp_st_prev = CHG_RAMP_DISCONNECTED, ramp_st_new = CHG_RAMP_DISCONNECTED; int active_icl_new; - static uint8_t values_have_changed_at_least_once; /* Clear last OCP supplier to guarantee we ramp on first connect */ for (i = 0; i < CONFIG_USB_PD_PORT_COUNT; i++) oc_info[i][0].sup = CHARGE_SUPPLIER_NONE; + /* + * Sleep until chg_ramp_charge_supplier_change is called to avoid + * setting input current limit to zero. chg_ramp_charge_supplier_change + * won't be called until charge_manager is ready to call + * board_set_charge_limit by itself (if there is no chg_ramp_task). + */ + if (!IS_ENABLED(TEST_BUILD)) + task_wait_event(-1); + while (1) { ramp_st_new = ramp_st; active_icl_new = active_icl; @@ -323,23 +327,16 @@ void chg_ramp_task(void *u) task_wait_time = STABLE_VBUS_MONITOR_INTERVAL; break; } - if (ramp_st != ramp_st_new || active_icl != active_icl_new) { - CPRINTS("Ramp p%d st%d %dmA %dmA", - active_port, ramp_st_new, min_icl, - active_icl_new); - values_have_changed_at_least_once = 1; - } ramp_st_prev = ramp_st; ramp_st = ramp_st_new; active_icl = active_icl_new; - /* - * Don't perform any action unless something has changed. - * Otherwise, when the task starts, we may try and set a current - * limit that's invalid/uninitialized. - */ - if (values_have_changed_at_least_once) { + /* Skip setting limit if status is stable twice in a row */ + if (ramp_st_prev != CHG_RAMP_STABLE || + ramp_st != CHG_RAMP_STABLE) { + CPRINTS("Ramp p%d st%d %dmA %dmA", + active_port, ramp_st, min_icl, active_icl); /* Set the input current limit */ lim = chg_ramp_get_current_limit(); board_set_charge_limit(active_port, active_sup, lim, |