Skip to contentSkip to conversation

USB Type-C Connector class

PATCH Superseded Heikki Krogerus 11 participants 64 messages Feb 21, 2017 – Apr 28, 2017

Subsystems (5)

v17 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

v17 cover USB Type-C Connector class

The USB Type-C class is meant to provide unified interface to the userspace to present the USB Type-C ports in a system.

Changes since v16:
- Using PTR_ERR_OR_ZERO macro in typec_init().

Changes since v15:
- "stingification" as proposed by Felipe
- Checking ARRAY_SIZE in supported_accessory_modes() as proposed by Guenter

Changes since v14:
- Fixes proposed by Mika
- "identity" directory for all discover identity VDOs instead of "vdo" attribute
- alternate mode device names to just "svid-<svid>"

Changes since v13:
- New API. Everything is registered separately.

Changes since v12:
- Added prefer_role member to typec_capability structure as requested by Guenter

Changes since v11:
- The port drivers are responsible of removing the alternate modes (just like the documentation already said).

Changes since v10:
- Using ATTRIBUTE_GROUPS and DEVICE_ATTR marcos everywhere
- Moved sysfs_match_string to lib/string.c
- Rationalized uevents
- Calling ida_destroy

Changes since v9:
- Minor typec_wcove.c cleanup as proposed by Guenter Roeck. No function affect.

Changes since v8:
- checking sysfs_streq() result correctly in sysfs_strmatch
- fixed accessory check in supported_accessory_mode
- using "none" as the only string that can clear the preferred role

Changes since v7:
- Removed "type" attribute from partners
- Added supports_usb_power_delivery attribute for partner and cable

Changes since v6:
- current_vconn_role attr renamed to vconn_source (no API changes)
- Small documentation improvements proposed by Vincent Palatin

Changes since v5:
- Only updating the roles based on driver notifications
- Added MODULE_ALIAS for the WhiskeyCove module
- Including the patch that creates the actual platform device for the WhiskeyCove Type-C PHY in this series.

Changes since v4:
- Remove the port lock completely

Changes since v3:
- Documentation cleanup as proposed by Roger Quadros
- Setting partner altmodes member to NULL on removal and fixing a warning, as proposed by Guenter Roeck
- Added the following attributes for partners and cables:
* supports_usb_power_delivery
* id_header_vdo
- "id_header_vdo" is visible only when the partner or cable supports USB Power Delivery communication.
- Partner attribute "accessory" is hidden when the partner type is not "Accessory".

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 (3):
lib/string: add sysfs_match_string helper
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 |  276 ++++++
 Documentation/usb/typec.rst                 |  185 ++++
 MAINTAINERS                                 |    9 +
 drivers/usb/Kconfig                         |    2 +
 drivers/usb/Makefile                        |    2 +
 drivers/usb/typec/Kconfig                   |   22 +
 drivers/usb/typec/Makefile                  |    2 +
 drivers/usb/typec/typec.c                   | 1262 +++++++++++++++++++++++++++
 drivers/usb/typec/typec_wcove.c             |  377 ++++++++
 include/linux/string.h                      |   10 +
 include/linux/usb/typec.h                   |  243 ++++++
 lib/string.c                                |   26 +
 12 files changed, 2416 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.rst
 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.11.0
author maintainer
#1 lore raw

PATCH v17 1/3 lib/string: add sysfs_match_string helper

Make a simple helper for matching strings with sysfs attribute files. In most parts the same as match_string(), except sysfs_match_string() uses sysfs_streq() instead of strcmp() for matching. This is more convenient when used with sysfs attributes.

---
 include/linux/string.h | 10 ++++++++++
 lib/string.c           | 26 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/linux/string.h +10 -0
index 040eab355533..96e4ad598210 100644
@@ -136,6 +136,16 @@ static inline int strtobool(const char *s, bool *res)
 }
 
 int match_string(const char * const *array, size_t n, const char *string);
+int __sysfs_match_string(const char * const *array, size_t n, const char *s);
+
+/**
+ * sysfs_match_string - matches given string in an array
+ * @_a: array of strings
+ * @_s: string to match with
+ *
+ * Helper for __sysfs_match_string(). Calculates the size of @a automatically.
+ */
+#define sysfs_match_string(_a, _s) __sysfs_match_string(_a, ARRAY_SIZE(_a), _s)
 
 #ifdef CONFIG_BINARY_PRINTF
 int vbin_printf(u32 *bin_buf, size_t size, const char *fmt,
lib/string.c +26 -0
index b3c22a285a78..f47a72098c87 100644
@@ -656,6 +656,32 @@ int match_string(const char * const *array, size_t n, const char *string)
 }
 EXPORT_SYMBOL(match_string);
 
+/**
+ * __sysfs_match_string - matches given string in an array
+ * @array: array of strings
+ * @n: number of strings in the array or -1 for NULL terminated arrays
+ * @str: string to match with
+ *
+ * Returns index of @str in the @array or -EINVAL, just like match_string().
+ * Uses sysfs_streq instead of strcmp for matching.
+ */
+int __sysfs_match_string(const char * const *array, size_t n, const char *str)
+{
+	const char *item;
+	int index;
+
+	for (index = 0; index < n; index++) {
+		item = array[index];
+		if (!item)
+			break;
+		if (sysfs_streq(item, str))
+			return index;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL(__sysfs_match_string);
+
 #ifndef __HAVE_ARCH_MEMSET
 /**
  * memset - Fill a region of memory with the given value
Signature · 1 line
2.11.0
author maintainer
#2 lore raw

PATCH v17 2/3 usb: USB Type-C connector class

In reply to 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 the port supports USB Power Delivery, also control over power role swapping and Alternate Modes.

---
 Documentation/ABI/testing/sysfs-class-typec |  276 ++++++
 Documentation/usb/typec.rst                 |  185 ++++
 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                   | 1262 +++++++++++++++++++++++++++
 include/linux/usb/typec.h                   |  243 ++++++
 9 files changed, 1987 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-typec
 create mode 100644 Documentation/usb/typec.rst
 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 +276 -0
new file mode 100644
index 000000000000..3819fd9a5731
@@ -0,0 +1,276 @@
+USB Type-C port devices (eg. /sys/class/typec/port0/)
+
+What:		/sys/class/typec/<port>/data_role
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The supported USB data roles. This attribute can be used for
+		requesting data role swapping on the port. Swapping is supported
+		as synchronous operation, so write(2) to the attribute will not
+		return until the operation has finished. The attribute is
+		notified about role changes so that poll(2) on the attribute
+		wakes up. Change on the role will also generate uevent
+		KOBJ_CHANGE on the port. The current role is show in brackets,
+		for example "[host] device" when DRP port is in host mode.
+
+		Valid values: host, device
+
+What:		/sys/class/typec/<port>/power_role
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The supported power roles. This attribute can be used to request
+		power role swap on the port when the port supports USB Power
+		Delivery. Swapping is supported as synchronous operation, so
+		write(2) to the attribute will not return until the operation
+		has finished. The attribute is notified about role changes so
+		that poll(2) on the attribute wakes up. Change on the role will
+		also generate uevent KOBJ_CHANGE. The current role is show in
+		brackets, for example "[source] sink" when in source mode.
+
+		Valid values: source, sink
+
+What:		/sys/class/typec/<port>/vconn_source
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows is the port VCONN Source. This attribute can be used to
+		request VCONN swap to change the VCONN Source during connection
+		when both the port and the partner support USB Power Delivery.
+		Swapping is supported as synchronous operation, so write(2) to
+		the attribute will not return until the operation has finished.
+		The attribute is notified about VCONN source changes so that
+		poll(2) on the attribute wakes up. Change on VCONN source also
+		generates uevent KOBJ_CHANGE.
+
+		Valid values:
+		- "no" when the port is not the VCONN Source
+		- "yes" when the port is the VCONN Source
+
+What:		/sys/class/typec/<port>/power_operation_mode
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the current power operational mode the port is in. The
+		power operation mode means current level for VBUS. In case USB
+		Power Delivery communication is used for negotiating the levels,
+		power operation mode should show "usb_power_delivery".
+
+		Valid values:
+		- default
+		- 1.5A
+		- 3.0A
+		- usb_power_delivery
+
+What:		/sys/class/typec/<port>/preferred_role
+Date:		March 2017
+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. By
+		default the preferred role should come from the platform.
+
+		Valid values: source, sink, none (to remove preference)
+
+What:		/sys/class/typec/<port>/supported_accessory_modes
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Space separated list of accessory modes, defined in the USB
+		Type-C specification, the port supports.
+
+What:		/sys/class/typec/<port>/usb_power_delivery_revision
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Revision number of the supported USB Power Delivery
+		specification, or 0 when USB Power Delivery is not supported.
+
+What:		/sys/class/typec/<port>/usb_typec_revision
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Revision number of the supported USB Type-C specification.
+
+
+USB Type-C partner devices (eg. /sys/class/typec/port0-partner/)
+
+What:		/sys/class/typec/<port>-partner/accessory_mode
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the Accessory Mode name when the partner is an Accessory.
+		The Accessory Modes are defined in USB Type-C Specification.
+
+What:		/sys/class/typec/<port>-partner/supports_usb_power_delivery
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the partner supports USB Power Delivery communication:
+		Valid values: yes, no
+
+What:		/sys/class/typec/<port>-partner>/identity/
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This directory appears only if the port device driver is capable
+		of showing the result of Discover Identity USB power delivery
+		command. That will not always be possible even when USB power
+		delivery is supported, for example when USB power delivery
+		communication for the port is mostly handled in firmware. If the
+		directory exists, it will have an attribute file for every VDO
+		in Discover Identity command result.
+
+What:		/sys/class/typec/<port>-partner/identity/id_header
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		ID Header VDO part of Discover Identity command result. The
+		value will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+What:		/sys/class/typec/<port>-partner/identity/cert_stat
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Cert Stat VDO part of Discover Identity command result. The
+		value will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+What:		/sys/class/typec/<port>-partner/identity/product
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Product VDO part of Discover Identity command result. The value
+		will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+
+USB Type-C cable devices (eg. /sys/class/typec/port0-cable/)
+
+Note: Electronically Marked Cables will have a device also for one cable plug
+(eg. /sys/class/typec/port0-plug0). If the cable is active and has also SOP
+Double Prime controller (USB Power Deliver specification ch. 2.4) it will have
+second device also for the other plug. Both plugs may have alternate modes as
+described in USB Type-C and USB Power Delivery specifications.
+
+What:		/sys/class/typec/<port>-cable/type
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows if the cable is active.
+		Valid values: active, passive
+
+What:		/sys/class/typec/<port>-cable/plug_type
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows type of the plug on the cable:
+		- type-a - Standard A
+		- type-b - Standard B
+		- type-c
+		- captive
+
+What:		/sys/class/typec/<port>-cable/identity/
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		This directory appears only if the port device driver is capable
+		of showing the result of Discover Identity USB power delivery
+		command. That will not always be possible even when USB power
+		delivery is supported. If the directory exists, it will have an
+		attribute for every VDO returned by Discover Identity command.
+
+What:		/sys/class/typec/<port>-cable/identity/id_header
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		ID Header VDO part of Discover Identity command result. The
+		value will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+What:		/sys/class/typec/<port>-cable/identity/cert_stat
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Cert Stat VDO part of Discover Identity command result. The
+		value will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+What:		/sys/class/typec/<port>-cable/identity/product
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Product VDO part of Discover Identity command result. The value
+		will show 0 until Discover Identity command result becomes
+		available. The value can be polled.
+
+
+Alternate Mode devices.
+
+The alternate modes will have Standard or Vendor ID (SVID) assigned by USB-IF.
+The ports, partners and cable plugs can have alternate modes. A supported SVID
+will consist of a set of modes. Every SVID a port/partner/plug supports will
+have a device created for it, and every supported mode for a supported SVID will
+have its own directory under that device. Below <dev> refers to the device for
+the alternate mode.
+
+What:		/sys/class/typec/<port|partner|cable>/<dev>/svid
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		The SVID (Standard or Vendor ID) assigned by USB-IF for this
+		alternate mode.
+
+What:		/sys/class/typec/<port|partner|cable>/<dev>/mode<index>/
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Every supported mode will have its own directory. The name of
+		a mode will be "mode<index>" (for example mode1), where <index>
+		is the actual index to the mode VDO returned by Discover Modes
+		USB power delivery command.
+
+What:		/sys/class/typec/<port|partner|cable>/<dev>/mode<index>/description
+Date:		March 2017
+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/<port|partner|cable>/<dev>/mode<index>/vdo
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Shows the VDO in hexadecimal returned by Discover Modes command
+		for this mode.
+
+What:		/sys/class/typec/<port|partner|cable>/<dev>/mode<index>/active
+Date:		March 2017
+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. Entering/exiting modes is
+		supported as synchronous operation so write(2) to the attribute
+		does not return until the enter/exit mode operation has
+		finished. The attribute is notified when the mode is
+		entered/exited so poll(2) on the attribute wakes up.
+		Entering/exiting a mode will also generate uevent KOBJ_CHANGE.
+
+		Valid values: yes, no
+
+What:		/sys/class/typec/<port>/<dev>/mode<index>/supported_roles
+Date:		March 2017
+Contact:	Heikki Krogerus <[email protected]>
+Description:
+		Space separated list of the supported roles.
+
+		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.
+
+		Valid values: source, sink
Documentation/usb/typec.rst new file +185 -0

185 lines not on this page · raw message

MAINTAINERS +9 -0
index 277c2e2062bd..88824ca9cf4d 100644
@@ -13100,6 +13100,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.rst
+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 fbe493d44e81..89c322e0742b 100644
@@ -152,6 +152,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 && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
index 7791af6c102c..c7f409885eff 100644
@@ -62,3 +62,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 000000000000..17792f9114c6
@@ -0,0 +1,7 @@
+
+menu "USB Power Delivery and Type-C drivers"
+
+config TYPEC
+	tristate
+
+endmenu
drivers/usb/typec/Makefile new file +1 -0
new file mode 100644
index 000000000000..1012a8bed6d5
@@ -0,0 +1 @@
+obj-$(CONFIG_TYPEC)		+= typec.o
drivers/usb/typec/typec.c new file +1262 -0

1,262 lines not on this page · raw message

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

243 lines not on this page · raw message

Signature · 1 line
2.11.0
#3 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Hi Heikki,

Good to see things are happening with Type-C!

Documentation/usb/typec.rst line 36

Quoted 6 lines · Heikki Krogerus

...

Documentation/usb/typec.rst new file +5 -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 it
+is attached to. The partner attached to port "port0" will be named
+"port0-partner". Full path to the device would be
+/sys/class/typec/port0/port0-partner/.

A "/port0" too much?

Documentation/usb/typec.rst line 49

Quoted 13 lines
Documentation/usb/typec.rst new file +13 -0
+
+The cable and the two plugs on it may also be optionally presented as their own
+devices under /sys/class/typec/. The cable attached to the port "port0" port
+will be named port0-cable and the plug on the SOP Prime end (see USB Power
+Delivery Specification ch. 2.4) will be named "port0-plug0" and on the SOP
+Double Prime end "port0-plug1". The parent of a cable will always be the port,
+and the parent of the cable plugs will always be the cable.
+
+If the port, partner or cable plug support Alternate Modes, every supported
+Alternate Mode SVID will have their own device describing them. The Alternate
+Modes will not be attached to the typec class. The parent of an alternate mode
+will be the device that supports it, so for example an alternate mode of
+port0-partner will bees presented under /sys/class/typec/port0-partner/. Every

bees?

Documentation/usb/typec.rst line 54

Quoted 6 lines
Documentation/usb/typec.rst new file +5 -0
+mode that is supported will have its own group under the Alternate Mode device
+named "mode<index>", for example /sys/class/typec/port0/<alternate mode>/mode1/.
+The requests for entering/exiting a mode can be done with "active" attribute
+file in that group.
+
...

I'm hoping to find time to upgrade the kernel and try these patches in my system.

Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

BR // Mats

#4 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 40 lines · Mats Karrman

Hi Heikki,

Good to see things are happening with Type-C!

Documentation/usb/typec.rst line 36

Quoted 6 lines · Heikki Krogerus

...

Documentation/usb/typec.rst new file +5 -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 it
+is attached to. The partner attached to port "port0" will be named
+"port0-partner". Full path to the device would be
+/sys/class/typec/port0/port0-partner/.

A "/port0" too much?

Documentation/usb/typec.rst line 49

Quoted 13 lines
Documentation/usb/typec.rst new file +13 -0
+
+The cable and the two plugs on it may also be optionally presented as their own
+devices under /sys/class/typec/. The cable attached to the port "port0" port
+will be named port0-cable and the plug on the SOP Prime end (see USB Power
+Delivery Specification ch. 2.4) will be named "port0-plug0" and on the SOP
+Double Prime end "port0-plug1". The parent of a cable will always be the port,
+and the parent of the cable plugs will always be the cable.
+
+If the port, partner or cable plug support Alternate Modes, every supported
+Alternate Mode SVID will have their own device describing them. The Alternate
+Modes will not be attached to the typec class. The parent of an alternate mode
+will be the device that supports it, so for example an alternate mode of
+port0-partner will bees presented under /sys/class/typec/port0-partner/. Every

bees?

Documentation/usb/typec.rst line 54

Quoted 6 lines
Documentation/usb/typec.rst new file +5 -0
+mode that is supported will have its own group under the Alternate Mode device
+named "mode<index>", for example /sys/class/typec/port0/<alternate mode>/mode1/.
+The requests for entering/exiting a mode can be done with "active" attribute
+file in that group.
+
...

I'm hoping to find time to upgrade the kernel and try these patches in my system.

Quoted 7 lines

Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

That really depends on the lower level driver. For Chromebooks, where the Type-C Protocol Manager runs on the EC, we have an extcon driver which reports the pin states to the graphics drivers and connects to the Type-C class code using the Type-C class API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4, shows how it can be done, though that code currently still uses the Android Type-C infrastructure.

Guenter

#5 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Mats Karrman

....
Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

Quoted 7 lines

That really depends on the lower level driver. For Chromebooks, where the Type-C Protocol Manager runs on the EC, we have an extcon driver which reports the pin states to the graphics drivers and connects to the Type-C class code using the Type-C class API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4, shows how it can be done, though that code currently still uses the Android Type-C infrastructure.

OK, thanks!

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected

directly to the SoC and it's using DTB/OF.

Using extcon I would have a driver that is both typec class and extcon driver at the same time

since I can't share the access to the typec phy. Is this done elsewhere in the kernel?

I don't know much about the wcove PMIC and what alternate modes it might support but I

guess that driver would end up in the same place.

Do we need to further standardize attributes under (each) specific alternate mode to

include things such as HPD for the DP mode?

BR // Mats

#6 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

2017-03-03 8:29 GMT+01:00 Mats Karrman <[email protected]>:

Quoted 16 lines · Guenter Roeck
Quoted 15 lines · Mats Karrman
Quoted 12 lines

....
Looking forward, one thing I have run into is how to connect the typec driver with a
driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification
includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the
Attention message. These signals are needed by the DisplayPort driver to know when to
start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

Quoted 14 lines
Quoted 5 lines

That really depends on the lower level driver. For Chromebooks, where the Type-C
Protocol Manager runs on the EC, we have an extcon driver which reports the pin states
to the graphics drivers and connects to the Type-C class code using the

Quoted 8 lines

Type-C class
API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4,
shows how it can be done, though that code currently still uses the Android Type-C
infrastructure.

On a side note, the cros-ec extcon part for DP is currently discussed here [1]. This driver works together with the cdn-dp driver that just landed in mainline. So comments and feedback are welcome

[1] https://lkml.org/lkml/2017/3/1/301

Quoted 26 lines

OK, thanks!

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected

directly to the SoC and it's using DTB/OF.

Using extcon I would have a driver that is both typec class and extcon driver at the same time

since I can't share the access to the typec phy. Is this done elsewhere in the kernel?

I don't know much about the wcove PMIC and what alternate modes it might support but I

guess that driver would end up in the same place.

Do we need to further standardize attributes under (each) specific alternate mode to

include things such as HPD for the DP mode?

BR // Mats

#7 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Mats Karrman
Quoted 18 lines · Mats Karrman
Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Mats Karrman

....
Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

Quoted 7 lines

That really depends on the lower level driver. For Chromebooks, where the Type-C Protocol Manager runs on the EC, we have an extcon driver which reports the pin states to the graphics drivers and connects to the Type-C class code using the Type-C class API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4, shows how it can be done, though that code currently still uses the Android Type-C infrastructure.

Quoted 6 lines

OK, thanks!

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected

directly to the SoC and it's using DTB/OF.

Sounds quite similar to rk3399 (Samsung Chromebook Plus). I have not ported the Type-C class code to that system yet, but it does use the extcon cros_ec driver, and DP connectivity is signaled to the DP code through extcon events.

Quoted 4 lines

Using extcon I would have a driver that is both typec class and extcon driver at the same time

since I can't share the access to the typec phy. Is this done elsewhere in the kernel?

See above. The code is available in the repository mentioned above.

Guenter

Quoted 11 lines

I don't know much about the wcove PMIC and what alternate modes it might support but I

guess that driver would end up in the same place.

Do we need to further standardize attributes under (each) specific alternate mode to

include things such as HPD for the DP mode?

BR // Mats

author maintainer
#8 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Mats Karrman

Hi,

Quoted 10 lines · Mats Karrman
Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Mats Karrman

....
Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

My idea was to have something like the altmode "bus" at one point. We create a device for every alternate mode registered in typec class, so the alternate modes registered for the ports and partners would simply be attached to the altmode bus. There would be a bus per port of course.

The drivers for the port alternate modes would take care of things like muxing and other platform specific stuff as needed, and they would be tied to the underlying subsystems and drivers, graphics in case of DisplayPort. The drivers for the partner alternate modes would take care of the actual communication with the alternate mode with VDMs if needed (but not necessarily), and they would need to be tied to the port alternate modes. In practice the driver for both the port and the partner alternate modes will be the same (in the same location) obviously, at least in most cases.

I think a bus would allow us to support several ways of handling the alternate modes on different platforms. It would work fine also on platforms that had no use for it of course, like platforms where firmware or EC takes care of most things related to Type-C.

But please note that since this is just a high level idea still, we wouldn't for example need to create an actual bus if there is no use for it, but since we have the SVIDs that can be used for matching, then why not try take advantage of them, right.

How would something like that sound to you guys?

Quoted 7 lines
Quoted 7 lines

That really depends on the lower level driver. For Chromebooks, where the Type-C Protocol Manager runs on the EC, we have an extcon driver which reports the pin states to the graphics drivers and connects to the Type-C class code using the Type-C class API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4, shows how it can be done, though that code currently still uses the Android Type-C infrastructure.

In this case I think you would only need to register a driver with the bus in case you want the handle to the device for the alternate mode.

Quoted 4 lines

OK, thanks!

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected directly to the SoC and it's using DTB/OF.

Is this "DP controller" a controller that is capable of taking care of the USB Power Delivery communication with the partner regarding DisplayPort alternate mode?

Quoted 4 lines

Using extcon I would have a driver that is both typec class and extcon driver at the same time since I can't share the access to the typec phy. Is this done elsewhere in the kernel? I don't know much about the wcove PMIC and what alternate modes it might support but I guess that driver would end up in the same place.

What alternate modes systems with WhiskeyCove supports depends on the platform. WhiskeyCove PMIC (as in Power Management IC) is available on a few Intel Atom platforms. The USB Type-C PHY in it provides a simple USB PD transceiver that does not touch the actual communication with the partners. The communication needs to be done in software, including dealing with alternate modes.

I'm not planning on using extcon for anything with WhiskeyCove. I don't have any use for it. It looks to me that extcon is used just as a tool to create software couplings in many cases, and I'm not completely comfortable with that.

In my case with DP altmode, if we had for example muxes to take care of, I don't think it would be a problem to tie the driver for the mux to the graphics directly, so basically make it part of the graphics stack. That driver would be the port (and partner) altmode driver.

Quoted 2 lines

Do we need to further standardize attributes under (each) specific alternate mode to include things such as HPD for the DP mode?

I'm not completely sure what kind of system you have, but I would imagine that if we had the bus, your DP controller driver would be the port (and partner) alternate mode driver. The bus would bind you to the typec phy.

Thanks,

Signature · 1 line
heikki
#9 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 74 lines · Heikki Krogerus

Hi,

Quoted 10 lines · Mats Karrman
Quoted 8 lines · Guenter Roeck
Quoted 7 lines · Mats Karrman

....
Looking forward, one thing I have run into is how to connect the typec driver with a driver for an alternate mode. E.g. the DisplayPort Alternate Mode specification includes the HPD (hot plug) and HPD-INT (hot plug interrupt) signals as bits in the Attention message. These signals are needed by the DisplayPort driver to know when to start negotiation etc.
Have you got any thoughts on how to standardize such interfaces?

My idea was to have something like the altmode "bus" at one point. We create a device for every alternate mode registered in typec class, so the alternate modes registered for the ports and partners would simply be attached to the altmode bus. There would be a bus per port of course.

The drivers for the port alternate modes would take care of things like muxing and other platform specific stuff as needed, and they would be tied to the underlying subsystems and drivers, graphics in case of DisplayPort. The drivers for the partner alternate modes would take care of the actual communication with the alternate mode with VDMs if needed (but not necessarily), and they would need to be tied to the port alternate modes. In practice the driver for both the port and the partner alternate modes will be the same (in the same location) obviously, at least in most cases.

I think a bus would allow us to support several ways of handling the alternate modes on different platforms. It would work fine also on platforms that had no use for it of course, like platforms where firmware or EC takes care of most things related to Type-C.

But please note that since this is just a high level idea still, we wouldn't for example need to create an actual bus if there is no use for it, but since we have the SVIDs that can be used for matching, then why not try take advantage of them, right.

How would something like that sound to you guys?

Quoted 7 lines
Quoted 7 lines

That really depends on the lower level driver. For Chromebooks, where the Type-C Protocol Manager runs on the EC, we have an extcon driver which reports the pin states to the graphics drivers and connects to the Type-C class code using the Type-C class API. I still need to update, re-test, and publish that code. The published code in
https://chromium.googlesource.com/chromiumos/third_party/kernel/, branch chromeos-4.4, shows how it can be done, though that code currently still uses the Android Type-C infrastructure.

In this case I think you would only need to register a driver with the bus in case you want the handle to the device for the alternate mode.

Quoted 4 lines

OK, thanks!

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected directly to the SoC and it's using DTB/OF.

Is this "DP controller" a controller that is capable of taking care of the USB Power Delivery communication with the partner regarding DisplayPort alternate mode?

Quoted 4 lines

Using extcon I would have a driver that is both typec class and extcon driver at the same time since I can't share the access to the typec phy. Is this done elsewhere in the kernel? I don't know much about the wcove PMIC and what alternate modes it might support but I guess that driver would end up in the same place.

What alternate modes systems with WhiskeyCove supports depends on the platform. WhiskeyCove PMIC (as in Power Management IC) is available on a few Intel Atom platforms. The USB Type-C PHY in it provides a simple USB PD transceiver that does not touch the actual communication with the partners. The communication needs to be done in software, including dealing with alternate modes.

Quoted 5 lines

I'm not planning on using extcon for anything with WhiskeyCove. I don't have any use for it. It looks to me that extcon is used just as a tool to create software couplings in many cases, and I'm not completely comfortable with that.

For rk3399 we went back and forth trying other approaches, but using extcon turned out to be the most straightforward mechanism; everything else would just have replicated what extcon already provides. Having said that, I am open to other approaches. The rk3399 implementation may be seen as an example on what is required, specifically when it comes to the interaction between cable, DP, and the Type-C phy.

Guenter

Quoted 16 lines

In my case with DP altmode, if we had for example muxes to take care of, I don't think it would be a problem to tie the driver for the mux to the graphics directly, so basically make it part of the graphics stack. That driver would be the port (and partner) altmode driver.

Quoted 2 lines

Do we need to further standardize attributes under (each) specific alternate mode to include things such as HPD for the DP mode?

I'm not completely sure what kind of system you have, but I would imagine that if we had the bus, your DP controller driver would be the port (and partner) alternate mode driver. The bus would bind you to the typec phy.

Thanks,

#10 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Heikki Krogerus
Quoted 4 lines · Heikki Krogerus

On Fri, Mar 03, 2017 at 08:29:18AM +0100, Mats Karrman wrote:
....

How would something like that sound to you guys?

Complicated... Need to marinate on that for a while ;)

Quoted 5 lines
Quoted 2 lines

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected directly to the SoC and it's using DTB/OF.

Is this "DP controller" a controller that is capable of taking care of the USB Power Delivery communication with the partner regarding DisplayPort alternate mode?

No, the "DP controller" just talks DP and knows nothing about Type-C or USB PD. It takes a video stream from the SoC and turns it into a DP link, set up and orchestrated by the corresponding driver. And all the driver needs from Type-C is the plugged in / interrupt / plugged out events.

The analog switching between USB / safe / DP signal levels in the Type-C connector is, I think, best handled by the software doing the USB PD negotiation / Altmode handling (using some GPIOs).

Quoted 6 lines
Quoted 2 lines

Do we need to further standardize attributes under (each) specific alternate mode to include things such as HPD for the DP mode?

I'm not completely sure what kind of system you have, but I would imagine that if we had the bus, your DP controller driver would be the port (and partner) alternate mode driver. The bus would bind you to the typec phy.

So, both the DP controller and the USB PD phy are I2C devices, and now I have to make them both attach to the AM bus as well?

BR,
Mats

#11 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Am Freitag, den 03.03.2017, 20:27 +0100 schrieb Mats Karrman:

Quoted 10 lines · Heikki Krogerus
Quoted 7 lines · Mats Karrman

....

How would something like that sound to you guys?

Complicated... Need to marinate on that for a while ;)

The thing is that a type C plug has operations that affect every device on it and need to be synchronized. Reset and power requirements would be the obvious examples.

It seems to me that the natural way to represent this is a bus. Like SCSI where you have a bus reset operation.

Regards
Oliver

author maintainer
#12 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Mats Karrman

Hi Mats,

Quoted 8 lines · Mats Karrman
Quoted 4 lines · Heikki Krogerus

On Fri, Mar 03, 2017 at 08:29:18AM +0100, Mats Karrman wrote:
....

How would something like that sound to you guys?

Complicated... Need to marinate on that for a while ;)

Sorry about the bad explanation :-). Let me try again.. I'm simply looking for a method that is as scalable as possible to handle the alternate modes, basically how to couple the different components involved. Bus would feel like the best approach at the moment.

Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected directly to the SoC and it's using DTB/OF.

Is this "DP controller" a controller that is capable of taking care of the USB Power Delivery communication with the partner regarding DisplayPort alternate mode?

No, the "DP controller" just talks DP and knows nothing about Type-C or USB PD. It takes a video stream from the SoC and turns it into a DP link, set up and orchestrated by the corresponding driver. And all the driver needs from Type-C is the plugged in / interrupt / plugged out events.

Got it.

Quoted 5 lines

The analog switching between USB / safe / DP signal levels in the Type-C connector is, I think, best handled by the software doing the USB PD negotiation / Altmode handling (using some GPIOs).

Quoted 2 lines
Quoted 2 lines

Do we need to further standardize attributes under (each) specific alternate mode to include things such as HPD for the DP mode?

Quoted 7 lines
Quoted 4 lines

I'm not completely sure what kind of system you have, but I would imagine that if we had the bus, your DP controller driver would be the port (and partner) alternate mode driver. The bus would bind you to the typec phy.

So, both the DP controller and the USB PD phy are I2C devices, and now I have to make them both attach to the AM bus as well?

The DP controller would provide the driver and the USB PD phy (actually, the typec class) the device.

Would it be a problem to register these I2C devices with some other subsystem, was it extcon or something like AM bus? It really would not be that uncommon. Or have I misunderstood your question?

Thanks,

Signature · 1 line
heikki
#13 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 23 lines · Heikki Krogerus

Hi Mats,

Quoted 9 lines · Mats Karrman
Quoted 5 lines
Quoted 2 lines

My system is a bit different. It's an i.MX6 SoC with the typec phy and DP controller connected directly to the SoC and it's using DTB/OF.

Is this "DP controller" a controller that is capable of taking care of the USB Power Delivery communication with the partner regarding DisplayPort alternate mode?

No, the "DP controller" just talks DP and knows nothing about Type-C or USB PD. It takes a video stream from the SoC and turns it into a DP link, set up and orchestrated by the corresponding driver. And all the driver needs from Type-C is the plugged in / interrupt / plugged out events.

Got it.

Quoted 9 lines

The analog switching between USB / safe / DP signal levels in the Type-C connector is, I think, best handled by the software doing the USB PD negotiation / Altmode handling (using some GPIOs).

Quoted 6 lines
Quoted 2 lines

Do we need to further standardize attributes under (each) specific alternate mode to include things such as HPD for the DP mode?

I'm not completely sure what kind of system you have, but I would imagine that if we had the bus, your DP controller driver would be the port (and partner) alternate mode driver. The bus would bind you to the typec phy.

Quoted 8 lines
Quoted 2 lines

So, both the DP controller and the USB PD phy are I2C devices, and now I have to make them both attach to the AM bus as well?

The DP controller would provide the driver and the USB PD phy (actually, the typec class) the device.

Would it be a problem to register these I2C devices with some other subsystem, was it extcon or something like AM bus? It really would not be that uncommon. Or have I misunderstood your question?

OK, so a bus could be used for drivers to find each other but it still does not say anything about how those drivers are supposed to communicate so that must be prescribed separately, right?

If I read Heikki's original suggestion I understand it like the DP driver would be responsible for AM specific USB PD/VDM communication. But wouldn't that lead to a lot of code duplication since the AM protocol is the same for all drivers of a kind?

I'm still struggling to catch up on what you guys have been up to during the last year or so :-) and came across some patches of Guenter from last October:

http://www.mail-archive.com/[email protected]/msg1243527.html

What happened to them? Has there been any progress since then?

BR // Mats

#14 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

On 03/07/2017 02:30 PM, Mats Karrman wrote:
[ ... ]

Quoted 8 lines

I'm still struggling to catch up on what you guys have been up to during the last year or so :-) and came across some patches of Guenter from last October:

http://www.mail-archive.com/[email protected]/msg1243527.html

What happened to them? Has there been any progress since then?

Updates to keep in sync with API changes, bug fixes, and minor improvements, for the most part. I can post a current version if there is interest. The latest version is also available from
https://chromium-review.googlesource.com/#/c/389917/

Guenter

#15 lore raw

USB Type-C Port Manager API concern

Hi Guenter,

From a previous thread:

Quoted 9 lines · Guenter Roeck

On 03/07/2017 02:30 PM, Mats Karrman wrote:
[ ... ]

Quoted 6 lines

I'm still struggling to catch up on what you guys have been up to during the last year or so :-) and came across some patches of Guenter from last October:

http://www.mail-archive.com/[email protected]/msg1243527.html

Quoted 7 lines
Quoted 2 lines

What happened to them? Has there been any progress since then?

Updates to keep in sync with API changes, bug fixes, and minor improvements, for the most part. I can post a current version if there is interest. The latest version is also available from
https://chromium-review.googlesource.com/#/c/389917/

I'm working on a tcpi driver and have some concern about the tcpm api. The tcpm_register_port() is typically called from the probe function of tcpi driver where the tcpm_port reference returned is stored in the driver private data. The problem I ran into is that tcpm_register_port() calls back to the not yet fully initialized tcpi driver, causing null- pointer dereferences. This could of course be solved by extra logic in the tcpi driver but I think it would be more elegant if the registration of a port could be free of premature callbacks. E.g. it could be required that the tcpi driver probe called tcpm_tcpc_reset() once it's done initializing or the necessary data could be supplied in the call to tcpm_register_port().
What do you think?

BR,
Mats

#16 lore raw

Re: USB Type-C Port Manager API concern

Hi Mats,

Quoted 25 lines · Mats Karrman

Hi Guenter,

From a previous thread:

Quoted 11 lines · Guenter Roeck

On 03/07/2017 02:30 PM, Mats Karrman wrote:
[ ... ]

Quoted 8 lines

I'm still struggling to catch up on what you guys have been up to during the
last year or so :-) and came across some patches of Guenter from last October:

http://www.mail-archive.com/[email protected]/msg1243527.html

Quoted 8 lines
Quoted 2 lines

What happened to them? Has there been any progress since then?

Updates to keep in sync with API changes, bug fixes, and minor improvements,
for the most part. I can post a current version if there is interest. The latest version is also available from
https://chromium-review.googlesource.com/#/c/389917/

Quoted 12 lines

I'm working on a tcpi driver and have some concern about the tcpm api. The tcpm_register_port() is typically called from the probe function of tcpi driver where the tcpm_port reference returned is stored in the driver private data. The problem I ran into is that tcpm_register_port() calls back to the not yet fully initialized tcpi driver, causing null- pointer dereferences. This could of course be solved by extra logic in the tcpi driver but I think it would be more elegant if the registration of a port could be free of premature callbacks. E.g. it could be required that the tcpi driver probe called tcpm_tcpc_reset() once it's done initializing or the necessary data could be supplied in the call to tcpm_register_port().
What do you think?

Let me think about it. In theory it should be possible to avoid callbacks into the underlying driver until after the return from the registration code, but that would still be racy if the underlying driver is not ready.

Basic problem seems to be that an API in general assumes that the caller is ready to serve it once it registers itself. It is kind of unusual to have two calls, one to register the driver and one to tell the infrastructure that it is ready (which I assume your reset call would do). Ultimately this means that the tcpm driver would have to have additional logic to identify if the underlying driver is ready to handle callbacks.

Can you delay tcpm registration until after the underlying driver is ready, ie typically to the end of its probe function ? Or am I misunderstanding your problem ?

Thanks,
Guenter

#17 lore raw

Re: USB Type-C Port Manager API concern

Quoted 26 lines · Guenter Roeck

Hi Mats,

Quoted 4 lines · Mats Karrman

I'm working on a tcpi driver and have some concern about the tcpm api. The tcpm_register_port() is typically called from the probe function of tcpi driver where the tcpm_port reference returned is stored in the driver private data. The problem I ran into is that tcpm_register_port()

Quoted 8 lines

calls back to the not yet fully initialized tcpi driver, causing null- pointer dereferences. This could of course be solved by extra logic in the tcpi driver but I think it would be more elegant if the registration of a port could be free of premature callbacks. E.g. it could be required that the tcpi driver probe called tcpm_tcpc_reset() once it's done initializing or the necessary data could be supplied in the call to tcpm_register_port().
What do you think?

Let me think about it. In theory it should be possible to avoid callbacks into the underlying driver until after the return from the registration code, but that would still be racy if the underlying driver is not ready.

Basic problem seems to be that an API in general assumes that the caller is ready to serve it once it registers itself. It is kind of unusual to have two calls, one to register the driver and one to tell the infrastructure that it is ready (which I assume your reset call would do). Ultimately this means that the tcpm driver would have to have additional logic to identify if the underlying driver is ready to handle callbacks.

Quoted 3 lines

Can you delay tcpm registration until after the underlying driver is ready, ie typically to the end of its probe function ? Or am I misunderstanding your problem ?

The problem I had was that I was trying to pull the same trick that you do ;) I.e. the probe function calls tcpm_register_port() that is calling back to the driver that was trying to call back to tcpm, just that the call to tcpm_register_port() has not yet returned so the pointer to tcpm_port in the driver data structure was still null.

I was able to fix the issue by commenting out the call to tcpm_init() at the end of tcpm_register_port() and instead call ("your") tcpm_tcpc_reset(), that currently does nothing but calling tcpm_init(), after I'm done.

Even though I'm not overly excited about the tcpm register function calling back to the driver I don't think my fix is much better. I should live by my own words and refrain from calling back to tcpm until registration has finished...

// Mats

#18 lore raw

Re: USB Type-C Port Manager API concern

Quoted 38 lines · Mats Karrman
Quoted 26 lines · Guenter Roeck

Hi Mats,

Quoted 4 lines · Mats Karrman

I'm working on a tcpi driver and have some concern about the tcpm api. The tcpm_register_port() is typically called from the probe function of tcpi driver where the tcpm_port reference returned is stored in the driver private data. The problem I ran into is that tcpm_register_port()

Quoted 8 lines

calls back to the not yet fully initialized tcpi driver, causing null- pointer dereferences. This could of course be solved by extra logic in the tcpi driver but I think it would be more elegant if the registration of a port could be free of premature callbacks. E.g. it could be required that the tcpi driver probe called tcpm_tcpc_reset() once it's done initializing or the necessary data could be supplied in the call to tcpm_register_port().
What do you think?

Let me think about it. In theory it should be possible to avoid callbacks into the underlying driver until after the return from the registration code, but that would still be racy if the underlying driver is not ready.

Basic problem seems to be that an API in general assumes that the caller is ready to serve it once it registers itself. It is kind of unusual to have two calls, one to register the driver and one to tell the infrastructure that it is ready (which I assume your reset call would do). Ultimately this means that the tcpm driver would have to have additional logic to identify if the underlying driver is ready to handle callbacks.

Quoted 3 lines

Can you delay tcpm registration until after the underlying driver is ready, ie typically to the end of its probe function ? Or am I misunderstanding your problem ?

The problem I had was that I was trying to pull the same trick that you do ;) I.e. the probe function calls tcpm_register_port() that is calling back to the driver that was trying to call back to tcpm, just that the call to tcpm_register_port() has not yet returned so the pointer to tcpm_port in the driver data structure was still null.

Quoted 8 lines

I was able to fix the issue by commenting out the call to tcpm_init() at the end of tcpm_register_port() and instead call ("your") tcpm_tcpc_reset(), that currently does nothing but calling tcpm_init(), after I'm done.

Even though I'm not overly excited about the tcpm register function calling back to the driver I don't think my fix is much better. I should live by my own words and refrain from calling back to tcpm until registration has finished...

Problem is that I can't even defer the call to tcpm_init(), or for that matter any other call into the low level driver code, into the worker, since there is still no guarantee that the low level driver is "done" with its initialization. The only real solution I can think of is that the low level driver should not use the pointer to tcpm_port in any of its callback functions.

Overall I think there is an assumption in any API that any callback functions provided in a registration call can immediately be called. Otherwise any API would be in trouble. Can you modify your code to not require the port pointer in its callback functions ?

Thanks,
Guenter

#19 lore raw

Re: USB Type-C Port Manager API concern

Quoted 1 line · Guenter Roeck

... Overall I think there is an assumption in any API that any callback functions provided in a registration call can immediately be called. Otherwise any API would be in trouble. Can you modify your code to not require the port pointer in its callback functions ?

Yes, I have deferred my calls until after the registration function has returned which seems only logical. Thanks, Mats

author maintainer
#20 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Mats Karrman
Quoted 5 lines · Mats Karrman
Quoted 5 lines
Quoted 2 lines

So, both the DP controller and the USB PD phy are I2C devices, and now I have to make them both attach to the AM bus as well?

The DP controller would provide the driver and the USB PD phy (actually, the typec class) the device.

Quoted 7 lines
Quoted 3 lines

Would it be a problem to register these I2C devices with some other subsystem, was it extcon or something like AM bus? It really would not be that uncommon. Or have I misunderstood your question?

OK, so a bus could be used for drivers to find each other but it still does not say anything about how those drivers are supposed to communicate so that must be prescribed separately, right?

Yes.

Quoted 4 lines

If I read Heikki's original suggestion I understand it like the DP driver would be responsible for AM specific USB PD/VDM communication. But wouldn't that lead to a lot of code duplication since the AM protocol is the same for all drivers of a kind?

No that's not what I mean. I'm still mixing your PD controller with something else above, sorry about that. Your PD controller driver should not ideally even need to be aware of Type-C connector, right? It definitely does not need to do any USB PD communication.

I would imagine you have on top of the DP controller, a mux (which could be a DP/USB3 PHY like on Rockchip RK3399, discrete mux like Pericom PI3USB30532, or something else), and a USB Type-C PHY or USB PD controller. The bus would be tying the mux to the Type-C port (PHY or PD controller) and its partner (note that it does not tie the mux to the DP controller). Please correct me if I'm wrong about your hardware.

Assuming that is how your board roughly looks like, the driver for the mux would be the driver for the DP altmode devices. That driver would be the one converting things like the Attention messages notifying about HPD into toggling of GPIOs, or what ever is needed on your board, etc.

The actual PD communication with VDMs should be considered as just the protocol, so we probable should have "protocol drivers". For example DP alternate mode VDMs and communication will always be the same despite of the hardware. The DP alternate mode "protocol driver" would then be tied to the alternate mode device for the partner, and that driver could have its own hooks for what ever is needed, like HPD signal handling, configuration changes, whatever. In any case, hopefully making things easy and straightforward for the "mux driver", _so that it does not need to care about the actual PD communication_.

Thanks,

Signature · 1 line
heikki
#21 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 9 lines · Heikki Krogerus
Quoted 4 lines · Mats Karrman

If I read Heikki's original suggestion I understand it like the DP driver would be responsible for AM specific USB PD/VDM communication. But wouldn't that lead to a lot of code duplication since the AM protocol is the same for all drivers of a kind?

No that's not what I mean. I'm still mixing your PD controller with something else above, sorry about that. Your PD controller driver should not ideally even need to be aware of Type-C connector, right? It definitely does not need to do any USB PD communication.

Right.

Quoted 7 lines

I would imagine you have on top of the DP controller, a mux (which could be a DP/USB3 PHY like on Rockchip RK3399, discrete mux like Pericom PI3USB30532, or something else), and a USB Type-C PHY or USB PD controller. The bus would be tying the mux to the Type-C port (PHY or PD controller) and its partner (note that it does not tie the mux to the DP controller). Please correct me if I'm wrong about your hardware.

No, you're correct, a discrete mux and a fusb302.

Quoted 5 lines

Assuming that is how your board roughly looks like, the driver for the mux would be the driver for the DP altmode devices. That driver would be the one converting things like the Attention messages notifying about HPD into toggling of GPIOs, or what ever is needed on your board, etc.

OK.

Quoted 9 lines

The actual PD communication with VDMs should be considered as just the protocol, so we probable should have "protocol drivers". For example DP alternate mode VDMs and communication will always be the same despite of the hardware. The DP alternate mode "protocol driver" would then be tied to the alternate mode device for the partner, and that driver could have its own hooks for what ever is needed, like HPD signal handling, configuration changes, whatever. In any case, hopefully making things easy and straightforward for the "mux driver", _so that it does not need to care about the actual PD communication_.

I'm digesting your and Guenter's replies and patches.
I will try getting something up and running too soon and hopefully the foggy parts will dissolve. As for now I find it a lot easier to grok Guenter's drivers than to see the advantages and/or disadvantages of an altmode bus :-)

@Guenter: There _is_ interest for your fusb302 driver, thank you

BR // Mats

#22 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 42 lines · Mats Karrman
Quoted 9 lines · Heikki Krogerus
Quoted 4 lines · Mats Karrman

If I read Heikki's original suggestion I understand it like the DP driver would be responsible for AM specific USB PD/VDM communication. But wouldn't that lead to a lot of code duplication since the AM protocol is the same for all drivers of a kind?

No that's not what I mean. I'm still mixing your PD controller with something else above, sorry about that. Your PD controller driver should not ideally even need to be aware of Type-C connector, right? It definitely does not need to do any USB PD communication.

Right.

Quoted 7 lines

I would imagine you have on top of the DP controller, a mux (which could be a DP/USB3 PHY like on Rockchip RK3399, discrete mux like Pericom PI3USB30532, or something else), and a USB Type-C PHY or USB PD controller. The bus would be tying the mux to the Type-C port (PHY or PD controller) and its partner (note that it does not tie the mux to the DP controller). Please correct me if I'm wrong about your hardware.

No, you're correct, a discrete mux and a fusb302.

Quoted 5 lines

Assuming that is how your board roughly looks like, the driver for the mux would be the driver for the DP altmode devices. That driver would be the one converting things like the Attention messages notifying about HPD into toggling of GPIOs, or what ever is needed on your board, etc.

OK.

Quoted 9 lines

The actual PD communication with VDMs should be considered as just the protocol, so we probable should have "protocol drivers". For example DP alternate mode VDMs and communication will always be the same despite of the hardware. The DP alternate mode "protocol driver" would then be tied to the alternate mode device for the partner, and that driver could have its own hooks for what ever is needed, like HPD signal handling, configuration changes, whatever. In any case, hopefully making things easy and straightforward for the "mux driver", _so that it does not need to care about the actual PD communication_.

Quoted 7 lines

I'm digesting your and Guenter's replies and patches.
I will try getting something up and running too soon and hopefully the foggy parts will dissolve. As for now I find it a lot easier to grok Guenter's drivers than to see the advantages and/or disadvantages of an altmode bus :-)

@Guenter: There _is_ interest for your fusb302 driver, thank you

Ok, I'll see what I need to do to publish it.

Guenter

#23 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Hi Heikki,

I have a question regarding the preferred_role node.

+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.

+
+ Valid values: source, sink, none (to remove preference)

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)
2. Wait till the subsequent connect for resolving port roles based on the new state machine.

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

Thanks !!

Quoted 72 lines · Guenter Roeck
Quoted 52 lines · Mats Karrman
Quoted 10 lines · Heikki Krogerus
Quoted 8 lines · Mats Karrman

If I read Heikki's original suggestion I understand it like the DP driver would be
responsible for AM specific USB PD/VDM communication. But wouldn't that lead
to a lot of code duplication since the AM protocol is the same for all drivers of
a kind?

Quoted 4 lines

No that's not what I mean. I'm still mixing your PD controller with something else above, sorry about that. Your PD controller driver should not ideally even need to be aware of Type-C connector, right? It definitely does not need to do any USB PD communication.

Right.

Quoted 7 lines

I would imagine you have on top of the DP controller, a mux (which could be a DP/USB3 PHY like on Rockchip RK3399, discrete mux like Pericom PI3USB30532, or something else), and a USB Type-C PHY or USB PD controller. The bus would be tying the mux to the Type-C port (PHY or PD controller) and its partner (note that it does not tie the mux to the DP controller). Please correct me if I'm wrong about your hardware.

No, you're correct, a discrete mux and a fusb302.

Quoted 5 lines

Assuming that is how your board roughly looks like, the driver for the mux would be the driver for the DP altmode devices. That driver would be the one converting things like the Attention messages notifying about HPD into toggling of GPIOs, or what ever is needed on your board, etc.

OK.

Quoted 9 lines

The actual PD communication with VDMs should be considered as just the protocol, so we probable should have "protocol drivers". For example DP alternate mode VDMs and communication will always be the same despite of the hardware. The DP alternate mode "protocol driver" would then be tied to the alternate mode device for the partner, and that driver could have its own hooks for what ever is needed, like HPD signal handling, configuration changes, whatever. In any case, hopefully making things easy and straightforward for the "mux driver", _so that it does not need to care about the actual PD communication_.

Quoted 9 lines

I'm digesting your and Guenter's replies and patches.
I will try getting something up and running too soon and hopefully the foggy parts will
dissolve. As for now I find it a lot easier to grok Guenter's drivers than to see the
advantages and/or disadvantages of an altmode bus :-)

@Guenter: There _is_ interest for your fusb302 driver, thank you

Ok, I'll see what I need to do to publish it.

Guenter

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#24 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

The attribute will "enable" Try.SRC/SNK states, i.e. next time the state machine is executed, those states need to be considered. Changing the value of this attribute must not affect the current connection.

Quoted 2 lines

2. Wait till the subsequent connect for resolving port roles based on the new state machine.

Yes.

Quoted 10 lines

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Quoted 3 lines

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

I don't think we should even consider option #1, but just to be sure, Oliver, what do you say?

I guess we need to say in the documentation explicitly that changing the value will not affect the current connection.

Thanks,

Signature · 1 line
heikki
#25 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

Quoted 21 lines

The attribute will "enable" Try.SRC/SNK states, i.e. next time the state machine is executed, those states need to be considered. Changing the value of this attribute must not affect the current connection.

Quoted 2 lines

2. Wait till the subsequent connect for resolving port roles based on the new state machine.

Yes.

Quoted 10 lines

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Quoted 6 lines
Quoted 3 lines

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

I don't think we should even consider option #1, but just to be sure, Oliver, what do you say?

Can we at least consider exposing a port_reset field so that the userspace at least has an option to make the state machine to kick in right away with a hard reset ?

Please do consider. We can't expect all low-end phones and devices with smaller form factors then phones to implement PD as it might be an overkill for them.

Quoted 9 lines

I guess we need to say in the documentation explicitly that changing the value will not affect the current connection.

Thanks,

--
heikki

#26 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports. Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

	if (!port->pd_capable && connected && current role != desired role) {
		reset_port();
		goto done;
	}

My current code doesn't handle the !pd_capable state, so I'll need to do something anyway.

Thanks,
Guenter

Quoted 45 lines
Quoted 21 lines

The attribute will "enable" Try.SRC/SNK states, i.e. next time the state machine is executed, those states need to be considered. Changing the value of this attribute must not affect the current connection.

Quoted 2 lines

2. Wait till the subsequent connect for resolving port roles based on the new state machine.

Yes.

Quoted 10 lines

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Quoted 6 lines
Quoted 3 lines

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

I don't think we should even consider option #1, but just to be sure, Oliver, what do you say?

Can we at least consider exposing a port_reset field so that the userspace at least has an option to make the state machine to kick in right away with a hard reset ?

Please do consider. We can't expect all low-end phones and devices with smaller form factors then phones to implement PD as it might be an overkill for them.

Quoted 9 lines

I guess we need to say in the documentation explicitly that changing the value will not affect the current connection.

Thanks,

--
heikki

#27 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

Thanks,
Badhri

Quoted 52 lines

My current code doesn't handle the !pd_capable state, so I'll need to do something anyway.

Thanks,
Guenter

Quoted 45 lines
Quoted 21 lines

The attribute will "enable" Try.SRC/SNK states, i.e. next time the state machine is executed, those states need to be considered. Changing the value of this attribute must not affect the current connection.

Quoted 2 lines

2. Wait till the subsequent connect for resolving port roles based on the new state machine.

Yes.

Quoted 10 lines

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Quoted 6 lines
Quoted 3 lines

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

I don't think we should even consider option #1, but just to be sure, Oliver, what do you say?

Can we at least consider exposing a port_reset field so that the userspace at least has an option to make the state machine to kick in right away with a hard reset ?

Please do consider. We can't expect all low-end phones and devices with smaller form factors then phones to implement PD as it might be an overkill for them.

Quoted 9 lines

I guess we need to say in the documentation explicitly that changing the value will not affect the current connection.

Thanks,

--
heikki

#28 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 53 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

Quoted 9 lines
        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

At least in the current implementation of tcpm, the port type is reported from low level drivers and does not change if the partner is not PD capable. Port capabilities don't change if the partner is not PD capable, and both are reported separately to the typec infrastructure.

Quoted 6 lines
Quoted 6 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

Quoted 7 lines
Quoted 4 lines
        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }

By "desired role" you are referring to preferred_role right ?

That is what it would boil down to, but that is really up to user space to decide. User space would check if the reported role is the desired role, and request a role change if it is not.

Quoted 22 lines

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +12 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Ah yes, you are right. Of course, you could request a data role change, which doesn't have that restriction, at least not right now, but that would not really be clean. Maybe it should be left to the low level driver to do that check, or the check could be augmented to only require pwr_opmode == TYPEC_PWR_MODE_PD if a preferred role is not set.

Thanks,
Guenter

Quoted 66 lines

+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;

(quoted diff) +7 -0
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

Thanks,
Badhri

Quoted 52 lines

My current code doesn't handle the !pd_capable state, so I'll need to do something anyway.

Thanks,
Guenter

Quoted 45 lines
Quoted 21 lines

The attribute will "enable" Try.SRC/SNK states, i.e. next time the state machine is executed, those states need to be considered. Changing the value of this attribute must not affect the current connection.

Quoted 2 lines

2. Wait till the subsequent connect for resolving port roles based on the new state machine.

Yes.

Quoted 10 lines

For #1 to happen the policy_engine layer would have to reset the port to resolve the port roles based on the (Try.SRC /Try.SNK/ Default) new state machine preference.

Say for example when two non-PD devices following none (default state machine) are connected, the port role resolution is going to be random. But, if the userspace in one of the devices later changes the preferred_role to source, then that device is most likely to become source if the Try.SRC state-machine is re-run.

Quoted 6 lines
Quoted 3 lines

Does the above question fall under a policy decision ? If so, should there be another node to say if the port roles have to re-resolved based on the new state machine right away ?

I don't think we should even consider option #1, but just to be sure, Oliver, what do you say?

Can we at least consider exposing a port_reset field so that the userspace at least has an option to make the state machine to kick in right away with a hard reset ?

Please do consider. We can't expect all low-end phones and devices with smaller form factors then phones to implement PD as it might be an overkill for them.

Quoted 9 lines

I guess we need to say in the documentation explicitly that changing the value will not affect the current connection.

Thanks,

--
heikki

author maintainer
#29 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Badhri Jagan Sridharan
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Thanks,

Signature · 1 line
heikki
#30 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 132 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Thanks,

--
heikki

author maintainer
#31 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Hi,

Quoted 9 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 7 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Please send a patch for the class at least. I think the changes to the tcpm can just be amended still at this point. That is of course up to Guenter.

Thanks,

Signature · 1 line
heikki
#32 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 15 lines · Heikki Krogerus

Hi,

Quoted 12 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

Quoted 9 lines
Quoted 4 lines

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Please send a patch for the class at least. I think the changes to the tcpm can just be amended still at this point. That is of course up to Guenter.

I'll try to make the changes and post a new version today.

Guenter

#33 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Badhri Jagan Sridharan
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 150 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 128 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Quoted 4 lines

Thanks,

--
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#34 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 11 lines · Rajaram R
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request is to set the role to match the preferred role, I think it is reasonable to expect that re-establishing the connection would accomplish that if the partner supports it.

Of course, that won't change anything if the partner does not support the desired role, but it is better than doing nothing. This is also comparable to requesting a role change from the partner if it does support PD.

Do you have a better idea ?

Thanks,
Guenter

Quoted 5 lines
Quoted 5 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

... if the partner is not PD capable.

Quoted 146 lines
Quoted 146 lines

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 128 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Quoted 4 lines

Thanks,

--
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#35 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 19 lines · Guenter Roeck
Quoted 11 lines · Rajaram R
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 6 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request is to set the role to match the preferred role, I think it is reasonable to expect that re-establishing the connection would accomplish that if the partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.
So we need to understand what non PD device will fit into this scenario ?

Quoted 3 lines

Of course, that won't change anything if the partner does not support the desired role, but it is better than doing nothing. This is also comparable to requesting a role change from the partner if it does support PD.

All I am highlighting is that we can only TRY and there is no guaranteed role swap with Type-C

Quoted 2 lines

Do you have a better idea ?

If need a guaranteed role in a non-PD mode we need to set the required role in supported_power_roles.
An understanding of scenario will help take better approach.

Quoted 157 lines

Thanks,
Guenter

Quoted 5 lines
Quoted 5 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

... if the partner is not PD capable.

Quoted 146 lines
Quoted 146 lines

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 128 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Quoted 4 lines

Thanks,

--
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#36 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 31 lines · Rajaram R
Quoted 19 lines · Guenter Roeck
Quoted 11 lines · Rajaram R
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 6 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request is to set the role to match the preferred role, I think it is reasonable to expect that re-establishing the connection would accomplish that if the partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 8 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Quoted 1 line

So we need to understand what non PD device will fit into this scenario ?

Answered above.

Quoted 5 lines
Quoted 4 lines

Of course, that won't change anything if the partner does not support the desired role, but it is better than doing nothing. This is also comparable to requesting a role change from the partner if it does support PD.

Quoted 8 lines

All I am highlighting is that we can only TRY and there is no guaranteed role swap with Type-C

Quoted 2 lines

Do you have a better idea ?

If need a guaranteed role in a non-PD mode we need to set the required role in supported_power_roles.
An understanding of scenario will help take better approach.

The current Type-c connector class interface defines the support_*_roles as read-only nodes. Leaving that apart, I think what you are trying to say is that instead of running through the state machine again by switching to Try.SRC or Try.SNK, you are suggesting that switch from DRP to source/host (or) sink/device to make sure that CC is either pulled up through Rp or grounded through Rd so that it increases the chances of settling in the desired role. I do agree this, but, there is a pitfall here. Say when a DRP is connected to
a pure sink/device, when the DRP switches to being a pure sink as well, then the port roles would not resolve at all as both would be asserting Rd on CC and therefore it might not be possible to detect a disconnect unless we have a VCONN powered cable. Following Try.SRC, Try.SNK state machine actually takes care of this for you. When in Try.SRC or Try.SNK state, CC would either be pulled up or down for a specific amount of time (tCCDebounce) to check if the port partner is capable of switching to another role. If no port resolution happens
within the timer expiry, the state machine forces the port into the other role and
port resolution would eventually happen. IMHO So in short it is more safer to switch to between Try.SRC and Try.SNK state machine to land in a preferred role rather than switching a DRP to source or sink.

Quoted 158 lines
Quoted 158 lines

Thanks,
Guenter

Quoted 5 lines
Quoted 5 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

... if the partner is not PD capable.

Quoted 146 lines
Quoted 146 lines

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 128 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Quoted 4 lines

Thanks,

--
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#37 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 48 lines · Badhri Jagan Sridharan
Quoted 31 lines · Rajaram R
Quoted 19 lines · Guenter Roeck
Quoted 11 lines · Rajaram R
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 6 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request is to set the role to match the preferred role, I think it is reasonable to expect that re-establishing the connection would accomplish that if the partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 3 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

Quoted 8 lines
Quoted 5 lines

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Agree and as indicated it increases only chances.

Quoted 18 lines
Quoted 2 lines

So we need to understand what non PD device will fit into this scenario ?

Answered above.

Quoted 5 lines
Quoted 4 lines

Of course, that won't change anything if the partner does not support the desired role, but it is better than doing nothing. This is also comparable to requesting a role change from the partner if it does support PD.

Quoted 8 lines

All I am highlighting is that we can only TRY and there is no guaranteed role swap with Type-C

Quoted 2 lines

Do you have a better idea ?

If need a guaranteed role in a non-PD mode we need to set the required role in supported_power_roles.
An understanding of scenario will help take better approach.

Quoted 10 lines

The current Type-c connector class interface defines the support_*_roles as read-only nodes. Leaving that apart, I think what you are trying to say is that instead of running through the state machine again by switching to Try.SRC or Try.SNK, you are suggesting that switch from DRP to source/host (or) sink/device to make sure that CC is either pulled up through Rp or grounded through Rd so that it increases the chances of settling in the desired role. I do agree this, but, there is a pitfall here. Say when a DRP is connected to
a pure sink/device, when the DRP switches to being a pure sink as well, then the port roles would not resolve at all as both would be asserting Rd on CC and

If it is a pure SNK(presenting Rd), there is no conflict and a DRP be it TRY SRC or TRY SNK
will endup as SRC.

Quoted 2 lines

therefore it might not be possible to detect a disconnect unless we have a VCONN powered cable. Following Try.SRC, Try.SNK state machine actually

VConn does not play any role in detection.

Quoted 9 lines

takes care of this for you. When in Try.SRC or Try.SNK state, CC would either be pulled up or down for a specific amount of time (tCCDebounce) to check if the port partner is capable of switching to another role. If no port resolution happens
within the timer expiry, the state machine forces the port into the other role and
port resolution would eventually happen. IMHO So in short it is more safer to switch to between Try.SRC and Try.SNK state machine to land in a preferred role rather than switching a DRP to source or sink.

The only scenario i can think of now is when connecting two mobiles back to back. In this case if both devices
uses the same logic of switch to between Try.SRC and Try.SNK you will not get desired result.

I guess the way we choose USB Classes(MTP or PTP or Tethering) could be an approach where user know what he/she need.

Quoted 159 lines
Quoted 159 lines
Quoted 159 lines

Thanks,
Guenter

Quoted 5 lines
Quoted 5 lines

TCPM code will issue hard reset in tcpm_dr_set and tcpm_pr_set if current_role is not same as the preferred_role.

... if the partner is not PD capable.

Quoted 146 lines
Quoted 146 lines

I am going to make changes in my local kernel code base to start making the corresponding changes in userspace.
Should I post-back the local kernel changes or Heikki and Geunter you are planning to upload them ?

Thanks for the support !!
Badhri.

Quoted 128 lines · Heikki Krogerus
Quoted 73 lines · Badhri Jagan Sridharan
Quoted 42 lines · Guenter Roeck
Quoted 41 lines · Badhri Jagan Sridharan
Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 15 lines · Badhri Jagan Sridharan

Hi Heikki,

I have a question regarding the preferred_role node.

(quoted diff) +10 -0
+What:          /sys/class/typec/<port>/preferred_role
+Date:          March 2017
+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. By
+               default the preferred role should come from the platform.
+
+               Valid values: source, sink, none (to remove preference)
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 6 lines
Quoted 3 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

This is correct for the attribute definition, but it is not implemented that way. Writing the attribute is only read-only for non-DRP ports.

i.e. tcpm_dr_set/tcpm_pr_set at tcpm.c would return EINVAL when type is not TYPEC_PORT_DRP, is that what you are referring to ?

        if (port->typec_caps.type != TYPEC_PORT_DRP) {
                ret = -EINVAL;
                goto port_unlock;
        }

I do agree that this is actually correct. I am referring to the case where port is
dual-role-power and dual-role-data but NOT PD capable.

Quoted 10 lines

Given the standard, I would consider that to be intentional; it might make sense to update the description accordingly.

How about implementing a mechanism in the dr_set and pr_set code in tcpm which would handle that situation ? Something along the line of

        if (!port->pd_capable && connected && current role != desired role) {
                reset_port();
                goto done;
        }
Quoted 7 lines

By "desired role" you are referring to preferred_role right ?

If so yes, That's a good idea as well and it might work as long as type-c connector
class allows the call to reach tcpm code :) But the current connector class code does
not allow that because the power_role and data_role nodes are defined that way.

Well, the data_role does not limit the requests from reaching the low level drivers, but..

Quoted 26 lines

port->cap->pd_revision and the port->pwr_opmode check in the below code stub have to removed/refactored to make current_role/data_role writes to reach the tcpm code.

(quoted diff) +22 -0
+static ssize_t power_role_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t size)
+{
+ struct typec_port *port = to_typec_port(dev);
+ int ret = size;
+
+ if (!port->cap->pd_revision) {
+ dev_dbg(dev, "USB Power Delivery not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (!port->cap->pr_set) {
+ dev_dbg(dev, "power role swapping not supported\n");
+ return -EOPNOTSUPP;
+ }
+
+ if (port->pwr_opmode != TYPEC_PWR_MODE_PD) {
+ dev_dbg(dev, "partner unable to swap power role\n");
+ return -EIO;
+ }
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+ ret = sysfs_match_string(typec_roles, buf);
+ if (ret < 0)
+ return ret;
+
+ ret = port->cap->pr_set(port->cap, ret);
+ if (ret)
+ return ret;
+
+ return size;
+}

.. yes. The power_role_store() does indeed need to be refactored. The PD requirement should only be applied to Type-C spec versions < 1.2, or removed completely. I would be happy to leave the checks to the low level drivers.

Quoted 4 lines

Thanks,

--
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#38 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 53 lines · Rajaram R
Quoted 51 lines · Badhri Jagan Sridharan
Quoted 31 lines · Rajaram R
Quoted 19 lines · Guenter Roeck
Quoted 11 lines · Rajaram R
Quoted 8 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 6 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request is to set the role to match the preferred role, I think it is reasonable to expect that re-establishing the connection would accomplish that if the partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 6 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Agree and as indicated it increases only chances.

FWIW, this is pretty much the same as requesting a role change using PD. Based on my experience with various devices, the chance for that to succeed isn't really that high either.

I am not really sure I understand your problem with using Try.{SRC,SNK} to trigger (or attempt to trigger) a role change. Can we take a step back, and can you explain ?

Thanks,
Guenter

#39 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 78 lines · Guenter Roeck
Quoted 70 lines · Rajaram R
Quoted 67 lines · Badhri Jagan Sridharan
Quoted 40 lines · Rajaram R
Quoted 23 lines · Guenter Roeck
Quoted 14 lines · Rajaram R
Quoted 9 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 9 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request
is to set the role to match the preferred role, I think it is reasonable
to expect that re-establishing the connection would accomplish that if the
partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 8 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

Quoted 6 lines
Quoted 2 lines

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Agree and as indicated it increases only chances.

Quoted 7 lines

FWIW, this is pretty much the same as requesting a role change using PD. Based on my experience with various devices, the chance for that to succeed isn't really that high either.

I am not really sure I understand your problem with using Try.{SRC,SNK} to trigger (or attempt to trigger) a role change. Can we take a step back, and can you explain ?

The parameters required for a type-c connection is defined as follows and will have a default value.

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

When two DRP devices are connected and for which we have preferred_role which provides input on the preference, In a DRP mode we have randomness in the mode of connection and hence we require role swap mechanisms. A Type-C only device cannot role swap as this is valid only in PD operation.

# Question was how to choose a particular role in non-PD mode. Only way to have a deterministic role in a non-PD mode is to set expected supported_role of choice rather than DRP.

# As part of the solution suggested, checking of roles and triggering role swaps has to be done by the policy manager(PM) and delinked from Policy Engine. I guess the policy manager is at user space?.

I do not have the complete git repo and may be i could be missing something. If this is in any public git please let me know

Quoted 4 lines

Thanks,
Guenter

#40 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 83 lines · Rajaram R
Quoted 82 lines · Guenter Roeck
Quoted 70 lines · Rajaram R
Quoted 67 lines · Badhri Jagan Sridharan
Quoted 40 lines · Rajaram R
Quoted 23 lines · Guenter Roeck
Quoted 14 lines · Rajaram R
Quoted 9 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 9 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request
is to set the role to match the preferred role, I think it is reasonable
to expect that re-establishing the connection would accomplish that if the
partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 8 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

Quoted 6 lines
Quoted 2 lines

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Agree and as indicated it increases only chances.

FWIW, this is pretty much the same as requesting a role change using PD. Based on my experience with various devices, the chance for that to succeed isn't really that high either.

Quoted 8 lines
Quoted 3 lines

I am not really sure I understand your problem with using Try.{SRC,SNK} to trigger (or attempt to trigger) a role change. Can we take a step back, and can you explain ?

The parameters required for a type-c connection is defined as follows and will have a default value.

/sys/class/typec/<port>/supported_power_roles

I don't see that attribute (it is implied in the power_role attribute). It only existed in an earlier version of the driver.

Also, the attribute (when it existed) listed the roles supported by the port, not an administrative restriction of supported roles.

Quoted 8 lines

/sys/class/typec/<port>/preferred_role

When two DRP devices are connected and for which we have preferred_role which provides input on the preference, In a DRP mode we have randomness in the mode of connection and hence we require role swap mechanisms. A Type-C only device cannot role swap as this is valid only in PD operation.

The same is true for non-PD connections. Also, PD doesn't solve the problem if both ends have the same source/sink preference. The result is still randomness. To resolve that randomness, one of the connection partners would have to give up its preference. That is quite independent of PD support.

Quoted 11 lines

# Question was how to choose a particular role in non-PD mode. Only way to have a deterministic role in a non-PD mode is to set expected supported_role of choice rather than DRP.

# As part of the solution suggested, checking of roles and triggering role swaps has to be done by the policy manager(PM) and delinked from Policy Engine. I guess the policy manager is at user space?.

I do not have the complete git repo and may be i could be missing something. If this is in any public git please let me know

Even if a device does support PD, there is no guarantee that a power role swap is successful. That depends on the policy set by the partner, and for all practical purposes it also depends on the quality and stability of the PD protocol implementation on both ends. As mentioned above, if both ends have the same preferred role, the result is still randomness and requires manual intervention by the user if the "other" role is desired.

It seems to me that we are discussing if we should do as good as we can or if we should only implement what can be guaranteed. I strongly favor the first approach. I also think we should not preclude that approach in the kernel implementation. It should be left to a specific policy manager implementation to decide if a given device should be a DRP or source-only or sink-only, independent of the question if PD is supported on either end of a connection.

If a given implementation wants to restrict available port modes, it can do so by providing acceptable port capabilities (ie DRP or source or sink) when registering the port with the infrastructure.

I think you are suggesting that there should be a means to override port capabilities (more specifically, permitted roles) after port registration. That may be a matter for discussion, but it is a separate issue. Also, I am not sure if it was already discussed. Does anyone remember ?

Thanks,
Guenter

author maintainer
#41 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 142 lines · Guenter Roeck
Quoted 83 lines · Rajaram R
Quoted 82 lines · Guenter Roeck
Quoted 70 lines · Rajaram R
Quoted 67 lines · Badhri Jagan Sridharan
Quoted 40 lines · Rajaram R
Quoted 23 lines · Guenter Roeck
Quoted 14 lines · Rajaram R
Quoted 9 lines · Badhri Jagan Sridharan

Thanks for the responses :)

So seems like we have a plan.

In Type-C connector class the checks for TYPEC_PWR_MODE_PD and pd_revision for both the port and the partner will be removed in power_role_store and the data_role_store and will be delegated to the low level drivers.

Quoted 6 lines

It is important to remember what USB Type-C provide is mechanisms for "TRYing" to become a particular role and not guaranteeing.

With what device combination do you fore see we could get the desired role with this change ?

Quoted 9 lines

If the partner is not PD capable, if a preferred role is specified, if the current cole does not match the preferred role, and if the request
is to set the role to match the preferred role, I think it is reasonable
to expect that re-establishing the connection would accomplish that if the
partner supports it.

In this context I believe we have two different inputs as follows:

/sys/class/typec/<port>/supported_power_roles
/sys/class/typec/<port>/preferred_role

Quoted 6 lines

The need of preferred role is required when DRP is set in supported_power_roles option.
Ideally a battery powered device will TRY to be SNK and a a/c plugged device will TRY to be SRC

We need to understand which non-PD device will set to DRP? In the

Android Phones (actually it could be any phone which has a type-c port) since it can act as usb gadget (when connected to PC) or Usb host when connected to peripherals such as thumb drives, keyboard etc. Phones with smaller form factors might be thermally limited to charge above 15W, therefore supporting PD might be an overkill for them.

Quoted 8 lines

current ecosystem all legacy devices
will sit behind adapters which either present an Rp or Rd.

If it is a power adapter in 5V range can either present Rp or DRP with TRY.SRC and there is no role swap requirement.

If it is a laptop port or similar with non-PD (??) DRP there is no guaranteed role swap in a non-PD mode.

Quoted 6 lines
Quoted 2 lines

This is true, but following a Try.SRC or Try.SNK state machine can increase the chances of landing in the desired role/preferred role.

Agree and as indicated it increases only chances.

FWIW, this is pretty much the same as requesting a role change using PD. Based on my experience with various devices, the chance for that to succeed isn't really that high either.

Quoted 8 lines
Quoted 3 lines

I am not really sure I understand your problem with using Try.{SRC,SNK} to trigger (or attempt to trigger) a role change. Can we take a step back, and can you explain ?

The parameters required for a type-c connection is defined as follows and will have a default value.

/sys/class/typec/<port>/supported_power_roles

I don't see that attribute (it is implied in the power_role attribute). It only existed in an earlier version of the driver.

Also, the attribute (when it existed) listed the roles supported by the port, not an administrative restriction of supported roles.

Quoted 8 lines

/sys/class/typec/<port>/preferred_role

When two DRP devices are connected and for which we have preferred_role which provides input on the preference, In a DRP mode we have randomness in the mode of connection and hence we require role swap mechanisms. A Type-C only device cannot role swap as this is valid only in PD operation.

The same is true for non-PD connections. Also, PD doesn't solve the problem if both ends have the same source/sink preference. The result is still randomness. To resolve that randomness, one of the connection partners would have to give up its preference. That is quite independent of PD support.

Quoted 11 lines

# Question was how to choose a particular role in non-PD mode. Only way to have a deterministic role in a non-PD mode is to set expected supported_role of choice rather than DRP.

# As part of the solution suggested, checking of roles and triggering role swaps has to be done by the policy manager(PM) and delinked from Policy Engine. I guess the policy manager is at user space?.

I do not have the complete git repo and may be i could be missing something. If this is in any public git please let me know

Even if a device does support PD, there is no guarantee that a power role swap is successful. That depends on the policy set by the partner, and for all practical purposes it also depends on the quality and stability of the PD protocol implementation on both ends. As mentioned above, if both ends have the same preferred role, the result is still randomness and requires manual intervention by the user if the "other" role is desired.

It seems to me that we are discussing if we should do as good as we can or if we should only implement what can be guaranteed. I strongly favor the first approach. I also think we should not preclude that approach in the kernel implementation. It should be left to a specific policy manager implementation to decide if a given device should be a DRP or source-only or sink-only, independent of the question if PD is supported on either end of a connection.

Quoted 7 lines

If a given implementation wants to restrict available port modes, it can do so by providing acceptable port capabilities (ie DRP or source or sink) when registering the port with the infrastructure.

I think you are suggesting that there should be a means to override port capabilities (more specifically, permitted roles) after port registration. That may be a matter for discussion, but it is a separate issue.

That is how also I see it.

Quoted 1 line

Also, I am not sure if it was already discussed. Does anyone remember ?

Yes, I did propose an attribute that would allow fixing the role of a port to either sink or source at one point. I don't remember what was the reason I ended up dropping that proposal - I need to go through my archives - but I think it was seen as a feature that, if needed, can be added later by adding a new attribute file for it.

So if that is the functionality you want, please start a new thread and propose the new attribute. At least don't try to modify the behaviour of the existing ones because of it.

Thank you,

Signature · 1 line
heikki
author maintainer
#42 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Badhri Jagan Sridharan

Hi,

Quoted 21 lines · Badhri Jagan Sridharan
Quoted 7 lines
Quoted 5 lines

What is the expected behavior when the userspace changes the preferred_role node when the port is in connected state ?

1. the state machine re-resolves the port roles right away based on the new state machine in place ? (or)

No! There are separate attributes for sending role swap requests.

Right. But, that might not be helpful in cases when PD is not implemented. and Implementing PD is not mandatory according the spec :/

FYI quoting from the Type-C specification release(page 24), role swaps are not limited to devices that only support PD.

"Two independent set of mechanisms are defined to allow a USB Type-C DRP to functionally swap power and data roles. When USB PD is supported, power and data role swapping is performed as a subsequent step following the initial connection process. For non-PD implementations, power/data role swapping can optionally be dealt with as part of the initial connection process."

Quoted 2 lines

But, the current interface definition actually prevents current/data role swaps for non-pd devices.

No it doesn't. When USB PD is not supported, you can still use data_role to swap the role. Of course, the lower level driver may not support any role swapping in that case.

Thanks,

Signature · 1 line
heikki
#43 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Heikki Krogerus
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Have you tested this interface with real dual-role controller/board? What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

Maybe we can enhance Roger's drd framework [1] to fulfill that.

[1] https://lwn.net/Articles/682531/

Signature · 2 lines
Best Regards,
Peter Chen
#44 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

If it helps, my primary test system is a HP Chromebook 13 G1.

Quoted 3 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

I don't really understand "What interface you use when you receive this event". Can you explain ?

Quoted 4 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

That sounds like a kernel event delivered to user space via udev or sysfs notification and returned back into the kernel through a sysfs attribute. Do I understand that correctly ?

Thanks,
Guenter

Quoted 4 lines

Maybe we can enhance Roger's drd framework [1] to fulfill that.

[1] https://lwn.net/Articles/682531/

#45 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 28 lines · Guenter Roeck
Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

Quoted 9 lines

If it helps, my primary test system is a HP Chromebook 13 G1.

Quoted 3 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

I don't really understand "What interface you use when you receive this event". Can you explain ?

I mean "How to trigger kernel USB controller driver do role switch?"

Quoted 8 lines
Quoted 4 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

That sounds like a kernel event delivered to user space via udev or sysfs notification and returned back into the kernel through a sysfs attribute. Do I understand that correctly ?

Yes.

Signature · 2 lines
Best Regards,
Peter Chen
#46 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 35 lines · Peter Chen
Quoted 34 lines · Guenter Roeck
Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

If it helps, my primary test system is a HP Chromebook 13 G1.

Quoted 3 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Quoted 6 lines
Quoted 3 lines

I don't really understand "What interface you use when you receive this event". Can you explain ?

I mean "How to trigger kernel USB controller driver do role switch?"

I think this should be handled by the lower level driver. I am wide open to other ideas, though.

Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

That sounds like a kernel event delivered to user space via udev or sysfs notification and returned back into the kernel through a sysfs attribute. Do I understand that correctly ?

Yes.

That doesn't sound like a good idea to me, and I don't see a technical reason to require it.

Thanks,
Guenter

#47 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 40 lines · Guenter Roeck
Quoted 39 lines · Peter Chen
Quoted 37 lines · Guenter Roeck
Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

If it helps, my primary test system is a HP Chromebook 13 G1.

Quoted 3 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

I don't really understand "What interface you use when you receive this event". Can you explain ?

Quoted 6 lines
Quoted 2 lines

I mean "How to trigger kernel USB controller driver do role switch?"

I think this should be handled by the lower level driver. I am wide open to other ideas, though.

Would you show me how it works at your test system if it is not a private thing?

Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

That sounds like a kernel event delivered to user space via udev or sysfs notification and returned back into the kernel through a sysfs attribute. Do I understand that correctly ?

Quoted 6 lines
Quoted 2 lines

Yes.

That doesn't sound like a good idea to me, and I don't see a technical reason to require it.

I don't like it either, but current kernel has no ability to handle it except you use hardware signal like extcon-gpio or controller id as input pin to SoC handle this event.

Signature · 2 lines
Best Regards,
Peter Chen
author maintainer
#48 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

In reply to Peter Chen

Hi Peter,

Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

Yes. Our boards are mostly USB dual-role capable.

Quoted 6 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Thanks,

Signature · 1 line
heikki
#49 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 36 lines · Heikki Krogerus

Hi Peter,

Quoted 25 lines · Peter Chen
Quoted 11 lines · Heikki Krogerus
drivers/usb/typec/typec.c new file +11 -0
+/* --------------------------------------- */
+/* Driver callbacks to report role updates */
+
+/**
+ * typec_set_data_role - Report data role change
+ * @port: The USB Type-C Port where the role was changed
+ * @role: The new data role
+ *
+ * This routine is used by the port drivers to report data role changes.
+ */
+void typec_set_data_role(struct typec_port *port, enum typec_data_role role)

drivers/usb/typec/typec.c line 1088

Quoted 10 lines
drivers/usb/typec/typec.c new file +10 -0
+{
+	if (port->data_role == role)
+		return;
+
+	port->data_role = role;
+	sysfs_notify(&port->dev.kobj, NULL, "data_role");
+	kobject_uevent(&port->dev.kobj, KOBJ_CHANGE);
+}
+EXPORT_SYMBOL_GPL(typec_set_data_role);
+

Hi Keikki,

Quoted 1 line

Have you tested this interface with real dual-role controller/board?

Yes. Our boards are mostly USB dual-role capable.

Quoted 4 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Quoted 8 lines
Quoted 2 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Would you give me an example how kernel handle this? How type-C event triggers role switch?

Signature · 2 lines
Best Regards,
Peter Chen
author maintainer
#50 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Hi Peter,

Quoted 7 lines · Peter Chen
Quoted 7 lines
Quoted 6 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

Quoted 8 lines
Quoted 5 lines

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Would you give me an example how kernel handle this? How type-C event triggers role switch?

On our boards, the firmware or EC (or ACPI) configures the hardware as needed and also notifies the components using ACPI if needed. It's often not even possible to directly configure the components/hardware for a particular role.

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C class, but there just can not be any dependencies between the two.

Thanks,

Signature · 1 line
heikki
#51 lore raw

RE: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 16 lines · Peter Chen
Quoted 13 lines
Quoted 12 lines
Quoted 6 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Quoted 7 lines
Quoted 2 lines

Would you give me an example how kernel handle this? How type-C event triggers role switch?

On our boards, the firmware or EC (or ACPI) configures the hardware as needed and also notifies the components using ACPI if needed. It's often not even possible to directly configure the components/hardware for a particular role.

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch? If it is correct, there is a notifier between type-C and USB controller driver, how to define this notifier for non-ACPI platform?

Quoted 10 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C class, but there just can not be any dependencies between the two.

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

Peter

author maintainer
#52 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 17 lines · Peter Chen
Quoted 17 lines · Peter Chen
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Quoted 8 lines
Quoted 2 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Would you give me an example how kernel handle this? How type-C event triggers role switch?

Quoted 7 lines
Quoted 4 lines

On our boards, the firmware or EC (or ACPI) configures the hardware as needed and also notifies the components using ACPI if needed. It's often not even possible to directly configure the components/hardware for a particular role.

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch?

No (firmware programs the dual-role hw/registers), but never mind. That could be the case.

Quoted 2 lines

If it is correct, there is a notifier between type-C
and USB controller driver, how to define this notifier for non-ACPI platform?

Once there is a platform with Type-C like that, the problem needs to be solved. However..

Quoted 11 lines
Quoted 10 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C class, but there just can not be any dependencies between the two.

Quoted 4 lines

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

..what ever the solution is, it really can't rely on user space.

Thanks,

Signature · 1 line
heikki
#53 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 46 lines · Heikki Krogerus
Quoted 17 lines · Peter Chen
Quoted 17 lines · Peter Chen
Quoted 15 lines
Quoted 4 lines
Quoted 4 lines

What interface you use when you receive this event to handle dual-role switch? I am wonder if a common dual-role class is needed, then we can have a common user utility.

Quoted 8 lines
Quoted 2 lines

Eg, if "data_role" has changed, the udev can echo "data_role" to /sys/class/usb-dual-role/role

No. If the partner executes successfully for example DR_Swap message, the kernel has to take care everything that is needed for the role to be what ever was negotiated on its own. User space can't be involved with that.

Would you give me an example how kernel handle this? How type-C event triggers role switch?

Quoted 7 lines
Quoted 4 lines

On our boards, the firmware or EC (or ACPI) configures the hardware as needed and also notifies the components using ACPI if needed. It's often not even possible to directly configure the components/hardware for a particular role.

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch?

No (firmware programs the dual-role hw/registers), but never mind. That could be the case.

Quoted 2 lines

If it is correct, there is a notifier between type-C
and USB controller driver, how to define this notifier for non-ACPI platform?

Once there is a platform with Type-C like that, the problem needs to be solved. However..

Quoted 11 lines
Quoted 10 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C class, but there just can not be any dependencies between the two.

Quoted 7 lines
Quoted 4 lines

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

..what ever the solution is, it really can't rely on user space.

... and, at least for our application, using extcon for the necessary notifications works just fine.

Guenter

#54 lore raw

RE: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 30 lines
Quoted 4 lines
Quoted 3 lines

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch?

Quoted 18 lines

No (firmware programs the dual-role hw/registers), but never mind. That could be the case.

Quoted 2 lines

If it is correct, there is a notifier between type-C and USB controller driver, how to define this notifier for non-ACPI platform?

Once there is a platform with Type-C like that, the problem needs to be solved. However..

Quoted 9 lines
Quoted 9 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C

class, but there just can not be any dependencies between the two.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

Quoted 6 lines
Quoted 2 lines

..what ever the solution is, it really can't rely on user space.

... and, at least for our application, using extcon for the necessary notifications works just fine.

I see, that means you have a hardware signal to notify role switch.

Peter

#55 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 30 lines · Peter Chen
Quoted 30 lines
Quoted 4 lines
Quoted 3 lines

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch?

Quoted 18 lines

No (firmware programs the dual-role hw/registers), but never mind. That could be the case.

Quoted 2 lines

If it is correct, there is a notifier between type-C and USB controller driver, how to define this notifier for non-ACPI platform?

Once there is a platform with Type-C like that, the problem needs to be solved. However..

Quoted 9 lines
Quoted 9 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C

class, but there just can not be any dependencies between the two.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

..what ever the solution is, it really can't rely on user space.

... and, at least for our application, using extcon for the necessary notifications works just fine.

I see, that means you have a hardware signal to notify role switch.

In our case the Type-C protocol manager (including alternate mode handling) is implemented in an EC. The EC signals the extcon-cros_ec driver, which in turn signals the phy driver as well as the DP driver. The Type-C class is orthogonal; extcon-cros_ec will also register with the Type-C class code once that is upstream.

As mentioned earlier, using extcon for signaling was the most convenient means for us to pass events around. I am more than open to change it to a bus, if that can be made to work - we'd have to keep in mind though that this code already works without Type-C infrastructure and is for the most part already upstream (the rk3399 code it ties into is upstream, and extcon-cros_ec has been submitted as https://patchwork.kernel.org/patch/9583045/).

As for to how to handle alternate mode if the Type-C protocol manager (TCPM) is implemented in the kernel - I have not yet implemented it yet, but my thinking goes along the line described by Heikki in his last e-mail.

Note that we also have a kernel driver for FUSB302 which ties into my tcpm driver. I'll have to check if that is public yet and if I or someone else can publish it if there is interest.

Guenter

#56 lore raw

Re: [PATCH v17 2/3] usb: USB Type-C connector class

Quoted 47 lines · Guenter Roeck
Quoted 30 lines · Peter Chen
Quoted 30 lines
Quoted 4 lines
Quoted 3 lines

You mean type-C trigger an ACPI event, and this ACPI event can notify related USB controller driver doing role switch?

Quoted 18 lines

No (firmware programs the dual-role hw/registers), but never mind. That could be the case.

Quoted 2 lines

If it is correct, there is a notifier between type-C and USB controller driver, how to define this notifier for non-ACPI platform?

Once there is a platform with Type-C like that, the problem needs to be solved. However..

Quoted 9 lines
Quoted 9 lines

I'm not commenting on Roger's dual role patch series, but I don't really think it should be mixed with Type-C. USB Type-C and USB Power Delivery define their own ways of handling the roles, and they are not limited to the data role only. Things like OTG for example will, and actually can not be supported. With Type-C we will have competing state machines compared to OTG. The dual-role framework may be useful on systems that provide more traditional connectors, which possibly have the ID-pin like micro-AB, and possibly also support OTG. It can also be something that exist in parallel with the Type-C

class, but there just can not be any dependencies between the two.

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

Yes, there are two independent things. But if the kernel doesn't have a notifier between type-C message sender (type-c class) and message receiver (like USB controller driver for role switch or other drivers for alternate mode message), we had to find some ways at userspace.

Quoted 9 lines
Quoted 6 lines
Quoted 2 lines

..what ever the solution is, it really can't rely on user space.

... and, at least for our application, using extcon for the necessary notifications works just fine.

I see, that means you have a hardware signal to notify role switch.

In our case the Type-C protocol manager (including alternate mode handling) is implemented in an EC. The EC signals the extcon-cros_ec driver, which in turn signals the phy driver as well as the DP driver. The Type-C class is orthogonal; extcon-cros_ec will also register with the Type-C class code once that is upstream.

Quoted 7 lines

As mentioned earlier, using extcon for signaling was the most convenient means for us to pass events around. I am more than open to change it to a bus, if that can be made to work - we'd have to keep in mind though that this code already works without Type-C infrastructure and is for the most part already upstream (the rk3399 code it ties into is upstream, and extcon-cros_ec has been submitted as https://patchwork.kernel.org/patch/9583045/).

I am clear your implementation now, thank, Guenter.

Quoted 10 lines

As for to how to handle alternate mode if the Type-C protocol manager (TCPM) is implemented in the kernel - I have not yet implemented it yet, but my thinking goes along the line described by Heikki in his last e-mail.

Note that we also have a kernel driver for FUSB302 which ties into my tcpm driver. I'll have to check if that is public yet and if I or someone else can publish it if there is interest.

Guenter

Signature · 2 lines
Best Regards,
Peter Chen
author maintainer
#57 lore raw

PATCH v17 3/3 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       |  15 ++
 drivers/usb/typec/Makefile      |   1 +
 drivers/usb/typec/typec_wcove.c | 377 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 393 insertions(+)
 create mode 100644 drivers/usb/typec/typec_wcove.c
drivers/usb/typec/Kconfig +15 -0
index 17792f9114c6..dfcfe459b7cf 100644
@@ -4,4 +4,19 @@ menu "USB Power Delivery 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
+	depends on BXT_WC_PMIC_OPREGION
+	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 1012a8bed6d5..b9cb862221af 100644
@@ -1 +1,2 @@
 obj-$(CONFIG_TYPEC)		+= typec.o
+obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
drivers/usb/typec/typec_wcove.c new file +377 -0

377 lines not on this page · raw message

Signature · 1 line
2.11.0
#58 lore raw
In reply to Heikki Krogerus

Hi,

Quoted 78 lines · Heikki Krogerus

The USB Type-C class is meant to provide unified interface to the userspace to present the USB Type-C ports in a system.

Changes since v16:
- Using PTR_ERR_OR_ZERO macro in typec_init().

Changes since v15:
- "stingification" as proposed by Felipe
- Checking ARRAY_SIZE in supported_accessory_modes() as proposed by Guenter

Changes since v14:
- Fixes proposed by Mika
- "identity" directory for all discover identity VDOs instead of "vdo" attribute
- alternate mode device names to just "svid-<svid>"

Changes since v13:
- New API. Everything is registered separately.

Changes since v12:
- Added prefer_role member to typec_capability structure as requested by Guenter

Changes since v11:
- The port drivers are responsible of removing the alternate modes (just like the documentation already said).

Changes since v10:
- Using ATTRIBUTE_GROUPS and DEVICE_ATTR marcos everywhere
- Moved sysfs_match_string to lib/string.c
- Rationalized uevents
- Calling ida_destroy

Changes since v9:
- Minor typec_wcove.c cleanup as proposed by Guenter Roeck. No function affect.

Changes since v8:
- checking sysfs_streq() result correctly in sysfs_strmatch
- fixed accessory check in supported_accessory_mode
- using "none" as the only string that can clear the preferred role

Changes since v7:
- Removed "type" attribute from partners
- Added supports_usb_power_delivery attribute for partner and cable

Changes since v6:
- current_vconn_role attr renamed to vconn_source (no API changes)
- Small documentation improvements proposed by Vincent Palatin

Changes since v5:
- Only updating the roles based on driver notifications
- Added MODULE_ALIAS for the WhiskeyCove module
- Including the patch that creates the actual platform device for the WhiskeyCove Type-C PHY in this series.

Changes since v4:
- Remove the port lock completely

Changes since v3:
- Documentation cleanup as proposed by Roger Quadros
- Setting partner altmodes member to NULL on removal and fixing a warning, as proposed by Guenter Roeck
- Added the following attributes for partners and cables:
* supports_usb_power_delivery
* id_header_vdo
- "id_header_vdo" is visible only when the partner or cable supports USB Power Delivery communication.
- Partner attribute "accessory" is hidden when the partner type is not "Accessory".

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.

Quoted 4 lines

Heikki Krogerus (3):
lib/string: add sysfs_match_string helper
usb: USB Type-C connector class
usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY

Just to clarify one thing here: wherever it says "Reviewed-by: Felipe Balbi..." you could also read "Reviewed-and-Tested-by: Felipe Balbi..." as I have been running these patches for past few months to test code on Intel Joule.

Signature · 1 line
balbi
author maintainer
#59 lore raw
Quoted 4 lines · Felipe Balbi

Just to clarify one thing here: wherever it says "Reviewed-by: Felipe Balbi..." you could also read "Reviewed-and-Tested-by: Felipe Balbi..." as I have been running these patches for past few months to test code on Intel Joule.

OK :-)

Thanks,

Signature · 1 line
heikki
maintainer
#60 lore raw
In reply to Heikki Krogerus
Quoted 5 lines · Heikki Krogerus

The USB Type-C class is meant to provide unified interface to the userspace to present the USB Type-C ports in a system.

Changes since v16:
- Using PTR_ERR_OR_ZERO macro in typec_init().

I'm lost in the long thread here, is this series still ready to be merged in, or is there another version that is being worked on?

thanks,

greg k-h

author maintainer
#61 lore raw
Quoted 9 lines · Greg KH
Quoted 5 lines · Heikki Krogerus

The USB Type-C class is meant to provide unified interface to the userspace to present the USB Type-C ports in a system.

Changes since v16:
- Using PTR_ERR_OR_ZERO macro in typec_init().

I'm lost in the long thread here, is this series still ready to be merged in, or is there another version that is being worked on?

There was one documentation fix proposed Mats. The rest of the thread was not about these patches.

I'll send one more version and fix the documentation.

Thanks,

Signature · 1 line
heikki
#62 lore raw
Quoted 7 lines · Heikki Krogerus
Quoted 2 lines

I'm lost in the long thread here, is this series still ready to be merged in, or is there another version that is being worked on?

There was one documentation fix proposed Mats. The rest of the thread was not about these patches.

I'll send one more version and fix the documentation.

A bit late but...

After reading a bit more I found that there is a miss-match between Documentation/ABI/testing/sysfs-class-typec on one side and the actual code and Documentation/usb/typec.rst on the other side. In the first it looks like all attribute groups are flat under typec/ but in the code and the other document they are instead created in a tree, e.g.:

/sys/class/typec/port0/
/sys/class/typec/port0/svid-ff01/
/sys/class/typec/port0/svid-ff01/mode0/
/sys/class/typec/port0/port0-partner/
/sys/class/typec/port0/port0-cable/
/sys/class/typec/port0/port0-cable/identity/
/sys/class/typec/port0/port0-cable/port0-plug0/
/sys/class/typec/port0/port0-cable/port0-plug1/

BR // Mats

author maintainer
#63 lore raw

Hi Mats,

Quoted 17 lines · Mats Karrman
Quoted 7 lines · Heikki Krogerus
Quoted 2 lines

I'm lost in the long thread here, is this series still ready to be merged in, or is there another version that is being worked on?

There was one documentation fix proposed Mats. The rest of the thread was not about these patches.

I'll send one more version and fix the documentation.

A bit late but...

After reading a bit more I found that there is a miss-match between Documentation/ABI/testing/sysfs-class-typec on one side and the actual code and Documentation/usb/typec.rst on the other side. In the first it looks like all attribute groups are flat under typec/ but in the code and the other document they are instead created in a tree, e.g.:

Quoted 8 lines

/sys/class/typec/port0/
/sys/class/typec/port0/svid-ff01/
/sys/class/typec/port0/svid-ff01/mode0/
/sys/class/typec/port0/port0-partner/
/sys/class/typec/port0/port0-cable/
/sys/class/typec/port0/port0-cable/identity/
/sys/class/typec/port0/port0-cable/port0-plug0/
/sys/class/typec/port0/port0-cable/port0-plug1/

Documentation/ABI/testing/sysfs-class-typec describes the attributes from the classes point of view.

Documentation/usb/typec.rst tries to explain the actual hierarchy of the devices that the current typec class driver generates, however the "class" does not care about that. Every device will simply have a link added to the class directory (/sys/class/typec/ in our case) regardless of their parent. For example, port0 and its partners:

/sys/class/typec/port0 -> ../../devices/<path>/<to>/<your>/<device>/typec/port0
/sys/class/typec/port0-partner -> ../../devices/<path>/<to>/<your>/<device>/typec/port0/port0-partner
/sys/class/typec/port0-cable -> ../../devices/<path>/<to>/<your>/<device>/typec/port0/port0-cable
/sys/class/typec/port0-plug0 -> ../../devices/<path>/<to>/<your>/<device>/typec/port0/port0-cable/port0-plug0
/sys/class/typec/port0-plug1 -> ../../devices/<path>/<to>/<your>/<device>/typec/port0/port0-cable/port0-plug1

Thanks,

Signature · 1 line
heikki