diff options
author | Jason Yuan <jasonyuan@google.com> | 2023-01-17 12:59:20 -0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-17 23:44:23 +0000 |
commit | 09a6e247efd4100043d99c6309e1c96afa0bb484 (patch) | |
tree | 59aa0bba5dc760b7a8c08923100290d0eea645e1 | |
parent | 51656776e76fbf3db54c694dc0782d7e02a453c7 (diff) | |
download | chrome-ec-09a6e247efd4100043d99c6309e1c96afa0bb484.tar.gz |
zephyr: test: ps8xxx: Test cache for multiport boards
A new test suite for multi-ps8xxx-port boards is created. A test is
implemented for the cache of firmware version for multiple ps8xxx ports
to be unique.
BUG=b:261874683
TEST=twister
BRANCH=none
Change-Id: I4b540919dca7ffc4fe8109ba1cf10b828341bc30
Signed-off-by: Jason Yuan <jasonyuan@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4175412
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Tested-by: zhi cheng yuan <jasonyuan@chromium.org>
Commit-Queue: zhi cheng yuan <jasonyuan@chromium.org>
Reviewed-by: Sam Hurst <shurst@google.com>
Commit-Queue: Sam Hurst <shurst@google.com>
Auto-Submit: zhi cheng yuan <jasonyuan@chromium.org>
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/Kconfig | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/common/src/stubs.c | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/ps8xxx/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/ps8xxx/prj.conf | 11 | ||||
-rw-r--r-- | zephyr/test/drivers/ps8xxx/src/multi_port.c | 70 | ||||
-rw-r--r-- | zephyr/test/drivers/ps8xxx/usbc.dts | 46 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 4 |
8 files changed, 144 insertions, 3 deletions
diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 5ca57abe1b..a890dd46f8 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -61,6 +61,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_HOST_CMD_THREAD host_command_threa add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PI3USB9201 bc12_pi3usb9201) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MEMMAP memmap) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_COMMON led_common) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PS8XXX ps8xxx) get_target_property(TEST_SOURCES_NEW app SOURCES) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index 2b728c1201..299e4fd3f5 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -85,6 +85,9 @@ config LINK_TEST_SUITE_PANIC_OUTPUT config LINK_TEST_SUITE_POWER_HOST_SLEEP bool "Link and run the power/host_sleep.c specific tests" +config LINK_TEST_SUITE_PS8XXX + bool "Link and test the ps8xxx tests" + config LINK_TEST_SUITE_RT9490 bool "Link and test the rt9490 tests" diff --git a/zephyr/test/drivers/common/src/stubs.c b/zephyr/test/drivers/common/src/stubs.c index accfb426c0..cb0e915017 100644 --- a/zephyr/test/drivers/common/src/stubs.c +++ b/zephyr/test/drivers/common/src/stubs.c @@ -104,11 +104,11 @@ static uint16_t ps8xxx_product_id = PS8805_PRODUCT_ID; uint16_t board_get_ps8xxx_product_id(int port) { - if (port != USBC_PORT_C1) { - return 0; + if (tcpc_config[port].drv == &ps8xxx_tcpm_drv) { + return ps8xxx_product_id; } - return ps8xxx_product_id; + return 0; } void board_set_ps8xxx_product_id(uint16_t product_id) diff --git a/zephyr/test/drivers/ps8xxx/CMakeLists.txt b/zephyr/test/drivers/ps8xxx/CMakeLists.txt new file mode 100644 index 0000000000..2d15560cf0 --- /dev/null +++ b/zephyr/test/drivers/ps8xxx/CMakeLists.txt @@ -0,0 +1,6 @@ +# 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. + +# Add source files +target_sources(app PRIVATE src/multi_port.c) diff --git a/zephyr/test/drivers/ps8xxx/prj.conf b/zephyr/test/drivers/ps8xxx/prj.conf new file mode 100644 index 0000000000..1914f331ef --- /dev/null +++ b/zephyr/test/drivers/ps8xxx/prj.conf @@ -0,0 +1,11 @@ +# 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. + +CONFIG_PLATFORM_EC_USB_PD_TCPC_LOW_POWER=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8745=n +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8745_FORCE_ID=n +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8805=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8805_FORCE_DID=n +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8815=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8815_FORCE_DID=n diff --git a/zephyr/test/drivers/ps8xxx/src/multi_port.c b/zephyr/test/drivers/ps8xxx/src/multi_port.c new file mode 100644 index 0000000000..f3b5d7d066 --- /dev/null +++ b/zephyr/test/drivers/ps8xxx/src/multi_port.c @@ -0,0 +1,70 @@ +/* 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 "driver/tcpm/tcpci.h" +#include "emul/tcpc/emul_ps8xxx.h" +#include "tcpm/tcpm.h" +#include "test/drivers/stubs.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +#include <zephyr/shell/shell.h> +#include <zephyr/ztest.h> + +#define PS8XXX_NODE_0 DT_NODELABEL(ps8xxx_emul0) +#define PS8XXX_NODE_1 DT_NODELABEL(ps8xxx_emul1) + +ZTEST_SUITE(multi_port, drivers_predicate_post_main, NULL, NULL, NULL, NULL); + +const struct emul *ps8xxx_emul_0 = EMUL_DT_GET(PS8XXX_NODE_0); +const struct emul *ps8xxx_emul_1 = EMUL_DT_GET(PS8XXX_NODE_1); + +ZTEST(multi_port, test_multiple_ports) +{ + zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_0, TCPC_REG_BCD_DEV, 2), + "Unable to set device id for emulator 0.\n"); + zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_1, TCPC_REG_BCD_DEV, 3), + "Unable to set device id for emulator 1.\n"); + + struct ec_response_pd_chip_info_v1 info[USBC_PORT_COUNT]; + + for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) { + zassert_ok(tcpm_get_chip_info(p, true, &info[p]), + "Failed to process tcpm_get_chip_info for port %d", + p); + } + + zassert_true(info[USBC_PORT_C0].device_id != + info[USBC_PORT_C1].device_id, + "port 0 and port 1 contains duplicate information.\n"); +} + +ZTEST(multi_port, fw_version_cache) +{ + zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_0, PS8XXX_REG_FW_REV, 0x12), + "Unable to set firmware rev for emulator 0.\n"); + zassert_ok(tcpci_emul_set_reg(ps8xxx_emul_1, PS8XXX_REG_FW_REV, 0x13), + "Unable to set firmware rev for emulator 1.\n"); + + struct ec_response_pd_chip_info_v1 info[USBC_PORT_COUNT]; + + for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) { + zassert_ok(tcpm_get_chip_info(p, true, &info[p]), + "Failed to process tcpm_get_chip_info for port %d", + p); + } + + /* info is read from the cache the second time */ + for (enum usbc_port p = USBC_PORT_C0; p < USBC_PORT_COUNT; p++) { + zassert_ok(tcpm_get_chip_info(p, false, &info[p]), + "Failed to process tcpm_get_chip_info for port %d", + p); + } + + zassert_true(info[USBC_PORT_C0].fw_version_number == 0x12, + "port 0 fw version cache is incorrect.\n"); + zassert_true(info[USBC_PORT_C1].fw_version_number == 0x13, + "port 1 fw version cache is incorrect.\n"); +} diff --git a/zephyr/test/drivers/ps8xxx/usbc.dts b/zephyr/test/drivers/ps8xxx/usbc.dts new file mode 100644 index 0000000000..5bdf9b1696 --- /dev/null +++ b/zephyr/test/drivers/ps8xxx/usbc.dts @@ -0,0 +1,46 @@ +/* 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 <dt-bindings/usb_pd_tcpm.h> + +/ { + usbc { + port0@0 { + compatible = "named-usbc-port"; + tcpc = <&ps8xxx_emul0>; + }; + port1@1 { + compatible = "named-usbc-port"; + tcpc = <&ps8xxx_emul1>; + }; + }; +}; + +&i2c2 { + status="okay"; + + ps8xxx_emul0: ps8xxx_emul@c { + compatible = "cros,ps8xxx-emul"; + reg = <0xc>; + p0-i2c-addr = <0x10>; + p1-i2c-addr = <0x11>; + gpio-i2c-addr = <0x1b>; + }; +}; + +&i2c3 { + status="okay"; + + /delete-node/ ps8xxx_emul@b; + + ps8xxx_emul1: ps8xxx_emul@b { + compatible = "cros,ps8xxx-emul"; + reg = <0xb>; + p0-i2c-addr = <0x8>; + p1-i2c-addr = <0x9>; + gpio-i2c-addr = <0x1a>; + }; + +}; diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index d4fa24355c..3f92f13d86 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -189,6 +189,10 @@ tests: - CONFIG_POWER_SEQUENCE_MOCK=y - CONFIG_PLATFORM_EC_POWERSEQ_HOST_SLEEP=y + drivers.ps8xxx: + extra_args: CONF_FILE="prj.conf;ps8xxx/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./ps8xxx/usbc.dts" + extra_configs: + - CONFIG_LINK_TEST_SUITE_PS8XXX=y drivers.rt9490: extra_args: CONF_FILE="prj.conf;rt9490/prj.conf" DTC_OVERLAY_FILE="./boards/native_posix.overlay;./rt9490/charger.dts" |