@@ -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+
159162static 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 , 190 A )) &&
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
23612414static 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
23872441static int dwc3_suspend_common (struct dwc3 * dwc , pm_message_t msg )
23882442{
23892443 u32 reg ;
0 commit comments