@@ -116,6 +116,9 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
116116 dwc -> current_dr_role = mode ;
117117}
118118
119+ static void dwc3_core_exit (struct dwc3 * dwc );
120+ static int dwc3_core_init_for_resume (struct dwc3 * dwc );
121+
119122static void __dwc3_set_mode (struct work_struct * work )
120123{
121124 struct dwc3 * dwc = work_to_dwc (work );
@@ -134,7 +137,7 @@ static void __dwc3_set_mode(struct work_struct *work)
134137 if (dwc -> current_dr_role == DWC3_GCTL_PRTCAP_OTG )
135138 dwc3_otg_update (dwc , 0 );
136139
137- if (!desired_dr_role )
140+ if (!desired_dr_role && ! dwc -> role_switch_reset_quirk )
138141 goto out ;
139142
140143 if (desired_dr_role == dwc -> current_dr_role )
@@ -162,13 +165,32 @@ static void __dwc3_set_mode(struct work_struct *work)
162165 break ;
163166 }
164167
168+ if (dwc -> role_switch_reset_quirk ) {
169+ if (dwc -> current_dr_role ) {
170+ dwc -> current_dr_role = 0 ;
171+ dwc3_core_exit (dwc );
172+ }
173+
174+ if (desired_dr_role ) {
175+ ret = dwc3_core_init_for_resume (dwc );
176+ if (ret ) {
177+ dev_err (dwc -> dev ,
178+ "failed to reinitialize core\n" );
179+ goto out ;
180+ }
181+ } else {
182+ goto out ;
183+ }
184+ }
185+
165186 /*
166187 * When current_dr_role is not set, there's no role switching.
167188 * Only perform GCTL.CoreSoftReset when there's DRD role switching.
168189 */
169- if (dwc -> current_dr_role && ((DWC3_IP_IS (DWC3 ) ||
190+ if (dwc -> role_switch_reset_quirk ||
191+ (dwc -> current_dr_role && ((DWC3_IP_IS (DWC3 ) ||
170192 DWC3_VER_IS_PRIOR (DWC31 , 190 A )) &&
171- desired_dr_role != DWC3_GCTL_PRTCAP_OTG )) {
193+ desired_dr_role != DWC3_GCTL_PRTCAP_OTG ))) {
172194 reg = dwc3_readl (dwc -> regs , DWC3_GCTL );
173195 reg |= DWC3_GCTL_CORESOFTRESET ;
174196 dwc3_writel (dwc -> regs , DWC3_GCTL , reg );
@@ -1344,6 +1366,18 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
13441366 ret = dwc3_drd_init (dwc );
13451367 if (ret )
13461368 return dev_err_probe (dev , ret , "failed to initialize dual-role\n" );
1369+
1370+ /*
1371+ * If the role switch reset quirk is required the first role
1372+ * switch notification will initialize the core such that we
1373+ * have to shut it down here. Make sure that the __dwc3_set_mode
1374+ * queued by dwc3_drd_init has completed before since it
1375+ * may still try to access MMIO.
1376+ */
1377+ if (dwc -> role_switch_reset_quirk ) {
1378+ flush_work (& dwc -> drd_work );
1379+ dwc3_core_exit (dwc );
1380+ }
13471381 break ;
13481382 default :
13491383 dev_err (dev , "Unsupported mode of operation %d\n" , dwc -> dr_mode );
@@ -1814,6 +1848,22 @@ static int dwc3_probe(struct platform_device *pdev)
18141848 if (ret )
18151849 goto err_put_psy ;
18161850
1851+ if (dev -> of_node ) {
1852+ if (of_device_is_compatible (dev -> of_node , "apple,dwc3" )) {
1853+ if (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) ||
1854+ !IS_ENABLED (CONFIG_USB_DWC3_DUAL_ROLE )) {
1855+ dev_err (dev ,
1856+ "Apple DWC3 requires role switch support.\n"
1857+ );
1858+ ret = - EINVAL ;
1859+ goto err_put_psy ;
1860+ }
1861+
1862+ dwc -> dr_mode = USB_DR_MODE_OTG ;
1863+ dwc -> role_switch_reset_quirk = true;
1864+ }
1865+ }
1866+
18171867 ret = reset_control_deassert (dwc -> reset );
18181868 if (ret )
18191869 goto err_put_psy ;
@@ -1937,7 +1987,6 @@ static void dwc3_remove(struct platform_device *pdev)
19371987 power_supply_put (dwc -> usb_psy );
19381988}
19391989
1940- #ifdef CONFIG_PM
19411990static int dwc3_core_init_for_resume (struct dwc3 * dwc )
19421991{
19431992 int ret ;
@@ -1964,6 +2013,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
19642013 return ret ;
19652014}
19662015
2016+ #ifdef CONFIG_PM
19672017static int dwc3_suspend_common (struct dwc3 * dwc , pm_message_t msg )
19682018{
19692019 unsigned long flags ;
0 commit comments