ehci-mxs.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Freescale i.MX28 USB Host driver
  3. *
  4. * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
  5. * on behalf of DENX Software Engineering GmbH
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <asm/io.h>
  11. #include <asm/arch/imx-regs.h>
  12. #include <errno.h>
  13. #include "ehci.h"
  14. /* This DIGCTL register ungates clock to USB */
  15. #define HW_DIGCTL_CTRL 0x8001c000
  16. #define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2)
  17. #define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16)
  18. struct ehci_mxs_port {
  19. uint32_t usb_regs;
  20. struct mxs_usbphy_regs *phy_regs;
  21. struct mxs_register_32 *pll;
  22. uint32_t pll_en_bits;
  23. uint32_t pll_dis_bits;
  24. uint32_t gate_bits;
  25. };
  26. static const struct ehci_mxs_port mxs_port[] = {
  27. #ifdef CONFIG_EHCI_MXS_PORT0
  28. {
  29. MXS_USBCTRL0_BASE,
  30. (struct mxs_usbphy_regs *)MXS_USBPHY0_BASE,
  31. (struct mxs_register_32 *)(MXS_CLKCTRL_BASE +
  32. offsetof(struct mxs_clkctrl_regs,
  33. hw_clkctrl_pll0ctrl0_reg)),
  34. CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER,
  35. CLKCTRL_PLL0CTRL0_EN_USB_CLKS,
  36. HW_DIGCTL_CTRL_USB0_CLKGATE,
  37. },
  38. #endif
  39. #ifdef CONFIG_EHCI_MXS_PORT1
  40. {
  41. MXS_USBCTRL1_BASE,
  42. (struct mxs_usbphy_regs *)MXS_USBPHY1_BASE,
  43. (struct mxs_register_32 *)(MXS_CLKCTRL_BASE +
  44. offsetof(struct mxs_clkctrl_regs,
  45. hw_clkctrl_pll1ctrl0_reg)),
  46. CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER,
  47. CLKCTRL_PLL1CTRL0_EN_USB_CLKS,
  48. HW_DIGCTL_CTRL_USB1_CLKGATE,
  49. },
  50. #endif
  51. };
  52. static int ehci_mxs_toggle_clock(const struct ehci_mxs_port *port, int enable)
  53. {
  54. struct mxs_register_32 *digctl_ctrl =
  55. (struct mxs_register_32 *)HW_DIGCTL_CTRL;
  56. int pll_offset, dig_offset;
  57. if (enable) {
  58. pll_offset = offsetof(struct mxs_register_32, reg_set);
  59. dig_offset = offsetof(struct mxs_register_32, reg_clr);
  60. writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset);
  61. writel(port->pll_en_bits, (u32)port->pll + pll_offset);
  62. } else {
  63. pll_offset = offsetof(struct mxs_register_32, reg_clr);
  64. dig_offset = offsetof(struct mxs_register_32, reg_set);
  65. writel(port->pll_dis_bits, (u32)port->pll + pll_offset);
  66. writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset);
  67. }
  68. return 0;
  69. }
  70. int __weak board_ehci_hcd_init(int port)
  71. {
  72. return 0;
  73. }
  74. int __weak board_ehci_hcd_exit(int port)
  75. {
  76. return 0;
  77. }
  78. int ehci_hcd_init(int index, enum usb_init_type init,
  79. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  80. {
  81. int ret;
  82. uint32_t usb_base, cap_base;
  83. const struct ehci_mxs_port *port;
  84. if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
  85. printf("Invalid port index (index = %d)!\n", index);
  86. return -EINVAL;
  87. }
  88. ret = board_ehci_hcd_init(index);
  89. if (ret)
  90. return ret;
  91. port = &mxs_port[index];
  92. /* Reset the PHY block */
  93. writel(USBPHY_CTRL_SFTRST, &port->phy_regs->hw_usbphy_ctrl_set);
  94. udelay(10);
  95. writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE,
  96. &port->phy_regs->hw_usbphy_ctrl_clr);
  97. /* Enable USB clock */
  98. ret = ehci_mxs_toggle_clock(port, 1);
  99. if (ret)
  100. return ret;
  101. /* Start USB PHY */
  102. writel(0, &port->phy_regs->hw_usbphy_pwd);
  103. /* Enable UTMI+ Level 2 and Level 3 compatibility */
  104. writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1,
  105. &port->phy_regs->hw_usbphy_ctrl_set);
  106. usb_base = port->usb_regs + 0x100;
  107. *hccr = (struct ehci_hccr *)usb_base;
  108. cap_base = ehci_readl(&(*hccr)->cr_capbase);
  109. *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  110. return 0;
  111. }
  112. int ehci_hcd_stop(int index)
  113. {
  114. int ret;
  115. uint32_t usb_base, cap_base, tmp;
  116. struct ehci_hccr *hccr;
  117. struct ehci_hcor *hcor;
  118. const struct ehci_mxs_port *port;
  119. if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
  120. printf("Invalid port index (index = %d)!\n", index);
  121. return -EINVAL;
  122. }
  123. port = &mxs_port[index];
  124. /* Stop the USB port */
  125. usb_base = port->usb_regs + 0x100;
  126. hccr = (struct ehci_hccr *)usb_base;
  127. cap_base = ehci_readl(&hccr->cr_capbase);
  128. hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  129. tmp = ehci_readl(&hcor->or_usbcmd);
  130. tmp &= ~CMD_RUN;
  131. ehci_writel(tmp, &hcor->or_usbcmd);
  132. /* Disable the PHY */
  133. tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF |
  134. USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV |
  135. USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS |
  136. USBPHY_PWD_TXPWDFS;
  137. writel(tmp, &port->phy_regs->hw_usbphy_pwd);
  138. /* Disable USB clock */
  139. ret = ehci_mxs_toggle_clock(port, 0);
  140. board_ehci_hcd_exit(index);
  141. return ret;
  142. }