diff options
author | Aseda Aboagye <aaboagye@google.com> | 2020-08-03 14:47:57 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-05 21:59:30 +0000 |
commit | e42d9cb6f88b6174b1ff7c554651f5151e4158f0 (patch) | |
tree | 881532435ba3fde9bf35df2268cdca22d5d68c47 | |
parent | 27fb6197d72e36af030eec3dddce815eead060fe (diff) | |
download | chrome-ec-e42d9cb6f88b6174b1ff7c554651f5151e4158f0.tar.gz |
OCPC: Add flag for ISYS measurement
This commit adds a charger flags member variable to the OCPC data
structure. This allows boards to define certain features that the
chargers that they are using have or don't have. To start, the
attribute of no Isys measurement is added.
BUG=b:155224387
BRANCH=None
TEST=With other CLs, build and flash waddledee, verify that DUT can
calculate combined resistance.
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: I6b8f0a9501e0d79747e42f3444397d7516f01b2f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2335892
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Auto-Submit: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | common/ocpc.c | 32 | ||||
-rw-r--r-- | include/ocpc.h | 5 |
2 files changed, 28 insertions, 9 deletions
diff --git a/common/ocpc.c b/common/ocpc.c index 3b16485690..c8b4d05f36 100644 --- a/common/ocpc.c +++ b/common/ocpc.c @@ -56,7 +56,11 @@ enum phase { enum ec_error_list ocpc_calc_resistances(struct ocpc_data *ocpc, struct batt_params *battery) { - if ((battery->current <= 0) || (ocpc->isys_ma <= 0) || + int act_chg = ocpc->active_chg_chip; + + if ((battery->current <= 0) || + (!(ocpc->chg_flags[act_chg] & OCPC_NO_ISYS_MEAS_CAP) && + (ocpc->isys_ma <= 0)) || (ocpc->vsys_aux_mv < ocpc->vsys_mv)) { CPRINTS_DBG("Not charging... won't determine resistance"); CPRINTS_DBG("vsys_aux_mv: %dmV vsys_mv: %dmV", @@ -68,14 +72,24 @@ enum ec_error_list ocpc_calc_resistances(struct ocpc_data *ocpc, * The combined system and battery resistance is the delta between Vsys * and Vbatt divided by Ibatt. */ - ocpc->rsys_mo = ((ocpc->vsys_aux_mv - ocpc->vsys_mv) * 1000) / - ocpc->isys_ma; - ocpc->rbatt_mo = ((ocpc->vsys_mv - battery->voltage) * 1000) / - battery->current; - ocpc->combined_rsys_rbatt_mo = ocpc->rsys_mo + ocpc->rbatt_mo; - CPRINTS_DBG("Rsys: %dmOhm Rbatt: %dmOhm", ocpc->rsys_mo, - ocpc->rbatt_mo); - + if ((ocpc->chg_flags[act_chg] & OCPC_NO_ISYS_MEAS_CAP)) { + /* + * There's no provision to measure Isys, so we cannot separate + * out Rsys from Rbatt. + */ + ocpc->combined_rsys_rbatt_mo = ((ocpc->vsys_aux_mv - + battery->voltage) * 1000) / + battery->current; + CPRINTS_DBG("Rsys+Rbatt: %dmOhm", ocpc->combined_rsys_rbatt_mo); + } else { + ocpc->rsys_mo = ((ocpc->vsys_aux_mv - ocpc->vsys_mv) * 1000) / + ocpc->isys_ma; + ocpc->rbatt_mo = ((ocpc->vsys_mv - battery->voltage) * 1000) / + battery->current; + ocpc->combined_rsys_rbatt_mo = ocpc->rsys_mo + ocpc->rbatt_mo; + CPRINTS_DBG("Rsys: %dmOhm Rbatt: %dmOhm", ocpc->rsys_mo, + ocpc->rbatt_mo); + } return EC_SUCCESS; } diff --git a/include/ocpc.h b/include/ocpc.h index aeec618863..0e1336873b 100644 --- a/include/ocpc.h +++ b/include/ocpc.h @@ -33,8 +33,13 @@ struct ocpc_data { int last_error; int integral; int last_vsys; +#ifdef HAS_TASK_PD_C1 + uint32_t chg_flags[CONFIG_USB_PD_PORT_MAX_COUNT]; +#endif /* HAS_TASK_PD_C1 */ }; +#define OCPC_NO_ISYS_MEAS_CAP BIT(0) + /** Set the VSYS target for the secondary charger IC. * * @param curr: Pointer to desired_input_current |