diff options
author | Aseda Aboagye <aaboagye@google.com> | 2020-09-25 11:19:23 -0700 |
---|---|---|
committer | Justin TerAvest <teravest@chromium.org> | 2020-09-28 21:57:50 +0000 |
commit | d41bc976a1ade050316ad43eec2b0a3122e8bd3b (patch) | |
tree | 965f6110960c849b78d732b1749c5ad2bbf2569f /common/ocpc.c | |
parent | 17da0aa502f8a550b4d4fd78a02fc9455a469270 (diff) | |
download | chrome-ec-d41bc976a1ade050316ad43eec2b0a3122e8bd3b.tar.gz |
ocpc: Misc fixes for coming out of cutoff
This commit fixes a bug in how OCPC determined which portion of the
charge curve that we are in. Upon startup, the phase is uninitialized
and we get a charge_request of 0,0. The code assumed that if the
battery voltage was less than the desired voltage, we'd be in the CV
state. But ignoring a zero desired voltage prevented us from assuming
we're in CV.
BUG=b:168135339
BRANCH=None
TEST=Build and flash drawcia, cutoff the battery, wait 15s, plug in a
charger on C1, verify that the DUT comes out of cutoff.
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: Id5f36d701c2d4e1608954c898c5bc4f0010dec1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2431695
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/ocpc.c')
-rw-r--r-- | common/ocpc.c | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/common/ocpc.c b/common/ocpc.c index 42963751e3..75876457c4 100644 --- a/common/ocpc.c +++ b/common/ocpc.c @@ -142,6 +142,8 @@ int ocpc_config_secondary_charger(int *desired_input_current, if (chgnum != CHARGER_SECONDARY) return EC_ERROR_INVAL; + batt_info = battery_get_info(); + if (current_ma == 0) { vsys_target = voltage_mv; goto set_vsys; @@ -152,10 +154,9 @@ int ocpc_config_secondary_charger(int *desired_input_current, * charging loop is broken and increasing VSYS will not actually help. * Therefore, don't make any changes at this time. */ - if (battery_is_charge_fet_disabled()) { - /* Only print this if there's actually a CFET present. */ - if (battery_is_present()) - CPRINTS("CFET disabled; not changing VSYS!"); + if (battery_is_charge_fet_disabled() && + (battery_get_disconnect_state() == BATTERY_NOT_DISCONNECTED)) { + CPRINTS("CFET disabled; not changing VSYS!"); /* * Let's check back in 5 seconds to see if the CFET is enabled @@ -231,19 +232,21 @@ int ocpc_config_secondary_charger(int *desired_input_current, } /* Set our current target accordingly. */ - if (batt.voltage < batt.desired_voltage) { - if (ph < PHASE_CV_TRIP) - ph = PHASE_CC; - i_ma = batt.desired_current; - } else{ - /* - * Once the battery voltage reaches the desired voltage, we - * should note that we've reached the CV step and set VSYS to - * the desired CV + offset. - */ - i_ma = batt.current; - ph = ph == PHASE_CC ? PHASE_CV_TRIP : PHASE_CV_COMPLETE; + if (batt.desired_voltage) { + if (batt.voltage < batt.desired_voltage) { + if (ph < PHASE_CV_TRIP) + ph = PHASE_CC; + i_ma = batt.desired_current; + } else{ + /* + * Once the battery voltage reaches the desired voltage, + * we should note that we've reached the CV step and set + * VSYS to the desired CV + offset. + */ + i_ma = batt.current; + ph = ph == PHASE_CC ? PHASE_CV_TRIP : PHASE_CV_COMPLETE; + } } /* Ensure our target is not negative. */ @@ -318,7 +321,9 @@ int ocpc_config_secondary_charger(int *desired_input_current, * desired voltage. */ if (ph >= PHASE_CV_TRIP) - vsys_target = batt.desired_voltage; + vsys_target = batt.desired_voltage + + ((batt_info->precharge_current * + ocpc->combined_rsys_rbatt_mo) / 1000); /* * Ensure VSYS is no higher than the specified maximum battery voltage @@ -342,6 +347,8 @@ int ocpc_config_secondary_charger(int *desired_input_current, prev_limited = 0; set_vsys: + /* VSYS should never be below the battery's min voltage. */ + vsys_target = MAX(vsys_target, batt_info->voltage_min); /* To reduce spam, only print when we change VSYS significantly. */ if ((ABS(vsys_target - ocpc->last_vsys) > 10) || debug_output) CPRINTS("OCPC: Target VSYS: %dmV", vsys_target); |