ehci-mxs.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  71. {
  72. int ret;
  73. uint32_t usb_base, cap_base;
  74. const struct ehci_mxs_port *port;
  75. if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
  76. printf("Invalid port index (index = %d)!\n", index);
  77. return -EINVAL;
  78. }
  79. port = &mxs_port[index];
  80. /* Reset the PHY block */
  81. writel(USBPHY_CTRL_SFTRST, &port->phy_regs->hw_usbphy_ctrl_set);
  82. udelay(10);
  83. writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE,
  84. &port->phy_regs->hw_usbphy_ctrl_clr);
  85. /* Enable USB clock */
  86. ret = ehci_mxs_toggle_clock(port, 1);
  87. if (ret)
  88. return ret;
  89. /* Start USB PHY */
  90. writel(0, &port->phy_regs->hw_usbphy_pwd);
  91. /* Enable UTMI+ Level 2 and Level 3 compatibility */
  92. writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1,
  93. &port->phy_regs->hw_usbphy_ctrl_set);
  94. usb_base = port->usb_regs + 0x100;
  95. *hccr = (struct ehci_hccr *)usb_base;
  96. cap_base = ehci_readl(&(*hccr)->cr_capbase);
  97. *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  98. return 0;
  99. }
  100. int ehci_hcd_stop(int index)
  101. {
  102. int ret;
  103. uint32_t usb_base, cap_base, tmp;
  104. struct ehci_hccr *hccr;
  105. struct ehci_hcor *hcor;
  106. const struct ehci_mxs_port *port;
  107. if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
  108. printf("Invalid port index (index = %d)!\n", index);
  109. return -EINVAL;
  110. }
  111. port = &mxs_port[index];
  112. /* Stop the USB port */
  113. usb_base = port->usb_regs + 0x100;
  114. hccr = (struct ehci_hccr *)usb_base;
  115. cap_base = ehci_readl(&hccr->cr_capbase);
  116. hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  117. tmp = ehci_readl(&hcor->or_usbcmd);
  118. tmp &= ~CMD_RUN;
  119. ehci_writel(tmp, &hcor->or_usbcmd);
  120. /* Disable the PHY */
  121. tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF |
  122. USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV |
  123. USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS |
  124. USBPHY_PWD_TXPWDFS;
  125. writel(tmp, &port->phy_regs->hw_usbphy_pwd);
  126. /* Disable USB clock */
  127. ret = ehci_mxs_toggle_clock(port, 0);
  128. return ret;
  129. }