common SVDM version and VDO from dt
Subsystems (5)
v2 cover common SVDM version and VDO from dt
patch v1 is here:
https://lore.kernel.org/linux-devicetree/[email protected]/
Changes from v1:
=================
usb: typec: Determine common SVDM Versions
- removed the "local" variables (svdm_version) in tcpm.c and (altmodes/ucsi)/displayport.c
- added a member "svdm_version" in struct typec_capabilities indicating the default SVDM version of the port
- added a member "common_svdm_ver" in struct typec_port indicating the common SVDM version between the port and the partner
- implemented the get/set API of the common_svdm_ver in typec/class.c so that clients can read/update the common SVDM version
- added more definitions of Product Type VDOs
dt-bindings: connector: Add SVDM VDO properties
- updated the dt-bindings documentations
- added more definitions of Product Type VDOs
usb: typec: tcpm: Get Sink VDO from fwnode
- updated the commit message
Kyle Tso (3):
usb: typec: Determine common SVDM Versions
dt-bindings: connector: Add SVDM VDO properties
usb: typec: tcpm: Get Sink VDO from fwnode
.../bindings/connector/usb-connector.yaml | 11 + drivers/usb/typec/altmodes/displayport.c | 5 +- drivers/usb/typec/class.c | 21 +- drivers/usb/typec/tcpm/tcpm.c | 61 +++- drivers/usb/typec/ucsi/displayport.c | 10 +- drivers/usb/typec/ucsi/ucsi.c | 2 + include/dt-bindings/usb/pd.h | 311 ++++++++++++++++- include/linux/usb/pd_vdo.h | 315 ++++++++++++++---- include/linux/usb/typec.h | 10 + 9 files changed, 656 insertions(+), 90 deletions(-)
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v2 1/3 usb: typec: Determine common SVDM Versions
PD Spec Revision 3.0 Version 2.0 + ECNs 2020-12-10
6.4.4.2.3 Structured VDM Version
"The Structured VDM Version field of the Discover Identity Command sent and received during VDM discovery Shall be used to determine the lowest common Structured VDM Version supported by the Port Partners or Cable Plug and Shall continue to operate using this Specification Revision until they are Detached."
Also clear the fields newly defined in SVDM version 2.0 for compatibilities. And fix some VDO definitions changed in the Spec.
---
Changes since v1:
- removed the "local" variables (svdm_version) in tcpm.c and (altmodes/ucsi)/displayport.c
- added a member "svdm_version" in struct typec_capabilities indicating the default SVDM version of the port
- added a member "common_svdm_ver" in struct typec_port indicating the common SVDM version between the port and the partner
- implemented the get/set API of the common_svdm_ver in typec/class.c so that clients can read/update the common SVDM version
- added more definitions of Product Type VDOs
drivers/usb/typec/altmodes/displayport.c | 5 +- drivers/usb/typec/class.c | 21 +- drivers/usb/typec/tcpm/tcpm.c | 49 +++- drivers/usb/typec/ucsi/displayport.c | 10 +- drivers/usb/typec/ucsi/ucsi.c | 2 + include/linux/usb/pd_vdo.h | 315 +++++++++++++++++------ include/linux/usb/typec.h | 10 + 7 files changed, 323 insertions(+), 89 deletions(-)
drivers/usb/typec/altmodes/displayport.c +4 -1
@@ -15,7 +15,8 @@#include <linux/usb/typec_dp.h> #include "displayport.h" -#define DP_HEADER (_dp, cmd) (VDO((_dp)->alt->svid, 1, cmd) | \ +#define COMMON_SVDM_VER (_dp) (typec_get_common_svdm_version((_dp)->typec)) +#define DP_HEADER (_dp, cmd) (VDO((_dp)->alt->svid, 1, COMMON_SVDM_VER(_dp), cmd) | \ VDO_OPOS(USB_TYPEC_DP_MODE))enum {
@@ -62,6 +63,7 @@ struct dp_altmode {struct work_struct work;struct typec_altmode *alt;const struct typec_altmode *port; +struct typec_port *typec; };static int dp_altmode_notify (struct dp_altmode *dp)
@@ -536,6 +538,7 @@ int dp_altmode_probe(struct typec_altmode *alt)mutex_init (&dp->lock); dp->port = port; dp->alt = alt; + dp->typec =typec_altmode2port (alt); alt->desc ="DisplayPort" ; alt->ops = &dp_altmode_ops;
drivers/usb/typec/class.c +17 -4
@@ -49,6 +49,7 @@ struct typec_port {enum typec_role vconn_role;enum typec_pwr_opmode pwr_opmode;enum typec_port_type port_type; +enum usb_pd_svdm_ver common_svdm_ver;struct mutex port_type_lock;enum typec_orientation orientation;
@@ -86,7 +87,7 @@ static const char * const typec_accessory_modes[] = {/* Product types defined in USB PD Specification R3.0 V2.0 */ static const char *const product_type_ufp[8 ] = { - [IDH_PTYPE_UNDEF ] ="undefined" , + [IDH_PTYPE_NOT_UFP ] ="not_ufp" , [IDH_PTYPE_HUB ] ="hub" , [IDH_PTYPE_PERIPH ] ="peripheral" , [IDH_PTYPE_PSD ] ="psd" ,
@@ -94,17 +95,17 @@ static const char * const product_type_ufp[8] = { };static const char *const product_type_dfp[8 ] = { - [IDH_PTYPE_DFP_UNDEF ] ="undefined" , + [IDH_PTYPE_NOT_DFP ] ="not_dfp" , [IDH_PTYPE_DFP_HUB ] ="hub" , [IDH_PTYPE_DFP_HOST ] ="host" , [IDH_PTYPE_DFP_PB ] ="power_brick" , - [IDH_PTYPE_DFP_AMC ] ="amc" , };static const char *const product_type_cable[8 ] = { - [IDH_PTYPE_UNDEF ] ="undefined" , + [IDH_PTYPE_NOT_CABLE ] ="not_cable" , [IDH_PTYPE_PCABLE ] ="passive" , [IDH_PTYPE_ACABLE ] ="active" , + [IDH_PTYPE_VPD ] ="vpd" , };static struct usb_pd_identity *get_pd_identity (struct device *dev)
@@ -1788,6 +1789,18 @@ int typec_find_port_data_role(const char *name) }EXPORT_SYMBOL_GPL (typec_find_port_data_role); +void typec_set_common_svdm_version (struct typec_port *port,enum usb_pd_svdm_ver ver) +{ + port->common_svdm_ver = ver; +} +EXPORT_SYMBOL_GPL (typec_set_common_svdm_version); + +enum usb_pd_svdm_ver typec_get_common_svdm_version (struct typec_port *port) +{ +return port->common_svdm_ver; +} +EXPORT_SYMBOL_GPL (typec_get_common_svdm_version); +/* ------------------------------------------ */ /* API for Multiplexer/DeMultiplexer Switches */
drivers/usb/typec/tcpm/tcpm.c +40 -9
151 lines not on this page · raw message
drivers/usb/typec/ucsi/displayport.c +7 -3
@@ -14,6 +14,7 @@#define UCSI_CMD_SET_NEW_CAM (_con_num_, _enter_, _cam_, _am_) \ (UCSI_SET_NEW_CAM | ((_con_num_) << 16) | ((_enter_) << 23) | \ ((_cam_) << 24) | ((u64)(_am_) << 32)) +#define common_svdm_ver (dp) (typec_get_common_svdm_version((dp)->con->port))struct ucsi_dp {struct typec_displayport_data data;
@@ -83,7 +84,7 @@ static int ucsi_displayport_enter(struct typec_altmode *alt, u32 *vdo)* mode, and letting the alt mode driver continue. */ - dp->header =VDO (USB_TYPEC_DP_SID ,1 ,CMD_ENTER_MODE ); + dp->header =VDO (USB_TYPEC_DP_SID ,1 ,common_svdm_ver (dp),CMD_ENTER_MODE ); dp->header |=VDO_OPOS (USB_TYPEC_DP_MODE ); dp->header |=VDO_CMDT (CMDT_RSP_ACK );
@@ -120,7 +121,7 @@ static int ucsi_displayport_exit(struct typec_altmode *alt)if (ret <0 ) goto out_unlock; - dp->header =VDO (USB_TYPEC_DP_SID ,1 ,CMD_EXIT_MODE ); + dp->header =VDO (USB_TYPEC_DP_SID ,1 ,common_svdm_ver (dp),CMD_EXIT_MODE ); dp->header |=VDO_OPOS (USB_TYPEC_DP_MODE ); dp->header |=VDO_CMDT (CMDT_RSP_ACK );
@@ -200,7 +201,10 @@ static int ucsi_displayport_vdm(struct typec_altmode *alt,switch (cmd_type) {case CMDT_INIT : - dp->header =VDO (USB_TYPEC_DP_SID ,1 , cmd); +if (PD_VDO_SVDM_VER (header) <common_svdm_ver (dp)) +typec_set_common_svdm_version (dp->con->port,PD_VDO_SVDM_VER (header)); + + dp->header =VDO (USB_TYPEC_DP_SID ,1 ,common_svdm_ver (dp), cmd); dp->header |=VDO_OPOS (USB_TYPEC_DP_MODE );switch (cmd) {
drivers/usb/typec/ucsi/ucsi.c +2 -0
@@ -764,6 +764,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)if (con->status.change &UCSI_CONSTAT_CONNECT_CHANGE ) {typec_set_pwr_role (con->port, role); +typec_set_common_svdm_version (con->port, con->typec_cap.svdm_version);switch (UCSI_CONSTAT_PARTNER_TYPE (con->status.flags)) {case UCSI_CONSTAT_PARTNER_TYPE_UFP :
@@ -1052,6 +1053,7 @@ static int ucsi_register_port(struct ucsi *ucsi, int index) cap->revision = ucsi->cap.typec_version; cap->pd_revision = ucsi->cap.pd_version; + cap->svdm_version =SVDM_VER_2_0 ; cap->prefer_role =TYPEC_NO_PREFERRED_ROLE ;if (con->cap.op_mode &UCSI_CONCAP_OPMODE_AUDIO_ACCESSORY )
include/linux/usb/pd_vdo.h +243 -72
423 lines not on this page · raw message
include/linux/usb/typec.h +10 -0
@@ -206,12 +206,19 @@ struct typec_operations { enum typec_port_type type); }; +enum usb_pd_svdm_ver { +SVDM_VER_1_0 =0 , +SVDM_VER_2_0 =1 , +SVDM_VER_MAX =SVDM_VER_2_0 , +}; +/* * struct typec_capability - USB Type-C Port Capabilities * @type: Supported power role of the port * @data: Supported data role of the port * @revision: USB Type-C Specification release. Binary coded decimal * @pd_revision: USB Power Delivery Specification revision if supported +* @svdm_version: USB PD Structured VDM version if supported * @prefer_role: Initial role preference (DRP ports). * @accessory: Supported Accessory Modes * @fwnode: Optional fwnode of the port
@@ -225,6 +232,7 @@ struct typec_capability {enum typec_port_data data;u16 revision;/* 0120H = "1.2" */ u16 pd_revision;/* 0300H = "3.0" */ +enum usb_pd_svdm_ver svdm_version;int prefer_role;enum typec_accessory accessory[TYPEC_MAX_ACCESSORY ]; unsigned int orientation_aware:1;
@@ -275,4 +283,6 @@ int typec_find_orientation(const char *name);int typec_find_port_power_role (const char *name);int typec_find_power_role (const char *name);int typec_find_port_data_role (const char *name); +void typec_set_common_svdm_version (struct typec_port *port,enum usb_pd_svdm_ver ); +enum usb_pd_svdm_ver typec_get_common_svdm_version (struct typec_port *port);#endif /* __LINUX_USB_TYPEC_H */
Signature · 1 line
2.30.0.365.g02bc693789-goog
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH v2 1/3] usb: typec: Determine common SVDM Versions
Quoted 10 lines · Guenter Roeck
Quoted 7 lines · Kyle Tso
Changes since v1:
- removed the "local" variables (svdm_version) intcpm.cand (altmodes/ucsi)/displayport.c
- added a member "svdm_version" in structtypec_capabilitiesindicating the default SVDM version of the port
- added a member "common_svdm_ver" in structtypec_portindicating the common SVDM version between the port and the partner
Quoted 3 lines
I personally find the "common" in the variable and function names unnecessary. I would prefer using something like
svdm_versioninstead ofcommon_svdm_ver.
The reason for the common_ prefix is just for the readability. That's totally fine with me to remove the prefix. Will fix this in the next version.
Quoted 7 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -1470,11 +1470,13 @@ static void tcpm_register_partner_altmodes(struct tcpm_port *port) }
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c static void tcpm_register_partner_altmodes(struct tcpm_port *port) · line 1473
Quoted 2 lines
drivers/usb/typec/tcpm/tcpm.c +1
-0#define supports_modal (port) PD_IDH_MODAL_SUPP((port)->partner_ident.id_header) +#define common_svdm_ver (typec) (typec_get_common_svdm_version(typec))I think that is unnecessary and confusing. We now have
typec_get_common_svdm_version()as well ascommon_svdm_ver()andCOMMON_SVDM_VER()macros. I would suggest to just use the function name (and maybe drop the 'common_' prefix from it).
will fix this in the next version.
Quoted 6 lines
Quoted 6 lines
drivers/usb/typec/ucsi/ucsi.c +0
-0@@ -764,6 +764,7 @@ static void ucsi_handle_connector_change(struct work_struct *work)
Quoted 9 lines
drivers/usb/typec/ucsi/ucsi.c static void ucsi_handle_connector_change(struct work_struct *work) · line 768
Quoted 4 lines
drivers/usb/typec/ucsi/ucsi.c +1
-0if (con->status.change &UCSI_CONSTAT_CONNECT_CHANGE ) {typec_set_pwr_role (con->port, role); +typec_set_common_svdm_version (con->port, con->typec_cap.svdm_version);I am a bit concerned that
svdm_versionis added totypec_capabilitiesbut not consistently used by all drivers registering with typec. I am not sure I understand if and how the value intypec_capabilitiesis used by the typec core.
I am not sure about it as well :p
From my POV, that is just the same nature as the "pd_revision" is in typec_capabilities which means the capabilities the port has regardless of the port partners.
The port needs to reset the operating mode to it's designed SVDM version upon detach. I think typec_capabilities is a good place to store this information.
What do you think?
BTW, the reset value of the variable "negotiated_rev" in tcpm/tcpm.c looks weird to me.
It is reset to "PD_MAX_REV" in SNK_STARTUP and SRC_STARTUP. However, the tcpm.c might not always support the max revision of PD. IMO, the pd_revision in typec_capabilities is a better choice compared to PD_MAX_REV.
Quoted 32 lines
Quoted 32 lines
include/linux/usb/typec.h +8
-0@@ -206,12 +206,19 @@ struct typec_operations { enum typec_port_type type); }; +enum usb_pd_svdm_ver { +SVDM_VER_1_0 =0 , +SVDM_VER_2_0 =1 , +SVDM_VER_MAX =SVDM_VER_2_0 , +}; +/* * struct typec_capability - USB Type-C Port Capabilities * @type: Supported power role of the port * @data: Supported data role of the port * @revision: USB Type-C Specification release. Binary coded decimal * @pd_revision: USB Power Delivery Specification revision if supported +* @svdm_version: USB PD Structured VDM version if supported * @prefer_role: Initial role preference (DRP ports). * @accessory: Supported Accessory Modes * @fwnode: Optional fwnode of the port @@ -225,6 +232,7 @@ struct typec_capability {enum typec_port_data data;u16 revision;/* 0120H = "1.2" */ u16 pd_revision;/* 0300H = "3.0" */ +enum usb_pd_svdm_ver svdm_version;int prefer_role;enum typec_accessory accessory[TYPEC_MAX_ACCESSORY ]; unsigned int orientation_aware:1;
Quoted 9 lines
include/linux/usb/typec.h int typec_find_orientation(const char *name); · line 288
Quoted 8 lines
include/linux/usb/typec.h +2
-0@@ -275,4 +283,6 @@ int typec_find_orientation(const char *name);int typec_find_port_power_role (const char *name);int typec_find_power_role (const char *name);int typec_find_port_data_role (const char *name); +void typec_set_common_svdm_version (struct typec_port *port,enum usb_pd_svdm_ver ); +enum usb_pd_svdm_ver typec_get_common_svdm_version (struct typec_port *port);#endif /* __LINUX_USB_TYPEC_H */
Thanks,
Kyle
PATCH v2 2/3 dt-bindings: connector: Add SVDM VDO properties
In reply to Kyle TsoAdd bindings of VDO properties of USB PD SVDM so that they can be used in device tree.
---
Changes since v1:
dt-bindings: connector: Add SVDM VDO properties
- updated the dt-bindings documentations
- added more definitions of Product Type VDOs
.../bindings/connector/usb-connector.yaml | 11 + include/dt-bindings/usb/pd.h | 311 +++++++++++++++++- 2 files changed, 321 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/connector/usb-connector.yaml +11 -0
@@ -137,6 +137,17 @@ properties: maxItems: 7 $ref: /schemas/types.yaml#/definitions/uint32-array + sink-vdos: + description: An array of u32 with each entry (VDM Objects) providing additional information + corresponding to the product, the detailed bit definitions and the order of each VDO can be + found in "USB Power Delivery Specification Revision 3.0, Version 2.0 + ECNs 2020-12-10" + chapter 6.4.4.3.1 Discover Identity. User can specify the VDO array via + VDO_IDH/_CERT/_PRODUCT/_UFP/_DFP/_PCABLE/_ACABLE(1/2)/_VPD() defined in + dt-bindings/usb/pd.h. + minItems: 3 + maxItems: 6 + $ref: /schemas/types.yaml#/definitions/uint32-array + op-sink-microwatt: description: Sink required operating power in microwatt, if source can't offer the power, Capability Mismatch is set. Required for power sink and
include/dt-bindings/usb/pd.h +310 -1
314 lines not on this page · raw message
Signature · 1 line
2.30.0.365.g02bc693789-goog
PATCH v2 3/3 usb: typec: tcpm: Get Sink VDO from fwnode
In reply to Kyle TsoCommit a079973f462a ("usb: typec: tcpm: Remove tcpc_config configuration mechanism") removed the tcpc_config which includes the Sink VDO and it is not yet added back with fwnode. Add it now.
---
Changes since v1:
- updated the commit message
drivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +12 -0
@@ -5677,6 +5677,18 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, port->new_source_frs_current = frs_current; } + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" ,NULL ,0 ); +if (ret <=0 && ret != -EINVAL ) { +return -EINVAL ; + }else if (ret >0 ) { + port->nr_snk_vdo =min (ret,VDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" , + port->snk_vdo, + port->nr_snk_vdo); +if (ret <0 ) +return -EINVAL ; + } +return 0 ; }
Signature · 1 line
2.30.0.365.g02bc693789-goog
Re: [PATCH v2 3/3] usb: typec: tcpm: Get Sink VDO from fwnode
Quoted 17 lines · Kyle Tso
Commit
a079973f462a("usb: typec: tcpm: Removetcpc_configconfiguration mechanism") removed thetcpc_configwhich includes the Sink VDO and it is not yet added back with fwnode. Add it now.Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- updated the commit messagedrivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/usb/typec/tcpm/tcpm.c +0
-0
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5680
Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c +1
-0@@ -5677,6 +5677,18 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, port->new_source_frs_current = frs_current; } + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" ,NULL ,0 );
fwnode_property_count_u32(), maybe ?
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5682
Quoted 2 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+if (ret <=0 && ret != -EINVAL ) { +return -EINVAL ;
Why return any error except -EINVAL (including return values of 0) as -EINVAL, and -EINVAL as no error ?
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5689
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ }else if (ret >0 ) { + port->nr_snk_vdo =min (ret,VDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" , + port->snk_vdo, + port->nr_snk_vdo); +if (ret <0 ) +return -EINVAL ;
static analyzer code used to complain about overriding error codes. Not sure if that is still true. Either case, why not return the original error ?
Thanks,
Guenter
Quoted 6 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+ } +return 0 ; }
Re: [PATCH v2 3/3] usb: typec: tcpm: Get Sink VDO from fwnode
Quoted 22 lines · Guenter Roeck
Quoted 20 lines · Kyle Tso
Commit
a079973f462a("usb: typec: tcpm: Removetcpc_configconfiguration mechanism") removed thetcpc_configwhich includes the Sink VDO and it is not yet added back with fwnode. Add it now.Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- updated the commit messagedrivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -5677,6 +5677,18 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, port->new_source_frs_current = frs_current; }
Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5680
Quoted 1 line
drivers/usb/typec/tcpm/tcpm.c +1
-0+ ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" ,NULL ,0 );
fwnode_property_count_u32(), maybe ?
That's the same and looks like fwnode_property_count_u32 is better to read. I will revise it in the next version.
Quoted 6 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5682
Quoted 2 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+if (ret <=0 && ret != -EINVAL ) { +return -EINVAL ;Why return any error except
-EINVAL(including return values of 0) as-EINVAL, and-EINVALas no error ?
sink-vdos is not a mandatory property which means -EINVAL is acceptable.
If the return < 0 and the value is not -EINVAL, it means that the error is other than "not present" in the device tree. If the return == 0, it means that the sink-vdos is present in the device tree but no value inside it.
Both of the above situations are not acceptable.
Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5689
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ }else if (ret >0 ) { + port->nr_snk_vdo =min (ret,VDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" , + port->snk_vdo, + port->nr_snk_vdo); +if (ret <0 ) +return -EINVAL ;
Quoted 4 lines
static analyzer code used to complain about overriding error codes. Not sure if that is still true. Either case, why not return the original error ?
Returning the original error codes is good. I just followed the return value of other error handling in this function.
will revise it in the next version.
Thanks,
Kyle
Quoted 10 lines
Thanks,
GuenterQuoted 6 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+ } +return 0 ; }
Re: [PATCH v2 3/3] usb: typec: tcpm: Get Sink VDO from fwnode
Quoted 36 lines · Kyle Tso
Quoted 22 lines · Guenter Roeck
Quoted 20 lines · Kyle Tso
Commit
a079973f462a("usb: typec: tcpm: Removetcpc_configconfiguration mechanism") removed thetcpc_configwhich includes the Sink VDO and it is not yet added back with fwnode. Add it now.Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- updated the commit messagedrivers/usb/typec/tcpm/tcpm.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/usb/typec/tcpm/tcpm.c +0
-0@@ -5677,6 +5677,18 @@ static int tcpm_fw_get_caps(struct tcpm_port *port, port->new_source_frs_current = frs_current; }Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5680
Quoted 1 line
drivers/usb/typec/tcpm/tcpm.c +1
-0+ ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" ,NULL ,0 );
fwnode_property_count_u32(), maybe ?That's the same and looks like
fwnode_property_count_u32is better to read. I will revise it in the next version.Quoted 6 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_fw_get_caps(struct tcpm_port *port, · line 5682
Quoted 2 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+if (ret <=0 && ret != -EINVAL ) { +return -EINVAL ;Why return any error except
-EINVAL(including return values of 0) as-EINVAL, and-EINVALas no error ?
Quoted 6 lines
sink-vdos is not a mandatory property which means
-EINVALis acceptable.If the return < 0 and the value is not
-EINVAL, it means that the error is other than "not present" in the device tree. If the return == 0, it means that the sink-vdos is present in the device tree but no value inside it.
I think that should return -ENODATA. Not sure if/when it would actually return 0.
Quoted 2 lines
Both of the above situations are not acceptable.
Personally I would prefer that a bit more explicit in the code, ie handle errors first and drop the else statement below. But maybe that is just me.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/usb/typec/tcpm/tcpm.c +7
-0+ }else if (ret >0 ) { + port->nr_snk_vdo =min (ret,VDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"sink-vdos" , + port->snk_vdo, + port->nr_snk_vdo); +if (ret <0 ) +return -EINVAL ;
Quoted 8 lines
Quoted 4 lines
static analyzer code used to complain about overriding error codes. Not sure if that is still true. Either case, why not return the original error ?
Returning the original error codes is good. I just followed the return value of other error handling in this function.
will revise it in the next version.
Never mind, with the rest of the code being similar I guess that either static analyzers gave up complaining or they already have a field day anyway.
Thanks,
Guenter
Quoted 15 lines
Thanks,
KyleQuoted 10 lines
Thanks,
GuenterQuoted 6 lines
drivers/usb/typec/tcpm/tcpm.c +2
-0+ } +return 0 ; }