ehci-exynos.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 <dm.h>
  11. #include <fdtdec.h>
  12. #include <libfdt.h>
  13. #include <malloc.h>
  14. #include <usb.h>
  15. #include <asm/arch/cpu.h>
  16. #include <asm/arch/ehci.h>
  17. #include <asm/arch/system.h>
  18. #include <asm/arch/power.h>
  19. #include <asm/gpio.h>
  20. #include <linux/errno.h>
  21. #include <linux/compat.h>
  22. #include "ehci.h"
  23. /* Declare global data pointer */
  24. DECLARE_GLOBAL_DATA_PTR;
  25. struct exynos_ehci_platdata {
  26. struct usb_platdata usb_plat;
  27. fdt_addr_t hcd_base;
  28. fdt_addr_t phy_base;
  29. struct gpio_desc vbus_gpio;
  30. };
  31. /**
  32. * Contains pointers to register base addresses
  33. * for the usb controller.
  34. */
  35. struct exynos_ehci {
  36. struct ehci_ctrl ctrl;
  37. struct exynos_usb_phy *usb;
  38. struct ehci_hccr *hcd;
  39. };
  40. static int ehci_usb_ofdata_to_platdata(struct udevice *dev)
  41. {
  42. struct exynos_ehci_platdata *plat = dev_get_platdata(dev);
  43. const void *blob = gd->fdt_blob;
  44. unsigned int node;
  45. int depth;
  46. /*
  47. * Get the base address for XHCI controller from the device node
  48. */
  49. plat->hcd_base = dev_get_addr(dev);
  50. if (plat->hcd_base == FDT_ADDR_T_NONE) {
  51. debug("Can't get the XHCI register base address\n");
  52. return -ENXIO;
  53. }
  54. depth = 0;
  55. node = fdtdec_next_compatible_subnode(blob, dev->of_offset,
  56. COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
  57. if (node <= 0) {
  58. debug("XHCI: Can't get device node for usb3-phy controller\n");
  59. return -ENODEV;
  60. }
  61. /*
  62. * Get the base address for usbphy from the device node
  63. */
  64. plat->phy_base = fdtdec_get_addr(blob, node, "reg");
  65. if (plat->phy_base == FDT_ADDR_T_NONE) {
  66. debug("Can't get the usbphy register address\n");
  67. return -ENXIO;
  68. }
  69. /* Vbus gpio */
  70. gpio_request_by_name(dev, "samsung,vbus-gpio", 0,
  71. &plat->vbus_gpio, GPIOD_IS_OUT);
  72. return 0;
  73. }
  74. static void exynos5_setup_usb_phy(struct exynos_usb_phy *usb)
  75. {
  76. u32 hsic_ctrl;
  77. clrbits_le32(&usb->usbphyctrl0,
  78. HOST_CTRL0_FSEL_MASK |
  79. HOST_CTRL0_COMMONON_N |
  80. /* HOST Phy setting */
  81. HOST_CTRL0_PHYSWRST |
  82. HOST_CTRL0_PHYSWRSTALL |
  83. HOST_CTRL0_SIDDQ |
  84. HOST_CTRL0_FORCESUSPEND |
  85. HOST_CTRL0_FORCESLEEP);
  86. setbits_le32(&usb->usbphyctrl0,
  87. /* Setting up the ref freq */
  88. (CLK_24MHZ << 16) |
  89. /* HOST Phy setting */
  90. HOST_CTRL0_LINKSWRST |
  91. HOST_CTRL0_UTMISWRST);
  92. udelay(10);
  93. clrbits_le32(&usb->usbphyctrl0,
  94. HOST_CTRL0_LINKSWRST |
  95. HOST_CTRL0_UTMISWRST);
  96. /* HSIC Phy Setting */
  97. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  98. HSIC_CTRL_FORCESLEEP |
  99. HSIC_CTRL_SIDDQ);
  100. clrbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  101. clrbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  102. hsic_ctrl = (((HSIC_CTRL_REFCLKDIV_12 & HSIC_CTRL_REFCLKDIV_MASK)
  103. << HSIC_CTRL_REFCLKDIV_SHIFT)
  104. | ((HSIC_CTRL_REFCLKSEL & HSIC_CTRL_REFCLKSEL_MASK)
  105. << HSIC_CTRL_REFCLKSEL_SHIFT)
  106. | HSIC_CTRL_UTMISWRST);
  107. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  108. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  109. udelay(10);
  110. clrbits_le32(&usb->hsicphyctrl1, HSIC_CTRL_PHYSWRST |
  111. HSIC_CTRL_UTMISWRST);
  112. clrbits_le32(&usb->hsicphyctrl2, HSIC_CTRL_PHYSWRST |
  113. HSIC_CTRL_UTMISWRST);
  114. udelay(20);
  115. /* EHCI Ctrl setting */
  116. setbits_le32(&usb->ehcictrl,
  117. EHCICTRL_ENAINCRXALIGN |
  118. EHCICTRL_ENAINCR4 |
  119. EHCICTRL_ENAINCR8 |
  120. EHCICTRL_ENAINCR16);
  121. }
  122. static void exynos4412_setup_usb_phy(struct exynos4412_usb_phy *usb)
  123. {
  124. writel(CLK_24MHZ, &usb->usbphyclk);
  125. clrbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  126. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  127. PHYPWR_NORMAL_MASK_PHY0));
  128. setbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  129. udelay(10);
  130. clrbits_le32(&usb->usbphyrstcon, (RSTCON_HOSTPHY_SWRST | RSTCON_SWRST));
  131. }
  132. static void setup_usb_phy(struct exynos_usb_phy *usb)
  133. {
  134. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  135. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  136. if (cpu_is_exynos5())
  137. exynos5_setup_usb_phy(usb);
  138. else if (cpu_is_exynos4())
  139. if (proid_is_exynos4412())
  140. exynos4412_setup_usb_phy((struct exynos4412_usb_phy *)
  141. usb);
  142. }
  143. static void exynos5_reset_usb_phy(struct exynos_usb_phy *usb)
  144. {
  145. u32 hsic_ctrl;
  146. /* HOST_PHY reset */
  147. setbits_le32(&usb->usbphyctrl0,
  148. HOST_CTRL0_PHYSWRST |
  149. HOST_CTRL0_PHYSWRSTALL |
  150. HOST_CTRL0_SIDDQ |
  151. HOST_CTRL0_FORCESUSPEND |
  152. HOST_CTRL0_FORCESLEEP);
  153. /* HSIC Phy reset */
  154. hsic_ctrl = (HSIC_CTRL_FORCESUSPEND |
  155. HSIC_CTRL_FORCESLEEP |
  156. HSIC_CTRL_SIDDQ |
  157. HSIC_CTRL_PHYSWRST);
  158. setbits_le32(&usb->hsicphyctrl1, hsic_ctrl);
  159. setbits_le32(&usb->hsicphyctrl2, hsic_ctrl);
  160. }
  161. static void exynos4412_reset_usb_phy(struct exynos4412_usb_phy *usb)
  162. {
  163. setbits_le32(&usb->usbphyctrl, (PHYPWR_NORMAL_MASK_HSIC0 |
  164. PHYPWR_NORMAL_MASK_HSIC1 | PHYPWR_NORMAL_MASK_PHY1 |
  165. PHYPWR_NORMAL_MASK_PHY0));
  166. }
  167. /* Reset the EHCI host controller. */
  168. static void reset_usb_phy(struct exynos_usb_phy *usb)
  169. {
  170. if (cpu_is_exynos5())
  171. exynos5_reset_usb_phy(usb);
  172. else if (cpu_is_exynos4())
  173. if (proid_is_exynos4412())
  174. exynos4412_reset_usb_phy((struct exynos4412_usb_phy *)
  175. usb);
  176. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  177. }
  178. static int ehci_usb_probe(struct udevice *dev)
  179. {
  180. struct exynos_ehci_platdata *plat = dev_get_platdata(dev);
  181. struct exynos_ehci *ctx = dev_get_priv(dev);
  182. struct ehci_hcor *hcor;
  183. ctx->hcd = (struct ehci_hccr *)plat->hcd_base;
  184. ctx->usb = (struct exynos_usb_phy *)plat->phy_base;
  185. /* setup the Vbus gpio here */
  186. if (dm_gpio_is_valid(&plat->vbus_gpio))
  187. dm_gpio_set_value(&plat->vbus_gpio, 1);
  188. setup_usb_phy(ctx->usb);
  189. hcor = (struct ehci_hcor *)((uint32_t)ctx->hcd +
  190. HC_LENGTH(ehci_readl(&ctx->hcd->cr_capbase)));
  191. return ehci_register(dev, ctx->hcd, hcor, NULL, 0, USB_INIT_HOST);
  192. }
  193. static int ehci_usb_remove(struct udevice *dev)
  194. {
  195. struct exynos_ehci *ctx = dev_get_priv(dev);
  196. int ret;
  197. ret = ehci_deregister(dev);
  198. if (ret)
  199. return ret;
  200. reset_usb_phy(ctx->usb);
  201. return 0;
  202. }
  203. static const struct udevice_id ehci_usb_ids[] = {
  204. { .compatible = "samsung,exynos-ehci" },
  205. { }
  206. };
  207. U_BOOT_DRIVER(usb_ehci) = {
  208. .name = "ehci_exynos",
  209. .id = UCLASS_USB,
  210. .of_match = ehci_usb_ids,
  211. .ofdata_to_platdata = ehci_usb_ofdata_to_platdata,
  212. .probe = ehci_usb_probe,
  213. .remove = ehci_usb_remove,
  214. .ops = &ehci_usb_ops,
  215. .priv_auto_alloc_size = sizeof(struct exynos_ehci),
  216. .platdata_auto_alloc_size = sizeof(struct exynos_ehci_platdata),
  217. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  218. };