ehci-exynos.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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. static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
  76. {
  77. u32 hsic_ctrl;
  78. clrbits_le32(&usb->usbphyctrl0,
  79. HOST_CTRL0_FSEL_MASK |
  80. HOST_CTRL0_COMMONON_N |
  81. /* HOST Phy setting */
  82. HOST_CTRL0_PHYSWRST |
  83. HOST_CTRL0_PHYSWRSTALL |
  84. HOST_CTRL0_SIDDQ |
  85. HOST_CTRL0_FORCESUSPEND |
  86. HOST_CTRL0_FORCESLEEP);
  87. setbits_le32(&usb->usbphyctrl0,
  88. /* Setting up the ref freq */
  89. (CLK_24MHZ << 16) |
  90. /* HOST Phy setting */
  91. HOST_CTRL0_LINKSWRST |
  92. HOST_CTRL0_UTMISWRST);
  93. udelay(10);
  94. clrbits_le32(&usb->usbphyctrl0,
  95. HOST_CTRL0_LINKSWRST |
  96. HOST_CTRL0_UTMISWRST);
  97. /* HSIC Phy Setting */
  98. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  99. HSIC_CTRL_FORCESLEEP |
  100. HSIC_CTRL_SIDDQ);
  101. clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  102. clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  103. hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
  104. << HSIC_CTRL_REFCLKDIV_SHIFT)
  105. | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
  106. << HSIC_CTRL_REFCLKSEL_SHIFT)
  107. | HSIC_CTRL_UTMISWRST);
  108. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  109. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  110. udelay(10);
  111. clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
  112. HSIC_CTRL_UTMISWRST);
  113. clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
  114. HSIC_CTRL_UTMISWRST);
  115. udelay(20);
  116. /* EHCI Ctrl setting */
  117. setbits_le32(&usb->ehcictrl,
  118. EHCICTRL_ENAINCRXALIGN |
  119. EHCICTRL_ENAINCR4 |
  120. EHCICTRL_ENAINCR8 |
  121. EHCICTRL_ENAINCR16);
  122. }
  123. static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
  124. {
  125. writel(CLK_24MHZ, &usb->usbphyclk);
  126. clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  127. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  128. PHYPWR_NORMAL_MASK_PHY0));
  129. setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  130. udelay(10);
  131. clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  132. }
  133. static void setup_usb_phy(struct exynos_usb_phy *usb)
  134. {
  135. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  136. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  137. if (cpu_is_exynos5())
  138. exynos5_setup_usb_phy(usb);
  139. else if (cpu_is_exynos4())
  140. if (proid_is_exynos4412())
  141. exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
  142. usb);
  143. }
  144. static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
  145. {
  146. u32 hsic_ctrl;
  147. /* HOST_PHY reset */
  148. setbits_le32(&usb->usbphyctrl0,
  149. HOST_CTRL0_PHYSWRST |
  150. HOST_CTRL0_PHYSWRSTALL |
  151. HOST_CTRL0_SIDDQ |
  152. HOST_CTRL0_FORCESUSPEND |
  153. HOST_CTRL0_FORCESLEEP);
  154. /* HSIC Phy reset */
  155. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  156. HSIC_CTRL_FORCESLEEP |
  157. HSIC_CTRL_SIDDQ |
  158. HSIC_CTRL_PHYSWRST);
  159. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  160. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  161. }
  162. static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
  163. {
  164. setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  165. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  166. PHYPWR_NORMAL_MASK_PHY0));
  167. }
  168. /* Reset the EHCI host controller. */
  169. static void reset_usb_phy(struct exynos_usb_phy *usb)
  170. {
  171. if (cpu_is_exynos5())
  172. exynos5_reset_usb_phy(usb);
  173. else if (cpu_is_exynos4())
  174. if (proid_is_exynos4412())
  175. exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
  176. usb);
  177. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  178. }
  179. /*
  180. * EHCI-initialization
  181. * Create the appropriate control structures to manage
  182. * a new EHCI host controller.
  183. */
  184. int ehci_hcd_init(int index, enum usb_init_type init,
  185. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  186. {
  187. struct exynos_ehci *ctx = &exynos;
  188. #ifdef CONFIG_OF_CONTROL
  189. if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
  190. debug("Unable to parse device tree for ehci-exynos\n");
  191. return -ENODEV;
  192. }
  193. #else
  194. ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
  195. ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
  196. #endif
  197. #ifdef CONFIG_OF_CONTROL
  198. /* setup the Vbus gpio here */
  199. if (fdt_gpio_isvalid(&ctx->vbus_gpio) &&
  200. !fdtdec_setup_gpio(&ctx->vbus_gpio))
  201. gpio_direction_output(ctx->vbus_gpio.gpio, 1);
  202. #endif
  203. setup_usb_phy(ctx->usb);
  204. board_usb_init(index, init);
  205. *hccr = ctx->hcd;
  206. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  207. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  208. debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
  209. (uint32_t)*hccr, (uint32_t)*hcor,
  210. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  211. return 0;
  212. }
  213. /*
  214. * Destroy the appropriate control structures corresponding
  215. * the EHCI host controller.
  216. */
  217. int ehci_hcd_stop(int index)
  218. {
  219. struct exynos_ehci *ctx = &exynos;
  220. reset_usb_phy(ctx->usb);
  221. return 0;
  222. }