summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2022-11-10 15:15:59 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-11 19:42:30 +0000
commit50ca1e0aa37d48ea42e96591a0dc41abd5526b5a (patch)
treee0a9e5bc86725b5ddaf125cbabf277e568aff08a
parent6acfadf0df547a86b1dfddb3f5487d606774be6a (diff)
downloadchrome-ec-50ca1e0aa37d48ea42e96591a0dc41abd5526b5a.tar.gz
test: usb_mux: use devicetrees
Update the tests to use the "cros-ec,usb-mux-chain" to specify the USB muxes under test instead of hard coding via stubs. BUG=b:239457738 BRANCH=none TEST=twister Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I5a5acaf0b3815558454d4ec886e1058e4ccf36ea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4023767 Reviewed-by: Abe Levkoy <alevkoy@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/test/drivers/boards/native_posix.overlay24
-rw-r--r--zephyr/test/drivers/common/include/test/drivers/stubs.h4
-rw-r--r--zephyr/test/drivers/common/src/stubs.c62
-rw-r--r--zephyr/test/drivers/default/boards/native_posix.overlay34
-rw-r--r--zephyr/test/drivers/default/src/tcpci.c10
-rw-r--r--zephyr/test/drivers/default/src/usb_mux.c35
-rw-r--r--zephyr/test/drivers/prj.conf1
-rw-r--r--zephyr/test/drivers/testcase.yaml3
-rw-r--r--zephyr/test/drivers/usbc_svdm_dfp_only/boards/native_posix.overlay23
-rw-r--r--zephyr/test/drivers/usbc_svdm_dfp_only/prj.conf1
-rw-r--r--zephyr/test/vboot_efs2/boards/native_posix.overlay9
-rw-r--r--zephyr/test/vboot_efs2/src/main.c11
12 files changed, 131 insertions, 86 deletions
diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay
index 4458df9703..e8c0667cb3 100644
--- a/zephyr/test/drivers/boards/native_posix.overlay
+++ b/zephyr/test/drivers/boards/native_posix.overlay
@@ -60,6 +60,19 @@
chg = <&isl923x_emul>;
tcpc = <&tcpci_emul>;
ppc = <&sn5s330_emul>;
+ usb-mux-chain-0 {
+ compatible = "cros-ec,usb-mux-chain";
+ usb-muxes = <&tcpci_mux_c0
+ &virtual_mux_c0>;
+ };
+ };
+ port0-muxes {
+ tcpci_mux_c0: tcpci-mux-c0 {
+ compatible = "cros-ec,usbc-mux-tcpci";
+ };
+ virtual_mux_c0: virtual-mux-c0 {
+ compatible = "cros-ec,usbc-mux-virtual";
+ };
};
port1@1 {
@@ -67,6 +80,16 @@
reg = <1>;
tcpc = <&ps8xxx_emul>;
ppc = <&syv682x_emul>;
+ usb-mux-chain-1 {
+ compatible = "cros-ec,usb-mux-chain";
+ usb-muxes = <&usb_c1_bb_retimer_emul
+ &virtual_mux_c1>;
+ };
+ };
+ port1-muxes {
+ virtual_mux_c1: virtual-mux-c1 {
+ compatible = "cros-ec,usbc-mux-virtual";
+ };
};
};
@@ -815,6 +838,7 @@
compatible = "intel,jhl8040r";
reg = <0x42>;
reset-pin = <&usb_c1_rt_rst_odl>;
+ ls-en-pin = <&usb_c1_ls_en>;
};
ps8xxx_emul: ps8xxx_emul@b {
diff --git a/zephyr/test/drivers/common/include/test/drivers/stubs.h b/zephyr/test/drivers/common/include/test/drivers/stubs.h
index 98f3fa1d15..8a739fa866 100644
--- a/zephyr/test/drivers/common/include/test/drivers/stubs.h
+++ b/zephyr/test/drivers/common/include/test/drivers/stubs.h
@@ -11,10 +11,6 @@
enum usbc_port { USBC_PORT_C0 = 0, USBC_PORT_C1, USBC_PORT_COUNT };
-/* Structure used by usb_mux test. It is part of usb_muxes chain. */
-extern struct usb_mux usbc1_virtual_usb_mux;
-extern struct usb_mux usbc0_mux0;
-
/**
* @brief Set product ID that should be returned by board_get_ps8xxx_product_id
*
diff --git a/zephyr/test/drivers/common/src/stubs.c b/zephyr/test/drivers/common/src/stubs.c
index d07683017f..98b5d5bc3c 100644
--- a/zephyr/test/drivers/common/src/stubs.c
+++ b/zephyr/test/drivers/common/src/stubs.c
@@ -148,68 +148,6 @@ int board_is_sourcing_vbus(int port)
return ppc_is_sourcing_vbus(port);
}
-/* TODO(b/239457738): Move to dts */
-struct usb_mux_chain usbc0_virtual_usb_mux_chain = {
- .mux =
- &(const struct usb_mux){
- .usb_port = USBC_PORT_C0,
- .driver = &virtual_usb_mux_driver,
- .hpd_update = &virtual_hpd_update,
- },
-};
-
-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_chain usbc1_virtual_usb_mux_chain = {
- .mux = &usbc1_virtual_usb_mux,
-};
-
-struct usb_mux usbc0_mux0 = {
- .usb_port = USBC_PORT_C0,
- .driver = &tcpci_tcpm_usb_mux_driver,
- .i2c_port = I2C_PORT_USB_C0,
- .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL(tcpci_emul)),
-};
-
-struct usb_mux_chain usb_muxes[] = {
- [USBC_PORT_C0] = {
- .mux = &usbc0_mux0,
- .next = &usbc0_virtual_usb_mux_chain,
- },
- [USBC_PORT_C1] = {
-#ifdef CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB
- .mux = &(const struct usb_mux){
- .usb_port = USBC_PORT_C1,
- .driver = &bb_usb_retimer,
- .hpd_update = bb_retimer_hpd_update,
- .i2c_port = I2C_PORT_USB_C1,
- .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL(
- usb_c1_bb_retimer_emul)),
- },
- .next = &usbc1_virtual_usb_mux_chain,
-#endif
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(usb_muxes) == USBC_PORT_COUNT);
-
-#ifdef CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB
-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_SIGNAL(DT_NODELABEL(usb_c1_ls_en)),
- .retimer_rst_gpio =
- GPIO_SIGNAL(DT_NODELABEL(usb_c1_rt_rst_odl)),
- },
-};
-BUILD_ASSERT(ARRAY_SIZE(bb_controls) == USBC_PORT_COUNT);
-#endif
-
void pd_power_supply_reset(int port)
{
}
diff --git a/zephyr/test/drivers/default/boards/native_posix.overlay b/zephyr/test/drivers/default/boards/native_posix.overlay
new file mode 100644
index 0000000000..a5e73e5653
--- /dev/null
+++ b/zephyr/test/drivers/default/boards/native_posix.overlay
@@ -0,0 +1,34 @@
+/* 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 "../../boards/native_posix.overlay"
+
+/*
+ * The TCPCI test verfies the mux behavior in two configurations:
+ * flags = USB_MUX_FLAG_NOT_TCPC;
+ * flags = 0;
+ *
+ * When USB_MUX_FLAG_NOT_TCPC is set, the TCPCI mux driver must initialize
+ * the I2C bus and address from the devicetree.
+ *
+ * The TCPCI mux doesn't have it's owm emulator and sends it's I2C transactions
+ * through the normal TCPCI driver, which then connects to the TCPCI emulator.
+ *
+ * Use 2 compaible strings here so that the same I2C device node gets setup for
+ * both the emulator and the TPCI mux.
+ */
+&tcpci_emul {
+ compatible = "cros,tcpci-generic-emul", "cros-ec,usbc-mux-tcpci";
+};
+
+/ {
+ usbc {
+ port0@0 {
+ usb-mux-chain-0 {
+ usb-muxes = <&tcpci_emul &virtual_mux_c0>;
+ };
+ };
+ };
+};
diff --git a/zephyr/test/drivers/default/src/tcpci.c b/zephyr/test/drivers/default/src/tcpci.c
index db0ad076ab..de2437eb96 100644
--- a/zephyr/test/drivers/default/src/tcpci.c
+++ b/zephyr/test/drivers/default/src/tcpci.c
@@ -22,6 +22,9 @@
#define TCPCI_EMUL_NODE DT_NODELABEL(tcpci_emul)
+/* Convenience pointer directly to the TCPCI mux under test */
+static struct usb_mux *tcpci_usb_mux;
+
/** Test TCPCI init and vbus level */
ZTEST(tcpci, test_generic_tcpci_init)
{
@@ -288,13 +291,13 @@ ZTEST(tcpci, test_generic_tcpci_debug_accessory)
/* Setup TCPCI usb mux to behave as it is used only for usb mux */
static void set_usb_mux_not_tcpc(void)
{
- usbc0_mux0.flags = USB_MUX_FLAG_NOT_TCPC;
+ tcpci_usb_mux->flags = USB_MUX_FLAG_NOT_TCPC;
}
/* Setup TCPCI usb mux to behave as it is used for usb mux and TCPC */
static void set_usb_mux_tcpc(void)
{
- usbc0_mux0.flags = 0;
+ tcpci_usb_mux->flags = 0;
}
/** Test TCPCI mux init */
@@ -531,7 +534,6 @@ void validate_mux_read_write16(const struct usb_mux *tcpci_usb_mux)
/** Test usb_mux read/write APIs */
ZTEST(tcpci, test_usb_mux_read_write)
{
- struct usb_mux *tcpci_usb_mux = &usbc0_mux0;
const int flags_restore = tcpci_usb_mux->flags;
/* Configure mux read/writes for TCPC APIs */
@@ -552,6 +554,8 @@ static void *tcpci_setup(void)
&tcpci_tcpm_usb_mux_driver,
"Invalid config of usb_muxes in test/drivers/src/stubs.c");
+ tcpci_usb_mux = (struct usb_mux *)usb_muxes[USBC_PORT_C0].mux;
+
return NULL;
}
diff --git a/zephyr/test/drivers/default/src/usb_mux.c b/zephyr/test/drivers/default/src/usb_mux.c
index 62d39e28d4..4aea56962e 100644
--- a/zephyr/test/drivers/default/src/usb_mux.c
+++ b/zephyr/test/drivers/default/src/usb_mux.c
@@ -29,7 +29,8 @@
#include "test/drivers/utils.h"
/** Copy of original usb_muxes[USB_PORT_C1] */
-struct usb_mux_chain usb_mux_c1;
+static struct usb_mux_chain usb_mux_c1;
+static struct usb_mux *usbc1_virtual_usb_mux;
/** Number of usb mux proxies in chain */
#define NUM_OF_PROXY 3
@@ -344,6 +345,26 @@ struct usb_mux_chain proxy_chain_0 = {
.next = &proxy_chain_1,
};
+static void find_virtual_mux(void)
+{
+ const struct usb_mux_chain *mux_chain;
+
+ mux_chain = &usb_muxes[1];
+ usbc1_virtual_usb_mux = NULL;
+ while (mux_chain) {
+ if (mux_chain->mux &&
+ mux_chain->mux->driver == &virtual_usb_mux_driver) {
+ usbc1_virtual_usb_mux =
+ (struct usb_mux *)mux_chain->mux;
+ break;
+ }
+ mux_chain = mux_chain->next;
+ }
+
+ __ASSERT(usbc1_virtual_usb_mux,
+ "USB-C port 1 must contain a virtual mux");
+}
+
/** Setup first 3 usb muxes of port 1 with proxy */
static void setup_usb_mux_proxy_chain(void)
{
@@ -693,13 +714,13 @@ ZTEST(usb_uninit_mux, test_usb_mux_hpd_update)
mux_state_t exp_mode, mode, virt_mode;
/* Get current state of virtual usb mux and set mock */
- usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &virt_mode);
+ usbc1_virtual_usb_mux->driver->get(usbc1_virtual_usb_mux, &virt_mode);
/* Test no hpd level and no irq */
exp_mode = virt_mode;
usb_mux_hpd_update(USBC_PORT_C1, exp_mode);
/* Check if virtual usb mux mode is updated correctly */
- usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &mode);
+ usbc1_virtual_usb_mux->driver->get(usbc1_virtual_usb_mux, &mode);
zassert_equal(exp_mode, mode, "virtual mux mode is 0x%x (!= 0x%x)",
mode, exp_mode);
CHECK_PROXY_FAKE_CALL_CNT(proxy_init, NUM_OF_PROXY);
@@ -711,7 +732,7 @@ ZTEST(usb_uninit_mux, test_usb_mux_hpd_update)
exp_mode = virt_mode | USB_PD_MUX_HPD_LVL | USB_PD_MUX_HPD_IRQ;
usb_mux_hpd_update(USBC_PORT_C1, exp_mode);
/* Check if virtual usb mux mode is updated correctly */
- usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &mode);
+ usbc1_virtual_usb_mux->driver->get(usbc1_virtual_usb_mux, &mode);
zassert_equal(exp_mode, mode, "virtual mux mode is 0x%x (!= 0x%x)",
mode, exp_mode);
CHECK_PROXY_FAKE_CALL_CNT(proxy_init, 0);
@@ -723,7 +744,7 @@ ZTEST(usb_uninit_mux, test_usb_mux_hpd_update)
exp_mode = virt_mode | USB_PD_MUX_HPD_IRQ;
usb_mux_hpd_update(USBC_PORT_C1, exp_mode);
/* Check if virtual usb mux mode is updated correctly */
- usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &mode);
+ usbc1_virtual_usb_mux->driver->get(usbc1_virtual_usb_mux, &mode);
zassert_equal(exp_mode, mode, "virtual mux mode is 0x%x (!= 0x%x)",
mode, exp_mode);
CHECK_PROXY_FAKE_CALL_CNT(proxy_init, 0);
@@ -735,7 +756,7 @@ ZTEST(usb_uninit_mux, test_usb_mux_hpd_update)
exp_mode = virt_mode | USB_PD_MUX_HPD_LVL;
usb_mux_hpd_update(USBC_PORT_C1, exp_mode);
/* Check if virtual usb mux mode is updated correctly */
- usbc1_virtual_usb_mux.driver->get(&usbc1_virtual_usb_mux, &mode);
+ usbc1_virtual_usb_mux->driver->get(usbc1_virtual_usb_mux, &mode);
zassert_equal(exp_mode, mode, "virtual mux mode is 0x%x (!= 0x%x)",
mode, exp_mode);
CHECK_PROXY_FAKE_CALL_CNT(proxy_init, 0);
@@ -916,6 +937,7 @@ ZTEST(usb_init_mux, test_usb_mux_typec_command)
void usb_uninit_mux_before(void *state)
{
ARG_UNUSED(state);
+ find_virtual_mux();
setup_usb_mux_proxy_chain();
set_test_runner_tid();
@@ -935,6 +957,7 @@ void usb_uninit_mux_after(void *state)
void usb_init_mux_before(void *state)
{
ARG_UNUSED(state);
+ find_virtual_mux();
setup_usb_mux_proxy_chain();
set_test_runner_tid();
diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf
index 3e3f9db02c..3169051bed 100644
--- a/zephyr/test/drivers/prj.conf
+++ b/zephyr/test/drivers/prj.conf
@@ -98,6 +98,7 @@ CONFIG_PLATFORM_EC_USB_PD_REV30=y
CONFIG_PLATFORM_EC_BATTERY_FUEL_GAUGE=y
CONFIG_PLATFORM_EC_HOSTCMD=y
CONFIG_PLATFORM_EC_USB_PD_TCPM_TUSB422=y
+CONFIG_PLATFORM_EC_USB_MUX_RUNTIME_CONFIG=y
CONFIG_PLATFORM_EC_USB_MUX_VIRTUAL=y
CONFIG_PLATFORM_EC_USBC_PPC_SN5S330=y
CONFIG_PLATFORM_EC_TEMP_SENSOR=y
diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml
index ed7c9b5635..d8a2dc838a 100644
--- a/zephyr/test/drivers/testcase.yaml
+++ b/zephyr/test/drivers/testcase.yaml
@@ -4,6 +4,7 @@ tests:
drivers.default:
timeout: 240
extra_args: CONF_FILE="prj.conf;default/prj.conf"
+ DTC_OVERLAY_FILE="default/boards/native_posix.overlay"
extra_configs:
- CONFIG_LINK_TEST_SUITE_DEFAULT=y
- CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK=y
@@ -13,6 +14,7 @@ tests:
drivers.default.mock_power:
timeout: 240
extra_args: CONF_FILE="prj.conf;default/prj.conf"
+ DTC_OVERLAY_FILE="default/boards/native_posix.overlay"
extra_configs:
- CONFIG_LINK_TEST_SUITE_DEFAULT=y
- CONFIG_LINK_TEST_SUITE_USB_MALFUNCTION_SINK=y
@@ -198,6 +200,7 @@ tests:
- CONFIG_LINK_TEST_SUITE_USBC_PPC=y
drivers.usbc_svdm_dfp_only:
extra_args: CONF_FILE="prj.conf;usbc_svdm_dfp_only/prj.conf"
+ DTC_OVERLAY_FILE="usbc_svdm_dfp_only/boards/native_posix.overlay"
extra_configs:
- CONFIG_LINK_TEST_SUITE_USBC_SVDM_DFP_ONLY=y
drivers.usbc_tbt_mode:
diff --git a/zephyr/test/drivers/usbc_svdm_dfp_only/boards/native_posix.overlay b/zephyr/test/drivers/usbc_svdm_dfp_only/boards/native_posix.overlay
new file mode 100644
index 0000000000..0e428e271a
--- /dev/null
+++ b/zephyr/test/drivers/usbc_svdm_dfp_only/boards/native_posix.overlay
@@ -0,0 +1,23 @@
+/* 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 "../../boards/native_posix.overlay"
+
+/*
+ * The SVDM DFP only tests explicitly do not support USB4/TBT which
+ * automatically get turned on if the Burnside Bridge retimer is used.
+ * Remove this device from the devicetree.
+ */
+ /delete-node/ &usb_c1_bb_retimer_emul;
+
+ / {
+ usbc {
+ port1@1 {
+ usb-mux-chain-1 {
+ usb-muxes = <&virtual_mux_c1>;
+ };
+ };
+ };
+};
diff --git a/zephyr/test/drivers/usbc_svdm_dfp_only/prj.conf b/zephyr/test/drivers/usbc_svdm_dfp_only/prj.conf
index 96c16cbd01..fefe9471ca 100644
--- a/zephyr/test/drivers/usbc_svdm_dfp_only/prj.conf
+++ b/zephyr/test/drivers/usbc_svdm_dfp_only/prj.conf
@@ -3,6 +3,7 @@
# found in the LICENSE file.
+CONFIG_EMUL_BB_RETIMER=n
CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB=n
CONFIG_PLATFORM_EC_USB_PD_USB4=n
CONFIG_PLATFORM_EC_USB_PD_TBT_COMPAT_MODE=n
diff --git a/zephyr/test/vboot_efs2/boards/native_posix.overlay b/zephyr/test/vboot_efs2/boards/native_posix.overlay
index ced94c28b1..d6b008c69d 100644
--- a/zephyr/test/vboot_efs2/boards/native_posix.overlay
+++ b/zephyr/test/vboot_efs2/boards/native_posix.overlay
@@ -61,6 +61,15 @@
reg = <0>;
chg = <&isl923x_emul>;
tcpc = <&tcpci_emul>;
+ usb-mux-chain-1 {
+ compatible = "cros-ec,usb-mux-chain";
+ usb-muxes = <&tcpci_mux_c0>;
+ };
+ };
+ port0-muxes {
+ tcpci_mux_c0: tcpci-mux-c0 {
+ compatible = "cros-ec,usbc-mux-tcpci";
+ };
};
};
i2c2: i2c@500 {
diff --git a/zephyr/test/vboot_efs2/src/main.c b/zephyr/test/vboot_efs2/src/main.c
index 1558fb75f0..f757030489 100644
--- a/zephyr/test/vboot_efs2/src/main.c
+++ b/zephyr/test/vboot_efs2/src/main.c
@@ -401,17 +401,6 @@ const struct pi3usb9201_config_t pi3usb9201_bc12_chips[] = {
},
};
-struct usb_mux_chain usb_muxes[] = {
- [USBC_PORT_C0] = {
- .mux = &(struct usb_mux) {
- .usb_port = USBC_PORT_C0,
- .driver = &tcpci_tcpm_usb_mux_driver,
- .i2c_port = I2C_PORT_USB_C0,
- .i2c_addr_flags = DT_REG_ADDR(DT_NODELABEL(tcpci_emul)),
- },
- },
-};
-
/* USBC PPC configuration */
struct ppc_config_t ppc_chips[] = {
[USBC_PORT_C0] = {