Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1237096ybt; Thu, 25 Jun 2020 00:46:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4xyqWgr6uYUJ4Zr74AZWa38GQsppfroa9jPWvvjr52Jh6FXcT8KOkQrWZv0HfS/X5SUyS X-Received: by 2002:a17:906:7c3:: with SMTP id m3mr11338415ejc.30.1593071212897; Thu, 25 Jun 2020 00:46:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593071212; cv=none; d=google.com; s=arc-20160816; b=RWf7gRZARZcBA2TXTUneUeieoeLOKMPhpqRF1EWnT+rTxwxDDQCLTl2tisOQsxfxQx YCdN8G7iH8Cm7qYVyBeNrRG+PpJwdmtYtnk8Y09yPgt1iQz2qgsKlOSNZWf6BpCfKYCT Gt7VNrsc1Pj/+EfGviW0JTo1UcHHhK8Idz4dYvoRtLYVKqA7ES2xNaCQgBn5bnvSfQ2A MiTSkES/BPAUOpKzGuX2OAjBY6WLSAkUP555P0/tstTcuXaekzYLDLwU/lOqs3zpQjcw iopQgpIWWYoCOATYh/N4JFFzAGjQCPsasJ26dspDypMiW+xZrPwVtu+pinBgrsM7GDnc 2fJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=y99b0mBoifAMf3KADLN9rupiZuqh7kzPDyiDpNSnAmg=; b=liwuKju89Nst5LNkMgAtF/utdc1eTdwgfOR7KzmNHaI17MGnCZBVs1HzYajKrp2PBb vH1aEXHmKcSqV2O3UwrXqOoNnUEuCPf2fLltC9mxh0ouZsCrZQz8+b7NPv4vDuoVFNRi woJFwdvIhUY7oEtSbGGoxecVQHnnBtBh6Ga9JpBm+fU/eEV/KhlAnDYrUEUsIf+zO7Sw Cm29NUESxs1mlb5EsLARFiBGAW8Ap1S1EKSa9VZDhuC/v+2b7K+/MdPJXXuzFhMMVTWK NVm6hN+WivfTGAOK0Ziyd/YmUby+ctZKJqwv0WacSIRc19phufhaVMxkTmtgENLiIKrB DPdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si8505940edw.413.2020.06.25.00.46.29; Thu, 25 Jun 2020 00:46:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390302AbgFYHpZ (ORCPT + 99 others); Thu, 25 Jun 2020 03:45:25 -0400 Received: from mga05.intel.com ([192.55.52.43]:45030 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390196AbgFYHpZ (ORCPT ); Thu, 25 Jun 2020 03:45:25 -0400 IronPort-SDR: ih2qe31/MnSyPRcoySATnDIYBWJAhMcu6sB+8eWOoKNqVAsivDpyh1QK69Vz08TxeJYl7KY0Vh X3tJJVWWGRTw== X-IronPort-AV: E=McAfee;i="6000,8403,9662"; a="229508976" X-IronPort-AV: E=Sophos;i="5.75,278,1589266800"; d="scan'208";a="229508976" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Jun 2020 00:45:23 -0700 IronPort-SDR: fbWzgUQtZj9rXxZUjUJVkz+RfkqTTiv2Y+nqxk/NV9Kg09VzHEKCyhF695CyYtvoLjOkKSWQP2 65/Iz63EJEkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,278,1589266800"; d="scan'208";a="385396963" Received: from kuha.fi.intel.com ([10.237.72.162]) by fmsmga001.fm.intel.com with SMTP; 25 Jun 2020 00:45:18 -0700 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Thu, 25 Jun 2020 10:45:17 +0300 Date: Thu, 25 Jun 2020 10:45:17 +0300 From: Heikki Krogerus To: Prashant Malani Cc: linux-kernel@vger.kernel.org, Azhar Shaikh , Casey Bowman , Benson Leung , Enric Balletbo i Serra , Guenter Roeck , Lee Jones , Mark Brown , Tzung-Bi Shih , Yicheng Li Subject: Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Message-ID: <20200625074517.GC1487@kuha.fi.intel.com> References: <20200624080926.165107-1-pmalani@chromium.org> <20200624080926.165107-2-pmalani@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200624080926.165107-2-pmalani@chromium.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Co-developed-by: Azhar Shaikh > Co-developed-by: Casey Bowman > Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus > --- > drivers/platform/chrome/cros_ec_typec.c | 70 ++++++++++++++++++++++++- > 1 file changed, 69 insertions(+), 1 deletion(-) > > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c > index 1df1386f32e4..0c041b79cbba 100644 > --- a/drivers/platform/chrome/cros_ec_typec.c > +++ b/drivers/platform/chrome/cros_ec_typec.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > > #define DRV_NAME "cros-ec-typec" > @@ -24,6 +25,7 @@ > /* Supported alt modes. */ > enum { > CROS_EC_ALTMODE_DP = 0, > + CROS_EC_ALTMODE_TBT, > CROS_EC_ALTMODE_MAX, > }; > > @@ -165,6 +167,14 @@ static void cros_typec_register_port_altmodes(struct cros_typec_data *typec, > port->p_altmode[CROS_EC_ALTMODE_DP].svid = USB_TYPEC_DP_SID; > port->p_altmode[CROS_EC_ALTMODE_DP].mode = USB_TYPEC_DP_MODE; > > + /* > + * Register TBT compatibility alt mode. The EC will not enter the mode > + * if it doesn't support it, so it's safe to register it unconditionally > + * here for now. > + */ > + port->p_altmode[CROS_EC_ALTMODE_TBT].svid = USB_TYPEC_TBT_SID; > + port->p_altmode[CROS_EC_ALTMODE_TBT].mode = TYPEC_ANY_MODE; > + > port->state.alt = NULL; > port->state.mode = TYPEC_STATE_USB; > port->state.data = NULL; > @@ -391,6 +401,62 @@ static int cros_typec_usb_safe_state(struct cros_typec_port *port) > return typec_mux_set(port->mux, &port->state); > } > > +/* > + * Spoof the VDOs that were likely communicated by the partner for TBT alt > + * mode. > + */ > +static int cros_typec_enable_tbt(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]; > + struct typec_thunderbolt_data data; > + int ret; > + > + if (typec->pd_ctrl_ver < 2) { > + dev_err(typec->dev, > + "PD_CTRL version too old: %d\n", typec->pd_ctrl_ver); > + return -ENOTSUPP; > + } > + > + /* Device Discover Mode VDO */ > + data.device_mode = TBT_MODE; > + > + if (pd_ctrl->control_flags & USB_PD_CTRL_TBT_LEGACY_ADAPTER) > + data.device_mode = TBT_SET_ADAPTER(TBT_ADAPTER_TBT3); > + > + /* Cable Discover Mode VDO */ > + data.cable_mode = TBT_MODE; > + data.cable_mode |= TBT_SET_CABLE_SPEED(pd_ctrl->cable_speed); > + > + if (pd_ctrl->control_flags & USB_PD_CTRL_OPTICAL_CABLE) > + data.cable_mode |= TBT_CABLE_OPTICAL; > + > + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_LINK_UNIDIR) > + data.cable_mode |= TBT_CABLE_LINK_TRAINING; > + > + if (pd_ctrl->cable_gen) > + data.cable_mode |= TBT_CABLE_ROUNDED; > + > + /* Enter Mode VDO */ > + data.enter_vdo = TBT_SET_CABLE_SPEED(pd_ctrl->cable_speed); > + > + if (pd_ctrl->control_flags & USB_PD_CTRL_ACTIVE_CABLE) > + data.enter_vdo |= TBT_ENTER_MODE_ACTIVE_CABLE; > + > + if (!port->state.alt) { > + port->state.alt = &port->p_altmode[CROS_EC_ALTMODE_TBT]; > + ret = cros_typec_usb_safe_state(port); > + if (ret) > + return ret; > + } > + > + port->state.data = &data; > + port->state.mode = TYPEC_TBT_MODE; > + > + return typec_mux_set(port->mux, &port->state); > +} > + > /* Spoof the VDOs that were likely communicated by the partner. */ > static int cros_typec_enable_dp(struct cros_typec_data *typec, > int port_num, > @@ -448,7 +514,9 @@ static int cros_typec_configure_mux(struct cros_typec_data *typec, int port_num, > if (ret) > return ret; > > - if (mux_flags & USB_PD_MUX_DP_ENABLED) { > + if (mux_flags & USB_PD_MUX_TBT_COMPAT_ENABLED) { > + ret = cros_typec_enable_tbt(typec, port_num, pd_ctrl); > + } else if (mux_flags & USB_PD_MUX_DP_ENABLED) { > ret = cros_typec_enable_dp(typec, port_num, pd_ctrl); > } else if (mux_flags & USB_PD_MUX_SAFE_MODE) { > ret = cros_typec_usb_safe_state(port); > -- > 2.27.0.111.gc72c7da667-goog thanks, -- heikki