All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: typec: tcpm: always rediscover when swapping DR
@ 2021-08-13  4:31 Icenowy Zheng
  2021-08-17  9:36 ` Heikki Krogerus
  0 siblings, 1 reply; 16+ messages in thread
From: Icenowy Zheng @ 2021-08-13  4:31 UTC (permalink / raw)
  To: Guenter Roeck, Heikki Krogerus, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Icenowy Zheng

Currently, TCPM code omits discover when swapping to gadget, and assume
that no altmodes are available when swapping from gadget. However, we do
send discover when we get attached as gadget -- this leads to modes to be
discovered twice when attached as gadget and then swap to host.

Always re-send discover when swapping DR, regardless of what change is
being made; and because of this, the assumption that no altmodes are
registered with gadget role is broken, and altmodes de-registeration is
always needed now.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
---
 drivers/usb/typec/tcpm/tcpm.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index b9bb63d749ec..ab6d0d51ee1c 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -4495,15 +4495,14 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
 	case DR_SWAP_CHANGE_DR:
-		if (port->data_role == TYPEC_HOST) {
-			tcpm_unregister_altmodes(port);
+		tcpm_unregister_altmodes(port);
+		if (port->data_role == TYPEC_HOST)
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_DEVICE);
-		} else {
+		else
 			tcpm_set_roles(port, true, port->pwr_role,
 				       TYPEC_HOST);
-			port->send_discover = true;
-		}
+		port->send_discover = true;
 		tcpm_ams_finish(port);
 		tcpm_set_state(port, ready_state(port), 0);
 		break;
-- 
2.30.2

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-08-18 16:25 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13  4:31 [PATCH] usb: typec: tcpm: always rediscover when swapping DR Icenowy Zheng
2021-08-17  9:36 ` Heikki Krogerus
2021-08-17  9:41   ` Icenowy Zheng
2021-08-17 11:00     ` Heikki Krogerus
2021-08-18 13:56       ` Greg Kroah-Hartman
2021-08-18 14:02         ` Icenowy Zheng
2021-08-18 14:40           ` Greg Kroah-Hartman
2021-08-18 16:13             ` Kyle Tso
2021-08-18 16:17               ` Icenowy Zheng
2021-08-18 16:24               ` Icenowy Zheng
2021-08-17 15:13   ` Guenter Roeck
2021-08-18  8:02     ` Kyle Tso
2021-08-18  8:16       ` Kyle Tso
2021-08-18  9:20       ` Icenowy Zheng
2021-08-18  9:27       ` Icenowy Zheng
2021-08-18 10:47         ` Kyle Tso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.