@@ -105,27 +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-
112- reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (0 ));
113- if (enable && !dwc -> dis_u3_susphy_quirk )
114- reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
115- else
116- reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
117-
118- dwc3_writel (dwc -> regs , DWC3_GUSB3PIPECTL (0 ), reg );
119-
120- reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (0 ));
121- if (enable && !dwc -> dis_u2_susphy_quirk )
122- reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
123- else
124- reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
125-
126- dwc3_writel (dwc -> regs , DWC3_GUSB2PHYCFG (0 ), reg );
127- }
128-
129108void dwc3_set_prtcap (struct dwc3 * dwc , u32 mode )
130109{
131110 u32 reg ;
@@ -138,6 +117,9 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
138117 dwc -> current_dr_role = mode ;
139118}
140119
120+ static void dwc3_core_exit (struct dwc3 * dwc );
121+ static int dwc3_core_init_for_resume (struct dwc3 * dwc );
122+
141123static void __dwc3_set_mode (struct work_struct * work )
142124{
143125 struct dwc3 * dwc = work_to_dwc (work );
@@ -157,7 +139,7 @@ static void __dwc3_set_mode(struct work_struct *work)
157139 if (dwc -> current_dr_role == DWC3_GCTL_PRTCAP_OTG )
158140 dwc3_otg_update (dwc , 0 );
159141
160- if (!desired_dr_role )
142+ if (!desired_dr_role && ! dwc -> role_switch_reset_quirk )
161143 goto out ;
162144
163145 if (desired_dr_role == dwc -> current_dr_role )
@@ -185,13 +167,32 @@ static void __dwc3_set_mode(struct work_struct *work)
185167 break ;
186168 }
187169
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+
188188 /*
189189 * When current_dr_role is not set, there's no role switching.
190190 * Only perform GCTL.CoreSoftReset when there's DRD role switching.
191191 */
192- 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 ) ||
193194 DWC3_VER_IS_PRIOR (DWC31 , 190 A )) &&
194- desired_dr_role != DWC3_GCTL_PRTCAP_OTG )) {
195+ desired_dr_role != DWC3_GCTL_PRTCAP_OTG ))) {
195196 reg = dwc3_readl (dwc -> regs , DWC3_GCTL );
196197 reg |= DWC3_GCTL_CORESOFTRESET ;
197198 dwc3_writel (dwc -> regs , DWC3_GCTL , reg );
@@ -617,8 +618,11 @@ static int dwc3_core_ulpi_init(struct dwc3 *dwc)
617618
618619static int dwc3_ss_phy_setup (struct dwc3 * dwc , int index )
619620{
621+ unsigned int hw_mode ;
620622 u32 reg ;
621623
624+ hw_mode = DWC3_GHWPARAMS0_MODE (dwc -> hwparams .hwparams0 );
625+
622626 reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (index ));
623627
624628 /*
@@ -628,16 +632,21 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
628632 reg &= ~DWC3_GUSB3PIPECTL_UX_EXIT_PX ;
629633
630634 /*
631- * Above DWC_usb3.0 1.94a, it is recommended to set
632- * DWC3_GUSB3PIPECTL_SUSPHY to '0' during coreConsultant configuration.
633- * So default value will be '0' when the core is reset. Application
634- * needs to set it to '1' after the core initialization is completed.
635- *
636- * Similarly for DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be
637- * cleared after power-on reset, and it can be set after core
638- * initialization.
635+ * Above 1.94a, it is recommended to set DWC3_GUSB3PIPECTL_SUSPHY
636+ * to '0' during coreConsultant configuration. So default value
637+ * will be '0' when the core is reset. Application needs to set it
638+ * to '1' after the core initialization is completed.
639+ */
640+ if (!DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A ))
641+ reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
642+
643+ /*
644+ * For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE must be cleared after
645+ * power-on reset, and it can be set after core initialization, which is
646+ * after device soft-reset during initialization.
639647 */
640- reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
648+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD )
649+ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
641650
642651 if (dwc -> u2ss_inp3_quirk )
643652 reg |= DWC3_GUSB3PIPECTL_U2SSINP3OK ;
@@ -663,6 +672,9 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
663672 if (dwc -> tx_de_emphasis_quirk )
664673 reg |= DWC3_GUSB3PIPECTL_TX_DEEPH (dwc -> tx_de_emphasis );
665674
675+ if (dwc -> dis_u3_susphy_quirk )
676+ reg &= ~DWC3_GUSB3PIPECTL_SUSPHY ;
677+
666678 if (dwc -> dis_del_phy_power_chg_quirk )
667679 reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE ;
668680
@@ -673,8 +685,11 @@ static int dwc3_ss_phy_setup(struct dwc3 *dwc, int index)
673685
674686static int dwc3_hs_phy_setup (struct dwc3 * dwc , int index )
675687{
688+ unsigned int hw_mode ;
676689 u32 reg ;
677690
691+ hw_mode = DWC3_GHWPARAMS0_MODE (dwc -> hwparams .hwparams0 );
692+
678693 reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (index ));
679694
680695 /* Select the HS PHY interface */
@@ -717,15 +732,24 @@ static int dwc3_hs_phy_setup(struct dwc3 *dwc, int index)
717732 }
718733
719734 /*
720- * Above DWC_usb3.0 1.94a, it is recommended to set
721- * DWC3_GUSB2PHYCFG_SUSPHY to '0' during coreConsultant configuration.
722- * So default value will be '0' when the core is reset. Application
723- * needs to set it to '1' after the core initialization is completed.
724- *
725- * Similarly for DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared
726- * after power-on reset, and it can be set after core initialization.
735+ * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
736+ * '0' during coreConsultant configuration. So default value will
737+ * be '0' when the core is reset. Application needs to set it to
738+ * '1' after the core initialization is completed.
739+ */
740+ if (!DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A ))
741+ reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
742+
743+ /*
744+ * For DRD controllers, GUSB2PHYCFG.SUSPHY must be cleared after
745+ * power-on reset, and it can be set after core initialization, which is
746+ * after device soft-reset during initialization.
727747 */
728- reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
748+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD )
749+ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
750+
751+ if (dwc -> dis_u2_susphy_quirk )
752+ reg &= ~DWC3_GUSB2PHYCFG_SUSPHY ;
729753
730754 if (dwc -> dis_enblslpm_quirk )
731755 reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM ;
@@ -1324,6 +1348,21 @@ static int dwc3_core_init(struct dwc3 *dwc)
13241348 if (ret )
13251349 goto err_exit_phy ;
13261350
1351+ if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD &&
1352+ !DWC3_VER_IS_WITHIN (DWC3 , ANY , 194 A )) {
1353+ if (!dwc -> dis_u3_susphy_quirk ) {
1354+ reg = dwc3_readl (dwc -> regs , DWC3_GUSB3PIPECTL (0 ));
1355+ reg |= DWC3_GUSB3PIPECTL_SUSPHY ;
1356+ dwc3_writel (dwc -> regs , DWC3_GUSB3PIPECTL (0 ), reg );
1357+ }
1358+
1359+ if (!dwc -> dis_u2_susphy_quirk ) {
1360+ reg = dwc3_readl (dwc -> regs , DWC3_GUSB2PHYCFG (0 ));
1361+ reg |= DWC3_GUSB2PHYCFG_SUSPHY ;
1362+ dwc3_writel (dwc -> regs , DWC3_GUSB2PHYCFG (0 ), reg );
1363+ }
1364+ }
1365+
13271366 dwc3_core_setup_global_control (dwc );
13281367 dwc3_core_num_eps (dwc );
13291368
@@ -1546,6 +1585,18 @@ static int dwc3_core_init_mode(struct dwc3 *dwc)
15461585 ret = dwc3_drd_init (dwc );
15471586 if (ret )
15481587 return dev_err_probe (dev , ret , "failed to initialize dual-role\n" );
1588+
1589+ /*
1590+ * If the role switch reset quirk is required the first role
1591+ * switch notification will initialize the core such that we
1592+ * have to shut it down here. Make sure that the __dwc3_set_mode
1593+ * queued by dwc3_drd_init has completed before since it
1594+ * may still try to access MMIO.
1595+ */
1596+ if (dwc -> role_switch_reset_quirk ) {
1597+ flush_work (& dwc -> drd_work );
1598+ dwc3_core_exit (dwc );
1599+ }
15491600 break ;
15501601 default :
15511602 dev_err (dev , "Unsupported mode of operation %d\n" , dwc -> dr_mode );
@@ -2100,6 +2151,22 @@ static int dwc3_probe(struct platform_device *pdev)
21002151 if (ret )
21012152 goto err_put_psy ;
21022153
2154+ if (dev -> of_node ) {
2155+ if (of_device_is_compatible (dev -> of_node , "apple,dwc3" )) {
2156+ if (!IS_ENABLED (CONFIG_USB_ROLE_SWITCH ) ||
2157+ !IS_ENABLED (CONFIG_USB_DWC3_DUAL_ROLE )) {
2158+ dev_err (dev ,
2159+ "Apple DWC3 requires role switch support.\n"
2160+ );
2161+ ret = - EINVAL ;
2162+ goto err_put_psy ;
2163+ }
2164+
2165+ dwc -> dr_mode = USB_DR_MODE_OTG ;
2166+ dwc -> role_switch_reset_quirk = true;
2167+ }
2168+ }
2169+
21032170 ret = reset_control_deassert (dwc -> reset );
21042171 if (ret )
21052172 goto err_put_psy ;
@@ -2239,7 +2306,6 @@ static void dwc3_remove(struct platform_device *pdev)
22392306 power_supply_put (dwc -> usb_psy );
22402307}
22412308
2242- #ifdef CONFIG_PM
22432309static int dwc3_core_init_for_resume (struct dwc3 * dwc )
22442310{
22452311 int ret ;
@@ -2266,6 +2332,7 @@ static int dwc3_core_init_for_resume(struct dwc3 *dwc)
22662332 return ret ;
22672333}
22682334
2335+ #ifdef CONFIG_PM
22692336static int dwc3_suspend_common (struct dwc3 * dwc , pm_message_t msg )
22702337{
22712338 u32 reg ;
0 commit comments