diff options
author | Diana Z <dzigterman@chromium.org> | 2023-02-22 14:08:00 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-02-23 22:01:18 +0000 |
commit | 751281d05b36c0432fed4a0dfd17febdc8ef927c (patch) | |
tree | 963facc98f844a7ec8a54c15b9122a466fa2b854 | |
parent | a644497359abf8fd188c1389ce6c69c54aab1495 (diff) | |
download | chrome-ec-751281d05b36c0432fed4a0dfd17febdc8ef927c.tar.gz |
Zephyr test: Add HPD GPIO to DP alt mode test
Add the HPD GPIO configuration to the DP alt mode tests so the module
can test for HPD to be set and cleared.
BRANCH=None
BUG=b:170372521,b:159856063
TEST=./twister -T ./zephyr/test
Change-Id: I344631c7548ee70914c2ab434216aac73a3fad4c
Signed-off-by: Diana Z <dzigterman@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4283688
Reviewed-by: Al Semjonovs <asemjonovs@google.com>
-rw-r--r-- | zephyr/test/drivers/boards/native_posix.overlay | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/usbc_alt_mode/prj.conf | 5 | ||||
-rw-r--r-- | zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c | 107 | ||||
-rw-r--r-- | zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c | 29 |
5 files changed, 151 insertions, 2 deletions
diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay index f2b41b0df0..cfca0475c2 100644 --- a/zephyr/test/drivers/boards/native_posix.overlay +++ b/zephyr/test/drivers/boards/native_posix.overlay @@ -277,6 +277,14 @@ gpio_usb_c1_bc12_int_l: usb_c1_bc12_int_l { gpios = <&gpio1 11 GPIO_INPUT>; }; + gpio_usb_c0_hpd: usb_c0_hpd { + gpios = <&gpio1 12 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_USB_C0_DP_HPD"; + }; + gpio_usb_c1_hpd: usb_c1_hpd { + gpios = <&gpio1 13 GPIO_OUTPUT_LOW>; + enum-name = "GPIO_USB_C1_DP_HPD"; + }; }; gpio1: gpio@101 { @@ -289,7 +297,7 @@ low-level; gpio-controller; #gpio-cells = <2>; - ngpios = <12>; + ngpios = <14>; }; gpio-interrupts { diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index e13692cce7..9bdedb6fc3 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -269,10 +269,12 @@ tests: extra_configs: - CONFIG_LINK_TEST_SUITE_USB_RETIMER_FW_UPDATE=y drivers.usbc_alt_mode: + extra_args: CONF_FILE="prj.conf;usbc_alt_mode/prj.conf" extra_configs: - CONFIG_LINK_TEST_SUITE_USBC_ALT_MODE=y timeout: 120 drivers.usbc_alt_mode_ec_entry: + extra_args: CONF_FILE="prj.conf;usbc_alt_mode/prj.conf" timeout: 120 extra_configs: - CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY=n diff --git a/zephyr/test/drivers/usbc_alt_mode/prj.conf b/zephyr/test/drivers/usbc_alt_mode/prj.conf new file mode 100644 index 0000000000..ce0e7f18a6 --- /dev/null +++ b/zephyr/test/drivers/usbc_alt_mode/prj.conf @@ -0,0 +1,5 @@ +# 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_DP_HPD_GPIO=y diff --git a/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c b/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c index f23af9356d..e92c2a33f9 100644 --- a/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c +++ b/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c @@ -23,6 +23,8 @@ #include <zephyr/kernel.h> #include <zephyr/ztest.h> +#include <gpio.h> + #define TEST_PORT 0 /* Arbitrary */ @@ -251,6 +253,9 @@ ZTEST_F(usbc_alt_mode, verify_discovery_params_too_small) ZTEST_F(usbc_alt_mode, verify_displayport_mode_entry) { + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + if (IS_ENABLED(CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY)) { host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP); k_sleep(K_SECONDS(1)); @@ -293,7 +298,107 @@ ZTEST_F(usbc_alt_mode, verify_displayport_mode_entry) zassert_equal((status.mux_state & USB_PD_MUX_HPD_LVL), USB_PD_MUX_HPD_LVL, "Failed to set HPD level in mux"); zassert_equal((status.mux_state & USB_PD_MUX_HPD_IRQ), - USB_PD_MUX_HPD_IRQ, "Failed to set HPD IRQin mux"); + USB_PD_MUX_HPD_IRQ, "Failed to set HPD IRQ in mux"); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); +} + +ZTEST_F(usbc_alt_mode, verify_bad_hpd_irq_reject) +{ + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + if (IS_ENABLED(CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY)) { + host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP); + k_sleep(K_SECONDS(1)); + } + + /* + * Compose a bad Attention packet which sets IRQ with HPD low + */ + uint32_t vdm_attention_data[2]; + + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(1) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + false, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + k_sleep(K_SECONDS(1)); + + /* Verify that no HPD notification triggered */ + struct ec_response_typec_status status; + + status = host_cmd_typec_status(TEST_PORT); + zassert_not_equal((status.mux_state & USB_PD_MUX_HPD_LVL), + USB_PD_MUX_HPD_LVL); + zassert_not_equal((status.mux_state & USB_PD_MUX_HPD_IRQ), + USB_PD_MUX_HPD_IRQ); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); +} + +ZTEST_F(usbc_alt_mode, verify_hpd_clear) +{ + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + + if (IS_ENABLED(CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY)) { + host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP); + k_sleep(K_SECONDS(1)); + } + + /* + * Set our HPD to high and then low, ensuring our HPD indicators + * track this + */ + uint32_t vdm_attention_data[2]; + + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(1) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION); + vdm_attention_data[1] = VDO_DP_STATUS(0, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + k_sleep(K_SECONDS(1)); + + /* Verify that HPD notification triggered */ + struct ec_response_typec_status status; + + status = host_cmd_typec_status(TEST_PORT); + zassert_equal((status.mux_state & USB_PD_MUX_HPD_LVL), + USB_PD_MUX_HPD_LVL); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); + + vdm_attention_data[1] = VDO_DP_STATUS(0, /* IRQ_HPD */ + false, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_SECONDS(1)); + /* Verify that HPD cleared */ + status = host_cmd_typec_status(TEST_PORT); + zassert_not_equal((status.mux_state & USB_PD_MUX_HPD_LVL), + USB_PD_MUX_HPD_LVL); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); } ZTEST_F(usbc_alt_mode, verify_discovery_via_pd_host_cmd) diff --git a/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c b/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c index a4c406a054..a936707809 100644 --- a/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c +++ b/zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c @@ -6,9 +6,12 @@ #include "test/drivers/utils.h" #include "test_usbc_alt_mode.h" +#include <zephyr/drivers/gpio/gpio_emul.h> #include <zephyr/kernel.h> #include <zephyr/ztest.h> +#include <gpio.h> + /* Tests that require CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY enabled */ ZTEST_F(usbc_alt_mode, verify_displayport_mode_reentry) @@ -45,6 +48,9 @@ ZTEST_F(usbc_alt_mode, verify_displayport_mode_reentry) ZTEST_F(usbc_alt_mode, verify_mode_exit_via_pd_host_cmd) { + const struct gpio_dt_spec *gpio = + GPIO_DT_FROM_NODELABEL(gpio_usb_c0_hpd); + if (!IS_ENABLED(CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY)) { ztest_test_skip(); } @@ -52,9 +58,32 @@ ZTEST_F(usbc_alt_mode, verify_mode_exit_via_pd_host_cmd) host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP); k_sleep(K_SECONDS(1)); + /* + * Set HPD so we can see it clear on Exit + */ + uint32_t vdm_attention_data[2]; + + vdm_attention_data[0] = + VDO(USB_SID_DISPLAYPORT, 1, + VDO_OPOS(1) | VDO_CMDT(CMDT_INIT) | CMD_ATTENTION); + vdm_attention_data[1] = VDO_DP_STATUS(1, /* IRQ_HPD */ + true, /* HPD_HI|LOW - Changed*/ + 0, /* request exit DP */ + 0, /* request exit USB */ + 0, /* MF pref */ + true, /* DP Enabled */ + 0, /* power low e.g. normal */ + 0x2 /* Connected as Sink */); + tcpci_partner_send_data_msg(&fixture->partner, PD_DATA_VENDOR_DEF, + vdm_attention_data, 2, 0); + + k_sleep(K_SECONDS(1)); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1); + host_cmd_typec_control_exit_modes(TEST_PORT); k_sleep(K_SECONDS(1)); zassert_false(fixture->partner.displayport_configured); + zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0); /* * Verify that DisplayPort is no longer active by checking our |