diff options
author | Kapil Porwal <kapilporwal@google.com> | 2023-07-10 11:37:26 +0000 |
---|---|---|
committer | Subrata Banik <subratabanik@google.com> | 2023-07-15 12:47:51 +0000 |
commit | 2ba4b1bebea4321cc4998ac5bf51a9e97795157e (patch) | |
tree | 9002e8befded4312cd719dd6f2596678133b6693 | |
parent | 1d85464df80eaefeef06df9a74018ed93f67e19d (diff) |
ec/google/chromeec: Split wait-loop for DP and HPD flags
Split wait-loop for DP and HPD flags as below -
- google_chromeec_wait_for_hpd
- google_chromeec_wait_for_dp_mode_entry
BUG=b:247670186
TEST=Verify display over TCSS and its impact on boot time for
google/rex
Signed-off-by: Kapil Porwal <kapilporwal@google.com>
Change-Id: I3e565d6134f6433930916071e94d56d92dc6cb06
Reviewed-on: https://review.coreboot.org/c/coreboot/+/76370
Reviewed-by: Subrata Banik <subratabanik@google.com>
Reviewed-by: Eric Lai <eric_lai@quanta.corp-partner.google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r-- | src/ec/google/chromeec/ec.c | 55 | ||||
-rw-r--r-- | src/ec/google/chromeec/ec.h | 6 | ||||
-rw-r--r-- | src/ec/google/chromeec/usbc_mux.c | 3 | ||||
-rw-r--r-- | src/include/device/usbc_mux.h | 9 |
4 files changed, 63 insertions, 10 deletions
diff --git a/src/ec/google/chromeec/ec.c b/src/ec/google/chromeec/ec.c index a3b1fe3045..c950673c65 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 42326601e8..61b23cf3ba 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 64195428b0..f89416a898 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 0648a74f66..cf109b7fe8 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: |