diff options
Diffstat (limited to 'board/reef/usb_pd_policy.c')
-rw-r--r-- | board/reef/usb_pd_policy.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/board/reef/usb_pd_policy.c b/board/reef/usb_pd_policy.c index e399e1686c..f442f725f3 100644 --- a/board/reef/usb_pd_policy.c +++ b/board/reef/usb_pd_policy.c @@ -9,6 +9,8 @@ #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" @@ -246,12 +248,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) @@ -285,7 +290,10 @@ 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); - /* board_set_usb_mux(port, TYPEC_MUX_DP, pd_get_polarity(port)); */ + + usb_mux_set(port, TYPEC_MUX_DP, + USB_SWITCH_CONNECT, 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 */ @@ -296,21 +304,37 @@ static int svdm_dp_config(int port, uint32_t *payload) 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) |