summaryrefslogtreecommitdiff
path: root/common/charge_ramp.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/charge_ramp.c')
-rw-r--r--common/charge_ramp.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/common/charge_ramp.c b/common/charge_ramp.c
index 1c9dfecc33..a5928983fc 100644
--- a/common/charge_ramp.c
+++ b/common/charge_ramp.c
@@ -159,6 +159,7 @@ void chg_ramp_task(void)
static 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++)
@@ -322,19 +323,28 @@ void chg_ramp_task(void)
task_wait_time = STABLE_VBUS_MONITOR_INTERVAL;
break;
}
- if (ramp_st != ramp_st_new || active_icl != active_icl_new)
+ 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;
- /* Set the input current limit */
- lim = chg_ramp_get_current_limit();
- board_set_charge_limit(active_port, active_sup, lim,
- lim, active_vtg);
+ /*
+ * 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) {
+ /* Set the input current limit */
+ lim = chg_ramp_get_current_limit();
+ board_set_charge_limit(active_port, active_sup, lim,
+ lim, active_vtg);
+ }
if (ramp_st == CHG_RAMP_STABILIZE)
/*