ehci-omap.c 7.4 KB

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