ehci-fsl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 "ehci.h"
  17. /* Check USB PHY clock valid */
  18. static int usb_phy_clk_valid(struct usb_ehci *ehci)
  19. {
  20. if (!((in_be32(&ehci->control) & PHY_CLK_VALID) ||
  21. in_be32(&ehci->prictrl))) {
  22. printf("USB PHY clock invalid!\n");
  23. return 0;
  24. } else {
  25. return 1;
  26. }
  27. }
  28. /*
  29. * Create the appropriate control structures to manage
  30. * a new EHCI host controller.
  31. *
  32. * Excerpts from linux ehci fsl driver.
  33. */
  34. int ehci_hcd_init(int index, enum usb_init_type init,
  35. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  36. {
  37. struct usb_ehci *ehci = NULL;
  38. const char *phy_type = NULL;
  39. size_t len;
  40. #ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
  41. char usb_phy[5];
  42. usb_phy[0] = '\0';
  43. #endif
  44. switch (index) {
  45. case 0:
  46. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB1_ADDR;
  47. break;
  48. case 1:
  49. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB2_ADDR;
  50. break;
  51. default:
  52. printf("ERROR: wrong controller index!!\n");
  53. break;
  54. };
  55. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  56. *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
  57. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  58. /* Set to Host mode */
  59. setbits_le32(&ehci->usbmode, CM_HOST);
  60. out_be32(&ehci->snoop1, SNOOP_SIZE_2GB);
  61. out_be32(&ehci->snoop2, 0x80000000 | SNOOP_SIZE_2GB);
  62. /* Init phy */
  63. if (hwconfig_sub("usb1", "phy_type"))
  64. phy_type = hwconfig_subarg("usb1", "phy_type", &len);
  65. else
  66. phy_type = getenv("usb_phy_type");
  67. if (!phy_type) {
  68. #ifdef CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY
  69. /* if none specified assume internal UTMI */
  70. strcpy(usb_phy, "utmi");
  71. phy_type = usb_phy;
  72. #else
  73. printf("WARNING: USB phy type not defined !!\n");
  74. return -1;
  75. #endif
  76. }
  77. if (!strncmp(phy_type, "utmi", 4)) {
  78. #if defined(CONFIG_SYS_FSL_USB_INTERNAL_UTMI_PHY)
  79. setbits_be32(&ehci->control, PHY_CLK_SEL_UTMI);
  80. setbits_be32(&ehci->control, UTMI_PHY_EN);
  81. udelay(1000); /* delay required for PHY Clk to appear */
  82. #endif
  83. out_le32(&(*hcor)->or_portsc[0], PORT_PTS_UTMI);
  84. setbits_be32(&ehci->control, USB_EN);
  85. } else {
  86. setbits_be32(&ehci->control, PHY_CLK_SEL_ULPI);
  87. clrsetbits_be32(&ehci->control, UTMI_PHY_EN, USB_EN);
  88. udelay(1000); /* delay required for PHY Clk to appear */
  89. if (!usb_phy_clk_valid(ehci))
  90. return -EINVAL;
  91. out_le32(&(*hcor)->or_portsc[0], PORT_PTS_ULPI);
  92. }
  93. out_be32(&ehci->prictrl, 0x0000000c);
  94. out_be32(&ehci->age_cnt_limit, 0x00000040);
  95. out_be32(&ehci->sictrl, 0x00000001);
  96. in_le32(&ehci->usbmode);
  97. return 0;
  98. }
  99. /*
  100. * Destroy the appropriate control structures corresponding
  101. * the the EHCI host controller.
  102. */
  103. int ehci_hcd_stop(int index)
  104. {
  105. return 0;
  106. }