ehci-exynos.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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-generic/errno.h>
  19. #include <linux/compat.h>
  20. #include "ehci.h"
  21. /* Declare global data pointer */
  22. DECLARE_GLOBAL_DATA_PTR;
  23. /**
  24. * Contains pointers to register base addresses
  25. * for the usb controller.
  26. */
  27. struct exynos_ehci {
  28. struct exynos_usb_phy *usb;
  29. struct ehci_hccr *hcd;
  30. };
  31. static struct exynos_ehci exynos;
  32. #ifdef CONFIG_OF_CONTROL
  33. static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
  34. {
  35. fdt_addr_t addr;
  36. unsigned int node;
  37. int depth;
  38. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI);
  39. if (node <= 0) {
  40. debug("EHCI: Can't get device node for ehci\n");
  41. return -ENODEV;
  42. }
  43. /*
  44. * Get the base address for EHCI controller from the device node
  45. */
  46. addr = fdtdec_get_addr(blob, node, "reg");
  47. if (addr == FDT_ADDR_T_NONE) {
  48. debug("Can't get the EHCI register address\n");
  49. return -ENXIO;
  50. }
  51. exynos->hcd = (struct ehci_hccr *)addr;
  52. depth = 0;
  53. node = fdtdec_next_compatible_subnode(blob, node,
  54. COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
  55. if (node <= 0) {
  56. debug("EHCI: Can't get device node for usb-phy controller\n");
  57. return -ENODEV;
  58. }
  59. /*
  60. * Get the base address for usbphy from the device node
  61. */
  62. exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
  63. "reg");
  64. if (exynos->usb == NULL) {
  65. debug("Can't get the usbphy register address\n");
  66. return -ENXIO;
  67. }
  68. return 0;
  69. }
  70. #endif
  71. /* Setup the EHCI host controller. */
  72. static void setup_usb_phy(struct exynos_usb_phy *usb)
  73. {
  74. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  75. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  76. clrbits_le32(&usb->usbphyctrl0,
  77. HOST_CTRL0_FSEL_MASK |
  78. HOST_CTRL0_COMMONON_N |
  79. /* HOST Phy setting */
  80. HOST_CTRL0_PHYSWRST |
  81. HOST_CTRL0_PHYSWRSTALL |
  82. HOST_CTRL0_SIDDQ |
  83. HOST_CTRL0_FORCESUSPEND |
  84. HOST_CTRL0_FORCESLEEP);
  85. setbits_le32(&usb->usbphyctrl0,
  86. /* Setting up the ref freq */
  87. (CLK_24MHZ << 16) |
  88. /* HOST Phy setting */
  89. HOST_CTRL0_LINKSWRST |
  90. HOST_CTRL0_UTMISWRST);
  91. udelay(10);
  92. clrbits_le32(&usb->usbphyctrl0,
  93. HOST_CTRL0_LINKSWRST |
  94. HOST_CTRL0_UTMISWRST);
  95. udelay(20);
  96. /* EHCI Ctrl setting */
  97. setbits_le32(&usb->ehcictrl,
  98. EHCICTRL_ENAINCRXALIGN |
  99. EHCICTRL_ENAINCR4 |
  100. EHCICTRL_ENAINCR8 |
  101. EHCICTRL_ENAINCR16);
  102. }
  103. /* Reset the EHCI host controller. */
  104. static void reset_usb_phy(struct exynos_usb_phy *usb)
  105. {
  106. /* HOST_PHY reset */
  107. setbits_le32(&usb->usbphyctrl0,
  108. HOST_CTRL0_PHYSWRST |
  109. HOST_CTRL0_PHYSWRSTALL |
  110. HOST_CTRL0_SIDDQ |
  111. HOST_CTRL0_FORCESUSPEND |
  112. HOST_CTRL0_FORCESLEEP);
  113. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  114. }
  115. /*
  116. * EHCI-initialization
  117. * Create the appropriate control structures to manage
  118. * a new EHCI host controller.
  119. */
  120. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  121. {
  122. struct exynos_ehci *ctx = &exynos;
  123. #ifdef CONFIG_OF_CONTROL
  124. if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
  125. debug("Unable to parse device tree for ehci-exynos\n");
  126. return -ENODEV;
  127. }
  128. #else
  129. ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
  130. ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
  131. #endif
  132. setup_usb_phy(ctx->usb);
  133. *hccr = ctx->hcd;
  134. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  135. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  136. debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
  137. (uint32_t)*hccr, (uint32_t)*hcor,
  138. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  139. return 0;
  140. }
  141. /*
  142. * Destroy the appropriate control structures corresponding
  143. * the EHCI host controller.
  144. */
  145. int ehci_hcd_stop(int index)
  146. {
  147. struct exynos_ehci *ctx = &exynos;
  148. reset_usb_phy(ctx->usb);
  149. return 0;
  150. }