ehci-exynos.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  20. * MA 02110-1301 USA
  21. */
  22. #include <common.h>
  23. #include <fdtdec.h>
  24. #include <libfdt.h>
  25. #include <malloc.h>
  26. #include <usb.h>
  27. #include <asm/arch/cpu.h>
  28. #include <asm/arch/ehci.h>
  29. #include <asm/arch/system.h>
  30. #include <asm/arch/power.h>
  31. #include <asm-generic/errno.h>
  32. #include <linux/compat.h>
  33. #include "ehci.h"
  34. /* Declare global data pointer */
  35. DECLARE_GLOBAL_DATA_PTR;
  36. /**
  37. * Contains pointers to register base addresses
  38. * for the usb controller.
  39. */
  40. struct exynos_ehci {
  41. struct exynos_usb_phy *usb;
  42. struct ehci_hccr *hcd;
  43. };
  44. static struct exynos_ehci exynos;
  45. #ifdef CONFIG_OF_CONTROL
  46. static int exynos_usb_parse_dt(const void *blob, struct exynos_ehci *exynos)
  47. {
  48. fdt_addr_t addr;
  49. unsigned int node;
  50. int depth;
  51. node = fdtdec_next_compatible(blob, 0, COMPAT_SAMSUNG_EXYNOS_EHCI);
  52. if (node <= 0) {
  53. debug("EHCI: Can't get device node for ehci\n");
  54. return -ENODEV;
  55. }
  56. /*
  57. * Get the base address for EHCI controller from the device node
  58. */
  59. addr = fdtdec_get_addr(blob, node, "reg");
  60. if (addr == FDT_ADDR_T_NONE) {
  61. debug("Can't get the EHCI register address\n");
  62. return -ENXIO;
  63. }
  64. exynos->hcd = (struct ehci_hccr *)addr;
  65. depth = 0;
  66. node = fdtdec_next_compatible_subnode(blob, node,
  67. COMPAT_SAMSUNG_EXYNOS_USB_PHY, &depth);
  68. if (node <= 0) {
  69. debug("EHCI: Can't get device node for usb-phy controller\n");
  70. return -ENODEV;
  71. }
  72. /*
  73. * Get the base address for usbphy from the device node
  74. */
  75. exynos->usb = (struct exynos_usb_phy *)fdtdec_get_addr(blob, node,
  76. "reg");
  77. if (exynos->usb == NULL) {
  78. debug("Can't get the usbphy register address\n");
  79. return -ENXIO;
  80. }
  81. return 0;
  82. }
  83. #endif
  84. /* Setup the EHCI host controller. */
  85. static void setup_usb_phy(struct exynos_usb_phy *usb)
  86. {
  87. set_usbhost_mode(USB20_PHY_CFG_HOST_LINK_EN);
  88. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_EN);
  89. clrbits_le32(&usb->usbphyctrl0,
  90. HOST_CTRL0_FSEL_MASK |
  91. HOST_CTRL0_COMMONON_N |
  92. /* HOST Phy setting */
  93. HOST_CTRL0_PHYSWRST |
  94. HOST_CTRL0_PHYSWRSTALL |
  95. HOST_CTRL0_SIDDQ |
  96. HOST_CTRL0_FORCESUSPEND |
  97. HOST_CTRL0_FORCESLEEP);
  98. setbits_le32(&usb->usbphyctrl0,
  99. /* Setting up the ref freq */
  100. (CLK_24MHZ << 16) |
  101. /* HOST Phy setting */
  102. HOST_CTRL0_LINKSWRST |
  103. HOST_CTRL0_UTMISWRST);
  104. udelay(10);
  105. clrbits_le32(&usb->usbphyctrl0,
  106. HOST_CTRL0_LINKSWRST |
  107. HOST_CTRL0_UTMISWRST);
  108. udelay(20);
  109. /* EHCI Ctrl setting */
  110. setbits_le32(&usb->ehcictrl,
  111. EHCICTRL_ENAINCRXALIGN |
  112. EHCICTRL_ENAINCR4 |
  113. EHCICTRL_ENAINCR8 |
  114. EHCICTRL_ENAINCR16);
  115. }
  116. /* Reset the EHCI host controller. */
  117. static void reset_usb_phy(struct exynos_usb_phy *usb)
  118. {
  119. /* HOST_PHY reset */
  120. setbits_le32(&usb->usbphyctrl0,
  121. HOST_CTRL0_PHYSWRST |
  122. HOST_CTRL0_PHYSWRSTALL |
  123. HOST_CTRL0_SIDDQ |
  124. HOST_CTRL0_FORCESUSPEND |
  125. HOST_CTRL0_FORCESLEEP);
  126. set_usbhost_phy_ctrl(POWER_USB_HOST_PHY_CTRL_DISABLE);
  127. }
  128. /*
  129. * EHCI-initialization
  130. * Create the appropriate control structures to manage
  131. * a new EHCI host controller.
  132. */
  133. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  134. {
  135. struct exynos_ehci *ctx = &exynos;
  136. #ifdef CONFIG_OF_CONTROL
  137. if (exynos_usb_parse_dt(gd->fdt_blob, ctx)) {
  138. debug("Unable to parse device tree for ehci-exynos\n");
  139. return -ENODEV;
  140. }
  141. #else
  142. ctx->usb = (struct exynos_usb_phy *)samsung_get_base_usb_phy();
  143. ctx->hcd = (struct ehci_hccr *)samsung_get_base_usb_ehci();
  144. #endif
  145. setup_usb_phy(ctx->usb);
  146. *hccr = ctx->hcd;
  147. *hcor = (struct ehci_hcor *)((uint32_t) *hccr
  148. + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  149. debug("Exynos5-ehci: init hccr %x and hcor %x hc_length %d\n",
  150. (uint32_t)*hccr, (uint32_t)*hcor,
  151. (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  152. return 0;
  153. }
  154. /*
  155. * Destroy the appropriate control structures corresponding
  156. * the EHCI host controller.
  157. */
  158. int ehci_hcd_stop(int index)
  159. {
  160. struct exynos_ehci *ctx = &exynos;
  161. reset_usb_phy(ctx->usb);
  162. return 0;
  163. }