ehci-mpc512x.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * (C) Copyright 2010, Damien Dusha, <d.dusha@gmail.com>
  3. *
  4. * (C) Copyright 2009, Value Team S.p.A.
  5. * Francesco Rendine, <francesco.rendine@valueteam.com>
  6. *
  7. * (C) Copyright 2009 Freescale Semiconductor, Inc.
  8. *
  9. * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
  10. *
  11. * Author: Tor Krill tor@excito.com
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License as
  15. * published by the Free Software Foundation; either version 2 of
  16. * the License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  26. * MA 02111-1307 USA
  27. */
  28. #include <common.h>
  29. #include <pci.h>
  30. #include <usb.h>
  31. #include <asm/io.h>
  32. #include <usb/ehci-fsl.h>
  33. #include "ehci.h"
  34. #include "ehci-core.h"
  35. static void fsl_setup_phy(volatile struct ehci_hcor *);
  36. static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci);
  37. static int reset_usb_controller(volatile struct usb_ehci *ehci);
  38. static void usb_platform_dr_init(volatile struct usb_ehci *ehci);
  39. /*
  40. * Initialize SOC FSL EHCI Controller
  41. *
  42. * This code is derived from EHCI FSL USB Linux driver for MPC5121
  43. *
  44. */
  45. int ehci_hcd_init(void)
  46. {
  47. volatile struct usb_ehci *ehci;
  48. /* Hook the memory mapped registers for EHCI-Controller */
  49. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
  50. hccr = (struct ehci_hccr *)((uint32_t)&(ehci->caplength));
  51. hcor = (struct ehci_hcor *)((uint32_t) hccr +
  52. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  53. /* configure interface for UTMI_WIDE */
  54. usb_platform_dr_init(ehci);
  55. /* Init Phy USB0 to UTMI+ */
  56. fsl_setup_phy(hcor);
  57. /* Set to host mode */
  58. fsl_platform_set_host_mode(ehci);
  59. /*
  60. * Setting the burst size seems to be required to prevent the
  61. * USB from hanging when communicating with certain USB Mass
  62. * storage devices. This was determined by analysing the
  63. * EHCI registers under Linux vs U-Boot and burstsize was the
  64. * major non-interrupt related difference between the two
  65. * implementations.
  66. *
  67. * Some USB sticks behave better than others. In particular,
  68. * the following USB stick is especially problematic:
  69. * 0930:6545 Toshiba Corp
  70. *
  71. * The burstsize is set here to match the Linux implementation.
  72. */
  73. out_be32(&ehci->burstsize, FSL_EHCI_TXPBURST(8) |
  74. FSL_EHCI_RXPBURST(8));
  75. return 0;
  76. }
  77. /*
  78. * Destroy the appropriate control structures corresponding
  79. * the the EHCI host controller.
  80. */
  81. int ehci_hcd_stop(void)
  82. {
  83. volatile struct usb_ehci *ehci;
  84. int exit_status = 0;
  85. if (hcor) {
  86. /* Unhook struct */
  87. hccr = NULL;
  88. hcor = NULL;
  89. /* Reset the USB controller */
  90. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
  91. exit_status = reset_usb_controller(ehci);
  92. }
  93. return exit_status;
  94. }
  95. static int reset_usb_controller(volatile struct usb_ehci *ehci)
  96. {
  97. unsigned int i;
  98. /* Command a reset of the USB Controller */
  99. out_be32(&(ehci->usbcmd), EHCI_FSL_USBCMD_RST);
  100. /* Wait for the reset process to finish */
  101. for (i = 65535 ; i > 0 ; i--) {
  102. /*
  103. * The host will set this bit to zero once the
  104. * reset process is complete
  105. */
  106. if ((in_be32(&(ehci->usbcmd)) & EHCI_FSL_USBCMD_RST) == 0)
  107. return 0;
  108. }
  109. /* Hub did not reset in time */
  110. return -1;
  111. }
  112. static void fsl_setup_phy(volatile struct ehci_hcor *hcor)
  113. {
  114. uint32_t portsc;
  115. portsc = ehci_readl(&hcor->or_portsc[0]);
  116. portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
  117. /* Enable the phy mode to UTMI Wide */
  118. portsc |= PORT_PTS_PTW;
  119. portsc |= PORT_PTS_UTMI;
  120. ehci_writel(&hcor->or_portsc[0], portsc);
  121. }
  122. static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci)
  123. {
  124. uint32_t temp;
  125. temp = in_le32(&ehci->usbmode);
  126. temp |= CM_HOST | ES_BE;
  127. out_le32(&ehci->usbmode, temp);
  128. }
  129. static void usb_platform_dr_init(volatile struct usb_ehci *ehci)
  130. {
  131. /* Configure interface for UTMI_WIDE */
  132. out_be32(&ehci->isiphyctrl, PHYCTRL_PHYE | PHYCTRL_PXE);
  133. out_be32(&ehci->usbgenctrl, GC_PPP | GC_PFP );
  134. }