ehci-exynos.c 6.3 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 gpio_desc 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. gpio_request_by_name_nodev(blob, node, "samsung,vbus-gpio", 0,
  56. &exynos->vbus_gpio, GPIOD_IS_OUT);
  57. depth = 0;
  58. node = fdtdec_next_compatible_subnode(blob, node,
  59. COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
  60. if (node <= 0) {
  61. debug("EHCI: Can't get device node for usb-phy controller\n");
  62. return -ENODEV;
  63. }
  64. /*
  65. * Get the base address for usbphy from the device node
  66. */
  67. exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
  68. "reg");
  69. if (exynos->usb == NULL) {
  70. debug("Can't get the usbphy register address\n");
  71. return -ENXIO;
  72. }
  73. return 0;
  74. }
  75. #endif
  76. static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
  77. {
  78. u32 hsic_ctrl;
  79. clrbits_le32(&usb->usbphyctrl0,
  80. HOST_CTRL0_FSEL_MASK |
  81. HOST_CTRL0_COMMONON_N |
  82. /* HOST Phy setting */
  83. HOST_CTRL0_PHYSWRST |
  84. HOST_CTRL0_PHYSWRSTALL |
  85. HOST_CTRL0_SIDDQ |
  86. HOST_CTRL0_FORCESUSPEND |
  87. HOST_CTRL0_FORCESLEEP);
  88. setbits_le32(&usb->usbphyctrl0,
  89. /* Setting up the ref freq */
  90. (CLK_24MHZ << 16) |
  91. /* HOST Phy setting */
  92. HOST_CTRL0_LINKSWRST |
  93. HOST_CTRL0_UTMISWRST);
  94. udelay(10);
  95. clrbits_le32(&usb->usbphyctrl0,
  96. HOST_CTRL0_LINKSWRST |
  97. HOST_CTRL0_UTMISWRST);
  98. /* HSIC Phy Setting */
  99. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  100. HSIC_CTRL_FORCESLEEP |
  101. HSIC_CTRL_SIDDQ);
  102. clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  103. clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  104. hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
  105. << HSIC_CTRL_REFCLKDIV_SHIFT)
  106. | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
  107. << HSIC_CTRL_REFCLKSEL_SHIFT)
  108. | HSIC_CTRL_UTMISWRST);
  109. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  110. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  111. udelay(10);
  112. clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
  113. HSIC_CTRL_UTMISWRST);
  114. clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
  115. HSIC_CTRL_UTMISWRST);
  116. udelay(20);
  117. /* EHCI Ctrl setting */
  118. setbits_le32(&usb->ehcictrl,
  119. EHCICTRL_ENAINCRXALIGN |
  120. EHCICTRL_ENAINCR4 |
  121. EHCICTRL_ENAINCR8 |
  122. EHCICTRL_ENAINCR16);
  123. }
  124. static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
  125. {
  126. writel(CLK_24MHZ, &usb->usbphyclk);
  127. clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  128. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  129. PHYPWR_NORMAL_MASK_PHY0));
  130. setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  131. udelay(10);
  132. clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  133. }
  134. static void setup_usb_phy(struct exynos_usb_phy *usb)
  135. {
  136. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  137. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  138. if (cpu_is_exynos5())
  139. exynos5_setup_usb_phy(usb);
  140. else if (cpu_is_exynos4())
  141. if (proid_is_exynos4412())
  142. exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
  143. usb);
  144. }
  145. static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
  146. {
  147. u32 hsic_ctrl;
  148. /* HOST_PHY reset */
  149. setbits_le32(&usb->usbphyctrl0,
  150. HOST_CTRL0_PHYSWRST |
  151. HOST_CTRL0_PHYSWRSTALL |
  152. HOST_CTRL0_SIDDQ |
  153. HOST_CTRL0_FORCESUSPEND |
  154. HOST_CTRL0_FORCESLEEP);
  155. /* HSIC Phy reset */
  156. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  157. HSIC_CTRL_FORCESLEEP |
  158. HSIC_CTRL_SIDDQ |
  159. HSIC_CTRL_PHYSWRST);
  160. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  161. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  162. }
  163. static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
  164. {
  165. setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  166. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  167. PHYPWR_NORMAL_MASK_PHY0));
  168. }
  169. /* Reset the EHCI host controller. */
  170. static void reset_usb_phy(struct exynos_usb_phy *usb)
  171. {
  172. if (cpu_is_exynos5())
  173. exynos5_reset_usb_phy(usb);
  174. else if (cpu_is_exynos4())
  175. if (proid_is_exynos4412())
  176. exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
  177. usb);
  178. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  179. }
  180. /*
  181. * EHCI-initialization
  182. * Create the appropriate control structures to manage
  183. * a new EHCI host controller.
  184. */
  185. int ehci_hcd_init(int index, enum usb_init_type init,
  186. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  187. {
  188. struct exynos_ehci *ctx = &exynos;
  189. #ifdef CONFIG_OF_CONTROL
  190. if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
  191. debug("Unable to parse device tree for ehci-exynos\n");
  192. return -ENODEV;
  193. }
  194. #else
  195. ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
  196. ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
  197. #endif
  198. #ifdef CONFIG_OF_CONTROL
  199. /* setup the Vbus gpio here */
  200. if (dm_gpio_is_valid(&ctx->vbus_gpio))
  201. dm_gpio_set_value(&ctx->vbus_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. }