ehci-mxs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <common.h>
  22. #include <asm/io.h>
  23. #include <asm/arch/imx-regs.h>
  24. #include <errno.h>
  25. #include "ehci.h"
  26. /* This DIGCTL register ungates clock to USB */
  27. #define HW_DIGCTL_CTRL 0x8001c000
  28. #define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2)
  29. #define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16)
  30. struct ehci_mxs_port {
  31. uint32_t usb_regs;
  32. struct mxs_usbphy_regs *phy_regs;
  33. struct mxs_register_32 *pll;
  34. uint32_t pll_en_bits;
  35. uint32_t pll_dis_bits;
  36. uint32_t gate_bits;
  37. };
  38. static const struct ehci_mxs_port mxs_port[] = {
  39. #ifdef CONFIG_EHCI_MXS_PORT0
  40. {
  41. MXS_USBCTRL0_BASE,
  42. (struct mxs_usbphy_regs *)MXS_USBPHY0_BASE,
  43. (struct mxs_register_32 *)(MXS_CLKCTRL_BASE +
  44. offsetof(struct mxs_clkctrl_regs,
  45. hw_clkctrl_pll0ctrl0_reg)),
  46. CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER,
  47. CLKCTRL_PLL0CTRL0_EN_USB_CLKS,
  48. HW_DIGCTL_CTRL_USB0_CLKGATE,
  49. },
  50. #endif
  51. #ifdef CONFIG_EHCI_MXS_PORT1
  52. {
  53. MXS_USBCTRL1_BASE,
  54. (struct mxs_usbphy_regs *)MXS_USBPHY1_BASE,
  55. (struct mxs_register_32 *)(MXS_CLKCTRL_BASE +
  56. offsetof(struct mxs_clkctrl_regs,
  57. hw_clkctrl_pll1ctrl0_reg)),
  58. CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER,
  59. CLKCTRL_PLL1CTRL0_EN_USB_CLKS,
  60. HW_DIGCTL_CTRL_USB1_CLKGATE,
  61. },
  62. #endif
  63. };
  64. static int ehci_mxs_toggle_clock(const struct ehci_mxs_port *port, int enable)
  65. {
  66. struct mxs_register_32 *digctl_ctrl =
  67. (struct mxs_register_32 *)HW_DIGCTL_CTRL;
  68. int pll_offset, dig_offset;
  69. if (enable) {
  70. pll_offset = offsetof(struct mxs_register_32, reg_set);
  71. dig_offset = offsetof(struct mxs_register_32, reg_clr);
  72. writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset);
  73. writel(port->pll_en_bits, (u32)port->pll + pll_offset);
  74. } else {
  75. pll_offset = offsetof(struct mxs_register_32, reg_clr);
  76. dig_offset = offsetof(struct mxs_register_32, reg_set);
  77. writel(port->pll_dis_bits, (u32)port->pll + pll_offset);
  78. writel(port->gate_bits, (u32)&digctl_ctrl->reg + dig_offset);
  79. }
  80. return 0;
  81. }
  82. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  83. {
  84. int ret;
  85. uint32_t usb_base, cap_base;
  86. const struct ehci_mxs_port *port;
  87. if ((index < 0) || (index >= ARRAY_SIZE(mxs_port))) {
  88. printf("Invalid port index (index = %d)!\n", index);
  89. return -EINVAL;
  90. }
  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. return ret;
  141. }