usb: typec: tcpm: Relax disconnect threshold during power negotiation
Subsystems (3)
PATCH v2 1/1 usb: typec: tcpm: Relax disconnect threshold during power negotiation
If the voltage is being decreased in power negotiation, the Source will set the power supply to operate at the new voltage level before sending PS_RDY. For non-PPS negotiation, relax the disconnect threshold on Sink after receiving Accept Message to ensure the relaxed setting is enabled before the voltage collapse. For PPS, relax the threshold before sending Request Message so that it will not race with Source which begins to adjust the voltage right after it sends Accept Message.
The real threshold will be set after Sink receives PS_RDY Message.
---
Changes since v1:
- move the timing of setting threshold up to "before sending Request" for PPS power negotiation so that it won't race with the Source.
- PPS: if it fails to send the Request, fallback to previous threshold
- PPS: if the Source doesn't respond Accept, fallback to previous threshold
- update the commit message for above changes
drivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +14 -0
@@ -2599,6 +2599,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, port->send_discover) port->vdm_sm_running = true; +/* Threshold was relaxed before sending Request. Restore it back. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); +tcpm_set_state (port,SNK_READY ,0 );break ;case DR_SWAP_SEND :
@@ -2646,6 +2651,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,switch (port->state) {case SNK_NEGOTIATE_CAPABILITIES : port->pps_data.active = false; +/* Voltage is going to be at new level. Relax the threshold here. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 );tcpm_set_state (port,SNK_TRANSITION_SINK ,0 );break ;case SNK_NEGOTIATE_PPS_CAPABILITIES :
@@ -3423,6 +3430,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port)if (ret <0 )return ret; +/* Relax the threshold as voltage will be adjusted right after Accept Message. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 ); +memset (&msg,0 ,sizeof (msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role,
@@ -4196,6 +4206,10 @@ static void run_state_machine(struct tcpm_port *port)case SNK_NEGOTIATE_PPS_CAPABILITIES : ret =tcpm_pd_send_pps_request (port);if (ret <0 ) { +/* Restore back to the original state */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); port->pps_status = ret;/* * If this was called due to updates to sink
Signature · 1 line
2.32.0.272.g935e593368-goog
Badhri Jagan Sridharan
maintainerQuoted 52 lines · Kyle Tso
If the voltage is being decreased in power negotiation, the Source will set the power supply to operate at the new voltage level before sending
PS_RDY. For non-PPS negotiation, relax the disconnect threshold on Sink after receiving Accept Message to ensure the relaxed setting is enabled before the voltage collapse. For PPS, relax the threshold before sending Request Message so that it will not race with Source which begins to adjust the voltage right after it sends Accept Message.The real threshold will be set after Sink receives
PS_RDYMessage.Fixes f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support")Cc Badhri Jagan Sridharan <[email protected]>Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- move the timing of setting threshold up to "before sending Request" for PPS power negotiation so that it won't race with the Source.
- PPS: if it fails to send the Request, fallback to previous threshold
- PPS: if the Source doesn't respond Accept, fallback to previous threshold
- update the commit message for above changesdrivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/usb/typec/tcpm/tcpm.c +7
-0@@ -2599,6 +2599,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, port->send_discover) port->vdm_sm_running = true; +/* Threshold was relaxed before sending Request. Restore it back. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); +tcpm_set_state (port,SNK_READY ,0 );break ;case DR_SWAP_SEND :@@ -2646,6 +2651,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,switch (port->state) {case SNK_NEGOTIATE_CAPABILITIES : port->pps_data.active = false; +/* Voltage is going to be at new level. Relax the threshold here. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 );tcpm_set_state (port,SNK_TRANSITION_SINK ,0 );break ;case SNK_NEGOTIATE_PPS_CAPABILITIES :
drivers/usb/typec/tcpm/tcpm.c static int tcpm_pd_send_pps_request(struct tcpm_port *port) · line 3433
Quoted 4 lines
drivers/usb/typec/tcpm/tcpm.c +1
-0@@ -3423,6 +3430,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port)if (ret <0 )return ret; +/* Relax the threshold as voltage will be adjusted right after Accept Message. */
This makes sense. Shouldn't we have the same approach for tcpm_pd_send_request as it's equally applicable for fixed RDO as well ?
Quoted 19 lines
drivers/usb/typec/tcpm/tcpm.c +6
-1+tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 ); +memset (&msg,0 ,sizeof (msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role,@@ -4196,6 +4206,10 @@ static void run_state_machine(struct tcpm_port *port)case SNK_NEGOTIATE_PPS_CAPABILITIES : ret =tcpm_pd_send_pps_request (port);if (ret <0 ) { +/* Restore back to the original state */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); port->pps_status = ret;/* * If this was called due to updates to sink -- 2.32.0.272.g935e593368-goog
Quoted 57 lines · Badhri Jagan Sridharan
Quoted 55 lines · Kyle Tso
If the voltage is being decreased in power negotiation, the Source will set the power supply to operate at the new voltage level before sending
PS_RDY. For non-PPS negotiation, relax the disconnect threshold on Sink after receiving Accept Message to ensure the relaxed setting is enabled before the voltage collapse. For PPS, relax the threshold before sending Request Message so that it will not race with Source which begins to adjust the voltage right after it sends Accept Message.The real threshold will be set after Sink receives
PS_RDYMessage.Fixes f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support")Cc Badhri Jagan Sridharan <[email protected]>Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- move the timing of setting threshold up to "before sending Request" for PPS power negotiation so that it won't race with the Source.
- PPS: if it fails to send the Request, fallback to previous threshold
- PPS: if the Source doesn't respond Accept, fallback to previous threshold
- update the commit message for above changesdrivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/usb/typec/tcpm/tcpm.c +7
-0@@ -2599,6 +2599,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, port->send_discover) port->vdm_sm_running = true; +/* Threshold was relaxed before sending Request. Restore it back. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); +tcpm_set_state (port,SNK_READY ,0 );break ;case DR_SWAP_SEND :@@ -2646,6 +2651,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,switch (port->state) {case SNK_NEGOTIATE_CAPABILITIES : port->pps_data.active = false; +/* Voltage is going to be at new level. Relax the threshold here. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 );tcpm_set_state (port,SNK_TRANSITION_SINK ,0 );break ;case SNK_NEGOTIATE_PPS_CAPABILITIES :@@ -3423,6 +3430,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port)if (ret <0 )return ret;
Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_pd_send_pps_request(struct tcpm_port *port) · line 3433
Quoted 1 line
drivers/usb/typec/tcpm/tcpm.c +1
-0+/* Relax the threshold as voltage will be adjusted right after Accept Message. */ This makes sense. Shouldn't we have the same approach for
tcpm_pd_send_requestas it's equally applicable for fixed RDO as well ?
I don't think we need to do that because for the power negotiation using Fixed RDO, the voltage adjustment from Source side takes place after the time sending Accept Message plus tSrcTransition (25~35ms). So setting the threshold after the Sink gets Accept Message should be enough.
thanks,
Kyle
Quoted 19 lines
Quoted 19 lines
drivers/usb/typec/tcpm/tcpm.c +6
-1+tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 ); +memset (&msg,0 ,sizeof (msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role,@@ -4196,6 +4206,10 @@ static void run_state_machine(struct tcpm_port *port)case SNK_NEGOTIATE_PPS_CAPABILITIES : ret =tcpm_pd_send_pps_request (port);if (ret <0 ) { +/* Restore back to the original state */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); port->pps_status = ret;/* * If this was called due to updates to sink -- 2.32.0.272.g935e593368-goog
Quoted 66 lines · Kyle Tso
Quoted 57 lines · Badhri Jagan Sridharan
Quoted 55 lines · Kyle Tso
If the voltage is being decreased in power negotiation, the Source will set the power supply to operate at the new voltage level before sending
PS_RDY. For non-PPS negotiation, relax the disconnect threshold on Sink after receiving Accept Message to ensure the relaxed setting is enabled before the voltage collapse. For PPS, relax the threshold before sending Request Message so that it will not race with Source which begins to adjust the voltage right after it sends Accept Message.The real threshold will be set after Sink receives
PS_RDYMessage.Fixes f321a02caebd ("usb: typec: tcpm: Implement enabling Auto Discharge disconnect support")Cc Badhri Jagan Sridharan <[email protected]>Signed-off-by Kyle Tso <[email protected]>---
Changes since v1:
- move the timing of setting threshold up to "before sending Request" for PPS power negotiation so that it won't race with the Source.
- PPS: if it fails to send the Request, fallback to previous threshold
- PPS: if the Source doesn't respond Accept, fallback to previous threshold
- update the commit message for above changesdrivers/usb/typec/tcpm/tcpm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)drivers/usb/typec/tcpm/tcpm.c +7
-0@@ -2599,6 +2599,11 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, port->send_discover) port->vdm_sm_running = true; +/* Threshold was relaxed before sending Request. Restore it back. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); +tcpm_set_state (port,SNK_READY ,0 );break ;case DR_SWAP_SEND :@@ -2646,6 +2651,8 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port,switch (port->state) {case SNK_NEGOTIATE_CAPABILITIES : port->pps_data.active = false; +/* Voltage is going to be at new level. Relax the threshold here. */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 );tcpm_set_state (port,SNK_TRANSITION_SINK ,0 );break ;case SNK_NEGOTIATE_PPS_CAPABILITIES :@@ -3423,6 +3430,9 @@ static int tcpm_pd_send_pps_request(struct tcpm_port *port)if (ret <0 )return ret;Quoted 5 lines
drivers/usb/typec/tcpm/tcpm.c static int tcpm_pd_send_pps_request(struct tcpm_port *port) · line 3433
Quoted 1 line
drivers/usb/typec/tcpm/tcpm.c +1
-0+/* Relax the threshold as voltage will be adjusted right after Accept Message. */ This makes sense. Shouldn't we have the same approach for
tcpm_pd_send_requestas it's equally applicable for fixed RDO as well ?
Quoted 9 lines
I don't think we need to do that because for the power negotiation using Fixed RDO, the voltage adjustment from Source side takes place after the time sending Accept Message plus tSrcTransition (25~35ms). So setting the threshold after the Sink gets Accept Message should be enough.
thanks,
Kyle
Ah, I know your concern here. So you were saying that the tSrcTransition may not be enough in some situations so it is better to do the similar thing for Fixed RDO?
Yeah it makes sense. I will do it in v3.
thanks,
Kyle
Quoted 19 lines
Quoted 19 lines
Quoted 19 lines
drivers/usb/typec/tcpm/tcpm.c +6
-1+tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_USB , false,0 ); +memset (&msg,0 ,sizeof (msg)); msg.header = PD_HEADER_LE(PD_DATA_REQUEST, port->pwr_role,@@ -4196,6 +4206,10 @@ static void run_state_machine(struct tcpm_port *port)case SNK_NEGOTIATE_PPS_CAPABILITIES : ret =tcpm_pd_send_pps_request (port);if (ret <0 ) { +/* Restore back to the original state */ +tcpm_set_auto_vbus_discharge_threshold (port,TYPEC_PWR_MODE_PD , + port->pps_data.active, + port->supply_voltage); port->pps_status = ret;/* * If this was called due to updates to sink -- 2.32.0.272.g935e593368-goog