2 * core.c - DesignWare HS OTG Controller common routines
4 * Copyright (C) 2004-2013 Synopsys, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The names of the above-listed copyright holders may not be used
16 * to endorse or promote products derived from this software without
17 * specific prior written permission.
19 * ALTERNATIVELY, this software may be distributed under the terms of the
20 * GNU General Public License ("GPL") as published by the Free Software
21 * Foundation; either version 2 of the License, or (at your option) any
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * The Core code provides basic services for accessing and managing the
39 * DWC_otg hardware. These services are used by both the Host Controller
40 * Driver and the Peripheral Controller Driver.
42 #include <linux/kernel.h>
43 #include <linux/module.h>
44 #include <linux/moduleparam.h>
45 #include <linux/spinlock.h>
46 #include <linux/interrupt.h>
47 #include <linux/dma-mapping.h>
48 #include <linux/delay.h>
50 #include <linux/slab.h>
51 #include <linux/usb.h>
53 #include <linux/usb/hcd.h>
54 #include <linux/usb/ch11.h>
59 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
61 * dwc2_backup_host_registers() - Backup controller host registers.
62 * When suspending usb bus, registers needs to be backuped
63 * if controller power is disabled once suspended.
65 * @hsotg: Programming view of the DWC_otg controller
67 static int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
69 struct dwc2_hregs_backup *hr;
72 dev_dbg(hsotg->dev, "%s\n", __func__);
74 /* Backup Host regs */
75 hr = &hsotg->hr_backup;
76 hr->hcfg = readl(hsotg->regs + HCFG);
77 hr->haintmsk = readl(hsotg->regs + HAINTMSK);
78 for (i = 0; i < hsotg->core_params->host_channels; ++i)
79 hr->hcintmsk[i] = readl(hsotg->regs + HCINTMSK(i));
81 hr->hprt0 = readl(hsotg->regs + HPRT0);
82 hr->hfir = readl(hsotg->regs + HFIR);
89 * dwc2_restore_host_registers() - Restore controller host registers.
90 * When resuming usb bus, device registers needs to be restored
91 * if controller power were disabled.
93 * @hsotg: Programming view of the DWC_otg controller
95 static int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
97 struct dwc2_hregs_backup *hr;
100 dev_dbg(hsotg->dev, "%s\n", __func__);
102 /* Restore host regs */
103 hr = &hsotg->hr_backup;
105 dev_err(hsotg->dev, "%s: no host registers to restore\n",
111 writel(hr->hcfg, hsotg->regs + HCFG);
112 writel(hr->haintmsk, hsotg->regs + HAINTMSK);
114 for (i = 0; i < hsotg->core_params->host_channels; ++i)
115 writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i));
117 writel(hr->hprt0, hsotg->regs + HPRT0);
118 writel(hr->hfir, hsotg->regs + HFIR);
123 static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
126 static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
130 #if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
131 IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
133 * dwc2_backup_device_registers() - Backup controller device registers.
134 * When suspending usb bus, registers needs to be backuped
135 * if controller power is disabled once suspended.
137 * @hsotg: Programming view of the DWC_otg controller
139 static int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
141 struct dwc2_dregs_backup *dr;
144 dev_dbg(hsotg->dev, "%s\n", __func__);
146 /* Backup dev regs */
147 dr = &hsotg->dr_backup;
149 dr->dcfg = readl(hsotg->regs + DCFG);
150 dr->dctl = readl(hsotg->regs + DCTL);
151 dr->daintmsk = readl(hsotg->regs + DAINTMSK);
152 dr->diepmsk = readl(hsotg->regs + DIEPMSK);
153 dr->doepmsk = readl(hsotg->regs + DOEPMSK);
155 for (i = 0; i < hsotg->num_of_eps; i++) {
157 dr->diepctl[i] = readl(hsotg->regs + DIEPCTL(i));
159 /* Ensure DATA PID is correctly configured */
160 if (dr->diepctl[i] & DXEPCTL_DPID)
161 dr->diepctl[i] |= DXEPCTL_SETD1PID;
163 dr->diepctl[i] |= DXEPCTL_SETD0PID;
165 dr->dieptsiz[i] = readl(hsotg->regs + DIEPTSIZ(i));
166 dr->diepdma[i] = readl(hsotg->regs + DIEPDMA(i));
169 dr->doepctl[i] = readl(hsotg->regs + DOEPCTL(i));
171 /* Ensure DATA PID is correctly configured */
172 if (dr->doepctl[i] & DXEPCTL_DPID)
173 dr->doepctl[i] |= DXEPCTL_SETD1PID;
175 dr->doepctl[i] |= DXEPCTL_SETD0PID;
177 dr->doeptsiz[i] = readl(hsotg->regs + DOEPTSIZ(i));
178 dr->doepdma[i] = readl(hsotg->regs + DOEPDMA(i));
185 * dwc2_restore_device_registers() - Restore controller device registers.
186 * When resuming usb bus, device registers needs to be restored
187 * if controller power were disabled.
189 * @hsotg: Programming view of the DWC_otg controller
191 static int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
193 struct dwc2_dregs_backup *dr;
197 dev_dbg(hsotg->dev, "%s\n", __func__);
199 /* Restore dev regs */
200 dr = &hsotg->dr_backup;
202 dev_err(hsotg->dev, "%s: no device registers to restore\n",
208 writel(dr->dcfg, hsotg->regs + DCFG);
209 writel(dr->dctl, hsotg->regs + DCTL);
210 writel(dr->daintmsk, hsotg->regs + DAINTMSK);
211 writel(dr->diepmsk, hsotg->regs + DIEPMSK);
212 writel(dr->doepmsk, hsotg->regs + DOEPMSK);
214 for (i = 0; i < hsotg->num_of_eps; i++) {
216 writel(dr->diepctl[i], hsotg->regs + DIEPCTL(i));
217 writel(dr->dieptsiz[i], hsotg->regs + DIEPTSIZ(i));
218 writel(dr->diepdma[i], hsotg->regs + DIEPDMA(i));
220 /* Restore OUT EPs */
221 writel(dr->doepctl[i], hsotg->regs + DOEPCTL(i));
222 writel(dr->doeptsiz[i], hsotg->regs + DOEPTSIZ(i));
223 writel(dr->doepdma[i], hsotg->regs + DOEPDMA(i));
226 /* Set the Power-On Programming done bit */
227 dctl = readl(hsotg->regs + DCTL);
228 dctl |= DCTL_PWRONPRGDONE;
229 writel(dctl, hsotg->regs + DCTL);
234 static inline int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
237 static inline int dwc2_restore_device_registers(struct dwc2_hsotg *hsotg)
242 * dwc2_backup_global_registers() - Backup global controller registers.
243 * When suspending usb bus, registers needs to be backuped
244 * if controller power is disabled once suspended.
246 * @hsotg: Programming view of the DWC_otg controller
248 static int dwc2_backup_global_registers(struct dwc2_hsotg *hsotg)
250 struct dwc2_gregs_backup *gr;
253 /* Backup global regs */
254 gr = &hsotg->gr_backup;
256 gr->gotgctl = readl(hsotg->regs + GOTGCTL);
257 gr->gintmsk = readl(hsotg->regs + GINTMSK);
258 gr->gahbcfg = readl(hsotg->regs + GAHBCFG);
259 gr->gusbcfg = readl(hsotg->regs + GUSBCFG);
260 gr->grxfsiz = readl(hsotg->regs + GRXFSIZ);
261 gr->gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ);
262 gr->hptxfsiz = readl(hsotg->regs + HPTXFSIZ);
263 gr->gdfifocfg = readl(hsotg->regs + GDFIFOCFG);
264 for (i = 0; i < MAX_EPS_CHANNELS; i++)
265 gr->dtxfsiz[i] = readl(hsotg->regs + DPTXFSIZN(i));
272 * dwc2_restore_global_registers() - Restore controller global registers.
273 * When resuming usb bus, device registers needs to be restored
274 * if controller power were disabled.
276 * @hsotg: Programming view of the DWC_otg controller
278 static int dwc2_restore_global_registers(struct dwc2_hsotg *hsotg)
280 struct dwc2_gregs_backup *gr;
283 dev_dbg(hsotg->dev, "%s\n", __func__);
285 /* Restore global regs */
286 gr = &hsotg->gr_backup;
288 dev_err(hsotg->dev, "%s: no global registers to restore\n",
294 writel(0xffffffff, hsotg->regs + GINTSTS);
295 writel(gr->gotgctl, hsotg->regs + GOTGCTL);
296 writel(gr->gintmsk, hsotg->regs + GINTMSK);
297 writel(gr->gusbcfg, hsotg->regs + GUSBCFG);
298 writel(gr->gahbcfg, hsotg->regs + GAHBCFG);
299 writel(gr->grxfsiz, hsotg->regs + GRXFSIZ);
300 writel(gr->gnptxfsiz, hsotg->regs + GNPTXFSIZ);
301 writel(gr->hptxfsiz, hsotg->regs + HPTXFSIZ);
302 writel(gr->gdfifocfg, hsotg->regs + GDFIFOCFG);
303 for (i = 0; i < MAX_EPS_CHANNELS; i++)
304 writel(gr->dtxfsiz[i], hsotg->regs + DPTXFSIZN(i));
310 * dwc2_exit_hibernation() - Exit controller from Partial Power Down.
312 * @hsotg: Programming view of the DWC_otg controller
313 * @restore: Controller registers need to be restored
315 int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool restore)
320 if (!hsotg->core_params->hibernation)
323 pcgcctl = readl(hsotg->regs + PCGCTL);
324 pcgcctl &= ~PCGCTL_STOPPCLK;
325 writel(pcgcctl, hsotg->regs + PCGCTL);
327 pcgcctl = readl(hsotg->regs + PCGCTL);
328 pcgcctl &= ~PCGCTL_PWRCLMP;
329 writel(pcgcctl, hsotg->regs + PCGCTL);
331 pcgcctl = readl(hsotg->regs + PCGCTL);
332 pcgcctl &= ~PCGCTL_RSTPDWNMODULE;
333 writel(pcgcctl, hsotg->regs + PCGCTL);
337 ret = dwc2_restore_global_registers(hsotg);
339 dev_err(hsotg->dev, "%s: failed to restore registers\n",
343 if (dwc2_is_host_mode(hsotg)) {
344 ret = dwc2_restore_host_registers(hsotg);
346 dev_err(hsotg->dev, "%s: failed to restore host registers\n",
351 ret = dwc2_restore_device_registers(hsotg);
353 dev_err(hsotg->dev, "%s: failed to restore device registers\n",
364 * dwc2_enter_hibernation() - Put controller in Partial Power Down.
366 * @hsotg: Programming view of the DWC_otg controller
368 int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
373 if (!hsotg->core_params->hibernation)
376 /* Backup all registers */
377 ret = dwc2_backup_global_registers(hsotg);
379 dev_err(hsotg->dev, "%s: failed to backup global registers\n",
384 if (dwc2_is_host_mode(hsotg)) {
385 ret = dwc2_backup_host_registers(hsotg);
387 dev_err(hsotg->dev, "%s: failed to backup host registers\n",
392 ret = dwc2_backup_device_registers(hsotg);
394 dev_err(hsotg->dev, "%s: failed to backup device registers\n",
400 /* Put the controller in low power state */
401 pcgcctl = readl(hsotg->regs + PCGCTL);
403 pcgcctl |= PCGCTL_PWRCLMP;
404 writel(pcgcctl, hsotg->regs + PCGCTL);
407 pcgcctl |= PCGCTL_RSTPDWNMODULE;
408 writel(pcgcctl, hsotg->regs + PCGCTL);
411 pcgcctl |= PCGCTL_STOPPCLK;
412 writel(pcgcctl, hsotg->regs + PCGCTL);
418 * dwc2_enable_common_interrupts() - Initializes the commmon interrupts,
419 * used in both device and host modes
421 * @hsotg: Programming view of the DWC_otg controller
423 static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)
427 /* Clear any pending OTG Interrupts */
428 writel(0xffffffff, hsotg->regs + GOTGINT);
430 /* Clear any pending interrupts */
431 writel(0xffffffff, hsotg->regs + GINTSTS);
433 /* Enable the interrupts in the GINTMSK */
434 intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT;
436 if (hsotg->core_params->dma_enable <= 0)
437 intmsk |= GINTSTS_RXFLVL;
438 if (hsotg->core_params->external_id_pin_ctl <= 0)
439 intmsk |= GINTSTS_CONIDSTSCHNG;
441 intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP |
444 writel(intmsk, hsotg->regs + GINTMSK);
448 * Initializes the FSLSPClkSel field of the HCFG register depending on the
451 static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
455 if ((hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
456 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
457 hsotg->core_params->ulpi_fs_ls > 0) ||
458 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
460 val = HCFG_FSLSPCLKSEL_48_MHZ;
462 /* High speed PHY running at full speed or high speed */
463 val = HCFG_FSLSPCLKSEL_30_60_MHZ;
466 dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val);
467 hcfg = readl(hsotg->regs + HCFG);
468 hcfg &= ~HCFG_FSLSPCLKSEL_MASK;
469 hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT;
470 writel(hcfg, hsotg->regs + HCFG);
474 * Do core a soft reset of the core. Be careful with this because it
475 * resets all the internal state machines of the core.
477 static int dwc2_core_reset(struct dwc2_hsotg *hsotg)
483 dev_vdbg(hsotg->dev, "%s()\n", __func__);
485 /* Wait for AHB master IDLE state */
487 usleep_range(20000, 40000);
488 greset = readl(hsotg->regs + GRSTCTL);
491 "%s() HANG! AHB Idle GRSTCTL=%0x\n",
495 } while (!(greset & GRSTCTL_AHBIDLE));
497 /* Core Soft Reset */
499 greset |= GRSTCTL_CSFTRST;
500 writel(greset, hsotg->regs + GRSTCTL);
502 usleep_range(20000, 40000);
503 greset = readl(hsotg->regs + GRSTCTL);
506 "%s() HANG! Soft Reset GRSTCTL=%0x\n",
510 } while (greset & GRSTCTL_CSFTRST);
512 if (hsotg->dr_mode == USB_DR_MODE_HOST) {
513 gusbcfg = readl(hsotg->regs + GUSBCFG);
514 gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
515 gusbcfg |= GUSBCFG_FORCEHOSTMODE;
516 writel(gusbcfg, hsotg->regs + GUSBCFG);
517 } else if (hsotg->dr_mode == USB_DR_MODE_PERIPHERAL) {
518 gusbcfg = readl(hsotg->regs + GUSBCFG);
519 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
520 gusbcfg |= GUSBCFG_FORCEDEVMODE;
521 writel(gusbcfg, hsotg->regs + GUSBCFG);
522 } else if (hsotg->dr_mode == USB_DR_MODE_OTG) {
523 gusbcfg = readl(hsotg->regs + GUSBCFG);
524 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
525 gusbcfg &= ~GUSBCFG_FORCEDEVMODE;
526 writel(gusbcfg, hsotg->regs + GUSBCFG);
530 * NOTE: This long sleep is _very_ important, otherwise the core will
531 * not stay in host mode after a connector ID change!
533 usleep_range(150000, 200000);
538 static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
544 * core_init() is now called on every switch so only call the
545 * following for the first time through
548 dev_dbg(hsotg->dev, "FS PHY selected\n");
549 usbcfg = readl(hsotg->regs + GUSBCFG);
550 usbcfg |= GUSBCFG_PHYSEL;
551 writel(usbcfg, hsotg->regs + GUSBCFG);
553 /* Reset after a PHY select */
554 retval = dwc2_core_reset(hsotg);
556 dev_err(hsotg->dev, "%s() Reset failed, aborting",
563 * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
564 * do this on HNP Dev/Host mode switches (done in dev_init and
567 if (dwc2_is_host_mode(hsotg))
568 dwc2_init_fs_ls_pclk_sel(hsotg);
570 if (hsotg->core_params->i2c_enable > 0) {
571 dev_dbg(hsotg->dev, "FS PHY enabling I2C\n");
573 /* Program GUSBCFG.OtgUtmiFsSel to I2C */
574 usbcfg = readl(hsotg->regs + GUSBCFG);
575 usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL;
576 writel(usbcfg, hsotg->regs + GUSBCFG);
578 /* Program GI2CCTL.I2CEn */
579 i2cctl = readl(hsotg->regs + GI2CCTL);
580 i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK;
581 i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT;
582 i2cctl &= ~GI2CCTL_I2CEN;
583 writel(i2cctl, hsotg->regs + GI2CCTL);
584 i2cctl |= GI2CCTL_I2CEN;
585 writel(i2cctl, hsotg->regs + GI2CCTL);
591 static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
599 usbcfg = readl(hsotg->regs + GUSBCFG);
602 * HS PHY parameters. These parameters are preserved during soft reset
603 * so only program the first time. Do a soft reset immediately after
606 switch (hsotg->core_params->phy_type) {
607 case DWC2_PHY_TYPE_PARAM_ULPI:
609 dev_dbg(hsotg->dev, "HS ULPI PHY selected\n");
610 usbcfg |= GUSBCFG_ULPI_UTMI_SEL;
611 usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL);
612 if (hsotg->core_params->phy_ulpi_ddr > 0)
613 usbcfg |= GUSBCFG_DDRSEL;
615 case DWC2_PHY_TYPE_PARAM_UTMI:
616 /* UTMI+ interface */
617 dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n");
618 usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16);
619 if (hsotg->core_params->phy_utmi_width == 16)
620 usbcfg |= GUSBCFG_PHYIF16;
623 dev_err(hsotg->dev, "FS PHY selected at HS!\n");
627 writel(usbcfg, hsotg->regs + GUSBCFG);
629 /* Reset after setting the PHY parameters */
630 retval = dwc2_core_reset(hsotg);
632 dev_err(hsotg->dev, "%s() Reset failed, aborting",
640 static int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
645 if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL &&
646 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
647 /* If FS mode with FS PHY */
648 retval = dwc2_fs_phy_init(hsotg, select_phy);
653 retval = dwc2_hs_phy_init(hsotg, select_phy);
658 if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
659 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
660 hsotg->core_params->ulpi_fs_ls > 0) {
661 dev_dbg(hsotg->dev, "Setting ULPI FSLS\n");
662 usbcfg = readl(hsotg->regs + GUSBCFG);
663 usbcfg |= GUSBCFG_ULPI_FS_LS;
664 usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M;
665 writel(usbcfg, hsotg->regs + GUSBCFG);
667 usbcfg = readl(hsotg->regs + GUSBCFG);
668 usbcfg &= ~GUSBCFG_ULPI_FS_LS;
669 usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M;
670 writel(usbcfg, hsotg->regs + GUSBCFG);
676 static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
678 u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
680 switch (hsotg->hw_params.arch) {
681 case GHWCFG2_EXT_DMA_ARCH:
682 dev_err(hsotg->dev, "External DMA Mode not supported\n");
685 case GHWCFG2_INT_DMA_ARCH:
686 dev_dbg(hsotg->dev, "Internal DMA Mode\n");
687 if (hsotg->core_params->ahbcfg != -1) {
688 ahbcfg &= GAHBCFG_CTRL_MASK;
689 ahbcfg |= hsotg->core_params->ahbcfg &
694 case GHWCFG2_SLAVE_ONLY_ARCH:
696 dev_dbg(hsotg->dev, "Slave Only Mode\n");
700 dev_dbg(hsotg->dev, "dma_enable:%d dma_desc_enable:%d\n",
701 hsotg->core_params->dma_enable,
702 hsotg->core_params->dma_desc_enable);
704 if (hsotg->core_params->dma_enable > 0) {
705 if (hsotg->core_params->dma_desc_enable > 0)
706 dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n");
708 dev_dbg(hsotg->dev, "Using Buffer DMA mode\n");
710 dev_dbg(hsotg->dev, "Using Slave mode\n");
711 hsotg->core_params->dma_desc_enable = 0;
714 if (hsotg->core_params->dma_enable > 0)
715 ahbcfg |= GAHBCFG_DMA_EN;
717 writel(ahbcfg, hsotg->regs + GAHBCFG);
722 static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
726 usbcfg = readl(hsotg->regs + GUSBCFG);
727 usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP);
729 switch (hsotg->hw_params.op_mode) {
730 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
731 if (hsotg->core_params->otg_cap ==
732 DWC2_CAP_PARAM_HNP_SRP_CAPABLE)
733 usbcfg |= GUSBCFG_HNPCAP;
734 if (hsotg->core_params->otg_cap !=
735 DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
736 usbcfg |= GUSBCFG_SRPCAP;
739 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
740 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
741 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
742 if (hsotg->core_params->otg_cap !=
743 DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE)
744 usbcfg |= GUSBCFG_SRPCAP;
747 case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE:
748 case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE:
749 case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST:
754 writel(usbcfg, hsotg->regs + GUSBCFG);
758 * dwc2_core_init() - Initializes the DWC_otg controller registers and
759 * prepares the core for device mode or host mode operation
761 * @hsotg: Programming view of the DWC_otg controller
762 * @select_phy: If true then also set the Phy type
763 * @irq: If >= 0, the irq to register
765 int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq)
770 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
772 usbcfg = readl(hsotg->regs + GUSBCFG);
774 /* Set ULPI External VBUS bit if needed */
775 usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV;
776 if (hsotg->core_params->phy_ulpi_ext_vbus ==
777 DWC2_PHY_ULPI_EXTERNAL_VBUS)
778 usbcfg |= GUSBCFG_ULPI_EXT_VBUS_DRV;
780 /* Set external TS Dline pulsing bit if needed */
781 usbcfg &= ~GUSBCFG_TERMSELDLPULSE;
782 if (hsotg->core_params->ts_dline > 0)
783 usbcfg |= GUSBCFG_TERMSELDLPULSE;
785 writel(usbcfg, hsotg->regs + GUSBCFG);
787 /* Reset the Controller */
788 retval = dwc2_core_reset(hsotg);
790 dev_err(hsotg->dev, "%s(): Reset failed, aborting\n",
796 * This needs to happen in FS mode before any other programming occurs
798 retval = dwc2_phy_init(hsotg, select_phy);
802 /* Program the GAHBCFG Register */
803 retval = dwc2_gahbcfg_init(hsotg);
807 /* Program the GUSBCFG register */
808 dwc2_gusbcfg_init(hsotg);
810 /* Program the GOTGCTL register */
811 otgctl = readl(hsotg->regs + GOTGCTL);
812 otgctl &= ~GOTGCTL_OTGVER;
813 if (hsotg->core_params->otg_ver > 0)
814 otgctl |= GOTGCTL_OTGVER;
815 writel(otgctl, hsotg->regs + GOTGCTL);
816 dev_dbg(hsotg->dev, "OTG VER PARAM: %d\n", hsotg->core_params->otg_ver);
818 /* Clear the SRP success bit for FS-I2c */
819 hsotg->srp_success = 0;
821 /* Enable common interrupts */
822 dwc2_enable_common_interrupts(hsotg);
825 * Do device or host initialization based on mode during PCD and
828 if (dwc2_is_host_mode(hsotg)) {
829 dev_dbg(hsotg->dev, "Host Mode\n");
830 hsotg->op_state = OTG_STATE_A_HOST;
832 dev_dbg(hsotg->dev, "Device Mode\n");
833 hsotg->op_state = OTG_STATE_B_PERIPHERAL;
840 * dwc2_enable_host_interrupts() - Enables the Host mode interrupts
842 * @hsotg: Programming view of DWC_otg controller
844 void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg)
848 dev_dbg(hsotg->dev, "%s()\n", __func__);
850 /* Disable all interrupts */
851 writel(0, hsotg->regs + GINTMSK);
852 writel(0, hsotg->regs + HAINTMSK);
854 /* Enable the common interrupts */
855 dwc2_enable_common_interrupts(hsotg);
857 /* Enable host mode interrupts without disturbing common interrupts */
858 intmsk = readl(hsotg->regs + GINTMSK);
859 intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT;
860 writel(intmsk, hsotg->regs + GINTMSK);
864 * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts
866 * @hsotg: Programming view of DWC_otg controller
868 void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
870 u32 intmsk = readl(hsotg->regs + GINTMSK);
872 /* Disable host mode interrupts without disturbing common interrupts */
873 intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT |
874 GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP);
875 writel(intmsk, hsotg->regs + GINTMSK);
879 * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
880 * For system that have a total fifo depth that is smaller than the default
883 * @hsotg: Programming view of DWC_otg controller
885 static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg)
887 struct dwc2_core_params *params = hsotg->core_params;
888 struct dwc2_hw_params *hw = &hsotg->hw_params;
889 u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
891 total_fifo_size = hw->total_fifo_size;
892 rxfsiz = params->host_rx_fifo_size;
893 nptxfsiz = params->host_nperio_tx_fifo_size;
894 ptxfsiz = params->host_perio_tx_fifo_size;
897 * Will use Method 2 defined in the DWC2 spec: minimum FIFO depth
898 * allocation with support for high bandwidth endpoints. Synopsys
899 * defines MPS(Max Packet size) for a periodic EP=1024, and for
900 * non-periodic as 512.
902 if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) {
904 * For Buffer DMA mode/Scatter Gather DMA mode
905 * 2 * ((Largest Packet size / 4) + 1 + 1) + n
906 * with n = number of host channel.
907 * 2 * ((1024/4) + 2) = 516
909 rxfsiz = 516 + hw->host_channels;
912 * min non-periodic tx fifo depth
913 * 2 * (largest non-periodic USB packet used / 4)
919 * min periodic tx fifo depth
920 * (largest packet size*MC)/4
925 params->host_rx_fifo_size = rxfsiz;
926 params->host_nperio_tx_fifo_size = nptxfsiz;
927 params->host_perio_tx_fifo_size = ptxfsiz;
931 * If the summation of RX, NPTX and PTX fifo sizes is still
932 * bigger than the total_fifo_size, then we have a problem.
934 * We won't be able to allocate as many endpoints. Right now,
935 * we're just printing an error message, but ideally this FIFO
936 * allocation algorithm would be improved in the future.
938 * FIXME improve this FIFO allocation algorithm.
940 if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)))
941 dev_err(hsotg->dev, "invalid fifo sizes\n");
944 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
946 struct dwc2_core_params *params = hsotg->core_params;
947 u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz;
949 if (!params->enable_dynamic_fifo)
952 dwc2_calculate_dynamic_fifo(hsotg);
955 grxfsiz = readl(hsotg->regs + GRXFSIZ);
956 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz);
957 grxfsiz &= ~GRXFSIZ_DEPTH_MASK;
958 grxfsiz |= params->host_rx_fifo_size <<
959 GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK;
960 writel(grxfsiz, hsotg->regs + GRXFSIZ);
961 dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ));
963 /* Non-periodic Tx FIFO */
964 dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n",
965 readl(hsotg->regs + GNPTXFSIZ));
966 nptxfsiz = params->host_nperio_tx_fifo_size <<
967 FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
968 nptxfsiz |= params->host_rx_fifo_size <<
969 FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
970 writel(nptxfsiz, hsotg->regs + GNPTXFSIZ);
971 dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n",
972 readl(hsotg->regs + GNPTXFSIZ));
974 /* Periodic Tx FIFO */
975 dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n",
976 readl(hsotg->regs + HPTXFSIZ));
977 hptxfsiz = params->host_perio_tx_fifo_size <<
978 FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK;
979 hptxfsiz |= (params->host_rx_fifo_size +
980 params->host_nperio_tx_fifo_size) <<
981 FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK;
982 writel(hptxfsiz, hsotg->regs + HPTXFSIZ);
983 dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n",
984 readl(hsotg->regs + HPTXFSIZ));
986 if (hsotg->core_params->en_multiple_tx_fifo > 0 &&
987 hsotg->hw_params.snpsid <= DWC2_CORE_REV_2_94a) {
989 * Global DFIFOCFG calculation for Host mode -
990 * include RxFIFO, NPTXFIFO and HPTXFIFO
992 dfifocfg = readl(hsotg->regs + GDFIFOCFG);
993 dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK;
994 dfifocfg |= (params->host_rx_fifo_size +
995 params->host_nperio_tx_fifo_size +
996 params->host_perio_tx_fifo_size) <<
997 GDFIFOCFG_EPINFOBASE_SHIFT &
998 GDFIFOCFG_EPINFOBASE_MASK;
999 writel(dfifocfg, hsotg->regs + GDFIFOCFG);
1004 * dwc2_core_host_init() - Initializes the DWC_otg controller registers for
1007 * @hsotg: Programming view of DWC_otg controller
1009 * This function flushes the Tx and Rx FIFOs and flushes any entries in the
1010 * request queues. Host channels are reset to ensure that they are ready for
1011 * performing transfers.
1013 void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
1015 u32 hcfg, hfir, otgctl;
1017 dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg);
1019 /* Restart the Phy Clock */
1020 writel(0, hsotg->regs + PCGCTL);
1022 /* Initialize Host Configuration Register */
1023 dwc2_init_fs_ls_pclk_sel(hsotg);
1024 if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL) {
1025 hcfg = readl(hsotg->regs + HCFG);
1026 hcfg |= HCFG_FSLSSUPP;
1027 writel(hcfg, hsotg->regs + HCFG);
1031 * This bit allows dynamic reloading of the HFIR register during
1032 * runtime. This bit needs to be programmed during initial configuration
1033 * and its value must not be changed during runtime.
1035 if (hsotg->core_params->reload_ctl > 0) {
1036 hfir = readl(hsotg->regs + HFIR);
1037 hfir |= HFIR_RLDCTRL;
1038 writel(hfir, hsotg->regs + HFIR);
1041 if (hsotg->core_params->dma_desc_enable > 0) {
1042 u32 op_mode = hsotg->hw_params.op_mode;
1043 if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a ||
1044 !hsotg->hw_params.dma_desc_enable ||
1045 op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE ||
1046 op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE ||
1047 op_mode == GHWCFG2_OP_MODE_UNDEFINED) {
1049 "Hardware does not support descriptor DMA mode -\n");
1051 "falling back to buffer DMA mode.\n");
1052 hsotg->core_params->dma_desc_enable = 0;
1054 hcfg = readl(hsotg->regs + HCFG);
1055 hcfg |= HCFG_DESCDMA;
1056 writel(hcfg, hsotg->regs + HCFG);
1060 /* Configure data FIFO sizes */
1061 dwc2_config_fifos(hsotg);
1063 /* TODO - check this */
1064 /* Clear Host Set HNP Enable in the OTG Control Register */
1065 otgctl = readl(hsotg->regs + GOTGCTL);
1066 otgctl &= ~GOTGCTL_HSTSETHNPEN;
1067 writel(otgctl, hsotg->regs + GOTGCTL);
1069 /* Make sure the FIFOs are flushed */
1070 dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */);
1071 dwc2_flush_rx_fifo(hsotg);
1073 /* Clear Host Set HNP Enable in the OTG Control Register */
1074 otgctl = readl(hsotg->regs + GOTGCTL);
1075 otgctl &= ~GOTGCTL_HSTSETHNPEN;
1076 writel(otgctl, hsotg->regs + GOTGCTL);
1078 if (hsotg->core_params->dma_desc_enable <= 0) {
1079 int num_channels, i;
1082 /* Flush out any leftover queued requests */
1083 num_channels = hsotg->core_params->host_channels;
1084 for (i = 0; i < num_channels; i++) {
1085 hcchar = readl(hsotg->regs + HCCHAR(i));
1086 hcchar &= ~HCCHAR_CHENA;
1087 hcchar |= HCCHAR_CHDIS;
1088 hcchar &= ~HCCHAR_EPDIR;
1089 writel(hcchar, hsotg->regs + HCCHAR(i));
1092 /* Halt all channels to put them into a known state */
1093 for (i = 0; i < num_channels; i++) {
1096 hcchar = readl(hsotg->regs + HCCHAR(i));
1097 hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS;
1098 hcchar &= ~HCCHAR_EPDIR;
1099 writel(hcchar, hsotg->regs + HCCHAR(i));
1100 dev_dbg(hsotg->dev, "%s: Halt channel %d\n",
1103 hcchar = readl(hsotg->regs + HCCHAR(i));
1104 if (++count > 1000) {
1106 "Unable to clear enable on channel %d\n",
1111 } while (hcchar & HCCHAR_CHENA);
1115 /* Turn on the vbus power */
1116 dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state);
1117 if (hsotg->op_state == OTG_STATE_A_HOST) {
1118 u32 hprt0 = dwc2_read_hprt0(hsotg);
1120 dev_dbg(hsotg->dev, "Init: Power Port (%d)\n",
1121 !!(hprt0 & HPRT0_PWR));
1122 if (!(hprt0 & HPRT0_PWR)) {
1124 writel(hprt0, hsotg->regs + HPRT0);
1128 dwc2_enable_host_interrupts(hsotg);
1131 static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg,
1132 struct dwc2_host_chan *chan)
1134 u32 hcintmsk = HCINTMSK_CHHLTD;
1136 switch (chan->ep_type) {
1137 case USB_ENDPOINT_XFER_CONTROL:
1138 case USB_ENDPOINT_XFER_BULK:
1139 dev_vdbg(hsotg->dev, "control/bulk\n");
1140 hcintmsk |= HCINTMSK_XFERCOMPL;
1141 hcintmsk |= HCINTMSK_STALL;
1142 hcintmsk |= HCINTMSK_XACTERR;
1143 hcintmsk |= HCINTMSK_DATATGLERR;
1144 if (chan->ep_is_in) {
1145 hcintmsk |= HCINTMSK_BBLERR;
1147 hcintmsk |= HCINTMSK_NAK;
1148 hcintmsk |= HCINTMSK_NYET;
1150 hcintmsk |= HCINTMSK_ACK;
1153 if (chan->do_split) {
1154 hcintmsk |= HCINTMSK_NAK;
1155 if (chan->complete_split)
1156 hcintmsk |= HCINTMSK_NYET;
1158 hcintmsk |= HCINTMSK_ACK;
1161 if (chan->error_state)
1162 hcintmsk |= HCINTMSK_ACK;
1165 case USB_ENDPOINT_XFER_INT:
1167 dev_vdbg(hsotg->dev, "intr\n");
1168 hcintmsk |= HCINTMSK_XFERCOMPL;
1169 hcintmsk |= HCINTMSK_NAK;
1170 hcintmsk |= HCINTMSK_STALL;
1171 hcintmsk |= HCINTMSK_XACTERR;
1172 hcintmsk |= HCINTMSK_DATATGLERR;
1173 hcintmsk |= HCINTMSK_FRMOVRUN;
1176 hcintmsk |= HCINTMSK_BBLERR;
1177 if (chan->error_state)
1178 hcintmsk |= HCINTMSK_ACK;
1179 if (chan->do_split) {
1180 if (chan->complete_split)
1181 hcintmsk |= HCINTMSK_NYET;
1183 hcintmsk |= HCINTMSK_ACK;
1187 case USB_ENDPOINT_XFER_ISOC:
1189 dev_vdbg(hsotg->dev, "isoc\n");
1190 hcintmsk |= HCINTMSK_XFERCOMPL;
1191 hcintmsk |= HCINTMSK_FRMOVRUN;
1192 hcintmsk |= HCINTMSK_ACK;
1194 if (chan->ep_is_in) {
1195 hcintmsk |= HCINTMSK_XACTERR;
1196 hcintmsk |= HCINTMSK_BBLERR;
1200 dev_err(hsotg->dev, "## Unknown EP type ##\n");
1204 writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
1206 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk);
1209 static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg,
1210 struct dwc2_host_chan *chan)
1212 u32 hcintmsk = HCINTMSK_CHHLTD;
1215 * For Descriptor DMA mode core halts the channel on AHB error.
1216 * Interrupt is not required.
1218 if (hsotg->core_params->dma_desc_enable <= 0) {
1220 dev_vdbg(hsotg->dev, "desc DMA disabled\n");
1221 hcintmsk |= HCINTMSK_AHBERR;
1224 dev_vdbg(hsotg->dev, "desc DMA enabled\n");
1225 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
1226 hcintmsk |= HCINTMSK_XFERCOMPL;
1229 if (chan->error_state && !chan->do_split &&
1230 chan->ep_type != USB_ENDPOINT_XFER_ISOC) {
1232 dev_vdbg(hsotg->dev, "setting ACK\n");
1233 hcintmsk |= HCINTMSK_ACK;
1234 if (chan->ep_is_in) {
1235 hcintmsk |= HCINTMSK_DATATGLERR;
1236 if (chan->ep_type != USB_ENDPOINT_XFER_INT)
1237 hcintmsk |= HCINTMSK_NAK;
1241 writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
1243 dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk);
1246 static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg,
1247 struct dwc2_host_chan *chan)
1251 if (hsotg->core_params->dma_enable > 0) {
1253 dev_vdbg(hsotg->dev, "DMA enabled\n");
1254 dwc2_hc_enable_dma_ints(hsotg, chan);
1257 dev_vdbg(hsotg->dev, "DMA disabled\n");
1258 dwc2_hc_enable_slave_ints(hsotg, chan);
1261 /* Enable the top level host channel interrupt */
1262 intmsk = readl(hsotg->regs + HAINTMSK);
1263 intmsk |= 1 << chan->hc_num;
1264 writel(intmsk, hsotg->regs + HAINTMSK);
1266 dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk);
1268 /* Make sure host channel interrupts are enabled */
1269 intmsk = readl(hsotg->regs + GINTMSK);
1270 intmsk |= GINTSTS_HCHINT;
1271 writel(intmsk, hsotg->regs + GINTMSK);
1273 dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk);
1277 * dwc2_hc_init() - Prepares a host channel for transferring packets to/from
1278 * a specific endpoint
1280 * @hsotg: Programming view of DWC_otg controller
1281 * @chan: Information needed to initialize the host channel
1283 * The HCCHARn register is set up with the characteristics specified in chan.
1284 * Host channel interrupts that may need to be serviced while this transfer is
1285 * in progress are enabled.
1287 void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
1289 u8 hc_num = chan->hc_num;
1295 dev_vdbg(hsotg->dev, "%s()\n", __func__);
1297 /* Clear old interrupt conditions for this host channel */
1298 hcintmsk = 0xffffffff;
1299 hcintmsk &= ~HCINTMSK_RESERVED14_31;
1300 writel(hcintmsk, hsotg->regs + HCINT(hc_num));
1302 /* Enable channel interrupts required for this transfer */
1303 dwc2_hc_enable_ints(hsotg, chan);
1306 * Program the HCCHARn register with the endpoint characteristics for
1307 * the current transfer
1309 hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK;
1310 hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK;
1312 hcchar |= HCCHAR_EPDIR;
1313 if (chan->speed == USB_SPEED_LOW)
1314 hcchar |= HCCHAR_LSPDDEV;
1315 hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK;
1316 hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK;
1317 writel(hcchar, hsotg->regs + HCCHAR(hc_num));
1319 dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n",
1322 dev_vdbg(hsotg->dev, "%s: Channel %d\n",
1324 dev_vdbg(hsotg->dev, " Dev Addr: %d\n",
1326 dev_vdbg(hsotg->dev, " Ep Num: %d\n",
1328 dev_vdbg(hsotg->dev, " Is In: %d\n",
1330 dev_vdbg(hsotg->dev, " Is Low Speed: %d\n",
1331 chan->speed == USB_SPEED_LOW);
1332 dev_vdbg(hsotg->dev, " Ep Type: %d\n",
1334 dev_vdbg(hsotg->dev, " Max Pkt: %d\n",
1338 /* Program the HCSPLT register for SPLITs */
1339 if (chan->do_split) {
1341 dev_vdbg(hsotg->dev,
1342 "Programming HC %d with split --> %s\n",
1344 chan->complete_split ? "CSPLIT" : "SSPLIT");
1345 if (chan->complete_split)
1346 hcsplt |= HCSPLT_COMPSPLT;
1347 hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT &
1348 HCSPLT_XACTPOS_MASK;
1349 hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT &
1350 HCSPLT_HUBADDR_MASK;
1351 hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT &
1352 HCSPLT_PRTADDR_MASK;
1354 dev_vdbg(hsotg->dev, " comp split %d\n",
1355 chan->complete_split);
1356 dev_vdbg(hsotg->dev, " xact pos %d\n",
1358 dev_vdbg(hsotg->dev, " hub addr %d\n",
1360 dev_vdbg(hsotg->dev, " hub port %d\n",
1362 dev_vdbg(hsotg->dev, " is_in %d\n",
1364 dev_vdbg(hsotg->dev, " Max Pkt %d\n",
1366 dev_vdbg(hsotg->dev, " xferlen %d\n",
1371 writel(hcsplt, hsotg->regs + HCSPLT(hc_num));
1375 * dwc2_hc_halt() - Attempts to halt a host channel
1377 * @hsotg: Controller register interface
1378 * @chan: Host channel to halt
1379 * @halt_status: Reason for halting the channel
1381 * This function should only be called in Slave mode or to abort a transfer in
1382 * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the
1383 * controller halts the channel when the transfer is complete or a condition
1384 * occurs that requires application intervention.
1386 * In slave mode, checks for a free request queue entry, then sets the Channel
1387 * Enable and Channel Disable bits of the Host Channel Characteristics
1388 * register of the specified channel to intiate the halt. If there is no free
1389 * request queue entry, sets only the Channel Disable bit of the HCCHARn
1390 * register to flush requests for this channel. In the latter case, sets a
1391 * flag to indicate that the host channel needs to be halted when a request
1392 * queue slot is open.
1394 * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
1395 * HCCHARn register. The controller ensures there is space in the request
1396 * queue before submitting the halt request.
1398 * Some time may elapse before the core flushes any posted requests for this
1399 * host channel and halts. The Channel Halted interrupt handler completes the
1400 * deactivation of the host channel.
1402 void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan,
1403 enum dwc2_halt_status halt_status)
1405 u32 nptxsts, hptxsts, hcchar;
1408 dev_vdbg(hsotg->dev, "%s()\n", __func__);
1409 if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS)
1410 dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status);
1412 if (halt_status == DWC2_HC_XFER_URB_DEQUEUE ||
1413 halt_status == DWC2_HC_XFER_AHB_ERR) {
1415 * Disable all channel interrupts except Ch Halted. The QTD
1416 * and QH state associated with this transfer has been cleared
1417 * (in the case of URB_DEQUEUE), so the channel needs to be
1418 * shut down carefully to prevent crashes.
1420 u32 hcintmsk = HCINTMSK_CHHLTD;
1422 dev_vdbg(hsotg->dev, "dequeue/error\n");
1423 writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num));
1426 * Make sure no other interrupts besides halt are currently
1427 * pending. Handling another interrupt could cause a crash due
1428 * to the QTD and QH state.
1430 writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num));
1433 * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
1434 * even if the channel was already halted for some other
1437 chan->halt_status = halt_status;
1439 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
1440 if (!(hcchar & HCCHAR_CHENA)) {
1442 * The channel is either already halted or it hasn't
1443 * started yet. In DMA mode, the transfer may halt if
1444 * it finishes normally or a condition occurs that
1445 * requires driver intervention. Don't want to halt
1446 * the channel again. In either Slave or DMA mode,
1447 * it's possible that the transfer has been assigned
1448 * to a channel, but not started yet when an URB is
1449 * dequeued. Don't want to halt a channel that hasn't
1455 if (chan->halt_pending) {
1457 * A halt has already been issued for this channel. This might
1458 * happen when a transfer is aborted by a higher level in
1461 dev_vdbg(hsotg->dev,
1462 "*** %s: Channel %d, chan->halt_pending already set ***\n",
1463 __func__, chan->hc_num);
1467 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
1469 /* No need to set the bit in DDMA for disabling the channel */
1470 /* TODO check it everywhere channel is disabled */
1471 if (hsotg->core_params->dma_desc_enable <= 0) {
1473 dev_vdbg(hsotg->dev, "desc DMA disabled\n");
1474 hcchar |= HCCHAR_CHENA;
1477 dev_dbg(hsotg->dev, "desc DMA enabled\n");
1479 hcchar |= HCCHAR_CHDIS;
1481 if (hsotg->core_params->dma_enable <= 0) {
1483 dev_vdbg(hsotg->dev, "DMA not enabled\n");
1484 hcchar |= HCCHAR_CHENA;
1486 /* Check for space in the request queue to issue the halt */
1487 if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
1488 chan->ep_type == USB_ENDPOINT_XFER_BULK) {
1489 dev_vdbg(hsotg->dev, "control/bulk\n");
1490 nptxsts = readl(hsotg->regs + GNPTXSTS);
1491 if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) {
1492 dev_vdbg(hsotg->dev, "Disabling channel\n");
1493 hcchar &= ~HCCHAR_CHENA;
1497 dev_vdbg(hsotg->dev, "isoc/intr\n");
1498 hptxsts = readl(hsotg->regs + HPTXSTS);
1499 if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 ||
1500 hsotg->queuing_high_bandwidth) {
1502 dev_vdbg(hsotg->dev, "Disabling channel\n");
1503 hcchar &= ~HCCHAR_CHENA;
1508 dev_vdbg(hsotg->dev, "DMA enabled\n");
1511 writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
1512 chan->halt_status = halt_status;
1514 if (hcchar & HCCHAR_CHENA) {
1516 dev_vdbg(hsotg->dev, "Channel enabled\n");
1517 chan->halt_pending = 1;
1518 chan->halt_on_queue = 0;
1521 dev_vdbg(hsotg->dev, "Channel disabled\n");
1522 chan->halt_on_queue = 1;
1526 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
1528 dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n",
1530 dev_vdbg(hsotg->dev, " halt_pending: %d\n",
1531 chan->halt_pending);
1532 dev_vdbg(hsotg->dev, " halt_on_queue: %d\n",
1533 chan->halt_on_queue);
1534 dev_vdbg(hsotg->dev, " halt_status: %d\n",
1540 * dwc2_hc_cleanup() - Clears the transfer state for a host channel
1542 * @hsotg: Programming view of DWC_otg controller
1543 * @chan: Identifies the host channel to clean up
1545 * This function is normally called after a transfer is done and the host
1546 * channel is being released
1548 void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
1552 chan->xfer_started = 0;
1555 * Clear channel interrupt enables and any unhandled channel interrupt
1558 writel(0, hsotg->regs + HCINTMSK(chan->hc_num));
1559 hcintmsk = 0xffffffff;
1560 hcintmsk &= ~HCINTMSK_RESERVED14_31;
1561 writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num));
1565 * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in
1566 * which frame a periodic transfer should occur
1568 * @hsotg: Programming view of DWC_otg controller
1569 * @chan: Identifies the host channel to set up and its properties
1570 * @hcchar: Current value of the HCCHAR register for the specified host channel
1572 * This function has no effect on non-periodic transfers
1574 static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg,
1575 struct dwc2_host_chan *chan, u32 *hcchar)
1577 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1578 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1579 /* 1 if _next_ frame is odd, 0 if it's even */
1580 if (!(dwc2_hcd_get_frame_number(hsotg) & 0x1))
1581 *hcchar |= HCCHAR_ODDFRM;
1585 static void dwc2_set_pid_isoc(struct dwc2_host_chan *chan)
1587 /* Set up the initial PID for the transfer */
1588 if (chan->speed == USB_SPEED_HIGH) {
1589 if (chan->ep_is_in) {
1590 if (chan->multi_count == 1)
1591 chan->data_pid_start = DWC2_HC_PID_DATA0;
1592 else if (chan->multi_count == 2)
1593 chan->data_pid_start = DWC2_HC_PID_DATA1;
1595 chan->data_pid_start = DWC2_HC_PID_DATA2;
1597 if (chan->multi_count == 1)
1598 chan->data_pid_start = DWC2_HC_PID_DATA0;
1600 chan->data_pid_start = DWC2_HC_PID_MDATA;
1603 chan->data_pid_start = DWC2_HC_PID_DATA0;
1608 * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with
1611 * @hsotg: Programming view of DWC_otg controller
1612 * @chan: Information needed to initialize the host channel
1614 * This function should only be called in Slave mode. For a channel associated
1615 * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel
1616 * associated with a periodic EP, the periodic Tx FIFO is written.
1618 * Upon return the xfer_buf and xfer_count fields in chan are incremented by
1619 * the number of bytes written to the Tx FIFO.
1621 static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg,
1622 struct dwc2_host_chan *chan)
1625 u32 remaining_count;
1628 u32 __iomem *data_fifo;
1629 u32 *data_buf = (u32 *)chan->xfer_buf;
1632 dev_vdbg(hsotg->dev, "%s()\n", __func__);
1634 data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num));
1636 remaining_count = chan->xfer_len - chan->xfer_count;
1637 if (remaining_count > chan->max_packet)
1638 byte_count = chan->max_packet;
1640 byte_count = remaining_count;
1642 dword_count = (byte_count + 3) / 4;
1644 if (((unsigned long)data_buf & 0x3) == 0) {
1645 /* xfer_buf is DWORD aligned */
1646 for (i = 0; i < dword_count; i++, data_buf++)
1647 writel(*data_buf, data_fifo);
1649 /* xfer_buf is not DWORD aligned */
1650 for (i = 0; i < dword_count; i++, data_buf++) {
1651 u32 data = data_buf[0] | data_buf[1] << 8 |
1652 data_buf[2] << 16 | data_buf[3] << 24;
1653 writel(data, data_fifo);
1657 chan->xfer_count += byte_count;
1658 chan->xfer_buf += byte_count;
1662 * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host
1663 * channel and starts the transfer
1665 * @hsotg: Programming view of DWC_otg controller
1666 * @chan: Information needed to initialize the host channel. The xfer_len value
1667 * may be reduced to accommodate the max widths of the XferSize and
1668 * PktCnt fields in the HCTSIZn register. The multi_count value may be
1669 * changed to reflect the final xfer_len value.
1671 * This function may be called in either Slave mode or DMA mode. In Slave mode,
1672 * the caller must ensure that there is sufficient space in the request queue
1675 * For an OUT transfer in Slave mode, it loads a data packet into the
1676 * appropriate FIFO. If necessary, additional data packets are loaded in the
1679 * For an IN transfer in Slave mode, a data packet is requested. The data
1680 * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
1681 * additional data packets are requested in the Host ISR.
1683 * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
1684 * register along with a packet count of 1 and the channel is enabled. This
1685 * causes a single PING transaction to occur. Other fields in HCTSIZ are
1686 * simply set to 0 since no data transfer occurs in this case.
1688 * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
1689 * all the information required to perform the subsequent data transfer. In
1690 * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
1691 * controller performs the entire PING protocol, then starts the data
1694 void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg,
1695 struct dwc2_host_chan *chan)
1697 u32 max_hc_xfer_size = hsotg->core_params->max_transfer_size;
1698 u16 max_hc_pkt_count = hsotg->core_params->max_packet_count;
1704 dev_vdbg(hsotg->dev, "%s()\n", __func__);
1706 if (chan->do_ping) {
1707 if (hsotg->core_params->dma_enable <= 0) {
1709 dev_vdbg(hsotg->dev, "ping, no DMA\n");
1710 dwc2_hc_do_ping(hsotg, chan);
1711 chan->xfer_started = 1;
1715 dev_vdbg(hsotg->dev, "ping, DMA\n");
1716 hctsiz |= TSIZ_DOPNG;
1720 if (chan->do_split) {
1722 dev_vdbg(hsotg->dev, "split\n");
1725 if (chan->complete_split && !chan->ep_is_in)
1727 * For CSPLIT OUT Transfer, set the size to 0 so the
1728 * core doesn't expect any data written to the FIFO
1731 else if (chan->ep_is_in || chan->xfer_len > chan->max_packet)
1732 chan->xfer_len = chan->max_packet;
1733 else if (!chan->ep_is_in && chan->xfer_len > 188)
1734 chan->xfer_len = 188;
1736 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
1740 dev_vdbg(hsotg->dev, "no split\n");
1742 * Ensure that the transfer length and packet count will fit
1743 * in the widths allocated for them in the HCTSIZn register
1745 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1746 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
1748 * Make sure the transfer size is no larger than one
1749 * (micro)frame's worth of data. (A check was done
1750 * when the periodic transfer was accepted to ensure
1751 * that a (micro)frame's worth of data can be
1752 * programmed into a channel.)
1754 u32 max_periodic_len =
1755 chan->multi_count * chan->max_packet;
1757 if (chan->xfer_len > max_periodic_len)
1758 chan->xfer_len = max_periodic_len;
1759 } else if (chan->xfer_len > max_hc_xfer_size) {
1761 * Make sure that xfer_len is a multiple of max packet
1765 max_hc_xfer_size - chan->max_packet + 1;
1768 if (chan->xfer_len > 0) {
1769 num_packets = (chan->xfer_len + chan->max_packet - 1) /
1771 if (num_packets > max_hc_pkt_count) {
1772 num_packets = max_hc_pkt_count;
1773 chan->xfer_len = num_packets * chan->max_packet;
1776 /* Need 1 packet for transfer length of 0 */
1782 * Always program an integral # of max packets for IN
1785 chan->xfer_len = num_packets * chan->max_packet;
1787 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
1788 chan->ep_type == USB_ENDPOINT_XFER_ISOC)
1790 * Make sure that the multi_count field matches the
1791 * actual transfer length
1793 chan->multi_count = num_packets;
1795 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
1796 dwc2_set_pid_isoc(chan);
1798 hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT &
1802 chan->start_pkt_count = num_packets;
1803 hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK;
1804 hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT &
1805 TSIZ_SC_MC_PID_MASK;
1806 writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
1808 dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n",
1809 hctsiz, chan->hc_num);
1811 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
1813 dev_vdbg(hsotg->dev, " Xfer Size: %d\n",
1814 (hctsiz & TSIZ_XFERSIZE_MASK) >>
1815 TSIZ_XFERSIZE_SHIFT);
1816 dev_vdbg(hsotg->dev, " Num Pkts: %d\n",
1817 (hctsiz & TSIZ_PKTCNT_MASK) >>
1819 dev_vdbg(hsotg->dev, " Start PID: %d\n",
1820 (hctsiz & TSIZ_SC_MC_PID_MASK) >>
1821 TSIZ_SC_MC_PID_SHIFT);
1824 if (hsotg->core_params->dma_enable > 0) {
1825 dma_addr_t dma_addr;
1827 if (chan->align_buf) {
1829 dev_vdbg(hsotg->dev, "align_buf\n");
1830 dma_addr = chan->align_buf;
1832 dma_addr = chan->xfer_dma;
1834 writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num));
1836 dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n",
1837 (unsigned long)dma_addr, chan->hc_num);
1840 /* Start the split */
1841 if (chan->do_split) {
1842 u32 hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num));
1844 hcsplt |= HCSPLT_SPLTENA;
1845 writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num));
1848 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
1849 hcchar &= ~HCCHAR_MULTICNT_MASK;
1850 hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT &
1851 HCCHAR_MULTICNT_MASK;
1852 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
1854 if (hcchar & HCCHAR_CHDIS)
1855 dev_warn(hsotg->dev,
1856 "%s: chdis set, channel %d, hcchar 0x%08x\n",
1857 __func__, chan->hc_num, hcchar);
1859 /* Set host channel enable after all other setup is complete */
1860 hcchar |= HCCHAR_CHENA;
1861 hcchar &= ~HCCHAR_CHDIS;
1864 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n",
1865 (hcchar & HCCHAR_MULTICNT_MASK) >>
1866 HCCHAR_MULTICNT_SHIFT);
1868 writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
1870 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar,
1873 chan->xfer_started = 1;
1876 if (hsotg->core_params->dma_enable <= 0 &&
1877 !chan->ep_is_in && chan->xfer_len > 0)
1878 /* Load OUT packet into the appropriate Tx FIFO */
1879 dwc2_hc_write_packet(hsotg, chan);
1883 * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a
1884 * host channel and starts the transfer in Descriptor DMA mode
1886 * @hsotg: Programming view of DWC_otg controller
1887 * @chan: Information needed to initialize the host channel
1889 * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
1890 * Sets PID and NTD values. For periodic transfers initializes SCHED_INFO field
1891 * with micro-frame bitmap.
1893 * Initializes HCDMA register with descriptor list address and CTD value then
1894 * starts the transfer via enabling the channel.
1896 void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg,
1897 struct dwc2_host_chan *chan)
1904 hctsiz |= TSIZ_DOPNG;
1906 if (chan->ep_type == USB_ENDPOINT_XFER_ISOC)
1907 dwc2_set_pid_isoc(chan);
1909 /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
1910 hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT &
1911 TSIZ_SC_MC_PID_MASK;
1913 /* 0 - 1 descriptor, 1 - 2 descriptors, etc */
1914 hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK;
1916 /* Non-zero only for high-speed interrupt endpoints */
1917 hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK;
1920 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
1922 dev_vdbg(hsotg->dev, " Start PID: %d\n",
1923 chan->data_pid_start);
1924 dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1);
1927 writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
1929 hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK;
1931 /* Always start from first descriptor */
1932 hc_dma &= ~HCDMA_CTD_MASK;
1933 writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num));
1935 dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n",
1936 hc_dma, chan->hc_num);
1938 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
1939 hcchar &= ~HCCHAR_MULTICNT_MASK;
1940 hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT &
1941 HCCHAR_MULTICNT_MASK;
1943 if (hcchar & HCCHAR_CHDIS)
1944 dev_warn(hsotg->dev,
1945 "%s: chdis set, channel %d, hcchar 0x%08x\n",
1946 __func__, chan->hc_num, hcchar);
1948 /* Set host channel enable after all other setup is complete */
1949 hcchar |= HCCHAR_CHENA;
1950 hcchar &= ~HCCHAR_CHDIS;
1953 dev_vdbg(hsotg->dev, " Multi Cnt: %d\n",
1954 (hcchar & HCCHAR_MULTICNT_MASK) >>
1955 HCCHAR_MULTICNT_SHIFT);
1957 writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
1959 dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar,
1962 chan->xfer_started = 1;
1967 * dwc2_hc_continue_transfer() - Continues a data transfer that was started by
1968 * a previous call to dwc2_hc_start_transfer()
1970 * @hsotg: Programming view of DWC_otg controller
1971 * @chan: Information needed to initialize the host channel
1973 * The caller must ensure there is sufficient space in the request queue and Tx
1974 * Data FIFO. This function should only be called in Slave mode. In DMA mode,
1975 * the controller acts autonomously to complete transfers programmed to a host
1978 * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
1979 * if there is any data remaining to be queued. For an IN transfer, another
1980 * data packet is always requested. For the SETUP phase of a control transfer,
1981 * this function does nothing.
1983 * Return: 1 if a new request is queued, 0 if no more requests are required
1986 int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg,
1987 struct dwc2_host_chan *chan)
1990 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
1994 /* SPLITs always queue just once per channel */
1997 if (chan->data_pid_start == DWC2_HC_PID_SETUP)
1998 /* SETUPs are queued only once since they can't be NAK'd */
2001 if (chan->ep_is_in) {
2003 * Always queue another request for other IN transfers. If
2004 * back-to-back INs are issued and NAKs are received for both,
2005 * the driver may still be processing the first NAK when the
2006 * second NAK is received. When the interrupt handler clears
2007 * the NAK interrupt for the first NAK, the second NAK will
2008 * not be seen. So we can't depend on the NAK interrupt
2009 * handler to requeue a NAK'd request. Instead, IN requests
2010 * are issued each time this function is called. When the
2011 * transfer completes, the extra requests for the channel will
2014 u32 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
2016 dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar);
2017 hcchar |= HCCHAR_CHENA;
2018 hcchar &= ~HCCHAR_CHDIS;
2020 dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n",
2022 writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
2029 if (chan->xfer_count < chan->xfer_len) {
2030 if (chan->ep_type == USB_ENDPOINT_XFER_INT ||
2031 chan->ep_type == USB_ENDPOINT_XFER_ISOC) {
2032 u32 hcchar = readl(hsotg->regs +
2033 HCCHAR(chan->hc_num));
2035 dwc2_hc_set_even_odd_frame(hsotg, chan,
2039 /* Load OUT packet into the appropriate Tx FIFO */
2040 dwc2_hc_write_packet(hsotg, chan);
2049 * dwc2_hc_do_ping() - Starts a PING transfer
2051 * @hsotg: Programming view of DWC_otg controller
2052 * @chan: Information needed to initialize the host channel
2054 * This function should only be called in Slave mode. The Do Ping bit is set in
2055 * the HCTSIZ register, then the channel is enabled.
2057 void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
2063 dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__,
2067 hctsiz = TSIZ_DOPNG;
2068 hctsiz |= 1 << TSIZ_PKTCNT_SHIFT;
2069 writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num));
2071 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num));
2072 hcchar |= HCCHAR_CHENA;
2073 hcchar &= ~HCCHAR_CHDIS;
2074 writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num));
2078 * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for
2079 * the HFIR register according to PHY type and speed
2081 * @hsotg: Programming view of DWC_otg controller
2083 * NOTE: The caller can modify the value of the HFIR register only after the
2084 * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort)
2087 u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
2091 int clock = 60; /* default value */
2093 usbcfg = readl(hsotg->regs + GUSBCFG);
2094 hprt0 = readl(hsotg->regs + HPRT0);
2096 if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) &&
2097 !(usbcfg & GUSBCFG_PHYIF16))
2099 if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type ==
2100 GHWCFG2_FS_PHY_TYPE_SHARED_ULPI)
2102 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
2103 !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
2105 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
2106 !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16))
2108 if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
2109 !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
2111 if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) &&
2112 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI)
2114 if ((usbcfg & GUSBCFG_PHYSEL) &&
2115 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
2118 if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED)
2119 /* High speed case */
2123 return 1000 * clock;
2127 * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination
2130 * @core_if: Programming view of DWC_otg controller
2131 * @dest: Destination buffer for the packet
2132 * @bytes: Number of bytes to copy to the destination
2134 void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes)
2136 u32 __iomem *fifo = hsotg->regs + HCFIFO(0);
2137 u32 *data_buf = (u32 *)dest;
2138 int word_count = (bytes + 3) / 4;
2142 * Todo: Account for the case where dest is not dword aligned. This
2143 * requires reading data from the FIFO into a u32 temp buffer, then
2144 * moving it into the data buffer.
2147 dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes);
2149 for (i = 0; i < word_count; i++, data_buf++)
2150 *data_buf = readl(fifo);
2154 * dwc2_dump_host_registers() - Prints the host registers
2156 * @hsotg: Programming view of DWC_otg controller
2158 * NOTE: This function will be removed once the peripheral controller code
2159 * is integrated and the driver is stable
2161 void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg)
2167 dev_dbg(hsotg->dev, "Host Global Registers\n");
2168 addr = hsotg->regs + HCFG;
2169 dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n",
2170 (unsigned long)addr, readl(addr));
2171 addr = hsotg->regs + HFIR;
2172 dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n",
2173 (unsigned long)addr, readl(addr));
2174 addr = hsotg->regs + HFNUM;
2175 dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n",
2176 (unsigned long)addr, readl(addr));
2177 addr = hsotg->regs + HPTXSTS;
2178 dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n",
2179 (unsigned long)addr, readl(addr));
2180 addr = hsotg->regs + HAINT;
2181 dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n",
2182 (unsigned long)addr, readl(addr));
2183 addr = hsotg->regs + HAINTMSK;
2184 dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n",
2185 (unsigned long)addr, readl(addr));
2186 if (hsotg->core_params->dma_desc_enable > 0) {
2187 addr = hsotg->regs + HFLBADDR;
2188 dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n",
2189 (unsigned long)addr, readl(addr));
2192 addr = hsotg->regs + HPRT0;
2193 dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n",
2194 (unsigned long)addr, readl(addr));
2196 for (i = 0; i < hsotg->core_params->host_channels; i++) {
2197 dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i);
2198 addr = hsotg->regs + HCCHAR(i);
2199 dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n",
2200 (unsigned long)addr, readl(addr));
2201 addr = hsotg->regs + HCSPLT(i);
2202 dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n",
2203 (unsigned long)addr, readl(addr));
2204 addr = hsotg->regs + HCINT(i);
2205 dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n",
2206 (unsigned long)addr, readl(addr));
2207 addr = hsotg->regs + HCINTMSK(i);
2208 dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n",
2209 (unsigned long)addr, readl(addr));
2210 addr = hsotg->regs + HCTSIZ(i);
2211 dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n",
2212 (unsigned long)addr, readl(addr));
2213 addr = hsotg->regs + HCDMA(i);
2214 dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n",
2215 (unsigned long)addr, readl(addr));
2216 if (hsotg->core_params->dma_desc_enable > 0) {
2217 addr = hsotg->regs + HCDMAB(i);
2218 dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n",
2219 (unsigned long)addr, readl(addr));
2226 * dwc2_dump_global_registers() - Prints the core global registers
2228 * @hsotg: Programming view of DWC_otg controller
2230 * NOTE: This function will be removed once the peripheral controller code
2231 * is integrated and the driver is stable
2233 void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg)
2238 dev_dbg(hsotg->dev, "Core Global Registers\n");
2239 addr = hsotg->regs + GOTGCTL;
2240 dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n",
2241 (unsigned long)addr, readl(addr));
2242 addr = hsotg->regs + GOTGINT;
2243 dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n",
2244 (unsigned long)addr, readl(addr));
2245 addr = hsotg->regs + GAHBCFG;
2246 dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n",
2247 (unsigned long)addr, readl(addr));
2248 addr = hsotg->regs + GUSBCFG;
2249 dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n",
2250 (unsigned long)addr, readl(addr));
2251 addr = hsotg->regs + GRSTCTL;
2252 dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n",
2253 (unsigned long)addr, readl(addr));
2254 addr = hsotg->regs + GINTSTS;
2255 dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n",
2256 (unsigned long)addr, readl(addr));
2257 addr = hsotg->regs + GINTMSK;
2258 dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n",
2259 (unsigned long)addr, readl(addr));
2260 addr = hsotg->regs + GRXSTSR;
2261 dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n",
2262 (unsigned long)addr, readl(addr));
2263 addr = hsotg->regs + GRXFSIZ;
2264 dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n",
2265 (unsigned long)addr, readl(addr));
2266 addr = hsotg->regs + GNPTXFSIZ;
2267 dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n",
2268 (unsigned long)addr, readl(addr));
2269 addr = hsotg->regs + GNPTXSTS;
2270 dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n",
2271 (unsigned long)addr, readl(addr));
2272 addr = hsotg->regs + GI2CCTL;
2273 dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n",
2274 (unsigned long)addr, readl(addr));
2275 addr = hsotg->regs + GPVNDCTL;
2276 dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n",
2277 (unsigned long)addr, readl(addr));
2278 addr = hsotg->regs + GGPIO;
2279 dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n",
2280 (unsigned long)addr, readl(addr));
2281 addr = hsotg->regs + GUID;
2282 dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n",
2283 (unsigned long)addr, readl(addr));
2284 addr = hsotg->regs + GSNPSID;
2285 dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n",
2286 (unsigned long)addr, readl(addr));
2287 addr = hsotg->regs + GHWCFG1;
2288 dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n",
2289 (unsigned long)addr, readl(addr));
2290 addr = hsotg->regs + GHWCFG2;
2291 dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n",
2292 (unsigned long)addr, readl(addr));
2293 addr = hsotg->regs + GHWCFG3;
2294 dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n",
2295 (unsigned long)addr, readl(addr));
2296 addr = hsotg->regs + GHWCFG4;
2297 dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n",
2298 (unsigned long)addr, readl(addr));
2299 addr = hsotg->regs + GLPMCFG;
2300 dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n",
2301 (unsigned long)addr, readl(addr));
2302 addr = hsotg->regs + GPWRDN;
2303 dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n",
2304 (unsigned long)addr, readl(addr));
2305 addr = hsotg->regs + GDFIFOCFG;
2306 dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n",
2307 (unsigned long)addr, readl(addr));
2308 addr = hsotg->regs + HPTXFSIZ;
2309 dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n",
2310 (unsigned long)addr, readl(addr));
2312 addr = hsotg->regs + PCGCTL;
2313 dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n",
2314 (unsigned long)addr, readl(addr));
2319 * dwc2_flush_tx_fifo() - Flushes a Tx FIFO
2321 * @hsotg: Programming view of DWC_otg controller
2322 * @num: Tx FIFO to flush
2324 void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num)
2329 dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num);
2331 greset = GRSTCTL_TXFFLSH;
2332 greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK;
2333 writel(greset, hsotg->regs + GRSTCTL);
2336 greset = readl(hsotg->regs + GRSTCTL);
2337 if (++count > 10000) {
2338 dev_warn(hsotg->dev,
2339 "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
2341 readl(hsotg->regs + GNPTXSTS));
2345 } while (greset & GRSTCTL_TXFFLSH);
2347 /* Wait for at least 3 PHY Clocks */
2352 * dwc2_flush_rx_fifo() - Flushes the Rx FIFO
2354 * @hsotg: Programming view of DWC_otg controller
2356 void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg)
2361 dev_vdbg(hsotg->dev, "%s()\n", __func__);
2363 greset = GRSTCTL_RXFFLSH;
2364 writel(greset, hsotg->regs + GRSTCTL);
2367 greset = readl(hsotg->regs + GRSTCTL);
2368 if (++count > 10000) {
2369 dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n",
2374 } while (greset & GRSTCTL_RXFFLSH);
2376 /* Wait for at least 3 PHY Clocks */
2380 #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c))
2382 /* Parameter access functions */
2383 void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
2388 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
2389 if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
2392 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
2393 switch (hsotg->hw_params.op_mode) {
2394 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
2395 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
2396 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
2397 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
2404 case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE:
2415 "%d invalid for otg_cap parameter. Check HW configuration.\n",
2417 switch (hsotg->hw_params.op_mode) {
2418 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
2419 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
2421 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
2422 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
2423 case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST:
2424 val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE;
2427 val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE;
2430 dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val);
2433 hsotg->core_params->otg_cap = val;
2436 void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val)
2440 if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH)
2448 "%d invalid for dma_enable parameter. Check HW configuration.\n",
2450 val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH;
2451 dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val);
2454 hsotg->core_params->dma_enable = val;
2457 void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
2461 if (val > 0 && (hsotg->core_params->dma_enable <= 0 ||
2462 !hsotg->hw_params.dma_desc_enable))
2470 "%d invalid for dma_desc_enable parameter. Check HW configuration.\n",
2472 val = (hsotg->core_params->dma_enable > 0 &&
2473 hsotg->hw_params.dma_desc_enable);
2474 dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val);
2477 hsotg->core_params->dma_desc_enable = val;
2480 void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg,
2483 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2486 "Wrong value for host_support_fs_low_power\n");
2488 "host_support_fs_low_power must be 0 or 1\n");
2492 "Setting host_support_fs_low_power to %d\n", val);
2495 hsotg->core_params->host_support_fs_ls_low_power = val;
2498 void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val)
2502 if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo)
2510 "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n",
2512 val = hsotg->hw_params.enable_dynamic_fifo;
2513 dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val);
2516 hsotg->core_params->enable_dynamic_fifo = val;
2519 void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2523 if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size)
2529 "%d invalid for host_rx_fifo_size. Check HW configuration.\n",
2531 val = hsotg->hw_params.host_rx_fifo_size;
2532 dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
2535 hsotg->core_params->host_rx_fifo_size = val;
2538 void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2542 if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size)
2548 "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
2550 val = hsotg->hw_params.host_nperio_tx_fifo_size;
2551 dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n",
2555 hsotg->core_params->host_nperio_tx_fifo_size = val;
2558 void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2562 if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size)
2568 "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
2570 val = hsotg->hw_params.host_perio_tx_fifo_size;
2571 dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n",
2575 hsotg->core_params->host_perio_tx_fifo_size = val;
2578 void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
2582 if (val < 2047 || val > hsotg->hw_params.max_transfer_size)
2588 "%d invalid for max_transfer_size. Check HW configuration.\n",
2590 val = hsotg->hw_params.max_transfer_size;
2591 dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val);
2594 hsotg->core_params->max_transfer_size = val;
2597 void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
2601 if (val < 15 || val > hsotg->hw_params.max_packet_count)
2607 "%d invalid for max_packet_count. Check HW configuration.\n",
2609 val = hsotg->hw_params.max_packet_count;
2610 dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val);
2613 hsotg->core_params->max_packet_count = val;
2616 void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
2620 if (val < 1 || val > hsotg->hw_params.host_channels)
2626 "%d invalid for host_channels. Check HW configuration.\n",
2628 val = hsotg->hw_params.host_channels;
2629 dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val);
2632 hsotg->core_params->host_channels = val;
2635 void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
2638 u32 hs_phy_type, fs_phy_type;
2640 if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS,
2641 DWC2_PHY_TYPE_PARAM_ULPI)) {
2643 dev_err(hsotg->dev, "Wrong value for phy_type\n");
2644 dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n");
2650 hs_phy_type = hsotg->hw_params.hs_phy_type;
2651 fs_phy_type = hsotg->hw_params.fs_phy_type;
2652 if (val == DWC2_PHY_TYPE_PARAM_UTMI &&
2653 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
2654 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
2656 else if (val == DWC2_PHY_TYPE_PARAM_ULPI &&
2657 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI ||
2658 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
2660 else if (val == DWC2_PHY_TYPE_PARAM_FS &&
2661 fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
2667 "%d invalid for phy_type. Check HW configuration.\n",
2669 val = DWC2_PHY_TYPE_PARAM_FS;
2670 if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) {
2671 if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
2672 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)
2673 val = DWC2_PHY_TYPE_PARAM_UTMI;
2675 val = DWC2_PHY_TYPE_PARAM_ULPI;
2677 dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val);
2680 hsotg->core_params->phy_type = val;
2683 static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg)
2685 return hsotg->core_params->phy_type;
2688 void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val)
2692 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2694 dev_err(hsotg->dev, "Wrong value for speed parameter\n");
2695 dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n");
2700 if (val == DWC2_SPEED_PARAM_HIGH &&
2701 dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
2707 "%d invalid for speed parameter. Check HW configuration.\n",
2709 val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ?
2710 DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH;
2711 dev_dbg(hsotg->dev, "Setting speed to %d\n", val);
2714 hsotg->core_params->speed = val;
2717 void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, int val)
2721 if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ,
2722 DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) {
2725 "Wrong value for host_ls_low_power_phy_clk parameter\n");
2727 "host_ls_low_power_phy_clk must be 0 or 1\n");
2732 if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ &&
2733 dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS)
2739 "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
2741 val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS
2742 ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ
2743 : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
2744 dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n",
2748 hsotg->core_params->host_ls_low_power_phy_clk = val;
2751 void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val)
2753 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2755 dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n");
2756 dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n");
2759 dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val);
2762 hsotg->core_params->phy_ulpi_ddr = val;
2765 void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val)
2767 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2770 "Wrong value for phy_ulpi_ext_vbus\n");
2772 "phy_ulpi_ext_vbus must be 0 or 1\n");
2775 dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val);
2778 hsotg->core_params->phy_ulpi_ext_vbus = val;
2781 void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val)
2785 switch (hsotg->hw_params.utmi_phy_data_width) {
2786 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8:
2789 case GHWCFG4_UTMI_PHY_DATA_WIDTH_16:
2790 valid = (val == 16);
2792 case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16:
2793 valid = (val == 8 || val == 16);
2800 "%d invalid for phy_utmi_width. Check HW configuration.\n",
2803 val = (hsotg->hw_params.utmi_phy_data_width ==
2804 GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16;
2805 dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val);
2808 hsotg->core_params->phy_utmi_width = val;
2811 void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val)
2813 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2815 dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n");
2816 dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n");
2819 dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val);
2822 hsotg->core_params->ulpi_fs_ls = val;
2825 void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val)
2827 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2829 dev_err(hsotg->dev, "Wrong value for ts_dline\n");
2830 dev_err(hsotg->dev, "ts_dline must be 0 or 1\n");
2833 dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val);
2836 hsotg->core_params->ts_dline = val;
2839 void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
2843 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2845 dev_err(hsotg->dev, "Wrong value for i2c_enable\n");
2846 dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n");
2852 if (val == 1 && !(hsotg->hw_params.i2c_enable))
2858 "%d invalid for i2c_enable. Check HW configuration.\n",
2860 val = hsotg->hw_params.i2c_enable;
2861 dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
2864 hsotg->core_params->i2c_enable = val;
2867 void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val)
2871 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2874 "Wrong value for en_multiple_tx_fifo,\n");
2876 "en_multiple_tx_fifo must be 0 or 1\n");
2881 if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo)
2887 "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
2889 val = hsotg->hw_params.en_multiple_tx_fifo;
2890 dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val);
2893 hsotg->core_params->en_multiple_tx_fifo = val;
2896 void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
2900 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2903 "'%d' invalid for parameter reload_ctl\n", val);
2904 dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n");
2909 if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a)
2915 "%d invalid for parameter reload_ctl. Check HW configuration.\n",
2917 val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a;
2918 dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val);
2921 hsotg->core_params->reload_ctl = val;
2924 void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)
2927 hsotg->core_params->ahbcfg = val;
2929 hsotg->core_params->ahbcfg = GAHBCFG_HBSTLEN_INCR4 <<
2930 GAHBCFG_HBSTLEN_SHIFT;
2933 void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val)
2935 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2938 "'%d' invalid for parameter otg_ver\n", val);
2940 "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n");
2943 dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val);
2946 hsotg->core_params->otg_ver = val;
2949 static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val)
2951 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2954 "'%d' invalid for parameter uframe_sched\n",
2956 dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n");
2959 dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val);
2962 hsotg->core_params->uframe_sched = val;
2965 static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg,
2968 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2971 "'%d' invalid for parameter external_id_pin_ctl\n",
2973 dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 1\n");
2976 dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val);
2979 hsotg->core_params->external_id_pin_ctl = val;
2982 static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg,
2985 if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
2988 "'%d' invalid for parameter hibernation\n",
2990 dev_err(hsotg->dev, "hibernation must be 0 or 1\n");
2993 dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val);
2996 hsotg->core_params->hibernation = val;
3000 * This function is called during module intialization to pass module parameters
3001 * for the DWC_otg core.
3003 void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
3004 const struct dwc2_core_params *params)
3006 dev_dbg(hsotg->dev, "%s()\n", __func__);
3008 dwc2_set_param_otg_cap(hsotg, params->otg_cap);
3009 dwc2_set_param_dma_enable(hsotg, params->dma_enable);
3010 dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable);
3011 dwc2_set_param_host_support_fs_ls_low_power(hsotg,
3012 params->host_support_fs_ls_low_power);
3013 dwc2_set_param_enable_dynamic_fifo(hsotg,
3014 params->enable_dynamic_fifo);
3015 dwc2_set_param_host_rx_fifo_size(hsotg,
3016 params->host_rx_fifo_size);
3017 dwc2_set_param_host_nperio_tx_fifo_size(hsotg,
3018 params->host_nperio_tx_fifo_size);
3019 dwc2_set_param_host_perio_tx_fifo_size(hsotg,
3020 params->host_perio_tx_fifo_size);
3021 dwc2_set_param_max_transfer_size(hsotg,
3022 params->max_transfer_size);
3023 dwc2_set_param_max_packet_count(hsotg,
3024 params->max_packet_count);
3025 dwc2_set_param_host_channels(hsotg, params->host_channels);
3026 dwc2_set_param_phy_type(hsotg, params->phy_type);
3027 dwc2_set_param_speed(hsotg, params->speed);
3028 dwc2_set_param_host_ls_low_power_phy_clk(hsotg,
3029 params->host_ls_low_power_phy_clk);
3030 dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr);
3031 dwc2_set_param_phy_ulpi_ext_vbus(hsotg,
3032 params->phy_ulpi_ext_vbus);
3033 dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width);
3034 dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls);
3035 dwc2_set_param_ts_dline(hsotg, params->ts_dline);
3036 dwc2_set_param_i2c_enable(hsotg, params->i2c_enable);
3037 dwc2_set_param_en_multiple_tx_fifo(hsotg,
3038 params->en_multiple_tx_fifo);
3039 dwc2_set_param_reload_ctl(hsotg, params->reload_ctl);
3040 dwc2_set_param_ahbcfg(hsotg, params->ahbcfg);
3041 dwc2_set_param_otg_ver(hsotg, params->otg_ver);
3042 dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
3043 dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
3044 dwc2_set_param_hibernation(hsotg, params->hibernation);
3048 * During device initialization, read various hardware configuration
3049 * registers and interpret the contents.
3051 int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
3053 struct dwc2_hw_params *hw = &hsotg->hw_params;
3055 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
3056 u32 hptxfsiz, grxfsiz, gnptxfsiz;
3060 * Attempt to ensure this device is really a DWC_otg Controller.
3061 * Read and verify the GSNPSID register contents. The value should be
3062 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
3063 * as in "OTG version 2.xx" or "OTG version 3.xx".
3065 hw->snpsid = readl(hsotg->regs + GSNPSID);
3066 if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
3067 (hw->snpsid & 0xfffff000) != 0x4f543000) {
3068 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
3073 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
3074 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
3075 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
3077 hwcfg1 = readl(hsotg->regs + GHWCFG1);
3078 hwcfg2 = readl(hsotg->regs + GHWCFG2);
3079 hwcfg3 = readl(hsotg->regs + GHWCFG3);
3080 hwcfg4 = readl(hsotg->regs + GHWCFG4);
3081 grxfsiz = readl(hsotg->regs + GRXFSIZ);
3083 dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1);
3084 dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2);
3085 dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3);
3086 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4);
3087 dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz);
3089 /* Force host mode to get HPTXFSIZ / GNPTXFSIZ exact power on value */
3090 gusbcfg = readl(hsotg->regs + GUSBCFG);
3091 gusbcfg |= GUSBCFG_FORCEHOSTMODE;
3092 writel(gusbcfg, hsotg->regs + GUSBCFG);
3093 usleep_range(100000, 150000);
3095 gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ);
3096 hptxfsiz = readl(hsotg->regs + HPTXFSIZ);
3097 dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
3098 dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz);
3099 gusbcfg = readl(hsotg->regs + GUSBCFG);
3100 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
3101 writel(gusbcfg, hsotg->regs + GUSBCFG);
3102 usleep_range(100000, 150000);
3105 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
3106 GHWCFG2_OP_MODE_SHIFT;
3107 hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
3108 GHWCFG2_ARCHITECTURE_SHIFT;
3109 hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
3110 hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
3111 GHWCFG2_NUM_HOST_CHAN_SHIFT);
3112 hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
3113 GHWCFG2_HS_PHY_TYPE_SHIFT;
3114 hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
3115 GHWCFG2_FS_PHY_TYPE_SHIFT;
3116 hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
3117 GHWCFG2_NUM_DEV_EP_SHIFT;
3118 hw->nperio_tx_q_depth =
3119 (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
3120 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
3121 hw->host_perio_tx_q_depth =
3122 (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
3123 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
3124 hw->dev_token_q_depth =
3125 (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
3126 GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
3129 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
3130 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
3131 hw->max_transfer_size = (1 << (width + 11)) - 1;
3133 * Clip max_transfer_size to 65535. dwc2_hc_setup_align_buf() allocates
3134 * coherent buffers with this size, and if it's too large we can
3135 * exhaust the coherent DMA pool.
3137 if (hw->max_transfer_size > 65535)
3138 hw->max_transfer_size = 65535;
3139 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
3140 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
3141 hw->max_packet_count = (1 << (width + 4)) - 1;
3142 hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
3143 hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
3144 GHWCFG3_DFIFO_DEPTH_SHIFT;
3147 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
3148 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
3149 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
3150 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
3151 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
3152 hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >>
3153 GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT;
3156 hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
3157 GRXFSIZ_DEPTH_SHIFT;
3158 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
3159 FIFOSIZE_DEPTH_SHIFT;
3160 hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
3161 FIFOSIZE_DEPTH_SHIFT;
3163 dev_dbg(hsotg->dev, "Detected values from hardware:\n");
3164 dev_dbg(hsotg->dev, " op_mode=%d\n",
3166 dev_dbg(hsotg->dev, " arch=%d\n",
3168 dev_dbg(hsotg->dev, " dma_desc_enable=%d\n",
3169 hw->dma_desc_enable);
3170 dev_dbg(hsotg->dev, " power_optimized=%d\n",
3171 hw->power_optimized);
3172 dev_dbg(hsotg->dev, " i2c_enable=%d\n",
3174 dev_dbg(hsotg->dev, " hs_phy_type=%d\n",
3176 dev_dbg(hsotg->dev, " fs_phy_type=%d\n",
3178 dev_dbg(hsotg->dev, " utmi_phy_data_width=%d\n",
3179 hw->utmi_phy_data_width);
3180 dev_dbg(hsotg->dev, " num_dev_ep=%d\n",
3182 dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n",
3183 hw->num_dev_perio_in_ep);
3184 dev_dbg(hsotg->dev, " host_channels=%d\n",
3186 dev_dbg(hsotg->dev, " max_transfer_size=%d\n",
3187 hw->max_transfer_size);
3188 dev_dbg(hsotg->dev, " max_packet_count=%d\n",
3189 hw->max_packet_count);
3190 dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n",
3191 hw->nperio_tx_q_depth);
3192 dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n",
3193 hw->host_perio_tx_q_depth);
3194 dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n",
3195 hw->dev_token_q_depth);
3196 dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n",
3197 hw->enable_dynamic_fifo);
3198 dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n",
3199 hw->en_multiple_tx_fifo);
3200 dev_dbg(hsotg->dev, " total_fifo_size=%d\n",
3201 hw->total_fifo_size);
3202 dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n",
3203 hw->host_rx_fifo_size);
3204 dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n",
3205 hw->host_nperio_tx_fifo_size);
3206 dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n",
3207 hw->host_perio_tx_fifo_size);
3208 dev_dbg(hsotg->dev, "\n");
3214 * Sets all parameters to the given value.
3216 * Assumes that the dwc2_core_params struct contains only integers.
3218 void dwc2_set_all_params(struct dwc2_core_params *params, int value)
3220 int *p = (int *)params;
3221 size_t size = sizeof(*params) / sizeof(*p);
3224 for (i = 0; i < size; i++)
3229 u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg)
3231 return hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103;
3234 bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg)
3236 if (readl(hsotg->regs + GSNPSID) == 0xffffffff)
3243 * dwc2_enable_global_interrupts() - Enables the controller's Global
3244 * Interrupt in the AHB Config register
3246 * @hsotg: Programming view of DWC_otg controller
3248 void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg)
3250 u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
3252 ahbcfg |= GAHBCFG_GLBL_INTR_EN;
3253 writel(ahbcfg, hsotg->regs + GAHBCFG);
3257 * dwc2_disable_global_interrupts() - Disables the controller's Global
3258 * Interrupt in the AHB Config register
3260 * @hsotg: Programming view of DWC_otg controller
3262 void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg)
3264 u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
3266 ahbcfg &= ~GAHBCFG_GLBL_INTR_EN;
3267 writel(ahbcfg, hsotg->regs + GAHBCFG);
3270 MODULE_DESCRIPTION("DESIGNWARE HS OTG Core");
3271 MODULE_AUTHOR("Synopsys, Inc.");
3272 MODULE_LICENSE("Dual BSD/GPL");