linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields
@ 2020-06-24  8:09 Prashant Malani
  2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
  2020-06-26  9:10 ` [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Enric Balletbo i Serra
  0 siblings, 2 replies; 8+ messages in thread
From: Prashant Malani @ 2020-06-24  8:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: heikki.krogerus, Prashant Malani, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Gwendal Grignou,
	Mark Brown, Tzung-Bi Shih, Yicheng Li

To support Thunderbolt compatibility mode, synchronize
ec_response_usb_pd_control_v2 with the Chrome EC version, so that
we get the Thunderbolt related control fields and macros.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
 .../linux/platform_data/cros_ec_commands.h    | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index a7b0fc440c35..b808570bdd04 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -4917,15 +4917,26 @@ struct ec_response_usb_pd_control_v1 {
 #define USBC_PD_CC_UFP_ATTACHED	4 /* UFP attached to usbc */
 #define USBC_PD_CC_DFP_ATTACHED	5 /* DPF attached to usbc */
 
+/* Active/Passive Cable */
+#define USB_PD_CTRL_ACTIVE_CABLE        BIT(0)
+/* Optical/Non-optical cable */
+#define USB_PD_CTRL_OPTICAL_CABLE       BIT(1)
+/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
+#define USB_PD_CTRL_TBT_LEGACY_ADAPTER  BIT(2)
+/* Active Link Uni-Direction */
+#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR  BIT(3)
+
 struct ec_response_usb_pd_control_v2 {
 	uint8_t enabled;
 	uint8_t role;
 	uint8_t polarity;
 	char state[32];
-	uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
-	uint8_t dp_mode;  /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
-	/* CL:1500994 Current cable type */
-	uint8_t reserved_cable_type;
+	uint8_t cc_state;	/* enum pd_cc_states representing cc state */
+	uint8_t dp_mode;	/* Current DP pin mode (MODE_DP_PIN_[A-E]) */
+	uint8_t reserved;	/* Reserved for future use */
+	uint8_t control_flags;	/* USB_PD_CTRL_*flags */
+	uint8_t cable_speed;	/* TBT_SS_* cable speed */
+	uint8_t cable_gen;	/* TBT_GEN3_* cable rounded support */
 } __ec_align1;
 
 #define EC_CMD_USB_PD_PORTS 0x0102
-- 
2.27.0.111.gc72c7da667-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
  2020-06-24  8:09 [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Prashant Malani
@ 2020-06-24  8:09 ` Prashant Malani
  2020-06-24  9:15   ` Heikki Krogerus
  2020-06-25  7:45   ` Heikki Krogerus
  2020-06-26  9:10 ` [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Enric Balletbo i Serra
  1 sibling, 2 replies; 8+ messages in thread
From: Prashant Malani @ 2020-06-24  8:09 UTC (permalink / raw)
  To: linux-kernel
  Cc: heikki.krogerus, Prashant Malani, Azhar Shaikh, Casey Bowman,
	Benson Leung, Enric Balletbo i Serra, Guenter Roeck, Lee Jones,
	Mark Brown, Tzung-Bi Shih, Yicheng Li

Add mux control support for Thunderbolt compatibility mode.

Suggested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
Signed-off-by: Prashant Malani <pmalani@chromium.org>
---
 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 <linux/usb/typec_altmode.h>
 #include <linux/usb/typec_dp.h>
 #include <linux/usb/typec_mux.h>
+#include <linux/usb/typec_tbt.h>
 #include <linux/usb/role.h>
 
 #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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
  2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
@ 2020-06-24  9:15   ` Heikki Krogerus
  2020-06-24  9:20     ` Heikki Krogerus
  2020-06-25  7:45   ` Heikki Krogerus
  1 sibling, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2020-06-24  9:15 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Azhar Shaikh, Casey Bowman, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Lee Jones, Mark Brown,
	Tzung-Bi Shih, Yicheng Li

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

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 <heikki.krogerus@linux.intel.com>
> Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
> Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> ---
>  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

[-- Attachment #2: 0001-platform-chrome-typec-USB4-support.patch --]
[-- Type: text/plain, Size: 2873 bytes --]

From cdc5d9528c4f751d856dfc1781f125a767a5de20 Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
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 <heikki.krogerus@linux.intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
  2020-06-24  9:15   ` Heikki Krogerus
@ 2020-06-24  9:20     ` Heikki Krogerus
  2020-06-24 17:42       ` Prashant Malani
  0 siblings, 1 reply; 8+ messages in thread
From: Heikki Krogerus @ 2020-06-24  9:20 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Azhar Shaikh, Casey Bowman, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Lee Jones, Mark Brown,
	Tzung-Bi Shih, Yicheng Li

[-- Attachment #1: Type: text/plain, Size: 928 bytes --]

On Wed, Jun 24, 2020 at 12:15:20PM +0300, Heikki Krogerus wrote:
> 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 <heikki.krogerus@linux.intel.com>
> > Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
> > Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
> > Signed-off-by: Prashant Malani <pmalani@chromium.org>
> > ---
> >  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...

Actually, I'll just attach that one here as well. Let me know if you
guys can test these.

thanks,

-- 
heikki

[-- Attachment #2: 0001-usb-typec-intel_pmc_mux-Add-support-for-USB4.patch --]
[-- Type: text/plain, Size: 3459 bytes --]

From 396bd399ac815165ec4992739d45d52ecf234acc Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Date: Wed, 3 Jun 2020 17:00:14 +0300
Subject: [PATCH] usb: typec: intel_pmc_mux: Add support for USB4

The PMC mux-agent can be used also when Enter_USB is used in
order to enter USB4 mode. The mux-agent does not have USB4
specific message, but instead needs to be put into TBT
alternate mode also with USB4. That is OK as the controller
is in any case the same with TBT3 and USB4.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/mux/intel_pmc_mux.c | 65 +++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index 70ddc9d6d49e4..6d223bd360b8e 100644
--- a/drivers/usb/typec/mux/intel_pmc_mux.c
+++ b/drivers/usb/typec/mux/intel_pmc_mux.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
+#include <linux/usb/pd.h>
 #include <linux/usb/role.h>
 #include <linux/usb/typec_mux.h>
 #include <linux/usb/typec_dp.h>
@@ -227,6 +228,41 @@ pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state)
 	return pmc_usb_command(port, (void *)&req, sizeof(req));
 }
 
+static int
+pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
+{
+	u32 eudo = *(u32 *)state->data;
+	struct altmode_req req = { };
+	u8 cable_speed;
+
+	req.usage = PMC_USB_ALT_MODE;
+	req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
+	req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT;
+
+	/* USB4 Mode */
+	req.mode_data = PMC_USB_ALTMODE_FORCE_LSR;
+	req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
+
+	req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
+	req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
+
+	switch ((eudo & EUDO_CABLE_TYPE_MASK) >> EUDO_CABLE_TYPE_SHIFT) {
+	case EUDO_CABLE_TYPE_PASSIVE:
+		break;
+	case EUDO_CABLE_TYPE_OPTICAL:
+		req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE;
+		/* fall through */
+	default:
+		req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
+		break;
+	}
+
+	cable_speed = (eudo & EUDO_CABLE_SPEED_MASK) >> EUDO_CABLE_SPEED_SHIFT;
+	req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed);
+
+	return pmc_usb_command(port, (void *)&req, sizeof(req));
+}
+
 static int pmc_usb_mux_safe_state(struct pmc_usb_port *port)
 {
 	u8 msg;
@@ -268,17 +304,28 @@ pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
 {
 	struct pmc_usb_port *port = typec_mux_get_drvdata(mux);
 
-	if (!state->alt)
-		return 0;
-
 	if (state->mode == TYPEC_STATE_SAFE)
 		return pmc_usb_mux_safe_state(port);
-
-	switch (state->alt->svid) {
-	case USB_TYPEC_TBT_SID:
-		return pmc_usb_mux_tbt(port, state);
-	case USB_TYPEC_DP_SID:
-		return pmc_usb_mux_dp(port, state);
+	if (state->mode == TYPEC_STATE_USB)
+		return pmc_usb_connect(port);
+
+	if (state->alt) {
+		switch (state->alt->svid) {
+		case USB_TYPEC_TBT_SID:
+			return pmc_usb_mux_tbt(port, state);
+		case USB_TYPEC_DP_SID:
+			return pmc_usb_mux_dp(port, state);
+		}
+	} else {
+		switch (state->mode) {
+		case TYPEC_MODE_USB2:
+			/* REVISIT: Try with usb3_port set to 0? */
+			break;
+		case TYPEC_MODE_USB3:
+			return pmc_usb_connect(port);
+		case TYPEC_MODE_USB4:
+			return pmc_usb_mux_usb4(port, state);
+		}
 	}
 
 	return -EOPNOTSUPP;
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
  2020-06-24  9:20     ` Heikki Krogerus
@ 2020-06-24 17:42       ` Prashant Malani
  0 siblings, 0 replies; 8+ messages in thread
From: Prashant Malani @ 2020-06-24 17:42 UTC (permalink / raw)
  To: Heikki Krogerus
  Cc: linux-kernel, Azhar Shaikh, Casey Bowman, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Lee Jones, Mark Brown,
	Tzung-Bi Shih, Yicheng Li

Hi Heikki,

On Wed, Jun 24, 2020 at 12:20:40PM +0300, Heikki Krogerus wrote:
> On Wed, Jun 24, 2020 at 12:15:20PM +0300, Heikki Krogerus wrote:
> > 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 <heikki.krogerus@linux.intel.com>
> > > Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
> > > Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
> > > Signed-off-by: Prashant Malani <pmalani@chromium.org>
> > > ---
> > >  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...
> 
> Actually, I'll just attach that one here as well. Let me know if you
> guys can test these.

Thanks for the patches. Will try them out today and compare the PMC IPC
buffers against what extcon is doing.

Best regards,

-Prashant
> 
> thanks,
> 
> -- 
> heikki

> From 396bd399ac815165ec4992739d45d52ecf234acc Mon Sep 17 00:00:00 2001
> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> Date: Wed, 3 Jun 2020 17:00:14 +0300
> Subject: [PATCH] usb: typec: intel_pmc_mux: Add support for USB4
> 
> The PMC mux-agent can be used also when Enter_USB is used in
> order to enter USB4 mode. The mux-agent does not have USB4
> specific message, but instead needs to be put into TBT
> alternate mode also with USB4. That is OK as the controller
> is in any case the same with TBT3 and USB4.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/mux/intel_pmc_mux.c | 65 +++++++++++++++++++++++----
>  1 file changed, 56 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
> index 70ddc9d6d49e4..6d223bd360b8e 100644
> --- a/drivers/usb/typec/mux/intel_pmc_mux.c
> +++ b/drivers/usb/typec/mux/intel_pmc_mux.c
> @@ -10,6 +10,7 @@
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
> +#include <linux/usb/pd.h>
>  #include <linux/usb/role.h>
>  #include <linux/usb/typec_mux.h>
>  #include <linux/usb/typec_dp.h>
> @@ -227,6 +228,41 @@ pmc_usb_mux_tbt(struct pmc_usb_port *port, struct typec_mux_state *state)
>  	return pmc_usb_command(port, (void *)&req, sizeof(req));
>  }
>  
> +static int
> +pmc_usb_mux_usb4(struct pmc_usb_port *port, struct typec_mux_state *state)
> +{
> +	u32 eudo = *(u32 *)state->data;
> +	struct altmode_req req = { };
> +	u8 cable_speed;
> +
> +	req.usage = PMC_USB_ALT_MODE;
> +	req.usage |= port->usb3_port << PMC_USB_MSG_USB3_PORT_SHIFT;
> +	req.mode_type = PMC_USB_MODE_TYPE_TBT << PMC_USB_MODE_TYPE_SHIFT;
> +
> +	/* USB4 Mode */
> +	req.mode_data = PMC_USB_ALTMODE_FORCE_LSR;
> +	req.mode_data |= PMC_USB_ALTMODE_ACTIVE_LINK;
> +
> +	req.mode_data |= (port->orientation - 1) << PMC_USB_ALTMODE_ORI_SHIFT;
> +	req.mode_data |= (port->role - 1) << PMC_USB_ALTMODE_UFP_SHIFT;
> +
> +	switch ((eudo & EUDO_CABLE_TYPE_MASK) >> EUDO_CABLE_TYPE_SHIFT) {
> +	case EUDO_CABLE_TYPE_PASSIVE:
> +		break;
> +	case EUDO_CABLE_TYPE_OPTICAL:
> +		req.mode_data |= PMC_USB_ALTMODE_CABLE_TYPE;
> +		/* fall through */
> +	default:
> +		req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
> +		break;
> +	}
> +
> +	cable_speed = (eudo & EUDO_CABLE_SPEED_MASK) >> EUDO_CABLE_SPEED_SHIFT;
> +	req.mode_data |= PMC_USB_ALTMODE_CABLE_SPD(cable_speed);
> +
> +	return pmc_usb_command(port, (void *)&req, sizeof(req));
> +}
> +
>  static int pmc_usb_mux_safe_state(struct pmc_usb_port *port)
>  {
>  	u8 msg;
> @@ -268,17 +304,28 @@ pmc_usb_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
>  {
>  	struct pmc_usb_port *port = typec_mux_get_drvdata(mux);
>  
> -	if (!state->alt)
> -		return 0;
> -
>  	if (state->mode == TYPEC_STATE_SAFE)
>  		return pmc_usb_mux_safe_state(port);
> -
> -	switch (state->alt->svid) {
> -	case USB_TYPEC_TBT_SID:
> -		return pmc_usb_mux_tbt(port, state);
> -	case USB_TYPEC_DP_SID:
> -		return pmc_usb_mux_dp(port, state);
> +	if (state->mode == TYPEC_STATE_USB)
> +		return pmc_usb_connect(port);
> +
> +	if (state->alt) {
> +		switch (state->alt->svid) {
> +		case USB_TYPEC_TBT_SID:
> +			return pmc_usb_mux_tbt(port, state);
> +		case USB_TYPEC_DP_SID:
> +			return pmc_usb_mux_dp(port, state);
> +		}
> +	} else {
> +		switch (state->mode) {
> +		case TYPEC_MODE_USB2:
> +			/* REVISIT: Try with usb3_port set to 0? */
> +			break;
> +		case TYPEC_MODE_USB3:
> +			return pmc_usb_connect(port);
> +		case TYPEC_MODE_USB4:
> +			return pmc_usb_mux_usb4(port, state);
> +		}
>  	}
>  
>  	return -EOPNOTSUPP;
> -- 
> 2.27.0
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support
  2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
  2020-06-24  9:15   ` Heikki Krogerus
@ 2020-06-25  7:45   ` Heikki Krogerus
  1 sibling, 0 replies; 8+ messages in thread
From: Heikki Krogerus @ 2020-06-25  7:45 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Azhar Shaikh, Casey Bowman, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck, Lee Jones, Mark Brown,
	Tzung-Bi Shih, Yicheng Li

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 <heikki.krogerus@linux.intel.com>
> Co-developed-by: Azhar Shaikh <azhar.shaikh@intel.com>
> Co-developed-by: Casey Bowman <casey.g.bowman@intel.com>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  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 <linux/usb/typec_altmode.h>
>  #include <linux/usb/typec_dp.h>
>  #include <linux/usb/typec_mux.h>
> +#include <linux/usb/typec_tbt.h>
>  #include <linux/usb/role.h>
>  
>  #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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields
  2020-06-24  8:09 [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Prashant Malani
  2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
@ 2020-06-26  9:10 ` Enric Balletbo i Serra
  2020-06-26 19:04   ` Prashant Malani
  1 sibling, 1 reply; 8+ messages in thread
From: Enric Balletbo i Serra @ 2020-06-26  9:10 UTC (permalink / raw)
  To: Prashant Malani, linux-kernel
  Cc: heikki.krogerus, Benson Leung, Guenter Roeck, Gwendal Grignou,
	Mark Brown, Tzung-Bi Shih, Yicheng Li

Hi Prashant,

On 24/6/20 10:09, Prashant Malani wrote:
> To support Thunderbolt compatibility mode, synchronize
> ec_response_usb_pd_control_v2 with the Chrome EC version, so that
> we get the Thunderbolt related control fields and macros.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Applied both patches for 5.9

> ---
>  .../linux/platform_data/cros_ec_commands.h    | 19 +++++++++++++++----
>  1 file changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
> index a7b0fc440c35..b808570bdd04 100644
> --- a/include/linux/platform_data/cros_ec_commands.h
> +++ b/include/linux/platform_data/cros_ec_commands.h
> @@ -4917,15 +4917,26 @@ struct ec_response_usb_pd_control_v1 {
>  #define USBC_PD_CC_UFP_ATTACHED	4 /* UFP attached to usbc */
>  #define USBC_PD_CC_DFP_ATTACHED	5 /* DPF attached to usbc */
>  
> +/* Active/Passive Cable */
> +#define USB_PD_CTRL_ACTIVE_CABLE        BIT(0)
> +/* Optical/Non-optical cable */
> +#define USB_PD_CTRL_OPTICAL_CABLE       BIT(1)
> +/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
> +#define USB_PD_CTRL_TBT_LEGACY_ADAPTER  BIT(2)
> +/* Active Link Uni-Direction */
> +#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR  BIT(3)
> +
>  struct ec_response_usb_pd_control_v2 {
>  	uint8_t enabled;
>  	uint8_t role;
>  	uint8_t polarity;
>  	char state[32];
> -	uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
> -	uint8_t dp_mode;  /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
> -	/* CL:1500994 Current cable type */
> -	uint8_t reserved_cable_type;
> +	uint8_t cc_state;	/* enum pd_cc_states representing cc state */
> +	uint8_t dp_mode;	/* Current DP pin mode (MODE_DP_PIN_[A-E]) */
> +	uint8_t reserved;	/* Reserved for future use */
> +	uint8_t control_flags;	/* USB_PD_CTRL_*flags */
> +	uint8_t cable_speed;	/* TBT_SS_* cable speed */
> +	uint8_t cable_gen;	/* TBT_GEN3_* cable rounded support */
>  } __ec_align1;
>  
>  #define EC_CMD_USB_PD_PORTS 0x0102
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields
  2020-06-26  9:10 ` [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Enric Balletbo i Serra
@ 2020-06-26 19:04   ` Prashant Malani
  0 siblings, 0 replies; 8+ messages in thread
From: Prashant Malani @ 2020-06-26 19:04 UTC (permalink / raw)
  To: Enric Balletbo i Serra
  Cc: Linux Kernel Mailing List, Heikki Krogerus, Benson Leung,
	Guenter Roeck, Gwendal Grignou, Mark Brown, Tzung-Bi Shih,
	Yicheng Li

Thanks Enric!

On Fri, Jun 26, 2020 at 2:11 AM Enric Balletbo i Serra
<enric.balletbo@collabora.com> wrote:
>
> Hi Prashant,
>
> On 24/6/20 10:09, Prashant Malani wrote:
> > To support Thunderbolt compatibility mode, synchronize
> > ec_response_usb_pd_control_v2 with the Chrome EC version, so that
> > we get the Thunderbolt related control fields and macros.
> >
> > Signed-off-by: Prashant Malani <pmalani@chromium.org>
>
> Applied both patches for 5.9
>
> > ---
> >  .../linux/platform_data/cros_ec_commands.h    | 19 +++++++++++++++----
> >  1 file changed, 15 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
> > index a7b0fc440c35..b808570bdd04 100644
> > --- a/include/linux/platform_data/cros_ec_commands.h
> > +++ b/include/linux/platform_data/cros_ec_commands.h
> > @@ -4917,15 +4917,26 @@ struct ec_response_usb_pd_control_v1 {
> >  #define USBC_PD_CC_UFP_ATTACHED      4 /* UFP attached to usbc */
> >  #define USBC_PD_CC_DFP_ATTACHED      5 /* DPF attached to usbc */
> >
> > +/* Active/Passive Cable */
> > +#define USB_PD_CTRL_ACTIVE_CABLE        BIT(0)
> > +/* Optical/Non-optical cable */
> > +#define USB_PD_CTRL_OPTICAL_CABLE       BIT(1)
> > +/* 3rd Gen TBT device (or AMA)/2nd gen tbt Adapter */
> > +#define USB_PD_CTRL_TBT_LEGACY_ADAPTER  BIT(2)
> > +/* Active Link Uni-Direction */
> > +#define USB_PD_CTRL_ACTIVE_LINK_UNIDIR  BIT(3)
> > +
> >  struct ec_response_usb_pd_control_v2 {
> >       uint8_t enabled;
> >       uint8_t role;
> >       uint8_t polarity;
> >       char state[32];
> > -     uint8_t cc_state; /* USBC_PD_CC_*Encoded cc state */
> > -     uint8_t dp_mode;  /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
> > -     /* CL:1500994 Current cable type */
> > -     uint8_t reserved_cable_type;
> > +     uint8_t cc_state;       /* enum pd_cc_states representing cc state */
> > +     uint8_t dp_mode;        /* Current DP pin mode (MODE_DP_PIN_[A-E]) */
> > +     uint8_t reserved;       /* Reserved for future use */
> > +     uint8_t control_flags;  /* USB_PD_CTRL_*flags */
> > +     uint8_t cable_speed;    /* TBT_SS_* cable speed */
> > +     uint8_t cable_gen;      /* TBT_GEN3_* cable rounded support */
> >  } __ec_align1;
> >
> >  #define EC_CMD_USB_PD_PORTS 0x0102
> >

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-06-26 19:05 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-24  8:09 [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Prashant Malani
2020-06-24  8:09 ` [PATCH 2/2] platform/chrome: cros_ec_typec: Add TBT compat support Prashant Malani
2020-06-24  9:15   ` Heikki Krogerus
2020-06-24  9:20     ` Heikki Krogerus
2020-06-24 17:42       ` Prashant Malani
2020-06-25  7:45   ` Heikki Krogerus
2020-06-26  9:10 ` [PATCH 1/2] platform/chrome: cros_ec_typec: Add TBT pd_ctrl fields Enric Balletbo i Serra
2020-06-26 19:04   ` Prashant Malani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).