@@ -313,63 +313,64 @@ static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg)
313313 * Do core a soft reset of the core. Be careful with this because it
314314 * resets all the internal state machines of the core.
315315 */
316- int dwc2_core_reset (struct dwc2_hsotg * hsotg )
316+ int dwc2_core_reset (struct dwc2_hsotg * hsotg , bool skip_wait )
317317{
318318 u32 greset ;
319319 int count = 0 ;
320- u32 gusbcfg ;
320+ bool wait_for_host_mode = false ;
321321
322322 dev_vdbg (hsotg -> dev , "%s()\n" , __func__ );
323323
324- /* Wait for AHB master IDLE state */
324+ /*
325+ * If the current mode is host, either due to the force mode
326+ * bit being set (which persists after core reset) or the
327+ * connector id pin, a core soft reset will temporarily reset
328+ * the mode to device. A delay from the IDDIG debounce filter
329+ * will occur before going back to host mode.
330+ *
331+ * Determine whether we will go back into host mode after a
332+ * reset and account for this delay after the reset.
333+ */
334+ if (dwc2_iddig_filter_enabled (hsotg )) {
335+ u32 gotgctl = dwc2_readl (hsotg -> regs + GOTGCTL );
336+ u32 gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
337+
338+ if (!(gotgctl & GOTGCTL_CONID_B ) ||
339+ (gusbcfg & GUSBCFG_FORCEHOSTMODE )) {
340+ wait_for_host_mode = true;
341+ }
342+ }
343+
344+ /* Core Soft Reset */
345+ greset = dwc2_readl (hsotg -> regs + GRSTCTL );
346+ greset |= GRSTCTL_CSFTRST ;
347+ dwc2_writel (greset , hsotg -> regs + GRSTCTL );
325348 do {
326- usleep_range ( 20000 , 40000 );
349+ udelay ( 1 );
327350 greset = dwc2_readl (hsotg -> regs + GRSTCTL );
328351 if (++ count > 50 ) {
329352 dev_warn (hsotg -> dev ,
330- "%s() HANG! AHB Idle GRSTCTL=%0x\n" ,
353+ "%s() HANG! Soft Reset GRSTCTL=%0x\n" ,
331354 __func__ , greset );
332355 return - EBUSY ;
333356 }
334- } while (!( greset & GRSTCTL_AHBIDLE ) );
357+ } while (greset & GRSTCTL_CSFTRST );
335358
336- /* Core Soft Reset */
359+ /* Wait for AHB master IDLE state */
337360 count = 0 ;
338- greset |= GRSTCTL_CSFTRST ;
339- dwc2_writel (greset , hsotg -> regs + GRSTCTL );
340361 do {
341- usleep_range ( 20000 , 40000 );
362+ udelay ( 1 );
342363 greset = dwc2_readl (hsotg -> regs + GRSTCTL );
343364 if (++ count > 50 ) {
344365 dev_warn (hsotg -> dev ,
345- "%s() HANG! Soft Reset GRSTCTL=%0x\n" ,
366+ "%s() HANG! AHB Idle GRSTCTL=%0x\n" ,
346367 __func__ , greset );
347368 return - EBUSY ;
348369 }
349- } while (greset & GRSTCTL_CSFTRST );
350-
351- if (hsotg -> dr_mode == USB_DR_MODE_HOST ) {
352- gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
353- gusbcfg &= ~GUSBCFG_FORCEDEVMODE ;
354- gusbcfg |= GUSBCFG_FORCEHOSTMODE ;
355- dwc2_writel (gusbcfg , hsotg -> regs + GUSBCFG );
356- } else if (hsotg -> dr_mode == USB_DR_MODE_PERIPHERAL ) {
357- gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
358- gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ;
359- gusbcfg |= GUSBCFG_FORCEDEVMODE ;
360- dwc2_writel (gusbcfg , hsotg -> regs + GUSBCFG );
361- } else if (hsotg -> dr_mode == USB_DR_MODE_OTG ) {
362- gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
363- gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ;
364- gusbcfg &= ~GUSBCFG_FORCEDEVMODE ;
365- dwc2_writel (gusbcfg , hsotg -> regs + GUSBCFG );
366- }
370+ } while (!(greset & GRSTCTL_AHBIDLE ));
367371
368- /*
369- * NOTE: This long sleep is _very_ important, otherwise the core will
370- * not stay in host mode after a connector ID change!
371- */
372- usleep_range (150000 , 200000 );
372+ if (wait_for_host_mode && !skip_wait )
373+ dwc2_wait_for_mode (hsotg , true);
373374
374375 return 0 ;
375376}
@@ -502,7 +503,7 @@ int dwc2_core_reset_and_force_dr_mode(struct dwc2_hsotg *hsotg)
502503{
503504 int retval ;
504505
505- retval = dwc2_core_reset (hsotg );
506+ retval = dwc2_core_reset (hsotg , false );
506507 if (retval )
507508 return retval ;
508509
@@ -837,6 +838,29 @@ void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
837838 hsotg -> core_params -> dma_desc_enable = val ;
838839}
839840
841+ void dwc2_set_param_dma_desc_fs_enable (struct dwc2_hsotg * hsotg , int val )
842+ {
843+ int valid = 1 ;
844+
845+ if (val > 0 && (hsotg -> core_params -> dma_enable <= 0 ||
846+ !hsotg -> hw_params .dma_desc_enable ))
847+ valid = 0 ;
848+ if (val < 0 )
849+ valid = 0 ;
850+
851+ if (!valid ) {
852+ if (val >= 0 )
853+ dev_err (hsotg -> dev ,
854+ "%d invalid for dma_desc_fs_enable parameter. Check HW configuration.\n" ,
855+ val );
856+ val = (hsotg -> core_params -> dma_enable > 0 &&
857+ hsotg -> hw_params .dma_desc_enable );
858+ }
859+
860+ hsotg -> core_params -> dma_desc_fs_enable = val ;
861+ dev_dbg (hsotg -> dev , "Setting dma_desc_fs_enable to %d\n" , val );
862+ }
863+
840864void dwc2_set_param_host_support_fs_ls_low_power (struct dwc2_hsotg * hsotg ,
841865 int val )
842866{
@@ -1368,6 +1392,7 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
13681392 dwc2_set_param_otg_cap (hsotg , params -> otg_cap );
13691393 dwc2_set_param_dma_enable (hsotg , params -> dma_enable );
13701394 dwc2_set_param_dma_desc_enable (hsotg , params -> dma_desc_enable );
1395+ dwc2_set_param_dma_desc_fs_enable (hsotg , params -> dma_desc_fs_enable );
13711396 dwc2_set_param_host_support_fs_ls_low_power (hsotg ,
13721397 params -> host_support_fs_ls_low_power );
13731398 dwc2_set_param_enable_dynamic_fifo (hsotg ,
@@ -1404,6 +1429,79 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
14041429 dwc2_set_param_hibernation (hsotg , params -> hibernation );
14051430}
14061431
1432+ /*
1433+ * Forces either host or device mode if the controller is not
1434+ * currently in that mode.
1435+ *
1436+ * Returns true if the mode was forced.
1437+ */
1438+ static bool dwc2_force_mode_if_needed (struct dwc2_hsotg * hsotg , bool host )
1439+ {
1440+ if (host && dwc2_is_host_mode (hsotg ))
1441+ return false;
1442+ else if (!host && dwc2_is_device_mode (hsotg ))
1443+ return false;
1444+
1445+ return dwc2_force_mode (hsotg , host );
1446+ }
1447+
1448+ /*
1449+ * Gets host hardware parameters. Forces host mode if not currently in
1450+ * host mode. Should be called immediately after a core soft reset in
1451+ * order to get the reset values.
1452+ */
1453+ static void dwc2_get_host_hwparams (struct dwc2_hsotg * hsotg )
1454+ {
1455+ struct dwc2_hw_params * hw = & hsotg -> hw_params ;
1456+ u32 gnptxfsiz ;
1457+ u32 hptxfsiz ;
1458+ bool forced ;
1459+
1460+ if (hsotg -> dr_mode == USB_DR_MODE_PERIPHERAL )
1461+ return ;
1462+
1463+ forced = dwc2_force_mode_if_needed (hsotg , true);
1464+
1465+ gnptxfsiz = dwc2_readl (hsotg -> regs + GNPTXFSIZ );
1466+ hptxfsiz = dwc2_readl (hsotg -> regs + HPTXFSIZ );
1467+ dev_dbg (hsotg -> dev , "gnptxfsiz=%08x\n" , gnptxfsiz );
1468+ dev_dbg (hsotg -> dev , "hptxfsiz=%08x\n" , hptxfsiz );
1469+
1470+ if (forced )
1471+ dwc2_clear_force_mode (hsotg );
1472+
1473+ hw -> host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK ) >>
1474+ FIFOSIZE_DEPTH_SHIFT ;
1475+ hw -> host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK ) >>
1476+ FIFOSIZE_DEPTH_SHIFT ;
1477+ }
1478+
1479+ /*
1480+ * Gets device hardware parameters. Forces device mode if not
1481+ * currently in device mode. Should be called immediately after a core
1482+ * soft reset in order to get the reset values.
1483+ */
1484+ static void dwc2_get_dev_hwparams (struct dwc2_hsotg * hsotg )
1485+ {
1486+ struct dwc2_hw_params * hw = & hsotg -> hw_params ;
1487+ bool forced ;
1488+ u32 gnptxfsiz ;
1489+
1490+ if (hsotg -> dr_mode == USB_DR_MODE_HOST )
1491+ return ;
1492+
1493+ forced = dwc2_force_mode_if_needed (hsotg , false);
1494+
1495+ gnptxfsiz = dwc2_readl (hsotg -> regs + GNPTXFSIZ );
1496+ dev_dbg (hsotg -> dev , "gnptxfsiz=%08x\n" , gnptxfsiz );
1497+
1498+ if (forced )
1499+ dwc2_clear_force_mode (hsotg );
1500+
1501+ hw -> dev_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK ) >>
1502+ FIFOSIZE_DEPTH_SHIFT ;
1503+ }
1504+
14071505/**
14081506 * During device initialization, read various hardware configuration
14091507 * registers and interpret the contents.
@@ -1413,8 +1511,7 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
14131511 struct dwc2_hw_params * hw = & hsotg -> hw_params ;
14141512 unsigned width ;
14151513 u32 hwcfg1 , hwcfg2 , hwcfg3 , hwcfg4 ;
1416- u32 hptxfsiz , grxfsiz , gnptxfsiz ;
1417- u32 gusbcfg ;
1514+ u32 grxfsiz ;
14181515
14191516 /*
14201517 * Attempt to ensure this device is really a DWC_otg Controller.
@@ -1446,20 +1543,16 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
14461543 dev_dbg (hsotg -> dev , "hwcfg4=%08x\n" , hwcfg4 );
14471544 dev_dbg (hsotg -> dev , "grxfsiz=%08x\n" , grxfsiz );
14481545
1449- /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */
1450- gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
1451- gusbcfg |= GUSBCFG_FORCEHOSTMODE ;
1452- dwc2_writel (gusbcfg , hsotg -> regs + GUSBCFG );
1453- usleep_range (100000 , 150000 );
1546+ /*
1547+ * Host specific hardware parameters. Reading these parameters
1548+ * requires the controller to be in host mode. The mode will
1549+ * be forced, if necessary, to read these values.
1550+ */
1551+ dwc2_get_host_hwparams (hsotg );
1552+ dwc2_get_dev_hwparams (hsotg );
14541553
1455- gnptxfsiz = dwc2_readl (hsotg -> regs + GNPTXFSIZ );
1456- hptxfsiz = dwc2_readl (hsotg -> regs + HPTXFSIZ );
1457- dev_dbg (hsotg -> dev , "gnptxfsiz=%08x\n" , gnptxfsiz );
1458- dev_dbg (hsotg -> dev , "hptxfsiz=%08x\n" , hptxfsiz );
1459- gusbcfg = dwc2_readl (hsotg -> regs + GUSBCFG );
1460- gusbcfg &= ~GUSBCFG_FORCEHOSTMODE ;
1461- dwc2_writel (gusbcfg , hsotg -> regs + GUSBCFG );
1462- usleep_range (100000 , 150000 );
1554+ /* hwcfg1 */
1555+ hw -> dev_ep_dirs = hwcfg1 ;
14631556
14641557 /* hwcfg2 */
14651558 hw -> op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK ) >>
@@ -1489,13 +1582,6 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
14891582 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK ) >>
14901583 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT ;
14911584 hw -> max_transfer_size = (1 << (width + 11 )) - 1 ;
1492- /*
1493- * Clip max_transfer_size to 65535. dwc2_hc_setup_align_buf() allocates
1494- * coherent buffers with this size, and if it's too large we can
1495- * exhaust the coherent DMA pool.
1496- */
1497- if (hw -> max_transfer_size > 65535 )
1498- hw -> max_transfer_size = 65535 ;
14991585 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK ) >>
15001586 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT ;
15011587 hw -> max_packet_count = (1 << (width + 4 )) - 1 ;
@@ -1515,10 +1601,6 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
15151601 /* fifo sizes */
15161602 hw -> host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK ) >>
15171603 GRXFSIZ_DEPTH_SHIFT ;
1518- hw -> host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK ) >>
1519- FIFOSIZE_DEPTH_SHIFT ;
1520- hw -> host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK ) >>
1521- FIFOSIZE_DEPTH_SHIFT ;
15221604
15231605 dev_dbg (hsotg -> dev , "Detected values from hardware:\n" );
15241606 dev_dbg (hsotg -> dev , " op_mode=%d\n" ,
0 commit comments