@@ -105,32 +105,6 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
105105 return 0 ;
106106}
107107
108- void dwc3_enable_susphy (struct dwc3 * dwc , bool enable )
109- {
110- u32 reg ;
111- int i ;
112-
113- for (i = 0 ; i < dwc -> num_usb3_ports ; i ++ ) {
114- reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (i ));
115- if (enable && !dwc -> dis_u3_susphy_quirk )
116- reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
117- else
118- reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
119-
120- dwc3_writel (dwc -> regs , DWC3_GUSB3PIPECTL (i ), reg );
121- }
122-
123- for (i = 0 ; i < dwc -> num_usb2_ports ; i ++ ) {
124- reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (i ));
125- if (enable && !dwc -> dis_u2_susphy_quirk )
126- reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
127- else
128- reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
129-
130- dwc3_writel (dwc -> regs , DWC3_GUSB2PHYCFG (i ), reg );
131- }
132- }
133-
134108void dwc3_set_prtcap (struct dwc3 * dwc , u32 mode )
135109{
136110 u32 reg ;
@@ -143,6 +117,9 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
143117 dwc -> current_dr_role = mode ;
144118}
145119
120+ static void dwc3_core_exit (struct dwc3 * dwc );
121+ static int dwc3_core_init_for_resume (struct dwc3 * dwc );
122+
146123static void __dwc3_set_mode (struct work_struct * work )
147124{
148125 struct dwc3 * dwc = work_to_dwc (work );
@@ -162,7 +139,7 @@ static void __dwc3_set_mode(struct work_struct *work)
162139 if (dwc -> current_dr_role == DWC3_GCTL_PRTCAP_OTG )
163140 dwc3_otg_update (dwc , 0 );
164141
165- if (!desired_dr_role )
142+ if (!desired_dr_role && ! dwc -> role_switch_reset_quirk )
166143 goto out ;
167144
168145 if (desired_dr_role == dwc -> current_dr_role )
@@ -190,13 +167,32 @@ static void __dwc3_set_mode(struct work_struct *work)
190167 break ;
191168 }
192169
170+ if (dwc -> role_switch_reset_quirk ) {
171+ if (dwc -> current_dr_role ) {
172+ dwc -> current_dr_role = 0 ;
173+ dwc3_core_exit (dwc );
174+ }
175+
176+ if (desired_dr_role ) {
177+ ret = dwc3_core_init_for_resume (dwc );
178+ if (ret ) {
179+ dev_err (dwc -> dev ,
180+ "failed to reinitialize core\n" );
181+ goto out ;
182+ }
183+ } else {
184+ goto out ;
185+ }
186+ }
187+
193188 /*
194189 * When current_dr_role is not set, there's no role switching.
195190 * Only perform GCTL.CoreSoftReset when there's DRD role switching.
196191 */
197- if (dwc -> current_dr_role && ((DWC3_IP_IS (DWC3 ) ||
192+ if (dwc -> role_switch_reset_quirk ||
193+ (dwc -> current_dr_role && ((DWC3_IP_IS (DWC3 ) ||
198194 DWC3_VER_IS_PRIOR (DWC31 , 190 A )) &&
199- desired_dr_role != DWC3_GCTL_PRTCAP_OTG )) {
195+ desired_dr_role != DWC3_GCTL_PRTCAP_OTG ))) {
200196 reg = dwc3_readl (dwc -> regs , DWC3_GCTL );
201197 reg |= DWC3_GCTL_CORESOFTRESET ;
202198 dwc3_writel (dwc -> regs , DWC3_GCTL , reg );
@@ -642,8 +638,11 @@ static int dwc3_core_ulpi_init(struct dwc3 *dwc)
642638
643639static int dwc3_ss_phy_setup (struct dwc3 * dwc , int index )
644640{
641+ unsigned int hw_mode ;
645642 u32 reg ;
646643
644+ hw_mode = DWC3_GHWPARAMS0_MODE (dwc -> hwparams .hwparams0 );
645+
647646 reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (index ));
648647
649648 /*
@@ -653,16 +652,21 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
653652 reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX ;
654653
655654 /*
656- * Above DWC_usb3.0 1.94a, it is recommended to set
657- * DWC3_GUSB3PIPECTL_SUSPHY to '0' during coreConsultant configuration.
658- * So default value will be '0' when the core is reset. Application
659- * needs to set it to '1' after the core initialization is completed.
660- *
661- * Similarly for DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be
662- * cleared after power-on reset, and it can be set after core
663- * initialization.
655+ * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
656+ * to '0' during coreConsultant configuration. So default value
657+ * will be '0' when the core is reset. Application needs to set it
658+ * to '1' after the core initialization is completed.
664659 */
665- reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
660+ if (!DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A ))
661+ reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
662+
663+ /*
664+ * For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after
665+ * power-on reset, and it can be set after core initialization, which is
666+ * after device soft-reset during initialization.
667+ */
668+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD )
669+ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
666670
667671 if (dwc -> u2ss_inp3_quirk )
668672 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK ;
@@ -688,6 +692,9 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
688692 if (dwc -> tx_de_emphasis_quirk )
689693 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH (dwc -> tx_de_emphasis );
690694
695+ if (dwc -> dis_u3_susphy_quirk )
696+ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
697+
691698 if (dwc -> dis_del_phy_power_chg_quirk )
692699 reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE ;
693700
@@ -698,8 +705,11 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
698705
699706static int dwc3_hs_phy_setup (struct dwc3 * dwc , int index )
700707{
708+ unsigned int hw_mode ;
701709 u32 reg ;
702710
711+ hw_mode = DWC3_GHWPARAMS0_MODE (dwc -> hwparams .hwparams0 );
712+
703713 reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (index ));
704714
705715 /* Select the HS PHY interface */
@@ -742,15 +752,24 @@ static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index)
742752 }
743753
744754 /*
745- * Above DWC_usb3.0 1.94a, it is recommended to set
746- * DWC3_GUSB2PHYCFG_SUSPHY to '0' during coreConsultant configuration.
747- * So default value will be '0' when the core is reset. Application
748- * needs to set it to '1' after the core initialization is completed.
749- *
750- * Similarly for DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared
751- * after power-on reset, and it can be set after core initialization.
755+ * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
756+ * '0' during coreConsultant configuration. So default value will
757+ * be '0' when the core is reset. Application needs to set it to
758+ * '1' after the core initialization is completed.
759+ */
760+ if (!DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A ))
761+ reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
762+
763+ /*
764+ * For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after
765+ * power-on reset, and it can be set after core initialization, which is
766+ * after device soft-reset during initialization.
752767 */
753- reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
768+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD )
769+ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
770+
771+ if (dwc -> dis_u2_susphy_quirk )
772+ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
754773
755774 if (dwc -> dis_enblslpm_quirk )
756775 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM ;
@@ -1349,6 +1368,21 @@ static int dwc3_core_init(struct dwc3 *dwc)
13491368 if (ret )
13501369 goto err_exit_phy ;
13511370
1371+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
1372+ !DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A )) {
1373+ if (!dwc -> dis_u3_susphy_quirk ) {
1374+ reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (0 ));
1375+ reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
1376+ dwc3_writel (dwc -> regs , DWC3_GUSB3PIPECTL (0 ), reg );
1377+ }
1378+
1379+ if (!dwc -> dis_u2_susphy_quirk ) {
1380+ reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (0 ));
1381+ reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
1382+ dwc3_writel (dwc -> regs , DWC3_GUSB2PHYCFG (0 ), reg );
1383+ }
1384+ }
1385+
13521386 dwc3_core_setup_global_control (dwc );
13531387 dwc3_core_num_eps (dwc );
13541388
@@ -1588,6 +1622,18 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
15881622 ret = dwc3_drd_init (dwc );
15891623 if (ret )
15901624 return dev_err_probe (dev , ret , "failed to initialize dual-role\n" );
1625+
1626+ /*
1627+ * If the role switch reset quirk is required the first role
1628+ * switch notification will initialize the core such that we
1629+ * have to shut it down here. Make sure that the __dwc3_set_mode
1630+ * queued by dwc3_drd_init has completed before since it
1631+ * may still try to access MMIO.
1632+ */
1633+ if (dwc -> role_switch_reset_quirk ) {
1634+ flush_work (& dwc -> drd_work );
1635+ dwc3_core_exit (dwc );
1636+ }
15911637 break ;
15921638 default :
15931639 dev_err (dev , "Unsupported mode of operation %d\n" , dwc -> dr_mode );
@@ -2165,6 +2211,22 @@ static int dwc3_probe(struct platform_device *pdev)
21652211 if (ret )
21662212 goto err_put_psy ;
21672213
2214+ if (dev -> of_node ) {
2215+ if (of_device_is_compatible (dev -> of_node , "apple,dwc3" )) {
2216+ if (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) ||
2217+ !IS_ENABLED (CONFIG_USB_DWC3_DUAL_ROLE )) {
2218+ dev_err (dev ,
2219+ "Apple DWC3 requires role switch support.\n"
2220+ );
2221+ ret = - EINVAL ;
2222+ goto err_put_psy ;
2223+ }
2224+
2225+ dwc -> dr_mode = USB_DR_MODE_OTG ;
2226+ dwc -> role_switch_reset_quirk = true;
2227+ }
2228+ }
2229+
21682230 ret = reset_control_deassert (dwc -> reset );
21692231 if (ret )
21702232 goto err_put_psy ;
@@ -2304,7 +2366,6 @@ static void dwc3_remove(struct platform_device *pdev)
23042366 power_supply_put (dwc -> usb_psy );
23052367}
23062368
2307- #ifdef CONFIG_PM
23082369static int dwc3_core_init_for_resume (struct dwc3 * dwc )
23092370{
23102371 int ret ;
@@ -2331,6 +2392,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
23312392 return ret ;
23322393}
23332394
2395+ #ifdef CONFIG_PM
23342396static int dwc3_suspend_common (struct dwc3 * dwc , pm_message_t msg )
23352397{
23362398 u32 reg ;
0 commit comments