USB Type-C device-connection, mux and switch support
Subsystems (12)
v2 cover USB Type-C device-connection, mux and switch support
Hi All,
Here is version 2 of Heikki's and my USB Type-C device-connection, mux and switch support series. Version 2 brings various small code and style fixes based on review of v1 (no major changes).
Here is the 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
PATCH v2 1/12 drivers: base: Unified device connection lookup
From: Heikki Krogerus <[email protected]>
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 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 | 139 +++++++++++++++++++++++++ include/linux/connection.h | 33 ++++++ 4 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 Documentation/driver-api/device_connection.rst create mode 100644 drivers/base/devcon.c create mode 100644 include/linux/connection.h
Documentation/driver-api/device_connection.rst new file +43 -0
@@ -0,0 +1,43 @@ +================== +Device connections +================== + +Introduction +------------ + +Devices have often connections to other devices that are out side 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 to for example 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 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 build-in. + +Usage +----- + +Device connections should exist before device ``->probe`` callback is called for +either endpoint devices in the description. If the connections are defined in +firmware, this is not a problem. It should be considered if the connection +descriptions are "build-in", and need to be added separately. + +The connection description consist 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 descriptions exist, 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_find_connection device_find_connection add_device_connection remove_device_connection
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 +139 -0
139 lines not on this page · raw message
include/linux/connection.h new file +33 -0
@@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0 + +#ifndef _LINUX_CONNECTION_H_ +#define _LINUX_CONNECTION_H_ + +#include <linux/list.h> + +struct device ; + +/** +* struct devcon - Device Connection Descriptor +* @endpoint: The names of the two devices connected together +* @id: Unique identifier for the connection +*/ +struct devcon { +const char *endpoint[2 ]; +const char *id; +struct list_head list; +}; + +void *__device_find_connection (struct device *dev,const char *con_id, +void *data, +void *(*match)(struct devcon *con,int ep, +void *data)); + +struct device *device_find_connection (struct device *dev,const char *con_id); + +#define DEVCON (_ep0, _ep1, _id) (struct devcon) { { _ep0, _ep1 }, _id, } + +void add_device_connection (struct devcon *con); +void remove_device_connection (struct devcon *con); + +#endif /* _LINUX_CONNECTION_H_ */
Randy Dunlap
reviewerRe: [PATCH v2 01/12] drivers: base: Unified device connection lookup
Quoted 35 lines · Hans de Goede
From: Heikki Krogerus <[email protected]>
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.
Signed-off-by Heikki Krogerus <[email protected]>Reviewed-by Hans de Goede <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:(quoted diff) +0
-2-Add a (struct devcon) cast to the DEVCON() macro --- Documentation/driver-api/device_connection.rst | 43 ++++++++ drivers/base/Makefile | 3 +- drivers/base/devcon.c | 139 +++++++++++++++++++++++++ include/linux/connection.h | 33 ++++++ 4 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 Documentation/driver-api/device_connection.rst create mode 100644 drivers/base/devcon.c create mode 100644 include/linux/connection.hDocumentation/driver-api/device_connection.rst new file +0
-0
Documentation/driver-api/device_connection.rst line 8
Quoted 8 lines
Documentation/driver-api/device_connection.rst new file +8
-0@@ -0,0 +1,43 @@ +================== +Device connections +================== + +Introduction +------------ + +Devices have often connections to other devices that are out side of the direct
Devices often have connections are outside of
Documentation/driver-api/device_connection.rst line 11
Quoted 3 lines
Documentation/driver-api/device_connection.rst new file +3
-0+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 to for example the I2C bus. Some device
could be attached for example to the I2C bus.
Documentation/driver-api/device_connection.rst line 19
Quoted 8 lines
Documentation/driver-api/device_connection.rst new file +8
-0+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 devices directly.
of the devices directly.
Documentation/driver-api/device_connection.rst line 22
Quoted 3 lines
Documentation/driver-api/device_connection.rst new file +3
-0+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 build-in.
built-in.
Documentation/driver-api/device_connection.rst line 28
Quoted 6 lines
Documentation/driver-api/device_connection.rst new file +6
-0+ +Usage +----- + +Device connections should exist before device ``->probe`` callback is called for +either endpoint devices in the description. If the connections are defined in
device
Documentation/driver-api/device_connection.rst line 30
Quoted 2 lines
Documentation/driver-api/device_connection.rst new file +2
-0+firmware, this is not a problem. It should be considered if the connection +descriptions are "build-in", and need to be added separately.
"built-in",
Documentation/driver-api/device_connection.rst line 32
Quoted 2 lines
Documentation/driver-api/device_connection.rst new file +2
-0+ +The connection description consist of the names of the two devices with the
consists
Documentation/driver-api/device_connection.rst line 36
Quoted 4 lines
Documentation/driver-api/device_connection.rst new file +4
-0+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 descriptions exist, the devices in it can request reference to the other
description exists,
Quoted 26 lines
Documentation/driver-api/device_connection.rst new file +7
-0+endpoint device, or they can request the description itself. + +API +--- + +.. kernel-doc:: drivers/base/devcon.c + : functions: __device_find_connection device_find_connection add_device_connection remove_device_connectiondrivers/base/devcon.c new file +12
-0@@ -0,0 +1,139 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* Device connections +* +* Copyright (C) 2018 Intel Corporation +* Author: Heikki Krogerus <[email protected]> +*/ + +#include <linux/connection.h> +#include <linux/device.h> + +static DEFINE_MUTEX (devcon_lock);
drivers/base/devcon.c line 22
Quoted 10 lines
drivers/base/devcon.c new file +10
-0+static LIST_HEAD (devcon_list); + +/** +* __device_find_connection - Find physical connection to a device +* @dev: Device with the connection +* @con_id: Identifier for the connection +* @data: Data for the match function +* @match: Function to check and convert the connection description +* +* Find a connection with unique identifier @con_id between @dev and an other
another
Quoted 60 lines
drivers/base/devcon.c new file +60
-0+* device. @match will be used to convert the connection description to data the +* caller is expecting to be returned. +*/ +void *__device_find_connection (struct device *dev,const char *con_id, +void *data, +void *(*match)(struct devcon *con,int ep, +void *data)) +{ +const char *devname =dev_name (dev); +struct devcon *con; +void *ret =NULL ; +int ep; + +if (!match) +return NULL ; + +rcu_read_lock (); + +list_for_each_entry_rcu (con, &devcon_list, list) { + ep =match_string (con->endpoint,2 , devname); +if (ep <0 ) +continue ; + +if (con_id &&strcmp (con->id, con_id)) +continue ; + + ret =match (con, !ep, data); +if (ret) +break ; + } + +rcu_read_unlock (); + +return ret; +} +EXPORT_SYMBOL_GPL (__device_find_connection); + +#include <linux/platform_device.h> +#include <linux/spi/spi.h> +#include <linux/i2c.h> +#include <linux/pci.h> + +static struct bus_type *generic_match_buses[] = { + &platform_bus_type, +#ifdef CONFIG_PCI + &pci_bus_type, +#endif +#ifdef CONFIG_I2C + &i2c_bus_type, +#endif +#ifdef CONFIG_SPI_MASTER + &spi_bus_type, +#endif +NULL , +}; + +/* This tries to find the device from the most common bus types by name. */ +static void *generic_match (struct devcon *con,int ep,void *data) +{ +struct bus_type *bus;
drivers/base/devcon.c line 92
Quoted 10 lines
drivers/base/devcon.c new file +10
-0+struct device *dev; + +for (bus = generic_match_buses[0 ]; bus; bus++) { + dev =bus_find_device_by_name (bus,NULL , con->endpoint[ep]); +if (dev) +return dev; + } + +/* +* We only get called if a connection was found, tell the caller to
found; tell
drivers/base/devcon.c line 93
Quoted 1 line
drivers/base/devcon.c new file +1
-0+* wait for the other device to show-up.
show up.
drivers/base/devcon.c line 103
Quoted 10 lines
drivers/base/devcon.c new file +10
-0+*/ +return ERR_PTR (-EPROBE_DEFER ); +} + +/** +* device_find_connection - Find two devices connected together +* @dev: Device with the connection +* @con_id: Identifier for the connection +* +* Find a connection with unique identifier @con_id between @dev and an
and
drivers/base/devcon.c line 104
Quoted 1 line
drivers/base/devcon.c new file +1
-0+* other device. On success returns handle to the device that is connected
another
Quoted 9 lines
drivers/base/devcon.c new file +9
-0+* to @dev, with the reference count for the found device incremented. Returns +* NULL if no matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a +* connection was found but the other device has not been enumerated yet. +*/ +struct device *device_find_connection (struct device *dev,const char *con_id) +{ +return __device_find_connection (dev, con_id, generic_match,NULL ); +} +EXPORT_SYMBOL_GPL (device_find_connection);
PATCH v2 2/12 usb: typec: Start using ERR_PTR
In reply to Hans de GoedeFrom: Heikki Krogerus <[email protected]>
In order to allow the USB Type-C Class driver take care of things like muxes and other possible dependencies for the port drivers, returning ERR_PTR instead of NULL from the registration functions in case of failure.
The reason for taking over control of the muxes for example is because handling them in the port drivers would be just boilerplate.
---
Changes in v2:
-Add IS_ERR_OR_NULL() checks to the unregister functions
--- drivers/usb/typec/tcpm.c | 16 +++++++++------- drivers/usb/typec/tps6598x.c | 15 ++++++++------- drivers/usb/typec/typec.c | 44 +++++++++++++++++++++---------------------- drivers/usb/typec/ucsi/ucsi.c | 31 ++++++++++++++++++------------ 4 files changed, 58 insertions(+), 48 deletions(-)
drivers/usb/typec/tcpm.c +9 -7
@@ -1044,7 +1044,7 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,break ;case CMDT_RSP_ACK :/* silently drop message if we are not connected */ -if (!port->partner) +if (IS_ERR_OR_NULL (port->partner))break ;switch (cmd) {
@@ -3743,8 +3743,8 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->port_type = tcpc->config->type; port->typec_port =typec_register_port (port->dev, &port->typec_caps); -if (!port->typec_port) { - err = -ENOMEM ; +if (IS_ERR (port->typec_port)) { + err =PTR_ERR (port->typec_port); goto out_destroy_wq; }
@@ -3753,15 +3753,17 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) i =0 ;while (paltmode->svid && i <ARRAY_SIZE (port->port_altmode)) { - port->port_altmode[i] = -typec_port_register_altmode (port->typec_port, - paltmode); -if (!port->port_altmode[i]) { +struct typec_altmode *alt; + + alt =typec_port_register_altmode (port->typec_port, + paltmode); +if (IS_ERR (alt)) {tcpm_log (port,"%s: failed to register port alternate mode 0x%x" ,dev_name (dev), paltmode->svid);break ; } + port->port_altmode[i] = alt; i++; paltmode++; }
drivers/usb/typec/tps6598x.c +8 -7
@@ -158,15 +158,15 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status) desc.identity = &tps->partner_identity; } - tps->partner =typec_register_partner (tps->port, &desc); -if (!tps->partner) -return -ENODEV ; -typec_set_pwr_opmode (tps->port, mode);typec_set_pwr_role (tps->port,TPS_STATUS_PORTROLE (status));typec_set_vconn_role (tps->port,TPS_STATUS_VCONN (status));typec_set_data_role (tps->port,TPS_STATUS_DATAROLE (status)); + tps->partner =typec_register_partner (tps->port, &desc); +if (IS_ERR (tps->partner)) +return PTR_ERR (tps->partner); +if (desc.identity)typec_partner_set_identity (tps->partner);
@@ -175,7 +175,8 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)static void tps6598x_disconnect (struct tps6598x *tps,u32 status) { -typec_unregister_partner (tps->partner); +if (!IS_ERR (tps->partner)) +typec_unregister_partner (tps->partner); tps->partner =NULL ;typec_set_pwr_opmode (tps->port,TYPEC_PWR_MODE_USB );typec_set_pwr_role (tps->port,TPS_STATUS_PORTROLE (status));
@@ -418,8 +419,8 @@ static int tps6598x_probe(struct i2c_client *client) tps->typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; tps->port =typec_register_port (&client->dev, &tps->typec_cap); -if (!tps->port) -return -ENODEV ; +if (IS_ERR (tps->port)) +return PTR_ERR (tps->port);if (status &TPS_STATUS_PLUG_PRESENT ) { ret =tps6598x_connect (tps, status);
drivers/usb/typec/typec.c +22 -22
174 lines not on this page · raw message
drivers/usb/typec/ucsi/ucsi.c +19 -12
@@ -260,38 +260,45 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)static int ucsi_register_partner (struct ucsi_connector *con) { -struct typec_partner_desc partner; +struct typec_partner_desc desc; +struct typec_partner *partner;if (con->partner)return 0 ; -memset (&partner,0 ,sizeof (partner)); +memset (&desc,0 ,sizeof (desc));switch (con->status.partner_type) {case UCSI_CONSTAT_PARTNER_TYPE_DEBUG : - partner.accessory =TYPEC_ACCESSORY_DEBUG ; + desc.accessory =TYPEC_ACCESSORY_DEBUG ;break ;case UCSI_CONSTAT_PARTNER_TYPE_AUDIO : - partner.accessory =TYPEC_ACCESSORY_AUDIO ; + desc.accessory =TYPEC_ACCESSORY_AUDIO ;break ;default :break ; } - partner.usb_pd = con->status.pwr_op_mode ==UCSI_CONSTAT_PWR_OPMODE_PD ; + desc.usb_pd = con->status.pwr_op_mode ==UCSI_CONSTAT_PWR_OPMODE_PD ; - con->partner =typec_register_partner (con->port, &partner); -if (!con->partner) { -dev_err (con->ucsi->dev,"con%d: failed to register partner\n" , - con->num); -return -ENODEV ; + partner =typec_register_partner (con->port, &desc); +if (IS_ERR (partner)) { +dev_err (con->ucsi->dev, +"con%d: failed to register partner (%ld)\n" , con->num, +PTR_ERR (partner)); +return PTR_ERR (partner); } + con->partner = partner; +return 0 ; }static void ucsi_unregister_partner (struct ucsi_connector *con) { +if (!con->partner) +return ; +typec_unregister_partner (con->partner); con->partner =NULL ; }
@@ -606,8 +613,8 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)/* Register the connector */ con->port =typec_register_port (ucsi->dev, cap); -if (!con->port) -return -ENODEV ; +if (IS_ERR (con->port)) +return PTR_ERR (con->port);/* Get the status */ UCSI_CMD_GET_CONNECTOR_STATUS (ctrl, con->num);
Re: [PATCH v2 02/12] usb: typec: Start using ERR_PTR
Quoted 7 lines · Hans de Goede
From: Heikki Krogerus <[email protected]>
In order to allow the USB Type-C Class driver take care of things like muxes and other possible dependencies for the port drivers, returning
ERR_PTRinstead of NULL from the registration functions in case of failure.
Quoted 7 lines
The reason for taking over control of the muxes for example is because handling them in the port drivers would be just boilerplate.
Signed-off-by Heikki Krogerus <[email protected]>Reviewed-by Hans de Goede <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Quoted 362 lines
---
Changes in v2:(quoted diff) +0
-2-Add IS_ERR_OR_NULL() checks to the unregister functions --- drivers/usb/typec/tcpm.c | 16 +++++++++------- drivers/usb/typec/tps6598x.c | 15 ++++++++------- drivers/usb/typec/typec.c | 44 +++++++++++++++++++++---------------------- drivers/usb/typec/ucsi/ucsi.c | 31 ++++++++++++++++++------------ 4 files changed, 58 insertions(+), 48 deletions(-)drivers/usb/typec/tcpm.c +9
-7@@ -1044,7 +1044,7 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,break ;case CMDT_RSP_ACK :/* silently drop message if we are not connected */ -if (!port->partner) +if (IS_ERR_OR_NULL (port->partner))break ;switch (cmd) {@@ -3743,8 +3743,8 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->port_type = tcpc->config->type; port->typec_port =typec_register_port (port->dev, &port->typec_caps); -if (!port->typec_port) { - err = -ENOMEM ; +if (IS_ERR (port->typec_port)) { + err =PTR_ERR (port->typec_port); goto out_destroy_wq; }@@ -3753,15 +3753,17 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) i =0 ;while (paltmode->svid && i <ARRAY_SIZE (port->port_altmode)) { - port->port_altmode[i] = -typec_port_register_altmode (port->typec_port, - paltmode); -if (!port->port_altmode[i]) { +struct typec_altmode *alt; + + alt =typec_port_register_altmode (port->typec_port, + paltmode); +if (IS_ERR (alt)) {tcpm_log (port,"%s: failed to register port alternate mode 0x%x" ,dev_name (dev), paltmode->svid);break ; } + port->port_altmode[i] = alt; i++; paltmode++; }drivers/usb/typec/tps6598x.c +8
-7@@ -158,15 +158,15 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status) desc.identity = &tps->partner_identity; } - tps->partner =typec_register_partner (tps->port, &desc); -if (!tps->partner) -return -ENODEV ; -typec_set_pwr_opmode (tps->port, mode);typec_set_pwr_role (tps->port,TPS_STATUS_PORTROLE (status));typec_set_vconn_role (tps->port,TPS_STATUS_VCONN (status));typec_set_data_role (tps->port,TPS_STATUS_DATAROLE (status)); + tps->partner =typec_register_partner (tps->port, &desc); +if (IS_ERR (tps->partner)) +return PTR_ERR (tps->partner); +if (desc.identity)typec_partner_set_identity (tps->partner);@@ -175,7 +175,8 @@ static int tps6598x_connect(struct tps6598x *tps, u32 status)static void tps6598x_disconnect (struct tps6598x *tps,u32 status) { -typec_unregister_partner (tps->partner); +if (!IS_ERR (tps->partner)) +typec_unregister_partner (tps->partner); tps->partner =NULL ;typec_set_pwr_opmode (tps->port,TYPEC_PWR_MODE_USB );typec_set_pwr_role (tps->port,TPS_STATUS_PORTROLE (status));@@ -418,8 +419,8 @@ static int tps6598x_probe(struct i2c_client *client) tps->typec_cap.prefer_role =TYPEC_NO_PREFERRED_ROLE ; tps->port =typec_register_port (&client->dev, &tps->typec_cap); -if (!tps->port) -return -ENODEV ; +if (IS_ERR (tps->port)) +return PTR_ERR (tps->port);if (status &TPS_STATUS_PLUG_PRESENT ) { ret =tps6598x_connect (tps, status);drivers/usb/typec/typec.c +22
-22@@ -386,7 +386,7 @@ typec_register_altmode(struct device *parent, alt =kzalloc (sizeof (*alt),GFP_KERNEL );if (!alt) -return NULL ; +return ERR_PTR (-ENOMEM ); alt->svid = desc->svid; alt->n_modes = desc->n_modes;@@ -402,7 +402,7 @@ typec_register_altmode(struct device *parent,dev_err (parent,"failed to register alternate mode (%d)\n" , ret);put_device (&alt->dev); -return NULL ; +return ERR_PTR (ret); }return alt;@@ -417,7 +417,7 @@ typec_register_altmode(struct device *parent,*/ void typec_unregister_altmode (struct typec_altmode *alt) { -if (alt) +if (!IS_ERR_OR_NULL (alt))device_unregister (&alt->dev); }EXPORT_SYMBOL_GPL (typec_unregister_altmode);@@ -509,7 +509,7 @@ EXPORT_SYMBOL_GPL(typec_partner_register_altmode);* * Registers a device for USB Type-C Partner described in @desc. * -* Returns handle to the partner on success or NULL on failure. +* Returns handle to the partner on success or ERR_PTR on failure. */ struct typec_partner *typec_register_partner (struct typec_port *port,struct typec_partner_desc *desc)@@ -519,7 +519,7 @@ struct typec_partner *typec_register_partner(struct typec_port *port, partner =kzalloc (sizeof (*partner),GFP_KERNEL );if (!partner) -return NULL ; +return ERR_PTR (-ENOMEM ); partner->usb_pd = desc->usb_pd; partner->accessory = desc->accessory;@@ -542,7 +542,7 @@ struct typec_partner *typec_register_partner(struct typec_port *port,if (ret) {dev_err (&port->dev,"failed to register partner (%d)\n" , ret);put_device (&partner->dev); -return NULL ; +return ERR_PTR (ret); }return partner;@@ -557,7 +557,7 @@ EXPORT_SYMBOL_GPL(typec_register_partner);*/ void typec_unregister_partner (struct typec_partner *partner) { -if (partner) +if (!IS_ERR_OR_NULL (partner))device_unregister (&partner->dev); }EXPORT_SYMBOL_GPL (typec_unregister_partner);@@ -587,7 +587,7 @@ static const struct device_type typec_plug_dev_type = {* the plug lists in response to Discover Modes command need to be listed in an * array in @desc. * -* Returns handle to the alternate mode on success or NULL on failure. +* Returns handle to the alternate mode on success or ERR_PTR on failure. */ struct typec_altmode * typec_plug_register_altmode(struct typec_plug *plug,@@ -606,7 +606,7 @@ EXPORT_SYMBOL_GPL(typec_plug_register_altmode);* Cable Plug represents a plug with electronics in it that can response to USB * Power Delivery SOP Prime or SOP Double Prime packages. * -* Returns handle to the cable plug on success or NULL on failure. +* Returns handle to the cable plug on success or ERR_PTR on failure. */ struct typec_plug *typec_register_plug (struct typec_cable *cable,struct typec_plug_desc *desc)@@ -617,7 +617,7 @@ struct typec_plug *typec_register_plug(struct typec_cable *cable, plug =kzalloc (sizeof (*plug),GFP_KERNEL );if (!plug) -return NULL ; +return ERR_PTR (-ENOMEM );sprintf (name,"plug%d" , desc->index);@@ -631,7 +631,7 @@ struct typec_plug *typec_register_plug(struct typec_cable *cable,if (ret) {dev_err (&cable->dev,"failed to register plug (%d)\n" , ret);put_device (&plug->dev); -return NULL ; +return ERR_PTR (ret); }return plug;@@ -646,7 +646,7 @@ EXPORT_SYMBOL_GPL(typec_register_plug);*/ void typec_unregister_plug (struct typec_plug *plug) { -if (plug) +if (!IS_ERR_OR_NULL (plug))device_unregister (&plug->dev); }EXPORT_SYMBOL_GPL (typec_unregister_plug);@@ -724,7 +724,7 @@ EXPORT_SYMBOL_GPL(typec_cable_set_identity);* Registers a device for USB Type-C Cable described in @desc. The cable will be * parent for the optional cable plug devises. * -* Returns handle to the cable on success or NULL on failure. +* Returns handle to the cable on success or ERR_PTR on failure. */ struct typec_cable *typec_register_cable (struct typec_port *port,struct typec_cable_desc *desc)@@ -734,7 +734,7 @@ struct typec_cable *typec_register_cable(struct typec_port *port, cable =kzalloc (sizeof (*cable),GFP_KERNEL );if (!cable) -return NULL ; +return ERR_PTR (-ENOMEM ); cable->type = desc->type; cable->active = desc->active;@@ -757,7 +757,7 @@ struct typec_cable *typec_register_cable(struct typec_port *port,if (ret) {dev_err (&port->dev,"failed to register cable (%d)\n" , ret);put_device (&cable->dev); -return NULL ; +return ERR_PTR (ret); }return cable;@@ -772,7 +772,7 @@ EXPORT_SYMBOL_GPL(typec_register_cable);*/ void typec_unregister_cable (struct typec_cable *cable) { -if (cable) +if (!IS_ERR_OR_NULL (cable))device_unregister (&cable->dev); }EXPORT_SYMBOL_GPL (typec_unregister_cable);@@ -1256,7 +1256,7 @@ EXPORT_SYMBOL_GPL(typec_set_pwr_opmode);* This routine is used to register an alternate mode that @port is capable of * supporting. * -* Returns handle to the alternate mode on success or NULL on failure. +* Returns handle to the alternate mode on success or ERR_PTR on failure. */ struct typec_altmode * typec_port_register_altmode(struct typec_port *port,@@ -1273,7 +1273,7 @@ EXPORT_SYMBOL_GPL(typec_port_register_altmode);* * Registers a device for USB Type-C Port described in @cap. * -* Returns handle to the port on success or NULL on failure. +* Returns handle to the port on success or ERR_PTR on failure. */ struct typec_port *typec_register_port (struct device *parent,const struct typec_capability *cap)@@ -1285,12 +1285,12 @@ struct typec_port *typec_register_port(struct device *parent, port =kzalloc (sizeof (*port),GFP_KERNEL );if (!port) -return NULL ; +return ERR_PTR (-ENOMEM ); id =ida_simple_get (&typec_index_ida,0 ,0 ,GFP_KERNEL );if (id <0 ) {kfree (port); -return NULL ; +return ERR_PTR (id); }if (cap->type ==TYPEC_PORT_DFP )@@ -1326,7 +1326,7 @@ struct typec_port *typec_register_port(struct device *parent,if (ret) {dev_err (parent,"failed to register port (%d)\n" , ret);put_device (&port->dev); -return NULL ; +return ERR_PTR (ret); }return port;@@ -1341,7 +1341,7 @@ EXPORT_SYMBOL_GPL(typec_register_port);*/ void typec_unregister_port (struct typec_port *port) { -if (port) +if (!IS_ERR_OR_NULL (port))device_unregister (&port->dev); }EXPORT_SYMBOL_GPL (typec_unregister_port);drivers/usb/typec/ucsi/ucsi.c +17
-10@@ -260,38 +260,45 @@ static void ucsi_pwr_opmode_change(struct ucsi_connector *con)static int ucsi_register_partner (struct ucsi_connector *con) { -struct typec_partner_desc partner; +struct typec_partner_desc desc; +struct typec_partner *partner;if (con->partner)return 0 ; -memset (&partner,0 ,sizeof (partner)); +memset (&desc,0 ,sizeof (desc));switch (con->status.partner_type) {case UCSI_CONSTAT_PARTNER_TYPE_DEBUG : - partner.accessory =TYPEC_ACCESSORY_DEBUG ; + desc.accessory =TYPEC_ACCESSORY_DEBUG ;break ;case UCSI_CONSTAT_PARTNER_TYPE_AUDIO : - partner.accessory =TYPEC_ACCESSORY_AUDIO ; + desc.accessory =TYPEC_ACCESSORY_AUDIO ;break ;default :break ; } - partner.usb_pd = con->status.pwr_op_mode ==UCSI_CONSTAT_PWR_OPMODE_PD ; + desc.usb_pd = con->status.pwr_op_mode ==UCSI_CONSTAT_PWR_OPMODE_PD ; - con->partner =typec_register_partner (con->port, &partner); -if (!con->partner) { -dev_err (con->ucsi->dev,"con%d: failed to register partner\n" , - con->num); -return -ENODEV ; + partner =typec_register_partner (con->port, &desc); +if (IS_ERR (partner)) { +dev_err (con->ucsi->dev, +"con%d: failed to register partner (%ld)\n" , con->num, +PTR_ERR (partner)); +return PTR_ERR (partner); } + con->partner = partner; +return 0 ; }static void ucsi_unregister_partner (struct ucsi_connector *con) { +if (!con->partner) +return ; +typec_unregister_partner (con->partner); con->partner =NULL ; }
drivers/usb/typec/ucsi/ucsi.c static int ucsi_register_port(struct ucsi *ucsi, int index) · line 620
Quoted 10 lines
drivers/usb/typec/ucsi/ucsi.c +2
-2@@ -606,8 +613,8 @@ static int ucsi_register_port(struct ucsi *ucsi, int index)/* Register the connector */ con->port =typec_register_port (ucsi->dev, cap); -if (!con->port) -return -ENODEV ; +if (IS_ERR (con->port)) +return PTR_ERR (con->port);/* Get the status */ UCSI_CMD_GET_CONNECTOR_STATUS (ctrl, con->num);
---
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
PATCH v2 3/12 usb: typec: API for controlling USB Type-C Multiplexers
In reply to Hans de GoedeFrom: Heikki Krogerus <[email protected]>
USB 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.
---
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 | 188 +++++++++++++++++++++++++++++++++
include/linux/usb/typec.h | 14 +++
include/linux/usb/typec_mux.h | 55 ++++++++++
6 files changed, 390 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, an other 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 of the orientation, and the +alternate mode drivers of 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 +188 -0
188 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
Randy Dunlap
reviewerRe: [PATCH v2 03/12] usb: typec: API for controlling USB Type-C Multiplexers
Quoted 18 lines · Hans de Goede
From: Heikki Krogerus <[email protected]>
--- 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 | 188 +++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 14 +++ include/linux/usb/typec_mux.h | 55 ++++++++++ 6 files changed, 390 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 +0
-0
Documentation/driver-api/usb/typec.rst own functions, but the registration will always return a handle to struct · line 190
Quoted 8 lines
Documentation/driver-api/usb/typec.rst +8
-0+ +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, an other switch is needed that can
another
Documentation/driver-api/usb/typec.rst own functions, but the registration will always return a handle to struct · line 198
Quoted 8 lines
Documentation/driver-api/usb/typec.rst +8
-0+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 of the orientation, and the
for the orientation,
Quoted 1 line
+alternate mode drivers of the mode, the two are always separated into their own
for the mode,
Quoted 43 lines
Documentation/driver-api/usb/typec.rst +34
-0+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/mux.c new file +2
-0@@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0 +/**
drivers/usb/typec/mux.c line 12
Quoted 10 lines
drivers/usb/typec/mux.c new file +10
-0+* USB Type-C Multiplexer/DeMultiplexer Switch support +* +* Copyright (C) 2018 Intel Corporation +* Author: Heikki Krogerus <[email protected]> +* Hans de Goede <[email protected]> +*/ + +#include <linux/device.h> +#include <linux/connection.h> +#include <linux/usb/typec_mux.h>
Needs: <linux/mutex.h> <linux/list.h> ...
Quoted 6 lines
drivers/usb/typec/mux.c new file +6
-0+static DEFINE_MUTEX (switch_lock); +static DEFINE_MUTEX (mux_lock); +static LIST_HEAD (switch_list); +static LIST_HEAD (mux_list); + +static void *typec_switch_match (struct devcon *con,int ep,void *data)
drivers/usb/typec/mux.c line 29
Quoted 10 lines
drivers/usb/typec/mux.c new file +10
-0+{ +struct typec_switch *sw; + +list_for_each_entry (sw, &switch_list, entry) +if (!strcmp (con->endpoint[ep],dev_name (sw->dev))) +return sw; + +/* +* We only get called if a connection was found, tell the caller to +* wait for the switch to show-up.
show up.
Quoted 7 lines
drivers/usb/typec/mux.c new file +5
-0+*/ +return ERR_PTR (-EPROBE_DEFER ); +} + +static void *typec_mux_match (struct devcon *con,int ep,void *data)
drivers/usb/typec/mux.c line 116
Quoted 10 lines
drivers/usb/typec/mux.c new file +10
-0+{ +struct typec_mux *mux; + +list_for_each_entry (mux, &mux_list, entry) +if (!strcmp (con->endpoint[ep],dev_name (mux->dev))) +return mux; + +/* +* We only get called if a connection was found, tell the caller to +* wait for the switch to show-up.
show up.
Quoted 12 lines
drivers/usb/typec/mux.c new file +3
-0+*/ +return ERR_PTR (-EPROBE_DEFER ); +}include/linux/usb/typec_mux.h new file +2
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0 +
include/linux/usb/typec_mux.h line 12
Quoted 10 lines
include/linux/usb/typec_mux.h new file +10
-0+#ifndef __USB_TYPEC_MUX +#define __USB_TYPEC_MUX + +#include <linux/list.h> +#include <linux/usb/typec.h> + +struct device ; + +/** +* typec_switch - USB Type-C cable orientation switch
* struct typec_switch - USB Type-C cable orientation switch
Quoted 7 lines
include/linux/usb/typec_mux.h new file +7
-0+* @dev: Switch device +* @entry: List entry +* @set: Callback to the driver for setting the orientation +* +* USB Type-C pin flipper switch routing the correct data pairs from the +* connector to the USB controller depending on the orientation of the cable +* plug.
include/linux/usb/typec_mux.h line 29
Quoted 10 lines
include/linux/usb/typec_mux.h new file +10
-0+*/ +struct typec_switch { +struct device *dev; +struct list_head entry; + +int (*set)(struct typec_switch *sw,enum typec_orientation orientation); +}; + +/** +* typec_switch - USB Type-C connector pin mux
* struct typec_mux - USB Type-C connector pin mux
Quoted 4 lines
include/linux/usb/typec_mux.h new file +4
-0+* @dev: Mux device +* @entry: List entry +* @set: Callback to the driver for setting the state of the mux +*
include/linux/usb/typec_mux.h line 43
Quoted 10 lines
include/linux/usb/typec_mux.h new file +10
-0+* Pin Multiplexer/DeMultiplexer switch routing the USB Type-C connector pins to +* different components depending on the requested mode of operation. Used with +* Accessory/Alternate modes. +*/ +struct typec_mux { +struct device *dev; +struct list_head entry; + +int (*set)(struct typec_mux *mux,int state); +};
ta.
PATCH v2 4/12 usb: common: Small class for USB role switches
In reply to Hans de GoedeFrom: Heikki Krogerus <[email protected]>
USB 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 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 | 51 +++++ 5 files changed, 381 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 +51 -0
51 lines not on this page · raw message
PATCH v2 5/12 usb: typec: tcpm: Set USB role switch to device mode when configured as such
In reply to Hans de GoedeSetting 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 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
@@ -618,15 +618,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;
@@ -742,14 +742,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;
@@ -2096,7 +2097,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; }
@@ -2140,6 +2141,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 ;
@@ -2190,8 +2192,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"
@@ -97,11 +98,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 */
@@ -118,7 +114,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;
Re: [PATCH v2 05/12] usb: typec: tcpm: Set USB role switch to device mode when configured as such
Quoted 14 lines · Hans de Goede
Setting the mux to
MUX_NONEand the switch toUSB_SWITCH_DISCONNECTwhen 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_HOSTandUSB_SWITCH_DEVICE. Rather then modifying thetcpc_usb_switchenum for this, simply remove it and switch to theusb_roleenum 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_roletype, this commit also actually sets the mux toTYPEC_MUX_USBand the switch toUSB_ROLE_DEVICEinstead of setting both to none when the data-role is device.
Quoted 6 lines
This commit also makes
tcpm_reset_port()calltcpm_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.Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Quoted 104 lines
---
Changes in v2:(quoted diff) +0
-2-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@@ -618,15 +618,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;@@ -742,14 +742,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;@@ -2096,7 +2097,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; }@@ -2140,6 +2141,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 ;@@ -2190,8 +2192,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 +1
-5@@ -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" @@ -97,11 +98,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 */
include/linux/usb/tcpm.h enum tcpc_mux_mode { · line 120
Quoted 8 lines
include/linux/usb/tcpm.h +1
-1@@ -118,7 +114,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;
---
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
PATCH v2 6/12 usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions
In reply to Hans de GoedeRemove 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 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
@@ -1249,7 +1249,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"
@@ -112,14 +111,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
@@ -171,7 +162,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 ;
Re: [PATCH v2 06/12] usb: typec: tcpm: Use new Type-C switch/mux and usb-role-switch functions
Quoted 6 lines · Hans de Goede
Remove the unused (not implemented anywhere)
tcpc_mux_devabstraction and replace it with calling the newtypec_set_orientation,usb_role_switch_setandtypec_set_modefunctions.Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Quoted 181 lines
---
Changes in v2:(quoted diff) +0
-2-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@@ -1249,7 +1249,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@@ -20,6 +20,7 @@#include <linux/usb/pd.h> #include <linux/usb/pd_bdo.h> #include <linux/usb/pd_vdo.h> +#include <linux/usb/role.h> #include <linux/usb/tcpm.h> #include <linux/usb/typec.h> #include <linux/workqueue.h> @@ -176,6 +177,7 @@ struct tcpm_port {struct typec_port *typec_port;struct tcpc_dev *tcpc; +struct usb_role_switch *role_sw;enum typec_role vconn_role;enum typec_role pwr_role;@@ -618,18 +620,25 @@ 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 usb_role usb_role) +enum usb_role usb_role, +enum typec_orientation orientation) { -int ret =0 ; +int ret; -tcpm_log (port,"Requesting mux mode %d, usb-role %d, polarity %d" , - mode, usb_role, port->polarity); +tcpm_log (port,"Requesting mux mode %d, usb-role %d, orientation %d" , + mode, usb_role, orientation); -if (port->tcpc->mux) - ret = port->tcpc->mux->set (port->tcpc->mux, mode, usb_role, - port->polarity); + ret =typec_set_orientation (port->typec_port, orientation); +if (ret) +return ret; -return ret; +if (port->role_sw) { + ret =usb_role_switch_set_role (port->role_sw, usb_role); +if (ret) +return ret; + } + +return typec_set_mode (port->typec_port, mode); } static int tcpm_set_polarity(struct tcpm_port *port,@@ -742,15 +751,21 @@ 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 typec_orientation orientation;enum usb_role usb_role;int ret; +if (port->polarity ==TYPEC_POLARITY_CC1 ) + orientation =TYPEC_ORIENTATION_NORMAL ; +else + orientation =TYPEC_ORIENTATION_REVERSE ; +if (data ==TYPEC_HOST ) usb_role =USB_ROLE_HOST ;else usb_role =USB_ROLE_DEVICE ; - ret =tcpm_mux_set (port,TYPEC_MUX_USB , usb_role); + ret =tcpm_mux_set (port,TYPEC_MUX_USB , usb_role, orientation);if (ret <0 )return ret;@@ -2097,7 +2112,8 @@ 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 ,USB_ROLE_NONE ); +tcpm_mux_set (port,TYPEC_MUX_NONE ,USB_ROLE_NONE , +TYPEC_ORIENTATION_NONE );return ret; }@@ -2141,7 +2157,8 @@ 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_mux_set (port,TYPEC_MUX_NONE ,USB_ROLE_NONE , +TYPEC_ORIENTATION_NONE );tcpm_set_attached_state (port, false); port->try_src_count =0 ; port->try_snk_count =0 ;@@ -3742,6 +3759,12 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) port->partner_desc.identity = &port->partner_ident; port->port_type = tcpc->config->type; + port->role_sw =usb_role_switch_get (port->dev); +if (IS_ERR (port->role_sw)) { + err =PTR_ERR (port->role_sw); + goto out_destroy_wq; + } + port->typec_port =typec_register_port (port->dev, &port->typec_caps);if (IS_ERR (port->typec_port)) { err =PTR_ERR (port->typec_port);@@ -3777,6 +3800,7 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)return port; out_destroy_wq: +usb_role_switch_put (port->role_sw);destroy_workqueue (port->wq);return ERR_PTR (err); }include/linux/usb/tcpm.h +0
-9@@ -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" @@ -112,14 +111,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
include/linux/usb/tcpm.h struct tcpc_dev { · line 167
Quoted 7 lines
include/linux/usb/tcpm.h +0
-1@@ -171,7 +162,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 ;
---
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
PATCH v2 7/12 xhci: Add option to get next extended capability in list by passing id = 0
In reply to Hans de GoedeFrom: 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 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);
PATCH v2 8/12 xhci: Add Intel extended cap / otg phy mux handling
In reply to Hans de GoedeThe 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 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
@@ -164,6 +164,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 ||
@@ -297,6 +298,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
@@ -1825,6 +1825,7 @@ struct xhci_hcd {/* Reserved. It was XHCI_U2_DISABLE_WAKE */ #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL (1 << 28)#define XHCI_HW_LPM_DISABLE (1 << 29) +#define XHCI_INTEL_USB_ROLE_SW (1 << 30)unsigned int num_active_eps;unsigned int limit_active_eps;
@@ -2020,6 +2021,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);
PATCH v2 9/12 usb: roles: Add Intel xHCI USB role switch driver
In reply to Hans de GoedeVarious 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 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
@@ -14395,6 +14395,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
Randy Dunlap
reviewerRe: [PATCH v2 09/12] usb: roles: Add Intel xHCI USB role switch driver
Quoted 8 lines · Hans de Goede
drivers/usb/roles/Kconfig new file +2
-0@@ -0,0 +1,14 @@ +if USB_ROLE_SWITCH +
drivers/usb/roles/Kconfig line 12
Quoted 10 lines
drivers/usb/roles/Kconfig new file +10
-0+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.
Wow. I hope that I never have to load that driver by hand. :)
PATCH v2 10/12 usb: typec: driver for Pericom PI3USB30532 Type-C cross switch
In reply to Hans de GoedeAdd a driver for the Pericom PI3USB30532 Type-C cross switch / mux chip found on some devices with a Type-C port.
---
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
@@ -14531,6 +14531,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
PATCH v2 11/12 platform/x86: intel_cht_int33fe: Add device connections for the Type-C port
In reply to Hans de GoedeWe 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 v2:
-Add Andy's Acked-by
-Add Heikki's Reviewed-by
--- drivers/platform/x86/intel_cht_int33fe.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/platform/x86/intel_cht_int33fe.c +25 -0
@@ -21,6 +21,7 @@*/ #include <linux/acpi.h> +#include <linux/connection.h> #include <linux/i2c.h> #include <linux/interrupt.h> #include <linux/module.h>
@@ -33,6 +34,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 devcon connections[3 ]; };/*
@@ -172,6 +175,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" ; + +add_device_connection (&data->connections[0 ]); +add_device_connection (&data->connections[1 ]); +add_device_connection (&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 +218,10 @@ static int cht_int33fe_probe(struct i2c_client *client)if (data->max17047)i2c_unregister_device (data->max17047); +remove_device_connection (&data->connections[2 ]); +remove_device_connection (&data->connections[1 ]); +remove_device_connection (&data->connections[0 ]); +return -EPROBE_DEFER ;/* Wait for the i2c-adapter to load */ }
@@ -213,6 +234,10 @@ static int cht_int33fe_remove(struct i2c_client *i2c)if (data->max17047)i2c_unregister_device (data->max17047); +remove_device_connection (&data->connections[2 ]); +remove_device_connection (&data->connections[1 ]); +remove_device_connection (&data->connections[0 ]); +return 0 ; }
PATCH v2 12/12 extcon: axp288: Set USB role where necessary
In reply to Hans de GoedeThe 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 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 | 177 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 171 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 +169 -8
261 lines not on this page · raw message
Randy Dunlap
reviewerRe: [PATCH v2 12/12] extcon: axp288: Set USB role where necessary
Hi,
drivers/extcon/Kconfig config EXTCON_ARIZONA · line 33
Quoted 10 lines · Hans de Goede
drivers/extcon/Kconfig +1
-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
Could that be:
depends on MFD_AXP20X && USB_SUPPORT && (X86 || COMPILE_TEST)
or is there some reason that it won't even build on other $ARCH?
drivers/extcon/Kconfig config EXTCON_ARIZONA · line 37
Quoted 4 lines
drivers/extcon/Kconfig +1
-0+ select USB_ROLE_SWITCH help Say Y here to enable support for USB peripheral detection and USB MUX switching by X-Power AXP288 PMIC.
thanks,
Re: [PATCH v2 12/12] extcon: axp288: Set USB role where necessary
Hi,
Quoted 16 lines · Randy Dunlap
Hi,
drivers/extcon/Kconfig config EXTCON_ARIZONA · line 33
Quoted 10 lines · Hans de Goede
drivers/extcon/Kconfig +1
-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 && X86Could that be:
Quoted 3 lines
depends on MFD_AXP20X && USB_SUPPORT && (X86 || COMPILE_TEST)or is there some reason that it won't even build on other $ARCH?
It uses:
#include <asm/cpu_device_id.h>
#include <asm/intel-family.h>
So it really should only be build on X86, it always was an X86 only driver, but it now it really depends on X86.
Thank you for all the reviews. I will prepare a v3 with all your proposed fixes soon(ish).
Regards,
Hans
Quoted 7 lines
drivers/extcon/Kconfig config EXTCON_ARIZONA · line 37
Quoted 4 lines
drivers/extcon/Kconfig +1
-0+ select USB_ROLE_SWITCH help Say Y here to enable support for USB peripheral detection and USB MUX switching by X-Power AXP288 PMIC.thanks,
---
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