ehci-omap.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 <usb/ulpi.h>
  31. #include <errno.h>
  32. #include <asm/io.h>
  33. #include <asm/gpio.h>
  34. #include <asm/arch/ehci.h>
  35. #include <asm/ehci-omap.h>
  36. #include "ehci-core.h"
  37. static struct omap_uhh *const uhh = (struct omap_uhh *)OMAP_UHH_BASE;
  38. static struct omap_usbtll *const usbtll = (struct omap_usbtll *)OMAP_USBTLL_BASE;
  39. static struct omap_ehci *const ehci = (struct omap_ehci *)OMAP_EHCI_BASE;
  40. static int omap_uhh_reset(void)
  41. {
  42. unsigned long init = get_timer(0);
  43. /* perform UHH soft reset, and wait until reset is complete */
  44. writel(OMAP_UHH_SYSCONFIG_SOFTRESET, &uhh->sysc);
  45. /* Wait for UHH reset to complete */
  46. while (!(readl(&uhh->syss) & OMAP_UHH_SYSSTATUS_EHCI_RESETDONE))
  47. if (get_timer(init) > CONFIG_SYS_HZ) {
  48. debug("OMAP UHH error: timeout resetting ehci\n");
  49. return -EL3RST;
  50. }
  51. return 0;
  52. }
  53. static int omap_ehci_tll_reset(void)
  54. {
  55. unsigned long init = get_timer(0);
  56. /* perform TLL soft reset, and wait until reset is complete */
  57. writel(OMAP_USBTLL_SYSCONFIG_SOFTRESET, &usbtll->sysc);
  58. /* Wait for TLL reset to complete */
  59. while (!(readl(&usbtll->syss) & OMAP_USBTLL_SYSSTATUS_RESETDONE))
  60. if (get_timer(init) > CONFIG_SYS_HZ) {
  61. debug("OMAP EHCI error: timeout resetting TLL\n");
  62. return -EL3RST;
  63. }
  64. return 0;
  65. }
  66. static void omap_usbhs_hsic_init(int port)
  67. {
  68. unsigned int reg;
  69. /* Enable channels now */
  70. reg = readl(&usbtll->channel_conf + port);
  71. setbits_le32(&reg, (OMAP_TLL_CHANNEL_CONF_CHANMODE_TRANSPARENT_UTMI
  72. | OMAP_TLL_CHANNEL_CONF_ULPINOBITSTUFF
  73. | OMAP_TLL_CHANNEL_CONF_DRVVBUS
  74. | OMAP_TLL_CHANNEL_CONF_CHRGVBUS
  75. | OMAP_TLL_CHANNEL_CONF_CHANEN));
  76. writel(reg, &usbtll->channel_conf + port);
  77. }
  78. static void omap_ehci_soft_phy_reset(int port)
  79. {
  80. struct ulpi_viewport ulpi_vp;
  81. ulpi_vp.viewport_addr = (u32)&ehci->insreg05_utmi_ulpi;
  82. ulpi_vp.port_num = port;
  83. ulpi_reset(&ulpi_vp);
  84. }
  85. inline int __board_usb_init(void)
  86. {
  87. return 0;
  88. }
  89. int board_usb_init(void) __attribute__((weak, alias("__board_usb_init")));
  90. #if defined(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO) || \
  91. defined(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO)
  92. /* controls PHY(s) reset signal(s) */
  93. static inline void omap_ehci_phy_reset(int on, int delay)
  94. {
  95. /*
  96. * Refer ISSUE1:
  97. * Hold the PHY in RESET for enough time till
  98. * PHY is settled and ready
  99. */
  100. if (delay && !on)
  101. udelay(delay);
  102. #ifdef CONFIG_OMAP_EHCI_PHY1_RESET_GPIO
  103. gpio_request(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, "USB PHY1 reset");
  104. gpio_direction_output(CONFIG_OMAP_EHCI_PHY1_RESET_GPIO, !on);
  105. #endif
  106. #ifdef CONFIG_OMAP_EHCI_PHY2_RESET_GPIO
  107. gpio_request(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, "USB PHY2 reset");
  108. gpio_direction_output(CONFIG_OMAP_EHCI_PHY2_RESET_GPIO, !on);
  109. #endif
  110. /* Hold the PHY in RESET for enough time till DIR is high */
  111. /* Refer: ISSUE1 */
  112. if (delay && on)
  113. udelay(delay);
  114. }
  115. #else
  116. #define omap_ehci_phy_reset(on, delay) do {} while (0)
  117. #endif
  118. /* Reset is needed otherwise the kernel-driver will throw an error. */
  119. int omap_ehci_hcd_stop(void)
  120. {
  121. debug("Resetting OMAP EHCI\n");
  122. omap_ehci_phy_reset(1, 0);
  123. if (omap_uhh_reset() < 0)
  124. return -1;
  125. if (omap_ehci_tll_reset() < 0)
  126. return -1;
  127. return 0;
  128. }
  129. /*
  130. * Initialize the OMAP EHCI controller and PHY.
  131. * Based on "drivers/usb/host/ehci-omap.c" from Linux 3.1
  132. * See there for additional Copyrights.
  133. */
  134. int omap_ehci_hcd_init(struct omap_usbhs_board_data *usbhs_pdata)
  135. {
  136. int ret;
  137. unsigned int i, reg = 0, rev = 0;
  138. debug("Initializing OMAP EHCI\n");
  139. ret = board_usb_init();
  140. if (ret < 0)
  141. return ret;
  142. /* Put the PHY in RESET */
  143. omap_ehci_phy_reset(1, 10);
  144. ret = omap_uhh_reset();
  145. if (ret < 0)
  146. return ret;
  147. ret = omap_ehci_tll_reset();
  148. if (ret)
  149. return ret;
  150. writel(OMAP_USBTLL_SYSCONFIG_ENAWAKEUP |
  151. OMAP_USBTLL_SYSCONFIG_SIDLEMODE |
  152. OMAP_USBTLL_SYSCONFIG_CACTIVITY, &usbtll->sysc);
  153. /* Put UHH in NoIdle/NoStandby mode */
  154. writel(OMAP_UHH_SYSCONFIG_VAL, &uhh->sysc);
  155. /* setup ULPI bypass and burst configurations */
  156. clrsetbits_le32(&reg, OMAP_UHH_HOSTCONFIG_INCRX_ALIGN_EN,
  157. (OMAP_UHH_HOSTCONFIG_INCR4_BURST_EN |
  158. OMAP_UHH_HOSTCONFIG_INCR8_BURST_EN |
  159. OMAP_UHH_HOSTCONFIG_INCR16_BURST_EN));
  160. rev = readl(&uhh->rev);
  161. if (rev == OMAP_USBHS_REV1) {
  162. if (is_ehci_phy_mode(usbhs_pdata->port_mode[0]))
  163. clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
  164. else
  165. setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
  166. if (is_ehci_phy_mode(usbhs_pdata->port_mode[1]))
  167. clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P2_BYPASS);
  168. else
  169. setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
  170. if (is_ehci_phy_mode(usbhs_pdata->port_mode[2]))
  171. clrbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P3_BYPASS);
  172. else
  173. setbits_le32(&reg, OMAP_UHH_HOSTCONFIG_ULPI_P1_BYPASS);
  174. } else if (rev == OMAP_USBHS_REV2) {
  175. clrsetbits_le32(&reg, (OMAP_P1_MODE_CLEAR | OMAP_P2_MODE_CLEAR),
  176. OMAP4_UHH_HOSTCONFIG_APP_START_CLK);
  177. /* Clear port mode fields for PHY mode*/
  178. if (is_ehci_hsic_mode(usbhs_pdata->port_mode[0]))
  179. setbits_le32(&reg, OMAP_P1_MODE_HSIC);
  180. if (is_ehci_hsic_mode(usbhs_pdata->port_mode[1]))
  181. setbits_le32(&reg, OMAP_P2_MODE_HSIC);
  182. if (is_ehci_hsic_mode(usbhs_pdata->port_mode[2]))
  183. setbits_le32(&reg, OMAP_P3_MODE_HSIC);
  184. }
  185. debug("OMAP UHH_REVISION 0x%x\n", rev);
  186. writel(reg, &uhh->hostconfig);
  187. for (i = 0; i < OMAP_HS_USB_PORTS; i++)
  188. if (is_ehci_hsic_mode(usbhs_pdata->port_mode[i]))
  189. omap_usbhs_hsic_init(i);
  190. omap_ehci_phy_reset(0, 10);
  191. /*
  192. * An undocumented "feature" in the OMAP3 EHCI controller,
  193. * causes suspended ports to be taken out of suspend when
  194. * the USBCMD.Run/Stop bit is cleared (for example when
  195. * we do ehci_bus_suspend).
  196. * This breaks suspend-resume if the root-hub is allowed
  197. * to suspend. Writing 1 to this undocumented register bit
  198. * disables this feature and restores normal behavior.
  199. */
  200. writel(EHCI_INSNREG04_DISABLE_UNSUSPEND, &ehci->insreg04);
  201. for (i = 0; i < OMAP_HS_USB_PORTS; i++)
  202. if (is_ehci_phy_mode(usbhs_pdata->port_mode[i]))
  203. omap_ehci_soft_phy_reset(i);
  204. dcache_disable();
  205. hccr = (struct ehci_hccr *)(OMAP_EHCI_BASE);
  206. hcor = (struct ehci_hcor *)(OMAP_EHCI_BASE + 0x10);
  207. debug("OMAP EHCI init done\n");
  208. return 0;
  209. }