From f24076c520d9c8ada777fe51816b1f193f0a9763 Mon Sep 17 00:00:00 2001 From: Li Jun Date: Thu, 27 Jul 2017 22:00:54 +0800 Subject: [PATCH] MLK-16013-22 staging: typec: tcpm: split operations of power swap from sink to source Add one more state:PR_SWAP_SNK_SRC_ASSERT_RP, as the next state of PR_SWAP_SNK_SRC_SINK_OFF, it will turn on vbus and wait the vbus is really on and then send the PS_RDY to the other side. Reviewed-by: Peter Chen Signed-off-by: Li Jun --- drivers/staging/typec/tcpm.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/staging/typec/tcpm.c b/drivers/staging/typec/tcpm.c index 0a96c4faaa4e..e56addada5b7 100644 --- a/drivers/staging/typec/tcpm.c +++ b/drivers/staging/typec/tcpm.c @@ -89,6 +89,7 @@ S(PR_SWAP_SRC_SNK_TRANSITION_OFF), \ S(PR_SWAP_SRC_SNK_SOURCE_OFF), \ S(PR_SWAP_SRC_SNK_SINK_ON), \ + S(PR_SWAP_SNK_SRC_ASSERT_RP), \ S(PR_SWAP_SNK_SRC_SINK_OFF), \ S(PR_SWAP_SNK_SRC_SOURCE_ON), \ \ @@ -1369,7 +1370,7 @@ static void tcpm_pd_ctrl_request(struct tcpm_port *port, tcpm_set_state(port, PR_SWAP_SRC_SNK_SINK_ON, 0); break; case PR_SWAP_SNK_SRC_SINK_OFF: - tcpm_set_state(port, PR_SWAP_SNK_SRC_SOURCE_ON, 0); + tcpm_set_state(port, PR_SWAP_SNK_SRC_ASSERT_RP, 0); break; case VCONN_SWAP_WAIT_FOR_VCONN: tcpm_set_state(port, VCONN_SWAP_TURN_OFF_VCONN, 0); @@ -2636,13 +2637,15 @@ static void run_state_machine(struct tcpm_port *port) tcpm_set_state(port, hard_reset_state(port), PD_T_PS_SOURCE_OFF); break; - case PR_SWAP_SNK_SRC_SOURCE_ON: + case PR_SWAP_SNK_SRC_ASSERT_RP: tcpm_set_cc(port, tcpm_rp_cc(port)); tcpm_set_vbus(port, true); - tcpm_pd_send_control(port, PD_CTRL_PS_RDY); + break; + case PR_SWAP_SNK_SRC_SOURCE_ON: tcpm_set_pwr_role(port, TYPEC_SOURCE); + tcpm_pd_send_control(port, PD_CTRL_PS_RDY); tcpm_swap_complete(port, 0); - tcpm_set_state(port, SRC_STARTUP, 0); + tcpm_set_state(port, SRC_STARTUP, 25); break; case VCONN_SWAP_ACCEPT: @@ -2911,6 +2914,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1, break; case PR_SWAP_SNK_SRC_SINK_OFF: + case PR_SWAP_SNK_SRC_ASSERT_RP: case PR_SWAP_SRC_SNK_TRANSITION_OFF: case PR_SWAP_SRC_SNK_SOURCE_OFF: /* @@ -2979,7 +2983,10 @@ static void _tcpm_pd_vbus_on(struct tcpm_port *port) case SNK_TRYWAIT: tcpm_set_state(port, SNK_TRYWAIT_VBUS, 0); break; - + case PR_SWAP_SNK_SRC_ASSERT_RP: + /* If vbus is reached, start source on to send PS_RDY */ + tcpm_set_state(port, PR_SWAP_SNK_SRC_SOURCE_ON, 0); + break; default: break; } -- 2.17.1