TCPM non-PD mode
v4 cover TCPM non-PD mode
cover-letter is the same as that in v3
The reason for this patch is to let the device/system policy decide whether PD is going to be supported using devicetree properties.
A new dt property "pd-unsupported" is introduced and TCPM uses this property as a flag to decide whether PD is supported. If the flag is false (the dt property is not present), the RX functionality of the low-level driver will not be enabled. The power negotiation related states will be skipped as well. If the flag is true, everything is a what it was before.
If "pd-unsupported" is present, and the port is SRC or DRP, another existing dt property "typec-power-opmode" needs to be specified to indicate which Rp value should be used when the port is SRC.
changes since v3:
usb: typec: tcpm: Support non-PD mode
- commit msg updated
- removed unnecessary empty lines
- re-factored the code of reading device tree properties and the error handling
- removed unnecessay variable initialization
- modified the comments
Kyle Tso (2):
dt-bindings: connector: Add pd-supported property
usb: typec: tcpm: Support non-PD mode
.../bindings/connector/usb-connector.yaml | 4 + drivers/usb/typec/tcpm/tcpm.c | 87 +++++++++++++++---- 2 files changed, 72 insertions(+), 19 deletions(-)
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
PATCH v4 1/2 dt-bindings: connector: Add pd-supported property
Set "pd-unsupported" property if the Type-C connector has no power delivery support.
--- .../devicetree/bindings/connector/usb-connector.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +4 -0
@@ -111,6 +111,10 @@ properties: - 1.5A - 3.0A + pd-unsupported: + description: Set this property if the Type-C connector has no power delivery support. + type: boolean + # The following are optional properties for "usb-c-connector" with power # delivery support. source-pdos:
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Re: [PATCH v4 1/2] dt-bindings: connector: Add pd-supported property
Quoted 3 lines · Kyle Tso
Set "pd-unsupported" property if the Type-C connector has no power delivery support.
subject is still wrong (it says pd-supported).
Quoted 21 lines
Signed-off-by Kyle Tso <[email protected]>--- .../devicetree/bindings/connector/usb-connector.yaml | 4 ++++ 1 file changed, 4 insertions(+)Documentation/devicetree/bindings/connector/usb-connector.yaml +4
-0@@ -111,6 +111,10 @@ properties: - 1.5A - 3.0A + pd-unsupported: + description: Set this property if the Type-C connector has no power delivery support. + type: boolean + # The following are optional properties for "usb-c-connector" with power # delivery support. source-pdos:
Rob Herring
maintainerRe: [PATCH v4 1/2] dt-bindings: connector: Add pd-supported property
Quoted 6 lines · Guenter Roeck
Quoted 3 lines · Kyle Tso
Set "pd-unsupported" property if the Type-C connector has no power delivery support.
subject is still wrong (it says pd-supported).
And the commit msg too.
Quoted 24 lines
Quoted 22 lines
Signed-off-by Kyle Tso <[email protected]>--- .../devicetree/bindings/connector/usb-connector.yaml | 4 ++++ 1 file changed, 4 insertions(+)Documentation/devicetree/bindings/connector/usb-connector.yaml +4
-0@@ -111,6 +111,10 @@ properties: - 1.5A - 3.0A + pd-unsupported: + description: Set this property if the Type-C connector has no power delivery support. + type: boolean + # The following are optional properties for "usb-c-connector" with power # delivery support. source-pdos:
Rob Herring
maintainerRe: [PATCH v4 1/2] dt-bindings: connector: Add pd-supported property
Quoted 10 lines · Rob Herring
Quoted 6 lines · Guenter Roeck
Quoted 3 lines · Kyle Tso
Set "pd-unsupported" property if the Type-C connector has no power delivery support.
subject is still wrong (it says pd-supported).
And the commit msg too.
Err, sorry, it's the cover letter that's wrong.
Rob
Rob Herring
maintainerRe: [PATCH v4 1/2] dt-bindings: connector: Add pd-supported property
In reply to Kyle TsoQuoted 13 lines · Kyle Tso
Set "pd-unsupported" property if the Type-C connector has no power delivery support.
Signed-off-by Kyle Tso <[email protected]>--- .../devicetree/bindings/connector/usb-connector.yaml | 4 ++++ 1 file changed, 4 insertions(+)Documentation/devicetree/bindings/connector/usb-connector.yaml +0
-0
Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 114
Quoted 4 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +1
-0@@ -111,6 +111,10 @@ properties: - 1.5A - 3.0A + pd-unsupported:
'disable-pd' or 'pd-disable' would be a bit more consistent with other flags like to enable/disable things.
Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3
-0+ description: Set this property if the Type-C connector has no power delivery support. + type: boolean + # The following are optional properties for "usb-c-connector" with power # delivery support. source-pdos:Signature · 1 line
2.32.0.554.ge1b32706d8-goog
PATCH v4 2/2 usb: typec: tcpm: Support non-PD mode
In reply to Kyle TsoEven if the Type-C controller supports PD, it is doable to disable PD capabilities with the current state machine in TCPM. Without enabling RX in low-level drivers and with skipping the power negotiation, the port is eligible to be a non-PD Type-C port. Use new flags whose values are populated from the device tree to decide the port PD capability. Adding "pd-unsupported" property in device tree indicates that the port does not support PD. If PD is not supported, the device tree property "typec-power-opmode" shall be added to specify the advertised Rp value if the port supports SRC role.
---
changes since v3:
- commit msg updated
- removed unnecessary empty lines
- re-factored the code of reading device tree properties and the error handling
- removed unnecessay variable initialization
- modified the comments
drivers/usb/typec/tcpm/tcpm.c | 87 +++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 19 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +68 -19
@@ -316,6 +316,7 @@ struct tcpm_port {struct typec_partner *partner;enum typec_cc_status cc_req; +enum typec_cc_status src_rp;/* work only if pd_supported == false */ enum typec_cc_status cc1;enum typec_cc_status cc2;
@@ -323,6 +324,7 @@ struct tcpm_port {bool attached;bool connected; +bool pd_supported;enum typec_port_type port_type;/*
@@ -815,6 +817,9 @@ static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port)int nr_pdo = port->nr_src_pdo;int i; +if (!port->pd_supported) +return port->src_rp; +/* * Search for first entry with matching voltage. * It should report the maximum supported current.
@@ -3568,9 +3573,11 @@ static int tcpm_src_attach(struct tcpm_port *port)if (ret <0 )return ret; - ret = port->tcpc->set_pd_rx (port->tcpc, true); -if (ret <0 ) - goto out_disable_mux; +if (port->pd_supported) { + ret = port->tcpc->set_pd_rx (port->tcpc, true); +if (ret <0 ) + goto out_disable_mux; + }/* * USB Type-C specification, version 1.2,
@@ -3600,7 +3607,8 @@ static int tcpm_src_attach(struct tcpm_port *port) out_disable_vconn:tcpm_set_vconn (port, false); out_disable_pd: - port->tcpc->set_pd_rx (port->tcpc, false); +if (port->pd_supported) + port->tcpc->set_pd_rx (port->tcpc, false); out_disable_mux:tcpm_mux_set (port,TYPEC_STATE_SAFE ,USB_ROLE_NONE ,TYPEC_ORIENTATION_NONE );
@@ -3804,6 +3812,20 @@ static enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc) } } +static enum typec_cc_status tcpm_pwr_opmode_to_rp (enum typec_pwr_opmode opmode) +{ +switch (opmode) { +case TYPEC_PWR_MODE_USB : +return TYPEC_CC_RP_DEF ; +case TYPEC_PWR_MODE_1_5A : +return TYPEC_CC_RP_1_5 ; +case TYPEC_PWR_MODE_3_0A : +case TYPEC_PWR_MODE_PD : +default : +return TYPEC_CC_RP_3_0 ; + } +} +static void run_state_machine (struct tcpm_port *port) {int ret;
@@ -3914,6 +3936,10 @@ static void run_state_machine(struct tcpm_port *port)if (port->ams ==POWER_ROLE_SWAP || port->ams ==FAST_ROLE_SWAP )tcpm_ams_finish (port); +if (!port->pd_supported) { +tcpm_set_state (port,SRC_READY ,0 ); +break ; + } port->upcoming_state =SRC_SEND_CAPABILITIES ;tcpm_ams_start (port,POWER_NEGOTIATION );break ;
@@ -4161,7 +4187,10 @@ static void run_state_machine(struct tcpm_port *port) current_lim =PD_P_SNK_STDBY_MW /5 ;tcpm_set_current_limit (port, current_lim,5000 );tcpm_set_charge (port, true); -tcpm_set_state (port,SNK_WAIT_CAPABILITIES ,0 ); +if (!port->pd_supported) +tcpm_set_state (port,SNK_READY ,0 ); +else +tcpm_set_state (port,SNK_WAIT_CAPABILITIES ,0 );break ; }/*
@@ -4389,7 +4418,8 @@ static void run_state_machine(struct tcpm_port *port)tcpm_set_vbus (port, true);if (port->ams ==HARD_RESET )tcpm_ams_finish (port); - port->tcpc->set_pd_rx (port->tcpc, true); +if (port->pd_supported) + port->tcpc->set_pd_rx (port->tcpc, true);tcpm_set_attached_state (port, true);tcpm_set_state (port,SRC_UNATTACHED ,PD_T_PS_SOURCE_ON );break ;
@@ -5898,6 +5928,7 @@ EXPORT_SYMBOL_GPL(tcpm_tcpc_reset);static int tcpm_fw_get_caps (struct tcpm_port *port,struct fwnode_handle *fwnode) { +const char *opmode_str;const char *cap_str;int ret;u32 mw, frs_current;
@@ -5932,22 +5963,37 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return ret; port->typec_caps.type = ret; port->port_type = port->typec_caps.type; + port->pd_supported = !fwnode_property_read_bool (fwnode,"pd-unsupported" ); port->slow_charger_loop =fwnode_property_read_bool (fwnode,"slow-charger-loop" );if (port->port_type ==TYPEC_PORT_SNK ) goto sink; -/* Get source pdos */ - ret =fwnode_property_count_u32 (fwnode,"source-pdos" ); -if (ret <=0 ) -return -EINVAL ; +/* Get Source PDOs for the PD port or Source Rp value for the non-PD port */ +if (port->pd_supported) { + ret =fwnode_property_count_u32 (fwnode,"source-pdos" ); +if (ret ==0 ) +return -EINVAL ; +else if (ret <0 ) +return ret; - port->nr_src_pdo =min (ret,PDO_MAX_OBJECTS ); - ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , - port->src_pdo, port->nr_src_pdo); -if ((ret <0 ) ||tcpm_validate_caps (port, port->src_pdo, - port->nr_src_pdo)) -return -EINVAL ; + port->nr_src_pdo =min (ret,PDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , + port->src_pdo, port->nr_src_pdo); +if (ret) +return ret; + ret =tcpm_validate_caps (port, port->src_pdo, port->nr_src_pdo); +if (ret) +return ret; + }else { + ret =fwnode_property_read_string (fwnode,"typec-power-opmode" , &opmode_str); +if (ret) +return ret; + ret =typec_find_pwr_opmode (opmode_str); +if (ret <0 ) +return ret; + port->src_rp =tcpm_pwr_opmode_to_rp (ret); + }if (port->port_type ==TYPEC_PORT_SRC )return 0 ;
@@ -5961,6 +6007,11 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,if (port->typec_caps.prefer_role <0 )return -EINVAL ; sink: + port->self_powered =fwnode_property_read_bool (fwnode,"self-powered" ); + +if (!port->pd_supported) +return 0 ; +/* Get sink pdos */ ret =fwnode_property_count_u32 (fwnode,"sink-pdos" );if (ret <=0 )
@@ -5977,9 +6028,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return -EINVAL ; port->operating_snk_mw = mw /1000 ; - port->self_powered =fwnode_property_read_bool (fwnode,"self-powered" ); - -/* FRS can only be supported byb DRP ports */ +/* FRS can only be supported by DRP ports */ if (port->port_type ==TYPEC_PORT_DRP ) { ret =fwnode_property_read_u32 (fwnode,"new-source-frs-typec-current" , &frs_current);
Signature · 1 line
2.32.0.554.ge1b32706d8-goog
Re: [PATCH v4 2/2] usb: typec: tcpm: Support non-PD mode
Quoted 11 lines · Kyle Tso
Even if the Type-C controller supports PD, it is doable to disable PD capabilities with the current state machine in TCPM. Without enabling RX in low-level drivers and with skipping the power negotiation, the port is eligible to be a non-PD Type-C port. Use new flags whose values are populated from the device tree to decide the port PD capability. Adding "pd-unsupported" property in device tree indicates that the port does not support PD. If PD is not supported, the device tree property "typec-power-opmode" shall be added to specify the advertised Rp value if the port supports SRC role.
Signed-off-by Kyle Tso <[email protected]>
Quoted 201 lines
---
changes since v3:
- commit msg updated
- removed unnecessary empty lines
- re-factored the code of reading device tree properties and the error handling
- removed unnecessay variable initialization
- modified the commentsdrivers/usb/typec/tcpm/tcpm.c | 87 +++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 19 deletions(-)drivers/usb/typec/tcpm/tcpm.c +68
-19@@ -316,6 +316,7 @@ struct tcpm_port {struct typec_partner *partner;enum typec_cc_status cc_req; +enum typec_cc_status src_rp;/* work only if pd_supported == false */ enum typec_cc_status cc1;enum typec_cc_status cc2;@@ -323,6 +324,7 @@ struct tcpm_port {bool attached;bool connected; +bool pd_supported;enum typec_port_type port_type;/* @@ -815,6 +817,9 @@ static enum typec_cc_status tcpm_rp_cc(struct tcpm_port *port)int nr_pdo = port->nr_src_pdo;int i; +if (!port->pd_supported) +return port->src_rp; +/* * Search for first entry with matching voltage. * It should report the maximum supported current. @@ -3568,9 +3573,11 @@ static int tcpm_src_attach(struct tcpm_port *port)if (ret <0 )return ret; - ret = port->tcpc->set_pd_rx (port->tcpc, true); -if (ret <0 ) - goto out_disable_mux; +if (port->pd_supported) { + ret = port->tcpc->set_pd_rx (port->tcpc, true); +if (ret <0 ) + goto out_disable_mux; + }/* * USB Type-C specification, version 1.2, @@ -3600,7 +3607,8 @@ static int tcpm_src_attach(struct tcpm_port *port) out_disable_vconn:tcpm_set_vconn (port, false); out_disable_pd: - port->tcpc->set_pd_rx (port->tcpc, false); +if (port->pd_supported) + port->tcpc->set_pd_rx (port->tcpc, false); out_disable_mux:tcpm_mux_set (port,TYPEC_STATE_SAFE ,USB_ROLE_NONE ,TYPEC_ORIENTATION_NONE );@@ -3804,6 +3812,20 @@ static enum typec_pwr_opmode tcpm_get_pwr_opmode(enum typec_cc_status cc) } } +static enum typec_cc_status tcpm_pwr_opmode_to_rp (enum typec_pwr_opmode opmode) +{ +switch (opmode) { +case TYPEC_PWR_MODE_USB : +return TYPEC_CC_RP_DEF ; +case TYPEC_PWR_MODE_1_5A : +return TYPEC_CC_RP_1_5 ; +case TYPEC_PWR_MODE_3_0A : +case TYPEC_PWR_MODE_PD : +default : +return TYPEC_CC_RP_3_0 ; + } +} +static void run_state_machine (struct tcpm_port *port) {int ret;@@ -3914,6 +3936,10 @@ static void run_state_machine(struct tcpm_port *port)if (port->ams ==POWER_ROLE_SWAP || port->ams ==FAST_ROLE_SWAP )tcpm_ams_finish (port); +if (!port->pd_supported) { +tcpm_set_state (port,SRC_READY ,0 ); +break ; + } port->upcoming_state =SRC_SEND_CAPABILITIES ;tcpm_ams_start (port,POWER_NEGOTIATION );break ;@@ -4161,7 +4187,10 @@ static void run_state_machine(struct tcpm_port *port) current_lim =PD_P_SNK_STDBY_MW /5 ;tcpm_set_current_limit (port, current_lim,5000 );tcpm_set_charge (port, true); -tcpm_set_state (port,SNK_WAIT_CAPABILITIES ,0 ); +if (!port->pd_supported) +tcpm_set_state (port,SNK_READY ,0 ); +else +tcpm_set_state (port,SNK_WAIT_CAPABILITIES ,0 );break ; }/* @@ -4389,7 +4418,8 @@ static void run_state_machine(struct tcpm_port *port)tcpm_set_vbus (port, true);if (port->ams ==HARD_RESET )tcpm_ams_finish (port); - port->tcpc->set_pd_rx (port->tcpc, true); +if (port->pd_supported) + port->tcpc->set_pd_rx (port->tcpc, true);tcpm_set_attached_state (port, true);tcpm_set_state (port,SRC_UNATTACHED ,PD_T_PS_SOURCE_ON );break ;@@ -5898,6 +5928,7 @@ EXPORT_SYMBOL_GPL(tcpm_tcpc_reset);static int tcpm_fw_get_caps (struct tcpm_port *port,struct fwnode_handle *fwnode) { +const char *opmode_str;const char *cap_str;int ret;u32 mw, frs_current;@@ -5932,22 +5963,37 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return ret; port->typec_caps.type = ret; port->port_type = port->typec_caps.type; + port->pd_supported = !fwnode_property_read_bool (fwnode,"pd-unsupported" ); port->slow_charger_loop =fwnode_property_read_bool (fwnode,"slow-charger-loop" );if (port->port_type ==TYPEC_PORT_SNK ) goto sink; -/* Get source pdos */ - ret =fwnode_property_count_u32 (fwnode,"source-pdos" ); -if (ret <=0 ) -return -EINVAL ; +/* Get Source PDOs for the PD port or Source Rp value for the non-PD port */ +if (port->pd_supported) { + ret =fwnode_property_count_u32 (fwnode,"source-pdos" ); +if (ret ==0 ) +return -EINVAL ; +else if (ret <0 ) +return ret; - port->nr_src_pdo =min (ret,PDO_MAX_OBJECTS ); - ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , - port->src_pdo, port->nr_src_pdo); -if ((ret <0 ) ||tcpm_validate_caps (port, port->src_pdo, - port->nr_src_pdo)) -return -EINVAL ; + port->nr_src_pdo =min (ret,PDO_MAX_OBJECTS ); + ret =fwnode_property_read_u32_array (fwnode,"source-pdos" , + port->src_pdo, port->nr_src_pdo); +if (ret) +return ret; + ret =tcpm_validate_caps (port, port->src_pdo, port->nr_src_pdo); +if (ret) +return ret; + }else { + ret =fwnode_property_read_string (fwnode,"typec-power-opmode" , &opmode_str); +if (ret) +return ret; + ret =typec_find_pwr_opmode (opmode_str); +if (ret <0 ) +return ret; + port->src_rp =tcpm_pwr_opmode_to_rp (ret); + }if (port->port_type ==TYPEC_PORT_SRC )return 0 ;@@ -5961,6 +6007,11 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,if (port->typec_caps.prefer_role <0 )return -EINVAL ; sink: + port->self_powered =fwnode_property_read_bool (fwnode,"self-powered" ); + +if (!port->pd_supported) +return 0 ; +/* Get sink pdos */ ret =fwnode_property_count_u32 (fwnode,"sink-pdos" );if (ret <=0 )@@ -5977,9 +6028,7 @@ static int tcpm_fw_get_caps(struct tcpm_port *port,return -EINVAL ; port->operating_snk_mw = mw /1000 ; - port->self_powered =fwnode_property_read_bool (fwnode,"self-powered" ); - -/* FRS can only be supported byb DRP ports */ +/* FRS can only be supported by DRP ports */ if (port->port_type ==TYPEC_PORT_DRP ) { ret =fwnode_property_read_u32 (fwnode,"new-source-frs-typec-current" , &frs_current);