summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2023-02-24 15:01:00 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-03-09 19:11:51 +0000
commit659cf9c7573602a0c4dff939becc2b031bb7014f (patch)
tree1a150f4e9ab015c17ec8ea98edf6b4d3b64cbc9b
parent691b0cb0f0726325c2787079f60c3b88098ded1c (diff)
downloadchrome-ec-659cf9c7573602a0c4dff939becc2b031bb7014f.tar.gz
Zephyr Test: Add more HPD cases
Add test cases for HPD IRQ being set high in a subsequent Attention packet and also for HPD set high early in the DP:Status message with no following Attention. Note, this also changes the HPD pins to be both input and output, so the code may read their state. BRANCH=None BUG=b:266714542 TEST=./twister -T ./zephyr/test Change-Id: I72c18d43a55a22c936ea2ebf4aeacef5412a5721 Signed-off-by: Diana Z <dzigterman@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4292303 Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/test/drivers/boards/native_posix.overlay4
-rw-r--r--zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode.c64
-rw-r--r--zephyr/test/drivers/usbc_alt_mode/src/usbc_alt_mode__require_ap_mode_entry.c30
3 files changed, 95 insertions, 3 deletions
diff --git a/zephyr/test/drivers/boards/native_posix.overlay b/zephyr/test/drivers/boards/native_posix.overlay
index ec2fa4ae3d..27b888439d 100644
--- a/zephyr/test/drivers/boards/native_posix.overlay
+++ b/zephyr/test/drivers/boards/native_posix.overlay
@@ -288,11 +288,11 @@
gpios = <&gpio1 11 GPIO_INPUT>;
};
gpio_usb_c0_hpd: usb_c0_hpd {
- gpios = <&gpio1 12 GPIO_OUTPUT_LOW>;
+ gpios = <&gpio1 12 (GPIO_OUTPUT_LOW | GPIO_INPUT)>;
enum-name = "GPIO_USB_C0_DP_HPD";
};
gpio_usb_c1_hpd: usb_c1_hpd {
- gpios = <&gpio1 13 GPIO_OUTPUT_LOW>;
+ gpios = <&gpio1 13 (GPIO_OUTPUT_LOW | GPIO_INPUT)>;
enum-name = "GPIO_USB_C1_DP_HPD";
};
};
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 e92c2a33f9..2d9d866d10 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
@@ -180,7 +180,6 @@ static void *usbc_alt_mode_setup(void)
fixture.charger_emul = EMUL_GET_USBC_BINDING(TEST_PORT, chg);
add_discovery_responses(partner);
- add_displayport_mode_responses(partner);
return &fixture;
}
@@ -195,6 +194,8 @@ static void usbc_alt_mode_before(void *data)
struct usbc_alt_mode_fixture *fixture = data;
+ /* Re-populate our usual responses in case a test overrode them */
+ add_displayport_mode_responses(&fixture->partner);
connect_partner_to_port(fixture->tcpci_emul, fixture->charger_emul,
&fixture->partner, &fixture->src_ext);
}
@@ -401,6 +402,67 @@ ZTEST_F(usbc_alt_mode, verify_hpd_clear)
zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 0);
}
+ZTEST_F(usbc_alt_mode, verify_hpd_irq_set)
+{
+ 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 toggle the IRQ low to high
+ */
+ 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_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), 1);
+
+ 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));
+ /* Verify that HPD IRQ set now */
+ status = host_cmd_typec_status(TEST_PORT);
+ zassert_equal((status.mux_state & USB_PD_MUX_HPD_LVL),
+ USB_PD_MUX_HPD_LVL);
+ zassert_equal((status.mux_state & USB_PD_MUX_HPD_IRQ),
+ USB_PD_MUX_HPD_IRQ);
+ zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1);
+}
+
ZTEST_F(usbc_alt_mode, verify_discovery_via_pd_host_cmd)
{
struct ec_params_usb_pd_info_request params = { .port = TEST_PORT };
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 a936707809..10bc4a7012 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
@@ -94,3 +94,33 @@ ZTEST_F(usbc_alt_mode, verify_mode_exit_via_pd_host_cmd)
status = host_cmd_typec_status(TEST_PORT);
zassert_equal((status.mux_state & USB_PD_MUX_DP_ENABLED), 0);
}
+
+ZTEST_F(usbc_alt_mode, verify_early_status_hpd_set)
+{
+ 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();
+ }
+
+ /*
+ * Tweak our DP:Status reply to set HPD and ensure it's transmitted
+ * through our HPD GPIO
+ */
+ fixture->partner.dp_status_vdm[VDO_INDEX_HDR + 1] =
+ /* Mainly copied from hoho */
+ 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 */);
+
+ host_cmd_typec_control_enter_mode(TEST_PORT, TYPEC_MODE_DP);
+ k_sleep(K_SECONDS(1));
+
+ zassert_equal(gpio_emul_output_get(gpio->port, gpio->pin), 1);
+}