ehci-exynos.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * SAMSUNG EXYNOS USB HOST EHCI Controller
  3. *
  4. * Copyright (C) 2012 Samsung Electronics Co.Ltd
  5. * Vivek Gautam <gautam.vivek@samsung.com>
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <common.h>
  10. #include <fdtdec.h>
  11. #include <libfdt.h>
  12. #include <malloc.h>
  13. #include <usb.h>
  14. #include <asm/arch/cpu.h>
  15. #include <asm/arch/ehci.h>
  16. #include <asm/arch/system.h>
  17. #include <asm/arch/power.h>
  18. #include <asm/gpio.h>
  19. #include <asm-generic/errno.h>
  20. #include <linux/compat.h>
  21. #include "ehci.h"
  22. /* Declare global data pointer */
  23. DECLARE_GLOBAL_DATA_PTR;
  24. /**
  25. * Contains pointers to register base addresses
  26. * for the usb controller.
  27. */
  28. struct exynos_ehci {
  29. struct exynos_usb_phy *usb;
  30. struct ehci_hccr *hcd;
  31. struct fdt_gpio_state vbus_gpio;
  32. };
  33. static struct exynos_ehci exynos;
  34. #ifdef CONFIG_OF_CONTROL
  35. static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
  36. {
  37. fdt_addr_t addr;
  38. unsigned int node;
  39. int depth;
  40. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI);
  41. if (node <= 0) {
  42. debug("EHCI: Can't get device node for ehci\n");
  43. return -ENODEV;
  44. }
  45. /*
  46. * Get the base address for EHCI controller from the device node
  47. */
  48. addr = fdtdec_get_addr(blob, node, "reg");
  49. if (addr == FDT_ADDR_T_NONE) {
  50. debug("Can't get the EHCI register address\n");
  51. return -ENXIO;
  52. }
  53. exynos->hcd = (struct ehci_hccr *)addr;
  54. /* Vbus gpio */
  55. fdtdec_decode_gpio(blob, node, "samsung,vbus-gpio", &exynos->vbus_gpio);
  56. depth = 0;
  57. node = fdtdec_next_compatible_subnode(blob, node,
  58. COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
  59. if (node <= 0) {
  60. debug("EHCI: Can't get device node for usb-phy controller\n");
  61. return -ENODEV;
  62. }
  63. /*
  64. * Get the base address for usbphy from the device node
  65. */
  66. exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
  67. "reg");
  68. if (exynos->usb == NULL) {
  69. debug("Can't get the usbphy register address\n");
  70. return -ENXIO;
  71. }
  72. return 0;
  73. }
  74. #endif
  75. /* Setup the EHCI host controller. */
  76. static void setup_usb_phy(struct exynos_usb_phy *usb)
  77. {
  78. u32 hsic_ctrl;
  79. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  80. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  81. clrbits_le32(&usb->usbphyctrl0,
  82. HOST_CTRL0_FSEL_MASK |
  83. HOST_CTRL0_COMMONON_N |
  84. /* HOST Phy setting */
  85. HOST_CTRL0_PHYSWRST |
  86. HOST_CTRL0_PHYSWRSTALL |
  87. HOST_CTRL0_SIDDQ |
  88. HOST_CTRL0_FORCESUSPEND |
  89. HOST_CTRL0_FORCESLEEP);
  90. setbits_le32(&usb->usbphyctrl0,
  91. /* Setting up the ref freq */
  92. (CLK_24MHZ << 16) |
  93. /* HOST Phy setting */
  94. HOST_CTRL0_LINKSWRST |
  95. HOST_CTRL0_UTMISWRST);
  96. udelay(10);
  97. clrbits_le32(&usb->usbphyctrl0,
  98. HOST_CTRL0_LINKSWRST |
  99. HOST_CTRL0_UTMISWRST);
  100. /* HSIC Phy Setting */
  101. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  102. HSIC_CTRL_FORCESLEEP |
  103. HSIC_CTRL_SIDDQ);
  104. clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  105. clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  106. hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
  107. << HSIC_CTRL_REFCLKDIV_SHIFT)
  108. | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
  109. << HSIC_CTRL_REFCLKSEL_SHIFT)
  110. | HSIC_CTRL_UTMISWRST);
  111. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  112. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  113. udelay(10);
  114. clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
  115. HSIC_CTRL_UTMISWRST);
  116. clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
  117. HSIC_CTRL_UTMISWRST);
  118. udelay(20);
  119. /* EHCI Ctrl setting */
  120. setbits_le32(&usb->ehcictrl,
  121. EHCICTRL_ENAINCRXALIGN |
  122. EHCICTRL_ENAINCR4 |
  123. EHCICTRL_ENAINCR8 |
  124. EHCICTRL_ENAINCR16);
  125. }
  126. /* Reset the EHCI host controller. */
  127. static void reset_usb_phy(struct exynos_usb_phy *usb)
  128. {
  129. u32 hsic_ctrl;
  130. /* HOST_PHY reset */
  131. setbits_le32(&usb->usbphyctrl0,
  132. HOST_CTRL0_PHYSWRST |
  133. HOST_CTRL0_PHYSWRSTALL |
  134. HOST_CTRL0_SIDDQ |
  135. HOST_CTRL0_FORCESUSPEND |
  136. HOST_CTRL0_FORCESLEEP);
  137. /* HSIC Phy reset */
  138. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  139. HSIC_CTRL_FORCESLEEP |
  140. HSIC_CTRL_SIDDQ |
  141. HSIC_CTRL_PHYSWRST);
  142. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  143. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  144. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  145. }
  146. /*
  147. * EHCI-initialization
  148. * Create the appropriate control structures to manage
  149. * a new EHCI host controller.
  150. */
  151. int ehci_hcd_init(int index, enum usb_init_type init,
  152. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  153. {
  154. struct exynos_ehci *ctx = &exynos;
  155. #ifdef CONFIG_OF_CONTROL
  156. if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
  157. debug("Unable to parse device tree for ehci-exynos\n");
  158. return -ENODEV;
  159. }
  160. #else
  161. ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
  162. ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
  163. #endif
  164. #ifdef CONFIG_OF_CONTROL
  165. /* setup the Vbus gpio here */
  166. if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
  167. !fdtdec_setup_gpio(&ctx->vbus_gpio))
  168. gpio_direction_output(ctx->vbus_gpio.gpio, 1);
  169. #endif
  170. setup_usb_phy(ctx->usb);
  171. board_usb_init(index, init);
  172. *hccr = ctx->hcd;
  173. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  174. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  175. debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
  176. (uint32_t)*hccr, (uint32_t)*hcor,
  177. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  178. return 0;
  179. }
  180. /*
  181. * Destroy the appropriate control structures corresponding
  182. * the EHCI host controller.
  183. */
  184. int ehci_hcd_stop(int index)
  185. {
  186. struct exynos_ehci *ctx = &exynos;
  187. reset_usb_phy(ctx->usb);
  188. return 0;
  189. }