mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 14:23:38 +00:00
173 lines
5.5 KiB
Diff
173 lines
5.5 KiB
Diff
From bda2c5ab3f028f25bf7d0e8196ee1dee38973153 Mon Sep 17 00:00:00 2001
|
|
From: Sven Peter <sven@svenpeter.dev>
|
|
Date: Sun, 7 Nov 2021 11:21:20 +0100
|
|
Subject: [PATCH 064/171] usb: dwc3: Add role switch reset quirk for Apple DWC3
|
|
|
|
As mad as it sounds, the dwc3 controller present on the Apple M1 must be
|
|
reset and reinitialized whenever a device is unplugged from the root port.
|
|
The only reliable unplug/plug notification available comes from the USB
|
|
PD controller through the role-switch infrastructure.
|
|
|
|
This is required for at least two reasons:
|
|
|
|
- The USB2 D+/D- lines are connected through a stateful eUSB2 repeater
|
|
which in turn is controlled by a variant of the TI TPS6598x USB PD
|
|
chip. When the USB PD controller detects a hotplug event it resets
|
|
the eUSB2 repeater. Afterwards, no new device is recognized before
|
|
the DWC3 core and PHY are reset as well.
|
|
|
|
- It's possible to completely break the dwc3 controller by switching
|
|
it to device mode and unplugging the cable at just the wrong time.
|
|
Even a CORESOFTRESET is not enough to allow new devices again.
|
|
The only workaround is to trigger a hard reset of the entire
|
|
dwc3 core.
|
|
|
|
Signed-off-by: Sven Peter <sven@svenpeter.dev>
|
|
---
|
|
drivers/usb/dwc3/core.c | 41 ++++++++++++++++++++++++++++++++++++++---
|
|
drivers/usb/dwc3/core.h | 6 ++++++
|
|
drivers/usb/dwc3/drd.c | 7 +++++++
|
|
3 files changed, 51 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
|
|
index 573421984948..b4c58deccabb 100644
|
|
--- a/drivers/usb/dwc3/core.c
|
|
+++ b/drivers/usb/dwc3/core.c
|
|
@@ -116,6 +116,9 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
|
|
dwc->current_dr_role = mode;
|
|
}
|
|
|
|
+static void dwc3_core_exit(struct dwc3 *dwc);
|
|
+static int dwc3_core_init_for_resume(struct dwc3 *dwc);
|
|
+
|
|
static void __dwc3_set_mode(struct work_struct *work)
|
|
{
|
|
struct dwc3 *dwc = work_to_dwc(work);
|
|
@@ -130,10 +133,11 @@ static void __dwc3_set_mode(struct work_struct *work)
|
|
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
|
|
dwc3_otg_update(dwc, 0);
|
|
|
|
- if (!dwc->desired_dr_role)
|
|
+ if (!dwc->desired_dr_role && !dwc->role_switch_reset_quirk)
|
|
goto out;
|
|
|
|
- if (dwc->desired_dr_role == dwc->current_dr_role)
|
|
+ if (dwc->desired_dr_role == dwc->current_dr_role &&
|
|
+ !dwc->role_switch_reset_quirk)
|
|
goto out;
|
|
|
|
if (dwc->desired_dr_role == DWC3_GCTL_PRTCAP_OTG && dwc->edev)
|
|
@@ -158,6 +162,34 @@ static void __dwc3_set_mode(struct work_struct *work)
|
|
break;
|
|
}
|
|
|
|
+ if (dwc->role_switch_reset_quirk) {
|
|
+ if (dwc->current_dr_role) {
|
|
+ dwc->current_dr_role = 0;
|
|
+ dwc3_core_exit(dwc);
|
|
+ }
|
|
+
|
|
+ if (dwc->desired_dr_role) {
|
|
+ /*
|
|
+ * the first call to __dwc3_set_mode comes from
|
|
+ * dwc3_drd_init. In that case dwc3_core_init has been
|
|
+ * called but dwc->current_dr_role is zero such that
|
|
+ * we must not reinitialize the core again here.
|
|
+ */
|
|
+ if (dwc->role_switch_reset_quirk_initialized) {
|
|
+ ret = dwc3_core_init_for_resume(dwc);
|
|
+ if (ret) {
|
|
+ dev_err(dwc->dev,
|
|
+ "failed to reinitialize core\n");
|
|
+ goto out;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ dwc->role_switch_reset_quirk_initialized = 1;
|
|
+ } else {
|
|
+ goto out;
|
|
+ }
|
|
+ }
|
|
+
|
|
/* For DRD host or device mode only */
|
|
if (dwc->desired_dr_role != DWC3_GCTL_PRTCAP_OTG) {
|
|
reg = dwc3_readl(dwc->regs, DWC3_GCTL);
|
|
@@ -1764,6 +1796,9 @@ static int dwc3_probe(struct platform_device *pdev)
|
|
return dev_err_probe(dev, PTR_ERR(dwc->susp_clk),
|
|
"could not get suspend clock\n");
|
|
}
|
|
+
|
|
+ if (of_device_is_compatible(dev->of_node, "apple,dwc3"))
|
|
+ dwc->role_switch_reset_quirk = true;
|
|
}
|
|
|
|
ret = reset_control_deassert(dwc->reset);
|
|
@@ -1900,7 +1935,6 @@ static int dwc3_remove(struct platform_device *pdev)
|
|
return 0;
|
|
}
|
|
|
|
-#ifdef CONFIG_PM
|
|
static int dwc3_core_init_for_resume(struct dwc3 *dwc)
|
|
{
|
|
int ret;
|
|
@@ -1927,6 +1961,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
|
|
return ret;
|
|
}
|
|
|
|
+#ifdef CONFIG_PM
|
|
static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
|
|
{
|
|
unsigned long flags;
|
|
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
|
|
index 81c486b3941c..ee0225ce2234 100644
|
|
--- a/drivers/usb/dwc3/core.h
|
|
+++ b/drivers/usb/dwc3/core.h
|
|
@@ -1103,6 +1103,9 @@ struct dwc3_scratchpad_array {
|
|
* 3 - Reserved
|
|
* @dis_metastability_quirk: set to disable metastability quirk.
|
|
* @dis_split_quirk: set to disable split boundary.
|
|
+ * @role_switch_reset_quirk: set to force reinitialization after any role switch
|
|
+ * @role_switch_reset_quirk_initialized: set to true after the first role switch
|
|
+ * which is triggered from dwc3_drd_init directly
|
|
* @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.
|
|
@@ -1318,6 +1321,9 @@ struct dwc3 {
|
|
unsigned dis_split_quirk:1;
|
|
unsigned async_callbacks:1;
|
|
|
|
+ unsigned role_switch_reset_quirk:1;
|
|
+ unsigned role_switch_reset_quirk_initialized:1;
|
|
+
|
|
u16 imod_interval;
|
|
|
|
int max_cfg_eps;
|
|
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
|
|
index 039bf241769a..4579505cac1f 100644
|
|
--- a/drivers/usb/dwc3/drd.c
|
|
+++ b/drivers/usb/dwc3/drd.c
|
|
@@ -461,6 +461,9 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw,
|
|
break;
|
|
}
|
|
|
|
+ if (dwc->role_switch_reset_quirk && role == USB_ROLE_NONE)
|
|
+ mode = 0;
|
|
+
|
|
dwc3_set_mode(dwc, mode);
|
|
return 0;
|
|
}
|
|
@@ -489,6 +492,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct usb_role_switch *sw)
|
|
role = USB_ROLE_DEVICE;
|
|
break;
|
|
}
|
|
+
|
|
+ if (dwc->role_switch_reset_quirk && !dwc->current_dr_role)
|
|
+ role = USB_ROLE_NONE;
|
|
+
|
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
|
return role;
|
|
}
|
|
--
|
|
2.34.1
|
|
|