summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ec/google/chromeec/ec.c55
-rw-r--r--src/ec/google/chromeec/ec.h6
-rw-r--r--src/ec/google/chromeec/usbc_mux.c3
-rw-r--r--src/include/device/usbc_mux.h9
4 files changed, 63 insertions, 10 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c
index a3b1fe304592..c950673c6538 100644
--- a/src/ec/google/chromeec/ec.c
+++ b/src/ec/google/chromeec/ec.c
@@ -1383,15 +1383,29 @@ int google_chromeec_wait_for_displayport(long timeout_ms)
return ret;
}
-int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms)
+/**
+ * Check for given flag in PD mux info for a port.
+ *
+ * @param port Type-C port number
+ * flag Flag to check
+ * @return 1: Flag is set. 0: Flag is not set.
+ */
+static int google_chromeec_check_mux_flag(int port, uint8_t flag)
+{
+ uint8_t mux_flags = 0;
+ google_chromeec_usb_get_pd_mux_info(port, &mux_flags);
+ if ((mux_flags & flag) == flag)
+ return 1;
+ return 0;
+}
+
+int google_chromeec_wait_for_dp_mode_entry(int port, long timeout_ms)
{
- uint8_t mux_flags;
struct stopwatch sw;
if (!google_chromeec_check_feature(EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY)) {
- google_chromeec_usb_get_pd_mux_info(port, &mux_flags);
- if (!(mux_flags & USB_PD_MUX_HPD_LVL) || !(mux_flags & USB_PD_MUX_DP_ENABLED)) {
- printk(BIOS_WARNING, "DP/HPD not ready. Abort.\n");
+ if (!google_chromeec_check_mux_flag(port, USB_PD_MUX_DP_ENABLED)) {
+ printk(BIOS_WARNING, "DP mode entry is not ready. Abort.\n");
return -1;
}
@@ -1399,14 +1413,39 @@ int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms)
}
stopwatch_init_msecs_expire(&sw, timeout_ms);
- do {
- google_chromeec_usb_get_pd_mux_info(port, &mux_flags);
+ while (!google_chromeec_check_mux_flag(port, USB_PD_MUX_DP_ENABLED)) {
+ if (stopwatch_expired(&sw)) {
+ printk(BIOS_WARNING, "DP not ready after %ldms. Abort.\n", timeout_ms);
+ return -1;
+ }
+ mdelay(100);
+ }
+ printk(BIOS_INFO, "DP ready after %lld ms\n", stopwatch_duration_msecs(&sw));
+
+ return 0;
+}
+
+int google_chromeec_wait_for_hpd(int port, long timeout_ms)
+{
+ struct stopwatch sw;
+
+ if (!google_chromeec_check_feature(EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY)) {
+ if (!google_chromeec_check_mux_flag(port, USB_PD_MUX_HPD_LVL)) {
+ printk(BIOS_WARNING, "HPD not ready. Abort.\n");
+ return -1;
+ }
+
+ return 0;
+ }
+
+ stopwatch_init_msecs_expire(&sw, timeout_ms);
+ while (!google_chromeec_check_mux_flag(port, USB_PD_MUX_HPD_LVL)) {
if (stopwatch_expired(&sw)) {
printk(BIOS_WARNING, "HPD not ready after %ldms. Abort.\n", timeout_ms);
return -1;
}
mdelay(100);
- } while (!(mux_flags & USB_PD_MUX_HPD_LVL) || !(mux_flags & USB_PD_MUX_DP_ENABLED));
+ }
printk(BIOS_INFO, "HPD ready after %lld ms\n", stopwatch_duration_msecs(&sw));
return 0;
diff --git a/src/ec/google/chromeec/ec.h b/src/ec/google/chromeec/ec.h
index 42326601e8a6..61b23cf3babd 100644
--- a/src/ec/google/chromeec/ec.h
+++ b/src/ec/google/chromeec/ec.h
@@ -38,10 +38,14 @@ int google_chromeec_usb_get_pd_mux_info(int port, uint8_t *flags);
* >=1: Bitmask of the ports that DP device is connected
*/
int google_chromeec_wait_for_displayport(long timeout_ms);
+/* Poll (up to `timeout_ms` ms) for the DP mode entry
+ * event on the specified port.
+ * Return: 0 on DP mode entry success, -1 on timeout */
+int google_chromeec_wait_for_dp_mode_entry(int port, long timeout_ms);
/* Poll (up to `timeout_ms` ms) for a Hot-Plug Detect (HPD)
* event on the specified port.
* Return: 0 on HPD ready, -1 on timeout */
-int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms);
+int google_chromeec_wait_for_hpd(int port, long timeout_ms);
/* Send command to EC to request to enter DisplayPort ALT mode on the
* specified port.
* Return: 0 on success, -1 on error */
diff --git a/src/ec/google/chromeec/usbc_mux.c b/src/ec/google/chromeec/usbc_mux.c
index 64195428b096..f89416a89848 100644
--- a/src/ec/google/chromeec/usbc_mux.c
+++ b/src/ec/google/chromeec/usbc_mux.c
@@ -9,7 +9,8 @@ static const struct usbc_ops google_chromeec_usbc_ops = {
.dp_ops = {
.wait_for_connection = google_chromeec_wait_for_displayport,
.enter_dp_mode = google_chromeec_typec_control_enter_dp_mode,
- .wait_for_hpd = google_chromeec_wait_for_dp_hpd,
+ .wait_for_dp_mode_entry = google_chromeec_wait_for_dp_mode_entry,
+ .wait_for_hpd = google_chromeec_wait_for_hpd,
},
};
diff --git a/src/include/device/usbc_mux.h b/src/include/device/usbc_mux.h
index 0648a74f667c..cf109b7fe8fd 100644
--- a/src/include/device/usbc_mux.h
+++ b/src/include/device/usbc_mux.h
@@ -55,6 +55,15 @@ struct usbc_dp_ops {
int (*enter_dp_mode)(int port);
/*
+ * Wait up to `timeout_ms` for DP mode entry on a given port.
+ *
+ * Return value:
+ * -1 = timeout
+ * 0 = success
+ */
+ int (*wait_for_dp_mode_entry)(int port, long timeout_ms);
+
+ /*
* Wait up to `timeout_ms` for HPD on a given port.
*
* Return value: