USB Type-C device-connection, mux and switch support
Subsystems (12)
Heikki Krogerus
maintainerv9 cover USB Type-C device-connection, mux and switch support
Hi,
This is version 9 of Hans' an my series introducing support for USB muxes, and generic device connection handling. The last version have been mostly about getting the first patch introducing the device connection handling right.
Check vesion 8 from here:
https://lkml.org/lkml/2018/3/14/428
Here is the original cover-letter of v1:
Some devices with an USB Type-C connector have a bunch of muxes behind that connector which need to be controlled by the kernel (rather then having them controlled by firmware as on most devices).
Quite a while back I submitted a patch-series to tie together these muxes and the Type-C Port Manager (tcpm) code, using the then new drivers/mux framework. But the way I used the mux framework went against what it was designed for, so in the end that series got nowhere.
Heikki Krogerus from Intel, who maintains the USB TYPEC subsystem, has recently been working on solving the same problem for some boards he is doing hardware-enablement for.
Heikki has come up with a number of infrastructure patches for this. The first one is a new device-connection framework. This solves the problem of describing non bus device-links on x86 in what in my experience with this problematic area is a really nice simple, clean and *generic* way. This could for example in the near future also replace the custom lookup code in the pwm subsys and the custom pwm_add_table() / pwm_remove_table() functions.
The other 3 patches add a framework for the different type of Type-C / USB "muxes".
Heikki and I have gone through a number of iterations of these patches together and we believe these are now ready for merging. Since merging infrastructure patches without users is not done and Heikki's own use-case for these is not yet ready for merging, the rest of this series consists of patches by me to make the Type-C connector found on some Cherry Trail devices (finally) be able to actually work as an USB port and not just a charge port.
The last patch uses the new usb-role-switch framework to also do proper devcie / host switching on CHT devices with a USB micro AB connector. This is also a big feature for CHT users, because before this they had to do a reboot to get an OTG-host cable recognized (on some devices).
Part of this series is an usb-role-switch driver for the role-switch found inside the xhci controller on e.g. CHT devices, this is currently implemented as the generic xhci controller instantiating a platform child-device for this, since this really is a separate chunk of HW which happens to sit in the XHCI mmio space. This approach may not be universally liked, given that in this new series the role-switch driver is much smaller and does not have any external deps anymore we could just integrate it into the xhci code if that is preferred.
About merging this series (once everything is reviewed, etc.), there are quite some interdependencies in it esp. a lot of the patches depend on the first patch. Luckily patches 1-10 all apply to subsystems which are maintained by Greg (most to the USB subsys). Which just leaves patches 11 and 12 once 1-10 are merged. Greg, can you create an immutable branch for the platform/x86 and extcon maintainers to merge once this is done?
Regards,
Hans
Hans de Goede (7):
usb: typec: tcpm: Set USB role switch to device mode when configured
as such
usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch
functions
xhci: Add Intel extended cap / otg phy mux handling
usb: roles: Add Intel xHCI USB role switch driver
usb: typec: driver for Pericom PI3USB30532 Type-C cross switch platform/x86: intel_cht_int33fe: Add device connections for the Type-C
port
extcon: axp288: Set USB role where necessary
Heikki Krogerus (4):
drivers: base: Unified device connection lookup
usb: typec: API for controlling USB Type-C Multiplexers
usb: common: Small class for USB role switches
usb: typec: Separate the definitions for data and power roles
Mathias Nyman (1):
xhci: Add option to get next extended capability in list by passing id
= 0
Documentation/ABI/testing/sysfs-class-usb_role | 21 ++
Documentation/driver-api/device_connection.rst | 43 ++++
Documentation/driver-api/usb/typec.rst | 73 +++++-
MAINTAINERS | 12 +
drivers/base/Makefile | 3 +-
drivers/base/devcon.c | 136 +++++++++++
drivers/extcon/Kconfig | 3 +-
drivers/extcon/extcon-axp288.c | 176 +++++++++++++-
drivers/platform/x86/intel_cht_int33fe.c | 24 ++
drivers/usb/Kconfig | 5 +
drivers/usb/Makefile | 2 +
drivers/usb/common/Makefile | 1 +
drivers/usb/common/roles.c | 305 +++++++++++++++++++++++++
drivers/usb/host/Makefile | 2 +-
drivers/usb/host/xhci-ext-caps.c | 90 ++++++++
drivers/usb/host/xhci-ext-caps.h | 7 +-
drivers/usb/host/xhci-pci.c | 5 +
drivers/usb/host/xhci.h | 2 +
drivers/usb/roles/Kconfig | 14 ++
drivers/usb/roles/Makefile | 1 +
drivers/usb/roles/intel-xhci-usb-role-switch.c | 192 ++++++++++++++++
drivers/usb/typec/Kconfig | 3 +
drivers/usb/typec/Makefile | 2 +
drivers/usb/typec/{typec.c => class.c} | 124 ++++++++--
drivers/usb/typec/fusb302/fusb302.c | 2 +-
drivers/usb/typec/mux.c | 191 ++++++++++++++++
drivers/usb/typec/mux/Kconfig | 10 +
drivers/usb/typec/mux/Makefile | 3 +
drivers/usb/typec/mux/pi3usb30532.c | 178 +++++++++++++++
drivers/usb/typec/tcpm.c | 63 +++--
drivers/usb/typec/tps6598x.c | 26 ++-
drivers/usb/typec/typec_wcove.c | 1 +
drivers/usb/typec/ucsi/ucsi.c | 13 +-
include/linux/device.h | 22 ++
include/linux/usb/role.h | 53 +++++
include/linux/usb/tcpm.h | 15 +-
include/linux/usb/typec.h | 28 ++-
include/linux/usb/typec_mux.h | 55 +++++
38 files changed, 1812 insertions(+), 94 deletions(-)
create mode 100644 Documentation/ABI/testing/sysfs-class-usb_role
create mode 100644 Documentation/driver-api/device_connection.rst
create mode 100644 drivers/base/devcon.c
create mode 100644 drivers/usb/common/roles.c
create mode 100644 drivers/usb/host/xhci-ext-caps.c
create mode 100644 drivers/usb/roles/Kconfig
create mode 100644 drivers/usb/roles/Makefile
create mode 100644 drivers/usb/roles/intel-xhci-usb-role-switch.c
rename drivers/usb/typec/{typec.c => class.c} (93%)
create mode 100644 drivers/usb/typec/mux.c
create mode 100644 drivers/usb/typec/mux/Kconfig
create mode 100644 drivers/usb/typec/mux/Makefile
create mode 100644 drivers/usb/typec/mux/pi3usb30532.c
create mode 100644 include/linux/usb/role.h
create mode 100644 include/linux/usb/typec_mux.hSignature · 1 line
2.16.2
Heikki Krogerus
maintainerPATCH v9 1/12 drivers: base: Unified device connection lookup
Several frameworks - clk, gpio, phy, pmw, etc. - maintain lookup tables for describing connections and provide custom API for handling them. This introduces a single generic lookup table and API for the connections.
The motivation for this commit is centralizing the connection lookup, but the goal is to ultimately extract the connection descriptions also from firmware by using the fwnode_graph_* functions and other mechanisms that are available.
---
Changes in v9
- Now really stop using rcu.
- Decalaring the bus types as extern so we don't have to include the header files.
Changes in v8:
- No longer using rcu.
Changes in v7:
- API naming improvements suggested by Greg
- Prototypes to device.h, also suggested by Greg
- I removed the DEVCON() macro as it was not used yet and it needs to be rewritten
Changes in v6:
-Fix data and match arguments being swapped in __device_find_connection()
call in device_find_connection() (as noticed by Jun Li)
Changes in v5:
-Add missing documentation for @list struct devcon member
Changes in v4:
-Add Andy's Reviewed-by
Changes in v3:
-Various spelling and gramar fixes in the docs pointed out by Randy Dunlap
Changes in v2:
-Add a (struct devcon) cast to the DEVCON() macro
--- Documentation/driver-api/device_connection.rst | 43 ++++++++ drivers/base/Makefile | 3 +- drivers/base/devcon.c | 136 +++++++++++++++++++++++++ include/linux/device.h | 22 ++++ 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 Documentation/driver-api/device_connection.rst create mode 100644 drivers/base/devcon.c
Documentation/driver-api/device_connection.rst new file +43 -0
@@ -0,0 +1,43 @@ +================== +Device connections +================== + +Introduction +------------ + +Devices often have connections to other devices that are outside of the direct +child/parent relationship. A serial or network communication controller, which +could be a PCI device, may need to be able to get a reference to its PHY +component, which could be attached for example to the I2C bus. Some device +drivers need to be able to control the clocks or the GPIOs for their devices, +and so on. + +Device connections are generic descriptions of any type of connection between +two separate devices. + +Device connections alone do not create a dependency between the two devices. +They are only descriptions which are not tied to either of the devices directly. +A dependency between the two devices exists only if one of the two endpoint +devices requests a reference to the other. The descriptions themselves can be +defined in firmware (not yet supported) or they can be built-in. + +Usage +----- + +Device connections should exist before device ``->probe`` callback is called for +either endpoint device in the description. If the connections are defined in +firmware, this is not a problem. It should be considered if the connection +descriptions are "built-in", and need to be added separately. + +The connection description consists of the names of the two devices with the +connection, i.e. the endpoints, and unique identifier for the connection which +is needed if there are multiple connections between the two devices. + +After a description exists, the devices in it can request reference to the other +endpoint device, or they can request the description itself. + +API +--- + +.. kernel-doc:: drivers/base/devcon.c + : functions: device_connection_find_match device_connection_find device_connection_add device_connection_remove
drivers/base/Makefile +2 -1
@@ -5,7 +5,8 @@ obj-y := component.o core.o bus.o dd.o syscore.o \ driver.o class.o platform.o \ cpu.o firmware.o init.o map.o devres.o \ attribute_container.o transport_class.o \ - topology.o container.o property.o cacheinfo.o + topology.o container.o property.o cacheinfo.o \ + devcon.o obj-$(CONFIG_DEVTMPFS) += devtmpfs.o obj-$(CONFIG_DMA_CMA) += dma-contiguous.o obj-y += power/
drivers/base/devcon.c new file +136 -0
136 lines not on this page · raw message
include/linux/device.h +22 -0
@@ -730,6 +730,28 @@ struct device_dma_parameters {unsigned long segment_boundary_mask; }; +/** +* struct device_connection - Device Connection Descriptor +* @endpoint: The names of the two devices connected together +* @id: Unique identifier for the connection +* @list: List head, private, for internal use only +*/ +struct device_connection { +const char *endpoint[2 ]; +const char *id; +struct list_head list; +}; + +void *device_connection_find_match (struct device *dev,const char *con_id, +void *data, +void *(*match)(struct device_connection *con, +int ep,void *data)); + +struct device *device_connection_find (struct device *dev,const char *con_id); + +void device_connection_add (struct device_connection *con); +void device_connection_remove (struct device_connection *con); +/** * enum device_link_state - Device link states. * @DL_STATE_NONE: The presence of the drivers is not being tracked.
Heikki Krogerus
maintainerPATCH v9 2/12 usb: typec: API for controlling USB Type-C Multiplexers
In reply to Heikki KrogerusUSB Type-C connectors consist of various muxes and switches that route the pins on the connector to the right locations. The USB Type-C drivers need to be able to control the muxes, as they are the ones that know things like the cable plug orientation, and the current mode that was negotiated with the partner.
This introduces a small API for registering and controlling cable plug orientation switches, and separate small API for registering and controlling pin multiplexer/demultiplexer switches that are needed with Accessory/Alternate Modes.
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v3:
-Add #include-s for a few missing headers to drivers/usb/typec/mux.c -Various spelling and gramar fixes in the docs pointed out by Randy Dunlap
---
Documentation/driver-api/usb/typec.rst | 73 +++++++++++--
drivers/usb/typec/Makefile | 1 +
drivers/usb/typec/{typec.c => class.c} | 70 ++++++++++++
drivers/usb/typec/mux.c | 191 +++++++++++++++++++++++++++++++++
include/linux/usb/typec.h | 14 +++
include/linux/usb/typec_mux.h | 55 ++++++++++
6 files changed, 393 insertions(+), 11 deletions(-)
rename drivers/usb/typec/{typec.c => class.c} (95%)
create mode 100644 drivers/usb/typec/mux.c
create mode 100644 include/linux/usb/typec_mux.hDocumentation/driver-api/usb/typec.rst +62 -11
@@ -61,7 +61,7 @@ Registering the ports The port drivers will describe every Type-C port they control with struct typec_capability data structure, and register them with the following API: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_register_port typec_unregister_port When registering the ports, the prefer_role member in struct typec_capability
@@ -80,7 +80,7 @@ typec_partner_desc. The class copies the details of the partner during registration. The class offers the following API for registering/unregistering partners. -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_register_partner typec_unregister_partner The class will provide a handle to struct typec_partner if the registration was
@@ -92,7 +92,7 @@ should include handle to struct usb_pd_identity instance. The class will then create a sysfs directory for the identity under the partner device. The result of Discover Identity command can then be reported with the following API: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_partner_set_identity Registering Cables
@@ -113,7 +113,7 @@ typec_cable_desc and about a plug in struct typec_plug_desc. The class copies the details during registration. The class offers the following API for registering/unregistering cables and their plugs: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_register_cable typec_unregister_cable typec_register_plug typec_unregister_plug The class will provide a handle to struct typec_cable and struct typec_plug if
@@ -125,7 +125,7 @@ include handle to struct usb_pd_identity instance. The class will then create a sysfs directory for the identity under the cable device. The result of Discover Identity command can then be reported with the following API: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_cable_set_identity Notifications
@@ -135,7 +135,7 @@ When the partner has executed a role change, or when the default roles change during connection of a partner or cable, the port driver must use the following APIs to report it to the class: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_set_data_role typec_set_pwr_role typec_set_vconn_role typec_set_pwr_opmode Alternate Modes
@@ -150,7 +150,7 @@ and struct typec_altmode_desc which is a container for all the supported modes. Ports that support Alternate Modes need to register each SVID they support with the following API: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_port_register_altmode If a partner or cable plug provides a list of SVIDs as response to USB Power
@@ -159,12 +159,12 @@ registered. API for the partners: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_partner_register_altmode API for the Cable Plugs: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_plug_register_altmode So ports, partners and cable plugs will register the alternate modes with their
@@ -172,11 +172,62 @@ own functions, but the registration will always return a handle to struct typec_altmode on success, or NULL. The unregistration will happen with the same function: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_unregister_altmode If a partner or cable plug enters or exits a mode, the port driver needs to notify the class with the following API: -.. kernel-doc:: drivers/usb/typec/typec.c +.. kernel-doc:: drivers/usb/typec/class.c :functions: typec_altmode_update_active + +Multiplexer/DeMultiplexer Switches +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +USB Type-C connectors may have one or more mux/demux switches behind them. Since +the plugs can be inserted right-side-up or upside-down, a switch is needed to +route the correct data pairs from the connector to the USB controllers. If +Alternate or Accessory Modes are supported, another switch is needed that can +route the pins on the connector to some other component besides USB. USB Type-C +Connector Class supplies an API for registering those switches. + +.. kernel-doc:: drivers/usb/typec/mux.c + :functions: typec_switch_register typec_switch_unregister typec_mux_register typec_mux_unregister + +In most cases the same physical mux will handle both the orientation and mode. +However, as the port drivers will be responsible for the orientation, and the +alternate mode drivers for the mode, the two are always separated into their +own logical components: "mux" for the mode and "switch" for the orientation. + +When a port is registered, USB Type-C Connector Class requests both the mux and +the switch for the port. The drivers can then use the following API for +controlling them: + +.. kernel-doc:: drivers/usb/typec/class.c + :functions: typec_set_orientation typec_set_mode + +If the connector is dual-role capable, there may also be a switch for the data +role. USB Type-C Connector Class does not supply separate API for them. The +port drivers can use USB Role Class API with those. + +Illustration of the muxes behind a connector that supports an alternate mode: + + ------------------------ + | Connector | + ------------------------ + | | + ------------------------ + \ Orientation / + -------------------- + | + -------------------- + / Mode \ + ------------------------ + / \ + ------------------------ -------------------- + | Alt Mode | / USB Role \ + ------------------------ ------------------------ + / \ + ------------------------ ------------------------ + | USB Host | | USB Device | + ------------------------ ------------------------
drivers/usb/typec/Makefile +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC) += typec.o +typec-y := class.o mux.o obj-$(CONFIG_TYPEC_TCPM) += tcpm.o obj-y += fusb302/ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o
drivers/usb/typec/class.c renamed from drivers/usb/typec/typec.c +70 -0
112 lines not on this page · raw message
drivers/usb/typec/mux.c new file +191 -0
191 lines not on this page · raw message
include/linux/usb/typec.h +14 -0
@@ -60,6 +60,12 @@ enum typec_accessory {#define TYPEC_MAX_ACCESSORY 3 +enum typec_orientation { +TYPEC_ORIENTATION_NONE , +TYPEC_ORIENTATION_NORMAL , +TYPEC_ORIENTATION_REVERSE , +}; +/* * struct usb_pd_identity - USB Power Delivery identity data * @id_header: ID Header VDO
@@ -185,6 +191,8 @@ struct typec_partner_desc {* @pd_revision: USB Power Delivery Specification revision if supported * @prefer_role: Initial role preference * @accessory: Supported Accessory Modes +* @sw: Cable plug orientation switch +* @mux: Multiplexer switch for Alternate/Accessory Modes * @fwnode: Optional fwnode of the port * @try_role: Set data role preference for DRP port * @dr_set: Set Data Role
@@ -202,6 +210,8 @@ struct typec_capability {int prefer_role;enum typec_accessory accessory[TYPEC_MAX_ACCESSORY ]; +struct typec_switch *sw; +struct typec_mux *mux;struct fwnode_handle *fwnode; int (*try_role)(const struct typec_capability *,
@@ -245,4 +255,8 @@ void typec_set_pwr_role(struct typec_port *port, enum typec_role role);void typec_set_vconn_role (struct typec_port *port,enum typec_role role);void typec_set_pwr_opmode (struct typec_port *port,enum typec_pwr_opmode mode); +int typec_set_orientation (struct typec_port *port, +enum typec_orientation orientation); +int typec_set_mode (struct typec_port *port,int mode); +#endif /* __LINUX_USB_TYPEC_H */
include/linux/usb/typec_mux.h new file +55 -0
55 lines not on this page · raw message
Heikki Krogerus
maintainerPATCH v9 3/12 usb: common: Small class for USB role switches
In reply to Heikki KrogerusUSB role switch is a device that can be used to choose the data role for USB connector. With dual-role capable USB controllers, the controller itself will be the switch, but on some platforms the USB host and device controllers are separate IPs and there is a mux between them and the connector. On those platforms the mux driver will need to register the switch.
With USB Type-C connectors, the host-to-device relationship is negotiated over the Configuration Channel (CC). That means the USB Type-C drivers need to be in control of the role switch. The class provides a simple API for the USB Type-C drivers for the control.
For other types of USB connectors (mainly microAB) the class provides user space control via sysfs attribute file that can be used to request role swapping from the switch.
---
Changes in v4:
-Consistently use IS_ERR_OR_NULL where applicable
-Add Andy's Reviewed-by
Changes in v2:
-Minor style fixes from review of v1
--- Documentation/ABI/testing/sysfs-class-usb_role | 21 ++ drivers/usb/Kconfig | 3 + drivers/usb/common/Makefile | 1 + drivers/usb/common/roles.c | 305 +++++++++++++++++++++++++ include/linux/usb/role.h | 53 +++++ 5 files changed, 383 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-usb_role create mode 100644 drivers/usb/common/roles.c create mode 100644 include/linux/usb/role.h
Documentation/ABI/testing/sysfs-class-usb_role new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/class/usb_role/ +Date: Jan 2018 +Contact: Heikki Krogerus <[email protected]> +Description: + Place in sysfs for USB Role Switches. USB Role Switch is a + device that can select the data role (host or device) for USB + port. + +What: /sys/class/usb_role/<switch>/role +Date: Jan 2018 +Contact: Heikki Krogerus <[email protected]> +Description: + The current role of the switch. This attribute can be used for + requesting role swapping with non-USB Type-C ports. With USB + Type-C ports, the ABI defined for USB Type-C connector class + must be used. + + Valid values: + - none + - host + - device
drivers/usb/Kconfig +3 -0
@@ -203,4 +203,7 @@ config USB_ULPI_BUS To compile this driver as a module, choose M here: the module will be called ulpi. +config USB_ROLE_SWITCH + tristate + endif # USB_SUPPORT
drivers/usb/common/Makefile +1 -0
@@ -9,3 +9,4 @@ usb-common-$(CONFIG_USB_LED_TRIG) += led.o obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o +obj-$(CONFIG_USB_ROLE_SWITCH) += roles.o
drivers/usb/common/roles.c new file +305 -0
305 lines not on this page · raw message
include/linux/usb/role.h new file +53 -0
53 lines not on this page · raw message
Heikki Krogerus
maintainerPATCH v9 4/12 usb: typec: Separate the definitions for data and power roles
In reply to Heikki KrogerusUSB Type-C specification v1.2 separated the power and data roles more clearly. Dual-Role-Data term was introduced, and the meaning of DRP was changed from "Dual-Role-Port" to "Dual-Role-Power".
In order to allow the port drivers to describe the capabilities of the ports more clearly according to the newest specifications, introducing separate definitions for the data roles.
--- drivers/usb/typec/class.c | 56 ++++++++++++++++++++++--------------- drivers/usb/typec/fusb302/fusb302.c | 1 + drivers/usb/typec/tcpm.c | 9 +++--- drivers/usb/typec/tps6598x.c | 26 +++++++++++------ drivers/usb/typec/typec_wcove.c | 1 + drivers/usb/typec/ucsi/ucsi.c | 13 +++++++-- include/linux/usb/tcpm.h | 1 + include/linux/usb/typec.h | 14 ++++++++-- 8 files changed, 80 insertions(+), 41 deletions(-)
drivers/usb/typec/class.c +34 -22
@@ -282,10 +282,10 @@ typec_altmode_roles_show(struct device *dev, struct device_attribute *attr,ssize_t ret;switch (mode->roles) { -case TYPEC_PORT_DFP : +case TYPEC_PORT_SRC : ret =sprintf (buf,"source\n" );break ; -case TYPEC_PORT_UFP : +case TYPEC_PORT_SNK : ret =sprintf (buf,"sink\n" );break ;case TYPEC_PORT_DRP :
@@ -797,14 +797,14 @@ static const char * const typec_data_roles[] = { };static const char *const typec_port_types[] = { - [TYPEC_PORT_DFP ] ="source" , - [TYPEC_PORT_UFP ] ="sink" , + [TYPEC_PORT_SRC ] ="source" , + [TYPEC_PORT_SNK ] ="sink" , [TYPEC_PORT_DRP ] ="dual" , };static const char *const typec_port_types_drp[] = { - [TYPEC_PORT_DFP ] ="dual [source] sink" , - [TYPEC_PORT_UFP ] ="dual source [sink]" , + [TYPEC_PORT_SRC ] ="dual [source] sink" , + [TYPEC_PORT_SNK ] ="dual source [sink]" , [TYPEC_PORT_DRP ] ="[dual] source sink" , };
@@ -875,9 +875,7 @@ static ssize_t data_role_store(struct device *dev,return ret;mutex_lock (&port->port_type_lock); -if (port->port_type !=TYPEC_PORT_DRP ) { -dev_dbg (dev,"port type fixed at \"%s\"" , - typec_port_types[port->port_type]); +if (port->cap->data !=TYPEC_PORT_DRD ) { ret = -EOPNOTSUPP ; goto unlock_and_ret; }
@@ -897,7 +895,7 @@ static ssize_t data_role_show(struct device *dev, {struct typec_port *port =to_typec_port (dev); -if (port->cap->type ==TYPEC_PORT_DRP ) +if (port->cap->data ==TYPEC_PORT_DRD )return sprintf (buf,"%s\n" , port->data_role ==TYPEC_HOST ?"[host] device" :"host [device]" );
@@ -1328,7 +1326,6 @@ struct typec_port *typec_register_port(struct device *parent, const struct typec_capability *cap) {struct typec_port *port; -int role;int ret;int id;
@@ -1354,21 +1351,36 @@ struct typec_port *typec_register_port(struct device *parent, goto err_mux; } -if (cap->type ==TYPEC_PORT_DFP ) - role =TYPEC_SOURCE ; -else if (cap->type ==TYPEC_PORT_UFP ) - role =TYPEC_SINK ; -else - role = cap->prefer_role; - -if (role ==TYPEC_SOURCE ) { - port->data_role =TYPEC_HOST ; +switch (cap->type) { +case TYPEC_PORT_SRC : port->pwr_role =TYPEC_SOURCE ; port->vconn_role =TYPEC_SOURCE ; - }else { - port->data_role =TYPEC_DEVICE ; +break ; +case TYPEC_PORT_SNK : port->pwr_role =TYPEC_SINK ; port->vconn_role =TYPEC_SINK ; +break ; +case TYPEC_PORT_DRP : +if (cap->prefer_role !=TYPEC_NO_PREFERRED_ROLE ) + port->pwr_role = cap->prefer_role; +else + port->pwr_role =TYPEC_SINK ; +break ; + } + +switch (cap->data) { +case TYPEC_PORT_DFP : + port->data_role =TYPEC_HOST ; +break ; +case TYPEC_PORT_UFP : + port->data_role =TYPEC_DEVICE ; +break ; +case TYPEC_PORT_DRD : +if (cap->prefer_role ==TYPEC_SOURCE ) + port->data_role =TYPEC_HOST ; +else + port->data_role =TYPEC_DEVICE ; +break ; } port->id = id;
drivers/usb/typec/fusb302/fusb302.c +1 -0
@@ -1219,6 +1219,7 @@ static const struct tcpc_config fusb302_tcpc_config = { .max_snk_mw = 15000, .operating_snk_mw = 2500, .type = TYPEC_PORT_DRP, + .data = TYPEC_PORT_DRD, .default_role = TYPEC_SINK, .alt_modes = NULL, };
drivers/usb/typec/tcpm.c +5 -4
@@ -345,7 +345,7 @@ static enum tcpm_state tcpm_default_state(struct tcpm_port *port)else if (port->tcpc->config->default_role ==TYPEC_SINK )return SNK_UNATTACHED ;/* Fall through to return SRC_UNATTACHED */ - }else if (port->port_type ==TYPEC_PORT_UFP ) { + }else if (port->port_type ==TYPEC_PORT_SNK ) {return SNK_UNATTACHED ; }return SRC_UNATTACHED ;
@@ -2179,7 +2179,7 @@ static inline enum tcpm_state unattached_state(struct tcpm_port *port)return SRC_UNATTACHED ; else return SNK_UNATTACHED; - }else if (port->port_type ==TYPEC_PORT_DFP ) { + }else if (port->port_type ==TYPEC_PORT_SRC ) {return SRC_UNATTACHED ; }
@@ -3469,11 +3469,11 @@ static int tcpm_port_type_set(const struct typec_capability *cap,if (!port->connected) {tcpm_set_state (port,PORT_RESET ,0 ); - }else if (type ==TYPEC_PORT_UFP ) { + }else if (type ==TYPEC_PORT_SNK ) {if (!(port->pwr_role ==TYPEC_SINK && port->data_role ==TYPEC_DEVICE ))tcpm_set_state (port,PORT_RESET ,0 ); - }else if (type ==TYPEC_PORT_DFP ) { + }else if (type ==TYPEC_PORT_SRC ) {if (!(port->pwr_role ==TYPEC_SOURCE && port->data_role ==TYPEC_HOST ))tcpm_set_state (port,PORT_RESET ,0 );
@@ -3641,6 +3641,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->typec_caps.prefer_role = tcpc->config->default_role; port->typec_caps.type = tcpc->config->type; + port->typec_caps.data = tcpc->config->data; port->typec_caps.revision =0x0120 ;/* Type-C spec release 1.2 */ port->typec_caps.pd_revision =0x0200 ;/* USB-PD spec release 2.0 */ port->typec_caps.dr_set = tcpm_dr_set;
drivers/usb/typec/tps6598x.c +17 -9
@@ -393,31 +393,39 @@ static int tps6598x_probe(struct i2c_client *client)if (ret <0 )return ret; + tps->typec_cap.revision =USB_TYPEC_REV_1_2 ; + tps->typec_cap.pd_revision =0x200 ; + tps->typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; + tps->typec_cap.pr_set = tps6598x_pr_set; + tps->typec_cap.dr_set = tps6598x_dr_set; +switch (TPS_SYSCONF_PORTINFO (conf)) {case TPS_PORTINFO_SINK_ACCESSORY :case TPS_PORTINFO_SINK : - tps->typec_cap.type =TYPEC_PORT_UFP ; + tps->typec_cap.type =TYPEC_PORT_SNK ; + tps->typec_cap.data =TYPEC_PORT_UFP ;break ;case TPS_PORTINFO_DRP_UFP_DRD :case TPS_PORTINFO_DRP_DFP_DRD : - tps->typec_cap.dr_set = tps6598x_dr_set; -/* fall through */ + tps->typec_cap.type =TYPEC_PORT_DRP ; + tps->typec_cap.data =TYPEC_PORT_DRD ; +break ;case TPS_PORTINFO_DRP_UFP : + tps->typec_cap.type =TYPEC_PORT_DRP ; + tps->typec_cap.data =TYPEC_PORT_UFP ; +break ;case TPS_PORTINFO_DRP_DFP : - tps->typec_cap.pr_set = tps6598x_pr_set; tps->typec_cap.type =TYPEC_PORT_DRP ; + tps->typec_cap.data =TYPEC_PORT_DFP ;break ;case TPS_PORTINFO_SOURCE : - tps->typec_cap.type =TYPEC_PORT_DFP ; + tps->typec_cap.type =TYPEC_PORT_SRC ; + tps->typec_cap.data =TYPEC_PORT_DFP ;break ;default :return -ENODEV ; } - tps->typec_cap.revision =USB_TYPEC_REV_1_2 ; - tps->typec_cap.pd_revision =0x200 ; - tps->typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; - tps->port =typec_register_port (&client->dev, &tps->typec_cap);if (IS_ERR (tps->port))return PTR_ERR (tps->port);
drivers/usb/typec/typec_wcove.c +1 -0
@@ -572,6 +572,7 @@ static struct tcpc_config wcove_typec_config = { .operating_snk_mw = 15000, .type = TYPEC_PORT_DRP, + .data = TYPEC_PORT_DRD, .default_role = TYPEC_SINK, };
drivers/usb/typec/ucsi/ucsi.c +10 -3
@@ -592,11 +592,18 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)return ret;if (con->cap.op_mode &UCSI_CONCAP_OPMODE_DRP ) - cap->type =TYPEC_PORT_DRP ; + cap->data =TYPEC_PORT_DRD ;else if (con->cap.op_mode &UCSI_CONCAP_OPMODE_DFP ) - cap->type =TYPEC_PORT_DFP ; + cap->data =TYPEC_PORT_DFP ;else if (con->cap.op_mode &UCSI_CONCAP_OPMODE_UFP ) - cap->type =TYPEC_PORT_UFP ; + cap->data =TYPEC_PORT_UFP ; + +if (con->cap.provider && con->cap.consumer) + cap->type =TYPEC_PORT_DRP ; +else if (con->cap.provider) + cap->type =TYPEC_PORT_SRC ; +else if (con->cap.consumer) + cap->type =TYPEC_PORT_SNK ; cap->revision = ucsi->cap.typec_version; cap->pd_revision = ucsi->cap.pd_version;
include/linux/usb/tcpm.h +1 -0
@@ -91,6 +91,7 @@ struct tcpc_config {unsigned int operating_snk_mw;enum typec_port_type type; +enum typec_port_data data;enum typec_role default_role;bool try_role_hw;/* try.{src,snk} implemented in hardware */
include/linux/usb/typec.h +11 -3
@@ -22,9 +22,15 @@ struct typec_port;struct fwnode_handle ;enum typec_port_type { +TYPEC_PORT_SRC , +TYPEC_PORT_SNK , +TYPEC_PORT_DRP , +}; + +enum typec_port_data {TYPEC_PORT_DFP ,TYPEC_PORT_UFP , -TYPEC_PORT_DRP , +TYPEC_PORT_DRD , };enum typec_plug_type {
@@ -186,10 +192,11 @@ struct typec_partner_desc {/* * struct typec_capability - USB Type-C Port Capabilities -* @role: DFP (Host-only), UFP (Device-only) or DRP (Dual Role) +* @type: Supported power role of the port +* @data: Supported data role of the port * @revision: USB Type-C Specification release. Binary coded decimal * @pd_revision: USB Power Delivery Specification revision if supported -* @prefer_role: Initial role preference +* @prefer_role: Initial role preference (DRP ports). * @accessory: Supported Accessory Modes * @sw: Cable plug orientation switch * @mux: Multiplexer switch for Alternate/Accessory Modes
@@ -205,6 +212,7 @@ struct typec_partner_desc {*/ struct typec_capability {enum typec_port_type type; +enum typec_port_data data;u16 revision;/* 0120H = "1.2" */ u16 pd_revision;/* 0300H = "3.0" */ int prefer_role;
Heikki Krogerus
maintainerPATCH v9 5/12 usb: typec: tcpm: Set USB role switch to device mode when configured as such
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
Setting the mux to MUX_NONE and the switch to USB_SWITCH_DISCONNECT when the data-role is device is not correct. Plenty of devices support operating as USB device through a (separate) USB device controller.
We really need 2 different versions of USB_SWITCH_CONNECT, USB_SWITCH_CONNECT_HOST and USB_SWITCH_DEVICE. Rather then modifying the tcpc_usb_switch enum for this, simply remove it and switch to the usb_role enum which provides exactly this, this will save use needing to convert betweent the 2 enums when calling an usb-role-switch driver later.
Besides switching to the usb_role type, this commit also actually sets the mux to TYPEC_MUX_USB and the switch to USB_ROLE_DEVICE instead of setting both to none when the data-role is device.
This commit also makes tcpm_reset_port() call tcpm_mux_set(port, TYPEC_MUX_NONE, USB_ROLE_NONE) so that the mux and switch do _not_ stay in their last mode after a detach.
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v3:
-Add Guenter's Reviewed-by
Changes in v2:
-Added Heikki's Reviewed-by
--- drivers/usb/typec/tcpm.c | 22 +++++++++++----------- include/linux/usb/tcpm.h | 8 ++------ 2 files changed, 13 insertions(+), 17 deletions(-)
drivers/usb/typec/tcpm.c +11 -11
@@ -604,15 +604,15 @@ void tcpm_pd_transmit_complete(struct tcpm_port *port,EXPORT_SYMBOL_GPL (tcpm_pd_transmit_complete);static int tcpm_mux_set (struct tcpm_port *port,enum tcpc_mux_mode mode, -enum tcpc_usb_switch config) +enum usb_role usb_role) {int ret =0 ; -tcpm_log (port,"Requesting mux mode %d, config %d, polarity %d" , - mode, config, port->polarity); +tcpm_log (port,"Requesting mux mode %d, usb-role %d, polarity %d" , + mode, usb_role, port->polarity);if (port->tcpc->mux) - ret = port->tcpc->mux->set (port->tcpc->mux, mode, config, + ret = port->tcpc->mux->set (port->tcpc->mux, mode, usb_role, port->polarity);return ret;
@@ -728,14 +728,15 @@ static int tcpm_set_attached_state(struct tcpm_port *port, bool attached)static int tcpm_set_roles (struct tcpm_port *port,bool attached,enum typec_role role,enum typec_data_role data) { +enum usb_role usb_role;int ret;if (data ==TYPEC_HOST ) - ret =tcpm_mux_set (port,TYPEC_MUX_USB , -TCPC_USB_SWITCH_CONNECT ); + usb_role =USB_ROLE_HOST ;else - ret =tcpm_mux_set (port,TYPEC_MUX_NONE , -TCPC_USB_SWITCH_DISCONNECT ); + usb_role =USB_ROLE_DEVICE ; + + ret =tcpm_mux_set (port,TYPEC_MUX_USB , usb_role);if (ret <0 )return ret;
@@ -2028,7 +2029,7 @@ static int tcpm_src_attach(struct tcpm_port *port) out_disable_pd: port->tcpc->set_pd_rx (port->tcpc, false); out_disable_mux: -tcpm_mux_set (port,TYPEC_MUX_NONE ,TCPC_USB_SWITCH_DISCONNECT ); +tcpm_mux_set (port,TYPEC_MUX_NONE ,USB_ROLE_NONE );return ret; }
@@ -2072,6 +2073,7 @@ static void tcpm_reset_port(struct tcpm_port *port)tcpm_init_vconn (port);tcpm_set_current_limit (port,0 ,0 );tcpm_set_polarity (port,TYPEC_POLARITY_CC1 ); +tcpm_mux_set (port,TYPEC_MUX_NONE ,USB_ROLE_NONE );tcpm_set_attached_state (port, false); port->try_src_count =0 ; port->try_snk_count =0 ;
@@ -2122,8 +2124,6 @@ static int tcpm_snk_attach(struct tcpm_port *port)static void tcpm_snk_detach (struct tcpm_port *port) {tcpm_detach (port); - -/* XXX: (Dis)connect SuperSpeed mux? */ }static int tcpm_acc_attach (struct tcpm_port *port)
include/linux/usb/tcpm.h +2 -6
@@ -16,6 +16,7 @@#define __LINUX_USB_TCPM_H#include <linux/bitops.h> +#include <linux/usb/role.h> #include <linux/usb/typec.h> #include "pd.h"
@@ -98,11 +99,6 @@ struct tcpc_config {const struct typec_altmode_desc *alt_modes; }; -enum tcpc_usb_switch { -TCPC_USB_SWITCH_CONNECT , -TCPC_USB_SWITCH_DISCONNECT , -}; -/* Mux state attributes */ #define TCPC_MUX_USB_ENABLED BIT(0)/* USB enabled */ #define TCPC_MUX_DP_ENABLED BIT(1)/* DP enabled */
@@ -119,7 +115,7 @@ enum tcpc_mux_mode {struct tcpc_mux_dev {int (*set)(struct tcpc_mux_dev *dev,enum tcpc_mux_mode mux_mode, -enum tcpc_usb_switch usb_config, +enum usb_role usb_role,enum typec_cc_polarity polarity);bool dfp_only;void *priv_data;
Heikki Krogerus
maintainerPATCH v9 6/12 usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
Remove the unused (not implemented anywhere) tcpc_mux_dev abstraction and replace it with calling the new typec_set_orientation, usb_role_switch_set and typec_set_mode functions.
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v3:
-Add Guenter's Reviewed-by
Changes in v2:
-Added Heikki's Reviewed-by
--- drivers/usb/typec/Kconfig | 1 + drivers/usb/typec/fusb302/fusb302.c | 1 - drivers/usb/typec/tcpm.c | 46 ++++++++++++++++++++++++++++--------- include/linux/usb/tcpm.h | 10 -------- 4 files changed, 36 insertions(+), 22 deletions(-)
drivers/usb/typec/Kconfig +1 -0
@@ -48,6 +48,7 @@ if TYPEC config TYPEC_TCPM tristate "USB Type-C Port Controller Manager" depends on USB + select USB_ROLE_SWITCH help The Type-C Port Controller Manager provides a USB PD and USB Type-C state machine for use with Type-C Port Controllers.
drivers/usb/typec/fusb302/fusb302.c +0 -1
@@ -1239,7 +1239,6 @@ static void init_tcpc_dev(struct tcpc_dev *fusb302_tcpc_dev) fusb302_tcpc_dev->set_roles = tcpm_set_roles; fusb302_tcpc_dev->start_drp_toggling = tcpm_start_drp_toggling; fusb302_tcpc_dev->pd_transmit = tcpm_pd_transmit; - fusb302_tcpc_dev->mux =NULL ; }static const char *const cc_polarity_name[] = {
drivers/usb/typec/tcpm.c +35 -11
106 lines not on this page · raw message
include/linux/usb/tcpm.h +0 -10
@@ -16,7 +16,6 @@#define __LINUX_USB_TCPM_H#include <linux/bitops.h> -#include <linux/usb/role.h> #include <linux/usb/typec.h> #include "pd.h"
@@ -113,14 +112,6 @@ enum tcpc_mux_mode { TCPC_MUX_DP_ENABLED, }; -struct tcpc_mux_dev { -int (*set)(struct tcpc_mux_dev *dev,enum tcpc_mux_mode mux_mode, -enum usb_role usb_role, -enum typec_cc_polarity polarity); -bool dfp_only; -void *priv_data; -}; -/** * struct tcpc_dev - Port configuration and callback functions * @config: Pointer to port configuration
@@ -172,7 +163,6 @@ struct tcpc_dev {int (*try_role)(struct tcpc_dev *dev,int role);int (*pd_transmit)(struct tcpc_dev *dev,enum tcpm_transmit_type type,const struct pd_message *msg); -struct tcpc_mux_dev *mux; };struct tcpm_port ;
Heikki Krogerus
maintainerPATCH v9 7/12 xhci: Add option to get next extended capability in list by passing id = 0
In reply to Heikki KrogerusFrom: Mathias Nyman <[email protected]>
Modify xhci_find_next_ext_cap(base, offset, id) to return the next capability offset if 0 is passed for id. Otherwise it will behave as previously and return the offset of the next capability with matching id
capability id 0 is not used by xHCI (reserved)
This is useful when we want to loop through all capabilities.
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v2:
-Added Heikki's Reviewed-by
--- drivers/usb/host/xhci-ext-caps.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/host/xhci-ext-caps.h +3 -2
@@ -84,7 +84,8 @@* @base PCI MMIO registers base address. * @start address at which to start looking, (0 or HCC_PARAMS to start at * beginning of list) -* @id Extended capability ID to search for. +* @id Extended capability ID to search for, or 0 for the next +* capability * * Returns the offset of the next matching extended capability structure. * Some capabilities can occur several times, e.g., the XHCI_EXT_CAPS_PROTOCOL,
@@ -110,7 +111,7 @@ static inline int xhci_find_next_ext_cap(void __iomem *base, u32 start, int id) val =readl (base + offset);if (val == ~0 )return 0 ; -if (XHCI_EXT_CAPS_ID (val) == id && offset != start) +if (offset != start && (id ==0 ||XHCI_EXT_CAPS_ID (val) == id))return offset; next =XHCI_EXT_CAPS_NEXT (val);
Heikki Krogerus
maintainerPATCH v9 8/12 xhci: Add Intel extended cap / otg phy mux handling
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
The xHCI controller on various Intel SoCs has an extended cap mmio-range which contains registers to control the muxing to the xHCI (host mode) or the dwc3 (device mode) and vbus-detection for the otg usb-phy.
Having a role-sw driver included in the xHCI code (under drivers/usb/host) is not desirable. So this commit adds a simple handler for this extended capability, which creates a platform device with the caps mmio region as resource, this allows us to write a separate platform role-sw driver for the role-switch.
Note this commit adds a call to the new xhci_ext_cap_init() function to xhci_pci_probe(), it is added here because xhci_ext_cap_init() must be called only once. If in the future we also want to handle ext-caps on non pci xHCI HCDs from xhci_ext_cap_init() a call to it should also be added to other bus probe paths.
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v2:
-Use SPDX license header
-Various small style cleanups / changes
-Add Heikki's Reviewed-by
Changes from some time ago when this patch was part of another patch-set:
-Check xHCI controller PCI device-id instead of only checking for the
Intel Extended capability ID, as the Extended capability ID is used on other model Intel xHCI controllers too
-Add a new generic xhci_ext_cap_init() function and handle the new
XHCI_INTEL_CHT_USB_MUX quirk there.
-Stop using Cherry Trail / CHT in various places as other Intel SoCs
(e.g. Broxton / Apollo Lake) also have this
--- drivers/usb/host/Makefile | 2 +- drivers/usb/host/xhci-ext-caps.c | 90 ++++++++++++++++++++++++++++++++++++++++ drivers/usb/host/xhci-ext-caps.h | 2 + drivers/usb/host/xhci-pci.c | 5 +++ drivers/usb/host/xhci.h | 2 + 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 drivers/usb/host/xhci-ext-caps.c
drivers/usb/host/Makefile +1 -1
@@ -11,7 +11,7 @@ fhci-y += fhci-mem.o fhci-tds.o fhci-sched.o fhci-$(CONFIG_FHCI_DEBUG) += fhci-dbg.o -xhci-hcd-y := xhci.o xhci-mem.o +xhci-hcd-y := xhci.o xhci-mem.o xhci-ext-caps.o xhci-hcd-y += xhci-ring.o xhci-hub.o xhci-dbg.o xhci-hcd-y += xhci-trace.o
drivers/usb/host/xhci-ext-caps.c new file +90 -0
90 lines not on this page · raw message
drivers/usb/host/xhci-ext-caps.h +2 -0
@@ -39,6 +39,8 @@#define XHCI_EXT_CAPS_ROUTE 5/* IDs 6-9 reserved */ #define XHCI_EXT_CAPS_DEBUG 10 +/* Vendor caps */ +#define XHCI_EXT_CAPS_VENDOR_INTEL 192/* USB Legacy Support Capability - section 7.1.1 */ #define XHCI_HC_BIOS_OWNED (1 << 16)#define XHCI_HC_OS_OWNED (1 << 24)
drivers/usb/host/xhci-pci.c +5 -0
@@ -178,6 +178,7 @@ static void xhci_pci_quirks(struct device *dev, struct xhci_hcd *xhci)if (pdev->vendor ==PCI_VENDOR_ID_INTEL && pdev->device ==PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ) { xhci->quirks |=XHCI_SSIC_PORT_UNUSED ; + xhci->quirks |=XHCI_INTEL_USB_ROLE_SW ; } if (pdev->vendor == PCI_VENDOR_ID_INTEL && (pdev->device == PCI_DEVICE_ID_INTEL_CHERRYVIEW_XHCI ||
@@ -311,6 +312,10 @@ static int xhci_pci_probe(struct pci_dev *dev, const struct pci_device_id *id) goto dealloc_usb2_hcd; } + retval =xhci_ext_cap_init (xhci); +if (retval) + goto put_usb3_hcd; + retval =usb_add_hcd (xhci->shared_hcd, dev->irq,IRQF_SHARED );if (retval)
drivers/usb/host/xhci.h +2 -0
@@ -1829,6 +1829,7 @@ struct xhci_hcd {#define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28)#define XHCI_HW_LPM_DISABLE (1 << 29)#define XHCI_SUSPEND_DELAY (1 << 30) +#define XHCI_INTEL_USB_ROLE_SW (1 << 31)unsigned int num_active_eps;unsigned int limit_active_eps;
@@ -2024,6 +2025,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks);void xhci_init_driver (struct hc_driver *drv,const struct xhci_driver_overrides *over);int xhci_disable_slot (struct xhci_hcd *xhci,u32 slot_id); +int xhci_ext_cap_init (struct xhci_hcd *xhci);int xhci_suspend (struct xhci_hcd *xhci,bool do_wakeup);int xhci_resume (struct xhci_hcd *xhci,bool hibernated);
Heikki Krogerus
maintainerPATCH v9 9/12 usb: roles: Add Intel xHCI USB role switch driver
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
Various Intel SoCs (Cherry Trail, Broxton and others) have an internal USB role switch for swiching the OTG USB data lines between the xHCI host controller and the dwc3 gadget controller.
Note on some Cherry Trail systems there is ACPI/AML code listening to edge interrupts on the id-pin (through an _AIE ACPI method) and switching the role between ROLE_HOST and ROLE_NONE based on the id-pin. Note it does not set the role to ROLE_DEVICE, because device-mode is usually not used under Windows.
The presence of AML code which modifies the cfg0 reg (on some systems) means that our read/write/modify of cfg0 may race with the AML code doing the same to avoid this we take the global ACPI lock while doing the read/write/modify.
---
Changes in v7:
- Declare intel_xhci_usb_remove() as static
Changes in v4:
-Add Andy's Reviewed-by
-Add Heikki's Reviewed-by
Changes in v2:
-Drop unnecessary depends on EXTCON from Kconfig
-Use BIT(), resource_size()
-Various other small style fixes
--- MAINTAINERS | 6 + drivers/usb/Kconfig | 2 + drivers/usb/Makefile | 2 + drivers/usb/roles/Kconfig | 14 ++ drivers/usb/roles/Makefile | 1 + drivers/usb/roles/intel-xhci-usb-role-switch.c | 192 +++++++++++++++++++++++++ 6 files changed, 217 insertions(+) create mode 100644 drivers/usb/roles/Kconfig create mode 100644 drivers/usb/roles/Makefile create mode 100644 drivers/usb/roles/intel-xhci-usb-role-switch.c
MAINTAINERS +6 -0
@@ -14471,6 +14471,12 @@ S: Maintained F: Documentation/hid/hiddev.txt F: drivers/hid/usbhid/ +USB INTEL XHCI ROLE MUX DRIVER +M: Hans de Goede <[email protected]> +L: [email protected] +S: Maintained +F: drivers/usb/roles/intel-xhci-usb-role-switch.c + USB ISP116X DRIVER M: Olav Kongas <[email protected]> L: [email protected]
drivers/usb/Kconfig +2 -0
@@ -171,6 +171,8 @@ source "drivers/usb/gadget/Kconfig" source "drivers/usb/typec/Kconfig" +source "drivers/usb/roles/Kconfig" + config USB_LED_TRIG bool "USB LED Triggers" depends on LEDS_CLASS && LEDS_TRIGGERS
drivers/usb/Makefile +2 -0
@@ -65,3 +65,5 @@ obj-$(CONFIG_USB_COMMON) += common/ obj-$(CONFIG_USBIP_CORE) += usbip/ obj-$(CONFIG_TYPEC) += typec/ + +obj-$(CONFIG_USB_ROLE_SWITCH) += roles/
drivers/usb/roles/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +if USB_ROLE_SWITCH + +config USB_ROLES_INTEL_XHCI + tristate "Intel XHCI USB Role Switch" + depends on ACPI && X86 + help + Driver for the internal USB role switch for switching the USB data + lines between the xHCI host controller and the dwc3 gadget controller + found on various Intel SoCs. + + To compile the driver as a module, choose M here: the module will + be called intel-xhci-usb-role-switch. + +endif # USB_ROLE_SWITCH
drivers/usb/roles/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_USB_ROLES_INTEL_XHCI) += intel-xhci-usb-role-switch.o
drivers/usb/roles/intel-xhci-usb-role-switch.c new file +192 -0
192 lines not on this page · raw message
Heikki Krogerus
maintainerPATCH v9 10/12 usb: typec: driver for Pericom PI3USB30532 Type-C cross switch
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
Add a driver for the Pericom PI3USB30532 Type-C cross switch / mux chip found on some devices with a Type-C port.
---
Changes in v7:
- Remove unneeded semicolon
Changes in v4:
-Add Andy's Reviewed-by
Changes in v2:
-Cleanup pi3usb30532_set_conf() error handling
-Add Heikki's Reviewed-by
Changes in v1:
-This is a rewrite of my previous driver which was using the
drivers/mux framework to use the new drivers/usb/typec/mux framework
--- MAINTAINERS | 6 ++ drivers/usb/typec/Kconfig | 2 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/mux/Kconfig | 10 ++ drivers/usb/typec/mux/Makefile | 3 + drivers/usb/typec/mux/pi3usb30532.c | 178 ++++++++++++++++++++++++++++++++++++ 6 files changed, 200 insertions(+) create mode 100644 drivers/usb/typec/mux/Kconfig create mode 100644 drivers/usb/typec/mux/Makefile create mode 100644 drivers/usb/typec/mux/pi3usb30532.c
MAINTAINERS +6 -0
@@ -14607,6 +14607,12 @@ F: drivers/usb/ F: include/linux/usb.h F: include/linux/usb/ +USB TYPEC PI3USB30532 MUX DRIVER +M: Hans de Goede <[email protected]> +L: [email protected] +S: Maintained +F: drivers/usb/typec/mux/pi3usb30532.c + USB TYPEC SUBSYSTEM M: Heikki Krogerus <[email protected]> L: [email protected]
drivers/usb/typec/Kconfig +2 -0
@@ -85,4 +85,6 @@ config TYPEC_TPS6598X If you choose to build this driver as a dynamically linked module, the module will be called tps6598x.ko. +source "drivers/usb/typec/mux/Kconfig" + endif # TYPEC
drivers/usb/typec/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-y += fusb302/ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o obj-$(CONFIG_TYPEC_UCSI) += ucsi/ obj-$(CONFIG_TYPEC_TPS6598X) += tps6598x.o +obj-$(CONFIG_TYPEC) += mux/
drivers/usb/typec/mux/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +menu "USB Type-C Multiplexer/DeMultiplexer Switch support" + +config TYPEC_MUX_PI3USB30532 + tristate "Pericom PI3USB30532 Type-C cross switch driver" + depends on I2C + help + Say Y or M if your system has a Pericom PI3USB30532 Type-C cross + switch / mux chip found on some devices with a Type-C port. + +endmenu
drivers/usb/typec/mux/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_TYPEC_MUX_PI3USB30532) += pi3usb30532.o
drivers/usb/typec/mux/pi3usb30532.c new file +178 -0
178 lines not on this page · raw message
Heikki Krogerus
maintainerPATCH v9 11/12 platform/x86: intel_cht_int33fe: Add device connections for the Type-C port
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
We need to add device-connections for the Type-C mux/switch and usb-role code to be able to find the PI3USB30532 Type-C cross-switch and the device/host role-switch integrated in the CHT SoC.
---
Changes in v4:
-Replace Andy's Acked-by with his Reviewed-by
Changes in v2:
-Add Andy's Acked-by
-Add Heikki's Reviewed-by
--- drivers/platform/x86/intel_cht_int33fe.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/platform/x86/intel_cht_int33fe.c +24 -0
@@ -33,6 +33,8 @@ struct cht_int33fe_data {struct i2c_client *max17047;struct i2c_client *fusb302;struct i2c_client *pi3usb30532; +/* Contain a list-head must be per device */ +struct device_connection connections[3 ]; };/*
@@ -172,6 +174,20 @@ static int cht_int33fe_probe(struct i2c_client *client)return -EPROBE_DEFER ;/* Wait for i2c-adapter to load */ } + data->connections[0 ].endpoint[0 ] ="i2c-fusb302" ; + data->connections[0 ].endpoint[1 ] ="i2c-pi3usb30532" ; + data->connections[0 ].id ="typec-switch" ; + data->connections[1 ].endpoint[0 ] ="i2c-fusb302" ; + data->connections[1 ].endpoint[1 ] ="i2c-pi3usb30532" ; + data->connections[1 ].id ="typec-mux" ; + data->connections[2 ].endpoint[0 ] ="i2c-fusb302" ; + data->connections[2 ].endpoint[1 ] ="intel_xhci_usb_sw-role-switch" ; + data->connections[2 ].id ="usb-role-switch" ; + +device_connection_add (&data->connections[0 ]); +device_connection_add (&data->connections[1 ]); +device_connection_add (&data->connections[2 ]); +memset (&board_info,0 ,sizeof (board_info));strlcpy (board_info.type,"typec_fusb302" ,I2C_NAME_SIZE ); board_info.dev_name ="fusb302" ;
@@ -201,6 +217,10 @@ static int cht_int33fe_probe(struct i2c_client *client)if (data->max17047)i2c_unregister_device (data->max17047); +device_connection_remove (&data->connections[2 ]); +device_connection_remove (&data->connections[1 ]); +device_connection_remove (&data->connections[0 ]); +return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ }
@@ -213,6 +233,10 @@ static int cht_int33fe_remove(struct i2c_client *i2c)if (data->max17047)i2c_unregister_device (data->max17047); +device_connection_remove (&data->connections[2 ]); +device_connection_remove (&data->connections[1 ]); +device_connection_remove (&data->connections[0 ]); +return 0 ; }
Heikki Krogerus
maintainerPATCH v9 12/12 extcon: axp288: Set USB role where necessary
In reply to Heikki KrogerusFrom: Hans de Goede <[email protected]>
The AXP288 BC1.2 charger detection / extcon code may seem like a strange place to add code to control the USB role-switch on devices with an AXP288, but there are 2 reasons to do this inside the axp288 extcon code:
1) On many devices the USB role is controlled by ACPI AML code, but the AML code only switches between the host and none roles, because of Windows not really using device mode. To make device mode work we need to toggle between the none/device roles based on Vbus presence, and the axp288 extcon gets interrupts on Vbus insertion / removal.
2) In order for our BC1.2 charger detection to work properly the role mux must be properly set to device mode before we do the detection.
Also note the Kconfig help-text / obsolete depends on USB_PHY which are remnants from older never upstreamed code also controlling the mux from the axp288 extcon code.
This commit also adds code to get notifications from the INT3496 extcon device, which is used on some devices to notify the kernel about id-pin changes instead of them being handled through AML code.
This fixes:
-Device mode not working on most CHT devices with an AXP288 -Host mode not working on devices with an INT3496 ACPI device -Charger-type misdetection (always SDP) on devices with an INT3496 when the
USB role (always) gets initialized as host
---
Changes in v4:
-Add Andy's Reviewed-by
Changes in v2:
-Add depends on X86 to Kconfig (the AXP288 PMIC is only used on X86) -Use new acpi_dev_get_first_match_name() helper to get the INT3496 device-name -Add Heikki's Reviewed-by
--- drivers/extcon/Kconfig | 3 +- drivers/extcon/extcon-axp288.c | 176 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 170 insertions(+), 9 deletions(-)
drivers/extcon/Kconfig +2 -1
@@ -30,7 +30,8 @@ config EXTCON_ARIZONA config EXTCON_AXP288 tristate "X-Power AXP288 EXTCON support" - depends on MFD_AXP20X && USB_PHY + depends on MFD_AXP20X && USB_SUPPORT && X86 + select USB_ROLE_SWITCH help Say Y here to enable support for USB peripheral detection and USB MUX switching by X-Power AXP288 PMIC.
drivers/extcon/extcon-axp288.c +168 -8
260 lines not on this page · raw message
Re: [PATCH v9 12/12] extcon: axp288: Set USB role where necessary
Quoted 37 lines · Heikki Krogerus
From: Hans de Goede <[email protected]>
The AXP288 BC1.2 charger detection / extcon code may seem like a strange place to add code to control the USB role-switch on devices with an AXP288, but there are 2 reasons to do this inside the axp288 extcon code:
1) On many devices the USB role is controlled by ACPI AML code, but the AML code only switches between the host and none roles, because of Windows not really using device mode. To make device mode work we need to toggle between the none/device roles based on Vbus presence, and the axp288 extcon gets interrupts on Vbus insertion / removal.
2) In order for our BC1.2 charger detection to work properly the role mux must be properly set to device mode before we do the detection.
Also note the
Kconfighelp-text / obsolete depends onUSB_PHYwhich are remnants from older never upstreamed code also controlling the mux from the axp288 extcon code.This commit also adds code to get notifications from the INT3496 extcon device, which is used on some devices to notify the kernel about id-pin changes instead of them being handled through AML code.
This fixes:
(quoted diff) +0
-3-Device mode not working on most CHT devices with an AXP288 -Host mode not working on devices with an INT3496 ACPI device -Charger-type misdetection (always SDP) on devices with an INT3496 when the USB role (always) gets initialized as hostSigned-off-by Hans de Goede <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>---
Changes in v4:
-Add Andy's Reviewed-byChanges in v2:
Review
Quoted 7 lines
(quoted diff) +0
-4-Add depends on X86 to Kconfig (the AXP288 PMIC is only used on X86) -Use new acpi_dev_get_first_match_name() helper to get the INT3496 device-name -Add Heikki's Reviewed-by --- drivers/extcon/Kconfig | 3 +- drivers/extcon/extcon-axp288.c | 176 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 170 insertions(+), 9 deletions(-)
[snip]
Greg Kroah-Hartman
maintainerQuoted 5 lines · Heikki Krogerus
Hi,
This is version 9 of Hans' an my series introducing support for USB muxes, and generic device connection handling. The last version have been mostly about getting the first patch introducing the device connection handling right.
Nice work, all now applied to my tree.
greg k-h