ehci-fsl.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * (C) Copyright 2009, 2011 Freescale Semiconductor, Inc.
  3. *
  4. * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
  5. *
  6. * Author: Tor Krill tor@excito.com
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <pci.h>
  12. #include <usb.h>
  13. #include <asm/io.h>
  14. #include <usb/ehci-fsl.h>
  15. #include <hwconfig.h>
  16. #include <asm/fsl_errata.h>
  17. #include "ehci.h"
  18. static void set_txfifothresh(struct usb_ehci *, u32);
  19. /* Check USB PHY clock valid */
  20. static int usb_phy_clk_valid(struct usb_ehci *ehci)
  21. {
  22. if (!((in_be32(&ehci->control) & PHY_CLK_VALID) ||
  23. in_be32(&ehci->prictrl))) {
  24. printf("USB PHY clock invalid!\n");
  25. return 0;
  26. } else {
  27. return 1;
  28. }
  29. }
  30. /*
  31. * Create the appropriate control structures to manage
  32. * a new EHCI host controller.
  33. *
  34. * Excerpts from linux ehci fsl driver.
  35. */
  36. int ehci_hcd_init(int index, enum usb_init_type init,
  37. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  38. {
  39. struct usb_ehci *ehci = NULL;
  40. const char *phy_type = NULL;
  41. size_t len;
  42. char current_usb_controller[5];
  43. #ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
  44. char usb_phy[5];
  45. usb_phy[0] = '\0';
  46. #endif
  47. if (has_erratum_a007075()) {
  48. /*
  49. * A 5ms delay is needed after applying soft-reset to the
  50. * controller to let external ULPI phy come out of reset.
  51. * This delay needs to be added before re-initializing
  52. * the controller after soft-resetting completes
  53. */
  54. mdelay(5);
  55. }
  56. memset(current_usb_controller, '\0', 5);
  57. snprintf(current_usb_controller, 4, "usb%d", index+1);
  58. switch (index) {
  59. case 0:
  60. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB1_ADDR;
  61. break;
  62. case 1:
  63. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB2_ADDR;
  64. break;
  65. default:
  66. printf("ERROR: wrong controller index!!\n");
  67. break;
  68. };
  69. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  70. *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
  71. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  72. /* Set to Host mode */
  73. setbits_le32(&ehci->usbmode, CM_HOST);
  74. out_be32(&ehci->snoop1, SNOOP_SIZE_2GB);
  75. out_be32(&ehci->snoop2, 0x80000000 | SNOOP_SIZE_2GB);
  76. /* Init phy */
  77. if (hwconfig_sub(current_usb_controller, "phy_type"))
  78. phy_type = hwconfig_subarg(current_usb_controller,
  79. "phy_type", &len);
  80. else
  81. phy_type = getenv("usb_phy_type");
  82. if (!phy_type) {
  83. #ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
  84. /* if none specified assume internal UTMI */
  85. strcpy(usb_phy, "utmi");
  86. phy_type = usb_phy;
  87. #else
  88. printf("WARNING: USB phy type not defined !!\n");
  89. return -1;
  90. #endif
  91. }
  92. if (!strncmp(phy_type, "utmi", 4)) {
  93. #if defined(CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY)
  94. clrsetbits_be32(&ehci->control, CONTROL_REGISTER_W1C_MASK,
  95. PHY_CLK_SEL_UTMI);
  96. clrsetbits_be32(&ehci->control, CONTROL_REGISTER_W1C_MASK,
  97. UTMI_PHY_EN);
  98. udelay(1000); /* delay required for PHY Clk to appear */
  99. #endif
  100. out_le32(&(*hcor)->or_portsc[0], PORT_PTS_UTMI);
  101. clrsetbits_be32(&ehci->control, CONTROL_REGISTER_W1C_MASK,
  102. USB_EN);
  103. } else {
  104. clrsetbits_be32(&ehci->control, CONTROL_REGISTER_W1C_MASK,
  105. PHY_CLK_SEL_ULPI);
  106. clrsetbits_be32(&ehci->control, UTMI_PHY_EN |
  107. CONTROL_REGISTER_W1C_MASK, USB_EN);
  108. udelay(1000); /* delay required for PHY Clk to appear */
  109. if (!usb_phy_clk_valid(ehci))
  110. return -EINVAL;
  111. out_le32(&(*hcor)->or_portsc[0], PORT_PTS_ULPI);
  112. }
  113. out_be32(&ehci->prictrl, 0x0000000c);
  114. out_be32(&ehci->age_cnt_limit, 0x00000040);
  115. out_be32(&ehci->sictrl, 0x00000001);
  116. in_le32(&ehci->usbmode);
  117. if (SVR_SOC_VER(get_svr()) == SVR_T4240 &&
  118. IS_SVR_REV(get_svr(), 2, 0))
  119. set_txfifothresh(ehci, TXFIFOTHRESH);
  120. return 0;
  121. }
  122. /*
  123. * Destroy the appropriate control structures corresponding
  124. * the the EHCI host controller.
  125. */
  126. int ehci_hcd_stop(int index)
  127. {
  128. return 0;
  129. }
  130. /*
  131. * Setting the value of TXFIFO_THRESH field in TXFILLTUNING register
  132. * to counter DDR latencies in writing data into Tx buffer.
  133. * This prevents Tx buffer from getting underrun
  134. */
  135. static void set_txfifothresh(struct usb_ehci *ehci, u32 txfifo_thresh)
  136. {
  137. u32 cmd;
  138. cmd = ehci_readl(&ehci->txfilltuning);
  139. cmd &= ~TXFIFO_THRESH_MASK;
  140. cmd |= TXFIFO_THRESH(txfifo_thresh);
  141. ehci_writel(&ehci->txfilltuning, cmd);
  142. }