ec/google/chromeec: Add APIs for USB-C DP ALT mode

Add API to allow AP to send the command to EC to enter DP ALT mode
and API to wait for DP HPD event.

BUG=b:192947843
TEST=select ENABLE_TCSS_DISPLAY_DETECTION in Kconfig.name. Build
coreboot and update your system. Boot the system you will find below
message in the coreboot log with or without USB-C display connected:
'HPD ready after %lu ms' or 'HPD not ready after %ldms. Abort.'.

Signed-off-by: Derek Huang <derek.huang@intel.corp-partner.google.com>
Change-Id: Id11510c1ff58579ae2cddfe5a4d69646fd84f5c3
Reviewed-on: https://review.coreboot.org/c/coreboot/+/57138
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
This commit is contained in:
Derek Huang 2021-08-25 17:19:39 +08:00 committed by Tim Wawrzynczak
parent c0f005a5d6
commit c0bd123408
2 changed files with 54 additions and 0 deletions

View File

@ -1508,6 +1508,33 @@ int google_chromeec_usb_pd_get_info(int port, bool *ufp, bool *dbg_acc,
return 0;
}
int google_chromeec_typec_control_enter_dp_mode(int port)
{
if (!google_chromeec_check_feature(EC_FEATURE_TYPEC_REQUIRE_AP_MODE_ENTRY))
return 0;
struct ec_params_typec_control typec_control = {
.port = port,
.command = TYPEC_CONTROL_COMMAND_ENTER_MODE,
.mode_to_enter = TYPEC_MODE_DP,
};
struct chromeec_command cmd = {
.cmd_code = EC_CMD_TYPEC_CONTROL,
.cmd_version = 0,
.cmd_data_in = &typec_control,
.cmd_size_in = sizeof(typec_control),
.cmd_data_out = NULL,
.cmd_size_out = 0,
.cmd_dev_index = 0,
};
if (google_chromeec_command(&cmd) < 0)
return -1;
return 0;
}
/**
* Check for the current mux state in EC. Flags representing the mux state found
* in ec_commands.h
@ -1632,6 +1659,25 @@ int google_chromeec_wait_for_displayport(long timeout_ms)
return ret;
}
int google_chromeec_wait_for_dp_hpd(int port, long timeout_ms)
{
uint8_t mux_flags;
struct stopwatch sw;
stopwatch_init_msecs_expire(&sw, timeout_ms);
do {
google_chromeec_usb_get_pd_mux_info(port, &mux_flags);
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 %lu ms\n", stopwatch_duration_msecs(&sw));
return 0;
}
int google_chromeec_get_keybd_config(struct ec_response_keybd_config *keybd)
{
struct chromeec_command cmd = {

View File

@ -40,6 +40,14 @@ int google_chromeec_usb_pd_get_info(int port, bool *ufp, bool *dbg_acc,
* >=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 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);
/* Send command to EC to request to enter DisplayPort ALT mode on the
* specified port.
* Return: 0 on success, -1 on error */
int google_chromeec_typec_control_enter_dp_mode(int port);
/* Device events */
uint64_t google_chromeec_get_device_enabled_events(void);