diff options
author | Aseda Aboagye <aaboagye@google.com> | 2020-05-08 17:22:22 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-06-04 02:50:29 +0000 |
commit | ca454e7f6ec451d7fcee5287534e6b63533b0b2f (patch) | |
tree | 2bd2d0f9ea55b2165cb22c2e52f5996127a83e5d | |
parent | 533c749098b53ec3e640f874dab20dda8adbd086 (diff) | |
download | chrome-ec-ca454e7f6ec451d7fcee5287534e6b63533b0b2f.tar.gz |
OCPC: charger: Add support for VSYS compensation
Some charger ICs can compensate VSYS for losses across the board when
charging from an auxiliary charger in an OCPC scheme. This commit
adds that support to the common charger and OCPC framework such that
it can be leveraged.
Charger ICs which can dynamically compensate and don't need continuous
adjustments should return EC_SUCCESS as the PID won't be needed.
Other chargers should return EC_ERROR_UNIMPLEMENTED since they require
continuous adjustments.
BUG=b:147440290,b:148980016
BRANCH=None
TEST=With driver changes made for RAA48900, build and flash on
waddledoo, verify that charging from the sub board works on board revs
0 and 1.
TEST=`make -j buildall`
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Change-Id: Ie6fb27260b2d6e040dbfdc0aaa5b64b52173037c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2191298
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r-- | common/charger.c | 23 | ||||
-rw-r--r-- | common/ocpc.c | 23 | ||||
-rw-r--r-- | include/charger.h | 29 |
3 files changed, 74 insertions, 1 deletions
diff --git a/common/charger.c b/common/charger.c index aac623d74a..3a980d99df 100644 --- a/common/charger.c +++ b/common/charger.c @@ -624,3 +624,26 @@ int chg_ramp_get_current_limit(void) return rv; } #endif + +enum ec_error_list charger_set_vsys_compensation(int chgnum, + struct ocpc_data *ocpc, + int current_ma, + int voltage_mv) +{ + if ((chgnum < 0) || (chgnum >= chg_cnt)) { + CPRINTS("%s(%d) Invalid charger!", __func__, chgnum); + return EC_ERROR_INVAL; + } + + if (chg_chips[chgnum].drv->set_vsys_compensation) + return chg_chips[chgnum].drv->set_vsys_compensation(chgnum, + ocpc, + current_ma, + voltage_mv); + + /* + * This shouldn't happen as this should only be called on chargers + * that support this. + */ + return EC_ERROR_UNIMPLEMENTED; +} diff --git a/common/ocpc.c b/common/ocpc.c index 0d0a7dc24a..abbbd3fd73 100644 --- a/common/ocpc.c +++ b/common/ocpc.c @@ -66,6 +66,8 @@ int ocpc_config_secondary_charger(int *desired_input_current, int derivative = 0; static enum phase ph; static int prev_limited; + int chgnum; + enum ec_error_list result; /* * There's nothing to do if we're not using this charger. Should @@ -73,9 +75,28 @@ int ocpc_config_secondary_charger(int *desired_input_current, * should change to ensure that only the active charger IC is acted * upon. */ - if (charge_get_active_chg_chip() != SECONDARY_CHARGER) + chgnum = charge_get_active_chg_chip(); + if (chgnum != SECONDARY_CHARGER) return EC_ERROR_INVAL; + result = charger_set_vsys_compensation(chgnum, ocpc, current_ma, + voltage_mv); + switch (result) { + case EC_SUCCESS: + /* No further action required, so we're done here. */ + return EC_SUCCESS; + + case EC_ERROR_UNIMPLEMENTED: + /* Let's get to work */ + break; + + default: + /* Something went wrong configuring the auxiliary charger IC. */ + CPRINTS("Failed to set VSYS compensation! (%d) (result: %d)", + chgnum, result); + return result; + } + if (ocpc->last_vsys == OCPC_UNINIT) ph = PHASE_UNKNOWN; diff --git a/include/charger.h b/include/charger.h index 310643017b..41f22adfad 100644 --- a/include/charger.h +++ b/include/charger.h @@ -9,6 +9,7 @@ #define __CROS_EC_CHARGER_H #include "common.h" +#include "ocpc.h" /* Charger information * voltage unit: mV @@ -106,6 +107,16 @@ struct charger_drv { int (*ramp_is_stable)(int chgnum); int (*ramp_is_detected)(int chgnum); int (*ramp_get_current_limit)(int chgnum); + + /* OCPC functions */ + /* + * Some chargers can perform VSYS output compensation. Configure the + * charger IC with the right parameters. + */ + enum ec_error_list (*set_vsys_compensation)(int chgnum, + struct ocpc_data *o, + int current_ma, + int voltage_mv); }; struct charger_config_t { @@ -251,6 +262,24 @@ enum ec_error_list charger_get_option(int *option); enum ec_error_list charger_set_option(int option); enum ec_error_list charger_set_hw_ramp(int enable); +/** + * Some charger ICs can compensate for board losses if charging from an + * auxiliary charger in a multi-charger IC design. (CONFIG_OCPC) Some of those + * charger ICs can dynamically compensate meaning that the PID loop may not be + * needed. For the others, it still will be needed. The charger driver should + * return the appropriate action. + * + * @param chgnum: Active charge port + * @param ocpc: Pointer to ocpc data + * @param current_ma: Desired charge current + * @param voltage_mv: Desired charge voltage + * @return EC_SUCCESS on success, error otherwise. + */ +enum ec_error_list charger_set_vsys_compensation(int chgnum, + struct ocpc_data *ocpc, + int current_ma, + int voltage_mv); + /* * Print all charger info for debugging purposes * @param chgnum: charger IC index. |