ehci-mxs.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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/regs-common.h>
  24. #include <asm/arch/regs-base.h>
  25. #include <asm/arch/regs-clkctrl-mx28.h>
  26. #include <asm/arch/regs-usb.h>
  27. #include <asm/arch/regs-usbphy.h>
  28. #include "ehci.h"
  29. #if (CONFIG_EHCI_MXS_PORT != 0) && (CONFIG_EHCI_MXS_PORT != 1)
  30. #error "MXS EHCI: Invalid port selected!"
  31. #endif
  32. #ifndef CONFIG_EHCI_MXS_PORT
  33. #error "MXS EHCI: Please define correct port using CONFIG_EHCI_MXS_PORT!"
  34. #endif
  35. static struct ehci_mxs {
  36. struct mxs_usb_regs *usb_regs;
  37. struct mxs_usbphy_regs *phy_regs;
  38. } ehci_mxs;
  39. int mxs_ehci_get_port(struct ehci_mxs *mxs_usb, int port)
  40. {
  41. uint32_t usb_base, phy_base;
  42. switch (port) {
  43. case 0:
  44. usb_base = MXS_USBCTRL0_BASE;
  45. phy_base = MXS_USBPHY0_BASE;
  46. break;
  47. case 1:
  48. usb_base = MXS_USBCTRL1_BASE;
  49. phy_base = MXS_USBPHY1_BASE;
  50. break;
  51. default:
  52. printf("CONFIG_EHCI_MXS_PORT (port = %d)\n", port);
  53. return -1;
  54. }
  55. mxs_usb->usb_regs = (struct mxs_usb_regs *)usb_base;
  56. mxs_usb->phy_regs = (struct mxs_usbphy_regs *)phy_base;
  57. return 0;
  58. }
  59. /* This DIGCTL register ungates clock to USB */
  60. #define HW_DIGCTL_CTRL 0x8001c000
  61. #define HW_DIGCTL_CTRL_USB0_CLKGATE (1 << 2)
  62. #define HW_DIGCTL_CTRL_USB1_CLKGATE (1 << 16)
  63. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  64. {
  65. int ret;
  66. uint32_t usb_base, cap_base;
  67. struct mxs_register_32 *digctl_ctrl =
  68. (struct mxs_register_32 *)HW_DIGCTL_CTRL;
  69. struct mxs_clkctrl_regs *clkctrl_regs =
  70. (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
  71. ret = mxs_ehci_get_port(&ehci_mxs, CONFIG_EHCI_MXS_PORT);
  72. if (ret)
  73. return ret;
  74. /* Reset the PHY block */
  75. writel(USBPHY_CTRL_SFTRST, &ehci_mxs.phy_regs->hw_usbphy_ctrl_set);
  76. udelay(10);
  77. writel(USBPHY_CTRL_SFTRST | USBPHY_CTRL_CLKGATE,
  78. &ehci_mxs.phy_regs->hw_usbphy_ctrl_clr);
  79. /* Enable USB clock */
  80. writel(CLKCTRL_PLL0CTRL0_EN_USB_CLKS | CLKCTRL_PLL0CTRL0_POWER,
  81. &clkctrl_regs->hw_clkctrl_pll0ctrl0_set);
  82. writel(CLKCTRL_PLL1CTRL0_EN_USB_CLKS | CLKCTRL_PLL1CTRL0_POWER,
  83. &clkctrl_regs->hw_clkctrl_pll1ctrl0_set);
  84. writel(HW_DIGCTL_CTRL_USB0_CLKGATE | HW_DIGCTL_CTRL_USB1_CLKGATE,
  85. &digctl_ctrl->reg_clr);
  86. /* Start USB PHY */
  87. writel(0, &ehci_mxs.phy_regs->hw_usbphy_pwd);
  88. /* Enable UTMI+ Level 2 and Level 3 compatibility */
  89. writel(USBPHY_CTRL_ENUTMILEVEL3 | USBPHY_CTRL_ENUTMILEVEL2 | 1,
  90. &ehci_mxs.phy_regs->hw_usbphy_ctrl_set);
  91. usb_base = ((uint32_t)ehci_mxs.usb_regs) + 0x100;
  92. *hccr = (struct ehci_hccr *)usb_base;
  93. cap_base = ehci_readl(&(*hccr)->cr_capbase);
  94. *hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  95. return 0;
  96. }
  97. int ehci_hcd_stop(int index)
  98. {
  99. int ret;
  100. uint32_t usb_base, cap_base, tmp;
  101. struct mxs_register_32 *digctl_ctrl =
  102. (struct mxs_register_32 *)HW_DIGCTL_CTRL;
  103. struct mxs_clkctrl_regs *clkctrl_regs =
  104. (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE;
  105. struct ehci_hccr *hccr;
  106. struct ehci_hcor *hcor;
  107. ret = mxs_ehci_get_port(&ehci_mxs, CONFIG_EHCI_MXS_PORT);
  108. if (ret)
  109. return ret;
  110. /* Stop the USB port */
  111. usb_base = ((uint32_t)ehci_mxs.usb_regs) + 0x100;
  112. hccr = (struct ehci_hccr *)usb_base;
  113. cap_base = ehci_readl(&hccr->cr_capbase);
  114. hcor = (struct ehci_hcor *)(usb_base + HC_LENGTH(cap_base));
  115. tmp = ehci_readl(&hcor->or_usbcmd);
  116. tmp &= ~CMD_RUN;
  117. ehci_writel(tmp, &hcor->or_usbcmd);
  118. /* Disable the PHY */
  119. tmp = USBPHY_PWD_RXPWDRX | USBPHY_PWD_RXPWDDIFF |
  120. USBPHY_PWD_RXPWD1PT1 | USBPHY_PWD_RXPWDENV |
  121. USBPHY_PWD_TXPWDV2I | USBPHY_PWD_TXPWDIBIAS |
  122. USBPHY_PWD_TXPWDFS;
  123. writel(tmp, &ehci_mxs.phy_regs->hw_usbphy_pwd);
  124. /* Disable USB clock */
  125. writel(CLKCTRL_PLL0CTRL0_EN_USB_CLKS,
  126. &clkctrl_regs->hw_clkctrl_pll0ctrl0_clr);
  127. writel(CLKCTRL_PLL1CTRL0_EN_USB_CLKS,
  128. &clkctrl_regs->hw_clkctrl_pll1ctrl0_clr);
  129. /* Gate off the USB clock */
  130. writel(HW_DIGCTL_CTRL_USB0_CLKGATE | HW_DIGCTL_CTRL_USB1_CLKGATE,
  131. &digctl_ctrl->reg_set);
  132. return 0;
  133. }