usb: typec: Add typec_port_register_altmodes()
v3 cover usb: typec: Add typec_port_register_altmodes()
Hi All,
Here is v3 of my series to actually make it possible to use alt-modes on tcpm managed Type-C ports.
Note this v3 series deliberately does not include devicetree bindings documentation, as requested by Rob. ATM the fwnodes used to register the altmodes are only used internally to pass platform info from a drivers/platform/x86 driver to the type-c subsystem.
When a devicetree user of this functionally comes up and the dt-bindings have been hashed out the internal use can be adjusted to match the dt-bindings.
Changes in v3:
- Rename typec_port_register_altmodes_from_fwnode() to typec_port_register_altmodes()
- Use fwnode_for_each_child_node()
Changes in v2:
- Drop the DT bindings doc, as requested by Rob
- Drop unnecessary fwnode parameter from
typec_port_register_altmodes_from_fwnode()
Greg, assuming there are no objections to merging this, then you hereby have my ack for also taking the platform/x86/intel_cht_int33fe change upstream through the USB tree.
Regards,
Hans
Hans de Goede (3):
usb: typec: Add typec_port_register_altmodes()
usb: typec: tcpm: Add support for altmodes platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the
connector fwnode
.../platform/x86/intel_cht_int33fe_typec.c | 19 +++++++ drivers/usb/typec/class.c | 54 +++++++++++++++++++ drivers/usb/typec/tcpm/tcpm.c | 4 ++ include/linux/usb/typec.h | 6 +++ 4 files changed, 83 insertions(+)
Signature · 1 line
2.30.2
PATCH v2 1/3 usb: typec: Add typec_port_register_altmodes()
This can be used by Type-C controller drivers which use a standard usb-connector fwnode, with altmodes sub-node, to describe the available altmodes.
Note there are is no devicetree bindings documentation for the altmodes node, this is deliberate. ATM the fwnodes used to register the altmodes are only used internally to pass platform info from a drivers/platform/x86 driver to the type-c subsystem.
When a devicetree user of this functionally comes up and the dt-bindings have been hashed out the internal use can be adjusted to match the dt-bindings.
Currently the typec_port_register_altmodes() function expects an "altmodes" child fwnode on port->dev with this "altmodes" fwnode having child fwnodes itself with each child containing 2 integer properties:
1. A "svid" property, which sets the id of the altmode, e.g. displayport altmode has a svid of 0xff01.
2. A "vdo" property, typically used as a bitmask describing the capabilities of the altmode, the bits in the vdo are specified in the specification of the altmode.
---
Changes in v3:
- Rename typec_port_register_altmodes_from_fwnode() to typec_port_register_altmodes()
- Use fwnode_for_each_child_node()
Changes in v2:
- Drop the unnecessary fwnode parameter from typec_port_register_altmodes_from_fwnode()
- Document the expected "altmodes" fwnode in the commit message for now as v2 of the patch-set drops the dt-bindings since there are not DT users for this yet
--- drivers/usb/typec/class.c | 54 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 6 +++++ 2 files changed, 60 insertions(+)
drivers/usb/typec/class.c +54 -0
@@ -1978,6 +1978,60 @@ typec_port_register_altmode(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_port_register_altmode); +void typec_port_register_altmodes (struct typec_port *port, +const struct typec_altmode_ops *ops,void *drvdata, +struct typec_altmode **altmodes,size_t n) +{ +struct fwnode_handle *altmodes_node, *child; +struct typec_altmode_desc desc; +struct typec_altmode *alt; +size_t index =0 ; +u32 svid, vdo; +int ret; + + altmodes_node =device_get_named_child_node (&port->dev,"altmodes" ); +if (!altmodes_node) +return ;/* No altmodes specified */ + +fwnode_for_each_child_node (altmodes_node, child) { + ret =fwnode_property_read_u32 (child,"svid" , &svid); +if (ret) { +dev_err (&port->dev,"Error reading svid for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + ret =fwnode_property_read_u32 (child,"vdo" , &vdo); +if (ret) { +dev_err (&port->dev,"Error reading vdo for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + +if (index >= n) { +dev_err (&port->dev,"Error not enough space for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + desc.svid = svid; + desc.vdo = vdo; + desc.mode = index +1 ; + alt =typec_port_register_altmode (port, &desc); +if (IS_ERR (alt)) { +dev_err (&port->dev,"Error registering altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + alt->ops = ops; +typec_altmode_set_drvdata (alt, drvdata); + altmodes[index] = alt; + index++; + } +} +EXPORT_SYMBOL_GPL (typec_port_register_altmodes); +/** * typec_register_port - Register a USB Type-C Port * @parent: Parent device
include/linux/usb/typec.h +6 -0
@@ -17,6 +17,7 @@ struct typec_partner;struct typec_cable ;struct typec_plug ;struct typec_port ; +struct typec_altmode_ops ;struct fwnode_handle ;struct device ;
@@ -138,6 +139,11 @@ struct typec_altmodestruct typec_altmode *typec_port_register_altmode (struct typec_port *port,const struct typec_altmode_desc *desc); + +void typec_port_register_altmodes (struct typec_port *port, +const struct typec_altmode_ops *ops,void *drvdata, +struct typec_altmode **altmodes,size_t n); +void typec_unregister_altmode (struct typec_altmode *altmode);struct typec_port *typec_altmode2port (struct typec_altmode *alt);
Signature · 1 line
2.30.2
Quoted 20 lines · Hans de Goede
This can be used by Type-C controller drivers which use a standard usb-connector fwnode, with altmodes sub-node, to describe the available altmodes.
Note there are is no devicetree bindings documentation for the altmodes node, this is deliberate. ATM the fwnodes used to register the altmodes are only used internally to pass platform info from a
drivers/platform/x86driver to the type-c subsystem.When a devicetree user of this functionally comes up and the dt-bindings have been hashed out the internal use can be adjusted to match the dt-bindings.
Currently the
typec_port_register_altmodes()function expects an "altmodes" child fwnode onport->devwith this "altmodes" fwnode having child fwnodes itself with each child containing 2 integer properties:1. A "svid" property, which sets the id of the altmode, e.g. displayport altmode has a svid of
0xff01.
Quoted 6 lines
2. A "vdo" property, typically used as a bitmask describing the capabilities of the altmode, the bits in the vdo are specified in the specification of the altmode.
Reviewed-by Heikki Krogerus <[email protected]>Signed-off-by Hans de Goede <[email protected]>
Quoted 107 lines
---
Changes in v3:
- Renametypec_port_register_altmodes_from_fwnode()totypec_port_register_altmodes()
- Usefwnode_for_each_child_node()Changes in v2:
- Drop the unnecessary fwnode parameter fromtypec_port_register_altmodes_from_fwnode()
- Document the expected "altmodes" fwnode in the commit message for now as v2 of the patch-set drops the dt-bindings since there are not DT users for this yet--- drivers/usb/typec/class.c | 54 +++++++++++++++++++++++++++++++++++++++ include/linux/usb/typec.h | 6 +++++ 2 files changed, 60 insertions(+)drivers/usb/typec/class.c +54
-0@@ -1978,6 +1978,60 @@ typec_port_register_altmode(struct typec_port *port, }EXPORT_SYMBOL_GPL (typec_port_register_altmode); +void typec_port_register_altmodes (struct typec_port *port, +const struct typec_altmode_ops *ops,void *drvdata, +struct typec_altmode **altmodes,size_t n) +{ +struct fwnode_handle *altmodes_node, *child; +struct typec_altmode_desc desc; +struct typec_altmode *alt; +size_t index =0 ; +u32 svid, vdo; +int ret; + + altmodes_node =device_get_named_child_node (&port->dev,"altmodes" ); +if (!altmodes_node) +return ;/* No altmodes specified */ + +fwnode_for_each_child_node (altmodes_node, child) { + ret =fwnode_property_read_u32 (child,"svid" , &svid); +if (ret) { +dev_err (&port->dev,"Error reading svid for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + ret =fwnode_property_read_u32 (child,"vdo" , &vdo); +if (ret) { +dev_err (&port->dev,"Error reading vdo for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + +if (index >= n) { +dev_err (&port->dev,"Error not enough space for altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + desc.svid = svid; + desc.vdo = vdo; + desc.mode = index +1 ; + alt =typec_port_register_altmode (port, &desc); +if (IS_ERR (alt)) { +dev_err (&port->dev,"Error registering altmode %s\n" , +fwnode_get_name (child)); +continue ; + } + + alt->ops = ops; +typec_altmode_set_drvdata (alt, drvdata); + altmodes[index] = alt; + index++; + } +} +EXPORT_SYMBOL_GPL (typec_port_register_altmodes); +/** * typec_register_port - Register a USB Type-C Port * @parent: Parent device include/linux/usb/typec.h +6
-0@@ -17,6 +17,7 @@ struct typec_partner;struct typec_cable ;struct typec_plug ;struct typec_port ; +struct typec_altmode_ops ;struct fwnode_handle ;struct device ;@@ -138,6 +139,11 @@ struct typec_altmodestruct typec_altmode *typec_port_register_altmode (struct typec_port *port,const struct typec_altmode_desc *desc); + +void typec_port_register_altmodes (struct typec_port *port, +const struct typec_altmode_ops *ops,void *drvdata, +struct typec_altmode **altmodes,size_t n); +void typec_unregister_altmode (struct typec_altmode *altmode);struct typec_port *typec_altmode2port (struct typec_altmode *alt);
PATCH v2 2/3 usb: typec: tcpm: Add support for altmodes
In reply to Hans de GoedeAdd support for altmodes described in the usb-connector fwnode associated with the Type-C controller by calling the new typec_port_register_altmodes_from_fwnode() helper for this.
--- drivers/usb/typec/tcpm/tcpm.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +4 -0
@@ -6072,6 +6072,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_role_sw_put; } +typec_port_register_altmodes (port->typec_port, + &tcpm_altmode_ops, port, + port->port_altmode,ALTMODE_DISCOVERY_MAX ); +mutex_lock (&port->lock);tcpm_init (port);mutex_unlock (&port->lock);
Signature · 1 line
2.30.2
Re: [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes
Quoted 5 lines · Hans de Goede
Add support for altmodes described in the usb-connector fwnode associated with the Type-C controller by calling the new
typec_port_register_altmodes_from_fwnode()helper for this.Signed-off-by Hans de Goede <[email protected]>
Quoted 21 lines
--- drivers/usb/typec/tcpm/tcpm.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/typec/tcpm/tcpm.c +4
-0@@ -6072,6 +6072,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_role_sw_put; } +typec_port_register_altmodes (port->typec_port, + &tcpm_altmode_ops, port, + port->port_altmode,ALTMODE_DISCOVERY_MAX ); +mutex_lock (&port->lock);tcpm_init (port);mutex_unlock (&port->lock);Signature · 1 line
2.30.2
Signature · 1 line
heikki
Re: [PATCH v2 2/3] usb: typec: tcpm: Add support for altmodes
In reply to Hans de GoedeQuoted 5 lines · Hans de Goede
Add support for altmodes described in the usb-connector fwnode associated with the Type-C controller by calling the new
typec_port_register_altmodes_from_fwnode()helper for this.Signed-off-by Hans de Goede <[email protected]>
Quoted 20 lines
--- drivers/usb/typec/tcpm/tcpm.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/usb/typec/tcpm/tcpm.c +4
-0@@ -6072,6 +6072,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc) goto out_role_sw_put; } +typec_port_register_altmodes (port->typec_port, + &tcpm_altmode_ops, port, + port->port_altmode,ALTMODE_DISCOVERY_MAX ); +mutex_lock (&port->lock);tcpm_init (port);mutex_unlock (&port->lock);
PATCH v2 3/3 platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
In reply to Hans de GoedeAdd a displayport altmode fwnode to the usb-connector fwnode, devices which use this driver support display-port altmode through the PI3USB30532 USB switch, this enables support for this.
--- .../platform/x86/intel_cht_int33fe_typec.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/platform/x86/intel_cht_int33fe_typec.c +19 -0
@@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = { .properties = usb_connector_properties, }; +static const struct software_node altmodes_node = { + .name ="altmodes" , + .parent = &usb_connector_node, +}; + +static const struct property_entry dp_altmode_properties[] = { +PROPERTY_ENTRY_U32 ("svid" ,0xff01 ), +PROPERTY_ENTRY_U32 ("vdo" ,0x0c0086 ), + { } +}; + +static const struct software_node dp_altmode_node = { + .name ="displayport-altmode" , + .parent = &altmodes_node, + .properties = dp_altmode_properties, +}; +static const struct software_node *node_group[] = { &fusb302_node, &max17047_node, &pi3usb30532_node, &displayport_node, &usb_connector_node, + &altmodes_node, + &dp_altmode_node,NULL };
Signature · 1 line
2.30.2
Re: [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
Quoted 5 lines · Hans de Goede
Add a displayport altmode fwnode to the usb-connector fwnode, devices which use this driver support display-port altmode through the PI3USB30532 USB switch, this enables support for this.
Signed-off-by Hans de Goede <[email protected]>
Quoted 29 lines
--- .../platform/x86/intel_cht_int33fe_typec.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/platform/x86/intel_cht_int33fe_typec.c +17
-0@@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = { .properties = usb_connector_properties, }; +static const struct software_node altmodes_node = { + .name ="altmodes" , + .parent = &usb_connector_node, +}; + +static const struct property_entry dp_altmode_properties[] = { +PROPERTY_ENTRY_U32 ("svid" ,0xff01 ), +PROPERTY_ENTRY_U32 ("vdo" ,0x0c0086 ), + { } +}; + +static const struct software_node dp_altmode_node = { + .name ="displayport-altmode" , + .parent = &altmodes_node, + .properties = dp_altmode_properties, +}; +
drivers/platform/x86/intel_cht_int33fe_typec.c static const struct software_node usb_connector_node = { · line 153
Quoted 10 lines
drivers/platform/x86/intel_cht_int33fe_typec.c +2
-0static const struct software_node *node_group[] = { &fusb302_node, &max17047_node, &pi3usb30532_node, &displayport_node, &usb_connector_node, + &altmodes_node, + &dp_altmode_node,NULL };
thanks,
Signature · 1 line
heikki
Re: [PATCH v2 3/3] platform/x86/intel_cht_int33fe: Add displayport altmode fwnode to the connector fwnode
In reply to Hans de GoedeQuoted 5 lines · Hans de Goede
Add a displayport altmode fwnode to the usb-connector fwnode, devices which use this driver support display-port altmode through the PI3USB30532 USB switch, this enables support for this.
Signed-off-by Hans de Goede <[email protected]>
Quoted 41 lines
--- .../platform/x86/intel_cht_int33fe_typec.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)drivers/platform/x86/intel_cht_int33fe_typec.c +19
-0@@ -124,12 +124,31 @@ static const struct software_node usb_connector_node = { .properties = usb_connector_properties, }; +static const struct software_node altmodes_node = { + .name ="altmodes" , + .parent = &usb_connector_node, +}; + +static const struct property_entry dp_altmode_properties[] = { +PROPERTY_ENTRY_U32 ("svid" ,0xff01 ), +PROPERTY_ENTRY_U32 ("vdo" ,0x0c0086 ), + { } +}; + +static const struct software_node dp_altmode_node = { + .name ="displayport-altmode" , + .parent = &altmodes_node, + .properties = dp_altmode_properties, +}; +static const struct software_node *node_group[] = { &fusb302_node, &max17047_node, &pi3usb30532_node, &displayport_node, &usb_connector_node, + &altmodes_node, + &dp_altmode_node,NULL };