diff options
Diffstat (limited to 'zephyr/test/drivers')
-rw-r--r-- | zephyr/test/drivers/overlay.dts | 21 | ||||
-rw-r--r-- | zephyr/test/drivers/prj.conf | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/src/bb_retimer.c | 426 | ||||
-rw-r--r-- | zephyr/test/drivers/src/main.c | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/src/stubs.c | 24 |
5 files changed, 472 insertions, 3 deletions
diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts index 4d650551fa..8e557b31bf 100644 --- a/zephyr/test/drivers/overlay.dts +++ b/zephyr/test/drivers/overlay.dts @@ -44,6 +44,16 @@ enum-name = "GPIO_EC_PCH_WAKE_ODL"; label = "EC_PCH_WAKE_ODL"; }; + usb_c1_ls_en { + gpios = <&gpio0 6 (GPIO_INPUT | GPIO_PULL_UP)>; + enum-name = "GPIO_USB_C1_LS_EN"; + label = "USB_C1_LS_EN"; + }; + usb_c1_rt_rst_odl { + gpios = <&gpio0 7 GPIO_ODR_LOW>; + enum-name = "GPIO_USB_C1_RT_RST_ODL"; + label = "USB_C1_RT_RST_ODL"; + }; }; named-i2c-ports { compatible = "named-i2c-ports"; @@ -407,7 +417,7 @@ }; &gpio0 { - ngpios = <6>; + ngpios = <8>; }; &i2c0 { @@ -462,4 +472,13 @@ error-on-reserved-bit-write; simulate-command-exec-time; }; + + usb_c1_bb_retimer_emul: bbretimer@42 { + compatible = "cros,bb-retimer-emul"; + reg = <0x42>; + label = "USB_C1_BB_RETIMER"; + vendor = "BB_RETIMER_VENDOR_ID_1"; + error-on-ro-write; + error-on-reserved-bit-write; + }; }; diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index 4ba0efc2a0..ed0b27432a 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -21,6 +21,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=1024 CONFIG_EMUL_BMA255=y CONFIG_EMUL_BMI=y CONFIG_EMUL_TCS3400=y +CONFIG_EMUL_BB_RETIMER=y CONFIG_PLATFORM_EC_BATTERY_PRESENT_GPIO=y CONFIG_PLATFORM_EC_EXTPOWER_GPIO=y @@ -60,6 +61,7 @@ CONFIG_PLATFORM_EC_ACCEL_INTERRUPTS=y CONFIG_PLATFORM_EC_ACCEL_FIFO=y CONFIG_PLATFORM_EC_SENSOR_TIGHT_TIMESTAMPS=y CONFIG_PLATFORM_EC_ALS_TCS3400=y +CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB=y CONFIG_ESPI=y CONFIG_ESPI_EMUL=y diff --git a/zephyr/test/drivers/src/bb_retimer.c b/zephyr/test/drivers/src/bb_retimer.c new file mode 100644 index 0000000000..ac53df4779 --- /dev/null +++ b/zephyr/test/drivers/src/bb_retimer.c @@ -0,0 +1,426 @@ +/* Copyright 2021 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include <zephyr.h> +#include <ztest.h> + +#include "common.h" +#include "ec_tasks.h" +#include "emul/emul_bb_retimer.h" +#include "hooks.h" +#include "i2c.h" +#include "stubs.h" +#include "usb_prl_sm.h" +#include "usb_tc_sm.h" + +#include "driver/retimer/bb_retimer.h" + +#define EMUL_LABEL DT_NODELABEL(usb_c1_bb_retimer_emul) + +#define BB_RETIMER_ORD DT_DEP_ORD(EMUL_LABEL) + +/** Test is retimer fw update capable function. */ +static void test_bb_is_fw_update_capable(void) +{ + /* BB retimer is fw update capable */ + zassert_true(bb_usb_retimer.is_retimer_fw_update_capable(), NULL); +} + +/** Test is retimer fw update capable function. */ +static void test_bb_set_state(void) +{ + struct pd_discovery *disc; + uint32_t conn, exp_conn; + struct i2c_emul *emul; + bool ack_required; + + emul = bb_emul_get(BB_RETIMER_ORD); + + set_test_runner_tid(); + + /* Setup emulator fail on write */ + bb_emul_set_write_fail_reg(emul, BB_RETIMER_REG_CONNECTION_STATE); + + /* Test fail on reset register write */ + zassert_equal(-EIO, bb_usb_retimer.set(&usb_muxes[USBC_PORT_C1], + USB_PD_MUX_NONE, &ack_required), + NULL); + zassert_false(ack_required, "ACK is never required for BB retimer"); + + /* Do not fail on write */ + bb_emul_set_write_fail_reg(emul, BB_EMUL_NO_FAIL_REG); + + /* Set UFP role for whole test */ + tc_set_data_role(USBC_PORT_C1, PD_ROLE_UFP); + + /* 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], + 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], + 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(USBC_PORT_C1, TCPCI_MSG_SOP_PRIME); + disc->identity.product_t1.p_rev20.ss = USB_R20_SS_U31_GEN1_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], + 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], + 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], + 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], + 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], + 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 | + BB_RETIMER_DP_CONNECTION; + 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], + 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_DP_CONNECTION | + 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], + 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_DP_CONNECTION | + 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 */ +static void test_bb_set_dfp_state(void) +{ + 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; + struct i2c_emul *emul; + bool ack_required; + + emul = bb_emul_get(BB_RETIMER_ORD); + + set_test_runner_tid(); + + tc_set_data_role(USBC_PORT_C1, PD_ROLE_DFP); + + /* 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], + 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(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; + 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(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], + 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], + 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], + 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], + 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], + 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], + 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], + 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], + 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], + 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], + 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], + 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 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], + 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); +} + +void test_suite_bb_retimer(void) +{ + ztest_test_suite(bb_retimer, + ztest_user_unit_test(test_bb_is_fw_update_capable), + ztest_user_unit_test(test_bb_set_state), + ztest_user_unit_test(test_bb_set_dfp_state)); + ztest_run_test_suite(bb_retimer); +} diff --git a/zephyr/test/drivers/src/main.c b/zephyr/test/drivers/src/main.c index 46fd462283..3336baeda5 100644 --- a/zephyr/test/drivers/src/main.c +++ b/zephyr/test/drivers/src/main.c @@ -19,6 +19,7 @@ extern void test_suite_bmi260(void); extern void test_suite_bmi160(void); extern void test_suite_tcs3400(void); extern void test_suite_espi(void); +extern void test_suite_bb_retimer(void); void test_main(void) { @@ -39,4 +40,5 @@ void test_main(void) test_suite_bmi160(); test_suite_tcs3400(); test_suite_espi(); + test_suite_bb_retimer(); } diff --git a/zephyr/test/drivers/src/stubs.c b/zephyr/test/drivers/src/stubs.c index ed7a8f2c8a..62d037d718 100644 --- a/zephyr/test/drivers/src/stubs.c +++ b/zephyr/test/drivers/src/stubs.c @@ -127,6 +127,12 @@ int board_is_sourcing_vbus(int port) return 0; } +struct usb_mux usbc1_virtual_usb_mux = { + .usb_port = USBC_PORT_C1, + .driver = &virtual_usb_mux_driver, + .hpd_update = &virtual_hpd_update, +}; + struct usb_mux usb_muxes[] = { [USBC_PORT_C0] = { .usb_port = USBC_PORT_C0, @@ -135,12 +141,26 @@ struct usb_mux usb_muxes[] = { }, [USBC_PORT_C1] = { .usb_port = USBC_PORT_C1, - .driver = &virtual_usb_mux_driver, - .hpd_update = &virtual_hpd_update, + .driver = &bb_usb_retimer, + .next_mux = &usbc1_virtual_usb_mux, + .i2c_port = I2C_PORT_USB_C1, + .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL( + usb_c1_bb_retimer_emul)), }, }; BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT); +struct bb_usb_control bb_controls[] = { + [USBC_PORT_C0] = { + /* USB-C port 0 doesn't have a retimer */ + }, + [USBC_PORT_C1] = { + .usb_ls_en_gpio = GPIO_USB_C1_LS_EN, + .retimer_rst_gpio = GPIO_USB_C1_RT_RST_ODL, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(bb_controls) == USBC_PORT_COUNT); + void pd_power_supply_reset(int port) { } |