staging: typec: USB Type-C Port Manager (tcpm)
PATCH v7 1/3 staging: typec: USB Type-C Port Manager (tcpm)
From: Guenter Roeck <[email protected]>
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.
---
v7:
- typec_register_port() returns NULL on error
- Adjust subject to indicate that this is a staging driver
- Add dependency on USB (USB_SUPPORT is insufficient; see drivers/Makefile)
- Add dummy tcpm_log_force() if CONFIG_DEBUG_FS is not enabled
v6:
- Move driver and include files to -staging
- Remove unused defines from include files
- Fix compile error seen when building on top of -next (include file change)
- Fix VDO log message
- Various endianness fixes
- Separate PDO logging into separate function
- Replace "SBZ" in include files with "Reserved; Shall be set to zero"
- Fix VDO_AMA macro
- Move pd_mode_data from pd_vdo.h to tcpm.c
- Add TODO file
v5:
- Adjust to infrastructure API changes
- Minor API change to low level driver
[set_pd_header -> set_roles]
- Set default state depending on preferred role
- Improve Try.SRC and Try.SNK implementation
- Do not report stale identity information to infrastructure
- Fix crash seen if a SVD message was received while disconnected
- Improve accessory handling
- If a role change is requested and the partner does not support PD, request a port reset
- Set state to SRC_READY after PD_N_CAPS_COUNT if the partner does not respond to capabilities messages
- Update PD_T_SEND_SOURCE_CAP to improve compatibility with slow partners
- Coding style fixes
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/staging/Kconfig | 2 + drivers/staging/Makefile | 2 +- drivers/staging/typec/Kconfig | 11 + drivers/staging/typec/Makefile | 1 + drivers/staging/typec/TODO | 12 + drivers/staging/typec/pd.h | 281 ++++ drivers/staging/typec/pd_bdo.h | 31 + drivers/staging/typec/pd_vdo.h | 249 +++ drivers/staging/typec/tcpm.c | 3465 ++++++++++++++++++++++++++++++++++++++++ drivers/staging/typec/tcpm.h | 150 ++ 10 files changed, 4203 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/typec/Kconfig create mode 100644 drivers/staging/typec/Makefile create mode 100644 drivers/staging/typec/TODO create mode 100644 drivers/staging/typec/pd.h create mode 100644 drivers/staging/typec/pd_bdo.h create mode 100644 drivers/staging/typec/pd_vdo.h create mode 100644 drivers/staging/typec/tcpm.c create mode 100644 drivers/staging/typec/tcpm.h
drivers/staging/Kconfig +2 -0
@@ -104,4 +104,6 @@ source "drivers/staging/greybus/Kconfig" source "drivers/staging/vc04_services/Kconfig" +source "drivers/staging/typec/Kconfig" + endif # STAGING
drivers/staging/Makefile +1 -1
@@ -41,4 +41,4 @@ obj-$(CONFIG_MOST) += most/ obj-$(CONFIG_KS7010) += ks7010/ obj-$(CONFIG_GREYBUS) += greybus/ obj-$(CONFIG_BCM2835_VCHIQ) += vc04_services/ - +obj-y += typec/
drivers/staging/typec/Kconfig new file +11 -0
@@ -0,0 +1,11 @@ +menu "USB Power Delivery and Type-C drivers" + +config TYPEC_TCPM + tristate "USB Type-C Port Controller Manager" + depends on USB + 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/staging/typec/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TYPEC_TCPM) += tcpm.o
drivers/staging/typec/TODO new file +12 -0
@@ -0,0 +1,12 @@ +tcpm: +- Add documentation (at the very least for the API to low level drivers) +- Split PD code into separate file +- Check if it makes sense to use tracepoints instead of debugfs for debug logs +- Implement Alternate Mode handling +- Address "#if 0" code if not addressed with the above +- Validate all comments marked with "XXX"; either address or remove comments +- Add support for USB PD 3.0. While not mandatory, at least fast role swap + as well as authentication support would be very desirable. + +Please send patches to Guenter Roeck <[email protected]> and copy +Heikki Krogerus <[email protected]>.
drivers/staging/typec/pd.h new file +281 -0
281 lines not on this page · raw message
drivers/staging/typec/pd_bdo.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Copyright 2015-2017 Google, Inc +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef __LINUX_USB_PD_BDO_H +#define __LINUX_USB_PD_BDO_H + +/* BDO : BIST Data Object */ +#define BDO_MODE_RECV (0 << 28) +#define BDO_MODE_TRANSMIT (1 << 28) +#define BDO_MODE_COUNTERS (2 << 28) +#define BDO_MODE_CARRIER0 (3 << 28) +#define BDO_MODE_CARRIER1 (4 << 28) +#define BDO_MODE_CARRIER2 (5 << 28) +#define BDO_MODE_CARRIER3 (6 << 28) +#define BDO_MODE_EYE (7 << 28) +#define BDO_MODE_TESTDATA (8 << 28) + +#define BDO_MODE_MASK (mode) ((mode) & 0xf0000000) + +#endif
drivers/staging/typec/pd_vdo.h new file +249 -0
249 lines not on this page · raw message
drivers/staging/typec/tcpm.c new file +3465 -0
2,404 lines not on this page · raw message
drivers/staging/typec/tcpm.h new file +150 -0
150 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH v7 2/3 staging: typec: Type-C Port Controller Interface driver (tcpci)
From: Guenter Roeck <[email protected]>
The port controller interface driver interconnects the Type-C Port Manager with a Type-C Port Controller Interface (TCPCI) compliant port controller.
---
v7:
- Adjust subject to indicate that this is a staging driver
- Add missing build dependencies
v6:
- Move to drivers/staging
- Use PTR_ERR_OR_ZERO()
v5:
- API changes
[set_pd_header -> set_roles]
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/staging/typec/Kconfig | 11 + drivers/staging/typec/Makefile | 1 + drivers/staging/typec/TODO | 3 + drivers/staging/typec/tcpci.c | 526 +++++++++++++++++++++++++++++++++++++++++ drivers/staging/typec/tcpci.h | 133 +++++++++++ 5 files changed, 674 insertions(+) create mode 100644 drivers/staging/typec/tcpci.c create mode 100644 drivers/staging/typec/tcpci.h
drivers/staging/typec/Kconfig +11 -0
@@ -8,4 +8,15 @@ 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" + depends on I2C + select REGMAP_I2C + help + Type-C Port Controller driver for TCPCI-compliant controller. + +endif + endmenu
drivers/staging/typec/Makefile +1 -0
@@ -1 +1,2 @@ obj-$(CONFIG_TYPEC_TCPM) += tcpm.o +obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o
drivers/staging/typec/TODO +3 -0
@@ -8,5 +8,8 @@ tcpm: - Add support for USB PD 3.0. While not mandatory, at least fast role swap as well as authentication support would be very desirable. +tcpci: +- Test with real hardware + Please send patches to Guenter Roeck <[email protected]> and copy Heikki Krogerus <[email protected]>.
drivers/staging/typec/tcpci.c new file +526 -0
526 lines not on this page · raw message
drivers/staging/typec/tcpci.h new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v7 3/3 staging: typec: Fairchild FUSB302 Type-c chip driver
In reply to Guenter RoeckFrom: Yueyao Zhu <[email protected]>
Fairchild FUSB302 Type-C chip driver that works with Type-C Port Controller Manager to provide USB PD and USB Type-C functionalities.
---
v7: Added patch to series
drivers/staging/typec/Kconfig | 2 + drivers/staging/typec/Makefile | 1 + drivers/staging/typec/fusb302/Kconfig | 7 + drivers/staging/typec/fusb302/Makefile | 1 + drivers/staging/typec/fusb302/TODO | 6 + drivers/staging/typec/fusb302/fusb302.c | 1815 +++++++++++++++++++++++++++ drivers/staging/typec/fusb302/fusb302_reg.h | 186 +++ 7 files changed, 2018 insertions(+) create mode 100644 drivers/staging/typec/fusb302/Kconfig create mode 100644 drivers/staging/typec/fusb302/Makefile create mode 100644 drivers/staging/typec/fusb302/TODO create mode 100644 drivers/staging/typec/fusb302/fusb302.c create mode 100644 drivers/staging/typec/fusb302/fusb302_reg.h
drivers/staging/typec/Kconfig +2 -0
@@ -17,6 +17,8 @@ config TYPEC_TCPCI help Type-C Port Controller driver for TCPCI-compliant controller. +source "drivers/staging/typec/fusb302/Kconfig" + endif endmenu
drivers/staging/typec/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_TYPEC_TCPM) += tcpm.o obj-$(CONFIG_TYPEC_TCPCI) += tcpci.o +obj-y += fusb302/
drivers/staging/typec/fusb302/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +config TYPEC_FUSB302 + tristate "Fairchild FUSB302 Type-C chip driver" + depends on I2C + help + The Fairchild FUSB302 Type-C chip driver that works with + Type-C Port Controller Manager to provide USB PD and USB + Type-C functionalities.
drivers/staging/typec/fusb302/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_TYPEC_FUSB302) += fusb302.o
drivers/staging/typec/fusb302/TODO new file +6 -0
@@ -0,0 +1,6 @@ +fusb302: +- Find a better logging scheme, at least not having the same debugging/logging + code replicated here and in tcpm +- Find a non-hacky way to coordinate between PM and I2C access +- Documentation? The FUSB302 datasheet provides information on the chip to help + understand the code. But it may still be helpful to have a documentation.
drivers/staging/typec/fusb302/fusb302.c new file +1815 -0
1,815 lines not on this page · raw message
drivers/staging/typec/fusb302/fusb302_reg.h new file +186 -0
186 lines not on this page · raw message
Signature · 1 line
2.7.4
Greg Kroah-Hartman
maintainerdrivers/staging/typec/pd.h line 7
Quoted 10 lines · Guenter Roeck
drivers/staging/typec/pd.h new file +7
-0@@ -0,0 +1,281 @@ +/* +* Copyright 2015-2017 Google, Inc +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version.
I have to ask, you really mean "any later version", for all of these patches, right?
thanks,
greg k-h
Quoted 15 lines · Greg Kroah-Hartman
drivers/staging/typec/pd.h line 7
Quoted 10 lines · Guenter Roeck
drivers/staging/typec/pd.h new file +7
-0@@ -0,0 +1,281 @@ +/* +* Copyright 2015-2017 Google, Inc +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. I have to ask, you really mean "any later version", for all of these patches, right?
Quoted 4 lines
thanks,
greg k-h
I have not really thought about it, but this is ok as-is.
Guenter
Greg Kroah-Hartman
maintainerQuoted 16 lines · Guenter Roeck
Quoted 15 lines · Greg Kroah-Hartman
drivers/staging/typec/pd.h line 7
Quoted 10 lines · Guenter Roeck
drivers/staging/typec/pd.h new file +7
-0@@ -0,0 +1,281 @@ +/* +* Copyright 2015-2017 Google, Inc +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. I have to ask, you really mean "any later version", for all of these patches, right?
Quoted 6 lines
Quoted 4 lines
thanks,
greg k-h
I have not really thought about it, but this is ok as-is.
Ok, patches are now applied in my USB tree, as I had to do that so they would build properly due to dependencies there.
thanks,
greg k-h
Quoted 19 lines · Greg Kroah-Hartman
Quoted 18 lines · Guenter Roeck
Quoted 17 lines · Greg Kroah-Hartman
drivers/staging/typec/pd.h line 7
Quoted 10 lines · Guenter Roeck
drivers/staging/typec/pd.h new file +7
-0@@ -0,0 +1,281 @@ +/* +* Copyright 2015-2017 Google, Inc +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. I have to ask, you really mean "any later version", for all of these patches, right?
thanks,
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
greg k-h
I have not really thought about it, but this is ok as-is.
Ok, patches are now applied in my USB tree, as I had to do that so they would build properly due to dependencies there.
Ah yes, sorry, I should have mentioned that.
Thanks!
Guenter