ehci-omap.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * (C) Copyright 2011 Ilya Yanok, Emcraft Systems
  3. * (C) Copyright 2004-2008
  4. * Texas Instruments, <www.ti.com>
  5. *
  6. * Derived from Beagle Board code by
  7. * Sunil Kumar <sunilsaini05@gmail.com>
  8. * Shashi Ranjan <shashiranjanmca05@gmail.com>
  9. *
  10. *
  11. * See file CREDITS for list of people who contributed to this
  12. * project.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License as
  16. * published by the Free Software Foundation; either version 2 of
  17. * the License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc.
  27. */
  28. #include <common.h>
  29. #include <usb.h>
  30. #include <asm/io.h>
  31. #include <asm/gpio.h>
  32. #include <asm/arch/clocks.h>
  33. #include <asm/arch/clocks_omap3.h>
  34. #include <asm/arch/ehci_omap3.h>
  35. #include <asm/arch/sys_proto.h>
  36. #include "ehci-core.h"
  37. inline int __board_usb_init(void)
  38. {
  39. return 0;
  40. }
  41. int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
  42. #if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
  43. defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO)
  44. /* controls PHY(s) reset signal(s) */
  45. static inline void omap_ehci_phy_reset(int on, int delay)
  46. {
  47. /*
  48. * Refer ISSUE1:
  49. * Hold the PHY in RESET for enough time till
  50. * PHY is settled and ready
  51. */
  52. if (delay && !on)
  53. udelay(delay);
  54. #ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
  55. gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
  56. gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
  57. #endif
  58. #ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
  59. gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
  60. gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
  61. #endif
  62. /* Hold the PHY in RESET for enough time till DIR is high */
  63. /* Refer: ISSUE1 */
  64. if (delay && on)
  65. udelay(delay);
  66. }
  67. #else
  68. #define omap_ehci_phy_reset(on, delay) do {} while (0)
  69. #endif
  70. /* Reset is needed otherwise the kernel-driver will throw an error. */
  71. int ehci_hcd_stop(void)
  72. {
  73. debug("Resetting OMAP3 EHCI\n");
  74. omap_ehci_phy_reset(1, 0);
  75. writel(OMAP_UHH_SYSCONFIG_SOFTRESET,
  76. OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  77. /* disable USB clocks */
  78. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  79. sr32(&prcm_base->iclken_usbhost, 0, 1, 0);
  80. sr32(&prcm_base->fclken_usbhost, 0, 2, 0);
  81. sr32(&prcm_base->iclken3_core, 2, 1, 0);
  82. sr32(&prcm_base->fclken3_core, 2, 1, 0);
  83. return 0;
  84. }
  85. /*
  86. * Initialize the OMAP3 EHCI controller and PHY.
  87. * Based on "drivers/usb/host/ehci-omap.c" from Linux 2.6.37.
  88. * See there for additional Copyrights.
  89. */
  90. int ehci_hcd_init(void)
  91. {
  92. int ret;
  93. debug("Initializing OMAP3 EHCI\n");
  94. ret = board_usb_init();
  95. if (ret < 0)
  96. return ret;
  97. /* Put the PHY in RESET */
  98. omap_ehci_phy_reset(1, 10);
  99. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  100. /* Enable USBHOST_L3_ICLK (USBHOST_MICLK) */
  101. sr32(&prcm_base->iclken_usbhost, 0, 1, 1);
  102. /*
  103. * Enable USBHOST_48M_FCLK (USBHOST_FCLK1)
  104. * and USBHOST_120M_FCLK (USBHOST_FCLK2)
  105. */
  106. sr32(&prcm_base->fclken_usbhost, 0, 2, 3);
  107. /* Enable USBTTL_ICLK */
  108. sr32(&prcm_base->iclken3_core, 2, 1, 1);
  109. /* Enable USBTTL_FCLK */
  110. sr32(&prcm_base->fclken3_core, 2, 1, 1);
  111. debug("USB clocks enabled\n");
  112. /* perform TLL soft reset, and wait until reset is complete */
  113. writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET,
  114. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  115. /* Wait for TLL reset to complete */
  116. while (!(readl(OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSSTATUS)
  117. & OMAP_USBTLL_SYSSTATUS_RESETDONE))
  118. ;
  119. debug("TLL reset done\n");
  120. writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  121. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  122. OMAP_USBTLL_SYSCONFIG_CACTIVITY,
  123. OMAP3_USBTLL_BASE + OMAP_USBTLL_SYSCONFIG);
  124. /* Put UHH in NoIdle/NoStandby mode */
  125. writel(OMAP_UHH_SYSCONFIG_ENAWAKEUP
  126. | OMAP_UHH_SYSCONFIG_SIDLEMODE
  127. | OMAP_UHH_SYSCONFIG_CACTIVITY
  128. | OMAP_UHH_SYSCONFIG_MIDLEMODE,
  129. OMAP3_UHH_BASE + OMAP_UHH_SYSCONFIG);
  130. /* setup burst configurations */
  131. writel(OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN
  132. | OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN
  133. | OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN,
  134. OMAP3_UHH_BASE + OMAP_UHH_HOSTCONFIG);
  135. omap_ehci_phy_reset(0, 10);
  136. hccr = (struct ehci_hccr *)(OMAP3_EHCI_BASE);
  137. hcor = (struct ehci_hcor *)(OMAP3_EHCI_BASE + 0x10);
  138. debug("OMAP3 EHCI init done\n");
  139. return 0;
  140. }