Skip to contentSkip to conversation

usb: typec: New attribute files for USB mode

RFC PATCH New Heikki Krogerus 1 participant 4 messages Dec 30, 2019

Subsystems (3)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

cover usb: typec: New attribute files for USB mode

Hi Guenter,

These patches introduce the new sysfs attribute files that allow the user to see and also control the USB mode. The last patch just adds driver for the TBT3 alt mode. The series is made on top of:
https://lore.kernel.org/linux-usb/[email protected]/

What I'm proposing is that we introduce a new sysfs attribute file named "usb_mode" for both the port and partner devices. The file displays the supported USB modes (usb2, usb3, usb4) when read in with both types of devices.

If the user writes to the port attribute file a mode, that mode will be used as the value for the "USB mode" field in the Enter_USB message next time there is a connection. Changing the active mode of the port does not affect the current connection. However, if the user writes to the partner attribute file a mode, Data Reset message is expected to be send to the partner, and the new mode is to be used with the Enter_USB message that follows (as defined in the latest USB Power Delivery spec.).

So the attribute file is the same for both port and partner, but writing to it has different behaviour.

The new attribute files should work, but I want to make sure that the approach is acceptable?

thanks,

Heikki Krogerus (3):
usb: typec: Add attribute file showing the USB mode of the port
usb: typec: Add attribute file showing the USB mode of the partner
usb: typec: Add driver for Thunderbolt 3 Alternate Mode

 Documentation/ABI/testing/sysfs-class-typec |  34 +++
 drivers/usb/typec/altmodes/Kconfig          |   9 +
 drivers/usb/typec/altmodes/Makefile         |   2 +
 drivers/usb/typec/altmodes/thunderbolt.c    | 309 ++++++++++++++++++++
 drivers/usb/typec/class.c                   | 133 ++++++++-
 include/linux/usb/typec.h                   |  11 +
 6 files changed, 497 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/typec/altmodes/thunderbolt.c
Signature · 1 line
2.24.1
author maintainer
#1 lore raw

RFC PATCH 1/3 usb: typec: Add attribute file showing the USB mode of the port

This attribute file, named "usb_mode", will show the supported USB modes, which are USB 2.0, USB 3.2 and USB4. These modes are defined in the latest USB Type-C (R2.0) and USB Power Delivery (R3.0 V2.0) Specifications.

---
 Documentation/ABI/testing/sysfs-class-typec | 12 ++++
 drivers/usb/typec/class.c                   | 61 +++++++++++++++++++++
 include/linux/usb/typec.h                   |  9 +++
 3 files changed, 82 insertions(+)
Documentation/ABI/testing/sysfs-class-typec +12 -0
index 0c2eb26fdc06..8df6f599c967 100644
@@ -108,6 +108,18 @@ Contact:	Heikki Krogerus <[email protected]>
 Description:
 		Revision number of the supported USB Type-C specification.
 
+What:		/sys/class/typec/<port>/usb_mode
+Date:		February 2020
+Contact:	Heikki Krogerus <[email protected]>
+Description:	The supported USB Modes with the active one, that is to be used
+		next time with the Enter_USB message, in brackets. The active
+		mode can be changed by writing to the file when the connector
+		interface supports it.
+
+		Valid values:
+		- usb2 (USB 2.0)
+		- usb3 (USB 3.2)
+		- usb4 (USB4)
 
 USB Type-C partner devices (eg. /sys/class/typec/port0-partner/)
 
drivers/usb/typec/class.c +61 -0

97 lines not on this page · raw message

include/linux/usb/typec.h +9 -0
index 0acfbcd8bf04..1128c3b58618 100644
@@ -72,6 +72,13 @@ enum typec_orientation {
 	TYPEC_ORIENTATION_REVERSE,
 };
 
+enum usb_mode {
+	USB_MODE_NONE,
+	USB_MODE_USB2,
+	USB_MODE_USB3,
+	USB_MODE_USB4
+};
+
 #define USB_CAPABILITY_USB2	BIT(0)
 #define USB_CAPABILITY_USB3	BIT(1)
 #define USB_CAPABILITY_USB4	BIT(2)
@@ -184,6 +191,7 @@ struct typec_partner_desc {
  * @pr_set: Set Power Role
  * @vconn_set: Source VCONN
  * @port_type_set: Set port type
+ * @usb_mode_set: Set the USB Mode to be used with Enter_USB message
  */
 struct typec_operations {
 	int (*try_role)(struct typec_port *port, int role);
@@ -192,6 +200,7 @@ struct typec_operations {
 	int (*vconn_set)(struct typec_port *port, enum typec_role role);
 	int (*port_type_set)(struct typec_port *port,
 			     enum typec_port_type type);
+	int (*usb_mode_set)(struct typec_port *port, enum usb_mode mode);
 };
 
 /*
Signature · 1 line
2.24.1
author maintainer
#2 lore raw

RFC PATCH 2/3 usb: typec: Add attribute file showing the USB mode of the partner

In reply to Heikki Krogerus

Exactly the same attribute that we have for the port. With partners this attribute will get the information from the Discover Identity Command response.

---
 Documentation/ABI/testing/sysfs-class-typec | 22 ++++++
 drivers/usb/typec/class.c                   | 80 +++++++++++++++++++--
 include/linux/usb/typec.h                   |  2 +
 3 files changed, 99 insertions(+), 5 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +22 -0
index 8df6f599c967..f13c2b30fb3d 100644
@@ -116,6 +116,12 @@ Description:	The supported USB Modes with the active one, that is to be used
 		mode can be changed by writing to the file when the connector
 		interface supports it.
 
+		Note. This attribute file can not be used for resetting the mode
+		after the connection has been established. The mode can be reset
+		after connection by writing to the attribute file with the same
+		name ("usb_mode") of the partner device (this is the port device
+		that has the partner attached to).
+
 		Valid values:
 		- usb2 (USB 2.0)
 		- usb3 (USB 3.2)
@@ -173,6 +179,22 @@ Description:
 		will show 0 until Discover Identity command result becomes
 		available. The value can be polled.
 
+What:		/sys/class/typec/<port>-partner/usb_mode
+Date:		February 2020
+Contact:	Heikki Krogerus <[email protected]>
+Description:	The USB Modes that the partner device supports. This information
+		requires the response from Discover Identity command, and will
+		therefore not always be available (as some firmware interfaces
+		do not share the information with the operating system). The
+		currently used mode can be changed by writing to this file when
+		the port driver is able to send Data Reset message to the
+		partner.
+
+		Valid values:
+		- usb2 (USB 2.0)
+		- usb3 (USB 3.2)
+		- usb4 (USB4)
+
 
 USB Type-C cable devices (eg. /sys/class/typec/port0-cable/)
 
drivers/usb/typec/class.c +75 -5

122 lines not on this page · raw message

include/linux/usb/typec.h +2 -0
index 1128c3b58618..e548e4d21908 100644
@@ -192,6 +192,7 @@ struct typec_partner_desc {
  * @vconn_set: Source VCONN
  * @port_type_set: Set port type
  * @usb_mode_set: Set the USB Mode to be used with Enter_USB message
+ * @data_reset: Set new USB mode by using the Data Reset message
  */
 struct typec_operations {
 	int (*try_role)(struct typec_port *port, int role);
@@ -201,6 +202,7 @@ struct typec_operations {
 	int (*port_type_set)(struct typec_port *port,
 			     enum typec_port_type type);
 	int (*usb_mode_set)(struct typec_port *port, enum usb_mode mode);
+	int (*data_reset)(struct typec_port *port, enum usb_mode mode);
 };
 
 /*
Signature · 1 line
2.24.1
author maintainer
#3 lore raw

RFC PATCH 3/3 usb: typec: Add driver for Thunderbolt 3 Alternate Mode

In reply to Heikki Krogerus

Thunderbolt 3 Alternate Mode entry flow is described in USB Type-C Specification Release 2.0.

---
 drivers/usb/typec/altmodes/Kconfig       |   9 +
 drivers/usb/typec/altmodes/Makefile      |   2 +
 drivers/usb/typec/altmodes/thunderbolt.c | 309 +++++++++++++++++++++++
 3 files changed, 320 insertions(+)
 create mode 100644 drivers/usb/typec/altmodes/thunderbolt.c
drivers/usb/typec/altmodes/Kconfig +9 -0
index 187690fd1a5b..e5c116067809 100644
@@ -22,4 +22,13 @@ config TYPEC_NVIDIA_ALTMODE
 	  To compile this driver as a module, choose M here: the
 	  module will be called typec_displayport.
 
+config TYPEC_TBT_ALTMODE
+	tristate "Thunderbolt3 Alternate Mode driver"
+	help
+	  Select this option if you have Thunderbolt3 hardware on your
+	  system.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called typec_thunderbolt.
+
 endmenu
drivers/usb/typec/altmodes/Makefile +2 -0
index 45717548b396..508a68351bd2 100644
@@ -4,3 +4,5 @@ obj-$(CONFIG_TYPEC_DP_ALTMODE)		+= typec_displayport.o
 typec_displayport-y			:= displayport.o
 obj-$(CONFIG_TYPEC_NVIDIA_ALTMODE)	+= typec_nvidia.o
 typec_nvidia-y				:= nvidia.o
+obj-$(CONFIG_TYPEC_TBT_ALTMODE)		+= typec_thunderbolt.o
+typec_thunderbolt-y			:= thunderbolt.o
drivers/usb/typec/altmodes/thunderbolt.c new file +309 -0

309 lines not on this page · raw message

Signature · 1 line
2.24.1