diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2022-11-23 13:18:26 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-02 10:06:15 +0000 |
commit | f2024e853eed7aad2f4d291fcb3e1e528622152d (patch) | |
tree | ea348f461036914f74ced0ff9929840c65568b7f /common | |
parent | 1424acad7097fb51639a8c4003281f78fc0497c8 (diff) | |
download | chrome-ec-f2024e853eed7aad2f4d291fcb3e1e528622152d.tar.gz |
dps: add PDO selection tests
It tests when the selected PDO is aligned to the
system power and the efficient PDO.
1. renames dps.c to dps_config.c
2. adds dps_selection.c
BUG=b:257200275 b:243840939
TEST=./twister -T test
BRANCH=none
Change-Id: Ie4f5e7171a922e63cbb276177a98024e11351245
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4060443
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Commit-Queue: Eric Yilun Lin <yllin@google.com>
Auto-Submit: Eric Yilun Lin <yllin@google.com>
Reviewed-by: Sung-Chi Li <lschyi@chromium.org>
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/dps.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/common/dps.c b/common/dps.c index b0751acc39..8facc57c68 100644 --- a/common/dps.c +++ b/common/dps.c @@ -169,7 +169,7 @@ bool is_more_efficient(int curr_mv, int prev_mv, int batt_mv, int batt_mw, * * @return input_power of the result of vbus * input_curr in mW */ -static int get_desired_input_power(int *vbus, int *input_current) +test_mockable_static int get_desired_input_power(int *vbus, int *input_current) { int active_port; int charger_id; @@ -197,7 +197,7 @@ static int get_desired_input_power(int *vbus, int *input_current) return (*vbus) * (*input_current) / 1000; } -static int get_battery_target_voltage(int *target_mv) +test_mockable_static int get_battery_target_voltage(int *target_mv) { int charger_id = charge_get_active_chg_chip(); int error = charger_get_voltage(charger_id, target_mv); @@ -231,7 +231,7 @@ static int get_battery_target_voltage(int *target_mv) * * @return 0 if error occurs, else battery efficient voltage in mV */ -static int get_efficient_voltage(void) +test_mockable_static int get_efficient_voltage(void) { int eff_mv = 0; int batt_mv; @@ -290,13 +290,20 @@ struct pdo_candidate { return false; \ } while (0) +test_mockable_static int get_batt_charge_power(void) +{ + const struct batt_params *batt = charger_current_battery_params(); + + return batt->current * batt->voltage / 1000; +} + /* * Evaluate the system power if a new PD power request is needed. * * @param struct pdo_candidate: The candidate PDO. (Return value) * @return true if a new power request, or false otherwise. */ -__maybe_unused static bool has_new_power_request(struct pdo_candidate *cand) +test_mockable_static bool has_new_power_request(struct pdo_candidate *cand) { int vbus, input_curr, input_pwr; int input_pwr_avg = 0, input_curr_avg = 0; @@ -311,7 +318,6 @@ __maybe_unused static bool has_new_power_request(struct pdo_candidate *cand) static int prev_active_port = CHARGE_PORT_NONE; static int prev_req_mv; static int moving_avg_count; - const struct batt_params *batt = charger_current_battery_params(); /* set a default value in case it early returns. */ UPDATE_CANDIDATE(CHARGE_PORT_NONE, INT32_MAX, 0); @@ -335,7 +341,7 @@ __maybe_unused static bool has_new_power_request(struct pdo_candidate *cand) prev_req_mv = req_mv; req_pwr = req_mv * req_ma / 1000; - batt_pwr = batt->current * batt->voltage / 1000; + batt_pwr = get_batt_charge_power(); input_pwr = get_desired_input_power(&vbus, &input_curr); if (!input_pwr) |