Skip to content

Commit 8779561

Browse files
committed
Merge branch 'bits/040-dwc3' into asahi-wip
2 parents 6cc8c20 + f52a438 commit 8779561

6 files changed

Lines changed: 144 additions & 7 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/usb/apple,dwc3.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Apple Silicon DWC3 USB controller
8+
9+
maintainers:
10+
- Sven Peter <sven@svenpeter.dev>
11+
12+
description:
13+
On Apple Silicon SoCs such as the M1 each Type-C port has a corresponding
14+
USB controller based on the Synopsys DesignWare USB3 controller.
15+
16+
The common content of this binding is defined in snps,dwc3.yaml.
17+
18+
allOf:
19+
- $ref: snps,dwc3.yaml#
20+
21+
select:
22+
properties:
23+
compatible:
24+
contains:
25+
const: apple,dwc3
26+
required:
27+
- compatible
28+
29+
properties:
30+
compatible:
31+
items:
32+
- enum:
33+
- apple,t8103-dwc3
34+
- apple,t6000-dwc3
35+
- const: apple,dwc3
36+
- const: snps,dwc3
37+
38+
reg:
39+
maxItems: 1
40+
41+
interrupts:
42+
maxItems: 1
43+
44+
unevaluatedProperties: false
45+
46+
required:
47+
- compatible
48+
- reg
49+
- interrupts
50+
51+
examples:
52+
- |
53+
#include <dt-bindings/interrupt-controller/apple-aic.h>
54+
#include <dt-bindings/interrupt-controller/irq.h>
55+
56+
usb@82280000 {
57+
compatible = "apple,t8103-dwc3", "apple,dwc3", "snps,dwc3";
58+
reg = <0x82280000 0x10000>;
59+
interrupts = <AIC_IRQ 777 IRQ_TYPE_LEVEL_HIGH>;
60+
61+
dr_mode = "otg";
62+
usb-role-switch;
63+
role-switch-default-mode = "host";
64+
};

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,7 @@ F: Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml
22392239
F: Documentation/devicetree/bindings/power/apple*
22402240
F: Documentation/devicetree/bindings/pwm/apple,s5l-fpwm.yaml
22412241
F: Documentation/devicetree/bindings/spi/apple,spi.yaml
2242+
F: Documentation/devicetree/bindings/usb/apple,dwc3.yaml
22422243
F: Documentation/devicetree/bindings/watchdog/apple,wdt.yaml
22432244
F: arch/arm64/boot/dts/apple/
22442245
F: drivers/bluetooth/hci_bcm4377.c

drivers/usb/dwc3/core.c

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy)
156156
dwc->current_dr_role = mode;
157157
}
158158

159+
static void dwc3_core_exit(struct dwc3 *dwc);
160+
static int dwc3_core_init_for_resume(struct dwc3 *dwc);
161+
159162
static void __dwc3_set_mode(struct work_struct *work)
160163
{
161164
struct dwc3 *dwc = work_to_dwc(work);
@@ -175,7 +178,7 @@ static void __dwc3_set_mode(struct work_struct *work)
175178
if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_OTG)
176179
dwc3_otg_update(dwc, 0);
177180

178-
if (!desired_dr_role)
181+
if (!desired_dr_role && !dwc->role_switch_reset_quirk)
179182
goto out;
180183

181184
if (desired_dr_role == dwc->current_dr_role)
@@ -203,13 +206,32 @@ static void __dwc3_set_mode(struct work_struct *work)
203206
break;
204207
}
205208

209+
if (dwc->role_switch_reset_quirk) {
210+
if (dwc->current_dr_role) {
211+
dwc->current_dr_role = 0;
212+
dwc3_core_exit(dwc);
213+
}
214+
215+
if (desired_dr_role) {
216+
ret = dwc3_core_init_for_resume(dwc);
217+
if (ret) {
218+
dev_err(dwc->dev,
219+
"failed to reinitialize core\n");
220+
goto out;
221+
}
222+
} else {
223+
goto out;
224+
}
225+
}
226+
206227
/*
207228
* When current_dr_role is not set, there's no role switching.
208229
* Only perform GCTL.CoreSoftReset when there's DRD role switching.
209230
*/
210-
if (dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
231+
if (dwc->role_switch_reset_quirk ||
232+
(dwc->current_dr_role && ((DWC3_IP_IS(DWC3) ||
211233
DWC3_VER_IS_PRIOR(DWC31, 190A)) &&
212-
desired_dr_role != DWC3_GCTL_PRTCAP_OTG)) {
234+
desired_dr_role != DWC3_GCTL_PRTCAP_OTG))) {
213235
reg = dwc3_readl(dwc->regs, DWC3_GCTL);
214236
reg |= DWC3_GCTL_CORESOFTRESET;
215237
dwc3_writel(dwc->regs, DWC3_GCTL, reg);
@@ -1370,6 +1392,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
13701392
if (ret)
13711393
goto err_exit_phy;
13721394

1395+
if (dwc->role_switch_reset_quirk)
1396+
dwc3_enable_susphy(dwc, true);
1397+
13731398
dwc3_core_setup_global_control(dwc);
13741399
dwc3_core_num_eps(dwc);
13751400

@@ -1633,6 +1658,18 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
16331658
ret = dwc3_drd_init(dwc);
16341659
if (ret)
16351660
return dev_err_probe(dev, ret, "failed to initialize dual-role\n");
1661+
1662+
/*
1663+
* If the role switch reset quirk is required the first role
1664+
* switch notification will initialize the core such that we
1665+
* have to shut it down here. Make sure that the __dwc3_set_mode
1666+
* queued by dwc3_drd_init has completed before since it
1667+
* may still try to access MMIO.
1668+
*/
1669+
if (dwc->role_switch_reset_quirk) {
1670+
flush_work(&dwc->drd_work);
1671+
dwc3_core_exit(dwc);
1672+
}
16361673
break;
16371674
default:
16381675
dev_err(dev, "Unsupported mode of operation %d\n", dwc->dr_mode);
@@ -2218,6 +2255,23 @@ static int dwc3_probe(struct platform_device *pdev)
22182255
if (ret)
22192256
goto err_put_psy;
22202257

2258+
if (dev->of_node) {
2259+
if (of_device_is_compatible(dev->of_node, "apple,dwc3")) {
2260+
if (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
2261+
!IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
2262+
dev_err(dev,
2263+
"Apple DWC3 requires role switch support.\n"
2264+
);
2265+
ret = -EINVAL;
2266+
goto err_put_psy;
2267+
}
2268+
2269+
dwc->dr_mode = USB_DR_MODE_OTG;
2270+
dwc->role_switch_reset_quirk = true;
2271+
dwc->no_early_roothub_poweroff = true;
2272+
}
2273+
}
2274+
22212275
ret = reset_control_deassert(dwc->reset);
22222276
if (ret)
22232277
goto err_put_psy;
@@ -2357,7 +2411,6 @@ static void dwc3_remove(struct platform_device *pdev)
23572411
power_supply_put(dwc->usb_psy);
23582412
}
23592413

2360-
#ifdef CONFIG_PM
23612414
static int dwc3_core_init_for_resume(struct dwc3 *dwc)
23622415
{
23632416
int ret;
@@ -2384,6 +2437,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
23842437
return ret;
23852438
}
23862439

2440+
#ifdef CONFIG_PM
23872441
static int dwc3_suspend_common(struct dwc3 *dwc, pm_message_t msg)
23882442
{
23892443
u32 reg;

drivers/usb/dwc3/core.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,8 @@ struct dwc3_scratchpad_array {
11531153
* @suspended: set to track suspend event due to U3/L2.
11541154
* @susphy_state: state of DWC3_GUSB2PHYCFG_SUSPHY + DWC3_GUSB3PIPECTL_SUSPHY
11551155
* before PM suspend.
1156+
* @role_switch_reset_quirk: set to force reinitialization after any role switch
1157+
* @no_early_roothub_poweroff: set to skip early root hub port power off
11561158
* @imod_interval: set the interrupt moderation interval in 250ns
11571159
* increments or 0 to disable.
11581160
* @max_cfg_eps: current max number of IN eps used across all USB configs.
@@ -1387,6 +1389,9 @@ struct dwc3 {
13871389
unsigned suspended:1;
13881390
unsigned susphy_state:1;
13891391

1392+
unsigned role_switch_reset_quirk:1;
1393+
unsigned no_early_roothub_poweroff:1;
1394+
13901395
u16 imod_interval;
13911396

13921397
int max_cfg_eps;

drivers/usb/dwc3/drd.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw,
464464
break;
465465
}
466466

467+
if (dwc->role_switch_reset_quirk && role == USB_ROLE_NONE)
468+
mode = 0;
469+
467470
dwc3_set_mode(dwc, mode);
468471
return 0;
469472
}
@@ -492,6 +495,10 @@ static enum usb_role dwc3_usb_role_switch_get(struct usb_role_switch *sw)
492495
role = USB_ROLE_DEVICE;
493496
break;
494497
}
498+
499+
if (dwc->role_switch_reset_quirk && !dwc->current_dr_role)
500+
role = USB_ROLE_NONE;
501+
495502
spin_unlock_irqrestore(&dwc->lock, flags);
496503
return role;
497504
}
@@ -502,7 +509,9 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc)
502509
u32 mode;
503510

504511
dwc->role_switch_default_mode = usb_get_role_switch_default_mode(dwc->dev);
505-
if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) {
512+
if (dwc->role_switch_reset_quirk) {
513+
mode = 0;
514+
} else if (dwc->role_switch_default_mode == USB_DR_MODE_HOST) {
506515
mode = DWC3_GCTL_PRTCAP_HOST;
507516
} else {
508517
dwc->role_switch_default_mode = USB_DR_MODE_PERIPHERAL;

drivers/usb/dwc3/host.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ int dwc3_host_init(struct dwc3 *dwc)
134134
/*
135135
* Some platforms need to power off all Root hub ports immediately after DWC3 set to host
136136
* mode to avoid VBUS glitch happen when xhci get reset later.
137+
* On Apple platforms we must not touch any MMIO yet because dwc3
138+
* will not work correctly before its PHY has been initialized.
137139
*/
138-
dwc3_power_off_all_roothub_ports(dwc);
140+
if (!dwc->no_early_roothub_poweroff)
141+
dwc3_power_off_all_roothub_ports(dwc);
139142

140143
irq = dwc3_host_get_irq(dwc);
141144
if (irq < 0)
@@ -220,7 +223,8 @@ void dwc3_host_exit(struct dwc3 *dwc)
220223
if (dwc->sys_wakeup)
221224
device_init_wakeup(&dwc->xhci->dev, false);
222225

223-
dwc3_enable_susphy(dwc, false);
226+
if (!dwc->role_switch_reset_quirk)
227+
dwc3_enable_susphy(dwc, false);
224228
platform_device_unregister(dwc->xhci);
225229
dwc->xhci = NULL;
226230
}

0 commit comments

Comments
 (0)