ehci-mpc512x.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. static void fsl_setup_phy(volatile struct ehci_hcor *);
  35. static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci);
  36. static int reset_usb_controller(volatile struct usb_ehci *ehci);
  37. static void usb_platform_dr_init(volatile struct usb_ehci *ehci);
  38. /*
  39. * Initialize SOC FSL EHCI Controller
  40. *
  41. * This code is derived from EHCI FSL USB Linux driver for MPC5121
  42. *
  43. */
  44. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  45. {
  46. volatile struct usb_ehci *ehci;
  47. /* Hook the memory mapped registers for EHCI-Controller */
  48. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
  49. *hccr = (struct ehci_hccr *)((uint32_t)&(ehci->caplength));
  50. *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
  51. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  52. /* configure interface for UTMI_WIDE */
  53. usb_platform_dr_init(ehci);
  54. /* Init Phy USB0 to UTMI+ */
  55. fsl_setup_phy(*hcor);
  56. /* Set to host mode */
  57. fsl_platform_set_host_mode(ehci);
  58. /*
  59. * Setting the burst size seems to be required to prevent the
  60. * USB from hanging when communicating with certain USB Mass
  61. * storage devices. This was determined by analysing the
  62. * EHCI registers under Linux vs U-Boot and burstsize was the
  63. * major non-interrupt related difference between the two
  64. * implementations.
  65. *
  66. * Some USB sticks behave better than others. In particular,
  67. * the following USB stick is especially problematic:
  68. * 0930:6545 Toshiba Corp
  69. *
  70. * The burstsize is set here to match the Linux implementation.
  71. */
  72. out_be32(&ehci->burstsize, FSL_EHCI_TXPBURST(8) |
  73. FSL_EHCI_RXPBURST(8));
  74. return 0;
  75. }
  76. /*
  77. * Destroy the appropriate control structures corresponding
  78. * the the EHCI host controller.
  79. */
  80. int ehci_hcd_stop(int index)
  81. {
  82. volatile struct usb_ehci *ehci;
  83. int exit_status = 0;
  84. /* Reset the USB controller */
  85. ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
  86. exit_status = reset_usb_controller(ehci);
  87. return exit_status;
  88. }
  89. static int reset_usb_controller(volatile struct usb_ehci *ehci)
  90. {
  91. unsigned int i;
  92. /* Command a reset of the USB Controller */
  93. out_be32(&(ehci->usbcmd), EHCI_FSL_USBCMD_RST);
  94. /* Wait for the reset process to finish */
  95. for (i = 65535 ; i > 0 ; i--) {
  96. /*
  97. * The host will set this bit to zero once the
  98. * reset process is complete
  99. */
  100. if ((in_be32(&(ehci->usbcmd)) & EHCI_FSL_USBCMD_RST) == 0)
  101. return 0;
  102. }
  103. /* Hub did not reset in time */
  104. return -1;
  105. }
  106. static void fsl_setup_phy(volatile struct ehci_hcor *hcor)
  107. {
  108. uint32_t portsc;
  109. portsc = ehci_readl(&hcor->or_portsc[0]);
  110. portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
  111. /* Enable the phy mode to UTMI Wide */
  112. portsc |= PORT_PTS_PTW;
  113. portsc |= PORT_PTS_UTMI;
  114. ehci_writel(&hcor->or_portsc[0], portsc);
  115. }
  116. static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci)
  117. {
  118. uint32_t temp;
  119. temp = in_le32(&ehci->usbmode);
  120. temp |= CM_HOST | ES_BE;
  121. out_le32(&ehci->usbmode, temp);
  122. }
  123. static void usb_platform_dr_init(volatile struct usb_ehci *ehci)
  124. {
  125. /* Configure interface for UTMI_WIDE */
  126. out_be32(&ehci->isiphyctrl, PHYCTRL_PHYE | PHYCTRL_PXE);
  127. out_be32(&ehci->usbgenctrl, GC_PPP | GC_PFP );
  128. }