diff options
Diffstat (limited to 'common/charge_ramp_sw.c')
-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, |