ehci-omap.c 7.2 KB

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