USB Type-C Port Manager
Subsystems (2)
v4 cover USB 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 two patches in the series. The first patch implements the Type-C Port Manager state machine. The second 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 2/2 (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 not 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.
TODO:
- Separation of PD, VDM, and TCPM code
- Full alternate mode support
v4:
- tcpm: Source and sink capabilities can now change on the fly
- tcpm: Introduced several new macros to identify CC states
- tcpm: Determine RP value to set based on maximum current supported by a port configured as source
- tcpm: Support for DRP toggling implemented in hardware (by Type-C port controller)
- tcpm: Added MODULE_ macros
- tcpci: Fix RP value set for ports supporting 3A current
- tcpci: Implement support for DRP toggling in hardware
- tcpci: When setting VBUS, disable both source and sink before enabling anything
- tcpci: Set correct byte count in tcpci_pd_transmit()
- tcpci: Disable chip interrupts before registering interrupt handler
- tcpci: Request IRQF_ONESHOT | IRQF_TRIGGER_LOW instead of IRQF_TRIGGER_FALLING
- Applies on top of v10 of "USB Type-C Connector class" patch series.
v3:
- Improve TCPM state machine resiliency if there are spurious CC line changes while the state machine is in a transient change (waiting for a timeout)
- Update current limit after CC voltage level changes on a port which is not PD capable.
- Applies on top of v6 of "USB Type-C Connector class" patch series.
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 on top of v5 of "USB Type-C Connector class" patch series.
RFC v4 1/2 usb: typec: USB Type-C Port Manager (tcpm)
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.
---
v4:
- Source and sink capabilities can now change on the fly
- Introduced several new macros to identify CC states
- Determine RP value to set based on maximum current supported
by a port configured as source
- Support for DRP toggling implemented in hardware (by Type-C port controller)
- Added MODULE_ macros
v3:
- Improve TCPM state machine resiliency if there are spurious CC line changes while the state machine is in a transient change (waiting for a timeout)
- Update current limit after CC voltage level changes on a port which is not PD capable.
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 | 3335 ++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tcpm.h | 148 ++ include/linux/usb/pd.h | 281 ++++ include/linux/usb/pd_bdo.h | 31 + include/linux/usb/pd_vdo.h | 412 ++++++ 7 files changed, 4215 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
@@ -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
@@ -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 +3335 -0
2,986 lines not on this page · raw message
drivers/usb/typec/tcpm.h new file +148 -0
148 lines not on this page · raw message
include/linux/usb/pd.h new file +281 -0
281 lines not on this page · raw message
include/linux/usb/pd_vdo.h new file +412 -0
412 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.
RFC v4 2/2 usb: typec: Type-C Port Controller Interface driver (tcpci)
In reply to Guenter RoeckThe port controller interface driver interconnects the Type-C Port Manager with a Type-C Port Controller Interface (TCPCI) compliant port controller.
---
v4:
- Fix RP value set for ports supporting 3A current
- Implement support for DRP toggling in hardware
- When setting VBUS, disable both source and sink before enabling anything
- Set correct byte count in tcpci_pd_transmit()
- Disable chip interrupts before registering interrupt handler
- Request IRQF_ONESHOT | IRQF_TRIGGER_LOW instead of IRQF_TRIGGER_FALLING v3:
- No change
v2:
- Adjust to modified callbacks into tcpm code
drivers/usb/typec/Kconfig | 9 + drivers/usb/typec/Kconfig | 9 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/tcpci.c | 529 +++++++++++++++++++++++++++++++++++++++++++++ drivers/usb/typec/tcpci.h | 133 ++++++++++++ 4 files changed, 672 insertions(+) create mode 100644 drivers/usb/typec/tcpci.c create mode 100644 drivers/usb/typec/tcpci.h
drivers/usb/typec/Kconfig +9 -0
@@ -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
@@ -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 +529 -0
529 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