1*197ba5f4SPaul Zimmerman /* 2*197ba5f4SPaul Zimmerman * core.c - DesignWare HS OTG Controller common routines 3*197ba5f4SPaul Zimmerman * 4*197ba5f4SPaul Zimmerman * Copyright (C) 2004-2013 Synopsys, Inc. 5*197ba5f4SPaul Zimmerman * 6*197ba5f4SPaul Zimmerman * Redistribution and use in source and binary forms, with or without 7*197ba5f4SPaul Zimmerman * modification, are permitted provided that the following conditions 8*197ba5f4SPaul Zimmerman * are met: 9*197ba5f4SPaul Zimmerman * 1. Redistributions of source code must retain the above copyright 10*197ba5f4SPaul Zimmerman * notice, this list of conditions, and the following disclaimer, 11*197ba5f4SPaul Zimmerman * without modification. 12*197ba5f4SPaul Zimmerman * 2. Redistributions in binary form must reproduce the above copyright 13*197ba5f4SPaul Zimmerman * notice, this list of conditions and the following disclaimer in the 14*197ba5f4SPaul Zimmerman * documentation and/or other materials provided with the distribution. 15*197ba5f4SPaul Zimmerman * 3. The names of the above-listed copyright holders may not be used 16*197ba5f4SPaul Zimmerman * to endorse or promote products derived from this software without 17*197ba5f4SPaul Zimmerman * specific prior written permission. 18*197ba5f4SPaul Zimmerman * 19*197ba5f4SPaul Zimmerman * ALTERNATIVELY, this software may be distributed under the terms of the 20*197ba5f4SPaul Zimmerman * GNU General Public License ("GPL") as published by the Free Software 21*197ba5f4SPaul Zimmerman * Foundation; either version 2 of the License, or (at your option) any 22*197ba5f4SPaul Zimmerman * later version. 23*197ba5f4SPaul Zimmerman * 24*197ba5f4SPaul Zimmerman * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25*197ba5f4SPaul Zimmerman * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 26*197ba5f4SPaul Zimmerman * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27*197ba5f4SPaul Zimmerman * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28*197ba5f4SPaul Zimmerman * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29*197ba5f4SPaul Zimmerman * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30*197ba5f4SPaul Zimmerman * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31*197ba5f4SPaul Zimmerman * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32*197ba5f4SPaul Zimmerman * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33*197ba5f4SPaul Zimmerman * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34*197ba5f4SPaul Zimmerman * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35*197ba5f4SPaul Zimmerman */ 36*197ba5f4SPaul Zimmerman 37*197ba5f4SPaul Zimmerman /* 38*197ba5f4SPaul Zimmerman * The Core code provides basic services for accessing and managing the 39*197ba5f4SPaul Zimmerman * DWC_otg hardware. These services are used by both the Host Controller 40*197ba5f4SPaul Zimmerman * Driver and the Peripheral Controller Driver. 41*197ba5f4SPaul Zimmerman */ 42*197ba5f4SPaul Zimmerman #include <linux/kernel.h> 43*197ba5f4SPaul Zimmerman #include <linux/module.h> 44*197ba5f4SPaul Zimmerman #include <linux/moduleparam.h> 45*197ba5f4SPaul Zimmerman #include <linux/spinlock.h> 46*197ba5f4SPaul Zimmerman #include <linux/interrupt.h> 47*197ba5f4SPaul Zimmerman #include <linux/dma-mapping.h> 48*197ba5f4SPaul Zimmerman #include <linux/delay.h> 49*197ba5f4SPaul Zimmerman #include <linux/io.h> 50*197ba5f4SPaul Zimmerman #include <linux/slab.h> 51*197ba5f4SPaul Zimmerman #include <linux/usb.h> 52*197ba5f4SPaul Zimmerman 53*197ba5f4SPaul Zimmerman #include <linux/usb/hcd.h> 54*197ba5f4SPaul Zimmerman #include <linux/usb/ch11.h> 55*197ba5f4SPaul Zimmerman 56*197ba5f4SPaul Zimmerman #include "core.h" 57*197ba5f4SPaul Zimmerman #include "hcd.h" 58*197ba5f4SPaul Zimmerman 59*197ba5f4SPaul Zimmerman /** 60*197ba5f4SPaul Zimmerman * dwc2_enable_common_interrupts() - Initializes the commmon interrupts, 61*197ba5f4SPaul Zimmerman * used in both device and host modes 62*197ba5f4SPaul Zimmerman * 63*197ba5f4SPaul Zimmerman * @hsotg: Programming view of the DWC_otg controller 64*197ba5f4SPaul Zimmerman */ 65*197ba5f4SPaul Zimmerman static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg) 66*197ba5f4SPaul Zimmerman { 67*197ba5f4SPaul Zimmerman u32 intmsk; 68*197ba5f4SPaul Zimmerman 69*197ba5f4SPaul Zimmerman /* Clear any pending OTG Interrupts */ 70*197ba5f4SPaul Zimmerman writel(0xffffffff, hsotg->regs + GOTGINT); 71*197ba5f4SPaul Zimmerman 72*197ba5f4SPaul Zimmerman /* Clear any pending interrupts */ 73*197ba5f4SPaul Zimmerman writel(0xffffffff, hsotg->regs + GINTSTS); 74*197ba5f4SPaul Zimmerman 75*197ba5f4SPaul Zimmerman /* Enable the interrupts in the GINTMSK */ 76*197ba5f4SPaul Zimmerman intmsk = GINTSTS_MODEMIS | GINTSTS_OTGINT; 77*197ba5f4SPaul Zimmerman 78*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable <= 0) 79*197ba5f4SPaul Zimmerman intmsk |= GINTSTS_RXFLVL; 80*197ba5f4SPaul Zimmerman 81*197ba5f4SPaul Zimmerman intmsk |= GINTSTS_CONIDSTSCHNG | GINTSTS_WKUPINT | GINTSTS_USBSUSP | 82*197ba5f4SPaul Zimmerman GINTSTS_SESSREQINT; 83*197ba5f4SPaul Zimmerman 84*197ba5f4SPaul Zimmerman writel(intmsk, hsotg->regs + GINTMSK); 85*197ba5f4SPaul Zimmerman } 86*197ba5f4SPaul Zimmerman 87*197ba5f4SPaul Zimmerman /* 88*197ba5f4SPaul Zimmerman * Initializes the FSLSPClkSel field of the HCFG register depending on the 89*197ba5f4SPaul Zimmerman * PHY type 90*197ba5f4SPaul Zimmerman */ 91*197ba5f4SPaul Zimmerman static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg) 92*197ba5f4SPaul Zimmerman { 93*197ba5f4SPaul Zimmerman u32 hcfg, val; 94*197ba5f4SPaul Zimmerman 95*197ba5f4SPaul Zimmerman if ((hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && 96*197ba5f4SPaul Zimmerman hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && 97*197ba5f4SPaul Zimmerman hsotg->core_params->ulpi_fs_ls > 0) || 98*197ba5f4SPaul Zimmerman hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { 99*197ba5f4SPaul Zimmerman /* Full speed PHY */ 100*197ba5f4SPaul Zimmerman val = HCFG_FSLSPCLKSEL_48_MHZ; 101*197ba5f4SPaul Zimmerman } else { 102*197ba5f4SPaul Zimmerman /* High speed PHY running at full speed or high speed */ 103*197ba5f4SPaul Zimmerman val = HCFG_FSLSPCLKSEL_30_60_MHZ; 104*197ba5f4SPaul Zimmerman } 105*197ba5f4SPaul Zimmerman 106*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Initializing HCFG.FSLSPClkSel to %08x\n", val); 107*197ba5f4SPaul Zimmerman hcfg = readl(hsotg->regs + HCFG); 108*197ba5f4SPaul Zimmerman hcfg &= ~HCFG_FSLSPCLKSEL_MASK; 109*197ba5f4SPaul Zimmerman hcfg |= val << HCFG_FSLSPCLKSEL_SHIFT; 110*197ba5f4SPaul Zimmerman writel(hcfg, hsotg->regs + HCFG); 111*197ba5f4SPaul Zimmerman } 112*197ba5f4SPaul Zimmerman 113*197ba5f4SPaul Zimmerman /* 114*197ba5f4SPaul Zimmerman * Do core a soft reset of the core. Be careful with this because it 115*197ba5f4SPaul Zimmerman * resets all the internal state machines of the core. 116*197ba5f4SPaul Zimmerman */ 117*197ba5f4SPaul Zimmerman static int dwc2_core_reset(struct dwc2_hsotg *hsotg) 118*197ba5f4SPaul Zimmerman { 119*197ba5f4SPaul Zimmerman u32 greset; 120*197ba5f4SPaul Zimmerman int count = 0; 121*197ba5f4SPaul Zimmerman 122*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 123*197ba5f4SPaul Zimmerman 124*197ba5f4SPaul Zimmerman /* Wait for AHB master IDLE state */ 125*197ba5f4SPaul Zimmerman do { 126*197ba5f4SPaul Zimmerman usleep_range(20000, 40000); 127*197ba5f4SPaul Zimmerman greset = readl(hsotg->regs + GRSTCTL); 128*197ba5f4SPaul Zimmerman if (++count > 50) { 129*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, 130*197ba5f4SPaul Zimmerman "%s() HANG! AHB Idle GRSTCTL=%0x\n", 131*197ba5f4SPaul Zimmerman __func__, greset); 132*197ba5f4SPaul Zimmerman return -EBUSY; 133*197ba5f4SPaul Zimmerman } 134*197ba5f4SPaul Zimmerman } while (!(greset & GRSTCTL_AHBIDLE)); 135*197ba5f4SPaul Zimmerman 136*197ba5f4SPaul Zimmerman /* Core Soft Reset */ 137*197ba5f4SPaul Zimmerman count = 0; 138*197ba5f4SPaul Zimmerman greset |= GRSTCTL_CSFTRST; 139*197ba5f4SPaul Zimmerman writel(greset, hsotg->regs + GRSTCTL); 140*197ba5f4SPaul Zimmerman do { 141*197ba5f4SPaul Zimmerman usleep_range(20000, 40000); 142*197ba5f4SPaul Zimmerman greset = readl(hsotg->regs + GRSTCTL); 143*197ba5f4SPaul Zimmerman if (++count > 50) { 144*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, 145*197ba5f4SPaul Zimmerman "%s() HANG! Soft Reset GRSTCTL=%0x\n", 146*197ba5f4SPaul Zimmerman __func__, greset); 147*197ba5f4SPaul Zimmerman return -EBUSY; 148*197ba5f4SPaul Zimmerman } 149*197ba5f4SPaul Zimmerman } while (greset & GRSTCTL_CSFTRST); 150*197ba5f4SPaul Zimmerman 151*197ba5f4SPaul Zimmerman /* 152*197ba5f4SPaul Zimmerman * NOTE: This long sleep is _very_ important, otherwise the core will 153*197ba5f4SPaul Zimmerman * not stay in host mode after a connector ID change! 154*197ba5f4SPaul Zimmerman */ 155*197ba5f4SPaul Zimmerman usleep_range(150000, 200000); 156*197ba5f4SPaul Zimmerman 157*197ba5f4SPaul Zimmerman return 0; 158*197ba5f4SPaul Zimmerman } 159*197ba5f4SPaul Zimmerman 160*197ba5f4SPaul Zimmerman static int dwc2_fs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 161*197ba5f4SPaul Zimmerman { 162*197ba5f4SPaul Zimmerman u32 usbcfg, i2cctl; 163*197ba5f4SPaul Zimmerman int retval = 0; 164*197ba5f4SPaul Zimmerman 165*197ba5f4SPaul Zimmerman /* 166*197ba5f4SPaul Zimmerman * core_init() is now called on every switch so only call the 167*197ba5f4SPaul Zimmerman * following for the first time through 168*197ba5f4SPaul Zimmerman */ 169*197ba5f4SPaul Zimmerman if (select_phy) { 170*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "FS PHY selected\n"); 171*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 172*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_PHYSEL; 173*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 174*197ba5f4SPaul Zimmerman 175*197ba5f4SPaul Zimmerman /* Reset after a PHY select */ 176*197ba5f4SPaul Zimmerman retval = dwc2_core_reset(hsotg); 177*197ba5f4SPaul Zimmerman if (retval) { 178*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "%s() Reset failed, aborting", 179*197ba5f4SPaul Zimmerman __func__); 180*197ba5f4SPaul Zimmerman return retval; 181*197ba5f4SPaul Zimmerman } 182*197ba5f4SPaul Zimmerman } 183*197ba5f4SPaul Zimmerman 184*197ba5f4SPaul Zimmerman /* 185*197ba5f4SPaul Zimmerman * Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also 186*197ba5f4SPaul Zimmerman * do this on HNP Dev/Host mode switches (done in dev_init and 187*197ba5f4SPaul Zimmerman * host_init). 188*197ba5f4SPaul Zimmerman */ 189*197ba5f4SPaul Zimmerman if (dwc2_is_host_mode(hsotg)) 190*197ba5f4SPaul Zimmerman dwc2_init_fs_ls_pclk_sel(hsotg); 191*197ba5f4SPaul Zimmerman 192*197ba5f4SPaul Zimmerman if (hsotg->core_params->i2c_enable > 0) { 193*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "FS PHY enabling I2C\n"); 194*197ba5f4SPaul Zimmerman 195*197ba5f4SPaul Zimmerman /* Program GUSBCFG.OtgUtmiFsSel to I2C */ 196*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 197*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_OTG_UTMI_FS_SEL; 198*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 199*197ba5f4SPaul Zimmerman 200*197ba5f4SPaul Zimmerman /* Program GI2CCTL.I2CEn */ 201*197ba5f4SPaul Zimmerman i2cctl = readl(hsotg->regs + GI2CCTL); 202*197ba5f4SPaul Zimmerman i2cctl &= ~GI2CCTL_I2CDEVADDR_MASK; 203*197ba5f4SPaul Zimmerman i2cctl |= 1 << GI2CCTL_I2CDEVADDR_SHIFT; 204*197ba5f4SPaul Zimmerman i2cctl &= ~GI2CCTL_I2CEN; 205*197ba5f4SPaul Zimmerman writel(i2cctl, hsotg->regs + GI2CCTL); 206*197ba5f4SPaul Zimmerman i2cctl |= GI2CCTL_I2CEN; 207*197ba5f4SPaul Zimmerman writel(i2cctl, hsotg->regs + GI2CCTL); 208*197ba5f4SPaul Zimmerman } 209*197ba5f4SPaul Zimmerman 210*197ba5f4SPaul Zimmerman return retval; 211*197ba5f4SPaul Zimmerman } 212*197ba5f4SPaul Zimmerman 213*197ba5f4SPaul Zimmerman static int dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 214*197ba5f4SPaul Zimmerman { 215*197ba5f4SPaul Zimmerman u32 usbcfg; 216*197ba5f4SPaul Zimmerman int retval = 0; 217*197ba5f4SPaul Zimmerman 218*197ba5f4SPaul Zimmerman if (!select_phy) 219*197ba5f4SPaul Zimmerman return -ENODEV; 220*197ba5f4SPaul Zimmerman 221*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 222*197ba5f4SPaul Zimmerman 223*197ba5f4SPaul Zimmerman /* 224*197ba5f4SPaul Zimmerman * HS PHY parameters. These parameters are preserved during soft reset 225*197ba5f4SPaul Zimmerman * so only program the first time. Do a soft reset immediately after 226*197ba5f4SPaul Zimmerman * setting phyif. 227*197ba5f4SPaul Zimmerman */ 228*197ba5f4SPaul Zimmerman switch (hsotg->core_params->phy_type) { 229*197ba5f4SPaul Zimmerman case DWC2_PHY_TYPE_PARAM_ULPI: 230*197ba5f4SPaul Zimmerman /* ULPI interface */ 231*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HS ULPI PHY selected\n"); 232*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_ULPI_UTMI_SEL; 233*197ba5f4SPaul Zimmerman usbcfg &= ~(GUSBCFG_PHYIF16 | GUSBCFG_DDRSEL); 234*197ba5f4SPaul Zimmerman if (hsotg->core_params->phy_ulpi_ddr > 0) 235*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_DDRSEL; 236*197ba5f4SPaul Zimmerman break; 237*197ba5f4SPaul Zimmerman case DWC2_PHY_TYPE_PARAM_UTMI: 238*197ba5f4SPaul Zimmerman /* UTMI+ interface */ 239*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HS UTMI+ PHY selected\n"); 240*197ba5f4SPaul Zimmerman usbcfg &= ~(GUSBCFG_ULPI_UTMI_SEL | GUSBCFG_PHYIF16); 241*197ba5f4SPaul Zimmerman if (hsotg->core_params->phy_utmi_width == 16) 242*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_PHYIF16; 243*197ba5f4SPaul Zimmerman break; 244*197ba5f4SPaul Zimmerman default: 245*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "FS PHY selected at HS!\n"); 246*197ba5f4SPaul Zimmerman break; 247*197ba5f4SPaul Zimmerman } 248*197ba5f4SPaul Zimmerman 249*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 250*197ba5f4SPaul Zimmerman 251*197ba5f4SPaul Zimmerman /* Reset after setting the PHY parameters */ 252*197ba5f4SPaul Zimmerman retval = dwc2_core_reset(hsotg); 253*197ba5f4SPaul Zimmerman if (retval) { 254*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "%s() Reset failed, aborting", 255*197ba5f4SPaul Zimmerman __func__); 256*197ba5f4SPaul Zimmerman return retval; 257*197ba5f4SPaul Zimmerman } 258*197ba5f4SPaul Zimmerman 259*197ba5f4SPaul Zimmerman return retval; 260*197ba5f4SPaul Zimmerman } 261*197ba5f4SPaul Zimmerman 262*197ba5f4SPaul Zimmerman static int dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 263*197ba5f4SPaul Zimmerman { 264*197ba5f4SPaul Zimmerman u32 usbcfg; 265*197ba5f4SPaul Zimmerman int retval = 0; 266*197ba5f4SPaul Zimmerman 267*197ba5f4SPaul Zimmerman if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL && 268*197ba5f4SPaul Zimmerman hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { 269*197ba5f4SPaul Zimmerman /* If FS mode with FS PHY */ 270*197ba5f4SPaul Zimmerman retval = dwc2_fs_phy_init(hsotg, select_phy); 271*197ba5f4SPaul Zimmerman if (retval) 272*197ba5f4SPaul Zimmerman return retval; 273*197ba5f4SPaul Zimmerman } else { 274*197ba5f4SPaul Zimmerman /* High speed PHY */ 275*197ba5f4SPaul Zimmerman retval = dwc2_hs_phy_init(hsotg, select_phy); 276*197ba5f4SPaul Zimmerman if (retval) 277*197ba5f4SPaul Zimmerman return retval; 278*197ba5f4SPaul Zimmerman } 279*197ba5f4SPaul Zimmerman 280*197ba5f4SPaul Zimmerman if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && 281*197ba5f4SPaul Zimmerman hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && 282*197ba5f4SPaul Zimmerman hsotg->core_params->ulpi_fs_ls > 0) { 283*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting ULPI FSLS\n"); 284*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 285*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_ULPI_FS_LS; 286*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_ULPI_CLK_SUSP_M; 287*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 288*197ba5f4SPaul Zimmerman } else { 289*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 290*197ba5f4SPaul Zimmerman usbcfg &= ~GUSBCFG_ULPI_FS_LS; 291*197ba5f4SPaul Zimmerman usbcfg &= ~GUSBCFG_ULPI_CLK_SUSP_M; 292*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 293*197ba5f4SPaul Zimmerman } 294*197ba5f4SPaul Zimmerman 295*197ba5f4SPaul Zimmerman return retval; 296*197ba5f4SPaul Zimmerman } 297*197ba5f4SPaul Zimmerman 298*197ba5f4SPaul Zimmerman static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg) 299*197ba5f4SPaul Zimmerman { 300*197ba5f4SPaul Zimmerman u32 ahbcfg = readl(hsotg->regs + GAHBCFG); 301*197ba5f4SPaul Zimmerman 302*197ba5f4SPaul Zimmerman switch (hsotg->hw_params.arch) { 303*197ba5f4SPaul Zimmerman case GHWCFG2_EXT_DMA_ARCH: 304*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "External DMA Mode not supported\n"); 305*197ba5f4SPaul Zimmerman return -EINVAL; 306*197ba5f4SPaul Zimmerman 307*197ba5f4SPaul Zimmerman case GHWCFG2_INT_DMA_ARCH: 308*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Internal DMA Mode\n"); 309*197ba5f4SPaul Zimmerman if (hsotg->core_params->ahbcfg != -1) { 310*197ba5f4SPaul Zimmerman ahbcfg &= GAHBCFG_CTRL_MASK; 311*197ba5f4SPaul Zimmerman ahbcfg |= hsotg->core_params->ahbcfg & 312*197ba5f4SPaul Zimmerman ~GAHBCFG_CTRL_MASK; 313*197ba5f4SPaul Zimmerman } 314*197ba5f4SPaul Zimmerman break; 315*197ba5f4SPaul Zimmerman 316*197ba5f4SPaul Zimmerman case GHWCFG2_SLAVE_ONLY_ARCH: 317*197ba5f4SPaul Zimmerman default: 318*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Slave Only Mode\n"); 319*197ba5f4SPaul Zimmerman break; 320*197ba5f4SPaul Zimmerman } 321*197ba5f4SPaul Zimmerman 322*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "dma_enable:%d dma_desc_enable:%d\n", 323*197ba5f4SPaul Zimmerman hsotg->core_params->dma_enable, 324*197ba5f4SPaul Zimmerman hsotg->core_params->dma_desc_enable); 325*197ba5f4SPaul Zimmerman 326*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable > 0) { 327*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable > 0) 328*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Using Descriptor DMA mode\n"); 329*197ba5f4SPaul Zimmerman else 330*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Using Buffer DMA mode\n"); 331*197ba5f4SPaul Zimmerman } else { 332*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Using Slave mode\n"); 333*197ba5f4SPaul Zimmerman hsotg->core_params->dma_desc_enable = 0; 334*197ba5f4SPaul Zimmerman } 335*197ba5f4SPaul Zimmerman 336*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable > 0) 337*197ba5f4SPaul Zimmerman ahbcfg |= GAHBCFG_DMA_EN; 338*197ba5f4SPaul Zimmerman 339*197ba5f4SPaul Zimmerman writel(ahbcfg, hsotg->regs + GAHBCFG); 340*197ba5f4SPaul Zimmerman 341*197ba5f4SPaul Zimmerman return 0; 342*197ba5f4SPaul Zimmerman } 343*197ba5f4SPaul Zimmerman 344*197ba5f4SPaul Zimmerman static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg) 345*197ba5f4SPaul Zimmerman { 346*197ba5f4SPaul Zimmerman u32 usbcfg; 347*197ba5f4SPaul Zimmerman 348*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 349*197ba5f4SPaul Zimmerman usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP); 350*197ba5f4SPaul Zimmerman 351*197ba5f4SPaul Zimmerman switch (hsotg->hw_params.op_mode) { 352*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 353*197ba5f4SPaul Zimmerman if (hsotg->core_params->otg_cap == 354*197ba5f4SPaul Zimmerman DWC2_CAP_PARAM_HNP_SRP_CAPABLE) 355*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_HNPCAP; 356*197ba5f4SPaul Zimmerman if (hsotg->core_params->otg_cap != 357*197ba5f4SPaul Zimmerman DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) 358*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_SRPCAP; 359*197ba5f4SPaul Zimmerman break; 360*197ba5f4SPaul Zimmerman 361*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 362*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 363*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 364*197ba5f4SPaul Zimmerman if (hsotg->core_params->otg_cap != 365*197ba5f4SPaul Zimmerman DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE) 366*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_SRPCAP; 367*197ba5f4SPaul Zimmerman break; 368*197ba5f4SPaul Zimmerman 369*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE: 370*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE: 371*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST: 372*197ba5f4SPaul Zimmerman default: 373*197ba5f4SPaul Zimmerman break; 374*197ba5f4SPaul Zimmerman } 375*197ba5f4SPaul Zimmerman 376*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 377*197ba5f4SPaul Zimmerman } 378*197ba5f4SPaul Zimmerman 379*197ba5f4SPaul Zimmerman /** 380*197ba5f4SPaul Zimmerman * dwc2_core_init() - Initializes the DWC_otg controller registers and 381*197ba5f4SPaul Zimmerman * prepares the core for device mode or host mode operation 382*197ba5f4SPaul Zimmerman * 383*197ba5f4SPaul Zimmerman * @hsotg: Programming view of the DWC_otg controller 384*197ba5f4SPaul Zimmerman * @select_phy: If true then also set the Phy type 385*197ba5f4SPaul Zimmerman * @irq: If >= 0, the irq to register 386*197ba5f4SPaul Zimmerman */ 387*197ba5f4SPaul Zimmerman int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq) 388*197ba5f4SPaul Zimmerman { 389*197ba5f4SPaul Zimmerman u32 usbcfg, otgctl; 390*197ba5f4SPaul Zimmerman int retval; 391*197ba5f4SPaul Zimmerman 392*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); 393*197ba5f4SPaul Zimmerman 394*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 395*197ba5f4SPaul Zimmerman 396*197ba5f4SPaul Zimmerman /* Set ULPI External VBUS bit if needed */ 397*197ba5f4SPaul Zimmerman usbcfg &= ~GUSBCFG_ULPI_EXT_VBUS_DRV; 398*197ba5f4SPaul Zimmerman if (hsotg->core_params->phy_ulpi_ext_vbus == 399*197ba5f4SPaul Zimmerman DWC2_PHY_ULPI_EXTERNAL_VBUS) 400*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_ULPI_EXT_VBUS_DRV; 401*197ba5f4SPaul Zimmerman 402*197ba5f4SPaul Zimmerman /* Set external TS Dline pulsing bit if needed */ 403*197ba5f4SPaul Zimmerman usbcfg &= ~GUSBCFG_TERMSELDLPULSE; 404*197ba5f4SPaul Zimmerman if (hsotg->core_params->ts_dline > 0) 405*197ba5f4SPaul Zimmerman usbcfg |= GUSBCFG_TERMSELDLPULSE; 406*197ba5f4SPaul Zimmerman 407*197ba5f4SPaul Zimmerman writel(usbcfg, hsotg->regs + GUSBCFG); 408*197ba5f4SPaul Zimmerman 409*197ba5f4SPaul Zimmerman /* Reset the Controller */ 410*197ba5f4SPaul Zimmerman retval = dwc2_core_reset(hsotg); 411*197ba5f4SPaul Zimmerman if (retval) { 412*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "%s(): Reset failed, aborting\n", 413*197ba5f4SPaul Zimmerman __func__); 414*197ba5f4SPaul Zimmerman return retval; 415*197ba5f4SPaul Zimmerman } 416*197ba5f4SPaul Zimmerman 417*197ba5f4SPaul Zimmerman /* 418*197ba5f4SPaul Zimmerman * This needs to happen in FS mode before any other programming occurs 419*197ba5f4SPaul Zimmerman */ 420*197ba5f4SPaul Zimmerman retval = dwc2_phy_init(hsotg, select_phy); 421*197ba5f4SPaul Zimmerman if (retval) 422*197ba5f4SPaul Zimmerman return retval; 423*197ba5f4SPaul Zimmerman 424*197ba5f4SPaul Zimmerman /* Program the GAHBCFG Register */ 425*197ba5f4SPaul Zimmerman retval = dwc2_gahbcfg_init(hsotg); 426*197ba5f4SPaul Zimmerman if (retval) 427*197ba5f4SPaul Zimmerman return retval; 428*197ba5f4SPaul Zimmerman 429*197ba5f4SPaul Zimmerman /* Program the GUSBCFG register */ 430*197ba5f4SPaul Zimmerman dwc2_gusbcfg_init(hsotg); 431*197ba5f4SPaul Zimmerman 432*197ba5f4SPaul Zimmerman /* Program the GOTGCTL register */ 433*197ba5f4SPaul Zimmerman otgctl = readl(hsotg->regs + GOTGCTL); 434*197ba5f4SPaul Zimmerman otgctl &= ~GOTGCTL_OTGVER; 435*197ba5f4SPaul Zimmerman if (hsotg->core_params->otg_ver > 0) 436*197ba5f4SPaul Zimmerman otgctl |= GOTGCTL_OTGVER; 437*197ba5f4SPaul Zimmerman writel(otgctl, hsotg->regs + GOTGCTL); 438*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "OTG VER PARAM: %d\n", hsotg->core_params->otg_ver); 439*197ba5f4SPaul Zimmerman 440*197ba5f4SPaul Zimmerman /* Clear the SRP success bit for FS-I2c */ 441*197ba5f4SPaul Zimmerman hsotg->srp_success = 0; 442*197ba5f4SPaul Zimmerman 443*197ba5f4SPaul Zimmerman if (irq >= 0) { 444*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "registering common handler for irq%d\n", 445*197ba5f4SPaul Zimmerman irq); 446*197ba5f4SPaul Zimmerman retval = devm_request_irq(hsotg->dev, irq, 447*197ba5f4SPaul Zimmerman dwc2_handle_common_intr, IRQF_SHARED, 448*197ba5f4SPaul Zimmerman dev_name(hsotg->dev), hsotg); 449*197ba5f4SPaul Zimmerman if (retval) 450*197ba5f4SPaul Zimmerman return retval; 451*197ba5f4SPaul Zimmerman } 452*197ba5f4SPaul Zimmerman 453*197ba5f4SPaul Zimmerman /* Enable common interrupts */ 454*197ba5f4SPaul Zimmerman dwc2_enable_common_interrupts(hsotg); 455*197ba5f4SPaul Zimmerman 456*197ba5f4SPaul Zimmerman /* 457*197ba5f4SPaul Zimmerman * Do device or host intialization based on mode during PCD and 458*197ba5f4SPaul Zimmerman * HCD initialization 459*197ba5f4SPaul Zimmerman */ 460*197ba5f4SPaul Zimmerman if (dwc2_is_host_mode(hsotg)) { 461*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Host Mode\n"); 462*197ba5f4SPaul Zimmerman hsotg->op_state = OTG_STATE_A_HOST; 463*197ba5f4SPaul Zimmerman } else { 464*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Device Mode\n"); 465*197ba5f4SPaul Zimmerman hsotg->op_state = OTG_STATE_B_PERIPHERAL; 466*197ba5f4SPaul Zimmerman } 467*197ba5f4SPaul Zimmerman 468*197ba5f4SPaul Zimmerman return 0; 469*197ba5f4SPaul Zimmerman } 470*197ba5f4SPaul Zimmerman 471*197ba5f4SPaul Zimmerman /** 472*197ba5f4SPaul Zimmerman * dwc2_enable_host_interrupts() - Enables the Host mode interrupts 473*197ba5f4SPaul Zimmerman * 474*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 475*197ba5f4SPaul Zimmerman */ 476*197ba5f4SPaul Zimmerman void dwc2_enable_host_interrupts(struct dwc2_hsotg *hsotg) 477*197ba5f4SPaul Zimmerman { 478*197ba5f4SPaul Zimmerman u32 intmsk; 479*197ba5f4SPaul Zimmerman 480*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "%s()\n", __func__); 481*197ba5f4SPaul Zimmerman 482*197ba5f4SPaul Zimmerman /* Disable all interrupts */ 483*197ba5f4SPaul Zimmerman writel(0, hsotg->regs + GINTMSK); 484*197ba5f4SPaul Zimmerman writel(0, hsotg->regs + HAINTMSK); 485*197ba5f4SPaul Zimmerman 486*197ba5f4SPaul Zimmerman /* Enable the common interrupts */ 487*197ba5f4SPaul Zimmerman dwc2_enable_common_interrupts(hsotg); 488*197ba5f4SPaul Zimmerman 489*197ba5f4SPaul Zimmerman /* Enable host mode interrupts without disturbing common interrupts */ 490*197ba5f4SPaul Zimmerman intmsk = readl(hsotg->regs + GINTMSK); 491*197ba5f4SPaul Zimmerman intmsk |= GINTSTS_DISCONNINT | GINTSTS_PRTINT | GINTSTS_HCHINT; 492*197ba5f4SPaul Zimmerman writel(intmsk, hsotg->regs + GINTMSK); 493*197ba5f4SPaul Zimmerman } 494*197ba5f4SPaul Zimmerman 495*197ba5f4SPaul Zimmerman /** 496*197ba5f4SPaul Zimmerman * dwc2_disable_host_interrupts() - Disables the Host Mode interrupts 497*197ba5f4SPaul Zimmerman * 498*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 499*197ba5f4SPaul Zimmerman */ 500*197ba5f4SPaul Zimmerman void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg) 501*197ba5f4SPaul Zimmerman { 502*197ba5f4SPaul Zimmerman u32 intmsk = readl(hsotg->regs + GINTMSK); 503*197ba5f4SPaul Zimmerman 504*197ba5f4SPaul Zimmerman /* Disable host mode interrupts without disturbing common interrupts */ 505*197ba5f4SPaul Zimmerman intmsk &= ~(GINTSTS_SOF | GINTSTS_PRTINT | GINTSTS_HCHINT | 506*197ba5f4SPaul Zimmerman GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP); 507*197ba5f4SPaul Zimmerman writel(intmsk, hsotg->regs + GINTMSK); 508*197ba5f4SPaul Zimmerman } 509*197ba5f4SPaul Zimmerman 510*197ba5f4SPaul Zimmerman static void dwc2_config_fifos(struct dwc2_hsotg *hsotg) 511*197ba5f4SPaul Zimmerman { 512*197ba5f4SPaul Zimmerman struct dwc2_core_params *params = hsotg->core_params; 513*197ba5f4SPaul Zimmerman u32 nptxfsiz, hptxfsiz, dfifocfg, grxfsiz; 514*197ba5f4SPaul Zimmerman 515*197ba5f4SPaul Zimmerman if (!params->enable_dynamic_fifo) 516*197ba5f4SPaul Zimmerman return; 517*197ba5f4SPaul Zimmerman 518*197ba5f4SPaul Zimmerman /* Rx FIFO */ 519*197ba5f4SPaul Zimmerman grxfsiz = readl(hsotg->regs + GRXFSIZ); 520*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); 521*197ba5f4SPaul Zimmerman grxfsiz &= ~GRXFSIZ_DEPTH_MASK; 522*197ba5f4SPaul Zimmerman grxfsiz |= params->host_rx_fifo_size << 523*197ba5f4SPaul Zimmerman GRXFSIZ_DEPTH_SHIFT & GRXFSIZ_DEPTH_MASK; 524*197ba5f4SPaul Zimmerman writel(grxfsiz, hsotg->regs + GRXFSIZ); 525*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "new grxfsiz=%08x\n", readl(hsotg->regs + GRXFSIZ)); 526*197ba5f4SPaul Zimmerman 527*197ba5f4SPaul Zimmerman /* Non-periodic Tx FIFO */ 528*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "initial gnptxfsiz=%08x\n", 529*197ba5f4SPaul Zimmerman readl(hsotg->regs + GNPTXFSIZ)); 530*197ba5f4SPaul Zimmerman nptxfsiz = params->host_nperio_tx_fifo_size << 531*197ba5f4SPaul Zimmerman FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; 532*197ba5f4SPaul Zimmerman nptxfsiz |= params->host_rx_fifo_size << 533*197ba5f4SPaul Zimmerman FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; 534*197ba5f4SPaul Zimmerman writel(nptxfsiz, hsotg->regs + GNPTXFSIZ); 535*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "new gnptxfsiz=%08x\n", 536*197ba5f4SPaul Zimmerman readl(hsotg->regs + GNPTXFSIZ)); 537*197ba5f4SPaul Zimmerman 538*197ba5f4SPaul Zimmerman /* Periodic Tx FIFO */ 539*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "initial hptxfsiz=%08x\n", 540*197ba5f4SPaul Zimmerman readl(hsotg->regs + HPTXFSIZ)); 541*197ba5f4SPaul Zimmerman hptxfsiz = params->host_perio_tx_fifo_size << 542*197ba5f4SPaul Zimmerman FIFOSIZE_DEPTH_SHIFT & FIFOSIZE_DEPTH_MASK; 543*197ba5f4SPaul Zimmerman hptxfsiz |= (params->host_rx_fifo_size + 544*197ba5f4SPaul Zimmerman params->host_nperio_tx_fifo_size) << 545*197ba5f4SPaul Zimmerman FIFOSIZE_STARTADDR_SHIFT & FIFOSIZE_STARTADDR_MASK; 546*197ba5f4SPaul Zimmerman writel(hptxfsiz, hsotg->regs + HPTXFSIZ); 547*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "new hptxfsiz=%08x\n", 548*197ba5f4SPaul Zimmerman readl(hsotg->regs + HPTXFSIZ)); 549*197ba5f4SPaul Zimmerman 550*197ba5f4SPaul Zimmerman if (hsotg->core_params->en_multiple_tx_fifo > 0 && 551*197ba5f4SPaul Zimmerman hsotg->hw_params.snpsid <= DWC2_CORE_REV_2_94a) { 552*197ba5f4SPaul Zimmerman /* 553*197ba5f4SPaul Zimmerman * Global DFIFOCFG calculation for Host mode - 554*197ba5f4SPaul Zimmerman * include RxFIFO, NPTXFIFO and HPTXFIFO 555*197ba5f4SPaul Zimmerman */ 556*197ba5f4SPaul Zimmerman dfifocfg = readl(hsotg->regs + GDFIFOCFG); 557*197ba5f4SPaul Zimmerman dfifocfg &= ~GDFIFOCFG_EPINFOBASE_MASK; 558*197ba5f4SPaul Zimmerman dfifocfg |= (params->host_rx_fifo_size + 559*197ba5f4SPaul Zimmerman params->host_nperio_tx_fifo_size + 560*197ba5f4SPaul Zimmerman params->host_perio_tx_fifo_size) << 561*197ba5f4SPaul Zimmerman GDFIFOCFG_EPINFOBASE_SHIFT & 562*197ba5f4SPaul Zimmerman GDFIFOCFG_EPINFOBASE_MASK; 563*197ba5f4SPaul Zimmerman writel(dfifocfg, hsotg->regs + GDFIFOCFG); 564*197ba5f4SPaul Zimmerman } 565*197ba5f4SPaul Zimmerman } 566*197ba5f4SPaul Zimmerman 567*197ba5f4SPaul Zimmerman /** 568*197ba5f4SPaul Zimmerman * dwc2_core_host_init() - Initializes the DWC_otg controller registers for 569*197ba5f4SPaul Zimmerman * Host mode 570*197ba5f4SPaul Zimmerman * 571*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 572*197ba5f4SPaul Zimmerman * 573*197ba5f4SPaul Zimmerman * This function flushes the Tx and Rx FIFOs and flushes any entries in the 574*197ba5f4SPaul Zimmerman * request queues. Host channels are reset to ensure that they are ready for 575*197ba5f4SPaul Zimmerman * performing transfers. 576*197ba5f4SPaul Zimmerman */ 577*197ba5f4SPaul Zimmerman void dwc2_core_host_init(struct dwc2_hsotg *hsotg) 578*197ba5f4SPaul Zimmerman { 579*197ba5f4SPaul Zimmerman u32 hcfg, hfir, otgctl; 580*197ba5f4SPaul Zimmerman 581*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "%s(%p)\n", __func__, hsotg); 582*197ba5f4SPaul Zimmerman 583*197ba5f4SPaul Zimmerman /* Restart the Phy Clock */ 584*197ba5f4SPaul Zimmerman writel(0, hsotg->regs + PCGCTL); 585*197ba5f4SPaul Zimmerman 586*197ba5f4SPaul Zimmerman /* Initialize Host Configuration Register */ 587*197ba5f4SPaul Zimmerman dwc2_init_fs_ls_pclk_sel(hsotg); 588*197ba5f4SPaul Zimmerman if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL) { 589*197ba5f4SPaul Zimmerman hcfg = readl(hsotg->regs + HCFG); 590*197ba5f4SPaul Zimmerman hcfg |= HCFG_FSLSSUPP; 591*197ba5f4SPaul Zimmerman writel(hcfg, hsotg->regs + HCFG); 592*197ba5f4SPaul Zimmerman } 593*197ba5f4SPaul Zimmerman 594*197ba5f4SPaul Zimmerman /* 595*197ba5f4SPaul Zimmerman * This bit allows dynamic reloading of the HFIR register during 596*197ba5f4SPaul Zimmerman * runtime. This bit needs to be programmed during initial configuration 597*197ba5f4SPaul Zimmerman * and its value must not be changed during runtime. 598*197ba5f4SPaul Zimmerman */ 599*197ba5f4SPaul Zimmerman if (hsotg->core_params->reload_ctl > 0) { 600*197ba5f4SPaul Zimmerman hfir = readl(hsotg->regs + HFIR); 601*197ba5f4SPaul Zimmerman hfir |= HFIR_RLDCTRL; 602*197ba5f4SPaul Zimmerman writel(hfir, hsotg->regs + HFIR); 603*197ba5f4SPaul Zimmerman } 604*197ba5f4SPaul Zimmerman 605*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable > 0) { 606*197ba5f4SPaul Zimmerman u32 op_mode = hsotg->hw_params.op_mode; 607*197ba5f4SPaul Zimmerman if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a || 608*197ba5f4SPaul Zimmerman !hsotg->hw_params.dma_desc_enable || 609*197ba5f4SPaul Zimmerman op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE || 610*197ba5f4SPaul Zimmerman op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE || 611*197ba5f4SPaul Zimmerman op_mode == GHWCFG2_OP_MODE_UNDEFINED) { 612*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 613*197ba5f4SPaul Zimmerman "Hardware does not support descriptor DMA mode -\n"); 614*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 615*197ba5f4SPaul Zimmerman "falling back to buffer DMA mode.\n"); 616*197ba5f4SPaul Zimmerman hsotg->core_params->dma_desc_enable = 0; 617*197ba5f4SPaul Zimmerman } else { 618*197ba5f4SPaul Zimmerman hcfg = readl(hsotg->regs + HCFG); 619*197ba5f4SPaul Zimmerman hcfg |= HCFG_DESCDMA; 620*197ba5f4SPaul Zimmerman writel(hcfg, hsotg->regs + HCFG); 621*197ba5f4SPaul Zimmerman } 622*197ba5f4SPaul Zimmerman } 623*197ba5f4SPaul Zimmerman 624*197ba5f4SPaul Zimmerman /* Configure data FIFO sizes */ 625*197ba5f4SPaul Zimmerman dwc2_config_fifos(hsotg); 626*197ba5f4SPaul Zimmerman 627*197ba5f4SPaul Zimmerman /* TODO - check this */ 628*197ba5f4SPaul Zimmerman /* Clear Host Set HNP Enable in the OTG Control Register */ 629*197ba5f4SPaul Zimmerman otgctl = readl(hsotg->regs + GOTGCTL); 630*197ba5f4SPaul Zimmerman otgctl &= ~GOTGCTL_HSTSETHNPEN; 631*197ba5f4SPaul Zimmerman writel(otgctl, hsotg->regs + GOTGCTL); 632*197ba5f4SPaul Zimmerman 633*197ba5f4SPaul Zimmerman /* Make sure the FIFOs are flushed */ 634*197ba5f4SPaul Zimmerman dwc2_flush_tx_fifo(hsotg, 0x10 /* all TX FIFOs */); 635*197ba5f4SPaul Zimmerman dwc2_flush_rx_fifo(hsotg); 636*197ba5f4SPaul Zimmerman 637*197ba5f4SPaul Zimmerman /* Clear Host Set HNP Enable in the OTG Control Register */ 638*197ba5f4SPaul Zimmerman otgctl = readl(hsotg->regs + GOTGCTL); 639*197ba5f4SPaul Zimmerman otgctl &= ~GOTGCTL_HSTSETHNPEN; 640*197ba5f4SPaul Zimmerman writel(otgctl, hsotg->regs + GOTGCTL); 641*197ba5f4SPaul Zimmerman 642*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable <= 0) { 643*197ba5f4SPaul Zimmerman int num_channels, i; 644*197ba5f4SPaul Zimmerman u32 hcchar; 645*197ba5f4SPaul Zimmerman 646*197ba5f4SPaul Zimmerman /* Flush out any leftover queued requests */ 647*197ba5f4SPaul Zimmerman num_channels = hsotg->core_params->host_channels; 648*197ba5f4SPaul Zimmerman for (i = 0; i < num_channels; i++) { 649*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(i)); 650*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHENA; 651*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHDIS; 652*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_EPDIR; 653*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(i)); 654*197ba5f4SPaul Zimmerman } 655*197ba5f4SPaul Zimmerman 656*197ba5f4SPaul Zimmerman /* Halt all channels to put them into a known state */ 657*197ba5f4SPaul Zimmerman for (i = 0; i < num_channels; i++) { 658*197ba5f4SPaul Zimmerman int count = 0; 659*197ba5f4SPaul Zimmerman 660*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(i)); 661*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA | HCCHAR_CHDIS; 662*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_EPDIR; 663*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(i)); 664*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "%s: Halt channel %d\n", 665*197ba5f4SPaul Zimmerman __func__, i); 666*197ba5f4SPaul Zimmerman do { 667*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(i)); 668*197ba5f4SPaul Zimmerman if (++count > 1000) { 669*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 670*197ba5f4SPaul Zimmerman "Unable to clear enable on channel %d\n", 671*197ba5f4SPaul Zimmerman i); 672*197ba5f4SPaul Zimmerman break; 673*197ba5f4SPaul Zimmerman } 674*197ba5f4SPaul Zimmerman udelay(1); 675*197ba5f4SPaul Zimmerman } while (hcchar & HCCHAR_CHENA); 676*197ba5f4SPaul Zimmerman } 677*197ba5f4SPaul Zimmerman } 678*197ba5f4SPaul Zimmerman 679*197ba5f4SPaul Zimmerman /* Turn on the vbus power */ 680*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Init: Port Power? op_state=%d\n", hsotg->op_state); 681*197ba5f4SPaul Zimmerman if (hsotg->op_state == OTG_STATE_A_HOST) { 682*197ba5f4SPaul Zimmerman u32 hprt0 = dwc2_read_hprt0(hsotg); 683*197ba5f4SPaul Zimmerman 684*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Init: Power Port (%d)\n", 685*197ba5f4SPaul Zimmerman !!(hprt0 & HPRT0_PWR)); 686*197ba5f4SPaul Zimmerman if (!(hprt0 & HPRT0_PWR)) { 687*197ba5f4SPaul Zimmerman hprt0 |= HPRT0_PWR; 688*197ba5f4SPaul Zimmerman writel(hprt0, hsotg->regs + HPRT0); 689*197ba5f4SPaul Zimmerman } 690*197ba5f4SPaul Zimmerman } 691*197ba5f4SPaul Zimmerman 692*197ba5f4SPaul Zimmerman dwc2_enable_host_interrupts(hsotg); 693*197ba5f4SPaul Zimmerman } 694*197ba5f4SPaul Zimmerman 695*197ba5f4SPaul Zimmerman static void dwc2_hc_enable_slave_ints(struct dwc2_hsotg *hsotg, 696*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 697*197ba5f4SPaul Zimmerman { 698*197ba5f4SPaul Zimmerman u32 hcintmsk = HCINTMSK_CHHLTD; 699*197ba5f4SPaul Zimmerman 700*197ba5f4SPaul Zimmerman switch (chan->ep_type) { 701*197ba5f4SPaul Zimmerman case USB_ENDPOINT_XFER_CONTROL: 702*197ba5f4SPaul Zimmerman case USB_ENDPOINT_XFER_BULK: 703*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "control/bulk\n"); 704*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XFERCOMPL; 705*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_STALL; 706*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XACTERR; 707*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_DATATGLERR; 708*197ba5f4SPaul Zimmerman if (chan->ep_is_in) { 709*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_BBLERR; 710*197ba5f4SPaul Zimmerman } else { 711*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NAK; 712*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NYET; 713*197ba5f4SPaul Zimmerman if (chan->do_ping) 714*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 715*197ba5f4SPaul Zimmerman } 716*197ba5f4SPaul Zimmerman 717*197ba5f4SPaul Zimmerman if (chan->do_split) { 718*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NAK; 719*197ba5f4SPaul Zimmerman if (chan->complete_split) 720*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NYET; 721*197ba5f4SPaul Zimmerman else 722*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 723*197ba5f4SPaul Zimmerman } 724*197ba5f4SPaul Zimmerman 725*197ba5f4SPaul Zimmerman if (chan->error_state) 726*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 727*197ba5f4SPaul Zimmerman break; 728*197ba5f4SPaul Zimmerman 729*197ba5f4SPaul Zimmerman case USB_ENDPOINT_XFER_INT: 730*197ba5f4SPaul Zimmerman if (dbg_perio()) 731*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "intr\n"); 732*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XFERCOMPL; 733*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NAK; 734*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_STALL; 735*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XACTERR; 736*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_DATATGLERR; 737*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_FRMOVRUN; 738*197ba5f4SPaul Zimmerman 739*197ba5f4SPaul Zimmerman if (chan->ep_is_in) 740*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_BBLERR; 741*197ba5f4SPaul Zimmerman if (chan->error_state) 742*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 743*197ba5f4SPaul Zimmerman if (chan->do_split) { 744*197ba5f4SPaul Zimmerman if (chan->complete_split) 745*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NYET; 746*197ba5f4SPaul Zimmerman else 747*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 748*197ba5f4SPaul Zimmerman } 749*197ba5f4SPaul Zimmerman break; 750*197ba5f4SPaul Zimmerman 751*197ba5f4SPaul Zimmerman case USB_ENDPOINT_XFER_ISOC: 752*197ba5f4SPaul Zimmerman if (dbg_perio()) 753*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "isoc\n"); 754*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XFERCOMPL; 755*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_FRMOVRUN; 756*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 757*197ba5f4SPaul Zimmerman 758*197ba5f4SPaul Zimmerman if (chan->ep_is_in) { 759*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XACTERR; 760*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_BBLERR; 761*197ba5f4SPaul Zimmerman } 762*197ba5f4SPaul Zimmerman break; 763*197ba5f4SPaul Zimmerman default: 764*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "## Unknown EP type ##\n"); 765*197ba5f4SPaul Zimmerman break; 766*197ba5f4SPaul Zimmerman } 767*197ba5f4SPaul Zimmerman 768*197ba5f4SPaul Zimmerman writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 769*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 770*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); 771*197ba5f4SPaul Zimmerman } 772*197ba5f4SPaul Zimmerman 773*197ba5f4SPaul Zimmerman static void dwc2_hc_enable_dma_ints(struct dwc2_hsotg *hsotg, 774*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 775*197ba5f4SPaul Zimmerman { 776*197ba5f4SPaul Zimmerman u32 hcintmsk = HCINTMSK_CHHLTD; 777*197ba5f4SPaul Zimmerman 778*197ba5f4SPaul Zimmerman /* 779*197ba5f4SPaul Zimmerman * For Descriptor DMA mode core halts the channel on AHB error. 780*197ba5f4SPaul Zimmerman * Interrupt is not required. 781*197ba5f4SPaul Zimmerman */ 782*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable <= 0) { 783*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 784*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "desc DMA disabled\n"); 785*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_AHBERR; 786*197ba5f4SPaul Zimmerman } else { 787*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 788*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "desc DMA enabled\n"); 789*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) 790*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_XFERCOMPL; 791*197ba5f4SPaul Zimmerman } 792*197ba5f4SPaul Zimmerman 793*197ba5f4SPaul Zimmerman if (chan->error_state && !chan->do_split && 794*197ba5f4SPaul Zimmerman chan->ep_type != USB_ENDPOINT_XFER_ISOC) { 795*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 796*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "setting ACK\n"); 797*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_ACK; 798*197ba5f4SPaul Zimmerman if (chan->ep_is_in) { 799*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_DATATGLERR; 800*197ba5f4SPaul Zimmerman if (chan->ep_type != USB_ENDPOINT_XFER_INT) 801*197ba5f4SPaul Zimmerman hcintmsk |= HCINTMSK_NAK; 802*197ba5f4SPaul Zimmerman } 803*197ba5f4SPaul Zimmerman } 804*197ba5f4SPaul Zimmerman 805*197ba5f4SPaul Zimmerman writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 806*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 807*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "set HCINTMSK to %08x\n", hcintmsk); 808*197ba5f4SPaul Zimmerman } 809*197ba5f4SPaul Zimmerman 810*197ba5f4SPaul Zimmerman static void dwc2_hc_enable_ints(struct dwc2_hsotg *hsotg, 811*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 812*197ba5f4SPaul Zimmerman { 813*197ba5f4SPaul Zimmerman u32 intmsk; 814*197ba5f4SPaul Zimmerman 815*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable > 0) { 816*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 817*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "DMA enabled\n"); 818*197ba5f4SPaul Zimmerman dwc2_hc_enable_dma_ints(hsotg, chan); 819*197ba5f4SPaul Zimmerman } else { 820*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 821*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "DMA disabled\n"); 822*197ba5f4SPaul Zimmerman dwc2_hc_enable_slave_ints(hsotg, chan); 823*197ba5f4SPaul Zimmerman } 824*197ba5f4SPaul Zimmerman 825*197ba5f4SPaul Zimmerman /* Enable the top level host channel interrupt */ 826*197ba5f4SPaul Zimmerman intmsk = readl(hsotg->regs + HAINTMSK); 827*197ba5f4SPaul Zimmerman intmsk |= 1 << chan->hc_num; 828*197ba5f4SPaul Zimmerman writel(intmsk, hsotg->regs + HAINTMSK); 829*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 830*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "set HAINTMSK to %08x\n", intmsk); 831*197ba5f4SPaul Zimmerman 832*197ba5f4SPaul Zimmerman /* Make sure host channel interrupts are enabled */ 833*197ba5f4SPaul Zimmerman intmsk = readl(hsotg->regs + GINTMSK); 834*197ba5f4SPaul Zimmerman intmsk |= GINTSTS_HCHINT; 835*197ba5f4SPaul Zimmerman writel(intmsk, hsotg->regs + GINTMSK); 836*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 837*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "set GINTMSK to %08x\n", intmsk); 838*197ba5f4SPaul Zimmerman } 839*197ba5f4SPaul Zimmerman 840*197ba5f4SPaul Zimmerman /** 841*197ba5f4SPaul Zimmerman * dwc2_hc_init() - Prepares a host channel for transferring packets to/from 842*197ba5f4SPaul Zimmerman * a specific endpoint 843*197ba5f4SPaul Zimmerman * 844*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 845*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel 846*197ba5f4SPaul Zimmerman * 847*197ba5f4SPaul Zimmerman * The HCCHARn register is set up with the characteristics specified in chan. 848*197ba5f4SPaul Zimmerman * Host channel interrupts that may need to be serviced while this transfer is 849*197ba5f4SPaul Zimmerman * in progress are enabled. 850*197ba5f4SPaul Zimmerman */ 851*197ba5f4SPaul Zimmerman void dwc2_hc_init(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) 852*197ba5f4SPaul Zimmerman { 853*197ba5f4SPaul Zimmerman u8 hc_num = chan->hc_num; 854*197ba5f4SPaul Zimmerman u32 hcintmsk; 855*197ba5f4SPaul Zimmerman u32 hcchar; 856*197ba5f4SPaul Zimmerman u32 hcsplt = 0; 857*197ba5f4SPaul Zimmerman 858*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 859*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 860*197ba5f4SPaul Zimmerman 861*197ba5f4SPaul Zimmerman /* Clear old interrupt conditions for this host channel */ 862*197ba5f4SPaul Zimmerman hcintmsk = 0xffffffff; 863*197ba5f4SPaul Zimmerman hcintmsk &= ~HCINTMSK_RESERVED14_31; 864*197ba5f4SPaul Zimmerman writel(hcintmsk, hsotg->regs + HCINT(hc_num)); 865*197ba5f4SPaul Zimmerman 866*197ba5f4SPaul Zimmerman /* Enable channel interrupts required for this transfer */ 867*197ba5f4SPaul Zimmerman dwc2_hc_enable_ints(hsotg, chan); 868*197ba5f4SPaul Zimmerman 869*197ba5f4SPaul Zimmerman /* 870*197ba5f4SPaul Zimmerman * Program the HCCHARn register with the endpoint characteristics for 871*197ba5f4SPaul Zimmerman * the current transfer 872*197ba5f4SPaul Zimmerman */ 873*197ba5f4SPaul Zimmerman hcchar = chan->dev_addr << HCCHAR_DEVADDR_SHIFT & HCCHAR_DEVADDR_MASK; 874*197ba5f4SPaul Zimmerman hcchar |= chan->ep_num << HCCHAR_EPNUM_SHIFT & HCCHAR_EPNUM_MASK; 875*197ba5f4SPaul Zimmerman if (chan->ep_is_in) 876*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_EPDIR; 877*197ba5f4SPaul Zimmerman if (chan->speed == USB_SPEED_LOW) 878*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_LSPDDEV; 879*197ba5f4SPaul Zimmerman hcchar |= chan->ep_type << HCCHAR_EPTYPE_SHIFT & HCCHAR_EPTYPE_MASK; 880*197ba5f4SPaul Zimmerman hcchar |= chan->max_packet << HCCHAR_MPS_SHIFT & HCCHAR_MPS_MASK; 881*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(hc_num)); 882*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) { 883*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "set HCCHAR(%d) to %08x\n", 884*197ba5f4SPaul Zimmerman hc_num, hcchar); 885*197ba5f4SPaul Zimmerman 886*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", 887*197ba5f4SPaul Zimmerman __func__, hc_num); 888*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Dev Addr: %d\n", 889*197ba5f4SPaul Zimmerman chan->dev_addr); 890*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Ep Num: %d\n", 891*197ba5f4SPaul Zimmerman chan->ep_num); 892*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Is In: %d\n", 893*197ba5f4SPaul Zimmerman chan->ep_is_in); 894*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Is Low Speed: %d\n", 895*197ba5f4SPaul Zimmerman chan->speed == USB_SPEED_LOW); 896*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Ep Type: %d\n", 897*197ba5f4SPaul Zimmerman chan->ep_type); 898*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Max Pkt: %d\n", 899*197ba5f4SPaul Zimmerman chan->max_packet); 900*197ba5f4SPaul Zimmerman } 901*197ba5f4SPaul Zimmerman 902*197ba5f4SPaul Zimmerman /* Program the HCSPLT register for SPLITs */ 903*197ba5f4SPaul Zimmerman if (chan->do_split) { 904*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 905*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, 906*197ba5f4SPaul Zimmerman "Programming HC %d with split --> %s\n", 907*197ba5f4SPaul Zimmerman hc_num, 908*197ba5f4SPaul Zimmerman chan->complete_split ? "CSPLIT" : "SSPLIT"); 909*197ba5f4SPaul Zimmerman if (chan->complete_split) 910*197ba5f4SPaul Zimmerman hcsplt |= HCSPLT_COMPSPLT; 911*197ba5f4SPaul Zimmerman hcsplt |= chan->xact_pos << HCSPLT_XACTPOS_SHIFT & 912*197ba5f4SPaul Zimmerman HCSPLT_XACTPOS_MASK; 913*197ba5f4SPaul Zimmerman hcsplt |= chan->hub_addr << HCSPLT_HUBADDR_SHIFT & 914*197ba5f4SPaul Zimmerman HCSPLT_HUBADDR_MASK; 915*197ba5f4SPaul Zimmerman hcsplt |= chan->hub_port << HCSPLT_PRTADDR_SHIFT & 916*197ba5f4SPaul Zimmerman HCSPLT_PRTADDR_MASK; 917*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) { 918*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " comp split %d\n", 919*197ba5f4SPaul Zimmerman chan->complete_split); 920*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " xact pos %d\n", 921*197ba5f4SPaul Zimmerman chan->xact_pos); 922*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " hub addr %d\n", 923*197ba5f4SPaul Zimmerman chan->hub_addr); 924*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " hub port %d\n", 925*197ba5f4SPaul Zimmerman chan->hub_port); 926*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " is_in %d\n", 927*197ba5f4SPaul Zimmerman chan->ep_is_in); 928*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Max Pkt %d\n", 929*197ba5f4SPaul Zimmerman chan->max_packet); 930*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " xferlen %d\n", 931*197ba5f4SPaul Zimmerman chan->xfer_len); 932*197ba5f4SPaul Zimmerman } 933*197ba5f4SPaul Zimmerman } 934*197ba5f4SPaul Zimmerman 935*197ba5f4SPaul Zimmerman writel(hcsplt, hsotg->regs + HCSPLT(hc_num)); 936*197ba5f4SPaul Zimmerman } 937*197ba5f4SPaul Zimmerman 938*197ba5f4SPaul Zimmerman /** 939*197ba5f4SPaul Zimmerman * dwc2_hc_halt() - Attempts to halt a host channel 940*197ba5f4SPaul Zimmerman * 941*197ba5f4SPaul Zimmerman * @hsotg: Controller register interface 942*197ba5f4SPaul Zimmerman * @chan: Host channel to halt 943*197ba5f4SPaul Zimmerman * @halt_status: Reason for halting the channel 944*197ba5f4SPaul Zimmerman * 945*197ba5f4SPaul Zimmerman * This function should only be called in Slave mode or to abort a transfer in 946*197ba5f4SPaul Zimmerman * either Slave mode or DMA mode. Under normal circumstances in DMA mode, the 947*197ba5f4SPaul Zimmerman * controller halts the channel when the transfer is complete or a condition 948*197ba5f4SPaul Zimmerman * occurs that requires application intervention. 949*197ba5f4SPaul Zimmerman * 950*197ba5f4SPaul Zimmerman * In slave mode, checks for a free request queue entry, then sets the Channel 951*197ba5f4SPaul Zimmerman * Enable and Channel Disable bits of the Host Channel Characteristics 952*197ba5f4SPaul Zimmerman * register of the specified channel to intiate the halt. If there is no free 953*197ba5f4SPaul Zimmerman * request queue entry, sets only the Channel Disable bit of the HCCHARn 954*197ba5f4SPaul Zimmerman * register to flush requests for this channel. In the latter case, sets a 955*197ba5f4SPaul Zimmerman * flag to indicate that the host channel needs to be halted when a request 956*197ba5f4SPaul Zimmerman * queue slot is open. 957*197ba5f4SPaul Zimmerman * 958*197ba5f4SPaul Zimmerman * In DMA mode, always sets the Channel Enable and Channel Disable bits of the 959*197ba5f4SPaul Zimmerman * HCCHARn register. The controller ensures there is space in the request 960*197ba5f4SPaul Zimmerman * queue before submitting the halt request. 961*197ba5f4SPaul Zimmerman * 962*197ba5f4SPaul Zimmerman * Some time may elapse before the core flushes any posted requests for this 963*197ba5f4SPaul Zimmerman * host channel and halts. The Channel Halted interrupt handler completes the 964*197ba5f4SPaul Zimmerman * deactivation of the host channel. 965*197ba5f4SPaul Zimmerman */ 966*197ba5f4SPaul Zimmerman void dwc2_hc_halt(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan, 967*197ba5f4SPaul Zimmerman enum dwc2_halt_status halt_status) 968*197ba5f4SPaul Zimmerman { 969*197ba5f4SPaul Zimmerman u32 nptxsts, hptxsts, hcchar; 970*197ba5f4SPaul Zimmerman 971*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 972*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 973*197ba5f4SPaul Zimmerman if (halt_status == DWC2_HC_XFER_NO_HALT_STATUS) 974*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "!!! halt_status = %d !!!\n", halt_status); 975*197ba5f4SPaul Zimmerman 976*197ba5f4SPaul Zimmerman if (halt_status == DWC2_HC_XFER_URB_DEQUEUE || 977*197ba5f4SPaul Zimmerman halt_status == DWC2_HC_XFER_AHB_ERR) { 978*197ba5f4SPaul Zimmerman /* 979*197ba5f4SPaul Zimmerman * Disable all channel interrupts except Ch Halted. The QTD 980*197ba5f4SPaul Zimmerman * and QH state associated with this transfer has been cleared 981*197ba5f4SPaul Zimmerman * (in the case of URB_DEQUEUE), so the channel needs to be 982*197ba5f4SPaul Zimmerman * shut down carefully to prevent crashes. 983*197ba5f4SPaul Zimmerman */ 984*197ba5f4SPaul Zimmerman u32 hcintmsk = HCINTMSK_CHHLTD; 985*197ba5f4SPaul Zimmerman 986*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "dequeue/error\n"); 987*197ba5f4SPaul Zimmerman writel(hcintmsk, hsotg->regs + HCINTMSK(chan->hc_num)); 988*197ba5f4SPaul Zimmerman 989*197ba5f4SPaul Zimmerman /* 990*197ba5f4SPaul Zimmerman * Make sure no other interrupts besides halt are currently 991*197ba5f4SPaul Zimmerman * pending. Handling another interrupt could cause a crash due 992*197ba5f4SPaul Zimmerman * to the QTD and QH state. 993*197ba5f4SPaul Zimmerman */ 994*197ba5f4SPaul Zimmerman writel(~hcintmsk, hsotg->regs + HCINT(chan->hc_num)); 995*197ba5f4SPaul Zimmerman 996*197ba5f4SPaul Zimmerman /* 997*197ba5f4SPaul Zimmerman * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR 998*197ba5f4SPaul Zimmerman * even if the channel was already halted for some other 999*197ba5f4SPaul Zimmerman * reason 1000*197ba5f4SPaul Zimmerman */ 1001*197ba5f4SPaul Zimmerman chan->halt_status = halt_status; 1002*197ba5f4SPaul Zimmerman 1003*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1004*197ba5f4SPaul Zimmerman if (!(hcchar & HCCHAR_CHENA)) { 1005*197ba5f4SPaul Zimmerman /* 1006*197ba5f4SPaul Zimmerman * The channel is either already halted or it hasn't 1007*197ba5f4SPaul Zimmerman * started yet. In DMA mode, the transfer may halt if 1008*197ba5f4SPaul Zimmerman * it finishes normally or a condition occurs that 1009*197ba5f4SPaul Zimmerman * requires driver intervention. Don't want to halt 1010*197ba5f4SPaul Zimmerman * the channel again. In either Slave or DMA mode, 1011*197ba5f4SPaul Zimmerman * it's possible that the transfer has been assigned 1012*197ba5f4SPaul Zimmerman * to a channel, but not started yet when an URB is 1013*197ba5f4SPaul Zimmerman * dequeued. Don't want to halt a channel that hasn't 1014*197ba5f4SPaul Zimmerman * started yet. 1015*197ba5f4SPaul Zimmerman */ 1016*197ba5f4SPaul Zimmerman return; 1017*197ba5f4SPaul Zimmerman } 1018*197ba5f4SPaul Zimmerman } 1019*197ba5f4SPaul Zimmerman if (chan->halt_pending) { 1020*197ba5f4SPaul Zimmerman /* 1021*197ba5f4SPaul Zimmerman * A halt has already been issued for this channel. This might 1022*197ba5f4SPaul Zimmerman * happen when a transfer is aborted by a higher level in 1023*197ba5f4SPaul Zimmerman * the stack. 1024*197ba5f4SPaul Zimmerman */ 1025*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, 1026*197ba5f4SPaul Zimmerman "*** %s: Channel %d, chan->halt_pending already set ***\n", 1027*197ba5f4SPaul Zimmerman __func__, chan->hc_num); 1028*197ba5f4SPaul Zimmerman return; 1029*197ba5f4SPaul Zimmerman } 1030*197ba5f4SPaul Zimmerman 1031*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1032*197ba5f4SPaul Zimmerman 1033*197ba5f4SPaul Zimmerman /* No need to set the bit in DDMA for disabling the channel */ 1034*197ba5f4SPaul Zimmerman /* TODO check it everywhere channel is disabled */ 1035*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable <= 0) { 1036*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1037*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "desc DMA disabled\n"); 1038*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1039*197ba5f4SPaul Zimmerman } else { 1040*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1041*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "desc DMA enabled\n"); 1042*197ba5f4SPaul Zimmerman } 1043*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHDIS; 1044*197ba5f4SPaul Zimmerman 1045*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable <= 0) { 1046*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1047*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "DMA not enabled\n"); 1048*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1049*197ba5f4SPaul Zimmerman 1050*197ba5f4SPaul Zimmerman /* Check for space in the request queue to issue the halt */ 1051*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || 1052*197ba5f4SPaul Zimmerman chan->ep_type == USB_ENDPOINT_XFER_BULK) { 1053*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "control/bulk\n"); 1054*197ba5f4SPaul Zimmerman nptxsts = readl(hsotg->regs + GNPTXSTS); 1055*197ba5f4SPaul Zimmerman if ((nptxsts & TXSTS_QSPCAVAIL_MASK) == 0) { 1056*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Disabling channel\n"); 1057*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHENA; 1058*197ba5f4SPaul Zimmerman } 1059*197ba5f4SPaul Zimmerman } else { 1060*197ba5f4SPaul Zimmerman if (dbg_perio()) 1061*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "isoc/intr\n"); 1062*197ba5f4SPaul Zimmerman hptxsts = readl(hsotg->regs + HPTXSTS); 1063*197ba5f4SPaul Zimmerman if ((hptxsts & TXSTS_QSPCAVAIL_MASK) == 0 || 1064*197ba5f4SPaul Zimmerman hsotg->queuing_high_bandwidth) { 1065*197ba5f4SPaul Zimmerman if (dbg_perio()) 1066*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Disabling channel\n"); 1067*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHENA; 1068*197ba5f4SPaul Zimmerman } 1069*197ba5f4SPaul Zimmerman } 1070*197ba5f4SPaul Zimmerman } else { 1071*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1072*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "DMA enabled\n"); 1073*197ba5f4SPaul Zimmerman } 1074*197ba5f4SPaul Zimmerman 1075*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1076*197ba5f4SPaul Zimmerman chan->halt_status = halt_status; 1077*197ba5f4SPaul Zimmerman 1078*197ba5f4SPaul Zimmerman if (hcchar & HCCHAR_CHENA) { 1079*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1080*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Channel enabled\n"); 1081*197ba5f4SPaul Zimmerman chan->halt_pending = 1; 1082*197ba5f4SPaul Zimmerman chan->halt_on_queue = 0; 1083*197ba5f4SPaul Zimmerman } else { 1084*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1085*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Channel disabled\n"); 1086*197ba5f4SPaul Zimmerman chan->halt_on_queue = 1; 1087*197ba5f4SPaul Zimmerman } 1088*197ba5f4SPaul Zimmerman 1089*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) { 1090*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 1091*197ba5f4SPaul Zimmerman chan->hc_num); 1092*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " hcchar: 0x%08x\n", 1093*197ba5f4SPaul Zimmerman hcchar); 1094*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " halt_pending: %d\n", 1095*197ba5f4SPaul Zimmerman chan->halt_pending); 1096*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " halt_on_queue: %d\n", 1097*197ba5f4SPaul Zimmerman chan->halt_on_queue); 1098*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " halt_status: %d\n", 1099*197ba5f4SPaul Zimmerman chan->halt_status); 1100*197ba5f4SPaul Zimmerman } 1101*197ba5f4SPaul Zimmerman } 1102*197ba5f4SPaul Zimmerman 1103*197ba5f4SPaul Zimmerman /** 1104*197ba5f4SPaul Zimmerman * dwc2_hc_cleanup() - Clears the transfer state for a host channel 1105*197ba5f4SPaul Zimmerman * 1106*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1107*197ba5f4SPaul Zimmerman * @chan: Identifies the host channel to clean up 1108*197ba5f4SPaul Zimmerman * 1109*197ba5f4SPaul Zimmerman * This function is normally called after a transfer is done and the host 1110*197ba5f4SPaul Zimmerman * channel is being released 1111*197ba5f4SPaul Zimmerman */ 1112*197ba5f4SPaul Zimmerman void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) 1113*197ba5f4SPaul Zimmerman { 1114*197ba5f4SPaul Zimmerman u32 hcintmsk; 1115*197ba5f4SPaul Zimmerman 1116*197ba5f4SPaul Zimmerman chan->xfer_started = 0; 1117*197ba5f4SPaul Zimmerman 1118*197ba5f4SPaul Zimmerman /* 1119*197ba5f4SPaul Zimmerman * Clear channel interrupt enables and any unhandled channel interrupt 1120*197ba5f4SPaul Zimmerman * conditions 1121*197ba5f4SPaul Zimmerman */ 1122*197ba5f4SPaul Zimmerman writel(0, hsotg->regs + HCINTMSK(chan->hc_num)); 1123*197ba5f4SPaul Zimmerman hcintmsk = 0xffffffff; 1124*197ba5f4SPaul Zimmerman hcintmsk &= ~HCINTMSK_RESERVED14_31; 1125*197ba5f4SPaul Zimmerman writel(hcintmsk, hsotg->regs + HCINT(chan->hc_num)); 1126*197ba5f4SPaul Zimmerman } 1127*197ba5f4SPaul Zimmerman 1128*197ba5f4SPaul Zimmerman /** 1129*197ba5f4SPaul Zimmerman * dwc2_hc_set_even_odd_frame() - Sets the channel property that indicates in 1130*197ba5f4SPaul Zimmerman * which frame a periodic transfer should occur 1131*197ba5f4SPaul Zimmerman * 1132*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1133*197ba5f4SPaul Zimmerman * @chan: Identifies the host channel to set up and its properties 1134*197ba5f4SPaul Zimmerman * @hcchar: Current value of the HCCHAR register for the specified host channel 1135*197ba5f4SPaul Zimmerman * 1136*197ba5f4SPaul Zimmerman * This function has no effect on non-periodic transfers 1137*197ba5f4SPaul Zimmerman */ 1138*197ba5f4SPaul Zimmerman static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, 1139*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan, u32 *hcchar) 1140*197ba5f4SPaul Zimmerman { 1141*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1142*197ba5f4SPaul Zimmerman chan->ep_type == USB_ENDPOINT_XFER_ISOC) { 1143*197ba5f4SPaul Zimmerman /* 1 if _next_ frame is odd, 0 if it's even */ 1144*197ba5f4SPaul Zimmerman if (!(dwc2_hcd_get_frame_number(hsotg) & 0x1)) 1145*197ba5f4SPaul Zimmerman *hcchar |= HCCHAR_ODDFRM; 1146*197ba5f4SPaul Zimmerman } 1147*197ba5f4SPaul Zimmerman } 1148*197ba5f4SPaul Zimmerman 1149*197ba5f4SPaul Zimmerman static void dwc2_set_pid_isoc(struct dwc2_host_chan *chan) 1150*197ba5f4SPaul Zimmerman { 1151*197ba5f4SPaul Zimmerman /* Set up the initial PID for the transfer */ 1152*197ba5f4SPaul Zimmerman if (chan->speed == USB_SPEED_HIGH) { 1153*197ba5f4SPaul Zimmerman if (chan->ep_is_in) { 1154*197ba5f4SPaul Zimmerman if (chan->multi_count == 1) 1155*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_DATA0; 1156*197ba5f4SPaul Zimmerman else if (chan->multi_count == 2) 1157*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_DATA1; 1158*197ba5f4SPaul Zimmerman else 1159*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_DATA2; 1160*197ba5f4SPaul Zimmerman } else { 1161*197ba5f4SPaul Zimmerman if (chan->multi_count == 1) 1162*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_DATA0; 1163*197ba5f4SPaul Zimmerman else 1164*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_MDATA; 1165*197ba5f4SPaul Zimmerman } 1166*197ba5f4SPaul Zimmerman } else { 1167*197ba5f4SPaul Zimmerman chan->data_pid_start = DWC2_HC_PID_DATA0; 1168*197ba5f4SPaul Zimmerman } 1169*197ba5f4SPaul Zimmerman } 1170*197ba5f4SPaul Zimmerman 1171*197ba5f4SPaul Zimmerman /** 1172*197ba5f4SPaul Zimmerman * dwc2_hc_write_packet() - Writes a packet into the Tx FIFO associated with 1173*197ba5f4SPaul Zimmerman * the Host Channel 1174*197ba5f4SPaul Zimmerman * 1175*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1176*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel 1177*197ba5f4SPaul Zimmerman * 1178*197ba5f4SPaul Zimmerman * This function should only be called in Slave mode. For a channel associated 1179*197ba5f4SPaul Zimmerman * with a non-periodic EP, the non-periodic Tx FIFO is written. For a channel 1180*197ba5f4SPaul Zimmerman * associated with a periodic EP, the periodic Tx FIFO is written. 1181*197ba5f4SPaul Zimmerman * 1182*197ba5f4SPaul Zimmerman * Upon return the xfer_buf and xfer_count fields in chan are incremented by 1183*197ba5f4SPaul Zimmerman * the number of bytes written to the Tx FIFO. 1184*197ba5f4SPaul Zimmerman */ 1185*197ba5f4SPaul Zimmerman static void dwc2_hc_write_packet(struct dwc2_hsotg *hsotg, 1186*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 1187*197ba5f4SPaul Zimmerman { 1188*197ba5f4SPaul Zimmerman u32 i; 1189*197ba5f4SPaul Zimmerman u32 remaining_count; 1190*197ba5f4SPaul Zimmerman u32 byte_count; 1191*197ba5f4SPaul Zimmerman u32 dword_count; 1192*197ba5f4SPaul Zimmerman u32 __iomem *data_fifo; 1193*197ba5f4SPaul Zimmerman u32 *data_buf = (u32 *)chan->xfer_buf; 1194*197ba5f4SPaul Zimmerman 1195*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1196*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 1197*197ba5f4SPaul Zimmerman 1198*197ba5f4SPaul Zimmerman data_fifo = (u32 __iomem *)(hsotg->regs + HCFIFO(chan->hc_num)); 1199*197ba5f4SPaul Zimmerman 1200*197ba5f4SPaul Zimmerman remaining_count = chan->xfer_len - chan->xfer_count; 1201*197ba5f4SPaul Zimmerman if (remaining_count > chan->max_packet) 1202*197ba5f4SPaul Zimmerman byte_count = chan->max_packet; 1203*197ba5f4SPaul Zimmerman else 1204*197ba5f4SPaul Zimmerman byte_count = remaining_count; 1205*197ba5f4SPaul Zimmerman 1206*197ba5f4SPaul Zimmerman dword_count = (byte_count + 3) / 4; 1207*197ba5f4SPaul Zimmerman 1208*197ba5f4SPaul Zimmerman if (((unsigned long)data_buf & 0x3) == 0) { 1209*197ba5f4SPaul Zimmerman /* xfer_buf is DWORD aligned */ 1210*197ba5f4SPaul Zimmerman for (i = 0; i < dword_count; i++, data_buf++) 1211*197ba5f4SPaul Zimmerman writel(*data_buf, data_fifo); 1212*197ba5f4SPaul Zimmerman } else { 1213*197ba5f4SPaul Zimmerman /* xfer_buf is not DWORD aligned */ 1214*197ba5f4SPaul Zimmerman for (i = 0; i < dword_count; i++, data_buf++) { 1215*197ba5f4SPaul Zimmerman u32 data = data_buf[0] | data_buf[1] << 8 | 1216*197ba5f4SPaul Zimmerman data_buf[2] << 16 | data_buf[3] << 24; 1217*197ba5f4SPaul Zimmerman writel(data, data_fifo); 1218*197ba5f4SPaul Zimmerman } 1219*197ba5f4SPaul Zimmerman } 1220*197ba5f4SPaul Zimmerman 1221*197ba5f4SPaul Zimmerman chan->xfer_count += byte_count; 1222*197ba5f4SPaul Zimmerman chan->xfer_buf += byte_count; 1223*197ba5f4SPaul Zimmerman } 1224*197ba5f4SPaul Zimmerman 1225*197ba5f4SPaul Zimmerman /** 1226*197ba5f4SPaul Zimmerman * dwc2_hc_start_transfer() - Does the setup for a data transfer for a host 1227*197ba5f4SPaul Zimmerman * channel and starts the transfer 1228*197ba5f4SPaul Zimmerman * 1229*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1230*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel. The xfer_len value 1231*197ba5f4SPaul Zimmerman * may be reduced to accommodate the max widths of the XferSize and 1232*197ba5f4SPaul Zimmerman * PktCnt fields in the HCTSIZn register. The multi_count value may be 1233*197ba5f4SPaul Zimmerman * changed to reflect the final xfer_len value. 1234*197ba5f4SPaul Zimmerman * 1235*197ba5f4SPaul Zimmerman * This function may be called in either Slave mode or DMA mode. In Slave mode, 1236*197ba5f4SPaul Zimmerman * the caller must ensure that there is sufficient space in the request queue 1237*197ba5f4SPaul Zimmerman * and Tx Data FIFO. 1238*197ba5f4SPaul Zimmerman * 1239*197ba5f4SPaul Zimmerman * For an OUT transfer in Slave mode, it loads a data packet into the 1240*197ba5f4SPaul Zimmerman * appropriate FIFO. If necessary, additional data packets are loaded in the 1241*197ba5f4SPaul Zimmerman * Host ISR. 1242*197ba5f4SPaul Zimmerman * 1243*197ba5f4SPaul Zimmerman * For an IN transfer in Slave mode, a data packet is requested. The data 1244*197ba5f4SPaul Zimmerman * packets are unloaded from the Rx FIFO in the Host ISR. If necessary, 1245*197ba5f4SPaul Zimmerman * additional data packets are requested in the Host ISR. 1246*197ba5f4SPaul Zimmerman * 1247*197ba5f4SPaul Zimmerman * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ 1248*197ba5f4SPaul Zimmerman * register along with a packet count of 1 and the channel is enabled. This 1249*197ba5f4SPaul Zimmerman * causes a single PING transaction to occur. Other fields in HCTSIZ are 1250*197ba5f4SPaul Zimmerman * simply set to 0 since no data transfer occurs in this case. 1251*197ba5f4SPaul Zimmerman * 1252*197ba5f4SPaul Zimmerman * For a PING transfer in DMA mode, the HCTSIZ register is initialized with 1253*197ba5f4SPaul Zimmerman * all the information required to perform the subsequent data transfer. In 1254*197ba5f4SPaul Zimmerman * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the 1255*197ba5f4SPaul Zimmerman * controller performs the entire PING protocol, then starts the data 1256*197ba5f4SPaul Zimmerman * transfer. 1257*197ba5f4SPaul Zimmerman */ 1258*197ba5f4SPaul Zimmerman void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, 1259*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 1260*197ba5f4SPaul Zimmerman { 1261*197ba5f4SPaul Zimmerman u32 max_hc_xfer_size = hsotg->core_params->max_transfer_size; 1262*197ba5f4SPaul Zimmerman u16 max_hc_pkt_count = hsotg->core_params->max_packet_count; 1263*197ba5f4SPaul Zimmerman u32 hcchar; 1264*197ba5f4SPaul Zimmerman u32 hctsiz = 0; 1265*197ba5f4SPaul Zimmerman u16 num_packets; 1266*197ba5f4SPaul Zimmerman 1267*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1268*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 1269*197ba5f4SPaul Zimmerman 1270*197ba5f4SPaul Zimmerman if (chan->do_ping) { 1271*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable <= 0) { 1272*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1273*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "ping, no DMA\n"); 1274*197ba5f4SPaul Zimmerman dwc2_hc_do_ping(hsotg, chan); 1275*197ba5f4SPaul Zimmerman chan->xfer_started = 1; 1276*197ba5f4SPaul Zimmerman return; 1277*197ba5f4SPaul Zimmerman } else { 1278*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1279*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "ping, DMA\n"); 1280*197ba5f4SPaul Zimmerman hctsiz |= TSIZ_DOPNG; 1281*197ba5f4SPaul Zimmerman } 1282*197ba5f4SPaul Zimmerman } 1283*197ba5f4SPaul Zimmerman 1284*197ba5f4SPaul Zimmerman if (chan->do_split) { 1285*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1286*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "split\n"); 1287*197ba5f4SPaul Zimmerman num_packets = 1; 1288*197ba5f4SPaul Zimmerman 1289*197ba5f4SPaul Zimmerman if (chan->complete_split && !chan->ep_is_in) 1290*197ba5f4SPaul Zimmerman /* 1291*197ba5f4SPaul Zimmerman * For CSPLIT OUT Transfer, set the size to 0 so the 1292*197ba5f4SPaul Zimmerman * core doesn't expect any data written to the FIFO 1293*197ba5f4SPaul Zimmerman */ 1294*197ba5f4SPaul Zimmerman chan->xfer_len = 0; 1295*197ba5f4SPaul Zimmerman else if (chan->ep_is_in || chan->xfer_len > chan->max_packet) 1296*197ba5f4SPaul Zimmerman chan->xfer_len = chan->max_packet; 1297*197ba5f4SPaul Zimmerman else if (!chan->ep_is_in && chan->xfer_len > 188) 1298*197ba5f4SPaul Zimmerman chan->xfer_len = 188; 1299*197ba5f4SPaul Zimmerman 1300*197ba5f4SPaul Zimmerman hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1301*197ba5f4SPaul Zimmerman TSIZ_XFERSIZE_MASK; 1302*197ba5f4SPaul Zimmerman } else { 1303*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1304*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "no split\n"); 1305*197ba5f4SPaul Zimmerman /* 1306*197ba5f4SPaul Zimmerman * Ensure that the transfer length and packet count will fit 1307*197ba5f4SPaul Zimmerman * in the widths allocated for them in the HCTSIZn register 1308*197ba5f4SPaul Zimmerman */ 1309*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1310*197ba5f4SPaul Zimmerman chan->ep_type == USB_ENDPOINT_XFER_ISOC) { 1311*197ba5f4SPaul Zimmerman /* 1312*197ba5f4SPaul Zimmerman * Make sure the transfer size is no larger than one 1313*197ba5f4SPaul Zimmerman * (micro)frame's worth of data. (A check was done 1314*197ba5f4SPaul Zimmerman * when the periodic transfer was accepted to ensure 1315*197ba5f4SPaul Zimmerman * that a (micro)frame's worth of data can be 1316*197ba5f4SPaul Zimmerman * programmed into a channel.) 1317*197ba5f4SPaul Zimmerman */ 1318*197ba5f4SPaul Zimmerman u32 max_periodic_len = 1319*197ba5f4SPaul Zimmerman chan->multi_count * chan->max_packet; 1320*197ba5f4SPaul Zimmerman 1321*197ba5f4SPaul Zimmerman if (chan->xfer_len > max_periodic_len) 1322*197ba5f4SPaul Zimmerman chan->xfer_len = max_periodic_len; 1323*197ba5f4SPaul Zimmerman } else if (chan->xfer_len > max_hc_xfer_size) { 1324*197ba5f4SPaul Zimmerman /* 1325*197ba5f4SPaul Zimmerman * Make sure that xfer_len is a multiple of max packet 1326*197ba5f4SPaul Zimmerman * size 1327*197ba5f4SPaul Zimmerman */ 1328*197ba5f4SPaul Zimmerman chan->xfer_len = 1329*197ba5f4SPaul Zimmerman max_hc_xfer_size - chan->max_packet + 1; 1330*197ba5f4SPaul Zimmerman } 1331*197ba5f4SPaul Zimmerman 1332*197ba5f4SPaul Zimmerman if (chan->xfer_len > 0) { 1333*197ba5f4SPaul Zimmerman num_packets = (chan->xfer_len + chan->max_packet - 1) / 1334*197ba5f4SPaul Zimmerman chan->max_packet; 1335*197ba5f4SPaul Zimmerman if (num_packets > max_hc_pkt_count) { 1336*197ba5f4SPaul Zimmerman num_packets = max_hc_pkt_count; 1337*197ba5f4SPaul Zimmerman chan->xfer_len = num_packets * chan->max_packet; 1338*197ba5f4SPaul Zimmerman } 1339*197ba5f4SPaul Zimmerman } else { 1340*197ba5f4SPaul Zimmerman /* Need 1 packet for transfer length of 0 */ 1341*197ba5f4SPaul Zimmerman num_packets = 1; 1342*197ba5f4SPaul Zimmerman } 1343*197ba5f4SPaul Zimmerman 1344*197ba5f4SPaul Zimmerman if (chan->ep_is_in) 1345*197ba5f4SPaul Zimmerman /* 1346*197ba5f4SPaul Zimmerman * Always program an integral # of max packets for IN 1347*197ba5f4SPaul Zimmerman * transfers 1348*197ba5f4SPaul Zimmerman */ 1349*197ba5f4SPaul Zimmerman chan->xfer_len = num_packets * chan->max_packet; 1350*197ba5f4SPaul Zimmerman 1351*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1352*197ba5f4SPaul Zimmerman chan->ep_type == USB_ENDPOINT_XFER_ISOC) 1353*197ba5f4SPaul Zimmerman /* 1354*197ba5f4SPaul Zimmerman * Make sure that the multi_count field matches the 1355*197ba5f4SPaul Zimmerman * actual transfer length 1356*197ba5f4SPaul Zimmerman */ 1357*197ba5f4SPaul Zimmerman chan->multi_count = num_packets; 1358*197ba5f4SPaul Zimmerman 1359*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) 1360*197ba5f4SPaul Zimmerman dwc2_set_pid_isoc(chan); 1361*197ba5f4SPaul Zimmerman 1362*197ba5f4SPaul Zimmerman hctsiz |= chan->xfer_len << TSIZ_XFERSIZE_SHIFT & 1363*197ba5f4SPaul Zimmerman TSIZ_XFERSIZE_MASK; 1364*197ba5f4SPaul Zimmerman } 1365*197ba5f4SPaul Zimmerman 1366*197ba5f4SPaul Zimmerman chan->start_pkt_count = num_packets; 1367*197ba5f4SPaul Zimmerman hctsiz |= num_packets << TSIZ_PKTCNT_SHIFT & TSIZ_PKTCNT_MASK; 1368*197ba5f4SPaul Zimmerman hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & 1369*197ba5f4SPaul Zimmerman TSIZ_SC_MC_PID_MASK; 1370*197ba5f4SPaul Zimmerman writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1371*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) { 1372*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Wrote %08x to HCTSIZ(%d)\n", 1373*197ba5f4SPaul Zimmerman hctsiz, chan->hc_num); 1374*197ba5f4SPaul Zimmerman 1375*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 1376*197ba5f4SPaul Zimmerman chan->hc_num); 1377*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Xfer Size: %d\n", 1378*197ba5f4SPaul Zimmerman (hctsiz & TSIZ_XFERSIZE_MASK) >> 1379*197ba5f4SPaul Zimmerman TSIZ_XFERSIZE_SHIFT); 1380*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Num Pkts: %d\n", 1381*197ba5f4SPaul Zimmerman (hctsiz & TSIZ_PKTCNT_MASK) >> 1382*197ba5f4SPaul Zimmerman TSIZ_PKTCNT_SHIFT); 1383*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Start PID: %d\n", 1384*197ba5f4SPaul Zimmerman (hctsiz & TSIZ_SC_MC_PID_MASK) >> 1385*197ba5f4SPaul Zimmerman TSIZ_SC_MC_PID_SHIFT); 1386*197ba5f4SPaul Zimmerman } 1387*197ba5f4SPaul Zimmerman 1388*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable > 0) { 1389*197ba5f4SPaul Zimmerman dma_addr_t dma_addr; 1390*197ba5f4SPaul Zimmerman 1391*197ba5f4SPaul Zimmerman if (chan->align_buf) { 1392*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1393*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "align_buf\n"); 1394*197ba5f4SPaul Zimmerman dma_addr = chan->align_buf; 1395*197ba5f4SPaul Zimmerman } else { 1396*197ba5f4SPaul Zimmerman dma_addr = chan->xfer_dma; 1397*197ba5f4SPaul Zimmerman } 1398*197ba5f4SPaul Zimmerman writel((u32)dma_addr, hsotg->regs + HCDMA(chan->hc_num)); 1399*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1400*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Wrote %08lx to HCDMA(%d)\n", 1401*197ba5f4SPaul Zimmerman (unsigned long)dma_addr, chan->hc_num); 1402*197ba5f4SPaul Zimmerman } 1403*197ba5f4SPaul Zimmerman 1404*197ba5f4SPaul Zimmerman /* Start the split */ 1405*197ba5f4SPaul Zimmerman if (chan->do_split) { 1406*197ba5f4SPaul Zimmerman u32 hcsplt = readl(hsotg->regs + HCSPLT(chan->hc_num)); 1407*197ba5f4SPaul Zimmerman 1408*197ba5f4SPaul Zimmerman hcsplt |= HCSPLT_SPLTENA; 1409*197ba5f4SPaul Zimmerman writel(hcsplt, hsotg->regs + HCSPLT(chan->hc_num)); 1410*197ba5f4SPaul Zimmerman } 1411*197ba5f4SPaul Zimmerman 1412*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1413*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_MULTICNT_MASK; 1414*197ba5f4SPaul Zimmerman hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & 1415*197ba5f4SPaul Zimmerman HCCHAR_MULTICNT_MASK; 1416*197ba5f4SPaul Zimmerman dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 1417*197ba5f4SPaul Zimmerman 1418*197ba5f4SPaul Zimmerman if (hcchar & HCCHAR_CHDIS) 1419*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, 1420*197ba5f4SPaul Zimmerman "%s: chdis set, channel %d, hcchar 0x%08x\n", 1421*197ba5f4SPaul Zimmerman __func__, chan->hc_num, hcchar); 1422*197ba5f4SPaul Zimmerman 1423*197ba5f4SPaul Zimmerman /* Set host channel enable after all other setup is complete */ 1424*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1425*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHDIS; 1426*197ba5f4SPaul Zimmerman 1427*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1428*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", 1429*197ba5f4SPaul Zimmerman (hcchar & HCCHAR_MULTICNT_MASK) >> 1430*197ba5f4SPaul Zimmerman HCCHAR_MULTICNT_SHIFT); 1431*197ba5f4SPaul Zimmerman 1432*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1433*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1434*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, 1435*197ba5f4SPaul Zimmerman chan->hc_num); 1436*197ba5f4SPaul Zimmerman 1437*197ba5f4SPaul Zimmerman chan->xfer_started = 1; 1438*197ba5f4SPaul Zimmerman chan->requests++; 1439*197ba5f4SPaul Zimmerman 1440*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_enable <= 0 && 1441*197ba5f4SPaul Zimmerman !chan->ep_is_in && chan->xfer_len > 0) 1442*197ba5f4SPaul Zimmerman /* Load OUT packet into the appropriate Tx FIFO */ 1443*197ba5f4SPaul Zimmerman dwc2_hc_write_packet(hsotg, chan); 1444*197ba5f4SPaul Zimmerman } 1445*197ba5f4SPaul Zimmerman 1446*197ba5f4SPaul Zimmerman /** 1447*197ba5f4SPaul Zimmerman * dwc2_hc_start_transfer_ddma() - Does the setup for a data transfer for a 1448*197ba5f4SPaul Zimmerman * host channel and starts the transfer in Descriptor DMA mode 1449*197ba5f4SPaul Zimmerman * 1450*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1451*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel 1452*197ba5f4SPaul Zimmerman * 1453*197ba5f4SPaul Zimmerman * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set. 1454*197ba5f4SPaul Zimmerman * Sets PID and NTD values. For periodic transfers initializes SCHED_INFO field 1455*197ba5f4SPaul Zimmerman * with micro-frame bitmap. 1456*197ba5f4SPaul Zimmerman * 1457*197ba5f4SPaul Zimmerman * Initializes HCDMA register with descriptor list address and CTD value then 1458*197ba5f4SPaul Zimmerman * starts the transfer via enabling the channel. 1459*197ba5f4SPaul Zimmerman */ 1460*197ba5f4SPaul Zimmerman void dwc2_hc_start_transfer_ddma(struct dwc2_hsotg *hsotg, 1461*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 1462*197ba5f4SPaul Zimmerman { 1463*197ba5f4SPaul Zimmerman u32 hcchar; 1464*197ba5f4SPaul Zimmerman u32 hc_dma; 1465*197ba5f4SPaul Zimmerman u32 hctsiz = 0; 1466*197ba5f4SPaul Zimmerman 1467*197ba5f4SPaul Zimmerman if (chan->do_ping) 1468*197ba5f4SPaul Zimmerman hctsiz |= TSIZ_DOPNG; 1469*197ba5f4SPaul Zimmerman 1470*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_ISOC) 1471*197ba5f4SPaul Zimmerman dwc2_set_pid_isoc(chan); 1472*197ba5f4SPaul Zimmerman 1473*197ba5f4SPaul Zimmerman /* Packet Count and Xfer Size are not used in Descriptor DMA mode */ 1474*197ba5f4SPaul Zimmerman hctsiz |= chan->data_pid_start << TSIZ_SC_MC_PID_SHIFT & 1475*197ba5f4SPaul Zimmerman TSIZ_SC_MC_PID_MASK; 1476*197ba5f4SPaul Zimmerman 1477*197ba5f4SPaul Zimmerman /* 0 - 1 descriptor, 1 - 2 descriptors, etc */ 1478*197ba5f4SPaul Zimmerman hctsiz |= (chan->ntd - 1) << TSIZ_NTD_SHIFT & TSIZ_NTD_MASK; 1479*197ba5f4SPaul Zimmerman 1480*197ba5f4SPaul Zimmerman /* Non-zero only for high-speed interrupt endpoints */ 1481*197ba5f4SPaul Zimmerman hctsiz |= chan->schinfo << TSIZ_SCHINFO_SHIFT & TSIZ_SCHINFO_MASK; 1482*197ba5f4SPaul Zimmerman 1483*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) { 1484*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 1485*197ba5f4SPaul Zimmerman chan->hc_num); 1486*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Start PID: %d\n", 1487*197ba5f4SPaul Zimmerman chan->data_pid_start); 1488*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " NTD: %d\n", chan->ntd - 1); 1489*197ba5f4SPaul Zimmerman } 1490*197ba5f4SPaul Zimmerman 1491*197ba5f4SPaul Zimmerman writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1492*197ba5f4SPaul Zimmerman 1493*197ba5f4SPaul Zimmerman hc_dma = (u32)chan->desc_list_addr & HCDMA_DMA_ADDR_MASK; 1494*197ba5f4SPaul Zimmerman 1495*197ba5f4SPaul Zimmerman /* Always start from first descriptor */ 1496*197ba5f4SPaul Zimmerman hc_dma &= ~HCDMA_CTD_MASK; 1497*197ba5f4SPaul Zimmerman writel(hc_dma, hsotg->regs + HCDMA(chan->hc_num)); 1498*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1499*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Wrote %08x to HCDMA(%d)\n", 1500*197ba5f4SPaul Zimmerman hc_dma, chan->hc_num); 1501*197ba5f4SPaul Zimmerman 1502*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1503*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_MULTICNT_MASK; 1504*197ba5f4SPaul Zimmerman hcchar |= chan->multi_count << HCCHAR_MULTICNT_SHIFT & 1505*197ba5f4SPaul Zimmerman HCCHAR_MULTICNT_MASK; 1506*197ba5f4SPaul Zimmerman 1507*197ba5f4SPaul Zimmerman if (hcchar & HCCHAR_CHDIS) 1508*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, 1509*197ba5f4SPaul Zimmerman "%s: chdis set, channel %d, hcchar 0x%08x\n", 1510*197ba5f4SPaul Zimmerman __func__, chan->hc_num, hcchar); 1511*197ba5f4SPaul Zimmerman 1512*197ba5f4SPaul Zimmerman /* Set host channel enable after all other setup is complete */ 1513*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1514*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHDIS; 1515*197ba5f4SPaul Zimmerman 1516*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1517*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " Multi Cnt: %d\n", 1518*197ba5f4SPaul Zimmerman (hcchar & HCCHAR_MULTICNT_MASK) >> 1519*197ba5f4SPaul Zimmerman HCCHAR_MULTICNT_SHIFT); 1520*197ba5f4SPaul Zimmerman 1521*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1522*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1523*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Wrote %08x to HCCHAR(%d)\n", hcchar, 1524*197ba5f4SPaul Zimmerman chan->hc_num); 1525*197ba5f4SPaul Zimmerman 1526*197ba5f4SPaul Zimmerman chan->xfer_started = 1; 1527*197ba5f4SPaul Zimmerman chan->requests++; 1528*197ba5f4SPaul Zimmerman } 1529*197ba5f4SPaul Zimmerman 1530*197ba5f4SPaul Zimmerman /** 1531*197ba5f4SPaul Zimmerman * dwc2_hc_continue_transfer() - Continues a data transfer that was started by 1532*197ba5f4SPaul Zimmerman * a previous call to dwc2_hc_start_transfer() 1533*197ba5f4SPaul Zimmerman * 1534*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1535*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel 1536*197ba5f4SPaul Zimmerman * 1537*197ba5f4SPaul Zimmerman * The caller must ensure there is sufficient space in the request queue and Tx 1538*197ba5f4SPaul Zimmerman * Data FIFO. This function should only be called in Slave mode. In DMA mode, 1539*197ba5f4SPaul Zimmerman * the controller acts autonomously to complete transfers programmed to a host 1540*197ba5f4SPaul Zimmerman * channel. 1541*197ba5f4SPaul Zimmerman * 1542*197ba5f4SPaul Zimmerman * For an OUT transfer, a new data packet is loaded into the appropriate FIFO 1543*197ba5f4SPaul Zimmerman * if there is any data remaining to be queued. For an IN transfer, another 1544*197ba5f4SPaul Zimmerman * data packet is always requested. For the SETUP phase of a control transfer, 1545*197ba5f4SPaul Zimmerman * this function does nothing. 1546*197ba5f4SPaul Zimmerman * 1547*197ba5f4SPaul Zimmerman * Return: 1 if a new request is queued, 0 if no more requests are required 1548*197ba5f4SPaul Zimmerman * for this transfer 1549*197ba5f4SPaul Zimmerman */ 1550*197ba5f4SPaul Zimmerman int dwc2_hc_continue_transfer(struct dwc2_hsotg *hsotg, 1551*197ba5f4SPaul Zimmerman struct dwc2_host_chan *chan) 1552*197ba5f4SPaul Zimmerman { 1553*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1554*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 1555*197ba5f4SPaul Zimmerman chan->hc_num); 1556*197ba5f4SPaul Zimmerman 1557*197ba5f4SPaul Zimmerman if (chan->do_split) 1558*197ba5f4SPaul Zimmerman /* SPLITs always queue just once per channel */ 1559*197ba5f4SPaul Zimmerman return 0; 1560*197ba5f4SPaul Zimmerman 1561*197ba5f4SPaul Zimmerman if (chan->data_pid_start == DWC2_HC_PID_SETUP) 1562*197ba5f4SPaul Zimmerman /* SETUPs are queued only once since they can't be NAK'd */ 1563*197ba5f4SPaul Zimmerman return 0; 1564*197ba5f4SPaul Zimmerman 1565*197ba5f4SPaul Zimmerman if (chan->ep_is_in) { 1566*197ba5f4SPaul Zimmerman /* 1567*197ba5f4SPaul Zimmerman * Always queue another request for other IN transfers. If 1568*197ba5f4SPaul Zimmerman * back-to-back INs are issued and NAKs are received for both, 1569*197ba5f4SPaul Zimmerman * the driver may still be processing the first NAK when the 1570*197ba5f4SPaul Zimmerman * second NAK is received. When the interrupt handler clears 1571*197ba5f4SPaul Zimmerman * the NAK interrupt for the first NAK, the second NAK will 1572*197ba5f4SPaul Zimmerman * not be seen. So we can't depend on the NAK interrupt 1573*197ba5f4SPaul Zimmerman * handler to requeue a NAK'd request. Instead, IN requests 1574*197ba5f4SPaul Zimmerman * are issued each time this function is called. When the 1575*197ba5f4SPaul Zimmerman * transfer completes, the extra requests for the channel will 1576*197ba5f4SPaul Zimmerman * be flushed. 1577*197ba5f4SPaul Zimmerman */ 1578*197ba5f4SPaul Zimmerman u32 hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1579*197ba5f4SPaul Zimmerman 1580*197ba5f4SPaul Zimmerman dwc2_hc_set_even_odd_frame(hsotg, chan, &hcchar); 1581*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1582*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHDIS; 1583*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1584*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, " IN xfer: hcchar = 0x%08x\n", 1585*197ba5f4SPaul Zimmerman hcchar); 1586*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1587*197ba5f4SPaul Zimmerman chan->requests++; 1588*197ba5f4SPaul Zimmerman return 1; 1589*197ba5f4SPaul Zimmerman } 1590*197ba5f4SPaul Zimmerman 1591*197ba5f4SPaul Zimmerman /* OUT transfers */ 1592*197ba5f4SPaul Zimmerman 1593*197ba5f4SPaul Zimmerman if (chan->xfer_count < chan->xfer_len) { 1594*197ba5f4SPaul Zimmerman if (chan->ep_type == USB_ENDPOINT_XFER_INT || 1595*197ba5f4SPaul Zimmerman chan->ep_type == USB_ENDPOINT_XFER_ISOC) { 1596*197ba5f4SPaul Zimmerman u32 hcchar = readl(hsotg->regs + 1597*197ba5f4SPaul Zimmerman HCCHAR(chan->hc_num)); 1598*197ba5f4SPaul Zimmerman 1599*197ba5f4SPaul Zimmerman dwc2_hc_set_even_odd_frame(hsotg, chan, 1600*197ba5f4SPaul Zimmerman &hcchar); 1601*197ba5f4SPaul Zimmerman } 1602*197ba5f4SPaul Zimmerman 1603*197ba5f4SPaul Zimmerman /* Load OUT packet into the appropriate Tx FIFO */ 1604*197ba5f4SPaul Zimmerman dwc2_hc_write_packet(hsotg, chan); 1605*197ba5f4SPaul Zimmerman chan->requests++; 1606*197ba5f4SPaul Zimmerman return 1; 1607*197ba5f4SPaul Zimmerman } 1608*197ba5f4SPaul Zimmerman 1609*197ba5f4SPaul Zimmerman return 0; 1610*197ba5f4SPaul Zimmerman } 1611*197ba5f4SPaul Zimmerman 1612*197ba5f4SPaul Zimmerman /** 1613*197ba5f4SPaul Zimmerman * dwc2_hc_do_ping() - Starts a PING transfer 1614*197ba5f4SPaul Zimmerman * 1615*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1616*197ba5f4SPaul Zimmerman * @chan: Information needed to initialize the host channel 1617*197ba5f4SPaul Zimmerman * 1618*197ba5f4SPaul Zimmerman * This function should only be called in Slave mode. The Do Ping bit is set in 1619*197ba5f4SPaul Zimmerman * the HCTSIZ register, then the channel is enabled. 1620*197ba5f4SPaul Zimmerman */ 1621*197ba5f4SPaul Zimmerman void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) 1622*197ba5f4SPaul Zimmerman { 1623*197ba5f4SPaul Zimmerman u32 hcchar; 1624*197ba5f4SPaul Zimmerman u32 hctsiz; 1625*197ba5f4SPaul Zimmerman 1626*197ba5f4SPaul Zimmerman if (dbg_hc(chan)) 1627*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s: Channel %d\n", __func__, 1628*197ba5f4SPaul Zimmerman chan->hc_num); 1629*197ba5f4SPaul Zimmerman 1630*197ba5f4SPaul Zimmerman 1631*197ba5f4SPaul Zimmerman hctsiz = TSIZ_DOPNG; 1632*197ba5f4SPaul Zimmerman hctsiz |= 1 << TSIZ_PKTCNT_SHIFT; 1633*197ba5f4SPaul Zimmerman writel(hctsiz, hsotg->regs + HCTSIZ(chan->hc_num)); 1634*197ba5f4SPaul Zimmerman 1635*197ba5f4SPaul Zimmerman hcchar = readl(hsotg->regs + HCCHAR(chan->hc_num)); 1636*197ba5f4SPaul Zimmerman hcchar |= HCCHAR_CHENA; 1637*197ba5f4SPaul Zimmerman hcchar &= ~HCCHAR_CHDIS; 1638*197ba5f4SPaul Zimmerman writel(hcchar, hsotg->regs + HCCHAR(chan->hc_num)); 1639*197ba5f4SPaul Zimmerman } 1640*197ba5f4SPaul Zimmerman 1641*197ba5f4SPaul Zimmerman /** 1642*197ba5f4SPaul Zimmerman * dwc2_calc_frame_interval() - Calculates the correct frame Interval value for 1643*197ba5f4SPaul Zimmerman * the HFIR register according to PHY type and speed 1644*197ba5f4SPaul Zimmerman * 1645*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1646*197ba5f4SPaul Zimmerman * 1647*197ba5f4SPaul Zimmerman * NOTE: The caller can modify the value of the HFIR register only after the 1648*197ba5f4SPaul Zimmerman * Port Enable bit of the Host Port Control and Status register (HPRT.EnaPort) 1649*197ba5f4SPaul Zimmerman * has been set 1650*197ba5f4SPaul Zimmerman */ 1651*197ba5f4SPaul Zimmerman u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) 1652*197ba5f4SPaul Zimmerman { 1653*197ba5f4SPaul Zimmerman u32 usbcfg; 1654*197ba5f4SPaul Zimmerman u32 hprt0; 1655*197ba5f4SPaul Zimmerman int clock = 60; /* default value */ 1656*197ba5f4SPaul Zimmerman 1657*197ba5f4SPaul Zimmerman usbcfg = readl(hsotg->regs + GUSBCFG); 1658*197ba5f4SPaul Zimmerman hprt0 = readl(hsotg->regs + HPRT0); 1659*197ba5f4SPaul Zimmerman 1660*197ba5f4SPaul Zimmerman if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) && 1661*197ba5f4SPaul Zimmerman !(usbcfg & GUSBCFG_PHYIF16)) 1662*197ba5f4SPaul Zimmerman clock = 60; 1663*197ba5f4SPaul Zimmerman if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type == 1664*197ba5f4SPaul Zimmerman GHWCFG2_FS_PHY_TYPE_SHARED_ULPI) 1665*197ba5f4SPaul Zimmerman clock = 48; 1666*197ba5f4SPaul Zimmerman if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && 1667*197ba5f4SPaul Zimmerman !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) 1668*197ba5f4SPaul Zimmerman clock = 30; 1669*197ba5f4SPaul Zimmerman if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && 1670*197ba5f4SPaul Zimmerman !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && !(usbcfg & GUSBCFG_PHYIF16)) 1671*197ba5f4SPaul Zimmerman clock = 60; 1672*197ba5f4SPaul Zimmerman if ((usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && 1673*197ba5f4SPaul Zimmerman !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) 1674*197ba5f4SPaul Zimmerman clock = 48; 1675*197ba5f4SPaul Zimmerman if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) && 1676*197ba5f4SPaul Zimmerman hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI) 1677*197ba5f4SPaul Zimmerman clock = 48; 1678*197ba5f4SPaul Zimmerman if ((usbcfg & GUSBCFG_PHYSEL) && 1679*197ba5f4SPaul Zimmerman hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) 1680*197ba5f4SPaul Zimmerman clock = 48; 1681*197ba5f4SPaul Zimmerman 1682*197ba5f4SPaul Zimmerman if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED) 1683*197ba5f4SPaul Zimmerman /* High speed case */ 1684*197ba5f4SPaul Zimmerman return 125 * clock; 1685*197ba5f4SPaul Zimmerman else 1686*197ba5f4SPaul Zimmerman /* FS/LS case */ 1687*197ba5f4SPaul Zimmerman return 1000 * clock; 1688*197ba5f4SPaul Zimmerman } 1689*197ba5f4SPaul Zimmerman 1690*197ba5f4SPaul Zimmerman /** 1691*197ba5f4SPaul Zimmerman * dwc2_read_packet() - Reads a packet from the Rx FIFO into the destination 1692*197ba5f4SPaul Zimmerman * buffer 1693*197ba5f4SPaul Zimmerman * 1694*197ba5f4SPaul Zimmerman * @core_if: Programming view of DWC_otg controller 1695*197ba5f4SPaul Zimmerman * @dest: Destination buffer for the packet 1696*197ba5f4SPaul Zimmerman * @bytes: Number of bytes to copy to the destination 1697*197ba5f4SPaul Zimmerman */ 1698*197ba5f4SPaul Zimmerman void dwc2_read_packet(struct dwc2_hsotg *hsotg, u8 *dest, u16 bytes) 1699*197ba5f4SPaul Zimmerman { 1700*197ba5f4SPaul Zimmerman u32 __iomem *fifo = hsotg->regs + HCFIFO(0); 1701*197ba5f4SPaul Zimmerman u32 *data_buf = (u32 *)dest; 1702*197ba5f4SPaul Zimmerman int word_count = (bytes + 3) / 4; 1703*197ba5f4SPaul Zimmerman int i; 1704*197ba5f4SPaul Zimmerman 1705*197ba5f4SPaul Zimmerman /* 1706*197ba5f4SPaul Zimmerman * Todo: Account for the case where dest is not dword aligned. This 1707*197ba5f4SPaul Zimmerman * requires reading data from the FIFO into a u32 temp buffer, then 1708*197ba5f4SPaul Zimmerman * moving it into the data buffer. 1709*197ba5f4SPaul Zimmerman */ 1710*197ba5f4SPaul Zimmerman 1711*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s(%p,%p,%d)\n", __func__, hsotg, dest, bytes); 1712*197ba5f4SPaul Zimmerman 1713*197ba5f4SPaul Zimmerman for (i = 0; i < word_count; i++, data_buf++) 1714*197ba5f4SPaul Zimmerman *data_buf = readl(fifo); 1715*197ba5f4SPaul Zimmerman } 1716*197ba5f4SPaul Zimmerman 1717*197ba5f4SPaul Zimmerman /** 1718*197ba5f4SPaul Zimmerman * dwc2_dump_host_registers() - Prints the host registers 1719*197ba5f4SPaul Zimmerman * 1720*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1721*197ba5f4SPaul Zimmerman * 1722*197ba5f4SPaul Zimmerman * NOTE: This function will be removed once the peripheral controller code 1723*197ba5f4SPaul Zimmerman * is integrated and the driver is stable 1724*197ba5f4SPaul Zimmerman */ 1725*197ba5f4SPaul Zimmerman void dwc2_dump_host_registers(struct dwc2_hsotg *hsotg) 1726*197ba5f4SPaul Zimmerman { 1727*197ba5f4SPaul Zimmerman #ifdef DEBUG 1728*197ba5f4SPaul Zimmerman u32 __iomem *addr; 1729*197ba5f4SPaul Zimmerman int i; 1730*197ba5f4SPaul Zimmerman 1731*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Host Global Registers\n"); 1732*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCFG; 1733*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCFG @0x%08lX : 0x%08X\n", 1734*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1735*197ba5f4SPaul Zimmerman addr = hsotg->regs + HFIR; 1736*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HFIR @0x%08lX : 0x%08X\n", 1737*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1738*197ba5f4SPaul Zimmerman addr = hsotg->regs + HFNUM; 1739*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HFNUM @0x%08lX : 0x%08X\n", 1740*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1741*197ba5f4SPaul Zimmerman addr = hsotg->regs + HPTXSTS; 1742*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HPTXSTS @0x%08lX : 0x%08X\n", 1743*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1744*197ba5f4SPaul Zimmerman addr = hsotg->regs + HAINT; 1745*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HAINT @0x%08lX : 0x%08X\n", 1746*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1747*197ba5f4SPaul Zimmerman addr = hsotg->regs + HAINTMSK; 1748*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HAINTMSK @0x%08lX : 0x%08X\n", 1749*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1750*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable > 0) { 1751*197ba5f4SPaul Zimmerman addr = hsotg->regs + HFLBADDR; 1752*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HFLBADDR @0x%08lX : 0x%08X\n", 1753*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1754*197ba5f4SPaul Zimmerman } 1755*197ba5f4SPaul Zimmerman 1756*197ba5f4SPaul Zimmerman addr = hsotg->regs + HPRT0; 1757*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HPRT0 @0x%08lX : 0x%08X\n", 1758*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1759*197ba5f4SPaul Zimmerman 1760*197ba5f4SPaul Zimmerman for (i = 0; i < hsotg->core_params->host_channels; i++) { 1761*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Host Channel %d Specific Registers\n", i); 1762*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCCHAR(i); 1763*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCCHAR @0x%08lX : 0x%08X\n", 1764*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1765*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCSPLT(i); 1766*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCSPLT @0x%08lX : 0x%08X\n", 1767*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1768*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCINT(i); 1769*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCINT @0x%08lX : 0x%08X\n", 1770*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1771*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCINTMSK(i); 1772*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCINTMSK @0x%08lX : 0x%08X\n", 1773*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1774*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCTSIZ(i); 1775*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCTSIZ @0x%08lX : 0x%08X\n", 1776*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1777*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCDMA(i); 1778*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCDMA @0x%08lX : 0x%08X\n", 1779*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1780*197ba5f4SPaul Zimmerman if (hsotg->core_params->dma_desc_enable > 0) { 1781*197ba5f4SPaul Zimmerman addr = hsotg->regs + HCDMAB(i); 1782*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HCDMAB @0x%08lX : 0x%08X\n", 1783*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1784*197ba5f4SPaul Zimmerman } 1785*197ba5f4SPaul Zimmerman } 1786*197ba5f4SPaul Zimmerman #endif 1787*197ba5f4SPaul Zimmerman } 1788*197ba5f4SPaul Zimmerman 1789*197ba5f4SPaul Zimmerman /** 1790*197ba5f4SPaul Zimmerman * dwc2_dump_global_registers() - Prints the core global registers 1791*197ba5f4SPaul Zimmerman * 1792*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1793*197ba5f4SPaul Zimmerman * 1794*197ba5f4SPaul Zimmerman * NOTE: This function will be removed once the peripheral controller code 1795*197ba5f4SPaul Zimmerman * is integrated and the driver is stable 1796*197ba5f4SPaul Zimmerman */ 1797*197ba5f4SPaul Zimmerman void dwc2_dump_global_registers(struct dwc2_hsotg *hsotg) 1798*197ba5f4SPaul Zimmerman { 1799*197ba5f4SPaul Zimmerman #ifdef DEBUG 1800*197ba5f4SPaul Zimmerman u32 __iomem *addr; 1801*197ba5f4SPaul Zimmerman 1802*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Core Global Registers\n"); 1803*197ba5f4SPaul Zimmerman addr = hsotg->regs + GOTGCTL; 1804*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GOTGCTL @0x%08lX : 0x%08X\n", 1805*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1806*197ba5f4SPaul Zimmerman addr = hsotg->regs + GOTGINT; 1807*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GOTGINT @0x%08lX : 0x%08X\n", 1808*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1809*197ba5f4SPaul Zimmerman addr = hsotg->regs + GAHBCFG; 1810*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GAHBCFG @0x%08lX : 0x%08X\n", 1811*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1812*197ba5f4SPaul Zimmerman addr = hsotg->regs + GUSBCFG; 1813*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GUSBCFG @0x%08lX : 0x%08X\n", 1814*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1815*197ba5f4SPaul Zimmerman addr = hsotg->regs + GRSTCTL; 1816*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GRSTCTL @0x%08lX : 0x%08X\n", 1817*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1818*197ba5f4SPaul Zimmerman addr = hsotg->regs + GINTSTS; 1819*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GINTSTS @0x%08lX : 0x%08X\n", 1820*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1821*197ba5f4SPaul Zimmerman addr = hsotg->regs + GINTMSK; 1822*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GINTMSK @0x%08lX : 0x%08X\n", 1823*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1824*197ba5f4SPaul Zimmerman addr = hsotg->regs + GRXSTSR; 1825*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GRXSTSR @0x%08lX : 0x%08X\n", 1826*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1827*197ba5f4SPaul Zimmerman addr = hsotg->regs + GRXFSIZ; 1828*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GRXFSIZ @0x%08lX : 0x%08X\n", 1829*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1830*197ba5f4SPaul Zimmerman addr = hsotg->regs + GNPTXFSIZ; 1831*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GNPTXFSIZ @0x%08lX : 0x%08X\n", 1832*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1833*197ba5f4SPaul Zimmerman addr = hsotg->regs + GNPTXSTS; 1834*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GNPTXSTS @0x%08lX : 0x%08X\n", 1835*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1836*197ba5f4SPaul Zimmerman addr = hsotg->regs + GI2CCTL; 1837*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GI2CCTL @0x%08lX : 0x%08X\n", 1838*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1839*197ba5f4SPaul Zimmerman addr = hsotg->regs + GPVNDCTL; 1840*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GPVNDCTL @0x%08lX : 0x%08X\n", 1841*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1842*197ba5f4SPaul Zimmerman addr = hsotg->regs + GGPIO; 1843*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GGPIO @0x%08lX : 0x%08X\n", 1844*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1845*197ba5f4SPaul Zimmerman addr = hsotg->regs + GUID; 1846*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GUID @0x%08lX : 0x%08X\n", 1847*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1848*197ba5f4SPaul Zimmerman addr = hsotg->regs + GSNPSID; 1849*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GSNPSID @0x%08lX : 0x%08X\n", 1850*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1851*197ba5f4SPaul Zimmerman addr = hsotg->regs + GHWCFG1; 1852*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GHWCFG1 @0x%08lX : 0x%08X\n", 1853*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1854*197ba5f4SPaul Zimmerman addr = hsotg->regs + GHWCFG2; 1855*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GHWCFG2 @0x%08lX : 0x%08X\n", 1856*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1857*197ba5f4SPaul Zimmerman addr = hsotg->regs + GHWCFG3; 1858*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GHWCFG3 @0x%08lX : 0x%08X\n", 1859*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1860*197ba5f4SPaul Zimmerman addr = hsotg->regs + GHWCFG4; 1861*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GHWCFG4 @0x%08lX : 0x%08X\n", 1862*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1863*197ba5f4SPaul Zimmerman addr = hsotg->regs + GLPMCFG; 1864*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GLPMCFG @0x%08lX : 0x%08X\n", 1865*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1866*197ba5f4SPaul Zimmerman addr = hsotg->regs + GPWRDN; 1867*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GPWRDN @0x%08lX : 0x%08X\n", 1868*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1869*197ba5f4SPaul Zimmerman addr = hsotg->regs + GDFIFOCFG; 1870*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "GDFIFOCFG @0x%08lX : 0x%08X\n", 1871*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1872*197ba5f4SPaul Zimmerman addr = hsotg->regs + HPTXFSIZ; 1873*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "HPTXFSIZ @0x%08lX : 0x%08X\n", 1874*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1875*197ba5f4SPaul Zimmerman 1876*197ba5f4SPaul Zimmerman addr = hsotg->regs + PCGCTL; 1877*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "PCGCTL @0x%08lX : 0x%08X\n", 1878*197ba5f4SPaul Zimmerman (unsigned long)addr, readl(addr)); 1879*197ba5f4SPaul Zimmerman #endif 1880*197ba5f4SPaul Zimmerman } 1881*197ba5f4SPaul Zimmerman 1882*197ba5f4SPaul Zimmerman /** 1883*197ba5f4SPaul Zimmerman * dwc2_flush_tx_fifo() - Flushes a Tx FIFO 1884*197ba5f4SPaul Zimmerman * 1885*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1886*197ba5f4SPaul Zimmerman * @num: Tx FIFO to flush 1887*197ba5f4SPaul Zimmerman */ 1888*197ba5f4SPaul Zimmerman void dwc2_flush_tx_fifo(struct dwc2_hsotg *hsotg, const int num) 1889*197ba5f4SPaul Zimmerman { 1890*197ba5f4SPaul Zimmerman u32 greset; 1891*197ba5f4SPaul Zimmerman int count = 0; 1892*197ba5f4SPaul Zimmerman 1893*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "Flush Tx FIFO %d\n", num); 1894*197ba5f4SPaul Zimmerman 1895*197ba5f4SPaul Zimmerman greset = GRSTCTL_TXFFLSH; 1896*197ba5f4SPaul Zimmerman greset |= num << GRSTCTL_TXFNUM_SHIFT & GRSTCTL_TXFNUM_MASK; 1897*197ba5f4SPaul Zimmerman writel(greset, hsotg->regs + GRSTCTL); 1898*197ba5f4SPaul Zimmerman 1899*197ba5f4SPaul Zimmerman do { 1900*197ba5f4SPaul Zimmerman greset = readl(hsotg->regs + GRSTCTL); 1901*197ba5f4SPaul Zimmerman if (++count > 10000) { 1902*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, 1903*197ba5f4SPaul Zimmerman "%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n", 1904*197ba5f4SPaul Zimmerman __func__, greset, 1905*197ba5f4SPaul Zimmerman readl(hsotg->regs + GNPTXSTS)); 1906*197ba5f4SPaul Zimmerman break; 1907*197ba5f4SPaul Zimmerman } 1908*197ba5f4SPaul Zimmerman udelay(1); 1909*197ba5f4SPaul Zimmerman } while (greset & GRSTCTL_TXFFLSH); 1910*197ba5f4SPaul Zimmerman 1911*197ba5f4SPaul Zimmerman /* Wait for at least 3 PHY Clocks */ 1912*197ba5f4SPaul Zimmerman udelay(1); 1913*197ba5f4SPaul Zimmerman } 1914*197ba5f4SPaul Zimmerman 1915*197ba5f4SPaul Zimmerman /** 1916*197ba5f4SPaul Zimmerman * dwc2_flush_rx_fifo() - Flushes the Rx FIFO 1917*197ba5f4SPaul Zimmerman * 1918*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 1919*197ba5f4SPaul Zimmerman */ 1920*197ba5f4SPaul Zimmerman void dwc2_flush_rx_fifo(struct dwc2_hsotg *hsotg) 1921*197ba5f4SPaul Zimmerman { 1922*197ba5f4SPaul Zimmerman u32 greset; 1923*197ba5f4SPaul Zimmerman int count = 0; 1924*197ba5f4SPaul Zimmerman 1925*197ba5f4SPaul Zimmerman dev_vdbg(hsotg->dev, "%s()\n", __func__); 1926*197ba5f4SPaul Zimmerman 1927*197ba5f4SPaul Zimmerman greset = GRSTCTL_RXFFLSH; 1928*197ba5f4SPaul Zimmerman writel(greset, hsotg->regs + GRSTCTL); 1929*197ba5f4SPaul Zimmerman 1930*197ba5f4SPaul Zimmerman do { 1931*197ba5f4SPaul Zimmerman greset = readl(hsotg->regs + GRSTCTL); 1932*197ba5f4SPaul Zimmerman if (++count > 10000) { 1933*197ba5f4SPaul Zimmerman dev_warn(hsotg->dev, "%s() HANG! GRSTCTL=%0x\n", 1934*197ba5f4SPaul Zimmerman __func__, greset); 1935*197ba5f4SPaul Zimmerman break; 1936*197ba5f4SPaul Zimmerman } 1937*197ba5f4SPaul Zimmerman udelay(1); 1938*197ba5f4SPaul Zimmerman } while (greset & GRSTCTL_RXFFLSH); 1939*197ba5f4SPaul Zimmerman 1940*197ba5f4SPaul Zimmerman /* Wait for at least 3 PHY Clocks */ 1941*197ba5f4SPaul Zimmerman udelay(1); 1942*197ba5f4SPaul Zimmerman } 1943*197ba5f4SPaul Zimmerman 1944*197ba5f4SPaul Zimmerman #define DWC2_OUT_OF_BOUNDS(a, b, c) ((a) < (b) || (a) > (c)) 1945*197ba5f4SPaul Zimmerman 1946*197ba5f4SPaul Zimmerman /* Parameter access functions */ 1947*197ba5f4SPaul Zimmerman void dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val) 1948*197ba5f4SPaul Zimmerman { 1949*197ba5f4SPaul Zimmerman int valid = 1; 1950*197ba5f4SPaul Zimmerman 1951*197ba5f4SPaul Zimmerman switch (val) { 1952*197ba5f4SPaul Zimmerman case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: 1953*197ba5f4SPaul Zimmerman if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) 1954*197ba5f4SPaul Zimmerman valid = 0; 1955*197ba5f4SPaul Zimmerman break; 1956*197ba5f4SPaul Zimmerman case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: 1957*197ba5f4SPaul Zimmerman switch (hsotg->hw_params.op_mode) { 1958*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 1959*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 1960*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 1961*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 1962*197ba5f4SPaul Zimmerman break; 1963*197ba5f4SPaul Zimmerman default: 1964*197ba5f4SPaul Zimmerman valid = 0; 1965*197ba5f4SPaul Zimmerman break; 1966*197ba5f4SPaul Zimmerman } 1967*197ba5f4SPaul Zimmerman break; 1968*197ba5f4SPaul Zimmerman case DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE: 1969*197ba5f4SPaul Zimmerman /* always valid */ 1970*197ba5f4SPaul Zimmerman break; 1971*197ba5f4SPaul Zimmerman default: 1972*197ba5f4SPaul Zimmerman valid = 0; 1973*197ba5f4SPaul Zimmerman break; 1974*197ba5f4SPaul Zimmerman } 1975*197ba5f4SPaul Zimmerman 1976*197ba5f4SPaul Zimmerman if (!valid) { 1977*197ba5f4SPaul Zimmerman if (val >= 0) 1978*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 1979*197ba5f4SPaul Zimmerman "%d invalid for otg_cap parameter. Check HW configuration.\n", 1980*197ba5f4SPaul Zimmerman val); 1981*197ba5f4SPaul Zimmerman switch (hsotg->hw_params.op_mode) { 1982*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 1983*197ba5f4SPaul Zimmerman val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; 1984*197ba5f4SPaul Zimmerman break; 1985*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 1986*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 1987*197ba5f4SPaul Zimmerman case GHWCFG2_OP_MODE_SRP_CAPABLE_HOST: 1988*197ba5f4SPaul Zimmerman val = DWC2_CAP_PARAM_SRP_ONLY_CAPABLE; 1989*197ba5f4SPaul Zimmerman break; 1990*197ba5f4SPaul Zimmerman default: 1991*197ba5f4SPaul Zimmerman val = DWC2_CAP_PARAM_NO_HNP_SRP_CAPABLE; 1992*197ba5f4SPaul Zimmerman break; 1993*197ba5f4SPaul Zimmerman } 1994*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting otg_cap to %d\n", val); 1995*197ba5f4SPaul Zimmerman } 1996*197ba5f4SPaul Zimmerman 1997*197ba5f4SPaul Zimmerman hsotg->core_params->otg_cap = val; 1998*197ba5f4SPaul Zimmerman } 1999*197ba5f4SPaul Zimmerman 2000*197ba5f4SPaul Zimmerman void dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val) 2001*197ba5f4SPaul Zimmerman { 2002*197ba5f4SPaul Zimmerman int valid = 1; 2003*197ba5f4SPaul Zimmerman 2004*197ba5f4SPaul Zimmerman if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH) 2005*197ba5f4SPaul Zimmerman valid = 0; 2006*197ba5f4SPaul Zimmerman if (val < 0) 2007*197ba5f4SPaul Zimmerman valid = 0; 2008*197ba5f4SPaul Zimmerman 2009*197ba5f4SPaul Zimmerman if (!valid) { 2010*197ba5f4SPaul Zimmerman if (val >= 0) 2011*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2012*197ba5f4SPaul Zimmerman "%d invalid for dma_enable parameter. Check HW configuration.\n", 2013*197ba5f4SPaul Zimmerman val); 2014*197ba5f4SPaul Zimmerman val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH; 2015*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val); 2016*197ba5f4SPaul Zimmerman } 2017*197ba5f4SPaul Zimmerman 2018*197ba5f4SPaul Zimmerman hsotg->core_params->dma_enable = val; 2019*197ba5f4SPaul Zimmerman } 2020*197ba5f4SPaul Zimmerman 2021*197ba5f4SPaul Zimmerman void dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val) 2022*197ba5f4SPaul Zimmerman { 2023*197ba5f4SPaul Zimmerman int valid = 1; 2024*197ba5f4SPaul Zimmerman 2025*197ba5f4SPaul Zimmerman if (val > 0 && (hsotg->core_params->dma_enable <= 0 || 2026*197ba5f4SPaul Zimmerman !hsotg->hw_params.dma_desc_enable)) 2027*197ba5f4SPaul Zimmerman valid = 0; 2028*197ba5f4SPaul Zimmerman if (val < 0) 2029*197ba5f4SPaul Zimmerman valid = 0; 2030*197ba5f4SPaul Zimmerman 2031*197ba5f4SPaul Zimmerman if (!valid) { 2032*197ba5f4SPaul Zimmerman if (val >= 0) 2033*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2034*197ba5f4SPaul Zimmerman "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", 2035*197ba5f4SPaul Zimmerman val); 2036*197ba5f4SPaul Zimmerman val = (hsotg->core_params->dma_enable > 0 && 2037*197ba5f4SPaul Zimmerman hsotg->hw_params.dma_desc_enable); 2038*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); 2039*197ba5f4SPaul Zimmerman } 2040*197ba5f4SPaul Zimmerman 2041*197ba5f4SPaul Zimmerman hsotg->core_params->dma_desc_enable = val; 2042*197ba5f4SPaul Zimmerman } 2043*197ba5f4SPaul Zimmerman 2044*197ba5f4SPaul Zimmerman void dwc2_set_param_host_support_fs_ls_low_power(struct dwc2_hsotg *hsotg, 2045*197ba5f4SPaul Zimmerman int val) 2046*197ba5f4SPaul Zimmerman { 2047*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2048*197ba5f4SPaul Zimmerman if (val >= 0) { 2049*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2050*197ba5f4SPaul Zimmerman "Wrong value for host_support_fs_low_power\n"); 2051*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2052*197ba5f4SPaul Zimmerman "host_support_fs_low_power must be 0 or 1\n"); 2053*197ba5f4SPaul Zimmerman } 2054*197ba5f4SPaul Zimmerman val = 0; 2055*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, 2056*197ba5f4SPaul Zimmerman "Setting host_support_fs_low_power to %d\n", val); 2057*197ba5f4SPaul Zimmerman } 2058*197ba5f4SPaul Zimmerman 2059*197ba5f4SPaul Zimmerman hsotg->core_params->host_support_fs_ls_low_power = val; 2060*197ba5f4SPaul Zimmerman } 2061*197ba5f4SPaul Zimmerman 2062*197ba5f4SPaul Zimmerman void dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val) 2063*197ba5f4SPaul Zimmerman { 2064*197ba5f4SPaul Zimmerman int valid = 1; 2065*197ba5f4SPaul Zimmerman 2066*197ba5f4SPaul Zimmerman if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo) 2067*197ba5f4SPaul Zimmerman valid = 0; 2068*197ba5f4SPaul Zimmerman if (val < 0) 2069*197ba5f4SPaul Zimmerman valid = 0; 2070*197ba5f4SPaul Zimmerman 2071*197ba5f4SPaul Zimmerman if (!valid) { 2072*197ba5f4SPaul Zimmerman if (val >= 0) 2073*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2074*197ba5f4SPaul Zimmerman "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", 2075*197ba5f4SPaul Zimmerman val); 2076*197ba5f4SPaul Zimmerman val = hsotg->hw_params.enable_dynamic_fifo; 2077*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); 2078*197ba5f4SPaul Zimmerman } 2079*197ba5f4SPaul Zimmerman 2080*197ba5f4SPaul Zimmerman hsotg->core_params->enable_dynamic_fifo = val; 2081*197ba5f4SPaul Zimmerman } 2082*197ba5f4SPaul Zimmerman 2083*197ba5f4SPaul Zimmerman void dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val) 2084*197ba5f4SPaul Zimmerman { 2085*197ba5f4SPaul Zimmerman int valid = 1; 2086*197ba5f4SPaul Zimmerman 2087*197ba5f4SPaul Zimmerman if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size) 2088*197ba5f4SPaul Zimmerman valid = 0; 2089*197ba5f4SPaul Zimmerman 2090*197ba5f4SPaul Zimmerman if (!valid) { 2091*197ba5f4SPaul Zimmerman if (val >= 0) 2092*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2093*197ba5f4SPaul Zimmerman "%d invalid for host_rx_fifo_size. Check HW configuration.\n", 2094*197ba5f4SPaul Zimmerman val); 2095*197ba5f4SPaul Zimmerman val = hsotg->hw_params.host_rx_fifo_size; 2096*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val); 2097*197ba5f4SPaul Zimmerman } 2098*197ba5f4SPaul Zimmerman 2099*197ba5f4SPaul Zimmerman hsotg->core_params->host_rx_fifo_size = val; 2100*197ba5f4SPaul Zimmerman } 2101*197ba5f4SPaul Zimmerman 2102*197ba5f4SPaul Zimmerman void dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) 2103*197ba5f4SPaul Zimmerman { 2104*197ba5f4SPaul Zimmerman int valid = 1; 2105*197ba5f4SPaul Zimmerman 2106*197ba5f4SPaul Zimmerman if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size) 2107*197ba5f4SPaul Zimmerman valid = 0; 2108*197ba5f4SPaul Zimmerman 2109*197ba5f4SPaul Zimmerman if (!valid) { 2110*197ba5f4SPaul Zimmerman if (val >= 0) 2111*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2112*197ba5f4SPaul Zimmerman "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", 2113*197ba5f4SPaul Zimmerman val); 2114*197ba5f4SPaul Zimmerman val = hsotg->hw_params.host_nperio_tx_fifo_size; 2115*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", 2116*197ba5f4SPaul Zimmerman val); 2117*197ba5f4SPaul Zimmerman } 2118*197ba5f4SPaul Zimmerman 2119*197ba5f4SPaul Zimmerman hsotg->core_params->host_nperio_tx_fifo_size = val; 2120*197ba5f4SPaul Zimmerman } 2121*197ba5f4SPaul Zimmerman 2122*197ba5f4SPaul Zimmerman void dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val) 2123*197ba5f4SPaul Zimmerman { 2124*197ba5f4SPaul Zimmerman int valid = 1; 2125*197ba5f4SPaul Zimmerman 2126*197ba5f4SPaul Zimmerman if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size) 2127*197ba5f4SPaul Zimmerman valid = 0; 2128*197ba5f4SPaul Zimmerman 2129*197ba5f4SPaul Zimmerman if (!valid) { 2130*197ba5f4SPaul Zimmerman if (val >= 0) 2131*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2132*197ba5f4SPaul Zimmerman "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", 2133*197ba5f4SPaul Zimmerman val); 2134*197ba5f4SPaul Zimmerman val = hsotg->hw_params.host_perio_tx_fifo_size; 2135*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", 2136*197ba5f4SPaul Zimmerman val); 2137*197ba5f4SPaul Zimmerman } 2138*197ba5f4SPaul Zimmerman 2139*197ba5f4SPaul Zimmerman hsotg->core_params->host_perio_tx_fifo_size = val; 2140*197ba5f4SPaul Zimmerman } 2141*197ba5f4SPaul Zimmerman 2142*197ba5f4SPaul Zimmerman void dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val) 2143*197ba5f4SPaul Zimmerman { 2144*197ba5f4SPaul Zimmerman int valid = 1; 2145*197ba5f4SPaul Zimmerman 2146*197ba5f4SPaul Zimmerman if (val < 2047 || val > hsotg->hw_params.max_transfer_size) 2147*197ba5f4SPaul Zimmerman valid = 0; 2148*197ba5f4SPaul Zimmerman 2149*197ba5f4SPaul Zimmerman if (!valid) { 2150*197ba5f4SPaul Zimmerman if (val >= 0) 2151*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2152*197ba5f4SPaul Zimmerman "%d invalid for max_transfer_size. Check HW configuration.\n", 2153*197ba5f4SPaul Zimmerman val); 2154*197ba5f4SPaul Zimmerman val = hsotg->hw_params.max_transfer_size; 2155*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); 2156*197ba5f4SPaul Zimmerman } 2157*197ba5f4SPaul Zimmerman 2158*197ba5f4SPaul Zimmerman hsotg->core_params->max_transfer_size = val; 2159*197ba5f4SPaul Zimmerman } 2160*197ba5f4SPaul Zimmerman 2161*197ba5f4SPaul Zimmerman void dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val) 2162*197ba5f4SPaul Zimmerman { 2163*197ba5f4SPaul Zimmerman int valid = 1; 2164*197ba5f4SPaul Zimmerman 2165*197ba5f4SPaul Zimmerman if (val < 15 || val > hsotg->hw_params.max_packet_count) 2166*197ba5f4SPaul Zimmerman valid = 0; 2167*197ba5f4SPaul Zimmerman 2168*197ba5f4SPaul Zimmerman if (!valid) { 2169*197ba5f4SPaul Zimmerman if (val >= 0) 2170*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2171*197ba5f4SPaul Zimmerman "%d invalid for max_packet_count. Check HW configuration.\n", 2172*197ba5f4SPaul Zimmerman val); 2173*197ba5f4SPaul Zimmerman val = hsotg->hw_params.max_packet_count; 2174*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); 2175*197ba5f4SPaul Zimmerman } 2176*197ba5f4SPaul Zimmerman 2177*197ba5f4SPaul Zimmerman hsotg->core_params->max_packet_count = val; 2178*197ba5f4SPaul Zimmerman } 2179*197ba5f4SPaul Zimmerman 2180*197ba5f4SPaul Zimmerman void dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val) 2181*197ba5f4SPaul Zimmerman { 2182*197ba5f4SPaul Zimmerman int valid = 1; 2183*197ba5f4SPaul Zimmerman 2184*197ba5f4SPaul Zimmerman if (val < 1 || val > hsotg->hw_params.host_channels) 2185*197ba5f4SPaul Zimmerman valid = 0; 2186*197ba5f4SPaul Zimmerman 2187*197ba5f4SPaul Zimmerman if (!valid) { 2188*197ba5f4SPaul Zimmerman if (val >= 0) 2189*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2190*197ba5f4SPaul Zimmerman "%d invalid for host_channels. Check HW configuration.\n", 2191*197ba5f4SPaul Zimmerman val); 2192*197ba5f4SPaul Zimmerman val = hsotg->hw_params.host_channels; 2193*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); 2194*197ba5f4SPaul Zimmerman } 2195*197ba5f4SPaul Zimmerman 2196*197ba5f4SPaul Zimmerman hsotg->core_params->host_channels = val; 2197*197ba5f4SPaul Zimmerman } 2198*197ba5f4SPaul Zimmerman 2199*197ba5f4SPaul Zimmerman void dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val) 2200*197ba5f4SPaul Zimmerman { 2201*197ba5f4SPaul Zimmerman int valid = 0; 2202*197ba5f4SPaul Zimmerman u32 hs_phy_type, fs_phy_type; 2203*197ba5f4SPaul Zimmerman 2204*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, DWC2_PHY_TYPE_PARAM_FS, 2205*197ba5f4SPaul Zimmerman DWC2_PHY_TYPE_PARAM_ULPI)) { 2206*197ba5f4SPaul Zimmerman if (val >= 0) { 2207*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for phy_type\n"); 2208*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "phy_type must be 0, 1 or 2\n"); 2209*197ba5f4SPaul Zimmerman } 2210*197ba5f4SPaul Zimmerman 2211*197ba5f4SPaul Zimmerman valid = 0; 2212*197ba5f4SPaul Zimmerman } 2213*197ba5f4SPaul Zimmerman 2214*197ba5f4SPaul Zimmerman hs_phy_type = hsotg->hw_params.hs_phy_type; 2215*197ba5f4SPaul Zimmerman fs_phy_type = hsotg->hw_params.fs_phy_type; 2216*197ba5f4SPaul Zimmerman if (val == DWC2_PHY_TYPE_PARAM_UTMI && 2217*197ba5f4SPaul Zimmerman (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 2218*197ba5f4SPaul Zimmerman hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) 2219*197ba5f4SPaul Zimmerman valid = 1; 2220*197ba5f4SPaul Zimmerman else if (val == DWC2_PHY_TYPE_PARAM_ULPI && 2221*197ba5f4SPaul Zimmerman (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI || 2222*197ba5f4SPaul Zimmerman hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) 2223*197ba5f4SPaul Zimmerman valid = 1; 2224*197ba5f4SPaul Zimmerman else if (val == DWC2_PHY_TYPE_PARAM_FS && 2225*197ba5f4SPaul Zimmerman fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED) 2226*197ba5f4SPaul Zimmerman valid = 1; 2227*197ba5f4SPaul Zimmerman 2228*197ba5f4SPaul Zimmerman if (!valid) { 2229*197ba5f4SPaul Zimmerman if (val >= 0) 2230*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2231*197ba5f4SPaul Zimmerman "%d invalid for phy_type. Check HW configuration.\n", 2232*197ba5f4SPaul Zimmerman val); 2233*197ba5f4SPaul Zimmerman val = DWC2_PHY_TYPE_PARAM_FS; 2234*197ba5f4SPaul Zimmerman if (hs_phy_type != GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED) { 2235*197ba5f4SPaul Zimmerman if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 2236*197ba5f4SPaul Zimmerman hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI) 2237*197ba5f4SPaul Zimmerman val = DWC2_PHY_TYPE_PARAM_UTMI; 2238*197ba5f4SPaul Zimmerman else 2239*197ba5f4SPaul Zimmerman val = DWC2_PHY_TYPE_PARAM_ULPI; 2240*197ba5f4SPaul Zimmerman } 2241*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting phy_type to %d\n", val); 2242*197ba5f4SPaul Zimmerman } 2243*197ba5f4SPaul Zimmerman 2244*197ba5f4SPaul Zimmerman hsotg->core_params->phy_type = val; 2245*197ba5f4SPaul Zimmerman } 2246*197ba5f4SPaul Zimmerman 2247*197ba5f4SPaul Zimmerman static int dwc2_get_param_phy_type(struct dwc2_hsotg *hsotg) 2248*197ba5f4SPaul Zimmerman { 2249*197ba5f4SPaul Zimmerman return hsotg->core_params->phy_type; 2250*197ba5f4SPaul Zimmerman } 2251*197ba5f4SPaul Zimmerman 2252*197ba5f4SPaul Zimmerman void dwc2_set_param_speed(struct dwc2_hsotg *hsotg, int val) 2253*197ba5f4SPaul Zimmerman { 2254*197ba5f4SPaul Zimmerman int valid = 1; 2255*197ba5f4SPaul Zimmerman 2256*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2257*197ba5f4SPaul Zimmerman if (val >= 0) { 2258*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for speed parameter\n"); 2259*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "max_speed parameter must be 0 or 1\n"); 2260*197ba5f4SPaul Zimmerman } 2261*197ba5f4SPaul Zimmerman valid = 0; 2262*197ba5f4SPaul Zimmerman } 2263*197ba5f4SPaul Zimmerman 2264*197ba5f4SPaul Zimmerman if (val == DWC2_SPEED_PARAM_HIGH && 2265*197ba5f4SPaul Zimmerman dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) 2266*197ba5f4SPaul Zimmerman valid = 0; 2267*197ba5f4SPaul Zimmerman 2268*197ba5f4SPaul Zimmerman if (!valid) { 2269*197ba5f4SPaul Zimmerman if (val >= 0) 2270*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2271*197ba5f4SPaul Zimmerman "%d invalid for speed parameter. Check HW configuration.\n", 2272*197ba5f4SPaul Zimmerman val); 2273*197ba5f4SPaul Zimmerman val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS ? 2274*197ba5f4SPaul Zimmerman DWC2_SPEED_PARAM_FULL : DWC2_SPEED_PARAM_HIGH; 2275*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting speed to %d\n", val); 2276*197ba5f4SPaul Zimmerman } 2277*197ba5f4SPaul Zimmerman 2278*197ba5f4SPaul Zimmerman hsotg->core_params->speed = val; 2279*197ba5f4SPaul Zimmerman } 2280*197ba5f4SPaul Zimmerman 2281*197ba5f4SPaul Zimmerman void dwc2_set_param_host_ls_low_power_phy_clk(struct dwc2_hsotg *hsotg, int val) 2282*197ba5f4SPaul Zimmerman { 2283*197ba5f4SPaul Zimmerman int valid = 1; 2284*197ba5f4SPaul Zimmerman 2285*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ, 2286*197ba5f4SPaul Zimmerman DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)) { 2287*197ba5f4SPaul Zimmerman if (val >= 0) { 2288*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2289*197ba5f4SPaul Zimmerman "Wrong value for host_ls_low_power_phy_clk parameter\n"); 2290*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2291*197ba5f4SPaul Zimmerman "host_ls_low_power_phy_clk must be 0 or 1\n"); 2292*197ba5f4SPaul Zimmerman } 2293*197ba5f4SPaul Zimmerman valid = 0; 2294*197ba5f4SPaul Zimmerman } 2295*197ba5f4SPaul Zimmerman 2296*197ba5f4SPaul Zimmerman if (val == DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ && 2297*197ba5f4SPaul Zimmerman dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS) 2298*197ba5f4SPaul Zimmerman valid = 0; 2299*197ba5f4SPaul Zimmerman 2300*197ba5f4SPaul Zimmerman if (!valid) { 2301*197ba5f4SPaul Zimmerman if (val >= 0) 2302*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2303*197ba5f4SPaul Zimmerman "%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n", 2304*197ba5f4SPaul Zimmerman val); 2305*197ba5f4SPaul Zimmerman val = dwc2_get_param_phy_type(hsotg) == DWC2_PHY_TYPE_PARAM_FS 2306*197ba5f4SPaul Zimmerman ? DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 2307*197ba5f4SPaul Zimmerman : DWC2_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ; 2308*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting host_ls_low_power_phy_clk to %d\n", 2309*197ba5f4SPaul Zimmerman val); 2310*197ba5f4SPaul Zimmerman } 2311*197ba5f4SPaul Zimmerman 2312*197ba5f4SPaul Zimmerman hsotg->core_params->host_ls_low_power_phy_clk = val; 2313*197ba5f4SPaul Zimmerman } 2314*197ba5f4SPaul Zimmerman 2315*197ba5f4SPaul Zimmerman void dwc2_set_param_phy_ulpi_ddr(struct dwc2_hsotg *hsotg, int val) 2316*197ba5f4SPaul Zimmerman { 2317*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2318*197ba5f4SPaul Zimmerman if (val >= 0) { 2319*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for phy_ulpi_ddr\n"); 2320*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "phy_upli_ddr must be 0 or 1\n"); 2321*197ba5f4SPaul Zimmerman } 2322*197ba5f4SPaul Zimmerman val = 0; 2323*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting phy_upli_ddr to %d\n", val); 2324*197ba5f4SPaul Zimmerman } 2325*197ba5f4SPaul Zimmerman 2326*197ba5f4SPaul Zimmerman hsotg->core_params->phy_ulpi_ddr = val; 2327*197ba5f4SPaul Zimmerman } 2328*197ba5f4SPaul Zimmerman 2329*197ba5f4SPaul Zimmerman void dwc2_set_param_phy_ulpi_ext_vbus(struct dwc2_hsotg *hsotg, int val) 2330*197ba5f4SPaul Zimmerman { 2331*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2332*197ba5f4SPaul Zimmerman if (val >= 0) { 2333*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2334*197ba5f4SPaul Zimmerman "Wrong value for phy_ulpi_ext_vbus\n"); 2335*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2336*197ba5f4SPaul Zimmerman "phy_ulpi_ext_vbus must be 0 or 1\n"); 2337*197ba5f4SPaul Zimmerman } 2338*197ba5f4SPaul Zimmerman val = 0; 2339*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting phy_ulpi_ext_vbus to %d\n", val); 2340*197ba5f4SPaul Zimmerman } 2341*197ba5f4SPaul Zimmerman 2342*197ba5f4SPaul Zimmerman hsotg->core_params->phy_ulpi_ext_vbus = val; 2343*197ba5f4SPaul Zimmerman } 2344*197ba5f4SPaul Zimmerman 2345*197ba5f4SPaul Zimmerman void dwc2_set_param_phy_utmi_width(struct dwc2_hsotg *hsotg, int val) 2346*197ba5f4SPaul Zimmerman { 2347*197ba5f4SPaul Zimmerman int valid = 0; 2348*197ba5f4SPaul Zimmerman 2349*197ba5f4SPaul Zimmerman switch (hsotg->hw_params.utmi_phy_data_width) { 2350*197ba5f4SPaul Zimmerman case GHWCFG4_UTMI_PHY_DATA_WIDTH_8: 2351*197ba5f4SPaul Zimmerman valid = (val == 8); 2352*197ba5f4SPaul Zimmerman break; 2353*197ba5f4SPaul Zimmerman case GHWCFG4_UTMI_PHY_DATA_WIDTH_16: 2354*197ba5f4SPaul Zimmerman valid = (val == 16); 2355*197ba5f4SPaul Zimmerman break; 2356*197ba5f4SPaul Zimmerman case GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16: 2357*197ba5f4SPaul Zimmerman valid = (val == 8 || val == 16); 2358*197ba5f4SPaul Zimmerman break; 2359*197ba5f4SPaul Zimmerman } 2360*197ba5f4SPaul Zimmerman 2361*197ba5f4SPaul Zimmerman if (!valid) { 2362*197ba5f4SPaul Zimmerman if (val >= 0) { 2363*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2364*197ba5f4SPaul Zimmerman "%d invalid for phy_utmi_width. Check HW configuration.\n", 2365*197ba5f4SPaul Zimmerman val); 2366*197ba5f4SPaul Zimmerman } 2367*197ba5f4SPaul Zimmerman val = (hsotg->hw_params.utmi_phy_data_width == 2368*197ba5f4SPaul Zimmerman GHWCFG4_UTMI_PHY_DATA_WIDTH_8) ? 8 : 16; 2369*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting phy_utmi_width to %d\n", val); 2370*197ba5f4SPaul Zimmerman } 2371*197ba5f4SPaul Zimmerman 2372*197ba5f4SPaul Zimmerman hsotg->core_params->phy_utmi_width = val; 2373*197ba5f4SPaul Zimmerman } 2374*197ba5f4SPaul Zimmerman 2375*197ba5f4SPaul Zimmerman void dwc2_set_param_ulpi_fs_ls(struct dwc2_hsotg *hsotg, int val) 2376*197ba5f4SPaul Zimmerman { 2377*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2378*197ba5f4SPaul Zimmerman if (val >= 0) { 2379*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for ulpi_fs_ls\n"); 2380*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "ulpi_fs_ls must be 0 or 1\n"); 2381*197ba5f4SPaul Zimmerman } 2382*197ba5f4SPaul Zimmerman val = 0; 2383*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting ulpi_fs_ls to %d\n", val); 2384*197ba5f4SPaul Zimmerman } 2385*197ba5f4SPaul Zimmerman 2386*197ba5f4SPaul Zimmerman hsotg->core_params->ulpi_fs_ls = val; 2387*197ba5f4SPaul Zimmerman } 2388*197ba5f4SPaul Zimmerman 2389*197ba5f4SPaul Zimmerman void dwc2_set_param_ts_dline(struct dwc2_hsotg *hsotg, int val) 2390*197ba5f4SPaul Zimmerman { 2391*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2392*197ba5f4SPaul Zimmerman if (val >= 0) { 2393*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for ts_dline\n"); 2394*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "ts_dline must be 0 or 1\n"); 2395*197ba5f4SPaul Zimmerman } 2396*197ba5f4SPaul Zimmerman val = 0; 2397*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting ts_dline to %d\n", val); 2398*197ba5f4SPaul Zimmerman } 2399*197ba5f4SPaul Zimmerman 2400*197ba5f4SPaul Zimmerman hsotg->core_params->ts_dline = val; 2401*197ba5f4SPaul Zimmerman } 2402*197ba5f4SPaul Zimmerman 2403*197ba5f4SPaul Zimmerman void dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val) 2404*197ba5f4SPaul Zimmerman { 2405*197ba5f4SPaul Zimmerman int valid = 1; 2406*197ba5f4SPaul Zimmerman 2407*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2408*197ba5f4SPaul Zimmerman if (val >= 0) { 2409*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Wrong value for i2c_enable\n"); 2410*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "i2c_enable must be 0 or 1\n"); 2411*197ba5f4SPaul Zimmerman } 2412*197ba5f4SPaul Zimmerman 2413*197ba5f4SPaul Zimmerman valid = 0; 2414*197ba5f4SPaul Zimmerman } 2415*197ba5f4SPaul Zimmerman 2416*197ba5f4SPaul Zimmerman if (val == 1 && !(hsotg->hw_params.i2c_enable)) 2417*197ba5f4SPaul Zimmerman valid = 0; 2418*197ba5f4SPaul Zimmerman 2419*197ba5f4SPaul Zimmerman if (!valid) { 2420*197ba5f4SPaul Zimmerman if (val >= 0) 2421*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2422*197ba5f4SPaul Zimmerman "%d invalid for i2c_enable. Check HW configuration.\n", 2423*197ba5f4SPaul Zimmerman val); 2424*197ba5f4SPaul Zimmerman val = hsotg->hw_params.i2c_enable; 2425*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); 2426*197ba5f4SPaul Zimmerman } 2427*197ba5f4SPaul Zimmerman 2428*197ba5f4SPaul Zimmerman hsotg->core_params->i2c_enable = val; 2429*197ba5f4SPaul Zimmerman } 2430*197ba5f4SPaul Zimmerman 2431*197ba5f4SPaul Zimmerman void dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val) 2432*197ba5f4SPaul Zimmerman { 2433*197ba5f4SPaul Zimmerman int valid = 1; 2434*197ba5f4SPaul Zimmerman 2435*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2436*197ba5f4SPaul Zimmerman if (val >= 0) { 2437*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2438*197ba5f4SPaul Zimmerman "Wrong value for en_multiple_tx_fifo,\n"); 2439*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2440*197ba5f4SPaul Zimmerman "en_multiple_tx_fifo must be 0 or 1\n"); 2441*197ba5f4SPaul Zimmerman } 2442*197ba5f4SPaul Zimmerman valid = 0; 2443*197ba5f4SPaul Zimmerman } 2444*197ba5f4SPaul Zimmerman 2445*197ba5f4SPaul Zimmerman if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo) 2446*197ba5f4SPaul Zimmerman valid = 0; 2447*197ba5f4SPaul Zimmerman 2448*197ba5f4SPaul Zimmerman if (!valid) { 2449*197ba5f4SPaul Zimmerman if (val >= 0) 2450*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2451*197ba5f4SPaul Zimmerman "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", 2452*197ba5f4SPaul Zimmerman val); 2453*197ba5f4SPaul Zimmerman val = hsotg->hw_params.en_multiple_tx_fifo; 2454*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val); 2455*197ba5f4SPaul Zimmerman } 2456*197ba5f4SPaul Zimmerman 2457*197ba5f4SPaul Zimmerman hsotg->core_params->en_multiple_tx_fifo = val; 2458*197ba5f4SPaul Zimmerman } 2459*197ba5f4SPaul Zimmerman 2460*197ba5f4SPaul Zimmerman void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val) 2461*197ba5f4SPaul Zimmerman { 2462*197ba5f4SPaul Zimmerman int valid = 1; 2463*197ba5f4SPaul Zimmerman 2464*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2465*197ba5f4SPaul Zimmerman if (val >= 0) { 2466*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2467*197ba5f4SPaul Zimmerman "'%d' invalid for parameter reload_ctl\n", val); 2468*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "reload_ctl must be 0 or 1\n"); 2469*197ba5f4SPaul Zimmerman } 2470*197ba5f4SPaul Zimmerman valid = 0; 2471*197ba5f4SPaul Zimmerman } 2472*197ba5f4SPaul Zimmerman 2473*197ba5f4SPaul Zimmerman if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a) 2474*197ba5f4SPaul Zimmerman valid = 0; 2475*197ba5f4SPaul Zimmerman 2476*197ba5f4SPaul Zimmerman if (!valid) { 2477*197ba5f4SPaul Zimmerman if (val >= 0) 2478*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2479*197ba5f4SPaul Zimmerman "%d invalid for parameter reload_ctl. Check HW configuration.\n", 2480*197ba5f4SPaul Zimmerman val); 2481*197ba5f4SPaul Zimmerman val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a; 2482*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); 2483*197ba5f4SPaul Zimmerman } 2484*197ba5f4SPaul Zimmerman 2485*197ba5f4SPaul Zimmerman hsotg->core_params->reload_ctl = val; 2486*197ba5f4SPaul Zimmerman } 2487*197ba5f4SPaul Zimmerman 2488*197ba5f4SPaul Zimmerman void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val) 2489*197ba5f4SPaul Zimmerman { 2490*197ba5f4SPaul Zimmerman if (val != -1) 2491*197ba5f4SPaul Zimmerman hsotg->core_params->ahbcfg = val; 2492*197ba5f4SPaul Zimmerman else 2493*197ba5f4SPaul Zimmerman hsotg->core_params->ahbcfg = GAHBCFG_HBSTLEN_INCR4 << 2494*197ba5f4SPaul Zimmerman GAHBCFG_HBSTLEN_SHIFT; 2495*197ba5f4SPaul Zimmerman } 2496*197ba5f4SPaul Zimmerman 2497*197ba5f4SPaul Zimmerman void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val) 2498*197ba5f4SPaul Zimmerman { 2499*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2500*197ba5f4SPaul Zimmerman if (val >= 0) { 2501*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2502*197ba5f4SPaul Zimmerman "'%d' invalid for parameter otg_ver\n", val); 2503*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2504*197ba5f4SPaul Zimmerman "otg_ver must be 0 (for OTG 1.3 support) or 1 (for OTG 2.0 support)\n"); 2505*197ba5f4SPaul Zimmerman } 2506*197ba5f4SPaul Zimmerman val = 0; 2507*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting otg_ver to %d\n", val); 2508*197ba5f4SPaul Zimmerman } 2509*197ba5f4SPaul Zimmerman 2510*197ba5f4SPaul Zimmerman hsotg->core_params->otg_ver = val; 2511*197ba5f4SPaul Zimmerman } 2512*197ba5f4SPaul Zimmerman 2513*197ba5f4SPaul Zimmerman static void dwc2_set_param_uframe_sched(struct dwc2_hsotg *hsotg, int val) 2514*197ba5f4SPaul Zimmerman { 2515*197ba5f4SPaul Zimmerman if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) { 2516*197ba5f4SPaul Zimmerman if (val >= 0) { 2517*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, 2518*197ba5f4SPaul Zimmerman "'%d' invalid for parameter uframe_sched\n", 2519*197ba5f4SPaul Zimmerman val); 2520*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "uframe_sched must be 0 or 1\n"); 2521*197ba5f4SPaul Zimmerman } 2522*197ba5f4SPaul Zimmerman val = 1; 2523*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Setting uframe_sched to %d\n", val); 2524*197ba5f4SPaul Zimmerman } 2525*197ba5f4SPaul Zimmerman 2526*197ba5f4SPaul Zimmerman hsotg->core_params->uframe_sched = val; 2527*197ba5f4SPaul Zimmerman } 2528*197ba5f4SPaul Zimmerman 2529*197ba5f4SPaul Zimmerman /* 2530*197ba5f4SPaul Zimmerman * This function is called during module intialization to pass module parameters 2531*197ba5f4SPaul Zimmerman * for the DWC_otg core. 2532*197ba5f4SPaul Zimmerman */ 2533*197ba5f4SPaul Zimmerman void dwc2_set_parameters(struct dwc2_hsotg *hsotg, 2534*197ba5f4SPaul Zimmerman const struct dwc2_core_params *params) 2535*197ba5f4SPaul Zimmerman { 2536*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "%s()\n", __func__); 2537*197ba5f4SPaul Zimmerman 2538*197ba5f4SPaul Zimmerman dwc2_set_param_otg_cap(hsotg, params->otg_cap); 2539*197ba5f4SPaul Zimmerman dwc2_set_param_dma_enable(hsotg, params->dma_enable); 2540*197ba5f4SPaul Zimmerman dwc2_set_param_dma_desc_enable(hsotg, params->dma_desc_enable); 2541*197ba5f4SPaul Zimmerman dwc2_set_param_host_support_fs_ls_low_power(hsotg, 2542*197ba5f4SPaul Zimmerman params->host_support_fs_ls_low_power); 2543*197ba5f4SPaul Zimmerman dwc2_set_param_enable_dynamic_fifo(hsotg, 2544*197ba5f4SPaul Zimmerman params->enable_dynamic_fifo); 2545*197ba5f4SPaul Zimmerman dwc2_set_param_host_rx_fifo_size(hsotg, 2546*197ba5f4SPaul Zimmerman params->host_rx_fifo_size); 2547*197ba5f4SPaul Zimmerman dwc2_set_param_host_nperio_tx_fifo_size(hsotg, 2548*197ba5f4SPaul Zimmerman params->host_nperio_tx_fifo_size); 2549*197ba5f4SPaul Zimmerman dwc2_set_param_host_perio_tx_fifo_size(hsotg, 2550*197ba5f4SPaul Zimmerman params->host_perio_tx_fifo_size); 2551*197ba5f4SPaul Zimmerman dwc2_set_param_max_transfer_size(hsotg, 2552*197ba5f4SPaul Zimmerman params->max_transfer_size); 2553*197ba5f4SPaul Zimmerman dwc2_set_param_max_packet_count(hsotg, 2554*197ba5f4SPaul Zimmerman params->max_packet_count); 2555*197ba5f4SPaul Zimmerman dwc2_set_param_host_channels(hsotg, params->host_channels); 2556*197ba5f4SPaul Zimmerman dwc2_set_param_phy_type(hsotg, params->phy_type); 2557*197ba5f4SPaul Zimmerman dwc2_set_param_speed(hsotg, params->speed); 2558*197ba5f4SPaul Zimmerman dwc2_set_param_host_ls_low_power_phy_clk(hsotg, 2559*197ba5f4SPaul Zimmerman params->host_ls_low_power_phy_clk); 2560*197ba5f4SPaul Zimmerman dwc2_set_param_phy_ulpi_ddr(hsotg, params->phy_ulpi_ddr); 2561*197ba5f4SPaul Zimmerman dwc2_set_param_phy_ulpi_ext_vbus(hsotg, 2562*197ba5f4SPaul Zimmerman params->phy_ulpi_ext_vbus); 2563*197ba5f4SPaul Zimmerman dwc2_set_param_phy_utmi_width(hsotg, params->phy_utmi_width); 2564*197ba5f4SPaul Zimmerman dwc2_set_param_ulpi_fs_ls(hsotg, params->ulpi_fs_ls); 2565*197ba5f4SPaul Zimmerman dwc2_set_param_ts_dline(hsotg, params->ts_dline); 2566*197ba5f4SPaul Zimmerman dwc2_set_param_i2c_enable(hsotg, params->i2c_enable); 2567*197ba5f4SPaul Zimmerman dwc2_set_param_en_multiple_tx_fifo(hsotg, 2568*197ba5f4SPaul Zimmerman params->en_multiple_tx_fifo); 2569*197ba5f4SPaul Zimmerman dwc2_set_param_reload_ctl(hsotg, params->reload_ctl); 2570*197ba5f4SPaul Zimmerman dwc2_set_param_ahbcfg(hsotg, params->ahbcfg); 2571*197ba5f4SPaul Zimmerman dwc2_set_param_otg_ver(hsotg, params->otg_ver); 2572*197ba5f4SPaul Zimmerman dwc2_set_param_uframe_sched(hsotg, params->uframe_sched); 2573*197ba5f4SPaul Zimmerman } 2574*197ba5f4SPaul Zimmerman 2575*197ba5f4SPaul Zimmerman /** 2576*197ba5f4SPaul Zimmerman * During device initialization, read various hardware configuration 2577*197ba5f4SPaul Zimmerman * registers and interpret the contents. 2578*197ba5f4SPaul Zimmerman */ 2579*197ba5f4SPaul Zimmerman int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) 2580*197ba5f4SPaul Zimmerman { 2581*197ba5f4SPaul Zimmerman struct dwc2_hw_params *hw = &hsotg->hw_params; 2582*197ba5f4SPaul Zimmerman unsigned width; 2583*197ba5f4SPaul Zimmerman u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4; 2584*197ba5f4SPaul Zimmerman u32 hptxfsiz, grxfsiz, gnptxfsiz; 2585*197ba5f4SPaul Zimmerman u32 gusbcfg; 2586*197ba5f4SPaul Zimmerman 2587*197ba5f4SPaul Zimmerman /* 2588*197ba5f4SPaul Zimmerman * Attempt to ensure this device is really a DWC_otg Controller. 2589*197ba5f4SPaul Zimmerman * Read and verify the GSNPSID register contents. The value should be 2590*197ba5f4SPaul Zimmerman * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3", 2591*197ba5f4SPaul Zimmerman * as in "OTG version 2.xx" or "OTG version 3.xx". 2592*197ba5f4SPaul Zimmerman */ 2593*197ba5f4SPaul Zimmerman hw->snpsid = readl(hsotg->regs + GSNPSID); 2594*197ba5f4SPaul Zimmerman if ((hw->snpsid & 0xfffff000) != 0x4f542000 && 2595*197ba5f4SPaul Zimmerman (hw->snpsid & 0xfffff000) != 0x4f543000) { 2596*197ba5f4SPaul Zimmerman dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n", 2597*197ba5f4SPaul Zimmerman hw->snpsid); 2598*197ba5f4SPaul Zimmerman return -ENODEV; 2599*197ba5f4SPaul Zimmerman } 2600*197ba5f4SPaul Zimmerman 2601*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n", 2602*197ba5f4SPaul Zimmerman hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf, 2603*197ba5f4SPaul Zimmerman hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid); 2604*197ba5f4SPaul Zimmerman 2605*197ba5f4SPaul Zimmerman hwcfg1 = readl(hsotg->regs + GHWCFG1); 2606*197ba5f4SPaul Zimmerman hwcfg2 = readl(hsotg->regs + GHWCFG2); 2607*197ba5f4SPaul Zimmerman hwcfg3 = readl(hsotg->regs + GHWCFG3); 2608*197ba5f4SPaul Zimmerman hwcfg4 = readl(hsotg->regs + GHWCFG4); 2609*197ba5f4SPaul Zimmerman gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ); 2610*197ba5f4SPaul Zimmerman grxfsiz = readl(hsotg->regs + GRXFSIZ); 2611*197ba5f4SPaul Zimmerman 2612*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1); 2613*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2); 2614*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3); 2615*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4); 2616*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz); 2617*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz); 2618*197ba5f4SPaul Zimmerman 2619*197ba5f4SPaul Zimmerman /* Force host mode to get HPTXFSIZ exact power on value */ 2620*197ba5f4SPaul Zimmerman gusbcfg = readl(hsotg->regs + GUSBCFG); 2621*197ba5f4SPaul Zimmerman gusbcfg |= GUSBCFG_FORCEHOSTMODE; 2622*197ba5f4SPaul Zimmerman writel(gusbcfg, hsotg->regs + GUSBCFG); 2623*197ba5f4SPaul Zimmerman usleep_range(100000, 150000); 2624*197ba5f4SPaul Zimmerman 2625*197ba5f4SPaul Zimmerman hptxfsiz = readl(hsotg->regs + HPTXFSIZ); 2626*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz); 2627*197ba5f4SPaul Zimmerman gusbcfg = readl(hsotg->regs + GUSBCFG); 2628*197ba5f4SPaul Zimmerman gusbcfg &= ~GUSBCFG_FORCEHOSTMODE; 2629*197ba5f4SPaul Zimmerman writel(gusbcfg, hsotg->regs + GUSBCFG); 2630*197ba5f4SPaul Zimmerman usleep_range(100000, 150000); 2631*197ba5f4SPaul Zimmerman 2632*197ba5f4SPaul Zimmerman /* hwcfg2 */ 2633*197ba5f4SPaul Zimmerman hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >> 2634*197ba5f4SPaul Zimmerman GHWCFG2_OP_MODE_SHIFT; 2635*197ba5f4SPaul Zimmerman hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 2636*197ba5f4SPaul Zimmerman GHWCFG2_ARCHITECTURE_SHIFT; 2637*197ba5f4SPaul Zimmerman hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO); 2638*197ba5f4SPaul Zimmerman hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >> 2639*197ba5f4SPaul Zimmerman GHWCFG2_NUM_HOST_CHAN_SHIFT); 2640*197ba5f4SPaul Zimmerman hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> 2641*197ba5f4SPaul Zimmerman GHWCFG2_HS_PHY_TYPE_SHIFT; 2642*197ba5f4SPaul Zimmerman hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> 2643*197ba5f4SPaul Zimmerman GHWCFG2_FS_PHY_TYPE_SHIFT; 2644*197ba5f4SPaul Zimmerman hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >> 2645*197ba5f4SPaul Zimmerman GHWCFG2_NUM_DEV_EP_SHIFT; 2646*197ba5f4SPaul Zimmerman hw->nperio_tx_q_depth = 2647*197ba5f4SPaul Zimmerman (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >> 2648*197ba5f4SPaul Zimmerman GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1; 2649*197ba5f4SPaul Zimmerman hw->host_perio_tx_q_depth = 2650*197ba5f4SPaul Zimmerman (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >> 2651*197ba5f4SPaul Zimmerman GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1; 2652*197ba5f4SPaul Zimmerman hw->dev_token_q_depth = 2653*197ba5f4SPaul Zimmerman (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >> 2654*197ba5f4SPaul Zimmerman GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT; 2655*197ba5f4SPaul Zimmerman 2656*197ba5f4SPaul Zimmerman /* hwcfg3 */ 2657*197ba5f4SPaul Zimmerman width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >> 2658*197ba5f4SPaul Zimmerman GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT; 2659*197ba5f4SPaul Zimmerman hw->max_transfer_size = (1 << (width + 11)) - 1; 2660*197ba5f4SPaul Zimmerman width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >> 2661*197ba5f4SPaul Zimmerman GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT; 2662*197ba5f4SPaul Zimmerman hw->max_packet_count = (1 << (width + 4)) - 1; 2663*197ba5f4SPaul Zimmerman hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C); 2664*197ba5f4SPaul Zimmerman hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >> 2665*197ba5f4SPaul Zimmerman GHWCFG3_DFIFO_DEPTH_SHIFT; 2666*197ba5f4SPaul Zimmerman 2667*197ba5f4SPaul Zimmerman /* hwcfg4 */ 2668*197ba5f4SPaul Zimmerman hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN); 2669*197ba5f4SPaul Zimmerman hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >> 2670*197ba5f4SPaul Zimmerman GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT; 2671*197ba5f4SPaul Zimmerman hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA); 2672*197ba5f4SPaul Zimmerman hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ); 2673*197ba5f4SPaul Zimmerman hw->utmi_phy_data_width = (hwcfg4 & GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK) >> 2674*197ba5f4SPaul Zimmerman GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT; 2675*197ba5f4SPaul Zimmerman 2676*197ba5f4SPaul Zimmerman /* fifo sizes */ 2677*197ba5f4SPaul Zimmerman hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >> 2678*197ba5f4SPaul Zimmerman GRXFSIZ_DEPTH_SHIFT; 2679*197ba5f4SPaul Zimmerman hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >> 2680*197ba5f4SPaul Zimmerman FIFOSIZE_DEPTH_SHIFT; 2681*197ba5f4SPaul Zimmerman hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >> 2682*197ba5f4SPaul Zimmerman FIFOSIZE_DEPTH_SHIFT; 2683*197ba5f4SPaul Zimmerman 2684*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "Detected values from hardware:\n"); 2685*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " op_mode=%d\n", 2686*197ba5f4SPaul Zimmerman hw->op_mode); 2687*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " arch=%d\n", 2688*197ba5f4SPaul Zimmerman hw->arch); 2689*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " dma_desc_enable=%d\n", 2690*197ba5f4SPaul Zimmerman hw->dma_desc_enable); 2691*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " power_optimized=%d\n", 2692*197ba5f4SPaul Zimmerman hw->power_optimized); 2693*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " i2c_enable=%d\n", 2694*197ba5f4SPaul Zimmerman hw->i2c_enable); 2695*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " hs_phy_type=%d\n", 2696*197ba5f4SPaul Zimmerman hw->hs_phy_type); 2697*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " fs_phy_type=%d\n", 2698*197ba5f4SPaul Zimmerman hw->fs_phy_type); 2699*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " utmi_phy_data_wdith=%d\n", 2700*197ba5f4SPaul Zimmerman hw->utmi_phy_data_width); 2701*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " num_dev_ep=%d\n", 2702*197ba5f4SPaul Zimmerman hw->num_dev_ep); 2703*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n", 2704*197ba5f4SPaul Zimmerman hw->num_dev_perio_in_ep); 2705*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " host_channels=%d\n", 2706*197ba5f4SPaul Zimmerman hw->host_channels); 2707*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " max_transfer_size=%d\n", 2708*197ba5f4SPaul Zimmerman hw->max_transfer_size); 2709*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " max_packet_count=%d\n", 2710*197ba5f4SPaul Zimmerman hw->max_packet_count); 2711*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n", 2712*197ba5f4SPaul Zimmerman hw->nperio_tx_q_depth); 2713*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n", 2714*197ba5f4SPaul Zimmerman hw->host_perio_tx_q_depth); 2715*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n", 2716*197ba5f4SPaul Zimmerman hw->dev_token_q_depth); 2717*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n", 2718*197ba5f4SPaul Zimmerman hw->enable_dynamic_fifo); 2719*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n", 2720*197ba5f4SPaul Zimmerman hw->en_multiple_tx_fifo); 2721*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " total_fifo_size=%d\n", 2722*197ba5f4SPaul Zimmerman hw->total_fifo_size); 2723*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n", 2724*197ba5f4SPaul Zimmerman hw->host_rx_fifo_size); 2725*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n", 2726*197ba5f4SPaul Zimmerman hw->host_nperio_tx_fifo_size); 2727*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n", 2728*197ba5f4SPaul Zimmerman hw->host_perio_tx_fifo_size); 2729*197ba5f4SPaul Zimmerman dev_dbg(hsotg->dev, "\n"); 2730*197ba5f4SPaul Zimmerman 2731*197ba5f4SPaul Zimmerman return 0; 2732*197ba5f4SPaul Zimmerman } 2733*197ba5f4SPaul Zimmerman 2734*197ba5f4SPaul Zimmerman u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg) 2735*197ba5f4SPaul Zimmerman { 2736*197ba5f4SPaul Zimmerman return hsotg->core_params->otg_ver == 1 ? 0x0200 : 0x0103; 2737*197ba5f4SPaul Zimmerman } 2738*197ba5f4SPaul Zimmerman 2739*197ba5f4SPaul Zimmerman bool dwc2_is_controller_alive(struct dwc2_hsotg *hsotg) 2740*197ba5f4SPaul Zimmerman { 2741*197ba5f4SPaul Zimmerman if (readl(hsotg->regs + GSNPSID) == 0xffffffff) 2742*197ba5f4SPaul Zimmerman return false; 2743*197ba5f4SPaul Zimmerman else 2744*197ba5f4SPaul Zimmerman return true; 2745*197ba5f4SPaul Zimmerman } 2746*197ba5f4SPaul Zimmerman 2747*197ba5f4SPaul Zimmerman /** 2748*197ba5f4SPaul Zimmerman * dwc2_enable_global_interrupts() - Enables the controller's Global 2749*197ba5f4SPaul Zimmerman * Interrupt in the AHB Config register 2750*197ba5f4SPaul Zimmerman * 2751*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 2752*197ba5f4SPaul Zimmerman */ 2753*197ba5f4SPaul Zimmerman void dwc2_enable_global_interrupts(struct dwc2_hsotg *hsotg) 2754*197ba5f4SPaul Zimmerman { 2755*197ba5f4SPaul Zimmerman u32 ahbcfg = readl(hsotg->regs + GAHBCFG); 2756*197ba5f4SPaul Zimmerman 2757*197ba5f4SPaul Zimmerman ahbcfg |= GAHBCFG_GLBL_INTR_EN; 2758*197ba5f4SPaul Zimmerman writel(ahbcfg, hsotg->regs + GAHBCFG); 2759*197ba5f4SPaul Zimmerman } 2760*197ba5f4SPaul Zimmerman 2761*197ba5f4SPaul Zimmerman /** 2762*197ba5f4SPaul Zimmerman * dwc2_disable_global_interrupts() - Disables the controller's Global 2763*197ba5f4SPaul Zimmerman * Interrupt in the AHB Config register 2764*197ba5f4SPaul Zimmerman * 2765*197ba5f4SPaul Zimmerman * @hsotg: Programming view of DWC_otg controller 2766*197ba5f4SPaul Zimmerman */ 2767*197ba5f4SPaul Zimmerman void dwc2_disable_global_interrupts(struct dwc2_hsotg *hsotg) 2768*197ba5f4SPaul Zimmerman { 2769*197ba5f4SPaul Zimmerman u32 ahbcfg = readl(hsotg->regs + GAHBCFG); 2770*197ba5f4SPaul Zimmerman 2771*197ba5f4SPaul Zimmerman ahbcfg &= ~GAHBCFG_GLBL_INTR_EN; 2772*197ba5f4SPaul Zimmerman writel(ahbcfg, hsotg->regs + GAHBCFG); 2773*197ba5f4SPaul Zimmerman } 2774*197ba5f4SPaul Zimmerman 2775*197ba5f4SPaul Zimmerman MODULE_DESCRIPTION("DESIGNWARE HS OTG Core"); 2776*197ba5f4SPaul Zimmerman MODULE_AUTHOR("Synopsys, Inc."); 2777*197ba5f4SPaul Zimmerman MODULE_LICENSE("Dual BSD/GPL"); 2778