xhci-dwc3.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2015 Freescale Semiconductor, Inc.
  3. *
  4. * DWC3 controller driver
  5. *
  6. * Author: Ramneek Mehresh<ramneek.mehresh@freescale.com>
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm/io.h>
  12. #include <linux/usb/dwc3.h>
  13. void dwc3_set_mode(struct dwc3 *dwc3_reg, u32 mode)
  14. {
  15. clrsetbits_le32(&dwc3_reg->g_ctl,
  16. DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG),
  17. DWC3_GCTL_PRTCAPDIR(mode));
  18. }
  19. void dwc3_phy_reset(struct dwc3 *dwc3_reg)
  20. {
  21. /* Assert USB3 PHY reset */
  22. setbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
  23. /* Assert USB2 PHY reset */
  24. setbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
  25. mdelay(100);
  26. /* Clear USB3 PHY reset */
  27. clrbits_le32(&dwc3_reg->g_usb3pipectl[0], DWC3_GUSB3PIPECTL_PHYSOFTRST);
  28. /* Clear USB2 PHY reset */
  29. clrbits_le32(&dwc3_reg->g_usb2phycfg, DWC3_GUSB2PHYCFG_PHYSOFTRST);
  30. }
  31. void dwc3_core_soft_reset(struct dwc3 *dwc3_reg)
  32. {
  33. /* Before Resetting PHY, put Core in Reset */
  34. setbits_le32(&dwc3_reg->g_ctl, DWC3_GCTL_CORESOFTRESET);
  35. /* reset USB3 phy - if required */
  36. dwc3_phy_reset(dwc3_reg);
  37. mdelay(100);
  38. /* After PHYs are stable we can take Core out of reset state */
  39. clrbits_le32(&dwc3_reg->g_ctl, DWC3_GCTL_CORESOFTRESET);
  40. }
  41. int dwc3_core_init(struct dwc3 *dwc3_reg)
  42. {
  43. u32 reg;
  44. u32 revision;
  45. unsigned int dwc3_hwparams1;
  46. revision = readl(&dwc3_reg->g_snpsid);
  47. /* This should read as U3 followed by revision number */
  48. if ((revision & DWC3_GSNPSID_MASK) != 0x55330000) {
  49. puts("this is not a DesignWare USB3 DRD Core\n");
  50. return -1;
  51. }
  52. dwc3_core_soft_reset(dwc3_reg);
  53. dwc3_hwparams1 = readl(&dwc3_reg->g_hwparams1);
  54. reg = readl(&dwc3_reg->g_ctl);
  55. reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
  56. reg &= ~DWC3_GCTL_DISSCRAMBLE;
  57. switch (DWC3_GHWPARAMS1_EN_PWROPT(dwc3_hwparams1)) {
  58. case DWC3_GHWPARAMS1_EN_PWROPT_CLK:
  59. reg &= ~DWC3_GCTL_DSBLCLKGTNG;
  60. break;
  61. default:
  62. debug("No power optimization available\n");
  63. }
  64. /*
  65. * WORKAROUND: DWC3 revisions <1.90a have a bug
  66. * where the device can fail to connect at SuperSpeed
  67. * and falls back to high-speed mode which causes
  68. * the device to enter a Connect/Disconnect loop
  69. */
  70. if ((revision & DWC3_REVISION_MASK) < 0x190a)
  71. reg |= DWC3_GCTL_U2RSTECN;
  72. writel(reg, &dwc3_reg->g_ctl);
  73. return 0;
  74. }
  75. void dwc3_set_fladj(struct dwc3 *dwc3_reg, u32 val)
  76. {
  77. setbits_le32(&dwc3_reg->g_fladj, GFLADJ_30MHZ_REG_SEL |
  78. GFLADJ_30MHZ(val));
  79. }