From: Hector Martin <marcan@marcan.st>
Apple's dwc3 is connected to a Type-C PHY which supports multiple
protocols (USB2, 3, DisplayPort, Thunderbolt) and has to act as a Type-C
protocol mux driven by the PD prot driver (tipd). The mode and mux
transitions have to be tightly synchronized with dwc3 bringup and
shutdown.
To avoid racing PHY (re-)configuration during hotplug or role switch
events run the role switching inside dwc3 synchronously instead of
relying on a work queue on these controllers.
Signed-off-by: Hector Martin <marcan@marcan.st>
[sven: added commit description]
Signed-off-by: Sven Peter <sven@kernel.org>
---
drivers/usb/dwc3/core.c | 6 +++++-
drivers/usb/dwc3/core.h | 3 +++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 8d2dc7fa18114102cc8893c4ca0e745e16f30754..f8013ba2bdc22fa5e719df0841b12b84d9465b62 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -317,7 +317,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
dwc->desired_dr_role = mode;
spin_unlock_irqrestore(&dwc->lock, flags);
- queue_work(system_freezable_wq, &dwc->drd_work);
+ if (dwc->synchronous_drd_switch)
+ __dwc3_set_mode(&dwc->drd_work);
+ else
+ queue_work(system_freezable_wq, &dwc->drd_work);
}
u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
@@ -2274,6 +2277,7 @@ int dwc3_core_probe(const struct dwc3_probe_data *data)
dwc->dr_mode = USB_DR_MODE_OTG;
dwc->role_switch_reset_quirk = true;
dwc->no_early_roothub_poweroff = true;
+ dwc->synchronous_drd_switch = true;
}
}
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 3c3a36ec37345b2f9e71444ba3b90b52dbd24443..98e748cc348dfd9de1962c93fcf9f6a6690c2388 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1156,6 +1156,8 @@ struct dwc3_scratchpad_array {
* before PM suspend.
* @role_switch_reset_quirk: set to force reinitialization after any role switch
* @no_early_roothub_poweroff: set to skip early root hub port power off
+ * @synchronous_drd_switch: set to perform role switches synchronously instead
+ * of using a workqueue
* @imod_interval: set the interrupt moderation interval in 250ns
* increments or 0 to disable.
* @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1396,6 +1398,7 @@ struct dwc3 {
unsigned role_switch_reset_quirk:1;
unsigned no_early_roothub_poweroff:1;
+ unsigned synchronous_drd_switch:1;
u16 imod_interval;
--
2.34.1