typec changes
Subsystems (4)
Heikki Krogerus
maintainercover typec changes
Hi Greg,
Here all the "trivial" changes I have for the USB Type-C class at this stage. The first patch I already send before [1]. You told me to leave the checks in, so I did. The rest of the patches in that series were about USB4, which I'm not including here. I decided to propose them separately.
The third patch in this series make's it possible to swap the power role even when USB Power Delivery is not supported since the latest specification now allows it. The rest of the patches are cleanups.
Let me know if you want me to change anything.
thanks,
[1] https://lore.kernel.org/linux-usb/[email protected]/
Heikki Krogerus (6):
usb: typec: Make the attributes read-only when writing is not possible
usb: typec: Hide the port_type attribute when it's not supported
usb: typec: Allow power role swapping even without USB PD
usb: typec: Fix the description of struct typec_capability
usb: typec: altmode: Remove the notification chain
usb: typec: mux: Drop support for device name matching
Documentation/ABI/testing/sysfs-class-typec | 14 +- Documentation/driver-api/usb/typec_bus.rst | 22 +--- drivers/usb/typec/bus.c | 12 +- drivers/usb/typec/bus.h | 2 - drivers/usb/typec/class.c | 137 +++++++++----------- drivers/usb/typec/mux.c | 25 +--- include/linux/usb/typec.h | 2 - include/linux/usb/typec_altmode.h | 7 - 8 files changed, 77 insertions(+), 144 deletions(-)
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH v2 1/6 usb: typec: Make the attributes read-only when writing is not possible
This affects the read-writable attribute files. Before this there was no way for the user to know is changing the value supported or not.
From now on those attribute files will be made read-only unless the underlying driver supports changing of the value.
---
Changes since v1:
- Left the checks in that make sure we don't crash the kernel even if somebody changes the permissions on the sysfs files.
--- drivers/usb/typec/class.c | 65 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-)
drivers/usb/typec/class.c +63 -2
@@ -432,7 +432,28 @@ static struct attribute *typec_altmode_attrs[] = { &dev_attr_vdo.attr, NULL }; -ATTRIBUTE_GROUPS (typec_altmode); + +static umode_t typec_altmode_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct typec_altmode *adev =to_typec_altmode (kobj_to_dev (kobj)); + +if (attr == &dev_attr_active.attr) +if (!adev->ops || !adev->ops->activate) +return 0444 ; + +return attr->mode; +} + +static struct attribute_group typec_altmode_group = { + .is_visible = typec_altmode_attr_is_visible, + .attrs = typec_altmode_attrs, +}; + +static const struct attribute_group *typec_altmode_groups[] = { + &typec_altmode_group, +NULL +};static int altmode_id_get (struct device *dev) {
@@ -1305,7 +1326,47 @@ static struct attribute *typec_attrs[] = { &dev_attr_port_type.attr, NULL, }; -ATTRIBUTE_GROUPS (typec); + +static umode_t typec_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct typec_port *port =to_typec_port (kobj_to_dev (kobj)); + +if (attr == &dev_attr_data_role.attr) { +if (port->cap->data !=TYPEC_PORT_DRD || + !port->ops || !port->ops->dr_set) +return 0444 ; + }else if (attr == &dev_attr_power_role.attr) { +if (port->cap->type !=TYPEC_PORT_DRP || + !port->cap->pd_revision || + !port->ops || !port->ops->pr_set) +return 0444 ; + }else if (attr == &dev_attr_vconn_source.attr) { +if (!port->cap->pd_revision || + !port->ops || !port->ops->vconn_set) +return 0444 ; + }else if (attr == &dev_attr_preferred_role.attr) { +if (port->cap->type !=TYPEC_PORT_DRP || + !port->ops || !port->ops->try_role) +return 0444 ; + }else if (attr == &dev_attr_port_type.attr) { +if (port->cap->type !=TYPEC_PORT_DRP || + !port->ops || !port->ops->port_type_set) +return 0444 ; + } + +return attr->mode; +} + +static struct attribute_group typec_group = { + .is_visible = typec_attr_is_visible, + .attrs = typec_attrs, +}; + +static const struct attribute_group *typec_groups[] = { + &typec_group, +NULL +};static int typec_uevent (struct device *dev,struct kobj_uevent_env *env) {
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH 2/6 usb: typec: Hide the port_type attribute when it's not supported
In reply to Heikki KrogerusThe port_type attribute is special. It is meant to allow changing the capability of the port in runtime. It is purely Linux kernel specific feature, i.e. the feature is not described in any of the USB specifications.
Because of the special nature of this attribute, handling it differently compared to the other writable attributes, and hiding it when the underlying port interface (or just the driver) does not support the feature.
--- drivers/usb/typec/class.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/usb/typec/class.c +3 -2
@@ -1350,8 +1350,9 @@ static umode_t typec_attr_is_visible(struct kobject *kobj, !port->ops || !port->ops->try_role)return 0444 ; }else if (attr == &dev_attr_port_type.attr) { -if (port->cap->type !=TYPEC_PORT_DRP || - !port->ops || !port->ops->port_type_set) +if (!port->ops || !port->ops->port_type_set) +return 0 ; +if (port->cap->type !=TYPEC_PORT_DRP )return 0444 ; }
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH 3/6 usb: typec: Allow power role swapping even without USB PD
In reply to Heikki KrogerusEven though originally the USB Type-C Specification did not describe the steps for power role swapping without USB PD contract in place, it did not actually mean power role swap without USB PD was not allowed. The USB Type-C Specification did not clearly separate the data and power roles until in the release 1.2 which is why there also were no clear steps for the scenario where only the power role was swapped without USB PD contract before that.
Since in the latest version of the specification the power role swap without USB PD is now clearly mentioned as allowed operation, removing the check that prevented power role swap without USB PD support.
--- Documentation/ABI/testing/sysfs-class-typec | 14 +++++++------- drivers/usb/typec/class.c | 6 ------ 2 files changed, 7 insertions(+), 13 deletions(-)
Documentation/ABI/testing/sysfs-class-typec +7 -7
@@ -20,13 +20,13 @@ Date: April 2017 Contact: Heikki Krogerus <[email protected]> Description: The supported power roles. This attribute can be used to request - power role swap on the port when the port supports USB Power - Delivery. Swapping is supported as synchronous operation, so - write(2) to the attribute will not return until the operation - has finished. The attribute is notified about role changes so - that poll(2) on the attribute wakes up. Change on the role will - also generate uevent KOBJ_CHANGE. The current role is show in - brackets, for example "[source] sink" when in source mode. + power role swap on the port. Swapping is supported as + synchronous operation, so write(2) to the attribute will not + return until the operation has finished. The attribute is + notified about role changes so that poll(2) on the attribute + wakes up. Change on the role will also generate uevent + KOBJ_CHANGE. The current role is show in brackets, for example + "[source] sink" when in source mode. Valid values: source, sink
drivers/usb/typec/class.c +0 -6
@@ -1112,11 +1112,6 @@ static ssize_t power_role_store(struct device *dev,struct typec_port *port =to_typec_port (dev);int ret; -if (!port->cap->pd_revision) { -dev_dbg (dev,"USB Power Delivery not supported\n" ); -return -EOPNOTSUPP ; - } -if (!port->ops || !port->ops->pr_set) {dev_dbg (dev,"power role swapping not supported\n" );return -EOPNOTSUPP ;
@@ -1338,7 +1333,6 @@ static umode_t typec_attr_is_visible(struct kobject *kobj,return 0444 ; }else if (attr == &dev_attr_power_role.attr) {if (port->cap->type !=TYPEC_PORT_DRP || - !port->cap->pd_revision || !port->ops || !port->ops->pr_set)return 0444 ; }else if (attr == &dev_attr_vconn_source.attr) {
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH 4/6 usb: typec: Fix the description of struct typec_capability
In reply to Heikki KrogerusRemoving descriptions of the mux and sw members. They are no longer part of the structure.
--- include/linux/usb/typec.h | 2 -- 1 file changed, 2 deletions(-)
include/linux/usb/typec.h +0 -2
@@ -198,8 +198,6 @@ struct typec_operations {* @pd_revision: USB Power Delivery Specification revision if supported * @prefer_role: Initial role preference (DRP ports). * @accessory: Supported Accessory Modes -* @sw: Cable plug orientation switch -* @mux: Multiplexer switch for Alternate/Accessory Modes * @fwnode: Optional fwnode of the port * @driver_data: Private pointer for driver specific info * @ops: Port operations vector
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH 5/6 usb: typec: altmode: Remove the notification chain
In reply to Heikki KrogerusUsing the generic notification chain is not reasonable with the alternate modes because it would require dependencies between the drivers of the components that need the notifications, and the typec drivers.
There are no users for the alternate mode notifications, so removing the chain and the API for it completely.
--- Documentation/driver-api/usb/typec_bus.rst | 22 +------ drivers/usb/typec/bus.c | 12 +--- drivers/usb/typec/bus.h | 2 - drivers/usb/typec/class.c | 67 +--------------------- include/linux/usb/typec_altmode.h | 7 --- 5 files changed, 3 insertions(+), 107 deletions(-)
Documentation/driver-api/usb/typec_bus.rst +1 -21
@@ -53,9 +53,7 @@ in need to reconfigure the pins on the connector, the alternate mode driver needs to notify the bus using :c:func:`typec_altmode_notify()`. The driver passes the negotiated SVID specific pin configuration value to the function as parameter. The bus driver will then configure the mux behind the connector using -that value as the state value for the mux, and also call blocking notification -chain to notify the external drivers about the state of the connector that need -to know it. +that value as the state value for the mux. NOTE: The SVID specific pin configuration values must always start from ``TYPEC_STATE_MODAL``. USB Type-C specification defines two default states for
@@ -80,19 +78,6 @@ Helper macro ``TYPEC_MODAL_STATE()`` can also be used:: #define ALTMODEX_CONF_A = TYPEC_MODAL_STATE(0); #define ALTMODEX_CONF_B = TYPEC_MODAL_STATE(1); -Notification chain -~~~~~~~~~~~~~~~~~~ - -The drivers for the components that the alternate modes are designed for need to -get details regarding the results of the negotiation with the partner, and the -pin configuration of the connector. In case of DisplayPort alternate mode for -example, the GPU drivers will need to know those details. In case of -Thunderbolt alternate mode, the thunderbolt drivers will need to know them, and -so on. - -The notification chain is designed for this purpose. The drivers can register -notifiers with :c:func:`typec_altmode_register_notifier()`. - Cable plug alternate modes ~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -129,8 +114,3 @@ Cable Plug operations .. kernel-doc:: drivers/usb/typec/bus.c :functions: typec_altmode_get_plug typec_altmode_put_plug - -Notifications -~~~~~~~~~~~~~ -.. kernel-doc:: drivers/usb/typec/class.c - :functions: typec_altmode_register_notifier typec_altmode_unregister_notifier
drivers/usb/typec/bus.c +1 -11
@@ -30,17 +30,10 @@ static int typec_altmode_set_state(struct typec_altmode *adev, {bool is_port =is_typec_port (adev->dev.parent);struct altmode *port_altmode; -int ret; port_altmode = is_port ?to_altmode (adev) :to_altmode (adev)->partner; - ret =typec_altmode_set_mux (port_altmode, conf, data); -if (ret) -return ret; - -blocking_notifier_call_chain (&port_altmode->nh, conf,NULL ); - -return 0 ; +return typec_altmode_set_mux (port_altmode, conf, data); }/* -------------------------------------------------------------------------- */
@@ -82,9 +75,6 @@ int typec_altmode_notify(struct typec_altmode *adev,if (ret)return ret; -blocking_notifier_call_chain (is_port ? &altmode->nh : &partner->nh, - conf, data); -if (partner->adev.ops && partner->adev.ops->notify)return partner->adev.ops->notify (&partner->adev, conf, data);
drivers/usb/typec/bus.h +0 -2
@@ -22,8 +22,6 @@ struct altmode {struct altmode *partner;struct altmode *plug[2 ]; - -struct blocking_notifier_head nh; };#define to_altmode (d) container_of(d, struct altmode, adev)
drivers/usb/typec/class.c +1 -66
79 lines not on this page · raw message
include/linux/usb/typec_altmode.h +0 -7
@@ -126,13 +126,6 @@ void typec_altmode_put_plug(struct typec_altmode *plug);struct typec_altmode *typec_match_altmode (struct typec_altmode **altmodes,size_t n,u16 svid,u8 mode); -struct typec_altmode * -typec_altmode_register_notifier (struct device *dev,u16 svid,u8 mode, -struct notifier_block *nb); - -void typec_altmode_unregister_notifier (struct typec_altmode *adev, -struct notifier_block *nb); -/** * typec_altmode_get_orientation - Get cable plug orientation * altmode: Handle to the alternate mode
Signature · 1 line
2.25.0
Heikki Krogerus
maintainerPATCH 6/6 usb: typec: mux: Drop support for device name matching
In reply to Heikki KrogerusThere are no more users for the old device connection descriptions that used device names.
--- drivers/usb/typec/mux.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-)
drivers/usb/typec/mux.c +4 -21
@@ -17,11 +17,6 @@#include "bus.h" -static int name_match (struct device *dev,const void *name) -{ -return !strcmp ((const char *)name,dev_name (dev)); -} -static bool dev_name_ends_with (struct device *dev,const char *suffix) {const char *name =dev_name (dev);
@@ -44,16 +39,11 @@ static void *typec_switch_match(struct device_connection *con, int ep, {struct device *dev; -if (con->fwnode) { -if (con->id && !fwnode_property_present (con->fwnode, con->id)) -return NULL ; +if (con->id && !fwnode_property_present (con->fwnode, con->id)) +return NULL ; - dev =class_find_device (&typec_mux_class,NULL , con->fwnode, - switch_fwnode_match); - }else { - dev =class_find_device (&typec_mux_class,NULL , - con->endpoint[ep], name_match); - } + dev =class_find_device (&typec_mux_class,NULL , con->fwnode, + switch_fwnode_match);return dev ?to_typec_switch (dev) :ERR_PTR (-EPROBE_DEFER ); }
@@ -191,13 +181,6 @@ static void *typec_mux_match(struct device_connection *con, int ep, void *data)u16 *val;int i; -if (!con->fwnode) { - dev =class_find_device (&typec_mux_class,NULL , - con->endpoint[ep], name_match); - -return dev ?to_typec_switch (dev) :ERR_PTR (-EPROBE_DEFER ); - } -/* * Check has the identifier already been "consumed". If it * has, no need to do any extra connection identification.
Signature · 1 line
2.25.0
Greg Kroah-Hartman
maintainerQuoted 8 lines · Heikki Krogerus
Hi Greg,
Here all the "trivial" changes I have for the USB Type-C class at this stage. The first patch I already send before [1]. You told me to leave the checks in, so I did. The rest of the patches in that series were about USB4, which I'm not including here. I decided to propose them separately.
Quoted 5 lines
The third patch in this series make's it possible to swap the power role even when USB Power Delivery is not supported since the latest specification now allows it. The rest of the patches are cleanups.
Let me know if you want me to change anything.
Are these fixes for 5.6-rc2 or for new stuff for 5.7-rc1?
thanks,
greg k-h
Heikki Krogerus
maintainerQuoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Heikki Krogerus
Hi Greg,
Here all the "trivial" changes I have for the USB Type-C class at this stage. The first patch I already send before [1]. You told me to leave the checks in, so I did. The rest of the patches in that series were about USB4, which I'm not including here. I decided to propose them separately.
Quoted 7 lines
Quoted 5 lines
The third patch in this series make's it possible to swap the power role even when USB Power Delivery is not supported since the latest specification now allows it. The rest of the patches are cleanups.
Let me know if you want me to change anything.
Are these fixes for 5.6-rc2 or for new stuff for 5.7-rc1?
For 5.7-rc1. Sorry.
thanks,
Signature · 1 line
heikki