diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-09-21 14:08:36 -0700 |
---|---|---|
committer | Tom Hughes <tomhughes@chromium.org> | 2022-09-22 12:59:38 -0700 |
commit | c453fd704268ef72de871b0c5ac7a989de662334 (patch) | |
tree | fcf6ce5810f9ff9e3c8cce434812dd75492269ed /zephyr/test/drivers/default/src/bb_retimer.c | |
parent | 6c1587ca70f558b4f96b3f0b18ad8b027d3ba99d (diff) | |
parent | 28712dae9d7ed1e694f7622cc083afa71090d4d5 (diff) | |
download | chrome-ec-c453fd704268ef72de871b0c5ac7a989de662334.tar.gz |
Merge remote-tracking branch cros/main into firmware-fpmcu-dartmonkey-releasefirmware-fpmcu-dartmonkey-release
Generated by: ./util/update_release_branch.py --board dartmonkey --relevant_paths_file
./util/fingerprint-relevant-paths.txt firmware-fpmcu-dartmonkey-release
Relevant changes:
git log --oneline 6c1587ca70..28712dae9d -- board/nocturne_fp
board/dartmonkey common/fpsensor docs/fingerprint driver/fingerprint
util/getversion.sh
ded9307b79 util/getversion.sh: Fix version when not in a git repo
956055e692 board: change Google USB vendor info
71b2ef709d Update license boilerplate text in source code files
33e11afda0 Revert "fpsensor: Build fpsensor source file with C++"
c8d0360723 fpsensor: Build fpsensor source file with C++
bc113abd53 fpsensor: Fix g++ compiler error
150a58a0dc fpsensor: Fix fp_set_sensor_mode return type
b33b5ce85b fpsensor: Remove nested designators for C++ compatibility
2e864b2539 tree-wide: const-ify argv for console commands
56d8b360f9 test: Add test for get ikm failure when seed not set
3a3d6c3690 test: Add test for fpsensor trivial key failure
233e6bbd08 fpsensor_crypto: Abstract calls to hmac_SHA256
0a041b285b docs/fingerprint: Typo correction
c03fab67e2 docs/fingerprint: Fix the path of fputils.py
0b5d4baf5a util/getversion.sh: Fix empty file list handling
6e128fe760 FPMCU dev board environment with Satlab
3eb29b6aa5 builtin: Move ssize_t to sys/types.h
345d62ebd1 docs/fingerprint: Update power numbers for latest dartmonkey release
c25ffdb316 common: Conditionally support printf %l and %i modifiers
9a3c514b45 test: Add a test to check if the debugger is connected
54e603413f Move standard library tests to their own file
43fa6b4bf8 docs/fingerprint: Update power numbers for latest bloonchipper release
25536f9a84 driver/fingerprint/fpc/bep/fpc_sensor_spi.c: Format with clang-format
4face99efd driver/fingerprint/fpc/libfp/fpc_sensor_pal.h: Format with clang-format
738de2b575 trng: Rename rand to trng_rand
14b8270edd docs/fingerprint: Update dragonclaw power numbers
0b268f93d1 driver/fingerprint/fpc/libfp/fpc_private.c: Format with clang-format
f80da163f2 driver/fingerprint/fpc/libfp/fpc_private.h: Format with clang-format
a0751778f4 board/nocturne_fp/ro_workarounds.c: Format with clang-format
5e9c85c9b1 driver/fingerprint/fpc/libfp/fpc_sensor_pal.c: Format with clang-format
c1f9dd3cf8 driver/fingerprint/fpc/libfp/fpc_bio_algorithm.h: Format with clang-format
eb1e1bed8d driver/fingerprint/fpc/libfp/fpc1145_private.h: Format with clang-format
6e7b611821 driver/fingerprint/fpc/bep/fpc_bio_algorithm.h: Format with clang-format
e0589cd5e2 driver/fingerprint/fpc/bep/fpc1035_private.h: Format with clang-format
58f0246dbe board/nocturne_fp/board_ro.c: Format with clang-format
7905e556a0 common/fpsensor/fpsensor_crypto.c: Format with clang-format
21289d170c driver/fingerprint/fpc/bep/fpc1025_private.h: Format with clang-format
98a20f937e common/fpsensor/fpsensor_state.c: Format with clang-format
a2d255d8af common/fpsensor/fpsensor.c: Format with clang-format
84e53a65da board/nocturne_fp/board.h: Format with clang-format
73055eeb3f driver/fingerprint/fpc/bep/fpc_private.c: Format with clang-format
0f7b5cb509 common/fpsensor/fpsensor_private.h: Format with clang-format
1ceade6e65 driver/fingerprint/fpc/bep/fpc_private.h: Format with clang-format
dca9d74321 Revert "trng: Rename rand to trng_rand"
a6b0b3554f trng: Rename rand to trng_rand
28d0b75b70 third_party/boringssl: Remove unused header
BRANCH=None
BUG=b:244387210 b:242720240 b:215613183 b:242720910 b:236386294
BUG=b:234181908 b:244781166 b:234781655 b:234143158 b:234181908
BUG=b:237344361 b:236025198 b:234181908 b:180945056 chromium:1098010
BUG=b:246424843 b:234181908 b:131913998
TEST=`make -j buildall`
TEST=./util/run_device_tests.py --board dartmonkey
Test "aes": PASSED
Test "cec": PASSED
Test "cortexm_fpu": PASSED
Test "crc": PASSED
Test "flash_physical": PASSED
Test "flash_write_protect": PASSED
Test "fpsensor_hw": PASSED
Test "fpsensor_spi_ro": PASSED
Test "fpsensor_spi_rw": PASSED
Test "fpsensor_uart_ro": PASSED
Test "fpsensor_uart_rw": PASSED
Test "mpu_ro": PASSED
Test "mpu_rw": PASSED
Test "mutex": PASSED
Test "pingpong": PASSED
Test "printf": PASSED
Test "queue": PASSED
Test "rollback_region0": PASSED
Test "rollback_region1": PASSED
Test "rollback_entropy": PASSED
Test "rtc": PASSED
Test "sha256": PASSED
Test "sha256_unrolled": PASSED
Test "static_if": PASSED
Test "stdlib": PASSED
Test "system_is_locked_wp_on": PASSED
Test "system_is_locked_wp_off": PASSED
Test "timer_dos": PASSED
Test "utils": PASSED
Test "utils_str": PASSED
Test "panic_data_dartmonkey_v2.0.2887": PASSED
Test "panic_data_nocturne_fp_v2.2.64": PASSED
Test "panic_data_nami_fp_v2.2.144": PASSED
Force-Relevant-Builds: all
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I2c312583a709fedae8fe11d92c22328c3b634bc7
Diffstat (limited to 'zephyr/test/drivers/default/src/bb_retimer.c')
-rw-r--r-- | zephyr/test/drivers/default/src/bb_retimer.c | 578 |
1 files changed, 578 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/bb_retimer.c b/zephyr/test/drivers/default/src/bb_retimer.c new file mode 100644 index 0000000000..74d8fa86a2 --- /dev/null +++ b/zephyr/test/drivers/default/src/bb_retimer.c @@ -0,0 +1,578 @@ +/* Copyright 2021 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr/kernel.h> +#include <zephyr/ztest.h> +#include <zephyr/drivers/gpio.h> +#include <zephyr/drivers/gpio/gpio_emul.h> + +#include "common.h" +#include "ec_tasks.h" +#include "emul/emul_bb_retimer.h" +#include "emul/emul_common_i2c.h" +#include "hooks.h" +#include "i2c.h" +#include "test/drivers/stubs.h" +#include "usb_prl_sm.h" +#include "usb_tc_sm.h" +#include "chipset.h" + +#include "driver/retimer/bb_retimer.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +#define GPIO_USB_C1_LS_EN_PATH DT_PATH(named_gpios, usb_c1_ls_en) +#define GPIO_USB_C1_LS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_LS_EN_PATH, gpios) +#define GPIO_USB_C1_RT_RST_ODL_PATH DT_PATH(named_gpios, usb_c1_rt_rst_odl) +#define GPIO_USB_C1_RT_RST_ODL_PORT \ + DT_GPIO_PIN(GPIO_USB_C1_RT_RST_ODL_PATH, gpios) +#define BB_RETIMER_NODE DT_NODELABEL(usb_c1_bb_retimer_emul) + +/** Test is retimer fw update capable function. */ +ZTEST_USER(bb_retimer, test_bb_is_fw_update_capable) +{ + /* BB retimer is fw update capable */ + zassert_true(bb_usb_retimer.is_retimer_fw_update_capable(), NULL); +} + +/** Test is retimer fw update capable function. */ +ZTEST_USER(bb_retimer_no_tasks, test_bb_set_state) +{ + struct pd_discovery *disc; + uint32_t conn, exp_conn; + const struct emul *emul = EMUL_DT_GET(BB_RETIMER_NODE); + struct i2c_common_emul_data *common_data = + emul_bb_retimer_get_i2c_common_data(emul); + bool ack_required; + + set_test_runner_tid(); + + /* Setup emulator fail on write */ + i2c_common_emul_set_write_fail_reg(common_data, + BB_RETIMER_REG_CONNECTION_STATE); + + /* Test fail on reset register write */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_NONE, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + + /* Do not fail on write */ + i2c_common_emul_set_write_fail_reg(common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Set UFP role for whole test */ + tc_set_data_role(USBC_PORT_C1, PD_ROLE_UFP); + zassume_equal(PD_ROLE_UFP, pd_get_data_role(USBC_PORT_C1), NULL); + + /* Test none mode */ + bb_emul_set_reg(emul, BB_RETIMER_REG_CONNECTION_STATE, 0x12144678); + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_NONE, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + /* Only UFP mode is set */ + exp_conn = BB_RETIMER_USB_DATA_ROLE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test USB3 gen1 mode */ + prl_set_rev(USBC_PORT_C1, TCPCI_MSG_SOP_PRIME, PD_REV10); + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_USB_ENABLED, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_USB_3_CONNECTION; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test USB3 gen2 mode */ + disc = pd_get_am_discovery_and_notify_access(USBC_PORT_C1, + TCPCI_MSG_SOP_PRIME); + disc->identity.product_t1.p_rev30.ss = USB_R30_SS_U32_U40_GEN2; + prl_set_rev(USBC_PORT_C1, TCPCI_MSG_SOP_PRIME, PD_REV30); + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_USB_ENABLED, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_USB_3_CONNECTION | BB_RETIMER_USB_3_SPEED; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test USB4 mode */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_USB4_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_USB4_ENABLED; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test USB4 mode with polarity inverted */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_USB4_ENABLED | + USB_PD_MUX_POLARITY_INVERTED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_CONNECTION_ORIENTATION | BB_RETIMER_USB4_ENABLED; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test DP mode */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_DP_ENABLED, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_DP_ENABLED | + USB_PD_MUX_HPD_IRQ, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_IRQ_HPD; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_DP_ENABLED | + USB_PD_MUX_HPD_LVL, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_USB_DATA_ROLE | + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_HPD_LVL; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); +} + +/** Test setting different options for DFP role */ +ZTEST_USER(bb_retimer_no_tasks, test_bb_set_dfp_state) +{ + union tbt_mode_resp_device device_resp; + union tbt_mode_resp_cable cable_resp; + struct pd_discovery *disc, *dev_disc; + uint32_t conn, exp_conn; + const struct emul *emul = EMUL_DT_GET(BB_RETIMER_NODE); + bool ack_required; + + set_test_runner_tid(); + + tc_set_data_role(USBC_PORT_C1, PD_ROLE_DFP); + zassume_equal(PD_ROLE_DFP, pd_get_data_role(USBC_PORT_C1), NULL); + + /* Test PD mux none mode with DFP should clear all bits in state */ + bb_emul_set_reg(emul, BB_RETIMER_REG_CONNECTION_STATE, 0x12144678); + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_NONE, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = 0; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Set active cable type */ + disc = pd_get_am_discovery_and_notify_access(USBC_PORT_C1, + TCPCI_MSG_SOP_PRIME); + disc->identity.idh.product_type = IDH_PTYPE_ACABLE; + disc->identity.product_t2.a2_rev30.active_elem = ACTIVE_RETIMER; + disc->identity.product_t1.p_rev30.ss = USB_R30_SS_U32_U40_GEN2; + prl_set_rev(USBC_PORT_C1, TCPCI_MSG_SOP_PRIME, PD_REV30); + + /* Set cable VDO */ + disc->svid_cnt = 1; + disc->svids[0].svid = USB_VID_INTEL; + disc->svids[0].discovery = PD_DISC_COMPLETE; + disc->svids[0].mode_cnt = 1; + cable_resp.tbt_alt_mode = TBT_ALTERNATE_MODE; + cable_resp.tbt_cable_speed = TBT_SS_RES_0; + cable_resp.tbt_rounded = TBT_GEN3_NON_ROUNDED; + cable_resp.tbt_cable = TBT_CABLE_NON_OPTICAL; + cable_resp.retimer_type = USB_NOT_RETIMER; + cable_resp.lsrx_comm = BIDIR_LSRX_COMM; + cable_resp.tbt_active_passive = TBT_CABLE_PASSIVE; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + + /* Set device VDO */ + dev_disc = pd_get_am_discovery_and_notify_access(USBC_PORT_C1, + TCPCI_MSG_SOP); + dev_disc->svid_cnt = 1; + dev_disc->svids[0].svid = USB_VID_INTEL; + dev_disc->svids[0].discovery = PD_DISC_COMPLETE; + dev_disc->svids[0].mode_cnt = 1; + device_resp.tbt_alt_mode = TBT_ALTERNATE_MODE; + device_resp.tbt_adapter = TBT_ADAPTER_TBT3; + device_resp.intel_spec_b0 = VENDOR_SPECIFIC_NOT_SUPPORTED; + device_resp.vendor_spec_b0 = VENDOR_SPECIFIC_NOT_SUPPORTED; + device_resp.vendor_spec_b1 = VENDOR_SPECIFIC_NOT_SUPPORTED; + dev_disc->svids[0].mode_vdo[0] = device_resp.raw_value; + + /* Test USB mode with active cable */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_USB_ENABLED, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_USB_3_CONNECTION | BB_RETIMER_USB_3_SPEED | + BB_RETIMER_RE_TIMER_DRIVER | BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with active cable */ + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with retimer */ + cable_resp.retimer_type = USB_RETIMER; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | BB_RETIMER_RE_TIMER_DRIVER | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with optical cable */ + cable_resp.retimer_type = USB_NOT_RETIMER; + cable_resp.tbt_cable = TBT_CABLE_OPTICAL; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | BB_RETIMER_TBT_CABLE_TYPE | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with active link training */ + cable_resp.tbt_cable = TBT_CABLE_NON_OPTICAL; + cable_resp.lsrx_comm = UNIDIR_LSRX_COMM; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_TBT_ACTIVE_LINK_TRAINING | BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with different cable speeds */ + cable_resp.lsrx_comm = BIDIR_LSRX_COMM; + cable_resp.tbt_cable_speed = TBT_SS_U31_GEN1; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_USB4_TBT_CABLE_SPEED_SUPPORT(1) | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + cable_resp.tbt_cable_speed = TBT_SS_U32_GEN1_GEN2; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_USB4_TBT_CABLE_SPEED_SUPPORT(2) | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + cable_resp.tbt_cable_speed = TBT_SS_TBT_GEN3; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_USB4_TBT_CABLE_SPEED_SUPPORT(3) | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with TBT gen4 cable */ + cable_resp.tbt_cable_speed = TBT_SS_RES_0; + cable_resp.tbt_rounded = TBT_GEN3_GEN4_ROUNDED_NON_ROUNDED; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_TBT_CABLE_GENERATION(1) | BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with legacy TBT adapter */ + cable_resp.tbt_rounded = TBT_GEN3_NON_ROUNDED; + disc->svids[0].mode_vdo[0] = cable_resp.raw_value; + device_resp.tbt_adapter = TBT_ADAPTER_TBT2_LEGACY; + dev_disc->svids[0].mode_vdo[0] = device_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | BB_RETIMER_TBT_TYPE | + BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with Intel specific b0 */ + device_resp.tbt_adapter = TBT_ADAPTER_TBT3; + device_resp.intel_spec_b0 = VENDOR_SPECIFIC_SUPPORTED; + dev_disc->svids[0].mode_vdo[0] = device_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = BB_RETIMER_DATA_CONNECTION_PRESENT | + BB_RETIMER_TBT_CONNECTION | BB_RETIMER_ACTIVE_PASSIVE; + + if (IS_ENABLED(CONFIG_USBC_RETIMER_INTEL_BB_VPRO_CAPABLE)) + exp_conn |= BB_RETIMER_VPRO_DOCK_DP_OVERDRIVE; + + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); + + /* Test TBT mode with vendor specific b1 */ + device_resp.intel_spec_b0 = VENDOR_SPECIFIC_NOT_SUPPORTED; + device_resp.vendor_spec_b1 = VENDOR_SPECIFIC_SUPPORTED; + dev_disc->svids[0].mode_vdo[0] = device_resp.raw_value; + zassert_equal(EC_SUCCESS, + bb_usb_retimer.set(usb_muxes[USBC_PORT_C1].mux, + USB_PD_MUX_TBT_COMPAT_ENABLED, + &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + conn = bb_emul_get_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + exp_conn = + BB_RETIMER_DATA_CONNECTION_PRESENT | BB_RETIMER_TBT_CONNECTION | + BB_RETIMER_VPRO_DOCK_DP_OVERDRIVE | BB_RETIMER_ACTIVE_PASSIVE; + zassert_equal(exp_conn, conn, "Expected state 0x%lx, got 0x%lx", + exp_conn, conn); +} + +/** Test BB retimer init */ +ZTEST_USER(bb_retimer, test_bb_init) +{ + const struct device *gpio_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_LS_EN_PATH, gpios)); + const struct emul *emul = EMUL_DT_GET(BB_RETIMER_NODE); + struct i2c_common_emul_data *common_data = + emul_bb_retimer_get_i2c_common_data(emul); + + zassert_not_null(gpio_dev, "Cannot get GPIO device"); + + /* Set AP to normal state and wait for chipset task */ + test_set_chipset_to_s0(); + + /* Setup emulator fail on read */ + i2c_common_emul_set_read_fail_reg(common_data, + BB_RETIMER_REG_VENDOR_ID); + /* Test fail on vendor ID read */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + /* Enable pins should be set always after init, when AP is on */ + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal( + 1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup wrong vendor ID */ + i2c_common_emul_set_read_fail_reg(common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + bb_emul_set_reg(emul, BB_RETIMER_REG_VENDOR_ID, 0x12144678); + /* Test fail on wrong vendor ID */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal( + 1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup emulator fail on device ID read */ + i2c_common_emul_set_read_fail_reg(common_data, + BB_RETIMER_REG_DEVICE_ID); + bb_emul_set_reg(emul, BB_RETIMER_REG_VENDOR_ID, BB_RETIMER_VENDOR_ID_1); + /* Test fail on device ID read */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal( + 1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Setup wrong device ID */ + i2c_common_emul_set_read_fail_reg(common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + bb_emul_set_reg(emul, BB_RETIMER_REG_DEVICE_ID, 0x12144678); + /* Test fail on wrong device ID */ + zassert_equal(EC_ERROR_INVAL, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal( + 1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Test successful init */ + bb_emul_set_reg(emul, BB_RETIMER_REG_DEVICE_ID, BB_RETIMER_DEVICE_ID); + zassert_equal(EC_SUCCESS, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + zassert_equal(1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + zassert_equal( + 1, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); + + /* Set AP to off state and wait for chipset task */ + test_set_chipset_to_g3(); + + /* With AP off, init should fail and pins should be unset */ + zassert_equal(EC_ERROR_NOT_POWERED, + bb_usb_retimer.init(usb_muxes[USBC_PORT_C1].mux), NULL); + zassert_equal(0, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_LS_EN_PORT), + NULL); + + msleep(1); + zassert_equal( + 0, gpio_emul_output_get(gpio_dev, GPIO_USB_C1_RT_RST_ODL_PORT), + NULL); +} + +/** Test BB retimer console command */ +ZTEST_USER(bb_retimer, test_bb_console_cmd) +{ + int rv; + + /* Validate well formed shell commands */ + rv = shell_execute_cmd(get_ec_shell(), "bb 1 r 2"); + zassert_ok(rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb 1 w 2 0"); + zassert_ok(rv, "rv=%d", rv); + + /* Validate errors for malformed shell commands */ + rv = shell_execute_cmd(get_ec_shell(), "bb x"); + zassert_equal(EC_ERROR_PARAM_COUNT, rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb x r 2"); + zassert_equal(EC_ERROR_PARAM1, rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb 0 r 2"); + zassert_equal(EC_ERROR_PARAM1, rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb 1 x 2"); + zassert_equal(EC_ERROR_PARAM2, rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb 1 r x"); + zassert_equal(EC_ERROR_PARAM3, rv, "rv=%d", rv); + rv = shell_execute_cmd(get_ec_shell(), "bb 1 w 2 x"); + zassert_equal(EC_ERROR_PARAM4, rv, "rv=%d", rv); +} + +ZTEST_SUITE(bb_retimer_no_tasks, drivers_predicate_pre_main, NULL, NULL, NULL, + NULL); + +ZTEST_SUITE(bb_retimer, drivers_predicate_post_main, NULL, NULL, NULL, NULL); |