usb: typec: Support for Alternate Modes
Subsystems (7)
Heikki Krogerus
maintainerRFC PATCH v4 1/8 usb: pd: include kernel.h
In reply to Heikki KrogerusSome of the macros use le16_to_cpu().
--- include/linux/usb/pd.h | 1 + 1 file changed, 1 insertion(+)
include/linux/usb/pd.h +1 -0
@@ -15,6 +15,7 @@#ifndef __LINUX_USB_PD_H#define __LINUX_USB_PD_H +#include <linux/kernel.h> #include <linux/types.h> #include <linux/usb/typec.h>
Heikki Krogerus
maintainerRFC PATCH v4 2/8 usb: typec: helper for checking cable plug orientation
In reply to Heikki KrogerusThis adds function typec_get_orientation() that can be used for checking the current cable plug orientation.
--- drivers/usb/typec/class.c | 11 +++++++++++ include/linux/usb/typec.h | 1 + 2 files changed, 12 insertions(+)
drivers/usb/typec/class.c +11 -0
@@ -1279,6 +1279,17 @@ int typec_set_orientation(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_set_orientation); +/** +* typec_get_orientation - Get USB Type-C cable plug orientation +* @port: USB Type-C Port +* +* Get current cable plug orientation for @port. +*/ +enum typec_orientation typec_get_orientation (struct typec_port *port) +{ +return port->orientation; +} +/** * typec_set_mode - Set mode of operation for USB Type-C connector * @port: USB Type-C port for the connector
include/linux/usb/typec.h +1 -0
@@ -265,6 +265,7 @@ 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); +enum typec_orientation typec_get_orientation (struct typec_port *port);int typec_set_mode (struct typec_port *port,int mode);#endif /* __LINUX_USB_TYPEC_H */
Heikki Krogerus
maintainerRFC PATCH v4 3/8 usb: typec: mux: Get the mux identifier from function parameter
In reply to Heikki KrogerusIn order for the muxes to be usable with alternate modes, the alternate mode devices will need also to be able to get a handle to the muxes on top of the port devices. To make that possible, the muxes need to be possible to request with an identifier.
This will change the API so that the mux identifier is given as a function parameter to typec_mux_get(), and the hard-coded "typec-mux" is replaced with that value.
--- drivers/usb/typec/class.c | 2 +- drivers/usb/typec/mux.c | 6 +++--- include/linux/usb/typec_mux.h | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/usb/typec/class.c +1 -1
@@ -1356,7 +1356,7 @@ struct typec_port *typec_register_port(struct device *parent, goto err_switch; } - port->mux =typec_mux_get (cap->fwnode ? &port->dev : parent); + port->mux =typec_mux_get (parent,"typec-mux" );if (IS_ERR (port->mux)) { ret =PTR_ERR (port->mux); goto err_mux;
drivers/usb/typec/mux.c +3 -3
@@ -123,19 +123,19 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data)/** * typec_mux_get - Find USB Type-C Multiplexer * @dev: The caller device +* @name: Mux identifier * * Finds a mux linked to the caller. This function is primarily meant for the * Type-C drivers. Returns a reference to the mux on success, NULL if no * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection * was found but the mux has not been enumerated yet. */ -struct typec_mux *typec_mux_get (struct device *dev) +struct typec_mux *typec_mux_get (struct device *dev,const char *name) {struct typec_mux *mux;mutex_lock (&mux_lock); - mux =device_connection_find_match (dev,"typec-mux" ,NULL , - typec_mux_match); + mux =device_connection_find_match (dev, name,NULL , typec_mux_match);if (!IS_ERR_OR_NULL (mux))get_device (mux->dev);mutex_unlock (&mux_lock);
include/linux/usb/typec_mux.h +1 -1
@@ -47,7 +47,7 @@ void typec_switch_put(struct typec_switch *sw);int typec_switch_register (struct typec_switch *sw);void typec_switch_unregister (struct typec_switch *sw); -struct typec_mux *typec_mux_get (struct device *dev); +struct typec_mux *typec_mux_get (struct device *dev,const char *name);void typec_mux_put (struct typec_mux *mux);int typec_mux_register (struct typec_mux *mux);void typec_mux_unregister (struct typec_mux *mux);
Heikki Krogerus
maintainerRFC PATCH v4 4/8 usb: typec: Register a device for every mode
In reply to Heikki KrogerusBefore a device was created for every discovered SVID, but this will create a device for every discovered mode of every SVID. The idea is to make it easier to create mode specific drivers once a bus for the alternate mode is added.
--- drivers/usb/typec/class.c | 172 ++++++++++++-------------------------- drivers/usb/typec/tcpm.c | 45 +++++----- include/linux/usb/typec.h | 37 ++------ 3 files changed, 83 insertions(+), 171 deletions(-)
drivers/usb/typec/class.c +54 -118
@@ -13,31 +13,20 @@#include <linux/usb/typec.h> #include <linux/usb/typec_mux.h> -struct typec_mode { -int index; +struct typec_altmode { +struct device dev; +u16 svid; +u8 mode; +u32 vdo;char *desc;enum typec_port_type roles; - -struct typec_altmode *alt_mode; -unsigned int active:1 ; +struct attribute *attrs[5 ];char group_name[6 ];struct attribute_group group; -struct attribute *attrs[5 ]; -struct device_attribute vdo_attr; -struct device_attribute desc_attr; -struct device_attribute active_attr; -struct device_attribute roles_attr; -}; - -struct typec_altmode { -struct device dev; -u16 svid; -int n_modes; -struct typec_mode modes[ALTMODE_MAX_MODES ]; -const struct attribute_group *mode_groups[ALTMODE_MAX_MODES ]; +const struct attribute_group *groups[2 ]; };struct typec_plug {
@@ -177,23 +166,20 @@ static void typec_report_identity(struct device *dev)/** * typec_altmode_update_active - Report Enter/Exit mode * @alt: Handle to the alternate mode -* @mode: Mode index * @active: True when the mode has been entered * * If a partner or cable plug executes Enter/Exit Mode command successfully, the * drivers use this routine to report the updated state of the mode. */ -void typec_altmode_update_active (struct typec_altmode *alt,int mode, -bool active) +void typec_altmode_update_active (struct typec_altmode *alt,bool active) { -struct typec_mode *m = &alt->modes[mode];char dir[6 ]; -if (m->active == active) +if (alt->active == active)return ; - m->active = active; -snprintf (dir,sizeof (dir),"mode%d" , mode); + alt->active = active; +snprintf (dir,sizeof (dir),"mode%d" , alt->mode);sysfs_notify (&alt->dev.kobj, dir,"active" );kobject_uevent (&alt->dev.kobj,KOBJ_CHANGE ); }
@@ -220,42 +206,36 @@ struct typec_port *typec_altmode2port(struct typec_altmode *alt)EXPORT_SYMBOL_GPL (typec_altmode2port);static ssize_t -typec_altmode_vdo_show (struct device *dev,struct device_attribute *attr, -char *buf) +vdo_show (struct device *dev,struct device_attribute *attr,char *buf) { - struct typec_mode *mode = container_of(attr, struct typec_mode, - vdo_attr); +struct typec_altmode *alt =to_altmode (dev); -return sprintf (buf,"0x%08x\n" , mode->vdo); +return sprintf (buf,"0x%08x\n" , alt->vdo); } +static DEVICE_ATTR_RO (vdo);static ssize_t -typec_altmode_desc_show (struct device *dev,struct device_attribute *attr, -char *buf) +description_show (struct device *dev,struct device_attribute *attr,char *buf) { - struct typec_mode *mode = container_of(attr, struct typec_mode, - desc_attr); +struct typec_altmode *alt =to_altmode (dev); -return sprintf (buf,"%s\n" , mode->desc ? mode->desc :"" ); +return sprintf (buf,"%s\n" , alt->desc ? alt->desc :"" ); } +static DEVICE_ATTR_RO (description);static ssize_t -typec_altmode_active_show (struct device *dev,struct device_attribute *attr, -char *buf) +active_show (struct device *dev,struct device_attribute *attr,char *buf) { - struct typec_mode *mode = container_of(attr, struct typec_mode, - active_attr); +struct typec_altmode *alt =to_altmode (dev); -return sprintf (buf,"%s\n" , mode->active ?"yes" :"no" ); +return sprintf (buf,"%s\n" , alt->active ?"yes" :"no" ); } -static ssize_t -typec_altmode_active_store (struct device *dev,struct device_attribute *attr, -const char *buf,size_t size) +static ssize_t active_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t size) { - struct typec_mode *mode = container_of(attr, struct typec_mode, - active_attr); -struct typec_port *port =typec_altmode2port (mode->alt_mode); +struct typec_altmode *alt =to_altmode (dev); +struct typec_port *port =typec_altmode2port (alt);bool activate;int ret;
@@ -266,22 +246,22 @@ typec_altmode_active_store(struct device *dev, struct device_attribute *attr,if (ret)return ret; - ret = port->cap->activate_mode (port->cap, mode->index, activate); + ret = port->cap->activate_mode (port->cap, alt->mode, activate);if (ret)return ret;return size; } +static DEVICE_ATTR_RW (active);static ssize_t -typec_altmode_roles_show (struct device *dev,struct device_attribute *attr, -char *buf) +supported_roles_show (struct device *dev,struct device_attribute *attr, +char *buf) { - struct typec_mode *mode = container_of(attr, struct typec_mode, - roles_attr); +struct typec_altmode *alt =to_altmode (dev);ssize_t ret; -switch (mode->roles) { +switch (alt->roles) {case TYPEC_PORT_SRC : ret =sprintf (buf,"source\n" );break ;
@@ -295,61 +275,13 @@ typec_altmode_roles_show(struct device *dev, struct device_attribute *attr, }return ret; } +static DEVICE_ATTR_RO (supported_roles); -static void typec_init_modes (struct typec_altmode *alt, -const struct typec_mode_desc *desc,bool is_port) +static void typec_altmode_release (struct device *dev) { -int i; - -for (i =0 ; i < alt->n_modes; i++, desc++) { -struct typec_mode *mode = &alt->modes[i]; - -/* Not considering the human readable description critical */ - mode->desc =kstrdup (desc->desc,GFP_KERNEL ); -if (desc->desc && !mode->desc) -dev_err (&alt->dev,"failed to copy mode%d desc\n" , i); - - mode->alt_mode = alt; - mode->vdo = desc->vdo; - mode->roles = desc->roles; - mode->index = desc->index; -sprintf (mode->group_name,"mode%d" , desc->index); - -sysfs_attr_init (&mode->vdo_attr.attr); - mode->vdo_attr.attr.name ="vdo" ; - mode->vdo_attr.attr.mode =0444 ; - mode->vdo_attr.show = typec_altmode_vdo_show; - -sysfs_attr_init (&mode->desc_attr.attr); - mode->desc_attr.attr.name ="description" ; - mode->desc_attr.attr.mode =0444 ; - mode->desc_attr.show = typec_altmode_desc_show; - -sysfs_attr_init (&mode->active_attr.attr); - mode->active_attr.attr.name ="active" ; - mode->active_attr.attr.mode =0644 ; - mode->active_attr.show = typec_altmode_active_show; - mode->active_attr.store = typec_altmode_active_store; - - mode->attrs[0 ] = &mode->vdo_attr.attr; - mode->attrs[1 ] = &mode->desc_attr.attr; - mode->attrs[2 ] = &mode->active_attr.attr; - -/* With ports, list the roles that the mode is supported with */ -if (is_port) { -sysfs_attr_init (&mode->roles_attr.attr); - mode->roles_attr.attr.name ="supported_roles" ; - mode->roles_attr.attr.mode =0444 ; - mode->roles_attr.show = typec_altmode_roles_show; - - mode->attrs[3 ] = &mode->roles_attr.attr; - } - - mode->group.attrs = mode->attrs; - mode->group.name = mode->group_name; +struct typec_altmode *alt =to_altmode (dev); - alt->mode_groups[i] = &mode->group; - } +kfree (alt); } static ssize_t svid_show(struct device *dev, struct device_attribute *attr,
@@ -367,16 +299,6 @@ static struct attribute *typec_altmode_attrs[] = { };ATTRIBUTE_GROUPS (typec_altmode); -static void typec_altmode_release (struct device *dev) -{ -struct typec_altmode *alt =to_altmode (dev); -int i; - -for (i =0 ; i < alt->n_modes; i++) -kfree (alt->modes[i].desc); -kfree (alt); -} -static const struct device_type typec_altmode_dev_type = { .name ="typec_alternate_mode" , .groups = typec_altmode_groups,
@@ -395,13 +317,27 @@ typec_register_altmode(struct device *parent,return ERR_PTR (-ENOMEM ); alt->svid = desc->svid; - alt->n_modes = desc->n_modes; -typec_init_modes (alt, desc->modes,is_typec_port (parent)); + alt->mode = desc->mode; + alt->vdo = desc->vdo; + alt->roles = desc->roles; + + alt->attrs[0 ] = &dev_attr_vdo.attr; + alt->attrs[1 ] = &dev_attr_description.attr; + alt->attrs[2 ] = &dev_attr_active.attr; + +if (is_typec_port (parent)) + alt->attrs[3 ] = &dev_attr_supported_roles.attr; + +sprintf (alt->group_name,"mode%d" , desc->mode); + alt->group.name = alt->group_name; + alt->group.attrs = alt->attrs; + alt->groups[0 ] = &alt->group; alt->dev.parent = parent; - alt->dev.groups = alt->mode_groups; + alt->dev.groups = alt->groups; alt->dev.type = &typec_altmode_dev_type; -dev_set_name (&alt->dev,"svid-%04x" , alt->svid); +dev_set_name (&alt->dev,"%s-%04x:%u" ,dev_name (parent), + alt->svid, alt->mode); ret =device_register (&alt->dev);if (ret) {
drivers/usb/typec/tcpm.c +20 -25
67 lines not on this page · raw message
include/linux/usb/typec.h +9 -28
@@ -93,41 +93,23 @@ int typec_partner_set_identity(struct typec_partner *partner);int typec_cable_set_identity (struct typec_cable *cable);/* -* struct typec_mode_desc - Individual Mode of an Alternate Mode -* @index: Index of the Mode within the SVID +* struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor +* @svid: Standard or Vendor ID +* @mode: Index of the Mode * @vdo: VDO returned by Discover Modes USB PD command -* @desc: Optional human readable description of the mode * @roles: Only for ports. DRP if the mode is available in both roles * -* Description of a mode of an Alternate Mode which a connector, cable plug or -* partner supports. Every mode will have it's own sysfs group. The details are -* the VDO returned by discover modes command, description for the mode and -* active flag telling has the mode being entered or not. +* Description of an Alternate Mode which a connector, cable plug or partner +* supports. */ -struct typec_mode_desc { -int index; +struct typec_altmode_desc { +u16 svid; +u8 mode;u32 vdo; -char *desc;/* Only used with ports */ enum typec_port_type roles; }; -/* -* struct typec_altmode_desc - USB Type-C Alternate Mode Descriptor -* @svid: Standard or Vendor ID -* @n_modes: Number of modes -* @modes: Array of modes supported by the Alternate Mode -* -* Representation of an Alternate Mode that has SVID assigned by USB-IF. The -* array of modes will list the modes of a particular SVID that are supported by -* a connector, partner of a cable plug. -*/ -struct typec_altmode_desc { -u16 svid; -int n_modes; -struct typec_mode_desc modes[ALTMODE_MAX_MODES ]; -}; -struct typec_altmode *typec_partner_register_altmode (struct typec_partner *partner,const struct typec_altmode_desc *desc);
@@ -141,8 +123,7 @@ void typec_unregister_altmode(struct typec_altmode *altmode);struct typec_port *typec_altmode2port (struct typec_altmode *alt); -void typec_altmode_update_active (struct typec_altmode *alt,int mode, -bool active); +void typec_altmode_update_active (struct typec_altmode *alt,bool active);enum typec_plug_index {TYPEC_PLUG_SOP_P ,
Heikki Krogerus
maintainerRFC PATCH v4 5/8 usb: typec: Bus type for alternate modes
In reply to Heikki KrogerusIntroducing a simple bus for the alternate modes. Bus allows binding drivers to the discovered alternate modes the partners support.
--- Documentation/ABI/obsolete/sysfs-class-typec | 48 +++ Documentation/ABI/testing/sysfs-bus-typec | 51 +++ Documentation/ABI/testing/sysfs-class-typec | 62 +-- Documentation/driver-api/usb/typec_bus.rst | 136 +++++++ MAINTAINERS | 13 +- drivers/usb/typec/Makefile | 2 +- drivers/usb/typec/bus.c | 401 +++++++++++++++++++ drivers/usb/typec/bus.h | 38 ++ drivers/usb/typec/class.c | 366 +++++++++++++---- include/linux/mod_devicetable.h | 15 + include/linux/usb/typec.h | 14 +- include/linux/usb/typec_altmode.h | 160 ++++++++ scripts/mod/devicetable-offsets.c | 4 + scripts/mod/file2alias.c | 13 + 14 files changed, 1175 insertions(+), 148 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-class-typec create mode 100644 Documentation/ABI/testing/sysfs-bus-typec create mode 100644 Documentation/driver-api/usb/typec_bus.rst create mode 100644 drivers/usb/typec/bus.c create mode 100644 drivers/usb/typec/bus.h create mode 100644 include/linux/usb/typec_altmode.h
Documentation/ABI/obsolete/sysfs-class-typec new file +48 -0
@@ -0,0 +1,48 @@ +These files are deprecated and will be removed. The same files are available +under /sys/bus/typec (see Documentation/ABI/testing/sysfs-bus-typec). + +What: /sys/class/typec/<port|partner|cable>/<dev>/svid +Date: April 2017 +Contact: Heikki Krogerus <[email protected]> +Description: + The SVID (Standard or Vendor ID) assigned by USB-IF for this + alternate mode. + +What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/ +Date: April 2017 +Contact: Heikki Krogerus <[email protected]> +Description: + Every supported mode will have its own directory. The name of + a mode will be "mode<index>" (for example mode1), where <index> + is the actual index to the mode VDO returned by Discover Modes + USB power delivery command. + +What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/description +Date: April 2017 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows description of the mode. The description is optional for + the drivers, just like with the Billboard Devices. + +What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/vdo +Date: April 2017 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the VDO in hexadecimal returned by Discover Modes command + for this mode. + +What: /sys/class/typec/<port|partner|cable>/<dev>/mode<index>/active +Date: April 2017 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows if the mode is active or not. The attribute can be used + for entering/exiting the mode with partners and cable plugs, and + with the port alternate modes it can be used for disabling + support for specific alternate modes. Entering/exiting modes is + supported as synchronous operation so write(2) to the attribute + does not return until the enter/exit mode operation has + finished. The attribute is notified when the mode is + entered/exited so poll(2) on the attribute wakes up. + Entering/exiting a mode will also generate uevent KOBJ_CHANGE. + + Valid values: yes, no
Documentation/ABI/testing/sysfs-bus-typec new file +51 -0
51 lines not on this page · raw message
Documentation/ABI/testing/sysfs-class-typec +2 -60
72 lines not on this page · raw message
Documentation/driver-api/usb/typec_bus.rst new file +136 -0
136 lines not on this page · raw message
MAINTAINERS +11 -2
@@ -14922,15 +14922,24 @@ L: [email protected] S: Maintained F: drivers/usb/typec/mux/pi3usb30532.c -USB TYPEC SUBSYSTEM +USB TYPEC CLASS M: Heikki Krogerus <[email protected]> L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-class-typec -F: Documentation/usb/typec.rst +F: Documentation/driver-api/usb/typec.rst F: drivers/usb/typec/ F: include/linux/usb/typec.h +USB TYPEC BUS FOR ALTERNATE MODES +M: Heikki Krogerus <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/ABI/testing/sysfs-bus-typec +F: Documentation/driver-api/usb/typec_bus.rst +F: drivers/usb/typec/altmodes/ +F: include/linux/usb/typec_altmode.h + USB UHCI DRIVER M: Alan Stern <[email protected]> L: [email protected]
drivers/usb/typec/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC) += typec.o -typec-y := class.o mux.o +typec-y := class.o mux.o bus.o obj-$(CONFIG_TYPEC_TCPM) += tcpm.o obj-y += fusb302/ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o
drivers/usb/typec/bus.c new file +401 -0
401 lines not on this page · raw message
drivers/usb/typec/bus.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __USB_TYPEC_ALTMODE_H__ +#define __USB_TYPEC_ALTMODE_H__ + +#include <linux/usb/typec_altmode.h> +#include <linux/usb/typec_mux.h> + +struct bus_type ; + +struct altmode { +unsigned int id; +struct typec_altmode adev; +struct typec_mux *mux; + +enum typec_port_data roles; + +struct attribute *attrs[5 ]; +char group_name[6 ]; +struct attribute_group group; +const struct attribute_group *groups[2 ]; + +struct altmode *partner; +struct altmode *plug[2 ]; + +struct blocking_notifier_head nh; +}; + +#define to_altmode (d) container_of(d, struct altmode, adev) + +extern struct bus_type typec_bus; +extern const struct device_type typec_altmode_dev_type; +extern const struct device_type typec_port_dev_type; + +#define is_typec_altmode (_dev_) (_dev_->type == &typec_altmode_dev_type) +#define is_typec_port (_dev_) (_dev_->type == &typec_port_dev_type) + +#endif /* __USB_TYPEC_ALTMODE_H__ */
drivers/usb/typec/class.c +292 -74
593 lines not on this page · raw message
include/linux/mod_devicetable.h +15 -0
@@ -746,4 +746,19 @@ struct tb_service_id {#define TBSVC_MATCH_PROTOCOL_VERSION 0x0004#define TBSVC_MATCH_PROTOCOL_REVISION 0x0008 +/* USB Type-C Alternate Modes */ + +#define TYPEC_ANY_MODE 0x7 + +/** +* struct typec_device_id - USB Type-C alternate mode identifiers +* @svid: Standard or Vendor ID +* @mode: Mode index +*/ +struct typec_device_id { +__u16 svid; +__u8 mode; +kernel_ulong_t driver_data; +}; +#endif /* LINUX_MOD_DEVICETABLE_H */
include/linux/usb/typec.h +3 -11
@@ -5,21 +5,18 @@#include <linux/types.h> -/* XXX: Once we have a header for USB Power Delivery, this belongs there */ -#define ALTMODE_MAX_MODES 6 -/* USB Type-C Specification releases */ #define USB_TYPEC_REV_1_0 0x100/* 1.0 */ #define USB_TYPEC_REV_1_1 0x110/* 1.1 */ #define USB_TYPEC_REV_1_2 0x120/* 1.2 */ -struct typec_altmode ;struct typec_partner ;struct typec_cable ;struct typec_plug ;struct typec_port ;struct fwnode_handle ; +struct device ;enum typec_port_type {TYPEC_PORT_SRC ,
@@ -107,7 +104,7 @@ struct typec_altmode_desc {u8 mode;u32 vdo;/* Only used with ports */ -enum typec_port_type roles; +enum typec_port_data roles; };struct typec_altmode
@@ -186,7 +183,6 @@ struct typec_partner_desc {* @dr_set: Set Data Role * @pr_set: Set Power Role * @vconn_set: Set VCONN Role -* @activate_mode: Enter/exit given Alternate Mode * @port_type_set: Set port type * * Static capabilities of a single USB Type-C port.
@@ -212,12 +208,8 @@ struct typec_capability { enum typec_role);int (*vconn_set)(const struct typec_capability *,enum typec_role ); - -int (*activate_mode)(const struct typec_capability *, -int mode,int activate);int (*port_type_set)(const struct typec_capability *, -enum typec_port_type ); - +enum typec_port_type ); };/* Specific to try_role(). Indicates the user want's to clear the preference. */
include/linux/usb/typec_altmode.h new file +160 -0
160 lines not on this page · raw message
scripts/mod/devicetable-offsets.c +4 -0
@@ -221,5 +221,9 @@ int main(void)DEVID_FIELD (tb_service_id, protocol_version);DEVID_FIELD (tb_service_id, protocol_revision); +DEVID (typec_device_id); +DEVID_FIELD (typec_device_id, svid); +DEVID_FIELD (typec_device_id, mode); +return 0 ; }
scripts/mod/file2alias.c +13 -0
@@ -1352,6 +1352,19 @@ static int do_tbsvc_entry(const char *filename, void *symval, char *alias) }ADD_TO_DEVTABLE ("tbsvc" , tb_service_id, do_tbsvc_entry); +/* Looks like: typec:idNmN */ +static int do_typec_entry (const char *filename,void *symval,char *alias) +{ +DEF_FIELD (symval, typec_device_id, svid); +DEF_FIELD (symval, typec_device_id, mode); + +sprintf (alias,"typec:id%04X" , svid); +ADD (alias,"m" , mode !=TYPEC_ANY_MODE , mode); + +return 1 ; +} +ADD_TO_DEVTABLE ("typec" , typec_device_id, do_typec_entry); +/* Does namelen bytes of name exactly match the symbol? */ static bool sym_is (const char *name,unsigned namelen,const char *symbol) {
Heikki Krogerus
maintainerRFC PATCH v4 6/8 usb: typec: Add driver for DisplayPort alternate mode
In reply to Heikki KrogerusDisplayPort USB Type-C Alt Mode allows DisplayPort displays and adapters to be attached to the USB Type-C ports on the system.
--- .../testing/sysfs-driver-typec-displayport | 49 ++ drivers/usb/typec/Kconfig | 2 + drivers/usb/typec/Makefile | 1 + drivers/usb/typec/altmodes/Kconfig | 14 + drivers/usb/typec/altmodes/Makefile | 2 + drivers/usb/typec/altmodes/displayport.c | 543 ++++++++++++++++++ include/linux/usb/typec_dp.h | 70 +++ 7 files changed, 681 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-typec-displayport create mode 100644 drivers/usb/typec/altmodes/Kconfig create mode 100644 drivers/usb/typec/altmodes/Makefile create mode 100644 drivers/usb/typec/altmodes/displayport.c create mode 100644 include/linux/usb/typec_dp.h
Documentation/ABI/testing/sysfs-driver-typec-displayport new file +49 -0
@@ -0,0 +1,49 @@ +What: /sys/bus/typec/devices/.../displayport/configuration +Date: July 2018 +Contact: Heikki Krogerus <[email protected]> +Description: + Shows the current DisplayPort configuration for the connector. + Valid values are USB, source and sink. Source means DisplayPort + source, and sink means DisplayPort sink. + + All supported configurations are listed as space separated list + with the active one wrapped in square brackets. + + Source example: + + USB [source] sink + + The configuration can be changed by writing to the file + + Note. USB configuration does not equal to Exit Mode. It is + separate configuration defined in VESA DisplayPort Alt Mode on + USB Type-C Standard. Functionally it equals to the situation + where the mode has been exited (to exit the mode, see + Documentation/ABI/testing/sysfs-bus-typec, and use file + /sys/bus/typec/devices/.../active). + +What: /sys/bus/typec/devices/.../displayport/pin_assignment +Date: July 2018 +Contact: Heikki Krogerus <[email protected]> +Description: + VESA DisplayPort Alt Mode on USB Type-C Standard defines six + different pin assignments for USB Type-C connector that are + labeled A, B, C, D, E, and F. The supported pin assignments are + listed as space separated list with the active one wrapped in + square brackets. + + Example: + + C [D] + + Pin assignment can be changed by writing to the file. It is + possible to set pin assignment before configuration has been + set, but the assignment will not be active before the + connector is actually configured. + + Note. As of VESA DisplayPort Alt Mode on USB Type-C Standard + version 1.0b, pin assignments A, B, and F are deprecated. Only + pin assignments D can now carry simultaneously one channel of + USB SuperSpeed protocol. From user perspective pin assignments C + and E are equal, where all channels on the connector are used + for carrying DisplayPort protocol (allowing higher resolutions).
drivers/usb/typec/Kconfig +2 -0
@@ -88,4 +88,6 @@ config TYPEC_TPS6598X source "drivers/usb/typec/mux/Kconfig" +source "drivers/usb/typec/altmodes/Kconfig" + endif # TYPEC
drivers/usb/typec/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_TYPEC) += typec.o typec-y := class.o mux.o bus.o +obj-$(CONFIG_TYPEC) += altmodes/ obj-$(CONFIG_TYPEC_TCPM) += tcpm.o obj-y += fusb302/ obj-$(CONFIG_TYPEC_WCOVE) += typec_wcove.o
drivers/usb/typec/altmodes/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ + +menu "USB Type-C Alternate Mode drivers" + +config TYPEC_DP_ALTMODE + tristate "DisplayPort Alternate Mode driver" + help + DisplayPort USB Type-C Alternate Mode allows DisplayPort + displays and adapters to be attached to the USB Type-C + connectors on the system. + + To compile this driver as a module, choose M here: the + module will be called typec_displayport. + +endmenu
drivers/usb/typec/altmodes/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_TYPEC_DP_ALTMODE) += typec_displayport.o +typec_displayport-y := displayport.o
drivers/usb/typec/altmodes/displayport.c new file +543 -0
543 lines not on this page · raw message
include/linux/usb/typec_dp.h new file +70 -0
70 lines not on this page · raw message
Heikki Krogerus
maintainerRFC PATCH v4 7/8 usb: typec: pi3usb30532: Start using generic state values
In reply to Heikki KrogerusInstead of the tcpm specific mux states, using the generic USB type-c connector state values, and with DisplayPort using connector states defined for the DisplayPort Alt Mode.
--- drivers/usb/typec/mux/pi3usb30532.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/usb/typec/mux/pi3usb30532.c +9 -6
@@ -9,7 +9,7 @@#include <linux/kernel.h> #include <linux/module.h> #include <linux/mutex.h> -#include <linux/usb/tcpm.h> +#include <linux/usb/typec_dp.h> #include <linux/usb/typec_mux.h> #define PI3USB30532_CONF 0x00
@@ -83,21 +83,24 @@ static int pi3usb30532_mux_set(struct typec_mux *mux, int state) new_conf = pi->conf;switch (state) { -case TYPEC_MUX_NONE : +case TYPEC_STATE_SAFE : new_conf =PI3USB30532_CONF_OPEN ;break ; -case TYPEC_MUX_USB : +case TYPEC_STATE_USB : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) | -PI3USB30532_CONF_USB3 ; +PI3USB30532_CONF_USB3 ;break ; -case TYPEC_MUX_DP : +case TYPEC_DP_STATE_C : +case TYPEC_DP_STATE_E : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) |PI3USB30532_CONF_4LANE_DP ;break ; -case TYPEC_MUX_DOCK : +case TYPEC_DP_STATE_D : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) |PI3USB30532_CONF_USB3_AND_2LANE_DP ;break ; +default : +break ; } ret =pi3usb30532_set_conf (pi, new_conf);
Heikki Krogerus
maintainerRFC PATCH v4 8/8 usb: typec: tcpm: Support for Alternate Modes
In reply to Heikki KrogerusThis adds more complete handling of VDMs and registration of partner alternate modes, and introduces callbacks for alternate mode operations.
Only DFP role is supported for now.
--- drivers/usb/typec/tcpm.c | 161 +++++++++++++++++++++++++++++++-------- include/linux/usb/tcpm.h | 9 --- 2 files changed, 131 insertions(+), 39 deletions(-)
drivers/usb/typec/tcpm.c +131 -30
@@ -26,7 +26,7 @@#include <linux/usb/pd_vdo.h> #include <linux/usb/role.h> #include <linux/usb/tcpm.h> -#include <linux/usb/typec.h> +#include <linux/usb/typec_altmode.h> #include <linux/workqueue.h> #define FOREACH_STATE (S ) \
@@ -169,13 +169,14 @@ enum pd_msg_request {/* Alternate mode support */ #define SVID_DISCOVERY_MAX 16 +#define ALTMODE_DISCOVERY_MAX (SVID_DISCOVERY_MAX * MODE_DISCOVERY_MAX)struct pd_mode_data {int svid_index;/* current SVID index */ int nsvids;u16 svids[SVID_DISCOVERY_MAX ];int altmodes;/* number of alternate modes */ -struct typec_altmode_desc altmode_desc[SVID_DISCOVERY_MAX ]; +struct typec_altmode_desc altmode_desc[ALTMODE_DISCOVERY_MAX ]; };struct pd_pps_data {
@@ -310,8 +311,8 @@ struct tcpm_port {/* Alternate mode data */ struct pd_mode_data mode_data; -struct typec_altmode *partner_altmode[SVID_DISCOVERY_MAX *6 ]; -struct typec_altmode *port_altmode[SVID_DISCOVERY_MAX *6 ]; +struct typec_altmode *partner_altmode[ALTMODE_DISCOVERY_MAX ]; +struct typec_altmode *port_altmode[ALTMODE_DISCOVERY_MAX ];/* Deadline in jiffies to exit src_try_wait state */ unsigned long max_wait;
@@ -640,14 +641,14 @@ 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, +static int tcpm_mux_set (struct tcpm_port *port,int state,enum usb_role usb_role,enum typec_orientation orientation) {int ret; -tcpm_log (port,"Requesting mux mode %d, usb-role %d, orientation %d" , - mode, usb_role, orientation); +tcpm_log (port,"Requesting mux state %d, usb-role %d, orientation %d" , + state, usb_role, orientation); ret =typec_set_orientation (port->typec_port, orientation);if (ret)
@@ -659,7 +660,7 @@ static int tcpm_mux_set(struct tcpm_port *port, enum tcpc_mux_mode mode,return ret; } -return typec_set_mode (port->typec_port, mode); +return typec_set_mode (port->typec_port, state); } static int tcpm_set_polarity(struct tcpm_port *port,
@@ -786,7 +787,7 @@ static int tcpm_set_roles(struct tcpm_port *port, bool attached,else usb_role =USB_ROLE_DEVICE ; - ret =tcpm_mux_set (port,TYPEC_MUX_USB , usb_role, orientation); + ret =tcpm_mux_set (port,TYPEC_STATE_USB , usb_role, orientation);if (ret <0 )return ret;
@@ -1013,36 +1014,57 @@ static void svdm_consume_modes(struct tcpm_port *port, const __le32 *payload, pmdata->altmodes, paltmode->svid, paltmode->mode, paltmode->vdo); - port->partner_altmode[pmdata->altmodes] = -typec_partner_register_altmode (port->partner, paltmode); -if (!port->partner_altmode[pmdata->altmodes]) { -tcpm_log (port, -"Failed to register modes for SVID 0x%04x" , - paltmode->svid); -return ; - } pmdata->altmodes++; } } +static void tcpm_register_partner_altmodes (struct tcpm_port *port) +{ +struct pd_mode_data *modep = &port->mode_data; +struct typec_altmode *altmode; +int i; + +for (i =0 ; i < modep->altmodes; i++) { + altmode =typec_partner_register_altmode (port->partner, + &modep->altmode_desc[i]); +if (!altmode) +tcpm_log (port,"Failed to register partner SVID 0x%04x" , + modep->altmode_desc[i].svid); + port->partner_altmode[i] = altmode; + } +} +#define supports_modal (port) PD_IDH_MODAL_SUPP((port)->partner_ident.id_header)static int tcpm_pd_svdm (struct tcpm_port *port,const __le32 *payload,int cnt,u32 *response) { -u32 p0 =le32_to_cpu (payload[0 ]); -int cmd_type =PD_VDO_CMDT (p0); -int cmd =PD_VDO_CMD (p0); +struct typec_altmode *adev; +struct typec_altmode *pdev;struct pd_mode_data *modep; +u32 p[PD_MAX_PAYLOAD ];int rlen =0 ; -u16 svid; +int cmd_type; +int cmd;int i; +for (i =0 ; i < cnt; i++) + p[i] =le32_to_cpu (payload[i]); + + cmd_type =PD_VDO_CMDT (p[0 ]); + cmd =PD_VDO_CMD (p[0 ]); +tcpm_log (port,"Rx VDM cmd 0x%x type %d cmd %d len %d" , - p0, cmd_type, cmd, cnt); + p[0 ], cmd_type, cmd, cnt); modep = &port->mode_data; + adev =typec_match_altmode (port->port_altmode,ALTMODE_DISCOVERY_MAX , +PD_VDO_VID (p[0 ]),PD_VDO_OPOS (p[0 ])); + + pdev =typec_match_altmode (port->partner_altmode,ALTMODE_DISCOVERY_MAX , +PD_VDO_VID (p[0 ]),PD_VDO_OPOS (p[0 ])); +switch (cmd_type) {case CMDT_INIT :switch (cmd) {
@@ -1064,17 +1086,19 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,case CMD_EXIT_MODE :break ;case CMD_ATTENTION : -break ; +/* Attention command does not have response */ +typec_altmode_attention (adev, p[1 ]); +return 0 ;default :break ; }if (rlen >=1 ) { - response[0 ] = p0 |VDO_CMDT (CMDT_RSP_ACK ); + response[0 ] = p[0 ] |VDO_CMDT (CMDT_RSP_ACK ); }else if (rlen ==0 ) { - response[0 ] = p0 |VDO_CMDT (CMDT_RSP_NAK ); + response[0 ] = p[0 ] |VDO_CMDT (CMDT_RSP_NAK ); rlen =1 ; }else { - response[0 ] = p0 |VDO_CMDT (CMDT_RSP_BUSY ); + response[0 ] = p[0 ] |VDO_CMDT (CMDT_RSP_BUSY ); rlen =1 ; }break ;
@@ -1107,14 +1131,39 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,svdm_consume_modes (port, payload, cnt); modep->svid_index++;if (modep->svid_index < modep->nsvids) { - svid = modep->svids[modep->svid_index]; +u16 svid = modep->svids[modep->svid_index]; response[0 ] =VDO (svid,1 ,CMD_DISCOVER_MODES ); rlen =1 ; }else { -/* enter alternate mode if/when implemented */ +tcpm_register_partner_altmodes (port); }break ;case CMD_ENTER_MODE : +typec_altmode_update_active (pdev, true); + +if (typec_altmode_vdm (adev, p[0 ], &p[1 ], cnt)) { + response[0 ] =VDO (adev->svid,1 ,CMD_EXIT_MODE ); + response[0 ] |=VDO_OPOS (adev->mode); +return 1 ; + } +return 0 ; +case CMD_EXIT_MODE : +typec_altmode_update_active (pdev, false); + +/* Back to USB Operation */ +WARN_ON (typec_altmode_notify (adev,TYPEC_STATE_USB , +NULL )); +break ; +default : +break ; + } +break ; +case CMDT_RSP_NAK : +switch (cmd) { +case CMD_ENTER_MODE : +/* Back to USB Operation */ +WARN_ON (typec_altmode_notify (adev,TYPEC_STATE_USB , +NULL ));break ;default :break ;
@@ -1124,6 +1173,9 @@ static int tcpm_pd_svdm(struct tcpm_port *port, const __le32 *payload, int cnt,break ; } +/* Informing the alternate mode drivers about everything */ +typec_altmode_vdm (adev, p[0 ], &p[1 ], cnt); +return rlen; }
@@ -1407,6 +1459,53 @@ static int tcpm_validate_caps(struct tcpm_port *port, const u32 *pdo,return 0 ; } +static void tcpm_altmode_enter (struct typec_altmode *altmode) +{ +struct tcpm_port *port =typec_altmode_get_drvdata (altmode); +u32 header; + +mutex_lock (&port->lock); + header =VDO (altmode->svid,1 ,CMD_ENTER_MODE ); + header |=VDO_OPOS (altmode->mode); + +tcpm_queue_vdm (port, header,NULL ,0 ); +mod_delayed_work (port->wq, &port->vdm_state_machine,0 ); +mutex_unlock (&port->lock); +} + +static void tcpm_altmode_exit (struct typec_altmode *altmode) +{ +struct tcpm_port *port =typec_altmode_get_drvdata (altmode); +u32 header; + +mutex_lock (&port->lock); + header =VDO (altmode->svid,1 ,CMD_EXIT_MODE ); + header |=VDO_OPOS (altmode->mode); + +tcpm_queue_vdm (port, header,NULL ,0 ); +mod_delayed_work (port->wq, &port->vdm_state_machine,0 ); +mutex_unlock (&port->lock); +} + +static int tcpm_altmode_vdm (struct typec_altmode *altmode, +u32 header,const u32 *data,int count) +{ +struct tcpm_port *port =typec_altmode_get_drvdata (altmode); + +mutex_lock (&port->lock); +tcpm_queue_vdm (port, header, data, count -1 ); +mod_delayed_work (port->wq, &port->vdm_state_machine,0 ); +mutex_unlock (&port->lock); + +return 0 ; +} + +static const struct typec_altmode_ops tcpm_altmode_ops = { + .enter = tcpm_altmode_enter, + .exit = tcpm_altmode_exit, + .vdm = tcpm_altmode_vdm, +}; +/* * PD (data, control) command handling functions */
@@ -2538,7 +2637,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 ,USB_ROLE_NONE , +tcpm_mux_set (port,TYPEC_STATE_SAFE ,USB_ROLE_NONE ,TYPEC_ORIENTATION_NONE );return ret; }
@@ -2584,7 +2683,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_mux_set (port,TYPEC_STATE_SAFE ,USB_ROLE_NONE ,TYPEC_ORIENTATION_NONE );tcpm_set_attached_state (port, false); port->try_src_count =0 ;
@@ -4616,6 +4715,8 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) dev_name(dev), paltmode->svid);break ; } +typec_altmode_set_drvdata (alt, port); + alt->ops = &tcpm_altmode_ops; port->port_altmode[i] = alt; i++; paltmode++;
include/linux/usb/tcpm.h +0 -9
@@ -98,15 +98,6 @@ struct tcpc_config {#define TCPC_MUX_DP_ENABLED BIT(1)/* DP enabled */ #define TCPC_MUX_POLARITY_INVERTED BIT(2)/* Polarity inverted */ -/* Mux modes, decoded to attributes */ -enum tcpc_mux_mode { -TYPEC_MUX_NONE =0 ,/* Open switch */ -TYPEC_MUX_USB =TCPC_MUX_USB_ENABLED ,/* USB only */ -TYPEC_MUX_DP =TCPC_MUX_DP_ENABLED ,/* DP only */ -TYPEC_MUX_DOCK =TCPC_MUX_USB_ENABLED |/* Both USB and DP */ -TCPC_MUX_DP_ENABLED , -}; -/** * struct tcpc_dev - Port configuration and callback functions * @config: Pointer to port configuration
Heikki Krogerus
maintainerv4 cover usb: typec: Support for Alternate Modes
Hi,
This is the fourth (and hopefully last RFC) of my proposal for more complete alternate mode support. In this version the main difference compared to the previous versions is the displayport alt mode driver.
For those who have no idea what is this about, the idea is to add a bus type for the USB-C alternate modes. All alternate modes, for example DisplayPort, require specific communication, so we will need separate driver for every alternate mode. For more details please read the cover letter of the previous version here:
https://lkml.org/lkml/2018/5/11/323
It took some time for me to get permission to publish the displayport alt mode driver. Sorry for the delay. I was actually hoping that I could include changes also to the drm subsystem already now, but it ended up being more complicated than I first though, and I quite simply don't have time for that, so let's just start with these.
Heikki Krogerus (8):
usb: pd: include kernel.h
usb: typec: helper for checking cable plug orientation
usb: typec: mux: Get the mux identifier from function parameter
usb: typec: Register a device for every mode
usb: typec: Bus type for alternate modes
usb: typec: Add driver for DisplayPort alternate mode
usb: typec: pi3usb30532: Start using generic state values
usb: typec: tcpm: Support for Alternate Modes
Documentation/ABI/obsolete/sysfs-class-typec | 48 ++ Documentation/ABI/testing/sysfs-bus-typec | 51 ++ Documentation/ABI/testing/sysfs-class-typec | 62 +- .../testing/sysfs-driver-typec-displayport | 49 ++ Documentation/driver-api/usb/typec_bus.rst | 136 +++++ MAINTAINERS | 13 +- drivers/usb/typec/Kconfig | 2 + drivers/usb/typec/Makefile | 3 +- drivers/usb/typec/altmodes/Kconfig | 14 + drivers/usb/typec/altmodes/Makefile | 2 + drivers/usb/typec/altmodes/displayport.c | 543 ++++++++++++++++++ drivers/usb/typec/bus.c | 401 +++++++++++++ drivers/usb/typec/bus.h | 38 ++ drivers/usb/typec/class.c | 485 ++++++++++------ drivers/usb/typec/mux.c | 6 +- drivers/usb/typec/mux/pi3usb30532.c | 15 +- drivers/usb/typec/tcpm.c | 184 ++++-- include/linux/mod_devicetable.h | 15 + include/linux/usb/pd.h | 1 + include/linux/usb/tcpm.h | 9 - include/linux/usb/typec.h | 52 +- include/linux/usb/typec_altmode.h | 160 ++++++ include/linux/usb/typec_dp.h | 70 +++ include/linux/usb/typec_mux.h | 2 +- scripts/mod/devicetable-offsets.c | 4 + scripts/mod/file2alias.c | 13 + 26 files changed, 2053 insertions(+), 325 deletions(-) create mode 100644 Documentation/ABI/obsolete/sysfs-class-typec create mode 100644 Documentation/ABI/testing/sysfs-bus-typec create mode 100644 Documentation/ABI/testing/sysfs-driver-typec-displayport create mode 100644 Documentation/driver-api/usb/typec_bus.rst create mode 100644 drivers/usb/typec/altmodes/Kconfig create mode 100644 drivers/usb/typec/altmodes/Makefile create mode 100644 drivers/usb/typec/altmodes/displayport.c create mode 100644 drivers/usb/typec/bus.c create mode 100644 drivers/usb/typec/bus.h create mode 100644 include/linux/usb/typec_altmode.h create mode 100644 include/linux/usb/typec_dp.h
Signature · 1 line
2.17.1
Heikki Krogerus
maintainerRe: [RFC PATCH v4 6/8] usb: typec: Add driver for DisplayPort alternate mode
In reply to Heikki KrogerusQuoted 221 lines · Heikki Krogerus
drivers/usb/typec/altmodes/displayport.c new file +215
-0@@ -0,0 +1,543 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* USB Typec-C DisplayPort Alternate Mode driver +* +* Copyright (C) 2018 Intel Corporation +* Author: Heikki Krogerus <[email protected]> +* +* DisplayPort is trademark of VESA (www.vesa.org) +*/ + +#include <linux/delay.h> +#include <linux/mutex.h> +#include <linux/module.h> +#include <linux/usb/pd_vdo.h> +#include <linux/usb/typec_dp.h> + +#define DP_HEADER (cmd) (VDO(USB_TYPEC_DP_SID, 1, cmd) | \ + VDO_OPOS(USB_TYPEC_DP_MODE)) + +/* DisplayPort alt mode specific commands */ +#define DP_CMD_STATUS_UPDATE VDO_CMD_VENDOR(0) +#define DP_CMD_CONFIGURE VDO_CMD_VENDOR(1) + +enum { +DP_CONF_USB , +DP_CONF_DFP_D , +DP_CONF_UFP_D , +DP_CONF_DUAL_D , +}; + +/* DisplayPort Capabilities VDO bits */ +#define DP_CAP_CAPABILITY (_cap_) ((_cap_) & 3) +#define DP_CAP_UFP_D 1 +#define DP_CAP_DFP_D 2 +#define DP_CAP_DFP_D_AND_UFP_D 3 +#define DP_CAP_DP_SIGNALING BIT(2)/* Always set */ +#define DP_CAP_GEN2 BIT(3)/* Reserved after v1.0b */ +#define DP_CAP_RECEPTACLE BIT(6) +#define DP_CAP_USB BIT(7) +#define DP_CAP_DFP_D_PIN_ASSIGN (_cap_) (((_cap_) & GENMASK(15, 8)) >> 8) +#define DP_CAP_UFP_D_PIN_ASSIGN (_cap_) (((_cap_) & GENMASK(23, 16)) >> 16) + +enum { +DP_PIN_ASSIGN_A ,/* Not supported after v1.0b */ +DP_PIN_ASSIGN_B ,/* Not supported after v1.0b */ +DP_PIN_ASSIGN_C , +DP_PIN_ASSIGN_D , +DP_PIN_ASSIGN_E , +DP_PIN_ASSIGN_F ,/* Not supported after v1.0b */ +}; + +/* Helper for setting/getting the pin assignement value to the configuration */ +#define DP_CONF_SET_PIN_ASSIGN (_a_) ((_a_) << 8) +#define DP_CONF_GET_PIN_ASSIGN (_conf_) (((_conf_) & GENMASK(15, 8)) >> 8) + +/* Pin assignments that use USB3.1 Gen2 signaling to carry DP protocol */ +#define DP_PIN_ASSIGN_GEN2_BR_MASK (BIT(DP_PIN_ASSIGN_A) | \ + BIT(DP_PIN_ASSIGN_B)) + +/* Pin assignments that use DP v1.3 signaling to carry DP protocol */ +#define DP_PIN_ASSIGN_DP_BR_MASK (BIT(DP_PIN_ASSIGN_C) | \ + BIT(DP_PIN_ASSIGN_D) | \ + BIT(DP_PIN_ASSIGN_E) | \ + BIT(DP_PIN_ASSIGN_F)) + +/* DP only pin assignments */ +#define DP_PIN_ASSIGN_DP_ONLY_MASK (BIT(DP_PIN_ASSIGN_A) | \ + BIT(DP_PIN_ASSIGN_C) | \ + BIT(DP_PIN_ASSIGN_E)) + +/* Pin assignments where one channel is for USB */ +#define DP_PIN_ASSIGN_MULTI_FUNC_MASK (BIT(DP_PIN_ASSIGN_B) | \ + BIT(DP_PIN_ASSIGN_D) | \ + BIT(DP_PIN_ASSIGN_F)) + +enum dp_state { +DP_STATE_NONE , +DP_STATE_ENTER , +DP_STATE_UPDATE , +DP_STATE_CONFIGURE , +DP_STATE_EXIT , +}; + +struct dp_altmode { +struct typec_displayport_data data; + +enum dp_state state; + +struct mutex lock; +struct work_struct work; +struct typec_altmode *alt; +const struct typec_altmode *port; +}; + +static int dp_altmode_configure (struct dp_altmode *dp,u8 con) +{ +u32 conf =DP_CONF_SIGNALING_DP ;/* Only DP signaling supported */ +u8 pin_assign =0 ; + +switch (con) { +case DP_STATUS_CON_DISABLED : + dp->data.conf =0 ; +return 0 ; +case DP_STATUS_CON_DFP_D : + conf |=DP_CONF_UFP_U_AS_DFP_D ; + pin_assign =DP_CAP_UFP_D_PIN_ASSIGN (dp->alt->vdo) & +DP_CAP_DFP_D_PIN_ASSIGN (dp->port->vdo); +break ; +case DP_STATUS_CON_UFP_D : +case DP_STATUS_CON_BOTH :/* NOTE: First acting as DP source */ + conf |=DP_CONF_UFP_U_AS_UFP_D ; + pin_assign =DP_CAP_DFP_D_PIN_ASSIGN (dp->alt->vdo) & +DP_CAP_UFP_D_PIN_ASSIGN (dp->port->vdo); +break ; +default : +break ; + } + +/* Determining the initial pin assignment. */ +if (!DP_CONF_GET_PIN_ASSIGN (dp->data.conf)) { +/* Is USB together with DP preferred */ +if (dp->data.status &DP_STATUS_PREFER_MULTI_FUNC && + pin_assign &DP_PIN_ASSIGN_MULTI_FUNC_MASK ) + pin_assign &=DP_PIN_ASSIGN_MULTI_FUNC_MASK ; +else + pin_assign &=DP_PIN_ASSIGN_DP_ONLY_MASK ; + +if (!pin_assign) +return -EINVAL ; + + conf |=DP_CONF_SET_PIN_ASSIGN (pin_assign); + } + + dp->data.conf |= conf; + +return 0 ; +} + +static int dp_altmode_status_update (struct dp_altmode *dp) +{ +bool configured = !!DP_CONF_GET_PIN_ASSIGN (dp->data.conf); +u8 con =DP_STATUS_CONNECTION (dp->data.status); +int ret =0 ; + +if (configured && (dp->data.status &DP_STATUS_SWITCH_TO_USB )) { + dp->data.conf =0 ; + dp->state =DP_STATE_CONFIGURE ; + }else if (dp->data.status &DP_STATUS_EXIT_DP_MODE ) { + dp->state =DP_STATE_EXIT ; + }else if (!(con &DP_CONF_CURRENTLY (dp->data.conf))) { + ret =dp_altmode_configure (dp, con); +if (!ret) + dp->state =DP_STATE_CONFIGURE ; + } + +return ret; +} + +static int dp_altmode_configured (struct dp_altmode *dp) +{ +u8 state; +int ret; + +sysfs_notify (&dp->alt->dev.kobj,"displayport" ,"configuration" ); + +if (!dp->data.conf) +return typec_altmode_notify (dp->alt,TYPEC_STATE_USB , + &dp->data); + + state =get_count_order (DP_CONF_GET_PIN_ASSIGN (dp->data.conf)); + ret =typec_altmode_notify (dp->alt,TYPEC_MODAL_STATE (state), + &dp->data); +if (ret) +return ret; + +sysfs_notify (&dp->alt->dev.kobj,"displayport" ,"pin_assignment" ); + +return 0 ; +} + +static void dp_altmode_work (struct work_struct *work) +{ + struct dp_altmode *dp = container_of(work, struct dp_altmode, work); +u32 header =0 ; +u32 vdo; +int ret; + +mutex_lock (&dp->lock); + +switch (dp->state) { +case DP_STATE_ENTER : + ret =typec_altmode_enter (dp->alt); +if (ret) +dev_err (&dp->alt->dev,"failed to enter mode\n" ); +break ; +case DP_STATE_UPDATE : + header =DP_HEADER (DP_CMD_STATUS_UPDATE ); + vdo =1 ; +break ; +case DP_STATE_CONFIGURE : + ret =typec_altmode_notify (dp->alt,TYPEC_STATE_SAFE , + &dp->data); +if (ret) { +dev_err (&dp->alt->dev, +"unable to put to connector to safe mode\n" ); +break ; + } + header =DP_HEADER (DP_CMD_CONFIGURE ); + vdo = dp->data.conf; +break ; +case DP_STATE_EXIT : +if (typec_altmode_exit (dp->alt)) +dev_err (&dp->alt->dev,"Exit Mode Failed!\n" ); +break ; +default :
drivers/usb/typec/altmodes/displayport.c line 225
Quoted 10 lines
drivers/usb/typec/altmodes/displayport.c new file +10
-0+break ; + } + +if (header) { +if (typec_altmode_vdm (dp->alt, header, &vdo,2 )) +dev_err (&dp->alt->dev,"unable to send VDM\n" ); + } + +mutex_unlock (&dp->lock); +}
FYI. Currently this little state machine is horribly racy. It needs to be fixed.
Quoted 307 lines
drivers/usb/typec/altmodes/displayport.c new file +307
-0+static void dp_altmode_attention (struct typec_altmode *alt,const u32 vdo) +{ +struct dp_altmode *dp =typec_altmode_get_drvdata (alt); +u8 state; + +mutex_lock (&dp->lock); + + dp->state =DP_STATE_NONE ; + dp->data.status = vdo; +dp_altmode_status_update (dp); + +if (dp->state ==DP_STATE_NONE ) { + state =get_count_order (DP_CONF_GET_PIN_ASSIGN (dp->data.conf)); +if (typec_altmode_notify (dp->alt,TYPEC_MODAL_STATE (state), + &dp->data)) +dev_err (&alt->dev,"%s: notification failed\n" , + __func__); + }else { +schedule_work (&dp->work); + } + +mutex_unlock (&dp->lock); +} + +static int dp_altmode_vdm (struct typec_altmode *alt, +const u32 hdr,const u32 *vdo,int count) +{ +struct dp_altmode *dp =typec_altmode_get_drvdata (alt); +int cmd_type =PD_VDO_CMDT (hdr); +int cmd =PD_VDO_CMD (hdr); +int ret =0 ; + +mutex_lock (&dp->lock); + + dp->state =DP_STATE_NONE ; + +switch (cmd_type) { +case CMDT_RSP_ACK : +switch (cmd) { +case CMD_ENTER_MODE : + dp->state =DP_STATE_UPDATE ; +break ; +case CMD_EXIT_MODE : + dp->data.status =0 ; + dp->data.conf =0 ; +break ; +case DP_CMD_STATUS_UPDATE : + dp->data.status = *vdo; + ret =dp_altmode_status_update (dp); +break ; +case DP_CMD_CONFIGURE : + ret =dp_altmode_configured (dp); +break ; +default : +break ; + } +break ; +case CMDT_RSP_NAK : +switch (cmd) { +case DP_CMD_CONFIGURE : + dp->data.conf =0 ; + ret =dp_altmode_configured (dp); +break ; +default : +break ; + } +break ; +default : +break ; + } + +if (dp->state !=DP_STATE_NONE ) +schedule_work (&dp->work); + +mutex_unlock (&dp->lock); +return ret; +} + +static int dp_altmode_activate (struct typec_altmode *alt,int activate) +{ +return activate ?typec_altmode_enter (alt) :typec_altmode_exit (alt); +} + +static const struct typec_altmode_ops dp_altmode_ops = { + .attention = dp_altmode_attention, + .vdm = dp_altmode_vdm, + .activate = dp_altmode_activate, +}; + +static const char *const configurations[] = { + [DP_CONF_USB ] ="USB" , + [DP_CONF_DFP_D ] ="source" , + [DP_CONF_UFP_D ] ="sink" , +}; + +static ssize_t +configuration_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t size) +{ +struct dp_altmode *dp =dev_get_drvdata (dev); +int conf; +int ret; + + conf =sysfs_match_string (configurations, buf); +if (conf <0 ) +return conf; + +mutex_lock (&dp->lock); + + ret =dp_altmode_configure (dp, conf); +if (!ret && dp->alt->active) { + dp->state =DP_STATE_CONFIGURE ; +schedule_work (&dp->work); + } + +mutex_unlock (&dp->lock); + +return ret ? ret : size; +} + +static ssize_t configuration_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct dp_altmode *dp =dev_get_drvdata (dev); +int len; +u8 cap; +u8 cur; +int i; + +mutex_lock (&dp->lock); + + cap =DP_CAP_CAPABILITY (dp->alt->vdo); + cur =DP_CONF_CURRENTLY (dp->data.conf); + + len =sprintf (buf,"%s " , cur ?"USB" :"[USB]" ); + +for (i =1 ; i <ARRAY_SIZE (configurations); i++) { +if (i == cur) + len +=sprintf (buf + len,"[%s] " , configurations[i]); +else if ((i ==DP_CONF_DFP_D && cap &DP_CAP_DFP_D ) || + (i ==DP_CONF_UFP_D && cap &DP_CAP_UFP_D )) + len +=sprintf (buf + len,"%s " , configurations[i]); + } + +mutex_unlock (&dp->lock); + + buf[len -1 ] ='\n' ; +return len; +} +static DEVICE_ATTR_RW (configuration); + +static const char *const pin_assignments[] = { + [DP_PIN_ASSIGN_A ] ="A" , + [DP_PIN_ASSIGN_B ] ="B" , + [DP_PIN_ASSIGN_C ] ="C" , + [DP_PIN_ASSIGN_D ] ="D" , + [DP_PIN_ASSIGN_E ] ="E" , + [DP_PIN_ASSIGN_F ] ="F" , +}; + +static ssize_t +pin_assignment_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t size) +{ +struct dp_altmode *dp =dev_get_drvdata (dev); +u8 assignments; +u32 conf; +int ret; + + ret =sysfs_match_string (pin_assignments, buf); +if (ret <0 ) +return ret; + + conf =DP_CONF_SET_PIN_ASSIGN (BIT (ret)); + ret =0 ; + +mutex_lock (&dp->lock); + +if (conf & dp->data.conf) + goto out_unlock; + +if (DP_CONF_CURRENTLY (dp->data.conf) ==DP_CONF_DFP_D ) + assignments =DP_CAP_UFP_D_PIN_ASSIGN (dp->alt->vdo); +else + assignments =DP_CAP_DFP_D_PIN_ASSIGN (dp->alt->vdo); + +if (!(DP_CONF_GET_PIN_ASSIGN (conf) & assignments)) { + ret = -EINVAL ; + goto out_unlock; + } + +/* Only send Configure command if a configuration has been set */ +if (dp->alt->active &&DP_CONF_CURRENTLY (dp->data.conf)) { + dp->state =DP_STATE_CONFIGURE ; +schedule_work (&dp->work); + } + + dp->data.conf &= ~DP_CONF_PIN_ASSIGNEMENT_MASK ; + dp->data.conf |= conf; + +out_unlock: +mutex_unlock (&dp->lock); + +return ret ? ret : size; +} + +static ssize_t pin_assignment_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct dp_altmode *dp =dev_get_drvdata (dev); +u8 assignments; +int len =0 ; +u8 cur; +int i; + +mutex_lock (&dp->lock); + + cur =get_count_order (DP_CONF_GET_PIN_ASSIGN (dp->data.conf)); + +if (DP_CONF_CURRENTLY (dp->data.conf) ==DP_CONF_DFP_D ) + assignments =DP_CAP_UFP_D_PIN_ASSIGN (dp->alt->vdo); +else + assignments =DP_CAP_DFP_D_PIN_ASSIGN (dp->alt->vdo); + +for (i =0 ; assignments; assignments >>=1 , i++) { +if (assignments &1 ) { +if (i == cur) + len +=sprintf (buf + len,"[%s] " , + pin_assignments[i]); +else + len +=sprintf (buf + len,"%s " , + pin_assignments[i]); + } + } + +mutex_unlock (&dp->lock); + + buf[len -1 ] ='\n' ; +return len; +} +static DEVICE_ATTR_RW (pin_assignment); + +static struct attribute *dp_altmode_attrs[] = { + &dev_attr_configuration.attr, + &dev_attr_pin_assignment.attr, +NULL +}; + +static const struct attribute_group dp_altmode_group = { + .name ="displayport" , + .attrs = dp_altmode_attrs, +}; + +static int dp_altmode_probe (struct typec_altmode *alt) +{ +const struct typec_altmode *port =typec_altmode_get_partner (alt); +struct dp_altmode *dp; +int ret; + +/* FIXME: Port can only be DFP_U. */ + +/* Make sure we have compatiple pin configurations */ +if (!(DP_CAP_DFP_D_PIN_ASSIGN (port->vdo) & +DP_CAP_UFP_D_PIN_ASSIGN (alt->vdo)) && + !(DP_CAP_UFP_D_PIN_ASSIGN (port->vdo) & +DP_CAP_DFP_D_PIN_ASSIGN (alt->vdo))) +return -ENODEV ; + + ret =sysfs_create_group (&alt->dev.kobj, &dp_altmode_group); +if (ret) +return ret; + + dp =devm_kzalloc (&alt->dev,sizeof (*dp),GFP_KERNEL ); +if (!dp) +return -ENOMEM ; + +INIT_WORK (&dp->work, dp_altmode_work); +mutex_init (&dp->lock); + dp->port = port; + dp->alt = alt; + + alt->desc ="DisplayPort" ; + alt->ops = &dp_altmode_ops; + +typec_altmode_set_drvdata (alt, dp); + + dp->state =DP_STATE_ENTER ; +schedule_work (&dp->work); + +return 0 ; +} + +static void dp_altmode_remove (struct typec_altmode *alt) +{ +sysfs_remove_group (&alt->dev.kobj, &dp_altmode_group); +} + +static const struct typec_device_id dp_typec_id[] = { + {USB_TYPEC_DP_SID ,USB_TYPEC_DP_MODE }, + { }, +}; +MODULE_DEVICE_TABLE (typec, dp_typec_id); + +static struct typec_altmode_driver dp_altmode_driver = { + .id_table = dp_typec_id, + .probe = dp_altmode_probe, + .remove = dp_altmode_remove,
drivers/usb/typec/altmodes/displayport.c line 543
Quoted 10 lines
drivers/usb/typec/altmodes/displayport.c new file +10
-0+ .driver = { + .name = "typec_displayport", + .owner = THIS_MODULE, + }, +}; +module_typec_altmode_driver (dp_altmode_driver); + +MODULE_AUTHOR ("Heikki Krogerus <[email protected]>" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_DESCRIPTION ("DisplayPort Alternate Mode" );
Br,
Re: [RFC PATCH v4 7/8] usb: typec: pi3usb30532: Start using generic state values
In reply to Heikki KrogerusQuoted 13 lines · Heikki Krogerus
Instead of the tcpm specific mux states, using the generic USB type-c connector state values, and with DisplayPort using connector states defined for the DisplayPort Alt Mode.
Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/typec/mux/pi3usb30532.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/usb/typec/mux/pi3usb30532.c +0
-0
[...]
drivers/usb/typec/mux/pi3usb30532.c static int pi3usb30532_mux_set(struct typec_mux *mux, int state) · line 91
Quoted 13 lines
drivers/usb/typec/mux/pi3usb30532.c +3
-3@@ -83,21 +83,24 @@ static int pi3usb30532_mux_set(struct typec_mux *mux, int state) new_conf = pi->conf;switch (state) { -case TYPEC_MUX_NONE : +case TYPEC_STATE_SAFE : new_conf =PI3USB30532_CONF_OPEN ;break ; -case TYPEC_MUX_USB : +case TYPEC_STATE_USB : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) | -PI3USB30532_CONF_USB3 ; +PI3USB30532_CONF_USB3 ;
Unrelated white space change, inconsistent with the others below...
Quoted 7 lines
drivers/usb/typec/mux/pi3usb30532.c +2
-1break ; -case TYPEC_MUX_DP : +case TYPEC_DP_STATE_C : +case TYPEC_DP_STATE_E : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) |PI3USB30532_CONF_4LANE_DP ;break ;
drivers/usb/typec/mux/pi3usb30532.c static int pi3usb30532_mux_set(struct typec_mux *mux, int state) · line 106
Quoted 10 lines
drivers/usb/typec/mux/pi3usb30532.c +3
-1-case TYPEC_MUX_DOCK : +case TYPEC_DP_STATE_D : new_conf = (new_conf &PI3USB30532_CONF_SWAP ) |PI3USB30532_CONF_USB3_AND_2LANE_DP ;break ; +default : +break ; } ret =pi3usb30532_set_conf (pi, new_conf);
MBR, Sergei
---
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
Greg Kroah-Hartman
maintainerRe: [RFC PATCH v4 1/8] usb: pd: include kernel.h
In reply to Heikki KrogerusQuoted 1 line · Heikki Krogerus
Some of the macros use
le16_to_cpu().
What macros?
Is this causing build errors today? If so, why should it not be included now?
thanks,
greg k-h
---
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
Heikki Krogerus
maintainerRe: [RFC PATCH v4 1/8] usb: pd: include kernel.h
Quoted 7 lines · Greg Kroah-Hartman
Quoted 1 line · Heikki Krogerus
Some of the macros use
le16_to_cpu().What macros?
Is this causing build errors today? If so, why should it not be included now?
There are no build errors today.
I'll write a better commit message for this patch. I think I need to improve the commit messages of some of the other patches in this series as well.
Thanks,
Re: [RFC PATCH v4 2/8] usb: typec: helper for checking cable plug orientation
In reply to Heikki KrogerusHi Heikki,
Quoted 17 lines · Heikki Krogerus
This adds function
typec_get_orientation()that can be used for checking the current cable plug orientation.Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/typec/class.c | 11 +++++++++++ include/linux/usb/typec.h | 1 + 2 files changed, 12 insertions(+)drivers/usb/typec/class.c +0
-0@@ -1279,6 +1279,17 @@ int typec_set_orientation(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_set_orientation);
drivers/usb/typec/class.c int typec_set_orientation(struct typec_port *port, · line 1291
Quoted 10 lines
drivers/usb/typec/class.c +10
-0+/** +* typec_get_orientation - Get USB Type-C cable plug orientation +* @port: USB Type-C Port +* +* Get current cable plug orientation for @port. +*/ +enum typec_orientation typec_get_orientation (struct typec_port *port) +{ +return port->orientation; +}
+EXPORT_SYMBOL_GPL(typec_get_orientation);
Isn't this a candidate for an inline?
BR // Mats
Quoted 10 lines
drivers/usb/typec/class.c +1
-0+/** * typec_set_mode - Set mode of operation for USB Type-C connector * @port: USB Type-C port for the connector include/linux/usb/typec.h +0
-0
include/linux/usb/typec.h void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); · line 271
Quoted 7 lines
include/linux/usb/typec.h +1
-0@@ -265,6 +265,7 @@ 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); +enum typec_orientation typec_get_orientation (struct typec_port *port);int typec_set_mode (struct typec_port *port,int mode);#endif /* __LINUX_USB_TYPEC_H */
---
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
Re: [RFC PATCH v4 2/8] usb: typec: helper for checking cable plug orientation
Quoted 33 lines · Mats Karrman
Hi Heikki,
Quoted 16 lines · Heikki Krogerus
This adds function
typec_get_orientation()that can be used for checking the current cable plug orientation.Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/typec/class.c | 11 +++++++++++ include/linux/usb/typec.h | 1 + 2 files changed, 12 insertions(+)drivers/usb/typec/class.c +0
-0@@ -1279,6 +1279,17 @@ int typec_set_orientation(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_set_orientation);drivers/usb/typec/class.c int typec_set_orientation(struct typec_port *port, · line 1290
Quoted 10 lines
drivers/usb/typec/class.c +10
-0+/** +* typec_get_orientation - Get USB Type-C cable plug orientation +* @port: USB Type-C Port +* +* Get current cable plug orientation for @port. +*/ +enum typec_orientation typec_get_orientation (struct typec_port *port) +{ +return port->orientation; +}+EXPORT_SYMBOL_GPL(typec_get_orientation);
Quoted 2 lines
Isn't this a candidate for an inline?
Currently struct typec_port is class private. To make this function inline, struct typec_port would have to be moved from drivers/usb/typec/class.c to include/linux/usb/typec.h. That doesn't sound like a good idea to me.
Guenter
Quoted 17 lines
BR // Mats
Quoted 9 lines
drivers/usb/typec/class.c +1
-0+/** * typec_set_mode - Set mode of operation for USB Type-C connector * @port: USB Type-C port for the connector include/linux/usb/typec.h +0
-0include/linux/usb/typec.h void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode); · line 270
Quoted 6 lines
include/linux/usb/typec.h +1
-0@@ -265,6 +265,7 @@ 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); +enum typec_orientation typec_get_orientation (struct typec_port *port);int typec_set_mode (struct typec_port *port,int mode);#endif /* __LINUX_USB_TYPEC_H */
---
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
Heikki Krogerus
maintainerRe: [RFC PATCH v4 2/8] usb: typec: helper for checking cable plug orientation
Quoted 34 lines · Guenter Roeck
Quoted 33 lines · Mats Karrman
Hi Heikki,
Quoted 16 lines · Heikki Krogerus
This adds function
typec_get_orientation()that can be used for checking the current cable plug orientation.Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/typec/class.c | 11 +++++++++++ include/linux/usb/typec.h | 1 + 2 files changed, 12 insertions(+)drivers/usb/typec/class.c +0
-0@@ -1279,6 +1279,17 @@ int typec_set_orientation(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_set_orientation);drivers/usb/typec/class.c int typec_set_orientation(struct typec_port *port, · line 1290
Quoted 10 lines
drivers/usb/typec/class.c +10
-0+/** +* typec_get_orientation - Get USB Type-C cable plug orientation +* @port: USB Type-C Port +* +* Get current cable plug orientation for @port. +*/ +enum typec_orientation typec_get_orientation (struct typec_port *port) +{ +return port->orientation; +}+EXPORT_SYMBOL_GPL(typec_get_orientation);
Quoted 6 lines
Quoted 2 lines
Isn't this a candidate for an inline?
Currently struct
typec_portis class private. To make this function inline, structtypec_portwould have to be moved fromdrivers/usb/typec/class.ctoinclude/linux/usb/typec.h. That doesn't sound like a good idea to me.
Yes, let's keep the structure protected.
But thanks for the report, I'll fix it.
Br,