Takashi Iwai 5971b1
From 6bbe2a90a0bb4af8dd99c3565e907fe9b5e7fd88 Mon Sep 17 00:00:00 2001
Takashi Iwai 5971b1
From: Badhri Jagan Sridharan <badhri@google.com>
Takashi Iwai 5971b1
Date: Mon, 17 Aug 2020 11:38:27 -0700
Takashi Iwai 5971b1
Subject: [PATCH] usb: typec: tcpm: During PR_SWAP, source caps should be sent only after tSwapSourceStart
Takashi Iwai 5971b1
Git-commit: 6bbe2a90a0bb4af8dd99c3565e907fe9b5e7fd88
Takashi Iwai 5971b1
Patch-mainline: v5.10-rc1
Takashi Iwai 5971b1
References: git-fixes
Takashi Iwai 5971b1
Takashi Iwai 5971b1
The patch addresses the compliance test failures while running
Takashi Iwai 5971b1
TD.PD.CP.E3, TD.PD.CP.E4, TD.PD.CP.E5 of the "Deterministic PD
Takashi Iwai 5971b1
Compliance MOI" test plan published in https://www.usb.org/usbc.
Takashi Iwai 5971b1
For a product to be Type-C compliant, it's expected that these tests
Takashi Iwai 5971b1
are run on usb.org certified Type-C compliance tester as mentioned in
Takashi Iwai 5971b1
https://www.usb.org/usbc.
Takashi Iwai 5971b1
Takashi Iwai 5971b1
The purpose of the tests TD.PD.CP.E3, TD.PD.CP.E4, TD.PD.CP.E5 is to
Takashi Iwai 5971b1
verify the PR_SWAP response of the device. While doing so, the test
Takashi Iwai 5971b1
asserts that Source Capabilities message is NOT received from the test
Takashi Iwai 5971b1
device within tSwapSourceStart min (20 ms) from the time the last bit
Takashi Iwai 5971b1
of GoodCRC corresponding to the RS_RDY message sent by the UUT was
Takashi Iwai 5971b1
sent. If it does then the test fails.
Takashi Iwai 5971b1
Takashi Iwai 5971b1
This is in line with the requirements from the USB Power Delivery
Takashi Iwai 5971b1
Specification Revision 3.0, Version 1.2:
Takashi Iwai 5971b1
"6.6.8.1 SwapSourceStartTimer
Takashi Iwai 5971b1
The SwapSourceStartTimer Shall be used by the new Source, after a
Takashi Iwai 5971b1
Power Role Swap or Fast Role Swap, to ensure that it does not send
Takashi Iwai 5971b1
Source_Capabilities Message before the new Sink is ready to receive
Takashi Iwai 5971b1
the
Takashi Iwai 5971b1
Source_Capabilities Message. The new Source Shall Not send the
Takashi Iwai 5971b1
Source_Capabilities Message earlier than tSwapSourceStart after the
Takashi Iwai 5971b1
last bit of the EOP of GoodCRC Message sent in response to the PS_RDY
Takashi Iwai 5971b1
Message sent by the new Source indicating that its power supply is
Takashi Iwai 5971b1
ready."
Takashi Iwai 5971b1
Takashi Iwai 5971b1
The patch makes sure that TCPM does not send the Source_Capabilities
Takashi Iwai 5971b1
Message within tSwapSourceStart(20ms) by transitioning into
Takashi Iwai 5971b1
SRC_STARTUP only after  tSwapSourceStart(20ms).
Takashi Iwai 5971b1
Takashi Iwai 5971b1
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Takashi Iwai 5971b1
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Takashi Iwai 5971b1
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Takashi Iwai 5971b1
Link: https://lore.kernel.org/r/20200817183828.1895015-1-badhri@google.com
Takashi Iwai 5971b1
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Takashi Iwai 5971b1
Acked-by: Takashi Iwai <tiwai@suse.de>
Takashi Iwai 5971b1
Takashi Iwai 5971b1
---
Takashi Iwai 5971b1
 drivers/usb/typec/tcpm/tcpm.c | 2 +-
Takashi Iwai 5971b1
 include/linux/usb/pd.h        | 1 +
Takashi Iwai 5971b1
 2 files changed, 2 insertions(+), 1 deletion(-)
Takashi Iwai 5971b1
Takashi Iwai 5971b1
diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
Takashi Iwai 5971b1
index 3ef37202ee37..d38347bd3335 100644
Takashi Iwai 5971b1
--- a/drivers/usb/typec/tcpm/tcpm.c
Takashi Iwai 5971b1
+++ b/drivers/usb/typec/tcpm/tcpm.c
Takashi Iwai 5971b1
@@ -3555,7 +3555,7 @@ static void run_state_machine(struct tcpm_port *port)
Takashi Iwai 5971b1
 		 */
Takashi Iwai 5971b1
 		tcpm_set_pwr_role(port, TYPEC_SOURCE);
Takashi Iwai 5971b1
 		tcpm_pd_send_control(port, PD_CTRL_PS_RDY);
Takashi Iwai 5971b1
-		tcpm_set_state(port, SRC_STARTUP, 0);
Takashi Iwai 5971b1
+		tcpm_set_state(port, SRC_STARTUP, PD_T_SWAP_SRC_START);
Takashi Iwai 5971b1
 		break;
Takashi Iwai 5971b1
 
Takashi Iwai 5971b1
 	case VCONN_SWAP_ACCEPT:
Takashi Iwai 5971b1
diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
Takashi Iwai 5971b1
index b6c233e79bd4..1df895e4680b 100644
Takashi Iwai 5971b1
--- a/include/linux/usb/pd.h
Takashi Iwai 5971b1
+++ b/include/linux/usb/pd.h
Takashi Iwai 5971b1
@@ -473,6 +473,7 @@ static inline unsigned int rdo_max_power(u32 rdo)
Takashi Iwai 5971b1
 #define PD_T_ERROR_RECOVERY	100	/* minimum 25 is insufficient */
Takashi Iwai 5971b1
 #define PD_T_SRCSWAPSTDBY      625     /* Maximum of 650ms */
Takashi Iwai 5971b1
 #define PD_T_NEWSRC            250     /* Maximum of 275ms */
Takashi Iwai 5971b1
+#define PD_T_SWAP_SRC_START	20	/* Minimum of 20ms */
Takashi Iwai 5971b1
 
Takashi Iwai 5971b1
 #define PD_T_DRP_TRY		100	/* 75 - 150 ms */
Takashi Iwai 5971b1
 #define PD_T_DRP_TRYWAIT	600	/* 400 - 800 ms */
Takashi Iwai 5971b1
-- 
Takashi Iwai 5971b1
2.16.4
Takashi Iwai 5971b1