diff options
author | Eric Yilun Lin <yllin@chromium.org> | 2022-08-19 15:35:52 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-25 06:33:45 +0000 |
commit | b7bcc2ae420f79a2b35f3410d3d1f5a8156eda2d (patch) | |
tree | 7fe6c7623910bf41e313e9c74038ee312af6f007 /common | |
parent | ed5c57252dbd3c577670112a0815c5ce90554706 (diff) | |
download | chrome-ec-b7bcc2ae420f79a2b35f3410d3d1f5a8156eda2d.tar.gz |
zephyr: test: add dps test cases
Setup DPS test environment and add test cases for config and enablement.
BUG=b:243105887
TEST=./twister -T zephyr/test/drivers/ --sub-test drivers.dps
BRANCH=none
Change-Id: I33d5a0c11ff58296c0faa953775220034fb13d92
Signed-off-by: Eric Yilun Lin <yllin@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3841536
Commit-Queue: Eric Yilun Lin <yllin@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: Eric Yilun Lin <yllin@google.com>
Reviewed-by: Yuval Peress <peress@google.com>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/dps.c | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/common/dps.c b/common/dps.c index a19838b867..ee2fd7e65d 100644 --- a/common/dps.c +++ b/common/dps.c @@ -10,6 +10,7 @@ #include "dps.h" #include "atomic.h" #include "battery.h" +#include "common.h" #include "console.h" #include "charger.h" #include "charge_manager.h" @@ -66,6 +67,11 @@ __overridable struct dps_config_t dps_config = { .is_more_efficient = NULL, }; +__test_only struct dps_config_t *dps_get_config(void) +{ + return &dps_config; +} + int dps_get_dynamic_voltage(void) { return dynamic_mv; @@ -81,14 +87,15 @@ bool dps_is_enabled(void) return is_enabled; } -static void dps_enable(bool en) +test_export_static void dps_enable(bool en) { bool prev_en = is_enabled; is_enabled = en; - if (is_enabled && !prev_en) + if (is_enabled && !prev_en) { task_wake(TASK_ID_DPS); + } if (!is_enabled) { /* issue a new PD request for a default voltage */ @@ -121,21 +128,24 @@ static void dps_reset(void) /* * DPS initialization. */ -static void dps_init(void) +test_export_static int dps_init(void) { + int rc = EC_SUCCESS; + dps_reset(); if (dps_config.k_window > MAX_MOVING_AVG_WINDOW) { - dps_config.k_window = MAX_MOVING_AVG_WINDOW; CPRINTS("ERR:WIN"); + rc = EC_ERROR_INVALID_CONFIG; } if (dps_config.k_less_pwr > 100 || dps_config.k_more_pwr > 100 || dps_config.k_more_pwr <= dps_config.k_less_pwr) { - dps_config.k_less_pwr = K_LESS_PWR; - dps_config.k_more_pwr = K_MORE_PWR; CPRINTS("ERR:COEF"); + rc = EC_ERROR_INVALID_CONFIG; } + + return rc; } static bool is_near_limit(int val, int limit) @@ -290,7 +300,7 @@ struct pdo_candidate { * @param struct pdo_candidate: The candidate PDO. (Return value) * @return true if a new power request, or false otherwise. */ -static bool has_new_power_request(struct pdo_candidate *cand) +__maybe_unused 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; @@ -449,7 +459,7 @@ static bool has_new_power_request(struct pdo_candidate *cand) return (cand->mv != req_mv); } -static bool has_srccap(void) +__maybe_unused static bool has_srccap(void) { for (int i = 0; i < board_get_usb_pd_port_count(); ++i) { if (pd_is_connected(i) && @@ -469,8 +479,14 @@ void dps_task(void *u) { struct pdo_candidate last_cand = { CHARGE_PORT_NONE, 0, 0 }; int sample_count = 0; + int rv; + + rv = dps_init(); + if (rv) { + CPRINTS("ERR:INIT%d", rv); + return; + } - dps_init(); update_timeout(dps_config.t_check); while (1) { |