All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver
@ 2020-07-01 11:56 Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes Heikki Krogerus
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Heikki Krogerus @ 2020-07-01 11:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

Hi Greg,

These include a couple of USB4 related improvements to the USB Type-C
class on top of the driver change.

FYI. I will be on vacation starting from next week (July 6th).

thanks,

Heikki Krogerus (4):
  usb: typec: Combine the definitions for Accessory and USB modes
  usb: typec: Add data structure for Enter_USB message
  usb: typec: intel_pmc_mux: Definitions for response status bits
  usb: typec: intel_pmc_mux: Add support for USB4

 drivers/usb/typec/mux/intel_pmc_mux.c | 75 +++++++++++++++++++++++----
 include/linux/usb/typec.h             | 14 +++++
 include/linux/usb/typec_altmode.h     | 14 ++---
 3 files changed, 83 insertions(+), 20 deletions(-)

-- 
2.27.0


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

* [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes
  2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
@ 2020-07-01 11:56 ` Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 2/4] usb: typec: Add data structure for Enter_USB message Heikki Krogerus
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2020-07-01 11:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

There is no need to describe them sparately.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 include/linux/usb/typec_altmode.h | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
index d834e236c6df6..a4b65eaa0f623 100644
--- a/include/linux/usb/typec_altmode.h
+++ b/include/linux/usb/typec_altmode.h
@@ -95,13 +95,7 @@ enum {
  *
  * Port drivers can use TYPEC_MODE_AUDIO and TYPEC_MODE_DEBUG as the mode
  * value for typec_set_mode() when accessory modes are supported.
- */
-enum {
-	TYPEC_MODE_AUDIO = TYPEC_STATE_MODAL,	/* Audio Accessory */
-	TYPEC_MODE_DEBUG,			/* Debug Accessory */
-};
-
-/*
+ *
  * USB4 also requires that the pins on the connector are repurposed, just like
  * Alternate Modes. USB4 mode is however not entered with the Enter Mode Command
  * like the Alternate Modes are, but instead with a special Enter_USB Message.
@@ -112,9 +106,11 @@ enum {
  * state values, just like the Accessory Modes.
  */
 enum {
-	TYPEC_MODE_USB2 = TYPEC_MODE_DEBUG,	/* USB 2.0 mode */
+	TYPEC_MODE_USB2 = TYPEC_STATE_MODAL,	/* USB 2.0 mode */
 	TYPEC_MODE_USB3,			/* USB 3.2 mode */
-	TYPEC_MODE_USB4				/* USB4 mode */
+	TYPEC_MODE_USB4,			/* USB4 mode */
+	TYPEC_MODE_AUDIO,			/* Audio Accessory */
+	TYPEC_MODE_DEBUG,			/* Debug Accessory */
 };
 
 #define TYPEC_MODAL_STATE(_state_)	((_state_) + TYPEC_STATE_MODAL)
-- 
2.27.0


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

* [PATCH 2/4] usb: typec: Add data structure for Enter_USB message
  2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes Heikki Krogerus
@ 2020-07-01 11:56 ` Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 3/4] usb: typec: intel_pmc_mux: Definitions for response status bits Heikki Krogerus
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2020-07-01 11:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

This data structure can be delivered to the mux drivers when
Enter_USB Message is used exactly the same way as the
Alternate Mode specific data structures are delivered to the
mux drivers when Enter Mode Messages are used.

The Enter_USB data structure shall have all details related
to the Enter_USB Message, most importantly the Enter_USB
Date Object that was used.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 include/linux/usb/typec.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 5daa1c49761c3..9cb1bec94b710 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -72,6 +72,20 @@ enum typec_orientation {
 	TYPEC_ORIENTATION_REVERSE,
 };
 
+/*
+ * struct enter_usb_data - Enter_USB Message details
+ * @eudo: Enter_USB Data Object
+ * @active_link_training: Active Cable Plug Link Training
+ *
+ * @active_link_training is a flag that should be set with uni-directional SBRX
+ * communication, and left 0 with passive cables and with bi-directional SBRX
+ * communication.
+ */
+struct enter_usb_data {
+	u32			eudo;
+	unsigned char		active_link_training:1;
+};
+
 /*
  * struct usb_pd_identity - USB Power Delivery identity data
  * @id_header: ID Header VDO
-- 
2.27.0


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

* [PATCH 3/4] usb: typec: intel_pmc_mux: Definitions for response status bits
  2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 2/4] usb: typec: Add data structure for Enter_USB message Heikki Krogerus
@ 2020-07-01 11:56 ` Heikki Krogerus
  2020-07-01 11:56 ` [PATCH 4/4] usb: typec: intel_pmc_mux: Add support for USB4 Heikki Krogerus
  2020-07-01 12:06 ` [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2020-07-01 11:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

Adding definitions for the two status bits that we have in
the command response data structure.

Also, from now on only considering the second status bit,
which tells was the failure fatal or not, if the first bit
is set. If the first bit is not set, then the command was
successful, and we need to ignore the second bit.

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

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index 70ddc9d6d49e4..31fa62f968fb2 100644
--- a/drivers/usb/typec/mux/intel_pmc_mux.c
+++ b/drivers/usb/typec/mux/intel_pmc_mux.c
@@ -19,6 +19,10 @@
 
 #define PMC_USBC_CMD		0xa7
 
+/* Response status bits */
+#define PMC_USB_RESP_STATUS_FAILURE	BIT(0)
+#define PMC_USB_RESP_STATUS_FATAL	BIT(1)
+
 /* "Usage" OOB Message field values */
 enum {
 	PMC_USB_CONNECT,
@@ -130,8 +134,8 @@ static int pmc_usb_command(struct pmc_usb_port *port, u8 *msg, u32 len)
 	 */
 	intel_scu_ipc_dev_command(port->pmc->ipc, PMC_USBC_CMD, 0, msg, len,
 				  response, sizeof(response));
-	if (response[2]) {
-		if (response[2] & BIT(1))
+	if (response[2] & PMC_USB_RESP_STATUS_FAILURE) {
+		if (response[2] & PMC_USB_RESP_STATUS_FATAL)
 			return -EIO;
 		return -EBUSY;
 	}
-- 
2.27.0


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

* [PATCH 4/4] usb: typec: intel_pmc_mux: Add support for USB4
  2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
                   ` (2 preceding siblings ...)
  2020-07-01 11:56 ` [PATCH 3/4] usb: typec: intel_pmc_mux: Definitions for response status bits Heikki Krogerus
@ 2020-07-01 11:56 ` Heikki Krogerus
  2020-07-01 12:06 ` [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: Heikki Krogerus @ 2020-07-01 11:56 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

The PMC mux-agent can be used also to enter USB4 mode. The
mux-agent does not have USB4 specific message, but it can be
put into the TBT3 alternate mode also with USB4. That is OK
because 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 | 67 +++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/typec/mux/intel_pmc_mux.c b/drivers/usb/typec/mux/intel_pmc_mux.c
index 31fa62f968fb2..2aba07c7b221a 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>
@@ -231,6 +232,43 @@ 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)
+{
+	struct enter_usb_data *data = 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;
+
+	if (data->active_link_training)
+		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 ((data->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;
+		fallthrough;
+	default:
+		req.mode_data |= PMC_USB_ALTMODE_ACTIVE_CABLE;
+		break;
+	}
+
+	cable_speed = (data->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;
@@ -272,17 +310,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] 6+ messages in thread

* Re: [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver
  2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
                   ` (3 preceding siblings ...)
  2020-07-01 11:56 ` [PATCH 4/4] usb: typec: intel_pmc_mux: Add support for USB4 Heikki Krogerus
@ 2020-07-01 12:06 ` Greg Kroah-Hartman
  4 siblings, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2020-07-01 12:06 UTC (permalink / raw)
  To: Heikki Krogerus; +Cc: Prashant Malani, Benson Leung, Mani, Rajmohan, linux-usb

On Wed, Jul 01, 2020 at 02:56:14PM +0300, Heikki Krogerus wrote:
> Hi Greg,
> 
> These include a couple of USB4 related improvements to the USB Type-C
> class on top of the driver change.
> 
> FYI. I will be on vacation starting from next week (July 6th).

All look good, thanks, enjoy your vacation!

greg k-h

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

end of thread, other threads:[~2020-07-01 12:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01 11:56 [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Heikki Krogerus
2020-07-01 11:56 ` [PATCH 1/4] usb: typec: Combine the definitions for Accessory and USB modes Heikki Krogerus
2020-07-01 11:56 ` [PATCH 2/4] usb: typec: Add data structure for Enter_USB message Heikki Krogerus
2020-07-01 11:56 ` [PATCH 3/4] usb: typec: intel_pmc_mux: Definitions for response status bits Heikki Krogerus
2020-07-01 11:56 ` [PATCH 4/4] usb: typec: intel_pmc_mux: Add support for USB4 Heikki Krogerus
2020-07-01 12:06 ` [PATCH 0/4] usb: typec: USB4 support to the Intel PMC mux driver Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.