From aff5c83053cf88edf3c4331b09b25d7361c1ba9a Mon Sep 17 00:00:00 2001 From: li feng Date: Wed, 4 May 2016 12:37:51 -0700 Subject: amenia: Support DP alt mode of Type-C controller in amenia. BUG=none BRANCH=none TEST=On Amenia TR1.2, tested with HDMI to Type-C dongle. Both Analogix and Parade ports have HDMI on extended display. Change-Id: Ifb95c289019063a8a24d135e3b3a09cb4d446210 Signed-off-by: Divya Sasidharan Signed-off-by: li feng Reviewed-on: https://chromium-review.googlesource.com/348881 Commit-Ready: Li1 Feng Tested-by: Li1 Feng Reviewed-by: Shawn N --- board/amenia/board.c | 3 +++ board/amenia/board.h | 1 + board/amenia/usb_pd_policy.c | 31 +++++++++++++++++++++++++++++-- include/usb_mux.h | 6 ++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/board/amenia/board.c b/board/amenia/board.c index 9dbf78e825..9b98a0a9f9 100644 --- a/board/amenia/board.c +++ b/board/amenia/board.c @@ -20,6 +20,7 @@ #include "driver/charger/bd99955.h" #include "driver/tcpm/anx74xx.h" #include "driver/tcpm/tcpci.h" +#include "driver/tcpm/ps8751.h" #include "driver/temp_sensor/g78x.h" #include "extpower.h" #include "gpio.h" @@ -152,10 +153,12 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = { { .port_addr = 0, .driver = &anx74xx_tcpm_usb_mux_driver, + .hpd_update = &anx74xx_tcpc_update_hpd_status, }, { .port_addr = 1, .driver = &tcpci_tcpm_usb_mux_driver, + .hpd_update = &ps8751_tcpc_update_hpd_status, } }; #endif diff --git a/board/amenia/board.h b/board/amenia/board.h index d8e417ea7e..b716519269 100644 --- a/board/amenia/board.h +++ b/board/amenia/board.h @@ -82,6 +82,7 @@ #define CONFIG_USB_PD_TCPM_ANX74XX #define TCPC0_I2C_ADDR 0x50 #define ANX74XX_INT_ACTIVE_POLARITY ANX74XX_REG_IRQ_POL_HIGH +#define CONFIG_USB_PD_TCPM_PS8751 #define CONFIG_USB_PD_TCPM_TCPCI #define TCPC1_I2C_ADDR 0x16 #define CONFIG_USB_PD_TCPM_MUX diff --git a/board/amenia/usb_pd_policy.c b/board/amenia/usb_pd_policy.c index f1c3b99326..df2d69770c 100644 --- a/board/amenia/usb_pd_policy.c +++ b/board/amenia/usb_pd_policy.c @@ -8,9 +8,12 @@ #include "common.h" #include "console.h" #include "driver/charger/bd99955.h" +#include "driver/tcpm/anx74xx.h" +#include "driver/tcpm/ps8751.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" +#include "i2c.h" #include "registers.h" #include "system.h" #include "task.h" @@ -222,12 +225,15 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, #ifdef CONFIG_USB_PD_ALT_MODE_DFP static int dp_flags[CONFIG_USB_PD_PORT_COUNT]; +static uint32_t dp_status[CONFIG_USB_PD_PORT_COUNT]; static void svdm_safe_dp_mode(int port) { /* make DP interface safe until configure */ dp_flags[port] = 0; - /* board_set_usb_mux(port, TYPEC_MUX_NONE, pd_get_polarity(port)); */ + dp_status[port] = 0; + usb_mux_set(port, TYPEC_MUX_NONE, + USB_SWITCH_CONNECT, pd_get_polarity(port)); } static int svdm_enter_dp_mode(int port, uint32_t mode_caps) @@ -261,32 +267,53 @@ static int svdm_dp_status(int port, uint32_t *payload) static int svdm_dp_config(int port, uint32_t *payload) { int opos = pd_alt_mode(port, USB_SID_DISPLAYPORT); + + usb_mux_set(port, TYPEC_MUX_DP, + USB_SWITCH_CONNECT, pd_get_polarity(port)); + /* board_set_usb_mux(port, TYPEC_MUX_DP, pd_get_polarity(port)); */ payload[0] = VDO(USB_SID_DISPLAYPORT, 1, CMD_DP_CONFIG | VDO_OPOS(opos)); payload[1] = VDO_DP_CFG(MODE_DP_PIN_E, /* pin mode */ 1, /* DPv1.3 signaling */ 2); /* UFP connected */ + return 2; }; static void svdm_dp_post_config(int port) { + const struct usb_mux *mux = &usb_muxes[port]; dp_flags[port] |= DP_FLAGS_DP_ON; if (!(dp_flags[port] & DP_FLAGS_HPD_HI_PENDING)) return; + mux->hpd_update(port, 1, 0); } static int svdm_dp_attention(int port, uint32_t *payload) { + int lvl = PD_VDO_DPSTS_HPD_LVL(payload[1]); + int irq = PD_VDO_DPSTS_HPD_IRQ(payload[1]); + const struct usb_mux *mux = &usb_muxes[port]; + + dp_status[port] = payload[1]; + + if (!(dp_flags[port] & DP_FLAGS_DP_ON)) { + if (lvl) + dp_flags[port] |= DP_FLAGS_HPD_HI_PENDING; + return 1; + } + mux->hpd_update(port, lvl, irq); + /* ack */ return 1; } static void svdm_exit_dp_mode(int port) { + const struct usb_mux *mux = &usb_muxes[port]; svdm_safe_dp_mode(port); - /* gpio_set_level(PORT_TO_HPD(port), 0); */ + mux->hpd_update(port, 0, 0); } static int svdm_enter_gfu_mode(int port, uint32_t mode_caps) diff --git a/include/usb_mux.h b/include/usb_mux.h index 4f38b8e68e..52917efb45 100644 --- a/include/usb_mux.h +++ b/include/usb_mux.h @@ -75,6 +75,12 @@ struct usb_mux { * @return EC_SUCCESS on success, non-zero error code on failure. */ int (*board_init)(const struct usb_mux *mux); + + /* + * USB Type-C DP alt mode support. Notify Type-C controller + * there is DP dongle hot-plug. + */ + void (*hpd_update)(int port, int hpd_lvl, int hpd_irq); }; /* Supported USB mux drivers */ -- cgit v1.2.1