Skip to contentSkip to conversation

USB Type-C Connector class

PATCH Superseded Heikki Krogerus 5 participants 34 messages Jun 21, 2016 – Jul 4, 2016 3 messages not in the archive

Subsystems (3)

v3 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

v3 cover USB Type-C Connector class

Hi,

I'm considering all the RFCs I send after v1 as v2 (I don't remember how many I send). Hope this is OK and hope there is nothing big missing anymore (or broken).

Sorry about the delay. I've been really busy with some internal tasks. I'm guessing we missed v4.8 with this thing. I'm sorry about that.

I'm including in this series a driver for the Broxton PMIC USB Type-C PHY.

Changes since v2:
- Notification on role and alternate mode changes
- cleanups

Changes since v1:
- Completely rewrote alternate mode support
- Patners, cables and cable plugs presented as devices.

Heikki Krogerus (2):
usb: USB Type-C connector class
usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY

 Documentation/ABI/testing/sysfs-class-typec |  163 ++++
 Documentation/usb/typec.txt                 |  101 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |   21 +
 drivers/usb/typec/Makefile                  |    2 +
 drivers/usb/typec/typec.c                   | 1173 +++++++++++++++++++++++++++
 drivers/usb/typec/typec_wcove.c             |  376 +++++++++
 include/linux/usb/typec.h                   |  255 ++++++
 10 files changed, 2104 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 drivers/usb/typec/typec_wcove.c
 create mode 100644 include/linux/usb/typec.h
Signature · 1 line
2.8.1
author maintainer
#1 lore raw

PATCH v3 1/2 usb: USB Type-C connector class

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when USB PD is available, also control over power role swapping and Alternate Modes.

---
 Documentation/ABI/testing/sysfs-class-typec |  163 ++++
 Documentation/usb/typec.txt                 |  101 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |    7 +
 drivers/usb/typec/Makefile                  |    1 +
 drivers/usb/typec/typec.c                   | 1173 +++++++++++++++++++++++++++
 include/linux/usb/typec.h                   |  255 ++++++
 9 files changed, 1713 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 include/linux/usb/typec.h
Documentation/ABI/testing/sysfs-class-typec new file +163 -0
new file mode 100644
index 0000000..ce577f3
@@ -0,0 +1,163 @@
+USB Type-C port devices (eg. /sys/class/typec/usbc0/)
+
+What:		/sys/class/typec/<port>/current_data_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current USB data role the port is operating in. This
+		attribute can be used for requestion data role swapping on th
+		port.
+
+What:		/sys/class/typec/<port>/current_power_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current power role, source or sink, of the port. This
+		attribute can be used to request power role swap on the port
+		when USB Power Delivery is available.
+
+What:		/sys/class/typec/<port>/current_vconn_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current VCONN role, source or sink, of the port. This
+		attribute can be used to request vconn role swap on the port
+		when USB Power Delivery is available.
+
+What:		/sys/class/typec/<port>/power_operation_mode
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current power power mode the port is in. Reads as on
+		of the following:
+		- USB - Normal power levels defined in USB specifications
+		- BC1.2 - Power levels defined in Battery Charging Specification
+			  v1.2
+		- USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C
+				    specification.
+		- USB Type-C 3.0A - Higher 3A current defined in USB Type-C
+				    specification.
+                - USB Power Delivery - The voltages and currents defined in USB
+				       Power Delivery specification
+
+What:		/sys/class/typec/<port>/preferred_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The user space can notify the driver about the preferred role.
+		It should be handled as enabling of Try.SRC or Try.SNK, as
+		defined in USB Type-C specification, in the port drivers.
+
+What:		/sys/class/typec/<port>/supported_accessory_modes
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the Accessory Modes, defined in the USB Type-C
+		specification, the port supports.
+
+What:		/sys/class/typec/<port>/supported_data_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the USB data roles, host or device, the port is capable
+		of supporting.
+
+What:		/sys/class/typec/<port>/supported_power_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the power roles, source and/or sink, the port is capable
+		of supporting.
+
+What:		/sys/class/typec/<port>/supports_usb_power_delivery
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the port support USB Power Delivery.
+
+
+USB Type-C partner devices (eg. /sys/class/typec/usbc0-partner/)
+
+What:		/sys/class/typec/<port>-partner/accessory
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the name of the Accessory Mode if the partner attached to
+		the port is an accessory. Otherwise shows nothing.
+
+What:		/sys/class/typec/<port>-partner/type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the type of the partner. Can be one of the following:
+		- USB - When the partner is normal USB host/peripheral.
+		- Charger - When the partner has been identified as dedicated
+			    charger.
+		- Alternate Mode - When the partner supports Alternate Modes.
+		- Accessory - When the partner is one of the accessories with
+			      specific Accessory Mode defined in USB Type-C
+			      specification.
+
+
+USB Type-C cable devices (eg. /sys/class/typec/usbc0-cable/)
+
+Note: The two cable plugs will have their own devices presenting when available
+(eg. /sys/class/typec/usbc0-plug0). Both plugs may have their own active
+alternate modes as described in USB Type-C and USB Power Delivery
+specifications.
+
+What:		/sys/class/typec/<port>-cable/active
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the cable is active or passive. Only active cables can
+		have configurable alternate modes, therefore only active cables
+		will have plug devices.
+
+What:		/sys/class/typec/<port>-cable/plug_type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows type of the plug on the cable:
+		Type-A - Standard A
+		Type-B - Standard B
+		Type-C - USB Type-C
+		Captive - Non-standard
+
+
+Alternate Mode devices  (For example,
+/sys/class/typec/usbc0-partner/usbc0-partner.svid:xxxx/)
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/active
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the mode is active or not. The attribute can be used
+		for entering/exiting the mode with partners and cable plugs, and
+		with the port alternate modes it can be used for disabling
+		support for specific alternate modes.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/description
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows description of the mode. The description is optional for
+		the drivers, just like with the Billboard Devices.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/vdo
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the VDO in hexadecimal returned from the Discover Modes
+		command.
+
+What:		/sys/class/typec/<port>/<port>.svid:<svid>/<mode>/supported_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the roles, source or sink, the mode is supported with.
+
+		This attribute is available for the devices describing the
+		alternate modes a port supports, and it will not be exposed with
+		the devices presenting the alternate modes the partners or cable
+		plugs support.
Documentation/usb/typec.txt new file +101 -0

101 lines not on this page · raw message

MAINTAINERS +9 -0
index e1b090f..0db33fb 100644
@@ -11983,6 +11983,15 @@ F:	drivers/usb/
 F:	include/linux/usb.h
 F:	include/linux/usb/
 
+USB TYPEC SUBSYSTEM
+M:	Heikki Krogerus <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/ABI/testing/sysfs-class-typec
+F:	Documentation/usb/typec.txt
+F:	drivers/usb/typec/
+F:	include/linux/usb/typec.h
+
 USB UHCI DRIVER
 M:	Alan Stern <[email protected]>
 L:	[email protected]
drivers/usb/Kconfig +2 -0
index 8689dcb..f42a3d3 100644
@@ -150,6 +150,8 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+source "drivers/usb/typec/Kconfig"
+
 config USB_LED_TRIG
 	bool "USB LED Triggers"
 	depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
index dca7856..51e381e 100644
@@ -61,3 +61,5 @@ obj-$(CONFIG_USB_GADGET)	+= gadget/
 obj-$(CONFIG_USB_COMMON)	+= common/
 
 obj-$(CONFIG_USBIP_CORE)	+= usbip/
+
+obj-$(CONFIG_TYPEC)		+= typec/
drivers/usb/typec/Kconfig new file +7 -0
new file mode 100644
index 0000000..b229fb9
@@ -0,0 +1,7 @@
+
+menu "USB PD and Type-C drivers"
+
+config TYPEC
+	tristate
+
+endmenu
drivers/usb/typec/Makefile new file +1 -0
new file mode 100644
index 0000000..1012a8b
@@ -0,0 +1 @@
+obj-$(CONFIG_TYPEC)		+= typec.o
drivers/usb/typec/typec.c new file +1173 -0

1,173 lines not on this page · raw message

include/linux/usb/typec.h new file +255 -0

255 lines not on this page · raw message

Signature · 1 line
2.8.1
#2 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 7 lines · Heikki Krogerus
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+What:          /sys/class/typec/<port>/supported_data_roles
+Data:          June 2016
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Lists the USB data roles, host or device, the port is

capable
+ of supporting.

On third thought, this is a problem. Looking at 4.4.8.1 DEVICE_CAPABILITIES (Required) of USB Type-C Port Controller Interface Specification we lack capability.

A port that can do DRP is not the same thing as a port that can be switched between DFP and UFP. We cannot express that.

Regards
Oliver

author maintainer
#3 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 13 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+What:          /sys/class/typec/<port>/supported_data_roles
+Data:          June 2016
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Lists the USB data roles, host or device, the port is

capable
+ of supporting.

On third thought, this is a problem. Looking at 4.4.8.1 DEVICE_CAPABILITIES (Required) of USB Type-C Port Controller Interface Specification we lack capability.

Quoted 2 lines

A port that can do DRP is not the same thing as a port that can be switched between DFP and UFP. We cannot express that.

What do you mean? DRP means we support and are able to swap the data role, but it just does not mean we can act as both source and sink. And that information we already get from separate attribute:
"supported_power_roles".

But if the port is DRP, we will always be able to swap the data role between DFP and UFP.

Thanks,

Signature · 1 line
heikki
author maintainer
#4 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 17 lines · Heikki Krogerus
Quoted 13 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+What:          /sys/class/typec/<port>/supported_data_roles
+Data:          June 2016
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Lists the USB data roles, host or device, the port is

capable
+ of supporting.

On third thought, this is a problem. Looking at 4.4.8.1 DEVICE_CAPABILITIES (Required) of USB Type-C Port Controller Interface Specification we lack capability.

Quoted 2 lines

A port that can do DRP is not the same thing as a port that can be switched between DFP and UFP. We cannot express that.

Quoted 7 lines

What do you mean? DRP means we support and are able to swap the data role, but it just does not mean we can act as both source and sink. And that information we already get from separate attribute:
"supported_power_roles".

But if the port is DRP, we will always be able to swap the data role between DFP and UFP.

Just to clarify: DRP as it's defined in Type-C spec < 1.2 means the data role, not power role. And that is what Universal Serial Bus Type-CTM Port Controller specification is based on. Please correct me if I'm wrong.

Thanks,

Signature · 1 line
heikki
#5 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 9 lines · Heikki Krogerus
Quoted 2 lines · Heikki Krogerus

But if the port is DRP, we will always be able to swap the data role between DFP and UFP.

Just to clarify: DRP as it's defined in Type-C spec < 1.2 means the data role, not power role. And that is what Universal Serial Bus Type-CTM Port Controller specification is based on. Please correct me if I'm wrong.

Understood. That is exactly the problem. That spec defines two ways to support host and client.

Regards
Oliver

#6 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

In reply to Heikki Krogerus
Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+What:          /sys/class/typec/<port>/supported_data_roles
+Data:          June 2016
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Lists the USB data roles, host or device, the port is

capable
+ of supporting.

On third thought, this is a problem. Looking at 4.4.8.1 DEVICE_CAPABILITIES (Required) of USB Type-C Port Controller Interface Specification we lack capability.

Quoted 4 lines
Quoted 2 lines

A port that can do DRP is not the same thing as a port that can be switched between DFP and UFP. We cannot express that.

What do you mean? DRP means we support and are able to swap the data

No. That is the error. We support them concurrently. And that is not obvious. It is perfectly possible to support both but not concurrently.

Quoted 3 lines

role, but it just does not mean we can act as both source and sink. And that information we already get from separate attribute:
"supported_power_roles".

But it is different. Suppose we have a port that can be switched between UFP and DFP, as the spec defines. If it is switched to DFP and we plug in a DFP it will not work. UFP into UFP has the same result.

Plugging it into a DRP will always work.

It is true that both support host and device, but the capability of the ports is different. And that is not expressed.

Regards
Oliver

author maintainer
#7 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 27 lines · Oliver Neukum
Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Oliver Neukum
Quoted 7 lines · Heikki Krogerus
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+What:          /sys/class/typec/<port>/supported_data_roles
+Data:          June 2016
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Lists the USB data roles, host or device, the port is

capable
+ of supporting.

On third thought, this is a problem. Looking at 4.4.8.1 DEVICE_CAPABILITIES (Required) of USB Type-C Port Controller Interface Specification we lack capability.

Quoted 4 lines
Quoted 2 lines

A port that can do DRP is not the same thing as a port that can be switched between DFP and UFP. We cannot express that.

What do you mean? DRP means we support and are able to swap the data

No. That is the error. We support them concurrently. And that is not obvious. It is perfectly possible to support both but not concurrently.

Quoted 3 lines

role, but it just does not mean we can act as both source and sink. And that information we already get from separate attribute:
"supported_power_roles".

Quoted 8 lines

But it is different. Suppose we have a port that can be switched between UFP and DFP, as the spec defines. If it is switched to DFP and we plug in a DFP it will not work. UFP into UFP has the same result.

Plugging it into a DRP will always work.

It is true that both support host and device, but the capability of the ports is different. And that is not expressed.

Sorry but I don't think I understand?

So if we can act only as UFP, the supported_data_roles will list:

device

If we can act only as DFP, the supported_data_roles will list:

host

If our port is DRD (which would be DRP in the port controller spec), the supported_power_roles will list:

device, host

And the power role, if the port is Source only, the supported_power_roles will list:

source

If the port is Sink only, the supported_power_roles will list:

sink

If our port is DRP, the supported_power_roles will list:

source, sink

What is there that is missing? We are able to express all the types of "Roles Supported" that the DEVICE_CAPABILITIES define, no?

Thanks,

Signature · 1 line
heikki
#8 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 12 lines · Heikki Krogerus

If our port is DRD (which would be DRP in the port controller spec), the supported_power_roles will list:

device, host

And the power role, if the port is Source only, the supported_power_roles will list:

source

If the port is Sink only, the supported_power_roles will list:

Quoted 8 lines

sink

If our port is DRP, the supported_power_roles will list:

source, sink

What is there that is missing? We are able to express all the types of "Roles Supported" that the DEVICE_CAPABILITIES define, no?

No, because these are distinct in time. Some ports are DRP so they support

device, host

at the same time. Some ports can be switched between DFP and UFP they then either support host or device. But you lose the information that the ports can be switched.

Regards
Oliver

author maintainer
#9 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 22 lines · Oliver Neukum
Quoted 12 lines · Heikki Krogerus

If our port is DRD (which would be DRP in the port controller spec), the supported_power_roles will list:

device, host

And the power role, if the port is Source only, the supported_power_roles will list:

source

If the port is Sink only, the supported_power_roles will list:

Quoted 8 lines

sink

If our port is DRP, the supported_power_roles will list:

source, sink

What is there that is missing? We are able to express all the types of "Roles Supported" that the DEVICE_CAPABILITIES define, no?

Quoted 8 lines

No, because these are distinct in time. Some ports are DRP so they support

device, host

at the same time. Some ports can be switched between DFP and UFP they then either support host or device. But you lose the information that the ports can be switched.

You can't ever be host and device at the same time. Just like you can't ever be source and sink at the same time.

Are we now talking about how should a port be advertised to the partners? So basically, do you want to be able to program the port to be DFP only, UFP only or DRP from user space?

Thanks,

Signature · 1 line
heikki
#10 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 26 lines · Heikki Krogerus
Quoted 25 lines · Oliver Neukum
Quoted 12 lines · Heikki Krogerus

If our port is DRD (which would be DRP in the port controller spec), the supported_power_roles will list:

device, host

And the power role, if the port is Source only, the supported_power_roles will list:

source

If the port is Sink only, the supported_power_roles will list:

Quoted 8 lines

sink

If our port is DRP, the supported_power_roles will list:

source, sink

What is there that is missing? We are able to express all the types of "Roles Supported" that the DEVICE_CAPABILITIES define, no?

No, because these are distinct in time. Some ports are DRP so they support

Quoted 8 lines
Quoted 5 lines

device, host

at the same time. Some ports can be switched between DFP and UFP they then either support host or device. But you lose the information that the ports can be switched.

You can't ever be host and device at the same time. Just like you can't ever be source and sink at the same time.

True, but you can be able to become host and device at the same time. That is the purpose of a DRP port.

And you can be able to become a host and be able to become a device. But not at the same time. These ports are switchable.

The current API cannot express the difference.

Quoted 3 lines

Are we now talking about how should a port be advertised to the partners? So basically, do you want to be able to program the port to be DFP only, UFP only or DRP from user space?

That would be cool, but according to the spec this is an unalterable attribute. Please look at section 4.4.8.1
It clearly describes different types of ports. We cannot express the differences between the types described there with the current API.

Regards
Oliver

author maintainer
#11 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 29 lines · Oliver Neukum
Quoted 28 lines · Heikki Krogerus
Quoted 27 lines · Oliver Neukum
Quoted 12 lines · Heikki Krogerus

If our port is DRD (which would be DRP in the port controller spec), the supported_power_roles will list:

device, host

And the power role, if the port is Source only, the supported_power_roles will list:

source

If the port is Sink only, the supported_power_roles will list:

Quoted 8 lines

sink

If our port is DRP, the supported_power_roles will list:

source, sink

What is there that is missing? We are able to express all the types of "Roles Supported" that the DEVICE_CAPABILITIES define, no?

No, because these are distinct in time. Some ports are DRP so they support

device, host

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

at the same time. Some ports can be switched between DFP and UFP they then either support host or device. But you lose the information that the ports can be switched.

You can't ever be host and device at the same time. Just like you can't ever be source and sink at the same time.

True, but you can be able to become host and device at the same time.

No you can't..

Quoted 1 line

That is the purpose of a DRP port.

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Quoted 4 lines

And you can be able to become a host and be able to become a device. But not at the same time. These ports are switchable.

The current API cannot express the difference.

I think you have misunderstood something. The only case where the port can be dual-role is if it's set to be DRP. Otherwise it's Source only OR Sink only.

The "Role Supported" bits only tell us how we can program for example the ROLE_CONTROL registers. I guess the "Roles Supported" bits in DEVICE_CAPABILITIES are not explained properly, so let's go over them here:

000b = Source _or_ Sink only
001b = Source only
010b = Sink only
011b = Sink only with support for autonomously detected accessory modes 100b = DRP only, and this I believe mean we can not program the port
to be Sink only or Source only
101b = Source only OR Sink only OR DRP, plus ability to detect
accessories and I guess also cables autonomously
110b = Source only OR Sink only OR DRP

So where the spec lists "Source, Sink", it actually should have said "Source only OR Sink only".

But you still have only the following options for a port:
1) Source only (host)
2) Sink only (device)
3) DRP (device, host)

Thanks,

Signature · 1 line
heikki
#12 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 4 lines · Heikki Krogerus

On Wed, Jun 22, 2016 at 06:44:18PM +0200, Oliver Neukum wrote:

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Yes, but it is unclear what you will be after a connection and that's the point.

Quoted 14 lines
Quoted 4 lines

And you can be able to become a host and be able to become a device. But not at the same time. These ports are switchable.

The current API cannot express the difference.

I think you have misunderstood something. The only case where the port can be dual-role is if it's set to be DRP. Otherwise it's Source only OR Sink only.

The "Role Supported" bits only tell us how we can program for example the ROLE_CONTROL registers. I guess the "Roles Supported" bits in DEVICE_CAPABILITIES are not explained properly, so let's go over them here:

Quoted 6 lines

000b = Source _or_ Sink only
001b = Source only
010b = Sink only
011b = Sink only with support for autonomously detected accessory modes 100b = DRP only, and this I believe mean we can not program the port
to be Sink only or Source only

I think so, too.

Quoted 11 lines

101b = Source only OR Sink only OR DRP, plus ability to detect
accessories and I guess also cables autonomously
110b = Source only OR Sink only OR DRP

So where the spec lists "Source, Sink", it actually should have said "Source only OR Sink only".

But you still have only the following options for a port:
1) Source only (host)
2) Sink only (device)
3) DRP (device, host)

Yes, so you can map "000b = Source _or_ Sink only" to host or device depending on the current setting. But then you lose the information that it can be changed. It either will look like "001b" or "010b". So we throw away information.

And you map "100b = DRP only" and "101b" and "110b" to host, device which again drops information.

Regards
Oliver

author maintainer
#13 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Hi Oliver,

Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus

On Wed, Jun 22, 2016 at 06:44:18PM +0200, Oliver Neukum wrote:

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Yes, but it is unclear what you will be after a connection and that's the point.

Which is a fact that we can do nothing about. The role after connection with DRP ports will be dictated by the partner or selected randomly in case the partner is also DRP. We can prefer a role, but that in the end guarantees nothing. So if the role that we end up with after connection (seen in current_data_role) does not satisfy us, all we can do is try to swap it.

I'm not sure what is your point here.

Quoted 30 lines
Quoted 14 lines
Quoted 4 lines

And you can be able to become a host and be able to become a device. But not at the same time. These ports are switchable.

The current API cannot express the difference.

I think you have misunderstood something. The only case where the port can be dual-role is if it's set to be DRP. Otherwise it's Source only OR Sink only.

The "Role Supported" bits only tell us how we can program for example the ROLE_CONTROL registers. I guess the "Roles Supported" bits in DEVICE_CAPABILITIES are not explained properly, so let's go over them here:

Quoted 6 lines

000b = Source _or_ Sink only
001b = Source only
010b = Sink only
011b = Sink only with support for autonomously detected accessory modes 100b = DRP only, and this I believe mean we can not program the port
to be Sink only or Source only

I think so, too.

Quoted 7 lines

101b = Source only OR Sink only OR DRP, plus ability to detect
accessories and I guess also cables autonomously
110b = Source only OR Sink only OR DRP

So where the spec lists "Source, Sink", it actually should have said "Source only OR Sink only".

Quoted 8 lines
Quoted 4 lines

But you still have only the following options for a port:
1) Source only (host)
2) Sink only (device)
3) DRP (device, host)

Yes, so you can map "000b = Source _or_ Sink only" to host or device depending on the current setting. But then you lose the information that it can be changed.

No it can't. The idea with the Roles Supported bits is for the driver to be able to select the most appropriate role that fits the abilities of the platform.

The configuration of the port after probing the port controller will never change. If you have initially configured the port to be Sink only (so device), it most likely means your platform can not act as Source even if the port controller would.

And if you want to change the configuration of the port, for example if your platform is capable of supporting Source and Sink modes, but your port controller is not capable of supporting DRP (which would be pretty messed up situation) but instead forces you to choose between Sink and Source, you would in practice in any case have to unregister, reconfigure and register the port again.

But in most cases the platform will not support all the capabilities the port controller will be capable of. If for example on your platform you have only USB host controller, it just means you will have to have port controller that returns either 000b, 001b, 101b or 110b in the supported roles bits. Otherwise it will no be usable on your platform.

Quoted 3 lines

So we throw away information.

And you map "100b = DRP only" and "101b" and "110b" to host, device

No I don't. If our platform can only support Sink mode, value "100b" will not work and can not be ever registered, and values "101b" and "110b" will report "device" in supported_data_roles.

And it is not the class that defines the capabilities of a port. They are defined by the drivers that register the ports.

Quoted 1 line

which again drops information.

There is no use in knowing details about the port controller capabilities like if a port could be configured to be Source or Sink only instead of just DRP from the typec class point of view. Those details are port controller specific, and completely out side the scope of the class driver. Not all USB Type-C PHYs will be port controllers and not all ports registered with the class will even have a PHY to deal with. This means we will not even always be able to read the same kinds of details of the port like we are with port controllers.

So if you want to get the capabilities of the port controller in use, the port controller driver will have to expose them to user space, not the class.

Br,

Signature · 1 line
heikki
#14 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Hi,

Quoted 12 lines · Heikki Krogerus

Hi Oliver,

Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus

On Wed, Jun 22, 2016 at 06:44:18PM +0200, Oliver Neukum wrote:

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Yes, but it is unclear what you will be after a connection and that's the point.

Quoted 8 lines

Which is a fact that we can do nothing about. The role after connection with DRP ports will be dictated by the partner or selected randomly in case the partner is also DRP. We can prefer a role, but that in the end guarantees nothing. So if the role that we end up with after connection (seen in current_data_role) does not satisfy us, all we can do is try to swap it.

I'm not sure what is your point here.

What if the application wants to know exactly what role the device is operating in at the current moment?

We need to have 2 distinct parameters.

1) supported_modes : host, device, host or device
2) current_mode: host, device, disconnected

--
cheers,
-roger

author maintainer
#15 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 24 lines · Roger Quadros

Hi,

Quoted 12 lines · Heikki Krogerus

Hi Oliver,

Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus

On Wed, Jun 22, 2016 at 06:44:18PM +0200, Oliver Neukum wrote:

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Yes, but it is unclear what you will be after a connection and that's the point.

Quoted 8 lines

Which is a fact that we can do nothing about. The role after connection with DRP ports will be dictated by the partner or selected randomly in case the partner is also DRP. We can prefer a role, but that in the end guarantees nothing. So if the role that we end up with after connection (seen in current_data_role) does not satisfy us, all we can do is try to swap it.

I'm not sure what is your point here.

Quoted 7 lines

What if the application wants to know exactly what role the device is operating in at the current moment?

We need to have 2 distinct parameters.

1) supported_modes : host, device, host or device
2) current_mode: host, device, disconnected

And we already do. But that is not the topic of this thread. Oliver I believe feels that we are not presenting all the capabilities of the ports.

Cheers,

Signature · 1 line
heikki
#16 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

In reply to Heikki Krogerus
Quoted 106 lines · Heikki Krogerus

Hi Oliver,

Quoted 8 lines · Oliver Neukum
Quoted 4 lines · Heikki Krogerus

On Wed, Jun 22, 2016 at 06:44:18PM +0200, Oliver Neukum wrote:

No it's not. DRP means a port that can operate as _either_ Source (host) or Sink (device), but not at the same time..

Yes, but it is unclear what you will be after a connection and that's the point.

Which is a fact that we can do nothing about. The role after connection with DRP ports will be dictated by the partner or selected randomly in case the partner is also DRP. We can prefer a role, but that in the end guarantees nothing. So if the role that we end up with after connection (seen in current_data_role) does not satisfy us, all we can do is try to swap it.

I'm not sure what is your point here.

Quoted 30 lines
Quoted 14 lines
Quoted 4 lines

And you can be able to become a host and be able to become a device. But not at the same time. These ports are switchable.

The current API cannot express the difference.

I think you have misunderstood something. The only case where the port can be dual-role is if it's set to be DRP. Otherwise it's Source only OR Sink only.

The "Role Supported" bits only tell us how we can program for example the ROLE_CONTROL registers. I guess the "Roles Supported" bits in DEVICE_CAPABILITIES are not explained properly, so let's go over them here:

Quoted 6 lines

000b = Source _or_ Sink only
001b = Source only
010b = Sink only
011b = Sink only with support for autonomously detected accessory modes 100b = DRP only, and this I believe mean we can not program the port
to be Sink only or Source only

I think so, too.

Quoted 7 lines

101b = Source only OR Sink only OR DRP, plus ability to detect
accessories and I guess also cables autonomously
110b = Source only OR Sink only OR DRP

So where the spec lists "Source, Sink", it actually should have said "Source only OR Sink only".

Quoted 8 lines
Quoted 4 lines

But you still have only the following options for a port:
1) Source only (host)
2) Sink only (device)
3) DRP (device, host)

Yes, so you can map "000b = Source _or_ Sink only" to host or device depending on the current setting. But then you lose the information that it can be changed.

No it can't. The idea with the Roles Supported bits is for the driver to be able to select the most appropriate role that fits the abilities of the platform.

The configuration of the port after probing the port controller will never change. If you have initially configured the port to be Sink only (so device), it most likely means your platform can not act as Source even if the port controller would.

And if you want to change the configuration of the port, for example if your platform is capable of supporting Source and Sink modes, but your port controller is not capable of supporting DRP (which would be pretty messed up situation) but instead forces you to choose between Sink and Source, you would in practice in any case have to unregister, reconfigure and register the port again.

But in most cases the platform will not support all the capabilities the port controller will be capable of. If for example on your platform you have only USB host controller, it just means you will have to have port controller that returns either 000b, 001b, 101b or 110b in the supported roles bits. Otherwise it will no be usable on your platform.

Quoted 3 lines

So we throw away information.

And you map "100b = DRP only" and "101b" and "110b" to host, device

No I don't. If our platform can only support Sink mode, value "100b" will not work and can not be ever registered, and values "101b" and "110b" will report "device" in supported_data_roles.

And it is not the class that defines the capabilities of a port. They are defined by the drivers that register the ports.

Quoted 1 line

which again drops information.

There is no use in knowing details about the port controller capabilities like if a port could be configured to be Source or Sink only instead of just DRP from the typec class point of view. Those details are port controller specific, and completely out side the scope of the class driver. Not all USB Type-C PHYs will be port controllers and not all ports registered with the class will even have a PHY to deal with. This means we will not even always be able to read the same kinds of details of the port like we are with port controllers.

Quoted 4 lines

So if you want to get the capabilities of the port controller in use, the port controller driver will have to expose them to user space, not the class.

Agreed.

Guenter

#17 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

In reply to Heikki Krogerus

Hi,

Quoted 9 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when USB PD is available, also control over power role swapping and Alternate Modes.

---

[ ... ]

drivers/usb/typec/typec.c line 145

Quoted 4 lines
drivers/usb/typec/typec.c new file +4 -0
+
+static void typec_remove_partner(struct typec_port *port)
+{
+	WARN_ON(port->partner->alt_modes);

You are setting partner->alt_modes in typec_register_altmodes(), but you don't clear it in typec_unregister_altmodes().

Does this work for you ? I always get the warning when I remove a cable.

Thanks,
Guenter

author maintainer
#18 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Hi,

Quoted 11 lines · Guenter Roeck

Hi,

drivers/usb/typec/typec.c line 145

Quoted 4 lines
drivers/usb/typec/typec.c new file +4 -0
+
+static void typec_remove_partner(struct typec_port *port)
+{
+	WARN_ON(port->partner->alt_modes);

You are setting partner->alt_modes in typec_register_altmodes(), but you don't clear it in typec_unregister_altmodes().

Does this work for you ? I always get the warning when I remove a cable.

Damn it.. I have managed to just ignore the warning.

Yeah, this has to be fixed. Sorry about that.

Thanks,

Signature · 1 line
heikki
#19 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

In reply to Heikki Krogerus

Hi Heikki,

Quoted 4 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when USB PD is

s/PD/PD (Power Delivery)

Quoted 28 lines

available, also control over power role swapping and Alternate Modes.

---
 Documentation/ABI/testing/sysfs-class-typec |  163 ++++
 Documentation/usb/typec.txt                 |  101 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |    7 +
 drivers/usb/typec/Makefile                  |    1 +
 drivers/usb/typec/typec.c                   | 1173 +++++++++++++++++++++++++++
 include/linux/usb/typec.h                   |  255 ++++++
 9 files changed, 1713 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 include/linux/usb/typec.h
Documentation/ABI/testing/sysfs-class-typec new file +0 -0
new file mode 100644
index 0000000..ce577f3

Documentation/ABI/testing/sysfs-class-typec line 4

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-typec new file +4 -0
@@ -0,0 +1,163 @@
+USB Type-C port devices (eg. /sys/class/typec/usbc0/)
+
+What:		/sys/class/typec/<port>/current_data_role
+Data:		June 2016

s/Data/Date everywhere in this patch.

Documentation/ABI/testing/sysfs-class-typec line 8

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-typec new file +4 -0
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current USB data role the port is operating in. This
+		attribute can be used for requestion data role swapping on th

s/requestion/requesting

s/th/the

Documentation/ABI/testing/sysfs-class-typec line 9

Quoted 1 line
Documentation/ABI/testing/sysfs-class-typec new file +1 -0
+		port.

Is it better to list all the values that can be here with a short note for each? Same for all properties below?

Otherwise as a user I have no clue as to what all values I can set this to.

Documentation/ABI/testing/sysfs-class-typec line 17

Quoted 8 lines
Documentation/ABI/testing/sysfs-class-typec new file +8 -0
+
+What:		/sys/class/typec/<port>/current_power_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current power role, source or sink, of the port. This
+		attribute can be used to request power role swap on the port
+		when USB Power Delivery is available.

So if it is not yet available, why add this now?

Documentation/ABI/testing/sysfs-class-typec line 24

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-typec new file +7 -0
+
+What:		/sys/class/typec/<port>/current_vconn_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current VCONN role, source or sink, of the port. This
+		attribute can be used to request vconn role swap on the port

s/vconn/VCONN

Documentation/ABI/testing/sysfs-class-typec line 25

Quoted 1 line
Documentation/ABI/testing/sysfs-class-typec new file +1 -0
+		when USB Power Delivery is available.

Why add if not yet available?

Documentation/ABI/testing/sysfs-class-typec line 31

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-typec new file +6 -0
+
+What:		/sys/class/typec/<port>/power_operation_mode
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current power power mode the port is in. Reads as on

s/on/one

Documentation/ABI/testing/sysfs-class-typec line 41

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+		of the following:
+		- USB - Normal power levels defined in USB specifications
+		- BC1.2 - Power levels defined in Battery Charging Specification
+			  v1.2
+		- USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C
+				    specification.
+		- USB Type-C 3.0A - Higher 3A current defined in USB Type-C
+				    specification.
+                - USB Power Delivery - The voltages and currents defined in USB
+				       Power Delivery specification

What would it show when the port is disconnected?

Instead, is it somehow possible to list the actual negotiated current (in mA) here or in some other property, if you want to know the mode as well?

Documentation/ABI/testing/sysfs-class-typec line 49

Quoted 8 lines
Documentation/ABI/testing/sysfs-class-typec new file +8 -0
+
+What:		/sys/class/typec/<port>/preferred_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The user space can notify the driver about the preferred role.
+		It should be handled as enabling of Try.SRC or Try.SNK, as
+		defined in USB Type-C specification, in the port drivers.

What would be the default setting?

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-typec new file +4 -0
+
+What:		/sys/class/typec/<port>/supported_accessory_modes
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>

Documentation/ABI/testing/sysfs-class-typec line 63

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+Description:
+		Lists the Accessory Modes, defined in the USB Type-C
+		specification, the port supports.
+
+What:		/sys/class/typec/<port>/supported_data_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the USB data roles, host or device, the port is capable
+		of supporting.

Can't it support both e.g in DRP case?

Documentation/ABI/testing/sysfs-class-typec line 76

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-typec new file +13 -0
+
+What:		/sys/class/typec/<port>/supported_power_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the power roles, source and/or sink, the port is capable
+		of supporting.
+
+What:		/sys/class/typec/<port>/supports_usb_power_delivery
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the port support USB Power Delivery.

s/support/supports

Documentation/ABI/testing/sysfs-class-typec line 81

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+
+
+USB Type-C partner devices (eg. /sys/class/typec/usbc0-partner/)
+
+What:		/sys/class/typec/<port>-partner/accessory

<port>-partner/ or <port>/partner ?

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-typec new file +13 -0
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the name of the Accessory Mode if the partner attached to
+		the port is an accessory. Otherwise shows nothing.
+
+What:		/sys/class/typec/<port>-partner/type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the type of the partner. Can be one of the following:
+		- USB - When the partner is normal USB host/peripheral.
+		- Charger - When the partner has been identified as dedicated

Documentation/ABI/testing/sysfs-class-typec line 104

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+			    charger.
+		- Alternate Mode - When the partner supports Alternate Modes.
+		- Accessory - When the partner is one of the accessories with
+			      specific Accessory Mode defined in USB Type-C
+			      specification.
+
+
+USB Type-C cable devices (eg. /sys/class/typec/usbc0-cable/)
+
+Note: The two cable plugs will have their own devices presenting when available

I didn't get this part. How come two cable plugs can have 2 devices? presenting what?

Documentation/ABI/testing/sysfs-class-typec line 109

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+(eg. /sys/class/typec/usbc0-plug0). Both plugs may have their own active
+alternate modes as described in USB Type-C and USB Power Delivery
+specifications.
+
+What:		/sys/class/typec/<port>-cable/active

<port>-cable/ or <port>/cable ?

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the cable is active or passive. Only active cables can
+		have configurable alternate modes, therefore only active cables
+		will have plug devices.
+
+What:		/sys/class/typec/<port>-cable/plug_type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>

Documentation/ABI/testing/sysfs-class-typec line 129

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+Description:
+		Shows type of the plug on the cable:
+		Type-A - Standard A
+		Type-B - Standard B
+		Type-C - USB Type-C
+		Captive - Non-standard
+
+
+Alternate Mode devices  (For example,
+/sys/class/typec/usbc0-partner/usbc0-partner.svid:xxxx/)

Why should it show usbc0-partner twice?

Quoted 40 lines
Documentation/ABI/testing/sysfs-class-typec new file +34 -0
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/active
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the mode is active or not. The attribute can be used
+		for entering/exiting the mode with partners and cable plugs, and
+		with the port alternate modes it can be used for disabling
+		support for specific alternate modes.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/description
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows description of the mode. The description is optional for
+		the drivers, just like with the Billboard Devices.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/vdo
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the VDO in hexadecimal returned from the Discover Modes
+		command.
+
+What:		/sys/class/typec/<port>/<port>.svid:<svid>/<mode>/supported_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the roles, source or sink, the mode is supported with.
+
+		This attribute is available for the devices describing the
+		alternate modes a port supports, and it will not be exposed with
+		the devices presenting the alternate modes the partners or cable
+		plugs support.
Documentation/usb/typec.txt new file +0 -0
new file mode 100644
index 0000000..ddeda97

Documentation/usb/typec.txt line 8

Quoted 8 lines
Documentation/usb/typec.txt new file +8 -0
@@ -0,0 +1,101 @@
+USB Type-C connector class
+==========================
+
+Introduction
+------------
+The typec class is meant for describing the USB Type-C ports in a system to the
+user space in unified fashion. The class is designed to provide nothing else
+expect the user space interface implementation in hope that it can be utilized

s/expect/except/

Quoted 11 lines
Documentation/usb/typec.txt new file +11 -0
+on as many platforms as possible.
+
+The platforms are expected to register every USB Type-C port they have with the
+class. In a normal case the registration will be done by a USB Type-C or PD PHY
+driver, but it may be a driver for firmware interface such as UCSI, driver for
+USB PD controller or even driver for Thunderbolt3 controller. This document
+considers the component registering the USB Type-C ports with the class as "port
+driver".
+
+On top of showing the capabilities, the class also offers the user space control
+over the roles and alternate modes they support when the port driver is capable

Documentation/usb/typec.txt line 29

Quoted 10 lines
Documentation/usb/typec.txt new file +10 -0
+of supporting those features.
+
+The class provides an API for the port drivers described in this document. The
+attributes are described in Documentation/ABI/testing/sysfs-class-typec.
+
+
+Interface
+---------
+Every port will be presented as its own device under /sys/class/typec/. The
+first port will be named "usbc0", the second "usbc1" and so on.

We already know it is typec since it sits in /sys/class/typec

Why not just call the instances "0", "1" and so on?

Documentation/usb/typec.txt line 33

Quoted 4 lines
Documentation/usb/typec.txt new file +4 -0
+
+When connected, the partner will be presented also as its own device under
+/sys/class/typec/. The parent of the partner device will always be the port. The
+partner attached to port "usbc0" will be named "usbc0-partner".

Can the partner exist without the port? If not the partner should be located within the port directory.

Documentation/usb/typec.txt line 39

Quoted 6 lines
Documentation/usb/typec.txt new file +6 -0
+
+The cable and the two plugs on it may also be optionally be presented as their
+own devices under /sys/class/typec/. The cable attached to the port "usbc0" port
+will be named usbc0-cable and the plug on the SOP Prime end (see USB Power
+Delivery Specification ch. 2.4) will be named "usbc-plug0" and on the SOP Double
+Prime end "usbc0-plug1".

If cables and plugs can't exist without the port they must come up within the port directory.

Quoted 111 lines
Documentation/usb/typec.txt new file +62 -0
+
+If the port, partner or cable plug support Alternate Modes, every Alternate Mode
+SVID will have their own device describing them. The Alternate Modes will not be
+attached to the typec class. For the port's "usbc0" partner, the Alternate Modes
+would have devices presented under /sys/class/typec/usbc0-partner/. Every mode
+that is supported will have its own group under the Alternate Mode device named
+"mode<id>". For example /sys/class/typec/usbc0/usbc0.svid:xxxx/mode0/. The
+requests for entering/exiting the modes happens with the "active" attribute in
+that group.
+
+
+API
+---
+
+* Registering the ports
+
+The port drivers will describe every Type-C port they control with struct
+typec_capability data structure, and register them with the following API:
+
+struct typec_port *typec_register_port(struct device *dev,
+				       const struct typec_capability *cap);
+
+The class will provide handle to struct typec_port on success and ERR_PTR on
+failure. The un-registration of the port happens with the following API:
+
+void typec_unregister_port(struct typec_port *port);
+
+
+* Notifications
+
+When connection happens on a port, the port driver fills struct typec_connection
+which is passed to the class. The class provides the following API for reporting
+connection/disconnection:
+
+int typec_connect(struct typec_port *port, struct typec_connection *);
+void typec_disconnect(struct typec_port *);
+
+When the partner end has executed a role change, the port driver uses the
+following APIs to report it to the class:
+
+void typec_set_data_role(struct typec_port *, enum typec_data_role);
+void typec_set_pwr_role(struct typec_port *, enum typec_role);
+void typec_set_vconn_role(struct typec_port *, enum typec_role);
+void typec_set_pwr_opmode(struct typec_port *, enum typec_pwr_opmode);
+
+
+* Alternate Modes
+
+After connection, the port drivers register the alternate modes the partner
+and/or cable plugs support. And before reporting disconnection, the port driver
+_must_ unregister all the alternate modes registered for the partner and cable
+plugs. The API takes the struct device of the partner or the cable plug as
+parameter:
+
+int typec_register_altmodes(struct device *, struct typec_altmode *);
+void typec_unregister_altmodes(struct device *);
+
+When the partner end enters or exits the modes, the port driver needs to notify
+the class with the following API:
+
+void typec_altmode_update_active(struct typec_altmode *alt, int mode,
+				 bool active);
MAINTAINERS +9 -0
index e1b090f..0db33fb 100644
@@ -11983,6 +11983,15 @@ F:	drivers/usb/
 F:	include/linux/usb.h
 F:	include/linux/usb/
 
+USB TYPEC SUBSYSTEM
+M:	Heikki Krogerus <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/ABI/testing/sysfs-class-typec
+F:	Documentation/usb/typec.txt
+F:	drivers/usb/typec/
+F:	include/linux/usb/typec.h
+
 USB UHCI DRIVER
 M:	Alan Stern <[email protected]>
 L:	[email protected]
drivers/usb/Kconfig +2 -0
index 8689dcb..f42a3d3 100644
@@ -150,6 +150,8 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+source "drivers/usb/typec/Kconfig"
+
 config USB_LED_TRIG
 	bool "USB LED Triggers"
 	depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
index dca7856..51e381e 100644
@@ -61,3 +61,5 @@ obj-$(CONFIG_USB_GADGET)	+= gadget/
 obj-$(CONFIG_USB_COMMON)	+= common/
 
 obj-$(CONFIG_USBIP_CORE)	+= usbip/
+
+obj-$(CONFIG_TYPEC)		+= typec/
drivers/usb/typec/Kconfig new file +0 -0
new file mode 100644
index 0000000..b229fb9

drivers/usb/typec/Kconfig line 2

Quoted 2 lines
drivers/usb/typec/Kconfig new file +2 -0
@@ -0,0 +1,7 @@
+
+menu "USB PD and Type-C drivers"

USB PD is independent of Type C right? Why club them together here?

drivers/usb/typec/Kconfig line 4

Quoted 2 lines
drivers/usb/typec/Kconfig new file +2 -0
+
+config TYPEC

No help description?

drivers/usb/typec/Makefile line 1

Quoted 10 lines
drivers/usb/typec/Kconfig new file +3 -0
+	tristate
+
+endmenu
drivers/usb/typec/Makefile new file +1 -0
new file mode 100644
index 0000000..1012a8b
@@ -0,0 +1 @@
+obj-$(CONFIG_TYPEC)		+= typec.o

<snip>

I'll review the code a bit later.

cheers,
-roger

author maintainer
#20 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Hi Roger,

I'll fix all the typos you mention below...

Quoted 52 lines · Roger Quadros

Hi Heikki,

Quoted 4 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system, control over data role swapping, and when USB PD is

s/PD/PD (Power Delivery)

Quoted 28 lines

available, also control over power role swapping and Alternate Modes.

---
 Documentation/ABI/testing/sysfs-class-typec |  163 ++++
 Documentation/usb/typec.txt                 |  101 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |    7 +
 drivers/usb/typec/Makefile                  |    1 +
 drivers/usb/typec/typec.c                   | 1173 +++++++++++++++++++++++++++
 include/linux/usb/typec.h                   |  255 ++++++
 9 files changed, 1713 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 include/linux/usb/typec.h
Documentation/ABI/testing/sysfs-class-typec new file +0 -0
new file mode 100644
index 0000000..ce577f3

Documentation/ABI/testing/sysfs-class-typec line 4

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-typec new file +4 -0
@@ -0,0 +1,163 @@
+USB Type-C port devices (eg. /sys/class/typec/usbc0/)
+
+What:		/sys/class/typec/<port>/current_data_role
+Data:		June 2016

s/Data/Date everywhere in this patch.

Documentation/ABI/testing/sysfs-class-typec line 8

Quoted 4 lines
Documentation/ABI/testing/sysfs-class-typec new file +4 -0
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current USB data role the port is operating in. This
+		attribute can be used for requestion data role swapping on th

s/requestion/requesting

Quoted 6 lines

s/th/the

Documentation/ABI/testing/sysfs-class-typec line 9

Quoted 1 line
Documentation/ABI/testing/sysfs-class-typec new file +1 -0
+		port.

Is it better to list all the values that can be here with a short note for each? Same for all properties below?

Sure.

Quoted 12 lines

Otherwise as a user I have no clue as to what all values I can set this to.

Documentation/ABI/testing/sysfs-class-typec line 17

Quoted 8 lines
Documentation/ABI/testing/sysfs-class-typec new file +8 -0
+
+What:		/sys/class/typec/<port>/current_power_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The current power role, source or sink, of the port. This
+		attribute can be used to request power role swap on the port
+		when USB Power Delivery is available.

So if it is not yet available, why add this now?

s/...when USB Power Delivery is available/...when the port supports USB Power Delivery/

Quoted 23 lines

Documentation/ABI/testing/sysfs-class-typec line 24

Quoted 7 lines
Documentation/ABI/testing/sysfs-class-typec new file +7 -0
+
+What:		/sys/class/typec/<port>/current_vconn_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current VCONN role, source or sink, of the port. This
+		attribute can be used to request vconn role swap on the port

s/vconn/VCONN

Documentation/ABI/testing/sysfs-class-typec line 25

Quoted 1 line
Documentation/ABI/testing/sysfs-class-typec new file +1 -0
+		when USB Power Delivery is available.

Why add if not yet available?

Documentation/ABI/testing/sysfs-class-typec line 31

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-typec new file +6 -0
+
+What:		/sys/class/typec/<port>/power_operation_mode
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current power power mode the port is in. Reads as on

s/on/one

Quoted 12 lines

Documentation/ABI/testing/sysfs-class-typec line 41

Quoted 10 lines
Documentation/ABI/testing/sysfs-class-typec new file +10 -0
+		of the following:
+		- USB - Normal power levels defined in USB specifications
+		- BC1.2 - Power levels defined in Battery Charging Specification
+			  v1.2
+		- USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C
+				    specification.
+		- USB Type-C 3.0A - Higher 3A current defined in USB Type-C
+				    specification.
+                - USB Power Delivery - The voltages and currents defined in USB
+				       Power Delivery specification

What would it show when the port is disconnected?

USB. That is the default.

Quoted 2 lines

Instead, is it somehow possible to list the actual negotiated current (in mA) here or in some other property, if you want to know the mode as well?

The current is not always going to be available for the port driver, and in any case out side the scope of the class. Those details are something that for example a USB Type-C PHY should always be able to detect, except BC1.2... I think I'm dropping that one.

Quoted 10 lines

Documentation/ABI/testing/sysfs-class-typec line 49

Quoted 8 lines
Documentation/ABI/testing/sysfs-class-typec new file +8 -0
+
+What:		/sys/class/typec/<port>/preferred_role
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The user space can notify the driver about the preferred role.
+		It should be handled as enabling of Try.SRC or Try.SNK, as
+		defined in USB Type-C specification, in the port drivers.

What would be the default setting?

Default is no preference. I'll fix this.

Quoted 8 lines
Quoted 8 lines
Documentation/ABI/testing/sysfs-class-typec new file +8 -0
+
+What:		/sys/class/typec/<port>/supported_accessory_modes
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the Accessory Modes, defined in the USB Type-C
+		specification, the port supports.
+
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-typec line 63

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-typec new file +6 -0
+What:		/sys/class/typec/<port>/supported_data_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the USB data roles, host or device, the port is capable
+		of supporting.

Can't it support both e.g in DRP case?

Yes. s/host or device/host and device/

Quoted 16 lines

Documentation/ABI/testing/sysfs-class-typec line 76

Quoted 13 lines
Documentation/ABI/testing/sysfs-class-typec new file +13 -0
+
+What:		/sys/class/typec/<port>/supported_power_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Lists the power roles, source and/or sink, the port is capable
+		of supporting.
+
+What:		/sys/class/typec/<port>/supports_usb_power_delivery
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the port support USB Power Delivery.

s/support/supports

Quoted 7 lines

Documentation/ABI/testing/sysfs-class-typec line 81

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+
+
+USB Type-C partner devices (eg. /sys/class/typec/usbc0-partner/)
+
+What:		/sys/class/typec/<port>-partner/accessory

<port>-partner/ or <port>/partner ?

<port>-partner/. It is a device.

Quoted 17 lines
Quoted 17 lines
Documentation/ABI/testing/sysfs-class-typec new file +17 -0
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the name of the Accessory Mode if the partner attached to
+		the port is an accessory. Otherwise shows nothing.
+
+What:		/sys/class/typec/<port>-partner/type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the type of the partner. Can be one of the following:
+		- USB - When the partner is normal USB host/peripheral.
+		- Charger - When the partner has been identified as dedicated
+			    charger.
+		- Alternate Mode - When the partner supports Alternate Modes.
+		- Accessory - When the partner is one of the accessories with
+			      specific Accessory Mode defined in USB Type-C
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-typec line 104

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-typec new file +6 -0
+			      specification.
+
+
+USB Type-C cable devices (eg. /sys/class/typec/usbc0-cable/)
+
+Note: The two cable plugs will have their own devices presenting when available

I didn't get this part. How come two cable plugs can have 2 devices?

One plug has one struct device? A cable has two plugs.

Quoted 1 line

presenting what?

The plug? On active cables the plugs may have alternate modes.

Quoted 7 lines

Documentation/ABI/testing/sysfs-class-typec line 109

Quoted 5 lines
Documentation/ABI/testing/sysfs-class-typec new file +5 -0
+(eg. /sys/class/typec/usbc0-plug0). Both plugs may have their own active
+alternate modes as described in USB Type-C and USB Power Delivery
+specifications.
+
+What:		/sys/class/typec/<port>-cable/active

<port>-cable/ or <port>/cable ?

<port>-cable/

Quoted 14 lines
Quoted 14 lines
Documentation/ABI/testing/sysfs-class-typec new file +14 -0
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the cable is active or passive. Only active cables can
+		have configurable alternate modes, therefore only active cables
+		will have plug devices.
+
+What:		/sys/class/typec/<port>-cable/plug_type
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows type of the plug on the cable:
+		Type-A - Standard A
+		Type-B - Standard B
Quoted 8 lines

Documentation/ABI/testing/sysfs-class-typec line 129

Quoted 6 lines
Documentation/ABI/testing/sysfs-class-typec new file +6 -0
+		Type-C - USB Type-C
+		Captive - Non-standard
+
+
+Alternate Mode devices  (For example,
+/sys/class/typec/usbc0-partner/usbc0-partner.svid:xxxx/)

Why should it show usbc0-partner twice?

Because device names need to be unique.

Quoted 75 lines
Quoted 40 lines
Documentation/ABI/testing/sysfs-class-typec new file +34 -0
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/active
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the mode is active or not. The attribute can be used
+		for entering/exiting the mode with partners and cable plugs, and
+		with the port alternate modes it can be used for disabling
+		support for specific alternate modes.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/description
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows description of the mode. The description is optional for
+		the drivers, just like with the Billboard Devices.
+
+What:		/sys/class/typec/<dev>/<dev>.svid:<svid>/<mode>/vdo
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the VDO in hexadecimal returned from the Discover Modes
+		command.
+
+What:		/sys/class/typec/<port>/<port>.svid:<svid>/<mode>/supported_roles
+Data:		June 2016
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the roles, source or sink, the mode is supported with.
+
+		This attribute is available for the devices describing the
+		alternate modes a port supports, and it will not be exposed with
+		the devices presenting the alternate modes the partners or cable
+		plugs support.
Documentation/usb/typec.txt new file +0 -0
new file mode 100644
index 0000000..ddeda97

Documentation/usb/typec.txt line 8

Quoted 8 lines
Documentation/usb/typec.txt new file +8 -0
@@ -0,0 +1,101 @@
+USB Type-C connector class
+==========================
+
+Introduction
+------------
+The typec class is meant for describing the USB Type-C ports in a system to the
+user space in unified fashion. The class is designed to provide nothing else
+expect the user space interface implementation in hope that it can be utilized

s/expect/except/

Quoted 11 lines
Documentation/usb/typec.txt new file +11 -0
+on as many platforms as possible.
+
+The platforms are expected to register every USB Type-C port they have with the
+class. In a normal case the registration will be done by a USB Type-C or PD PHY
+driver, but it may be a driver for firmware interface such as UCSI, driver for
+USB PD controller or even driver for Thunderbolt3 controller. This document
+considers the component registering the USB Type-C ports with the class as "port
+driver".
+
+On top of showing the capabilities, the class also offers the user space control
+over the roles and alternate modes they support when the port driver is capable

Documentation/usb/typec.txt line 29

Quoted 10 lines
Documentation/usb/typec.txt new file +10 -0
+of supporting those features.
+
+The class provides an API for the port drivers described in this document. The
+attributes are described in Documentation/ABI/testing/sysfs-class-typec.
+
+
+Interface
+---------
+Every port will be presented as its own device under /sys/class/typec/. The
+first port will be named "usbc0", the second "usbc1" and so on.

We already know it is typec since it sits in /sys/class/typec

Quoted 1 line

Why not just call the instances "0", "1" and so on?

A device named "0" or "1"... I wonder why other sub-systems are not naming their devices like that :-)

Quoted 7 lines

Documentation/usb/typec.txt line 33

Quoted 4 lines
Documentation/usb/typec.txt new file +4 -0
+
+When connected, the partner will be presented also as its own device under
+/sys/class/typec/. The parent of the partner device will always be the port. The
+partner attached to port "usbc0" will be named "usbc0-partner".

Can the partner exist without the port? If not the partner should be located within the port directory.

It can't and won't exist without port, and the actual device does exist in the port directory. However, from the classes point of view that is irrelevant. A class will always create a link to its own group for all the devices attached to it.

Quoted 9 lines

Documentation/usb/typec.txt line 39

Quoted 6 lines
Documentation/usb/typec.txt new file +6 -0
+
+The cable and the two plugs on it may also be optionally be presented as their
+own devices under /sys/class/typec/. The cable attached to the port "usbc0" port
+will be named usbc0-cable and the plug on the SOP Prime end (see USB Power
+Delivery Specification ch. 2.4) will be named "usbc-plug0" and on the SOP Double
+Prime end "usbc0-plug1".

If cables and plugs can't exist without the port they must come up within the port directory.

The same.

Quoted 102 lines
Quoted 102 lines
Documentation/usb/typec.txt new file +62 -0
+
+If the port, partner or cable plug support Alternate Modes, every Alternate Mode
+SVID will have their own device describing them. The Alternate Modes will not be
+attached to the typec class. For the port's "usbc0" partner, the Alternate Modes
+would have devices presented under /sys/class/typec/usbc0-partner/. Every mode
+that is supported will have its own group under the Alternate Mode device named
+"mode<id>". For example /sys/class/typec/usbc0/usbc0.svid:xxxx/mode0/. The
+requests for entering/exiting the modes happens with the "active" attribute in
+that group.
+
+
+API
+---
+
+* Registering the ports
+
+The port drivers will describe every Type-C port they control with struct
+typec_capability data structure, and register them with the following API:
+
+struct typec_port *typec_register_port(struct device *dev,
+				       const struct typec_capability *cap);
+
+The class will provide handle to struct typec_port on success and ERR_PTR on
+failure. The un-registration of the port happens with the following API:
+
+void typec_unregister_port(struct typec_port *port);
+
+
+* Notifications
+
+When connection happens on a port, the port driver fills struct typec_connection
+which is passed to the class. The class provides the following API for reporting
+connection/disconnection:
+
+int typec_connect(struct typec_port *port, struct typec_connection *);
+void typec_disconnect(struct typec_port *);
+
+When the partner end has executed a role change, the port driver uses the
+following APIs to report it to the class:
+
+void typec_set_data_role(struct typec_port *, enum typec_data_role);
+void typec_set_pwr_role(struct typec_port *, enum typec_role);
+void typec_set_vconn_role(struct typec_port *, enum typec_role);
+void typec_set_pwr_opmode(struct typec_port *, enum typec_pwr_opmode);
+
+
+* Alternate Modes
+
+After connection, the port drivers register the alternate modes the partner
+and/or cable plugs support. And before reporting disconnection, the port driver
+_must_ unregister all the alternate modes registered for the partner and cable
+plugs. The API takes the struct device of the partner or the cable plug as
+parameter:
+
+int typec_register_altmodes(struct device *, struct typec_altmode *);
+void typec_unregister_altmodes(struct device *);
+
+When the partner end enters or exits the modes, the port driver needs to notify
+the class with the following API:
+
+void typec_altmode_update_active(struct typec_altmode *alt, int mode,
+				 bool active);
MAINTAINERS +9 -0
index e1b090f..0db33fb 100644
@@ -11983,6 +11983,15 @@ F:	drivers/usb/
 F:	include/linux/usb.h
 F:	include/linux/usb/
 
+USB TYPEC SUBSYSTEM
+M:	Heikki Krogerus <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/ABI/testing/sysfs-class-typec
+F:	Documentation/usb/typec.txt
+F:	drivers/usb/typec/
+F:	include/linux/usb/typec.h
+
 USB UHCI DRIVER
 M:	Alan Stern <[email protected]>
 L:	[email protected]
drivers/usb/Kconfig +2 -0
index 8689dcb..f42a3d3 100644
@@ -150,6 +150,8 @@ source "drivers/usb/phy/Kconfig"
 
 source "drivers/usb/gadget/Kconfig"
 
+source "drivers/usb/typec/Kconfig"
+
 config USB_LED_TRIG
 	bool "USB LED Triggers"
 	depends on LEDS_CLASS && USB_COMMON && LEDS_TRIGGERS
drivers/usb/Makefile +0 -0
index dca7856..51e381e 100644
@@ -61,3 +61,5 @@ obj-$(CONFIG_USB_GADGET)	+= gadget/
 obj-$(CONFIG_USB_COMMON)	+= common/
 
Quoted 13 lines

drivers/usb/typec/Kconfig line 2

Quoted 11 lines
drivers/usb/Makefile +2 -0
 obj-$(CONFIG_USBIP_CORE)	+= usbip/
+
+obj-$(CONFIG_TYPEC)		+= typec/
drivers/usb/typec/Kconfig new file +2 -0
new file mode 100644
index 0000000..b229fb9
@@ -0,0 +1,7 @@
+
+menu "USB PD and Type-C drivers"

USB PD is independent of Type C right? Why club them together here?

The are not tied to each other, that is for sure, but I don't think there will be that many drivers for USB PD controller or PHYs that would function without Type-C, so would separating them be that useful?

Quoted 4 lines

drivers/usb/typec/Kconfig line 4

Quoted 2 lines
drivers/usb/typec/Kconfig new file +2 -0
+
+config TYPEC

No help description?

Nope. Alone the class is useless, so I don't want to make it something that can be selected separately. And the port drivers will in any case depend on it so why bother the users.

Thanks,

Signature · 1 line
heikki

A message that is not in the archive (sent off-list or not yet received): CAOiXhaKhPfY0Bz8TsZMFQsgLHZZ01DwZ=TPcXtH2nYvHx3PqVA@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): CAOiXhaJiche=jGbg_C2Jbmw1BnA5UYVNKOfhmy4CFiugoPV_+w@mail.gmail.com

author maintainer
#24 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

But there are a couple of attributes I have been thinking about adding for the partners:

supported_data_roles
supports_usb_power_delivery

The supported data roles would respond bits 30 and 31 of the ID Header VDO. But when the partner does not support USB PD, we will have to report "unknown" in it.

Oliver, Guenter! How do you guys feel about those? Is there any use for them?

Quoted 9 lines
Quoted 7 lines · Heikki Krogerus
Quoted 6 lines · Rajaram R
Quoted 3 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Since we are defining this is as a unified interface for user space, will the interface include identity details of local port and peer. Or am I over looking something ?

By peer, do you mean the partners? Sorry but could you elaborate the question?

Thanks,

Signature · 1 line
heikki
#25 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 17 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

But there are a couple of attributes I have been thinking about adding for the partners:

Quoted 7 lines

supported_data_roles
supports_usb_power_delivery

The supported data roles would respond bits 30 and 31 of the ID Header VDO. But when the partner does not support USB PD, we will have to report "unknown" in it.

Or make the attribute invisible in that case.

Quoted 3 lines

Oliver, Guenter! How do you guys feel about those? Is there any use for them?

Definitely good for debugging and informational. On the top of my head, I don't immediately see what a user would do with it, though, but then it would not hurt either to have the information.

I keep wondering if it would make sense to directly expose the ID header VDO, similar to the alternate mode VDOs, in the partner node.

Guenter

Quoted 20 lines
Quoted 10 lines
Quoted 7 lines · Heikki Krogerus
Quoted 6 lines · Rajaram R
Quoted 3 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Since we are defining this is as a unified interface for user space, will the interface include identity details of local port and peer. Or am I over looking something ?

By peer, do you mean the partners? Sorry but could you elaborate the question?

Thanks,

author maintainer
#26 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 21 lines · Guenter Roeck
Quoted 20 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

But there are a couple of attributes I have been thinking about adding for the partners:

supported_data_roles
supports_usb_power_delivery

Quoted 6 lines
Quoted 4 lines

The supported data roles would respond bits 30 and 31 of the ID Header VDO. But when the partner does not support USB PD, we will have to report "unknown" in it.

Or make the attribute invisible in that case.

Well, why not. I did not like the idea of hiding an attribute previously. I preferred to have an attribute always available, unless there was a single and clear way to determine the cases where any of the attributes for example with our partners would be visible or not.. But who cares.

Quoted 9 lines
Quoted 3 lines

Oliver, Guenter! How do you guys feel about those? Is there any use for them?

Definitely good for debugging and informational. On the top of my head, I don't immediately see what a user would do with it, though, but then it would not hurt either to have the information.

I keep wondering if it would make sense to directly expose the ID header VDO, similar to the alternate mode VDOs, in the partner node.

Yes, it makes sense. I'll add an attribute for that.

But since you proposed hiding the attributes, I'll add an attribute "supports_usb_power_deliver" in any case, and make the vdo attribute visible only if it returs 1. I'll also make the "accessory" attribute visible only in case the partner type is accessory.

Thanks Guenter,

Signature · 1 line
heikki
#27 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 27 lines · Heikki Krogerus
Quoted 26 lines · Guenter Roeck
Quoted 24 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

But there are a couple of attributes I have been thinking about adding for the partners:

supported_data_roles
supports_usb_power_delivery

The supported data roles would respond bits 30 and 31 of the ID Header VDO. But when the partner does not support USB PD, we will have to report "unknown" in it.

Quoted 8 lines
Quoted 1 line

Or make the attribute invisible in that case.

Well, why not. I did not like the idea of hiding an attribute previously. I preferred to have an attribute always available, unless there was a single and clear way to determine the cases where any of the attributes for example with our partners would be visible or not.. But who cares.

It would be visible if supports_usb_power_delivery is true. Doesn't that match your requirements ?

Quoted 10 lines
Quoted 9 lines
Quoted 3 lines

Oliver, Guenter! How do you guys feel about those? Is there any use for them?

Definitely good for debugging and informational. On the top of my head, I don't immediately see what a user would do with it, though, but then it would not hurt either to have the information.

I keep wondering if it would make sense to directly expose the ID header VDO, similar to the alternate mode VDOs, in the partner node.

Quoted 7 lines

Yes, it makes sense. I'll add an attribute for that.

But since you proposed hiding the attributes, I'll add an attribute "supports_usb_power_deliver" in any case, and make the vdo attribute visible only if it returs 1. I'll also make the "accessory" attribute visible only in case the partner type is accessory.

Ok with me.

Thanks,
Guenter

#28 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

In reply to Heikki Krogerus
Quoted 7 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Quoted 6 lines

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

Agree. What is the end use of this driver? IMO end use case will decide what attributes to be shared. Since we are terming this as a universal representation for user space we may need to expose details such as Discovery details say Vendor ID, Product ID, Super Speed support etc which are not related to alt mode. In the legacy drivers complete descriptors of the device is available for user space to build applications.

Quoted 36 lines

But there are a couple of attributes I have been thinking about adding for the partners:

supported_data_roles
supports_usb_power_delivery

The supported data roles would respond bits 30 and 31 of the ID Header VDO. But when the partner does not support USB PD, we will have to report "unknown" in it.

Oliver, Guenter! How do you guys feel about those? Is there any use for them?

Quoted 9 lines
Quoted 7 lines · Heikki Krogerus
Quoted 6 lines · Rajaram R
Quoted 3 lines · Heikki Krogerus

The purpose of USB Type-C connector class is to provide unified interface for the user space to get the status and basic information about USB Type-C connectors on a system,

Quoted 6 lines
Quoted 6 lines
Quoted 3 lines

Since we are defining this is as a unified interface for user space, will the interface include identity details of local port and peer. Or am I over looking something ?

By peer, do you mean the partners? Sorry but could you elaborate the question?

Thanks,

--
heikki

author maintainer
#29 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 16 lines · Rajaram R
Quoted 7 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Quoted 6 lines

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

Quoted 7 lines

Agree. What is the end use of this driver? IMO end use case will decide what attributes to be shared. Since we are terming this as a universal representation for user space we may need to expose details such as Discovery details say Vendor ID, Product ID, Super Speed support etc which are not related to alt mode. In the legacy drivers complete descriptors of the device is available for user space to build applications.

The details about the USB connection are out side the scope the this class, and in most cases the port driver will not even have them at their disposal. We can determine that the connector is in USB mode, and that's about it.

But those details will in any case be exposed by the USB subsystem, so why should we duplicate them? The user space has been so far relying on getting the details from the normal interfaces the USB subsystem provides and that should not change.

Thanks,

Signature · 1 line
heikki
#30 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 30 lines · Heikki Krogerus
Quoted 16 lines · Rajaram R
Quoted 7 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Quoted 6 lines

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

Quoted 7 lines

Agree. What is the end use of this driver? IMO end use case will decide what attributes to be shared. Since we are terming this as a universal representation for user space we may need to expose details such as Discovery details say Vendor ID, Product ID, Super Speed support etc which are not related to alt mode. In the legacy drivers complete descriptors of the device is available for user space to build applications.

The details about the USB connection are out side the scope the this class, and in most cases the port driver will not even have them at their disposal. We can determine that the connector is in USB mode, and that's about it.

Quoted 4 lines

But those details will in any case be exposed by the USB subsystem, so why should we duplicate them? The user space has been so far relying on getting the details from the normal interfaces the USB subsystem provides and that should not change.

Apologize for bringing in USB example. I used it to as an example to say that complete device details are exposed to user space by other drivers.

Sticking to the current topic/context more details of Type-C port/partner, a detailed information(with restrictions) will help build more user applications.

Quoted 6 lines

Thanks,

--
heikki

author maintainer
#31 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 37 lines · Rajaram R
Quoted 30 lines · Heikki Krogerus
Quoted 16 lines · Rajaram R
Quoted 7 lines · Heikki Krogerus

Hi,

Quoted 3 lines · Rajaram R

May be I am missing user or usage of the driver.. I see this driver is providing limited information of the Type-C connectors or the port partner

Quoted 6 lines

Yes, this interface can't provide directly information received from PD commands like Discover Identity. We will have to present the partners even when USB PD is not supported and in a consistent fashion. Some details will be available in any case indirectly. Like if there are modes, there will be devices presenting them, and the product type in case of partners will be the partner type.

Quoted 7 lines

Agree. What is the end use of this driver? IMO end use case will decide what attributes to be shared. Since we are terming this as a universal representation for user space we may need to expose details such as Discovery details say Vendor ID, Product ID, Super Speed support etc which are not related to alt mode. In the legacy drivers complete descriptors of the device is available for user space to build applications.

The details about the USB connection are out side the scope the this class, and in most cases the port driver will not even have them at their disposal. We can determine that the connector is in USB mode, and that's about it.

Quoted 4 lines

But those details will in any case be exposed by the USB subsystem, so why should we duplicate them? The user space has been so far relying on getting the details from the normal interfaces the USB subsystem provides and that should not change.

Quoted 7 lines

Apologize for bringing in USB example. I used it to as an example to say that complete device details are exposed to user space by other drivers.

Sticking to the current topic/context more details of Type-C port/partner, a detailed information(with restrictions) will help build more user applications.

IMO we are exposing more or less all relevant information about the ports that the USB Type-C specification defines. And for control we should also be providing mechanisms for all that the spec. defines, so mainly role swapping, and entering/exiting the altenate modes.

If there is something missing, please point it out. Otherwise, I think we are providing everything we can.

About the end user of the interface, I think Oliver knows more about that. But I would imagine that the use cases will be something like, for example, on systems that need prefer sertain roles, perhaps Host for example on some server systems, need to have something like a udev script to set the preferred role and/or attempt role swap if the other role (device) is initially given to a port after connection.

Br,

Signature · 1 line
heikki
#32 lore raw

Re: [PATCHv3 1/2] usb: USB Type-C connector class

Quoted 6 lines · Heikki Krogerus

About the end user of the interface, I think Oliver knows more about that. But I would imagine that the use cases will be something like, for example, on systems that need prefer sertain roles, perhaps Host for example on some server systems, need to have something like a udev script to set the preferred role and/or attempt role swap if the other role (device) is initially given to a port after connection.

And I would say again that try.SRC and try.SNK need a module parameter as a later reversal needs a virtual disconnect.

Regards
Oliver

author maintainer
#33 lore raw

PATCH v3 2/2 usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY

In reply to Heikki Krogerus

This adds driver for the USB Type-C PHY on Intel WhiskeyCove PMIC which is available on some of the Intel Broxton SoC based platforms.

---
 drivers/usb/typec/Kconfig       |  14 ++
 drivers/usb/typec/Makefile      |   1 +
 drivers/usb/typec/typec_wcove.c | 376 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 391 insertions(+)
 create mode 100644 drivers/usb/typec/typec_wcove.c
drivers/usb/typec/Kconfig +14 -0
index b229fb9..7a345a4 100644
@@ -4,4 +4,18 @@ menu "USB PD and Type-C drivers"
 config TYPEC
 	tristate
 
+config TYPEC_WCOVE
+	tristate "Intel WhiskeyCove PMIC USB Type-C PHY driver"
+	depends on ACPI
+	depends on INTEL_SOC_PMIC
+	depends on INTEL_PMC_IPC
+	select TYPEC
+	help
+	  This driver adds support for USB Type-C detection on Intel Broxton
+	  platforms that have Intel Whiskey Cove PMIC. The driver can detect the
+	  role and cable orientation.
+
+	  To compile this driver as module, choose M here: the module will be
+	  called typec_wcove
+
 endmenu
drivers/usb/typec/Makefile +1 -0
index 1012a8b..b9cb862 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_TYPEC)		+= typec.o
+obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
drivers/usb/typec/typec_wcove.c new file +376 -0

376 lines not on this page · raw message

Signature · 1 line
2.8.1
#34 lore raw
In reply to Heikki Krogerus
Quoted 6 lines · Heikki Krogerus

Hi,

I'm considering all the RFCs I send after v1 as v2 (I don't remember how many I send). Hope this is OK and hope there is nothing big missing anymore (or broken).

Quoted 6 lines

Sorry about the delay. I've been really busy with some internal tasks. I'm guessing we missed v4.8 with this thing. I'm sorry about that.

I'm including in this series a driver for the Broxton PMIC USB Type-C PHY.

Can you by any chance push the current version into your repository on github ?

Thanks,
Guenter

Quoted 36 lines

Changes since v2:
- Notification on role and alternate mode changes
- cleanups

Changes since v1:
- Completely rewrote alternate mode support
- Patners, cables and cable plugs presented as devices.

Heikki Krogerus (2):
usb: USB Type-C connector class
usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY

 Documentation/ABI/testing/sysfs-class-typec |  163 ++++
 Documentation/usb/typec.txt                 |  101 +++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |   21 +
 drivers/usb/typec/Makefile                  |    2 +
 drivers/usb/typec/typec.c                   | 1173 +++++++++++++++++++++++++++
 drivers/usb/typec/typec_wcove.c             |  376 +++++++++
 include/linux/usb/typec.h                   |  255 ++++++
 10 files changed, 2104 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.txt
 create mode 100644 drivers/usb/typec/Kconfig
 create mode 100644 drivers/usb/typec/Makefile
 create mode 100644 drivers/usb/typec/typec.c
 create mode 100644 drivers/usb/typec/typec_wcove.c
 create mode 100644 include/linux/usb/typec.h
Signature · 1 line
2.8.1
author maintainer
#35 lore raw

Hi Guenter,

Quoted 7 lines · Guenter Roeck
Quoted 6 lines · Heikki Krogerus

Hi,

I'm considering all the RFCs I send after v1 as v2 (I don't remember how many I send). Hope this is OK and hope there is nothing big missing anymore (or broken).

Quoted 8 lines
Quoted 6 lines

Sorry about the delay. I've been really busy with some internal tasks. I'm guessing we missed v4.8 with this thing. I'm sorry about that.

I'm including in this series a driver for the Broxton PMIC USB Type-C PHY.

Can you by any chance push the current version into your repository on github ?

Sure, but Felipe has also put these patches to a branch testing/typec in his tree:
https://git.kernel.org/cgit/linux/kernel/git/balbi/usb.git/log/?h=testing/typec

Cheers,

Signature · 1 line
heikki
#36 lore raw
Quoted 16 lines · Heikki Krogerus

Hi Guenter,

Quoted 13 lines · Guenter Roeck
Quoted 12 lines · Heikki Krogerus

Hi,

I'm considering all the RFCs I send after v1 as v2 (I don't remember how many I send). Hope this is OK and hope there is nothing big missing anymore (or broken).

Sorry about the delay. I've been really busy with some internal tasks. I'm guessing we missed v4.8 with this thing. I'm sorry about that.

I'm including in this series a driver for the Broxton PMIC USB Type-C PHY.

Quoted 7 lines
Quoted 2 lines

Can you by any chance push the current version into your repository on github ?

Sure, but Felipe has also put these patches to a branch testing/typec in his tree:
https://git.kernel.org/cgit/linux/kernel/git/balbi/usb.git/log/?h=testing/typec

That works just as well, of course.

Thanks,
Guenter