diff options
author | Siyu Qin <qinsiyu@huaqin.corp-partner.google.com> | 2023-02-09 17:48:49 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-29 13:39:39 +0000 |
commit | 9e9983c44d17aaf64469aa4e0535bb6754c042a4 (patch) | |
tree | 92a39bb21a209e9d0329f992d2b2730f48a83a2a /zephyr/test | |
parent | cec6e36084ca76f4d30f9f929ea3dfb2fa6ceb30 (diff) | |
download | chrome-ec-9e9983c44d17aaf64469aa4e0535bb6754c042a4.tar.gz |
voltorb: limit type-c output current in S3
According to OEM requirement, if battery power is lower than 30%
in S3, the type-c output current should be limited to 1.5A. For
devices that support PD, change source PDO to 1.5A.
BUG=b:270837688
BRANCH=corsola
TEST=1. zmake build voltorb
2. ./twister --coverage -v -i -T zephyr/test/kingler
Change-Id: I3852a96084f322875fa1117fd41a0b79c6d09afa
Signed-off-by: Siyu Qin <qinsiyu@huaqin.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4235510
Reviewed-by: Ting Shen <phoenixshen@chromium.org>
Reviewed-by: Eric Yilun Lin <yllin@google.com>
Reviewed-by: wen zhang <zhangwen6@huaqin.corp-partner.google.com>
Diffstat (limited to 'zephyr/test')
-rw-r--r-- | zephyr/test/kingler/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/test/kingler/Kconfig | 13 | ||||
-rw-r--r-- | zephyr/test/kingler/src/voltorb_usbc.c | 93 | ||||
-rw-r--r-- | zephyr/test/kingler/testcase.yaml | 6 |
4 files changed, 115 insertions, 0 deletions
diff --git a/zephyr/test/kingler/CMakeLists.txt b/zephyr/test/kingler/CMakeLists.txt index bbf7772361..0cecc14b8f 100644 --- a/zephyr/test/kingler/CMakeLists.txt +++ b/zephyr/test/kingler/CMakeLists.txt @@ -33,3 +33,6 @@ target_sources_ifdef(CONFIG_TEST_ALT_SENSOR_PROBE app PRIVATE src/alt_sensor.c) target_sources_ifdef(CONFIG_TEST_KINGLER_CCD app PRIVATE src/ccd.c ${PLATFORM_EC_PROGRAM_DIR}/corsola/src/board.c) +target_sources_ifdef(CONFIG_TEST_VOLTORB + app PRIVATE src/voltorb_usbc.c + ${PLATFORM_EC_PROGRAM_DIR}/corsola/voltorb/src/usbc.c) diff --git a/zephyr/test/kingler/Kconfig b/zephyr/test/kingler/Kconfig index 930185a5ef..a8449fe8c6 100644 --- a/zephyr/test/kingler/Kconfig +++ b/zephyr/test/kingler/Kconfig @@ -53,4 +53,17 @@ config TEST_KINGLER_CCD help Include alt_sensor.c into the binary to test the alt sensor probe via SSFC. + +config TEST_VOLTORB + bool "Run the tests intended for voltorb" + help + Include voltorb_usbc.c into the binary to test the type-c output + current limit function. + +config TEST_USB_PD_POLICY + bool "Run the tests intended for voltorb usb policy" + help + Include voltorb_usbc.c into the binary to test the type-c output + current limit function. + source "Kconfig.zephyr" diff --git a/zephyr/test/kingler/src/voltorb_usbc.c b/zephyr/test/kingler/src/voltorb_usbc.c new file mode 100644 index 0000000000..c325f86221 --- /dev/null +++ b/zephyr/test/kingler/src/voltorb_usbc.c @@ -0,0 +1,93 @@ +/* Copyright 2023 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "chipset.h" +#include "hooks.h" +#include "usb_pd.h" +#include "usb_pd_dpm_sm.h" + +#include <zephyr/fff.h> +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> + +#define PDO_FIXED_FLAGS \ + (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_COMM_CAP) + +FAKE_VALUE_FUNC(int, charge_get_percent); +FAKE_VALUE_FUNC(int, chipset_in_state, int); +FAKE_VALUE_FUNC(int, tc_is_attached_src, int); + +FAKE_VOID_FUNC(x_ec_interrupt); +FAKE_VOID_FUNC(bmi3xx_interrupt); +FAKE_VOID_FUNC(pd_update_contract, int); +FAKE_VOID_FUNC(check_src_port); +DECLARE_HOOK(HOOK_CHIPSET_SUSPEND, check_src_port, HOOK_PRIO_DEFAULT); +FAKE_VOID_FUNC(resume_src_port); +DECLARE_HOOK(HOOK_CHIPSET_RESUME, resume_src_port, HOOK_PRIO_DEFAULT); + +enum chipset_state_mask fake_chipset_state; + +int chipset_in_state_mock(int state_mask) +{ + return state_mask & fake_chipset_state; +} + +int tc_is_attached_src_mock(int port) +{ + /* Assume type-c port role is source */ + return 1; +} + +uint8_t board_get_usb_pd_port_count(void) +{ + return 2; +} + +ZTEST(current_limit, test_check_src_port) +{ + const int fake_port = 0; + const uint32_t *fake_pdo; + + tc_is_attached_src_fake.custom_fake = tc_is_attached_src_mock; + chipset_in_state_fake.custom_fake = chipset_in_state_mock; + + charge_get_percent_fake.return_val = 20; + fake_chipset_state = CHIPSET_STATE_SUSPEND; + hook_notify(HOOK_CHIPSET_SUSPEND); + k_sleep(K_SECONDS(3)); + zassert_equal(1, check_src_port_fake.call_count); + zassert_equal(1, dpm_get_source_pdo(&fake_pdo, fake_port)); + + charge_get_percent_fake.return_val = 40; + fake_chipset_state = CHIPSET_STATE_SUSPEND; + hook_notify(HOOK_CHIPSET_SUSPEND); + k_sleep(K_SECONDS(3)); + zassert_equal(2, check_src_port_fake.call_count); + + fake_chipset_state = CHIPSET_STATE_SOFT_OFF; + hook_notify(HOOK_CHIPSET_SUSPEND); + k_sleep(K_SECONDS(33)); + zassert_equal(3, check_src_port_fake.call_count); + zassert_equal(1, dpm_get_source_pdo(&fake_pdo, fake_port)); + + /* Assume type-c port role is sink */ + tc_is_attached_src_fake.custom_fake = NULL; + tc_is_attached_src_fake.return_val = 0; + hook_notify(HOOK_CHIPSET_SUSPEND); + k_sleep(K_SECONDS(3)); + zassert_equal(4, check_src_port_fake.call_count); +} + +ZTEST(current_limit, test_resume_src_port) +{ + tc_is_attached_src_fake.custom_fake = tc_is_attached_src_mock; + chipset_in_state_fake.custom_fake = chipset_in_state_mock; + fake_chipset_state = CHIPSET_STATE_ON; + hook_notify(HOOK_CHIPSET_RESUME); + k_sleep(K_SECONDS(3)); + zassert_equal(1, resume_src_port_fake.call_count); +} + +ZTEST_SUITE(current_limit, NULL, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/kingler/testcase.yaml b/zephyr/test/kingler/testcase.yaml index 540664af7d..c6507043f7 100644 --- a/zephyr/test/kingler/testcase.yaml +++ b/zephyr/test/kingler/testcase.yaml @@ -48,3 +48,9 @@ tests: extra_configs: - CONFIG_TEST_STEELIX_RUSTY=y - CONFIG_TEST_ALT_SENSOR_PROBE=y + kingler.voltorb: + extra_args: + DTC_OVERLAY_FILE="kingler.default.overlay" + extra_configs: + - CONFIG_TEST_VOLTORB=y + - CONFIG_TEST_USB_PD_POLICY=y |