2 * (C) Copyright 2010, Damien Dusha, <d.dusha@gmail.com>
4 * (C) Copyright 2009, Value Team S.p.A.
5 * Francesco Rendine, <francesco.rendine@valueteam.com>
7 * (C) Copyright 2009 Freescale Semiconductor, Inc.
9 * (C) Copyright 2008, Excito Elektronik i Sk=E5ne AB
11 * Author: Tor Krill tor@excito.com
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.
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.
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,
33 #include <usb/ehci-fsl.h>
36 #include "ehci-core.h"
38 static void fsl_setup_phy(volatile struct ehci_hcor *);
39 static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci);
40 static int reset_usb_controller(volatile struct usb_ehci *ehci);
41 static void usb_platform_dr_init(volatile struct usb_ehci *ehci);
44 * Initialize SOC FSL EHCI Controller
46 * This code is derived from EHCI FSL USB Linux driver for MPC5121
49 int ehci_hcd_init(void)
51 volatile struct usb_ehci *ehci;
53 /* Hook the memory mapped registers for EHCI-Controller */
54 ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
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)));
59 /* configure interface for UTMI_WIDE */
60 usb_platform_dr_init(ehci);
62 /* Init Phy USB0 to UTMI+ */
65 /* Set to host mode */
66 fsl_platform_set_host_mode(ehci);
69 * Setting the burst size seems to be required to prevent the
70 * USB from hanging when communicating with certain USB Mass
71 * storage devices. This was determined by analysing the
72 * EHCI registers under Linux vs U-Boot and burstsize was the
73 * major non-interrupt related difference between the two
76 * Some USB sticks behave better than others. In particular,
77 * the following USB stick is especially problematic:
78 * 0930:6545 Toshiba Corp
80 * The burstsize is set here to match the Linux implementation.
82 out_be32(&ehci->burstsize, FSL_EHCI_TXPBURST(8) |
83 FSL_EHCI_RXPBURST(8));
89 * Destroy the appropriate control structures corresponding
90 * the the EHCI host controller.
92 int ehci_hcd_stop(void)
94 volatile struct usb_ehci *ehci;
102 /* Reset the USB controller */
103 ehci = (struct usb_ehci *)CONFIG_SYS_FSL_USB_ADDR;
104 exit_status = reset_usb_controller(ehci);
110 static int reset_usb_controller(volatile struct usb_ehci *ehci)
114 /* Command a reset of the USB Controller */
115 out_be32(&(ehci->usbcmd), EHCI_FSL_USBCMD_RST);
117 /* Wait for the reset process to finish */
118 for (i = 65535 ; i > 0 ; i--) {
120 * The host will set this bit to zero once the
121 * reset process is complete
123 if ((in_be32(&(ehci->usbcmd)) & EHCI_FSL_USBCMD_RST) == 0)
127 /* Hub did not reset in time */
131 static void fsl_setup_phy(volatile struct ehci_hcor *hcor)
135 portsc = ehci_readl(&hcor->or_portsc[0]);
136 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
138 /* Enable the phy mode to UTMI Wide */
139 portsc |= PORT_PTS_PTW;
140 portsc |= PORT_PTS_UTMI;
142 ehci_writel(&hcor->or_portsc[0], portsc);
145 static void fsl_platform_set_host_mode(volatile struct usb_ehci *ehci)
149 temp = in_le32(&ehci->usbmode);
150 temp |= CM_HOST | ES_BE;
151 out_le32(&ehci->usbmode, temp);
154 static void usb_platform_dr_init(volatile struct usb_ehci *ehci)
156 /* Configure interface for UTMI_WIDE */
157 out_be32(&ehci->isiphyctrl, PHYCTRL_PHYE | PHYCTRL_PXE);
158 out_be32(&ehci->usbgenctrl, GC_PPP | GC_PFP );