@@ -218,25 +218,30 @@ static int dwc3_apple_core_init(struct dwc3_apple *appledwc)
218218 return ret ;
219219}
220220
221- static void dwc3_apple_phy_set_mode (struct dwc3_apple * appledwc , enum phy_mode mode )
222- {
223- lockdep_assert_held (& appledwc -> lock );
224-
225- /*
226- * This platform requires SUSPHY to be enabled here already in order to properly configure
227- * the PHY and switch dwc3's PIPE interface to USB3 PHY.
228- */
229- dwc3_enable_susphy (& appledwc -> dwc , true);
230- phy_set_mode (appledwc -> dwc .usb2_generic_phy [0 ], mode );
231- phy_set_mode (appledwc -> dwc .usb3_generic_phy [0 ], mode );
232- }
233-
234221static int dwc3_apple_init (struct dwc3_apple * appledwc , enum dwc3_apple_state state )
235222{
236223 int ret , ret_reset ;
237224
238225 lockdep_assert_held (& appledwc -> lock );
239226
227+ /*
228+ * The USB2 PHY on this platform must be configured for host or device mode while it is
229+ * still powered off and before dwc3 tries to access it. Otherwise the new configuration
230+ * will only take affect during the *next* time dwc3 is brought up.
231+ */
232+ switch (state ) {
233+ case DWC3_APPLE_HOST :
234+ phy_set_mode (appledwc -> dwc .usb2_generic_phy [0 ], PHY_MODE_USB_HOST );
235+ break ;
236+ case DWC3_APPLE_DEVICE :
237+ phy_set_mode (appledwc -> dwc .usb2_generic_phy [0 ], PHY_MODE_USB_DEVICE );
238+ break ;
239+ default :
240+ /* Unreachable unless there's a bug in this driver */
241+ WARN_ON_ONCE (1 );
242+ return - EINVAL ;
243+ }
244+
240245 ret = reset_control_deassert (appledwc -> reset );
241246 if (ret ) {
242247 dev_err (appledwc -> dev , "Failed to deassert reset, err=%d\n" , ret );
@@ -257,7 +262,13 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st
257262 case DWC3_APPLE_HOST :
258263 appledwc -> dwc .dr_mode = USB_DR_MODE_HOST ;
259264 dwc3_apple_set_ptrcap (appledwc , DWC3_GCTL_PRTCAP_HOST );
260- dwc3_apple_phy_set_mode (appledwc , PHY_MODE_USB_HOST );
265+ /*
266+ * This platform requires SUSPHY to be enabled here already in order to properly configure
267+ * the PHY and switch dwc3's PIPE interface to USB3 PHY. The USB2 PHY has already been
268+ * configured to the correct mode earlier.
269+ */
270+ dwc3_enable_susphy (& appledwc -> dwc , true);
271+ phy_set_mode (appledwc -> dwc .usb3_generic_phy [0 ], PHY_MODE_USB_HOST );
261272 ret = dwc3_host_init (& appledwc -> dwc );
262273 if (ret ) {
263274 dev_err (appledwc -> dev , "Failed to initialize host, ret=%d\n" , ret );
@@ -268,7 +279,13 @@ static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state st
268279 case DWC3_APPLE_DEVICE :
269280 appledwc -> dwc .dr_mode = USB_DR_MODE_PERIPHERAL ;
270281 dwc3_apple_set_ptrcap (appledwc , DWC3_GCTL_PRTCAP_DEVICE );
271- dwc3_apple_phy_set_mode (appledwc , PHY_MODE_USB_DEVICE );
282+ /*
283+ * This platform requires SUSPHY to be enabled here already in order to properly configure
284+ * the PHY and switch dwc3's PIPE interface to USB3 PHY. The USB2 PHY has already been
285+ * configured to the correct mode earlier.
286+ */
287+ dwc3_enable_susphy (& appledwc -> dwc , true);
288+ phy_set_mode (appledwc -> dwc .usb3_generic_phy [0 ], PHY_MODE_USB_DEVICE );
272289 ret = dwc3_gadget_init (& appledwc -> dwc );
273290 if (ret ) {
274291 dev_err (appledwc -> dev , "Failed to initialize gadget, ret=%d\n" , ret );
0 commit comments