From 7ce46148d48fc617b1a35d7fdc7d6c49eb3b5ea7 Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Thu, 22 Dec 2022 18:05:23 +0800 Subject: tentacruel: ppc test This test verifies the ppc chip selecting logic on tentacruel BUG=b:243841599 TEST=twister -T zephyr/test/krabby/ BRANCH=none Change-Id: I46c7840b9a88adab24751dd207e2d9cb9c3dbd21 Signed-off-by: Ting Shen Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4121663 Tested-by: Ting Shen Reviewed-by: Eric Yilun Lin Commit-Queue: Ting Shen Code-Coverage: Zoss --- zephyr/program/corsola/tentacruel/src/ppc.c | 2 +- zephyr/test/krabby/CMakeLists.txt | 2 + zephyr/test/krabby/krabby.tentacruel.overlay | 48 ++++++++++ zephyr/test/krabby/src/fake.c | 6 +- zephyr/test/krabby/src/ppc_tentacruel.c | 138 +++++++++++++++++++++++++++ zephyr/test/krabby/testcase.yaml | 2 + 6 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 zephyr/test/krabby/src/ppc_tentacruel.c diff --git a/zephyr/program/corsola/tentacruel/src/ppc.c b/zephyr/program/corsola/tentacruel/src/ppc.c index d544849296..28f745a14f 100644 --- a/zephyr/program/corsola/tentacruel/src/ppc.c +++ b/zephyr/program/corsola/tentacruel/src/ppc.c @@ -28,7 +28,7 @@ static bool board_has_syv_ppc(void) { static uint32_t board_version = BOARD_VERSION_UNKNOWN; - if (board_version == BOARD_VERSION_UNKNOWN) { + if (board_version == BOARD_VERSION_UNKNOWN || IS_ENABLED(CONFIG_TEST)) { if (cbi_get_board_version(&board_version) != EC_SUCCESS) { LOG_ERR("Failed to get board version."); board_version = 0; diff --git a/zephyr/test/krabby/CMakeLists.txt b/zephyr/test/krabby/CMakeLists.txt index f7361974c6..6e333dd7df 100644 --- a/zephyr/test/krabby/CMakeLists.txt +++ b/zephyr/test/krabby/CMakeLists.txt @@ -25,7 +25,9 @@ target_sources_ifdef(CONFIG_TEST_KRABBY target_sources_ifdef(CONFIG_TEST_TENTACRUEL app PRIVATE src/fake.c + src/ppc_tentacruel.c src/temp_tentacruel.c src/fwconfig_tentacruel.c + ${PLATFORM_EC_PROGRAM_DIR}/corsola/tentacruel/src/ppc.c ${PLATFORM_EC_PROGRAM_DIR}/corsola/tentacruel/src/temp.c ${PLATFORM_EC_PROGRAM_DIR}/corsola/tentacruel/src/sensor.c) diff --git a/zephyr/test/krabby/krabby.tentacruel.overlay b/zephyr/test/krabby/krabby.tentacruel.overlay index 553c19fb69..cd247f15b4 100644 --- a/zephyr/test/krabby/krabby.tentacruel.overlay +++ b/zephyr/test/krabby/krabby.tentacruel.overlay @@ -87,6 +87,25 @@ int_lid_imu: lid_imu { handler = "lid_sensor_interrupt"; }; + + int_usb_c0_ppc: usb_c0_ppc { + irq-pin = <&usb_c0_ppc_int_odl>; + flags = ; + handler = "ppc_interrupt"; + }; + + int_usb_c0_bc12: usb_c0_bc12 { + irq-pin = <&usb_c0_bc12_int_odl>; + flags = ; + handler = "bc12_interrupt"; + }; + + int_x_ec_gpio2: x_ec_gpio2 { + /* We have bypassed the db detection, so link + * int_x_ec_gpio2 to ppc_interrupt directly. + */ + handler = "ppc_interrupt"; + }; }; /* @@ -142,6 +161,16 @@ mutex = <&base_mutex>; }; }; + + usbc { + port0@0 { + ppc = <&bc12_ppc_port0>; + ppc_alt = <&ppc_port0>; + }; + port1@1 { + ppc = <&ppc_port1>; + }; + }; }; &i2c_ctrl0 { @@ -155,6 +184,25 @@ address-width = <8>; timeout = <5>; }; + + ppc_port0: syv682x@44 { + compatible = "silergy,syv682x", "cros,i2c-mock"; + status = "okay"; + reg = <0x44>; + }; + + ppc_port1: syv682x@443 { + compatible = "silergy,syv682x", "cros,i2c-mock"; + status = "okay"; + reg = <0x43>; + }; + + bc12_ppc_port0: rt1739@70 { + compatible = "richtek,rt1739-ppc", "richtek,rt1739-bc12", + "cros,i2c-mock"; + status = "okay"; + reg = <0x70>; + }; }; &lid_accel { diff --git a/zephyr/test/krabby/src/fake.c b/zephyr/test/krabby/src/fake.c index e66ee101e7..846f11eb9d 100644 --- a/zephyr/test/krabby/src/fake.c +++ b/zephyr/test/krabby/src/fake.c @@ -7,6 +7,8 @@ #include +/* LCOV_EXCL_START */ + FAKE_VOID_FUNC(power_button_interrupt, enum gpio_signal); FAKE_VOID_FUNC(button_interrupt, enum gpio_signal); FAKE_VOID_FUNC(lid_interrupt, enum gpio_signal); @@ -17,7 +19,7 @@ FAKE_VOID_FUNC(extpower_interrupt, enum gpio_signal); FAKE_VOID_FUNC(usb_a0_interrupt, enum gpio_signal); FAKE_VOID_FUNC(switch_interrupt, enum gpio_signal); FAKE_VOID_FUNC(spi_event, enum gpio_signal); -FAKE_VOID_FUNC(ppc_interrupt, enum gpio_signal); -FAKE_VOID_FUNC(bc12_interrupt, enum gpio_signal); FAKE_VOID_FUNC(ccd_interrupt, enum gpio_signal); FAKE_VOID_FUNC(x_ec_interrupt, enum gpio_signal); + +/* LCOV_EXCL_STOP */ diff --git a/zephyr/test/krabby/src/ppc_tentacruel.c b/zephyr/test/krabby/src/ppc_tentacruel.c new file mode 100644 index 0000000000..fb6a88cefd --- /dev/null +++ b/zephyr/test/krabby/src/ppc_tentacruel.c @@ -0,0 +1,138 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gpio.h" +#include "gpio/gpio_int.h" +#include "hooks.h" +#include "usbc/ppc.h" + +#include +#include +#include +#include +#include + +FAKE_VALUE_FUNC(int, cbi_get_board_version, uint32_t *); + +static int fake_board_version; + +static int fake_cbi_get_board_version(uint32_t *ver) +{ + *ver = fake_board_version; + return 0; +} + +FAKE_VOID_FUNC(ppc_chip_0_interrupt, int); +FAKE_VOID_FUNC(ppc_chip_alt_interrupt, int); +FAKE_VOID_FUNC(ppc_chip_1_interrupt, int); + +ZTEST(ppc_tentacruel, test_ppc_init) +{ + const struct device *ppc_int_gpio = DEVICE_DT_GET( + DT_GPIO_CTLR(DT_NODELABEL(usb_c0_ppc_int_odl), gpios)); + const gpio_port_pins_t ppc_int_pin = + DT_GPIO_PIN(DT_NODELABEL(usb_c0_ppc_int_odl), gpios); + + /* Board version 0, expect that main ppc is enabled. */ + RESET_FAKE(cbi_get_board_version); + cbi_get_board_version_fake.custom_fake = fake_cbi_get_board_version; + fake_board_version = 0; + hook_notify(HOOK_INIT); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 1), NULL); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 0), NULL); + k_sleep(K_MSEC(100)); + + zassert_equal(ppc_chip_0_interrupt_fake.call_count, 1); + zassert_equal(ppc_chip_alt_interrupt_fake.call_count, 0); + zassert_equal(ppc_chip_1_interrupt_fake.call_count, 0); + + /* CBI access fail, fallback to board version 0 */ + RESET_FAKE(cbi_get_board_version); + cbi_get_board_version_fake.return_val = -1; + fake_board_version = 0; + hook_notify(HOOK_INIT); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 1), NULL); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 0), NULL); + k_sleep(K_MSEC(100)); + + zassert_equal(ppc_chip_0_interrupt_fake.call_count, 2); + zassert_equal(ppc_chip_alt_interrupt_fake.call_count, 0); + zassert_equal(ppc_chip_1_interrupt_fake.call_count, 0); + + /* Board version 3, expect that alt ppc is enabled. + * Since PPC_ENABLE_ALTERNATE() is not reversible, we must test this + * after the board version 0 test. + */ + RESET_FAKE(cbi_get_board_version); + cbi_get_board_version_fake.custom_fake = fake_cbi_get_board_version; + fake_board_version = 3; + hook_notify(HOOK_INIT); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 1), NULL); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(ppc_int_gpio, ppc_int_pin, 0), NULL); + k_sleep(K_MSEC(100)); + + zassert_equal(ppc_chip_0_interrupt_fake.call_count, 2); + zassert_equal(ppc_chip_alt_interrupt_fake.call_count, 1); + zassert_equal(ppc_chip_1_interrupt_fake.call_count, 0); +} + +ZTEST(ppc_tentacruel, test_ppc_1_int) +{ + const struct device *x_ec_gpio2 = DEVICE_DT_GET( + DT_GPIO_CTLR(DT_NODELABEL(gpio_x_ec_gpio2), gpios)); + const gpio_port_pins_t x_ec_gpio2_pin = + DT_GPIO_PIN(DT_NODELABEL(gpio_x_ec_gpio2), gpios); + + zassert_ok(gpio_emul_input_set(x_ec_gpio2, x_ec_gpio2_pin, 1), NULL); + k_sleep(K_MSEC(100)); + zassert_ok(gpio_emul_input_set(x_ec_gpio2, x_ec_gpio2_pin, 0), NULL); + k_sleep(K_MSEC(100)); + + zassert_equal(ppc_chip_0_interrupt_fake.call_count, 0); + zassert_equal(ppc_chip_alt_interrupt_fake.call_count, 0); + zassert_equal(ppc_chip_1_interrupt_fake.call_count, 1); +} + +static void *ppc_tentacruel_init(void) +{ + static struct ppc_drv fake_ppc_drv_0; + static struct ppc_drv fake_ppc_drv_1; + static struct ppc_drv fake_ppc_drv_alt; + + zassert_equal(ppc_cnt, 2); + + /* inject mocked interrupt handlers into ppc_drv and ppc_drv_alt */ + fake_ppc_drv_0 = *ppc_chips[0].drv; + fake_ppc_drv_0.interrupt = ppc_chip_0_interrupt; + ppc_chips[0].drv = &fake_ppc_drv_0; + + fake_ppc_drv_alt = *ppc_chips_alt[0].drv; + fake_ppc_drv_alt.interrupt = ppc_chip_alt_interrupt; + ppc_chips_alt[0].drv = &fake_ppc_drv_alt; + + fake_ppc_drv_1 = *ppc_chips[1].drv; + fake_ppc_drv_1.interrupt = ppc_chip_1_interrupt; + ppc_chips[1].drv = &fake_ppc_drv_1; + + return NULL; +} + +static void ppc_tentacruel_before(void *fixture) +{ + RESET_FAKE(cbi_get_board_version); + RESET_FAKE(ppc_chip_0_interrupt); + RESET_FAKE(ppc_chip_alt_interrupt); + RESET_FAKE(ppc_chip_1_interrupt); + + /* We have bypassed the db detection, so we force enabling the + * int_x_ec_gpio2. + */ + gpio_enable_dt_interrupt(GPIO_INT_FROM_NODELABEL(int_x_ec_gpio2)); +} +ZTEST_SUITE(ppc_tentacruel, NULL, ppc_tentacruel_init, ppc_tentacruel_before, + NULL, NULL); diff --git a/zephyr/test/krabby/testcase.yaml b/zephyr/test/krabby/testcase.yaml index 3a8c0770e1..c579526d83 100644 --- a/zephyr/test/krabby/testcase.yaml +++ b/zephyr/test/krabby/testcase.yaml @@ -25,3 +25,5 @@ tests: - CONFIG_PLATFORM_EC_LID_ANGLE=y - CONFIG_PLATFORM_EC_ACCELGYRO_BMI260=y - CONFIG_PLATFORM_EC_ACCELGYRO_BMI_COMM_I2C=y + - CONFIG_PLATFORM_EC_USBC_PPC_RT1739=y + - CONFIG_PLATFORM_EC_BC12_SINGLE_DRIVER=n -- cgit v1.2.1