Skip to contentSkip to conversation

Type-C Port Manager

RFC PATCH Superseded Guenter Roeck 3 participants 7 messages Aug 17, 2016 – Aug 18, 2016

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Type-C Port Manager

The following series of patches implements a USB Type-C Port Manager using the pending USB Type-C class code as basis. The code is still WIP, but I think it is important to get feedback from the community at this point.

There are four patches in the series. The first two patches make necessary changes to the Type-C class code. The third patch implements the Type-C Port Manager state machine. The forth patch is an interface between the Type-C Port Manager and a TCPCI (Type-C Port Controller Interface) compliant USB Type-C Port Controller.

Patch 4/4 (the interface to a TCPCI compliant chip) is currently untested since I don't have the necessary hardware available. The port manager code was tested connecting to an Embedded Controller on a Chromebook, bypassing the Port Manager implementation in the EC.

Both Source and Sink operation was tested with various Type-C chargers, docks, and connectors. Alternate mode support is partially implemented (Alternate mode support is requested from the partner), but alternate modes are actually selected. Implementing this will require more thought, since the actual alternate mode support has to be implemented elsewhere, such as in a dedicated Phy driver. It should be possible to implement the interface between phy driver and Type-C Port Controller driver using extcon, but I have not further explored the possibilities, and other options might be possible and/or better.

v2:
- Class code no longer uses locking, so the patch to remove it is no longer necessary.
- tcpm: Only update polarity if setting it was successful
If setting the CC line polarity in the driver was not successful, don't update the internal polarity state.
- tcpm: All PD messages are little endian; convert to and from CPU endianness.
- tcpm: Avoid comparisons against NULL.
- tcpm: Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
- tcpm/tcpc: Callbacks into tcpm need to be lockless to avoid timing problems in low level drivers.
- tcpm/tcpc: Simplify callbacks; tcpm can request the current state of cc/vbus when it is ready to use it.
- Applies to v5 of "USB Type-C Connector class" patch series.

#1 lore raw

RFC PATCH v2 1/4 usb: typec: Do not check if connected when setting roles

The connection status can change after the connection status was checked. Leave it up to the driver to perform the necessary checks.

---
v2: Rebased to v5 of Type-C class code

 drivers/usb/typec/typec.c | 6 ------
 1 file changed, 6 deletions(-)
drivers/usb/typec/typec.c +0 -6
index 52a0431253a8..fa0261dad3b7 100644
@@ -785,9 +785,6 @@ current_data_role_store(struct device *dev, struct device_attribute *attr,
 		return -EOPNOTSUPP;
 	}
 
-	if (!port->connected)
-		return size;
-
 	ret = sysfs_strmatch(typec_data_roles, ARRAY_SIZE(typec_data_roles),
 			     buf);
 	if (ret < 0)
@@ -851,9 +848,6 @@ static ssize_t current_power_role_store(struct device *dev,
 		return -EIO;
 	}
 
-	if (!port->connected)
-		return size;
-
 	ret = sysfs_strmatch(typec_roles, ARRAY_SIZE(typec_roles), buf);
 	if (ret < 0)
 		return ret;
Signature · 1 line
2.8.0.rc3.226.g39d4020
#2 lore raw

RFC PATCH v2 2/4 usb: typec: Do not update modes in class driver

In reply to Guenter Roeck

Mode updates need to be triggered and reported by underlying drivers. Also add missing "if (ret)".

---
v2: Added fixup patch

 drivers/usb/typec/typec.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/usb/typec/typec.c +1 -10
index fa0261dad3b7..58de982ac927 100644
@@ -533,7 +533,6 @@ typec_altmode_active_store(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		return ret;
 
-	mode->active = activate;
 	return size;
 }
 
@@ -796,9 +795,6 @@ current_data_role_store(struct device *dev, struct device_attribute *attr,
 	if (ret)
 		return ret;
 
-	port->data_role = role;
-	sysfs_notify(&port->dev.kobj, NULL, "current_data_role");
-
 	return size;
 }
 
@@ -857,9 +853,6 @@ static ssize_t current_power_role_store(struct device *dev,
 	ret = port->cap->pr_set(port->cap, role);
 		return ret;
 
-	port->pwr_role = role;
-	sysfs_notify(&port->dev.kobj, NULL, "current_power_role");
-
 	return size;
 }
 
@@ -927,11 +920,9 @@ static ssize_t current_vconn_role_store(struct device *dev,
 	role = ret;
 
 	ret = port->cap->vconn_set(port->cap, role);
+	if (ret < 0)
 		return ret;
 
-	port->pwr_role = role;
-	sysfs_notify(&port->dev.kobj, NULL, "current_vconn_role");
-
 	return size;
 }
 
Signature · 1 line
2.8.0.rc3.226.g39d4020
#3 lore raw

RFC PATCH v2 3/4 usb: typec: USB Type-C Port Manager (tcpm)

In reply to Guenter Roeck

This driver implements the USB Type-C Power Delivery state machine for both source and sink ports. Alternate mode support is not fully implemented.

The driver attaches to the USB Type-C class code implemented in the following patches.

usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
usb: USB Type-C connector class

This driver only implements the state machine. Lower level drivers are responsible for
- Reporting VBUS status and activating VBUS
- Setting CC lines and providing CC line status
- Setting line polarity
- Activating and deactivating VCONN
- Setting the current limit
- Activating and deactivating PD message transfers
- Sending and receiving PD messages

The driver provides both a functional API as well as callbacks for lower level drivers.

---
v2:
- Only update polarity if setting it was successful
If setting the CC line polarity in the driver was not successful, don't update the internal polarity state.
- All PD messages are little endian; convert to and from CPU endianness.
- Avoid comparisons against NULL.
- Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
- Callbacks into tcpm need to be lockless to avoid timing problems in low level drivers.
- Simplify callbacks; tcpm can request the current state of cc/vbus when it is ready to use it.

 drivers/usb/typec/Kconfig  |    7 +
 drivers/usb/typec/Makefile |    1 +
 drivers/usb/typec/tcpm.c   | 3087 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tcpm.h   |  137 ++
 include/linux/usb/pd.h     |  282 ++++
 include/linux/usb/pd_bdo.h |   31 +
 include/linux/usb/pd_vdo.h |  411 ++++++
 7 files changed, 3956 insertions(+)
 create mode 100644 drivers/usb/typec/tcpm.c
 create mode 100644 drivers/usb/typec/tcpm.h
 create mode 100644 include/linux/usb/pd.h
 create mode 100644 include/linux/usb/pd_bdo.h
 create mode 100644 include/linux/usb/pd_vdo.h
drivers/usb/typec/Kconfig +7 -0
index 7a345a4b1e7a..113bb1b3589c 100644
@@ -18,4 +18,11 @@ config TYPEC_WCOVE
 	  To compile this driver as module, choose M here: the module will be
 	  called typec_wcove
 
+config TYPEC_TCPM
+	tristate "USB Type-C Port Controller Manager"
+	select TYPEC
+	help
+	  The Type-C Port Controller Manager provides a USB PD and USB Type-C
+	  state machine for use with Type-C Port Controllers.
+
 endmenu
drivers/usb/typec/Makefile +1 -0
index b9cb862221af..bbe45721cf52 100644
@@ -1,2 +1,3 @@
 obj-$(CONFIG_TYPEC)		+= typec.o
 obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
+obj-$(CONFIG_TYPEC_TCPM)	+= tcpm.o
drivers/usb/typec/tcpm.c new file +3087 -0

2,986 lines not on this page · raw message

drivers/usb/typec/tcpm.h new file +137 -0

137 lines not on this page · raw message

include/linux/usb/pd.h new file +282 -0

282 lines not on this page · raw message

include/linux/usb/pd_bdo.h new file +31 -0
new file mode 100644
index 000000000000..17e9388cf955

Lines of this file are not shown. View the raw message.

include/linux/usb/pd_vdo.h new file +411 -0

411 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.8.0.rc3.226.g39d4020

Part of the diff is not shown here. View the raw message.

#4 lore raw

RFC PATCH v2 4/4 usb: typec: Type-C Port Controller Interface driver (tcpci)

In reply to Guenter Roeck

The port controller interface driver interconnects the Type-C Port Manager with a Type-C Port Controller Interface (TCPCI) compliant port controller.

---
v2:
- Adjust to modified callbacks into tcpm code

 drivers/usb/typec/Kconfig  |   9 +
 drivers/usb/typec/Makefile |   1 +
 drivers/usb/typec/tcpci.c  | 487 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/typec/tcpci.h  | 133 +++++++++++++
 4 files changed, 630 insertions(+)
 create mode 100644 drivers/usb/typec/tcpci.c
 create mode 100644 drivers/usb/typec/tcpci.h
drivers/usb/typec/Kconfig +9 -0
index 113bb1b3589c..a92c9d1a3e00 100644
@@ -25,4 +25,13 @@ config TYPEC_TCPM
 	  The Type-C Port Controller Manager provides a USB PD and USB Type-C
 	  state machine for use with Type-C Port Controllers.
 
+if TYPEC_TCPM
+
+config TYPEC_TCPCI
+	tristate "Type-C Port Controller Interface driver"
+	help
+	  Type-C Port Controller driver for TCPCI-compliant controller.
+
+endif
+
 endmenu
drivers/usb/typec/Makefile +1 -0
index bbe45721cf52..7dbaf8c3911d 100644
@@ -1,3 +1,4 @@
 obj-$(CONFIG_TYPEC)		+= typec.o
 obj-$(CONFIG_TYPEC_WCOVE)	+= typec_wcove.o
 obj-$(CONFIG_TYPEC_TCPM)	+= tcpm.o
+obj-$(CONFIG_TYPEC_TCPCI)	+= tcpci.o
drivers/usb/typec/tcpci.c new file +487 -0

487 lines not on this page · raw message

drivers/usb/typec/tcpci.h new file +133 -0

133 lines not on this page · raw message

Signature · 1 line
2.8.0.rc3.226.g39d4020
#5 lore raw
In reply to Guenter Roeck
Quoted 5 lines · Guenter Roeck

The following series of patches implements a USB Type-C Port Manager using the pending USB Type-C class code as basis. The code is still WIP,
but I think it is important to get feedback from the community at this point.

Hi,

a question on design. What happens if the system wants to suspend while we are in the middle of a power negotiation?

Regards
Oliver

#6 lore raw
Quoted 7 lines · Oliver Neukum
Quoted 5 lines · Guenter Roeck

The following series of patches implements a USB Type-C Port Manager using the pending USB Type-C class code as basis. The code is still WIP,
but I think it is important to get feedback from the community at this point.

Quoted 5 lines

Hi,

a question on design. What happens if the system wants to suspend while we are in the middle of a power negotiation?

Abort power negotiation, I would think, unless you have a better idea.

Thanks,
Guenter