On Wed, Jun 24, 2020 at 01:09:24AM -0700, Prashant Malani wrote: > Add mux control support for Thunderbolt compatibility mode. > > Suggested-by: Heikki Krogerus <[email protected]> > Co-developed-by: Azhar Shaikh <[email protected]> > Co-developed-by: Casey Bowman <[email protected]> > Signed-off-by: Prashant Malani <[email protected]> > --- > drivers/platform/chrome/cros_ec_typec.c | 70 ++++++++++++++++++++++++- > 1 file changed, 69 insertions(+), 1 deletion(-)
Cool! Can you guys test also USB4 with the attached patch (still work in progress)? It should apply on top of these. The mux driver is still missing USB4 support, but I'll send the patches needed for that right now... thanks, -- heikki
>From cdc5d9528c4f751d856dfc1781f125a767a5de20 Mon Sep 17 00:00:00 2001 From: Heikki Krogerus <[email protected]> Date: Tue, 23 Jun 2020 15:53:02 +0300 Subject: [PATCH] platform/chrome: typec: USB4 support With USB4 the mux driver needs the Enter_USB VDO. Constructing one from the information we have. Signed-off-by: Heikki Krogerus <[email protected]> --- drivers/platform/chrome/cros_ec_typec.c | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 688d12efe9c42..c6448485ddfa3 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -13,6 +13,7 @@ #include <linux/platform_data/cros_ec_proto.h> #include <linux/platform_data/cros_usbpd_notify.h> #include <linux/platform_device.h> +#include <linux/usb/pd.h> #include <linux/usb/typec.h> #include <linux/usb/typec_altmode.h> #include <linux/usb/typec_dp.h> @@ -511,6 +512,40 @@ static int cros_typec_enable_tbt(struct cros_typec_data *typec, return typec_mux_set(port->mux, &port->state); } +static int cros_typec_enable_usb4(struct cros_typec_data *typec, + int port_num, + struct ec_response_usb_pd_control_v2 *pd_ctrl) +{ + struct cros_typec_port *port = typec->ports[port_num]; + u32 eudo; + + eudo = EUDO_USB_MODE_USB4 << EUDO_USB_MODE_SHIFT; + + /* Cable Speed */ + eudo |= pd_ctrl->cable_speed << EUDO_CABLE_SPEED_SHIFT; + + /* Cable Type */ + if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE) + eudo |= EUDO_CABLE_TYPE_OPTICAL << EUDO_CABLE_TYPE_SHIFT; + else if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE) + eudo |= EUDO_CABLE_TYPE_RE_TIMER << EUDO_CABLE_TYPE_SHIFT; + + /* FIXME: Cable Current */ + + /* REVISIT: Claiming unconditionally that all tunnels are supported. */ + eudo |= EUDO_PCIE_SUPPORT; + eudo |= EUDO_DP_SUPPORT; + + eudo |= EUDO_TBT_SUPPORT; + eudo |= EUDO_HOST_PRESENT; + + port->state.alt = NULL; + port->state.data = &eudo; + port->state.mode = TYPEC_MODE_USB4; + + return typec_mux_set(port->mux, &port->state); +} + int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, struct ec_response_usb_pd_mux_info *resp, struct ec_response_usb_pd_control_v2 *pd_ctrl) @@ -534,7 +569,9 @@ int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, port->state.alt = NULL; port->state.mode = TYPEC_STATE_USB; - if (resp->flags & USB_PD_MUX_TBT_COMPAT_ENABLED) + if (resp->flags & USB_PD_MUX_USB4_ENABLED) + ret = cros_typec_enable_usb4(typec, port_num, pd_ctrl); + else if (resp->flags & USB_PD_MUX_TBT_COMPAT_ENABLED) ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl); else if (resp->flags & USB_PD_MUX_DP_ENABLED) ret = cros_typec_enable_dp(typec, port_num, pd_ctrl); -- 2.27.0

