aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2013-08-30 12:45:21 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-30 17:14:53 -0400
commit9badec2f9fa9209ceb3bd427972299d69a37d8ee (patch)
treeb895d23abdbf9c302abe054c898baf8a1550599e
parenta1fc524393583a217ddbc71293eb30feef58530d (diff)
staging: dwc2: interpret all hwcfg and related register at init time
Before, the hwcfg registers were read at device init time, but interpreted at various parts in the code. This commit unpacks the hwcfg register values into a struct with properly labeled variables at init time, which makes all the other code using these values more consise and easier to read. Some values that were previously stored in the hsotg struct are now moved into this new struct as well. In addition to the hwcfg registers, the contents of some fifo size registers are also unpacked. The hwcfg registers are read-only, so they can be safely stored. The fifo size registers are read-write registers, but their power-on values are significant: they give the maximum depth of the fifo they describe. This commit mostly moves code, but also attempts to simplify some expressions from (val >> shift) & (mask >> shift) to (val & mask) >> shift. Finally, all of the parameters read from the hardware are debug printed after unpacking them, so a bunch of debug prints can be removed from other places. Signed-off-by: Matthijs Kooijman <matthijs@stdin.nl> Acked-by: Paul Zimmerman <paulz@synopsys.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/dwc2/core.c307
-rw-r--r--drivers/staging/dwc2/core.h96
-rw-r--r--drivers/staging/dwc2/core_intr.c4
-rw-r--r--drivers/staging/dwc2/hcd.c80
-rw-r--r--drivers/staging/dwc2/hcd.h1
-rw-r--r--drivers/staging/dwc2/hcd_intr.c2
6 files changed, 290 insertions, 200 deletions
diff --git a/drivers/staging/dwc2/core.c b/drivers/staging/dwc2/core.c
index 2f84c24a84ee..825c5e5f157f 100644
--- a/drivers/staging/dwc2/core.c
+++ b/drivers/staging/dwc2/core.c
@@ -90,14 +90,10 @@ static void dwc2_enable_common_interrupts(struct dwc2_hsotg *hsotg)
90 */ 90 */
91static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg) 91static void dwc2_init_fs_ls_pclk_sel(struct dwc2_hsotg *hsotg)
92{ 92{
93 u32 hs_phy_type = (hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
94 GHWCFG2_HS_PHY_TYPE_SHIFT;
95 u32 fs_phy_type = (hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
96 GHWCFG2_FS_PHY_TYPE_SHIFT;
97 u32 hcfg, val; 93 u32 hcfg, val;
98 94
99 if ((hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI && 95 if ((hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
100 fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED && 96 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
101 hsotg->core_params->ulpi_fs_ls > 0) || 97 hsotg->core_params->ulpi_fs_ls > 0) ||
102 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { 98 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
103 /* Full speed PHY */ 99 /* Full speed PHY */
@@ -247,7 +243,7 @@ static void dwc2_hs_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
247 243
248static void dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy) 244static void dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
249{ 245{
250 u32 usbcfg, hs_phy_type, fs_phy_type; 246 u32 usbcfg;
251 247
252 if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL && 248 if (hsotg->core_params->speed == DWC2_SPEED_PARAM_FULL &&
253 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) { 249 hsotg->core_params->phy_type == DWC2_PHY_TYPE_PARAM_FS) {
@@ -258,13 +254,8 @@ static void dwc2_phy_init(struct dwc2_hsotg *hsotg, bool select_phy)
258 dwc2_hs_phy_init(hsotg, select_phy); 254 dwc2_hs_phy_init(hsotg, select_phy);
259 } 255 }
260 256
261 hs_phy_type = (hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> 257 if (hsotg->hw_params.hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
262 GHWCFG2_HS_PHY_TYPE_SHIFT; 258 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
263 fs_phy_type = (hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
264 GHWCFG2_FS_PHY_TYPE_SHIFT;
265
266 if (hs_phy_type == GHWCFG2_HS_PHY_TYPE_ULPI &&
267 fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED &&
268 hsotg->core_params->ulpi_fs_ls > 0) { 259 hsotg->core_params->ulpi_fs_ls > 0) {
269 dev_dbg(hsotg->dev, "Setting ULPI FSLS\n"); 260 dev_dbg(hsotg->dev, "Setting ULPI FSLS\n");
270 usbcfg = readl(hsotg->regs + GUSBCFG); 261 usbcfg = readl(hsotg->regs + GUSBCFG);
@@ -283,8 +274,7 @@ static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
283{ 274{
284 u32 ahbcfg = readl(hsotg->regs + GAHBCFG); 275 u32 ahbcfg = readl(hsotg->regs + GAHBCFG);
285 276
286 switch ((hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 277 switch (hsotg->hw_params.arch) {
287 GHWCFG2_ARCHITECTURE_SHIFT) {
288 case GHWCFG2_EXT_DMA_ARCH: 278 case GHWCFG2_EXT_DMA_ARCH:
289 dev_err(hsotg->dev, "External DMA Mode not supported\n"); 279 dev_err(hsotg->dev, "External DMA Mode not supported\n");
290 return -EINVAL; 280 return -EINVAL;
@@ -333,8 +323,7 @@ static void dwc2_gusbcfg_init(struct dwc2_hsotg *hsotg)
333 usbcfg = readl(hsotg->regs + GUSBCFG); 323 usbcfg = readl(hsotg->regs + GUSBCFG);
334 usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP); 324 usbcfg &= ~(GUSBCFG_HNPCAP | GUSBCFG_SRPCAP);
335 325
336 switch ((hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK) >> 326 switch (hsotg->hw_params.op_mode) {
337 GHWCFG2_OP_MODE_SHIFT) {
338 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 327 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
339 if (hsotg->core_params->otg_cap == 328 if (hsotg->core_params->otg_cap ==
340 DWC2_CAP_PARAM_HNP_SRP_CAPABLE) 329 DWC2_CAP_PARAM_HNP_SRP_CAPABLE)
@@ -395,23 +384,6 @@ int dwc2_core_init(struct dwc2_hsotg *hsotg, bool select_phy, int irq)
395 /* Reset the Controller */ 384 /* Reset the Controller */
396 dwc2_core_reset(hsotg); 385 dwc2_core_reset(hsotg);
397 386
398 dev_dbg(hsotg->dev, "num_dev_perio_in_ep=%d\n",
399 hsotg->hwcfg4 >> GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT &
400 GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK >>
401 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT);
402
403 hsotg->total_fifo_size = hsotg->hwcfg3 >> GHWCFG3_DFIFO_DEPTH_SHIFT &
404 GHWCFG3_DFIFO_DEPTH_MASK >> GHWCFG3_DFIFO_DEPTH_SHIFT;
405 hsotg->rx_fifo_size = (readl(hsotg->regs + GRXFSIZ) &
406 GRXFSIZ_DEPTH_MASK) >>
407 GRXFSIZ_DEPTH_SHIFT;
408 hsotg->nperio_tx_fifo_size =
409 readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff;
410
411 dev_dbg(hsotg->dev, "Total FIFO SZ=%d\n", hsotg->total_fifo_size);
412 dev_dbg(hsotg->dev, "RxFIFO SZ=%d\n", hsotg->rx_fifo_size);
413 dev_dbg(hsotg->dev, "NP TxFIFO SZ=%d\n", hsotg->nperio_tx_fifo_size);
414
415 /* 387 /*
416 * This needs to happen in FS mode before any other programming occurs 388 * This needs to happen in FS mode before any other programming occurs
417 */ 389 */
@@ -514,13 +486,6 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
514 if (!params->enable_dynamic_fifo) 486 if (!params->enable_dynamic_fifo)
515 return; 487 return;
516 488
517 dev_dbg(hsotg->dev, "Total FIFO Size=%d\n", hsotg->total_fifo_size);
518 dev_dbg(hsotg->dev, "Rx FIFO Size=%d\n", params->host_rx_fifo_size);
519 dev_dbg(hsotg->dev, "NP Tx FIFO Size=%d\n",
520 params->host_nperio_tx_fifo_size);
521 dev_dbg(hsotg->dev, "P Tx FIFO Size=%d\n",
522 params->host_perio_tx_fifo_size);
523
524 /* Rx FIFO */ 489 /* Rx FIFO */
525 grxfsiz = readl(hsotg->regs + GRXFSIZ); 490 grxfsiz = readl(hsotg->regs + GRXFSIZ);
526 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz); 491 dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz);
@@ -554,7 +519,7 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
554 readl(hsotg->regs + HPTXFSIZ)); 519 readl(hsotg->regs + HPTXFSIZ));
555 520
556 if (hsotg->core_params->en_multiple_tx_fifo > 0 && 521 if (hsotg->core_params->en_multiple_tx_fifo > 0 &&
557 hsotg->snpsid <= DWC2_CORE_REV_2_94a) { 522 hsotg->hw_params.snpsid <= DWC2_CORE_REV_2_94a) {
558 /* 523 /*
559 * Global DFIFOCFG calculation for Host mode - 524 * Global DFIFOCFG calculation for Host mode -
560 * include RxFIFO, NPTXFIFO and HPTXFIFO 525 * include RxFIFO, NPTXFIFO and HPTXFIFO
@@ -609,11 +574,9 @@ void dwc2_core_host_init(struct dwc2_hsotg *hsotg)
609 } 574 }
610 575
611 if (hsotg->core_params->dma_desc_enable > 0) { 576 if (hsotg->core_params->dma_desc_enable > 0) {
612 u32 op_mode = (hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK) >> 577 u32 op_mode = hsotg->hw_params.op_mode;
613 GHWCFG2_OP_MODE_SHIFT; 578 if (hsotg->hw_params.snpsid < DWC2_CORE_REV_2_90a ||
614 579 !hsotg->hw_params.dma_desc_enable ||
615 if (hsotg->snpsid < DWC2_CORE_REV_2_90a ||
616 !(hsotg->hwcfg4 & GHWCFG4_DESC_DMA) ||
617 op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE || 580 op_mode == GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE ||
618 op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE || 581 op_mode == GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE ||
619 op_mode == GHWCFG2_OP_MODE_UNDEFINED) { 582 op_mode == GHWCFG2_OP_MODE_UNDEFINED) {
@@ -1659,19 +1622,16 @@ void dwc2_hc_do_ping(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan)
1659u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg) 1622u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
1660{ 1623{
1661 u32 usbcfg; 1624 u32 usbcfg;
1662 u32 hwcfg2;
1663 u32 hprt0; 1625 u32 hprt0;
1664 int clock = 60; /* default value */ 1626 int clock = 60; /* default value */
1665 1627
1666 usbcfg = readl(hsotg->regs + GUSBCFG); 1628 usbcfg = readl(hsotg->regs + GUSBCFG);
1667 hwcfg2 = readl(hsotg->regs + GHWCFG2);
1668 hprt0 = readl(hsotg->regs + HPRT0); 1629 hprt0 = readl(hsotg->regs + HPRT0);
1669 1630
1670 if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) && 1631 if (!(usbcfg & GUSBCFG_PHYSEL) && (usbcfg & GUSBCFG_ULPI_UTMI_SEL) &&
1671 !(usbcfg & GUSBCFG_PHYIF16)) 1632 !(usbcfg & GUSBCFG_PHYIF16))
1672 clock = 60; 1633 clock = 60;
1673 if ((usbcfg & GUSBCFG_PHYSEL) && 1634 if ((usbcfg & GUSBCFG_PHYSEL) && hsotg->hw_params.fs_phy_type ==
1674 (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> GHWCFG2_FS_PHY_TYPE_SHIFT ==
1675 GHWCFG2_FS_PHY_TYPE_SHARED_ULPI) 1635 GHWCFG2_FS_PHY_TYPE_SHARED_ULPI)
1676 clock = 48; 1636 clock = 48;
1677 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) && 1637 if (!(usbcfg & GUSBCFG_PHY_LP_CLK_SEL) && !(usbcfg & GUSBCFG_PHYSEL) &&
@@ -1684,12 +1644,10 @@ u32 dwc2_calc_frame_interval(struct dwc2_hsotg *hsotg)
1684 !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16)) 1644 !(usbcfg & GUSBCFG_ULPI_UTMI_SEL) && (usbcfg & GUSBCFG_PHYIF16))
1685 clock = 48; 1645 clock = 48;
1686 if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) && 1646 if ((usbcfg & GUSBCFG_PHYSEL) && !(usbcfg & GUSBCFG_PHYIF16) &&
1687 (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> GHWCFG2_FS_PHY_TYPE_SHIFT == 1647 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_SHARED_UTMI)
1688 GHWCFG2_FS_PHY_TYPE_SHARED_UTMI)
1689 clock = 48; 1648 clock = 48;
1690 if ((usbcfg & GUSBCFG_PHYSEL) && 1649 if ((usbcfg & GUSBCFG_PHYSEL) &&
1691 (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >> GHWCFG2_FS_PHY_TYPE_SHIFT == 1650 hsotg->hw_params.fs_phy_type == GHWCFG2_FS_PHY_TYPE_DEDICATED)
1692 GHWCFG2_FS_PHY_TYPE_DEDICATED)
1693 clock = 48; 1651 clock = 48;
1694 1652
1695 if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED) 1653 if ((hprt0 & HPRT0_SPD_MASK) >> HPRT0_SPD_SHIFT == HPRT0_SPD_HIGH_SPEED)
@@ -1961,18 +1919,14 @@ int dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
1961{ 1919{
1962 int valid = 1; 1920 int valid = 1;
1963 int retval = 0; 1921 int retval = 0;
1964 u32 op_mode;
1965
1966 op_mode = (hsotg->hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
1967 GHWCFG2_OP_MODE_SHIFT;
1968 1922
1969 switch (val) { 1923 switch (val) {
1970 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE: 1924 case DWC2_CAP_PARAM_HNP_SRP_CAPABLE:
1971 if (op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE) 1925 if (hsotg->hw_params.op_mode != GHWCFG2_OP_MODE_HNP_SRP_CAPABLE)
1972 valid = 0; 1926 valid = 0;
1973 break; 1927 break;
1974 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE: 1928 case DWC2_CAP_PARAM_SRP_ONLY_CAPABLE:
1975 switch (op_mode) { 1929 switch (hsotg->hw_params.op_mode) {
1976 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 1930 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
1977 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE: 1931 case GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE:
1978 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE: 1932 case GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE:
@@ -1996,7 +1950,7 @@ int dwc2_set_param_otg_cap(struct dwc2_hsotg *hsotg, int val)
1996 dev_err(hsotg->dev, 1950 dev_err(hsotg->dev,
1997 "%d invalid for otg_cap parameter. Check HW configuration.\n", 1951 "%d invalid for otg_cap parameter. Check HW configuration.\n",
1998 val); 1952 val);
1999 switch (op_mode) { 1953 switch (hsotg->hw_params.op_mode) {
2000 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE: 1954 case GHWCFG2_OP_MODE_HNP_SRP_CAPABLE:
2001 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE; 1955 val = DWC2_CAP_PARAM_HNP_SRP_CAPABLE;
2002 break; 1956 break;
@@ -2022,8 +1976,7 @@ int dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val)
2022 int valid = 1; 1976 int valid = 1;
2023 int retval = 0; 1977 int retval = 0;
2024 1978
2025 if (val > 0 && (hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 1979 if (val > 0 && hsotg->hw_params.arch == GHWCFG2_SLAVE_ONLY_ARCH)
2026 GHWCFG2_ARCHITECTURE_SHIFT == GHWCFG2_SLAVE_ONLY_ARCH)
2027 valid = 0; 1980 valid = 0;
2028 if (val < 0) 1981 if (val < 0)
2029 valid = 0; 1982 valid = 0;
@@ -2033,8 +1986,7 @@ int dwc2_set_param_dma_enable(struct dwc2_hsotg *hsotg, int val)
2033 dev_err(hsotg->dev, 1986 dev_err(hsotg->dev,
2034 "%d invalid for dma_enable parameter. Check HW configuration.\n", 1987 "%d invalid for dma_enable parameter. Check HW configuration.\n",
2035 val); 1988 val);
2036 val = (hsotg->hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >> 1989 val = hsotg->hw_params.arch != GHWCFG2_SLAVE_ONLY_ARCH;
2037 GHWCFG2_ARCHITECTURE_SHIFT != GHWCFG2_SLAVE_ONLY_ARCH;
2038 dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val); 1990 dev_dbg(hsotg->dev, "Setting dma_enable to %d\n", val);
2039 retval = -EINVAL; 1991 retval = -EINVAL;
2040 } 1992 }
@@ -2049,7 +2001,7 @@ int dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
2049 int retval = 0; 2001 int retval = 0;
2050 2002
2051 if (val > 0 && (hsotg->core_params->dma_enable <= 0 || 2003 if (val > 0 && (hsotg->core_params->dma_enable <= 0 ||
2052 !(hsotg->hwcfg4 & GHWCFG4_DESC_DMA))) 2004 !hsotg->hw_params.dma_desc_enable))
2053 valid = 0; 2005 valid = 0;
2054 if (val < 0) 2006 if (val < 0)
2055 valid = 0; 2007 valid = 0;
@@ -2060,7 +2012,7 @@ int dwc2_set_param_dma_desc_enable(struct dwc2_hsotg *hsotg, int val)
2060 "%d invalid for dma_desc_enable parameter. Check HW configuration.\n", 2012 "%d invalid for dma_desc_enable parameter. Check HW configuration.\n",
2061 val); 2013 val);
2062 val = (hsotg->core_params->dma_enable > 0 && 2014 val = (hsotg->core_params->dma_enable > 0 &&
2063 (hsotg->hwcfg4 & GHWCFG4_DESC_DMA)); 2015 hsotg->hw_params.dma_desc_enable);
2064 dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val); 2016 dev_dbg(hsotg->dev, "Setting dma_desc_enable to %d\n", val);
2065 retval = -EINVAL; 2017 retval = -EINVAL;
2066 } 2018 }
@@ -2096,7 +2048,7 @@ int dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val)
2096 int valid = 1; 2048 int valid = 1;
2097 int retval = 0; 2049 int retval = 0;
2098 2050
2099 if (val > 0 && !(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO)) 2051 if (val > 0 && !hsotg->hw_params.enable_dynamic_fifo)
2100 valid = 0; 2052 valid = 0;
2101 if (val < 0) 2053 if (val < 0)
2102 valid = 0; 2054 valid = 0;
@@ -2106,7 +2058,7 @@ int dwc2_set_param_enable_dynamic_fifo(struct dwc2_hsotg *hsotg, int val)
2106 dev_err(hsotg->dev, 2058 dev_err(hsotg->dev,
2107 "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n", 2059 "%d invalid for enable_dynamic_fifo parameter. Check HW configuration.\n",
2108 val); 2060 val);
2109 val = !!(hsotg->hwcfg2 & GHWCFG2_DYNAMIC_FIFO); 2061 val = hsotg->hw_params.enable_dynamic_fifo;
2110 dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val); 2062 dev_dbg(hsotg->dev, "Setting enable_dynamic_fifo to %d\n", val);
2111 retval = -EINVAL; 2063 retval = -EINVAL;
2112 } 2064 }
@@ -2120,9 +2072,7 @@ int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2120 int valid = 1; 2072 int valid = 1;
2121 int retval = 0; 2073 int retval = 0;
2122 2074
2123 if (val < 16 || val > (readl(hsotg->regs + GRXFSIZ) & 2075 if (val < 16 || val > hsotg->hw_params.host_rx_fifo_size)
2124 GRXFSIZ_DEPTH_MASK) >>
2125 GRXFSIZ_DEPTH_SHIFT)
2126 valid = 0; 2076 valid = 0;
2127 2077
2128 if (!valid) { 2078 if (!valid) {
@@ -2130,9 +2080,7 @@ int dwc2_set_param_host_rx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2130 dev_err(hsotg->dev, 2080 dev_err(hsotg->dev,
2131 "%d invalid for host_rx_fifo_size. Check HW configuration.\n", 2081 "%d invalid for host_rx_fifo_size. Check HW configuration.\n",
2132 val); 2082 val);
2133 val = (readl(hsotg->regs + GRXFSIZ) & 2083 val = hsotg->hw_params.host_rx_fifo_size;
2134 GRXFSIZ_DEPTH_MASK) >>
2135 GRXFSIZ_DEPTH_SHIFT;
2136 dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val); 2084 dev_dbg(hsotg->dev, "Setting host_rx_fifo_size to %d\n", val);
2137 retval = -EINVAL; 2085 retval = -EINVAL;
2138 } 2086 }
@@ -2146,7 +2094,7 @@ int dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2146 int valid = 1; 2094 int valid = 1;
2147 int retval = 0; 2095 int retval = 0;
2148 2096
2149 if (val < 16 || val > (readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff)) 2097 if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size)
2150 valid = 0; 2098 valid = 0;
2151 2099
2152 if (!valid) { 2100 if (!valid) {
@@ -2154,7 +2102,7 @@ int dwc2_set_param_host_nperio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2154 dev_err(hsotg->dev, 2102 dev_err(hsotg->dev,
2155 "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n", 2103 "%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
2156 val); 2104 val);
2157 val = readl(hsotg->regs + GNPTXFSIZ) >> 16 & 0xffff; 2105 val = hsotg->hw_params.host_nperio_tx_fifo_size;
2158 dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n", 2106 dev_dbg(hsotg->dev, "Setting host_nperio_tx_fifo_size to %d\n",
2159 val); 2107 val);
2160 retval = -EINVAL; 2108 retval = -EINVAL;
@@ -2169,7 +2117,7 @@ int dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2169 int valid = 1; 2117 int valid = 1;
2170 int retval = 0; 2118 int retval = 0;
2171 2119
2172 if (val < 16 || val > (hsotg->hptxfsiz >> 16)) 2120 if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size)
2173 valid = 0; 2121 valid = 0;
2174 2122
2175 if (!valid) { 2123 if (!valid) {
@@ -2177,7 +2125,7 @@ int dwc2_set_param_host_perio_tx_fifo_size(struct dwc2_hsotg *hsotg, int val)
2177 dev_err(hsotg->dev, 2125 dev_err(hsotg->dev,
2178 "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n", 2126 "%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
2179 val); 2127 val);
2180 val = hsotg->hptxfsiz >> 16; 2128 val = hsotg->hw_params.host_perio_tx_fifo_size;
2181 dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n", 2129 dev_dbg(hsotg->dev, "Setting host_perio_tx_fifo_size to %d\n",
2182 val); 2130 val);
2183 retval = -EINVAL; 2131 retval = -EINVAL;
@@ -2191,11 +2139,8 @@ int dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
2191{ 2139{
2192 int valid = 1; 2140 int valid = 1;
2193 int retval = 0; 2141 int retval = 0;
2194 int width = hsotg->hwcfg3 >> GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT &
2195 GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK >>
2196 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
2197 2142
2198 if (val < 2047 || val >= (1 << (width + 11))) 2143 if (val < 2047 || val > hsotg->hw_params.max_transfer_size)
2199 valid = 0; 2144 valid = 0;
2200 2145
2201 if (!valid) { 2146 if (!valid) {
@@ -2203,7 +2148,7 @@ int dwc2_set_param_max_transfer_size(struct dwc2_hsotg *hsotg, int val)
2203 dev_err(hsotg->dev, 2148 dev_err(hsotg->dev,
2204 "%d invalid for max_transfer_size. Check HW configuration.\n", 2149 "%d invalid for max_transfer_size. Check HW configuration.\n",
2205 val); 2150 val);
2206 val = (1 << (width + 11)) - 1; 2151 val = hsotg->hw_params.max_transfer_size;
2207 dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val); 2152 dev_dbg(hsotg->dev, "Setting max_transfer_size to %d\n", val);
2208 retval = -EINVAL; 2153 retval = -EINVAL;
2209 } 2154 }
@@ -2216,11 +2161,8 @@ int dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
2216{ 2161{
2217 int valid = 1; 2162 int valid = 1;
2218 int retval = 0; 2163 int retval = 0;
2219 int width = hsotg->hwcfg3 >> GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT &
2220 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK >>
2221 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
2222 2164
2223 if (val < 15 || val >= (1 << (width + 4))) 2165 if (val < 15 || val > hsotg->hw_params.max_packet_count)
2224 valid = 0; 2166 valid = 0;
2225 2167
2226 if (!valid) { 2168 if (!valid) {
@@ -2228,7 +2170,7 @@ int dwc2_set_param_max_packet_count(struct dwc2_hsotg *hsotg, int val)
2228 dev_err(hsotg->dev, 2170 dev_err(hsotg->dev,
2229 "%d invalid for max_packet_count. Check HW configuration.\n", 2171 "%d invalid for max_packet_count. Check HW configuration.\n",
2230 val); 2172 val);
2231 val = (1 << (width + 4)) - 1; 2173 val = hsotg->hw_params.max_packet_count;
2232 dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val); 2174 dev_dbg(hsotg->dev, "Setting max_packet_count to %d\n", val);
2233 retval = -EINVAL; 2175 retval = -EINVAL;
2234 } 2176 }
@@ -2241,10 +2183,8 @@ int dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
2241{ 2183{
2242 int valid = 1; 2184 int valid = 1;
2243 int retval = 0; 2185 int retval = 0;
2244 int num_chan = hsotg->hwcfg2 >> GHWCFG2_NUM_HOST_CHAN_SHIFT &
2245 GHWCFG2_NUM_HOST_CHAN_MASK >> GHWCFG2_NUM_HOST_CHAN_SHIFT;
2246 2186
2247 if (val < 1 || val > num_chan + 1) 2187 if (val < 1 || val > hsotg->hw_params.host_channels)
2248 valid = 0; 2188 valid = 0;
2249 2189
2250 if (!valid) { 2190 if (!valid) {
@@ -2252,7 +2192,7 @@ int dwc2_set_param_host_channels(struct dwc2_hsotg *hsotg, int val)
2252 dev_err(hsotg->dev, 2192 dev_err(hsotg->dev,
2253 "%d invalid for host_channels. Check HW configuration.\n", 2193 "%d invalid for host_channels. Check HW configuration.\n",
2254 val); 2194 val);
2255 val = num_chan + 1; 2195 val = hsotg->hw_params.host_channels;
2256 dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val); 2196 dev_dbg(hsotg->dev, "Setting host_channels to %d\n", val);
2257 retval = -EINVAL; 2197 retval = -EINVAL;
2258 } 2198 }
@@ -2265,8 +2205,7 @@ int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
2265{ 2205{
2266#ifndef NO_FS_PHY_HW_CHECKS 2206#ifndef NO_FS_PHY_HW_CHECKS
2267 int valid = 0; 2207 int valid = 0;
2268 u32 hs_phy_type; 2208 u32 hs_phy_type, fs_phy_type;
2269 u32 fs_phy_type;
2270#endif 2209#endif
2271 int retval = 0; 2210 int retval = 0;
2272 2211
@@ -2287,11 +2226,8 @@ int dwc2_set_param_phy_type(struct dwc2_hsotg *hsotg, int val)
2287 } 2226 }
2288 2227
2289#ifndef NO_FS_PHY_HW_CHECKS 2228#ifndef NO_FS_PHY_HW_CHECKS
2290 hs_phy_type = (hsotg->hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >> 2229 hs_phy_type = hsotg->hw_params.hs_phy_type;
2291 GHWCFG2_HS_PHY_TYPE_SHIFT; 2230 fs_phy_type = hsotg->hw_params.fs_phy_type;
2292 fs_phy_type = (hsotg->hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
2293 GHWCFG2_FS_PHY_TYPE_SHIFT;
2294
2295 if (val == DWC2_PHY_TYPE_PARAM_UTMI && 2231 if (val == DWC2_PHY_TYPE_PARAM_UTMI &&
2296 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI || 2232 (hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI ||
2297 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI)) 2233 hs_phy_type == GHWCFG2_HS_PHY_TYPE_UTMI_ULPI))
@@ -2515,7 +2451,7 @@ int dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
2515 } 2451 }
2516 2452
2517#ifndef NO_FS_PHY_HW_CHECKS 2453#ifndef NO_FS_PHY_HW_CHECKS
2518 if (val == 1 && !(hsotg->hwcfg3 & GHWCFG3_I2C)) 2454 if (val == 1 && !(hsotg->hw_params.i2c_enable))
2519 valid = 0; 2455 valid = 0;
2520 2456
2521 if (!valid) { 2457 if (!valid) {
@@ -2523,7 +2459,7 @@ int dwc2_set_param_i2c_enable(struct dwc2_hsotg *hsotg, int val)
2523 dev_err(hsotg->dev, 2459 dev_err(hsotg->dev,
2524 "%d invalid for i2c_enable. Check HW configuration.\n", 2460 "%d invalid for i2c_enable. Check HW configuration.\n",
2525 val); 2461 val);
2526 val = !!(hsotg->hwcfg3 & GHWCFG3_I2C); 2462 val = hsotg->hw_params.i2c_enable;
2527 dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val); 2463 dev_dbg(hsotg->dev, "Setting i2c_enable to %d\n", val);
2528 retval = -EINVAL; 2464 retval = -EINVAL;
2529 } 2465 }
@@ -2548,7 +2484,7 @@ int dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val)
2548 valid = 0; 2484 valid = 0;
2549 } 2485 }
2550 2486
2551 if (val == 1 && !(hsotg->hwcfg4 & GHWCFG4_DED_FIFO_EN)) 2487 if (val == 1 && !hsotg->hw_params.en_multiple_tx_fifo)
2552 valid = 0; 2488 valid = 0;
2553 2489
2554 if (!valid) { 2490 if (!valid) {
@@ -2556,7 +2492,7 @@ int dwc2_set_param_en_multiple_tx_fifo(struct dwc2_hsotg *hsotg, int val)
2556 dev_err(hsotg->dev, 2492 dev_err(hsotg->dev,
2557 "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n", 2493 "%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
2558 val); 2494 val);
2559 val = !!(hsotg->hwcfg4 & GHWCFG4_DED_FIFO_EN); 2495 val = hsotg->hw_params.en_multiple_tx_fifo;
2560 dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val); 2496 dev_dbg(hsotg->dev, "Setting en_multiple_tx_fifo to %d\n", val);
2561 retval = -EINVAL; 2497 retval = -EINVAL;
2562 } 2498 }
@@ -2579,7 +2515,7 @@ int dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
2579 valid = 0; 2515 valid = 0;
2580 } 2516 }
2581 2517
2582 if (val == 1 && hsotg->snpsid < DWC2_CORE_REV_2_92a) 2518 if (val == 1 && hsotg->hw_params.snpsid < DWC2_CORE_REV_2_92a)
2583 valid = 0; 2519 valid = 0;
2584 2520
2585 if (!valid) { 2521 if (!valid) {
@@ -2587,7 +2523,7 @@ int dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, int val)
2587 dev_err(hsotg->dev, 2523 dev_err(hsotg->dev,
2588 "%d invalid for parameter reload_ctl. Check HW configuration.\n", 2524 "%d invalid for parameter reload_ctl. Check HW configuration.\n",
2589 val); 2525 val);
2590 val = hsotg->snpsid >= DWC2_CORE_REV_2_92a; 2526 val = hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_92a;
2591 dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val); 2527 dev_dbg(hsotg->dev, "Setting reload_ctl to %d\n", val);
2592 retval = -EINVAL; 2528 retval = -EINVAL;
2593 } 2529 }
@@ -2626,6 +2562,161 @@ int dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val)
2626 return retval; 2562 return retval;
2627} 2563}
2628 2564
2565/**
2566 * During device initialization, read various hardware configuration
2567 * registers and interpret the contents.
2568 */
2569int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
2570{
2571 struct dwc2_hw_params *hw = &hsotg->hw_params;
2572 unsigned width;
2573 u32 hwcfg1, hwcfg2, hwcfg3, hwcfg4;
2574 u32 hptxfsiz, grxfsiz, gnptxfsiz;
2575 u32 gusbcfg;
2576
2577 /*
2578 * Attempt to ensure this device is really a DWC_otg Controller.
2579 * Read and verify the GSNPSID register contents. The value should be
2580 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
2581 * as in "OTG version 2.xx" or "OTG version 3.xx".
2582 */
2583 hw->snpsid = readl(hsotg->regs + GSNPSID);
2584 if ((hw->snpsid & 0xfffff000) != 0x4f542000 &&
2585 (hw->snpsid & 0xfffff000) != 0x4f543000) {
2586 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
2587 hw->snpsid);
2588 return -ENODEV;
2589 }
2590
2591 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x (snpsid=%x)\n",
2592 hw->snpsid >> 12 & 0xf, hw->snpsid >> 8 & 0xf,
2593 hw->snpsid >> 4 & 0xf, hw->snpsid & 0xf, hw->snpsid);
2594
2595 hwcfg1 = readl(hsotg->regs + GHWCFG1);
2596 hwcfg2 = readl(hsotg->regs + GHWCFG2);
2597 hwcfg3 = readl(hsotg->regs + GHWCFG3);
2598 hwcfg4 = readl(hsotg->regs + GHWCFG4);
2599 gnptxfsiz = readl(hsotg->regs + GNPTXFSIZ);
2600 grxfsiz = readl(hsotg->regs + GRXFSIZ);
2601
2602 dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hwcfg1);
2603 dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hwcfg2);
2604 dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hwcfg3);
2605 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hwcfg4);
2606 dev_dbg(hsotg->dev, "gnptxfsiz=%08x\n", gnptxfsiz);
2607 dev_dbg(hsotg->dev, "grxfsiz=%08x\n", grxfsiz);
2608
2609 /* Force host mode to get HPTXFSIZ exact power on value */
2610 gusbcfg = readl(hsotg->regs + GUSBCFG);
2611 gusbcfg |= GUSBCFG_FORCEHOSTMODE;
2612 writel(gusbcfg, hsotg->regs + GUSBCFG);
2613 usleep_range(100000, 150000);
2614
2615 hptxfsiz = readl(hsotg->regs + HPTXFSIZ);
2616 dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hptxfsiz);
2617 gusbcfg = readl(hsotg->regs + GUSBCFG);
2618 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
2619 writel(gusbcfg, hsotg->regs + GUSBCFG);
2620 usleep_range(100000, 150000);
2621
2622 /* hwcfg2 */
2623 hw->op_mode = (hwcfg2 & GHWCFG2_OP_MODE_MASK) >>
2624 GHWCFG2_OP_MODE_SHIFT;
2625 hw->arch = (hwcfg2 & GHWCFG2_ARCHITECTURE_MASK) >>
2626 GHWCFG2_ARCHITECTURE_SHIFT;
2627 hw->enable_dynamic_fifo = !!(hwcfg2 & GHWCFG2_DYNAMIC_FIFO);
2628 hw->host_channels = 1 + ((hwcfg2 & GHWCFG2_NUM_HOST_CHAN_MASK) >>
2629 GHWCFG2_NUM_HOST_CHAN_SHIFT);
2630 hw->hs_phy_type = (hwcfg2 & GHWCFG2_HS_PHY_TYPE_MASK) >>
2631 GHWCFG2_HS_PHY_TYPE_SHIFT;
2632 hw->fs_phy_type = (hwcfg2 & GHWCFG2_FS_PHY_TYPE_MASK) >>
2633 GHWCFG2_FS_PHY_TYPE_SHIFT;
2634 hw->num_dev_ep = (hwcfg2 & GHWCFG2_NUM_DEV_EP_MASK) >>
2635 GHWCFG2_NUM_DEV_EP_SHIFT;
2636 hw->nperio_tx_q_depth =
2637 (hwcfg2 & GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK) >>
2638 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT << 1;
2639 hw->host_perio_tx_q_depth =
2640 (hwcfg2 & GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK) >>
2641 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT << 1;
2642 hw->dev_token_q_depth =
2643 (hwcfg2 & GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK) >>
2644 GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT;
2645
2646 /* hwcfg3 */
2647 width = (hwcfg3 & GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK) >>
2648 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT;
2649 hw->max_transfer_size = (1 << (width + 11)) - 1;
2650 width = (hwcfg3 & GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK) >>
2651 GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT;
2652 hw->max_packet_count = (1 << (width + 4)) - 1;
2653 hw->i2c_enable = !!(hwcfg3 & GHWCFG3_I2C);
2654 hw->total_fifo_size = (hwcfg3 & GHWCFG3_DFIFO_DEPTH_MASK) >>
2655 GHWCFG3_DFIFO_DEPTH_SHIFT;
2656
2657 /* hwcfg4 */
2658 hw->en_multiple_tx_fifo = !!(hwcfg4 & GHWCFG4_DED_FIFO_EN);
2659 hw->num_dev_perio_in_ep = (hwcfg4 & GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK) >>
2660 GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT;
2661 hw->dma_desc_enable = !!(hwcfg4 & GHWCFG4_DESC_DMA);
2662 hw->power_optimized = !!(hwcfg4 & GHWCFG4_POWER_OPTIMIZ);
2663
2664 /* fifo sizes */
2665 hw->host_rx_fifo_size = (grxfsiz & GRXFSIZ_DEPTH_MASK) >>
2666 GRXFSIZ_DEPTH_SHIFT;
2667 hw->host_nperio_tx_fifo_size = (gnptxfsiz & FIFOSIZE_DEPTH_MASK) >>
2668 FIFOSIZE_DEPTH_SHIFT;
2669 hw->host_perio_tx_fifo_size = (hptxfsiz & FIFOSIZE_DEPTH_MASK) >>
2670 FIFOSIZE_DEPTH_SHIFT;
2671
2672 dev_dbg(hsotg->dev, "Detected values from hardware:\n");
2673 dev_dbg(hsotg->dev, " op_mode=%d\n",
2674 hw->op_mode);
2675 dev_dbg(hsotg->dev, " arch=%d\n",
2676 hw->arch);
2677 dev_dbg(hsotg->dev, " dma_desc_enable=%d\n",
2678 hw->dma_desc_enable);
2679 dev_dbg(hsotg->dev, " power_optimized=%d\n",
2680 hw->power_optimized);
2681 dev_dbg(hsotg->dev, " i2c_enable=%d\n",
2682 hw->i2c_enable);
2683 dev_dbg(hsotg->dev, " hs_phy_type=%d\n",
2684 hw->hs_phy_type);
2685 dev_dbg(hsotg->dev, " fs_phy_type=%d\n",
2686 hw->fs_phy_type);
2687 dev_dbg(hsotg->dev, " num_dev_ep=%d\n",
2688 hw->num_dev_ep);
2689 dev_dbg(hsotg->dev, " num_dev_perio_in_ep=%d\n",
2690 hw->num_dev_perio_in_ep);
2691 dev_dbg(hsotg->dev, " host_channels=%d\n",
2692 hw->host_channels);
2693 dev_dbg(hsotg->dev, " max_transfer_size=%d\n",
2694 hw->max_transfer_size);
2695 dev_dbg(hsotg->dev, " max_packet_count=%d\n",
2696 hw->max_packet_count);
2697 dev_dbg(hsotg->dev, " nperio_tx_q_depth=0x%0x\n",
2698 hw->nperio_tx_q_depth);
2699 dev_dbg(hsotg->dev, " host_perio_tx_q_depth=0x%0x\n",
2700 hw->host_perio_tx_q_depth);
2701 dev_dbg(hsotg->dev, " dev_token_q_depth=0x%0x\n",
2702 hw->dev_token_q_depth);
2703 dev_dbg(hsotg->dev, " enable_dynamic_fifo=%d\n",
2704 hw->enable_dynamic_fifo);
2705 dev_dbg(hsotg->dev, " en_multiple_tx_fifo=%d\n",
2706 hw->en_multiple_tx_fifo);
2707 dev_dbg(hsotg->dev, " total_fifo_size=%d\n",
2708 hw->total_fifo_size);
2709 dev_dbg(hsotg->dev, " host_rx_fifo_size=%d\n",
2710 hw->host_rx_fifo_size);
2711 dev_dbg(hsotg->dev, " host_nperio_tx_fifo_size=%d\n",
2712 hw->host_nperio_tx_fifo_size);
2713 dev_dbg(hsotg->dev, " host_perio_tx_fifo_size=%d\n",
2714 hw->host_perio_tx_fifo_size);
2715 dev_dbg(hsotg->dev, "\n");
2716
2717 return 0;
2718}
2719
2629/* 2720/*
2630 * This function is called during module intialization to pass module parameters 2721 * This function is called during module intialization to pass module parameters
2631 * for the DWC_otg core. It returns non-0 if any parameters are invalid. 2722 * for the DWC_otg core. It returns non-0 if any parameters are invalid.
diff --git a/drivers/staging/dwc2/core.h b/drivers/staging/dwc2/core.h
index e5b4dc8948a3..e4eb3a0d0b5b 100644
--- a/drivers/staging/dwc2/core.h
+++ b/drivers/staging/dwc2/core.h
@@ -194,21 +194,87 @@ struct dwc2_core_params {
194}; 194};
195 195
196/** 196/**
197 * struct dwc2_hw_params - Autodetected parameters.
198 *
199 * These parameters are the various parameters read from hardware
200 * registers during initialization. They typically contain the best
201 * supported or maximum value that can be configured in the
202 * corresponding dwc2_core_params value.
203 *
204 * The values that are not in dwc2_core_params are documented below.
205 *
206 * @op_mode Mode of Operation
207 * 0 - HNP- and SRP-Capable OTG (Host & Device)
208 * 1 - SRP-Capable OTG (Host & Device)
209 * 2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
210 * 3 - SRP-Capable Device
211 * 4 - Non-OTG Device
212 * 5 - SRP-Capable Host
213 * 6 - Non-OTG Host
214 * @arch Architecture
215 * 0 - Slave only
216 * 1 - External DMA
217 * 2 - Internal DMA
218 * @power_optimized Are power optimizations enabled?
219 * @num_dev_ep Number of device endpoints available
220 * @num_dev_perio_in_ep Number of device periodic IN endpoints
221 * avaialable
222 * @dev_token_q_depth Device Mode IN Token Sequence Learning Queue
223 * Depth
224 * 0 to 30
225 * @host_perio_tx_q_depth
226 * Host Mode Periodic Request Queue Depth
227 * 2, 4 or 8
228 * @nperio_tx_q_depth
229 * Non-Periodic Request Queue Depth
230 * 2, 4 or 8
231 * @hs_phy_type High-speed PHY interface type
232 * 0 - High-speed interface not supported
233 * 1 - UTMI+
234 * 2 - ULPI
235 * 3 - UTMI+ and ULPI
236 * @fs_phy_type Full-speed PHY interface type
237 * 0 - Full speed interface not supported
238 * 1 - Dedicated full speed interface
239 * 2 - FS pins shared with UTMI+ pins
240 * 3 - FS pins shared with ULPI pins
241 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
242 * @snpsid: Value from SNPSID register
243 */
244struct dwc2_hw_params {
245 unsigned op_mode:3;
246 unsigned arch:2;
247 unsigned dma_desc_enable:1;
248 unsigned enable_dynamic_fifo:1;
249 unsigned en_multiple_tx_fifo:1;
250 unsigned host_rx_fifo_size:16;
251 unsigned host_nperio_tx_fifo_size:16;
252 unsigned host_perio_tx_fifo_size:16;
253 unsigned nperio_tx_q_depth:3;
254 unsigned host_perio_tx_q_depth:3;
255 unsigned dev_token_q_depth:5;
256 unsigned max_transfer_size:26;
257 unsigned max_packet_count:11;
258 unsigned host_channels:4;
259 unsigned hs_phy_type:2;
260 unsigned fs_phy_type:2;
261 unsigned i2c_enable:1;
262 unsigned num_dev_ep:4;
263 unsigned num_dev_perio_in_ep:4;
264 unsigned total_fifo_size:16;
265 unsigned power_optimized:1;
266 u32 snpsid;
267};
268
269/**
197 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic 270 * struct dwc2_hsotg - Holds the state of the driver, including the non-periodic
198 * and periodic schedules 271 * and periodic schedules
199 * 272 *
200 * @dev: The struct device pointer 273 * @dev: The struct device pointer
201 * @regs: Pointer to controller regs 274 * @regs: Pointer to controller regs
202 * @core_params: Parameters that define how the core should be configured 275 * @core_params: Parameters that define how the core should be configured
203 * @hwcfg1: Hardware Configuration - stored here for convenience 276 * @hw_params: Parameters that were autodetected from the
204 * @hwcfg2: Hardware Configuration - stored here for convenience 277 * hardware registers
205 * @hwcfg3: Hardware Configuration - stored here for convenience
206 * @hwcfg4: Hardware Configuration - stored here for convenience
207 * @hptxfsiz: Hardware Configuration - stored here for convenience
208 * @snpsid: Value from SNPSID register
209 * @total_fifo_size: Total internal RAM for FIFOs (bytes)
210 * @rx_fifo_size: Size of Rx FIFO (bytes)
211 * @nperio_tx_fifo_size: Size of Non-periodic Tx FIFO (Bytes)
212 * @op_state: The operational State, during transitions (a_host=> 278 * @op_state: The operational State, during transitions (a_host=>
213 * a_peripheral and b_device=>b_host) this may not match 279 * a_peripheral and b_device=>b_host) this may not match
214 * the core, but allows the software to determine 280 * the core, but allows the software to determine
@@ -296,16 +362,10 @@ struct dwc2_core_params {
296struct dwc2_hsotg { 362struct dwc2_hsotg {
297 struct device *dev; 363 struct device *dev;
298 void __iomem *regs; 364 void __iomem *regs;
365 /** Params detected from hardware */
366 struct dwc2_hw_params hw_params;
367 /** Params to actually use */
299 struct dwc2_core_params *core_params; 368 struct dwc2_core_params *core_params;
300 u32 hwcfg1;
301 u32 hwcfg2;
302 u32 hwcfg3;
303 u32 hwcfg4;
304 u32 hptxfsiz;
305 u32 snpsid;
306 u16 total_fifo_size;
307 u16 rx_fifo_size;
308 u16 nperio_tx_fifo_size;
309 enum usb_otg_state op_state; 369 enum usb_otg_state op_state;
310 370
311 unsigned int queuing_high_bandwidth:1; 371 unsigned int queuing_high_bandwidth:1;
diff --git a/drivers/staging/dwc2/core_intr.c b/drivers/staging/dwc2/core_intr.c
index 98c51bba6622..07cfa2f6aa2b 100644
--- a/drivers/staging/dwc2/core_intr.c
+++ b/drivers/staging/dwc2/core_intr.c
@@ -166,7 +166,7 @@ static void dwc2_handle_otg_intr(struct dwc2_hsotg *hsotg)
166 * WA for 3.00a- HW is not setting cur_mode, even sometimes 166 * WA for 3.00a- HW is not setting cur_mode, even sometimes
167 * this does not help 167 * this does not help
168 */ 168 */
169 if (hsotg->snpsid >= DWC2_CORE_REV_3_00a) 169 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a)
170 udelay(100); 170 udelay(100);
171 if (gotgctl & GOTGCTL_HSTNEGSCS) { 171 if (gotgctl & GOTGCTL_HSTNEGSCS) {
172 if (dwc2_is_host_mode(hsotg)) { 172 if (dwc2_is_host_mode(hsotg)) {
@@ -380,7 +380,7 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
380 dev_dbg(hsotg->dev, 380 dev_dbg(hsotg->dev,
381 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n", 381 "DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
382 !!(dsts & DSTS_SUSPSTS), 382 !!(dsts & DSTS_SUSPSTS),
383 !!(hsotg->hwcfg4 & GHWCFG4_POWER_OPTIMIZ)); 383 hsotg->hw_params.power_optimized);
384 } else { 384 } else {
385 if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) { 385 if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
386 dev_dbg(hsotg->dev, "a_peripheral->a_host\n"); 386 dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
diff --git a/drivers/staging/dwc2/hcd.c b/drivers/staging/dwc2/hcd.c
index 9a1e062b7297..da0d35cc33ce 100644
--- a/drivers/staging/dwc2/hcd.c
+++ b/drivers/staging/dwc2/hcd.c
@@ -2678,7 +2678,7 @@ static void dwc2_hcd_free(struct dwc2_hsotg *hsotg)
2678 writel(ahbcfg, hsotg->regs + GAHBCFG); 2678 writel(ahbcfg, hsotg->regs + GAHBCFG);
2679 writel(0, hsotg->regs + GINTMSK); 2679 writel(0, hsotg->regs + GINTMSK);
2680 2680
2681 if (hsotg->snpsid >= DWC2_CORE_REV_3_00a) { 2681 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_3_00a) {
2682 dctl = readl(hsotg->regs + DCTL); 2682 dctl = readl(hsotg->regs + DCTL);
2683 dctl |= DCTL_SFTDISCON; 2683 dctl |= DCTL_SFTDISCON;
2684 writel(dctl, hsotg->regs + DCTL); 2684 writel(dctl, hsotg->regs + DCTL);
@@ -2730,80 +2730,22 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
2730{ 2730{
2731 struct usb_hcd *hcd; 2731 struct usb_hcd *hcd;
2732 struct dwc2_host_chan *channel; 2732 struct dwc2_host_chan *channel;
2733 u32 gusbcfg, hcfg; 2733 u32 hcfg;
2734 int i, num_channels; 2734 int i, num_channels;
2735 int retval = -ENOMEM; 2735 int retval;
2736 2736
2737 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n"); 2737 dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n");
2738 2738
2739 /* 2739 /* Detect config values from hardware */
2740 * Attempt to ensure this device is really a DWC_otg Controller. 2740 retval = dwc2_get_hwparams(hsotg);
2741 * Read and verify the GSNPSID register contents. The value should be
2742 * 0x45f42xxx or 0x45f43xxx, which corresponds to either "OT2" or "OT3",
2743 * as in "OTG version 2.xx" or "OTG version 3.xx".
2744 */
2745 hsotg->snpsid = readl(hsotg->regs + GSNPSID);
2746 if ((hsotg->snpsid & 0xfffff000) != 0x4f542000 &&
2747 (hsotg->snpsid & 0xfffff000) != 0x4f543000) {
2748 dev_err(hsotg->dev, "Bad value for GSNPSID: 0x%08x\n",
2749 hsotg->snpsid);
2750 retval = -ENODEV;
2751 goto error1;
2752 }
2753 2741
2754 /* 2742 if (retval)
2755 * Store the contents of the hardware configuration registers here for 2743 return retval;
2756 * easy access later 2744
2757 */ 2745 retval = -ENOMEM;
2758 hsotg->hwcfg1 = readl(hsotg->regs + GHWCFG1);
2759 hsotg->hwcfg2 = readl(hsotg->regs + GHWCFG2);
2760 hsotg->hwcfg3 = readl(hsotg->regs + GHWCFG3);
2761 hsotg->hwcfg4 = readl(hsotg->regs + GHWCFG4);
2762
2763 dev_dbg(hsotg->dev, "hwcfg1=%08x\n", hsotg->hwcfg1);
2764 dev_dbg(hsotg->dev, "hwcfg2=%08x\n", hsotg->hwcfg2);
2765 dev_dbg(hsotg->dev, "hwcfg3=%08x\n", hsotg->hwcfg3);
2766 dev_dbg(hsotg->dev, "hwcfg4=%08x\n", hsotg->hwcfg4);
2767
2768 /* Force host mode to get HPTXFSIZ exact power on value */
2769 gusbcfg = readl(hsotg->regs + GUSBCFG);
2770 gusbcfg |= GUSBCFG_FORCEHOSTMODE;
2771 writel(gusbcfg, hsotg->regs + GUSBCFG);
2772 usleep_range(100000, 150000);
2773
2774 hsotg->hptxfsiz = readl(hsotg->regs + HPTXFSIZ);
2775 dev_dbg(hsotg->dev, "hptxfsiz=%08x\n", hsotg->hptxfsiz);
2776 gusbcfg = readl(hsotg->regs + GUSBCFG);
2777 gusbcfg &= ~GUSBCFG_FORCEHOSTMODE;
2778 writel(gusbcfg, hsotg->regs + GUSBCFG);
2779 usleep_range(100000, 150000);
2780 2746
2781 hcfg = readl(hsotg->regs + HCFG); 2747 hcfg = readl(hsotg->regs + HCFG);
2782 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg); 2748 dev_dbg(hsotg->dev, "hcfg=%08x\n", hcfg);
2783 dev_dbg(hsotg->dev, "op_mode=%0x\n",
2784 hsotg->hwcfg2 >> GHWCFG2_OP_MODE_SHIFT &
2785 GHWCFG2_OP_MODE_MASK >> GHWCFG2_OP_MODE_SHIFT);
2786 dev_dbg(hsotg->dev, "arch=%0x\n",
2787 hsotg->hwcfg2 >> GHWCFG2_ARCHITECTURE_SHIFT &
2788 GHWCFG2_ARCHITECTURE_MASK >> GHWCFG2_ARCHITECTURE_SHIFT);
2789 dev_dbg(hsotg->dev, "num_dev_ep=%d\n",
2790 hsotg->hwcfg2 >> GHWCFG2_NUM_DEV_EP_SHIFT &
2791 GHWCFG2_NUM_DEV_EP_MASK >> GHWCFG2_NUM_DEV_EP_SHIFT);
2792 dev_dbg(hsotg->dev, "max_host_chan=%d\n",
2793 hsotg->hwcfg2 >> GHWCFG2_NUM_HOST_CHAN_SHIFT &
2794 GHWCFG2_NUM_HOST_CHAN_MASK >> GHWCFG2_NUM_HOST_CHAN_SHIFT);
2795 dev_dbg(hsotg->dev, "nonperio_tx_q_depth=0x%0x\n",
2796 hsotg->hwcfg2 >> GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT &
2797 GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK >>
2798 GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT);
2799 dev_dbg(hsotg->dev, "host_perio_tx_q_depth=0x%0x\n",
2800 hsotg->hwcfg2 >> GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT &
2801 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK >>
2802 GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT);
2803 dev_dbg(hsotg->dev, "dev_token_q_depth=0x%0x\n",
2804 hsotg->hwcfg2 >> GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT &
2805 GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK >>
2806 GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT);
2807 2749
2808#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS 2750#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS
2809 hsotg->frame_num_array = kzalloc(sizeof(*hsotg->frame_num_array) * 2751 hsotg->frame_num_array = kzalloc(sizeof(*hsotg->frame_num_array) *
@@ -2877,10 +2819,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
2877 } 2819 }
2878 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change); 2820 INIT_WORK(&hsotg->wf_otg, dwc2_conn_id_status_change);
2879 2821
2880 dev_dbg(hsotg->dev, "Core Release: %1x.%1x%1x%1x\n",
2881 hsotg->snpsid >> 12 & 0xf, hsotg->snpsid >> 8 & 0xf,
2882 hsotg->snpsid >> 4 & 0xf, hsotg->snpsid & 0xf);
2883
2884 setup_timer(&hsotg->wkp_timer, dwc2_wakeup_detected, 2822 setup_timer(&hsotg->wkp_timer, dwc2_wakeup_detected,
2885 (unsigned long)hsotg); 2823 (unsigned long)hsotg);
2886 2824
diff --git a/drivers/staging/dwc2/hcd.h b/drivers/staging/dwc2/hcd.h
index 65c782e90e93..cc0a11708319 100644
--- a/drivers/staging/dwc2/hcd.h
+++ b/drivers/staging/dwc2/hcd.h
@@ -453,6 +453,7 @@ extern void dwc2_hcd_remove(struct dwc2_hsotg *hsotg);
453extern int dwc2_set_parameters(struct dwc2_hsotg *hsotg, 453extern int dwc2_set_parameters(struct dwc2_hsotg *hsotg,
454 const struct dwc2_core_params *params); 454 const struct dwc2_core_params *params);
455extern void dwc2_set_all_params(struct dwc2_core_params *params, int value); 455extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
456extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
456 457
457/* Transaction Execution Functions */ 458/* Transaction Execution Functions */
458extern enum dwc2_transaction_type dwc2_hcd_select_transactions( 459extern enum dwc2_transaction_type dwc2_hcd_select_transactions(
diff --git a/drivers/staging/dwc2/hcd_intr.c b/drivers/staging/dwc2/hcd_intr.c
index f60b836b3d13..e143f69939f5 100644
--- a/drivers/staging/dwc2/hcd_intr.c
+++ b/drivers/staging/dwc2/hcd_intr.c
@@ -1759,7 +1759,7 @@ static void dwc2_hc_chhltd_intr_dma(struct dwc2_hsotg *hsotg,
1759 * For core with OUT NAK enhancement, the flow for high-speed 1759 * For core with OUT NAK enhancement, the flow for high-speed
1760 * CONTROL/BULK OUT is handled a little differently 1760 * CONTROL/BULK OUT is handled a little differently
1761 */ 1761 */
1762 if (hsotg->snpsid >= DWC2_CORE_REV_2_71a) { 1762 if (hsotg->hw_params.snpsid >= DWC2_CORE_REV_2_71a) {
1763 if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in && 1763 if (chan->speed == USB_SPEED_HIGH && !chan->ep_is_in &&
1764 (chan->ep_type == USB_ENDPOINT_XFER_CONTROL || 1764 (chan->ep_type == USB_ENDPOINT_XFER_CONTROL ||
1765 chan->ep_type == USB_ENDPOINT_XFER_BULK)) { 1765 chan->ep_type == USB_ENDPOINT_XFER_BULK)) {