2 * (C) Copyright David Brownell 2000-2002
3 * Copyright (c) 2005 MontaVista Software
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * Ported to 834x by Randy Vinson <rvinson@mvista.com> using code provided
23 #include <linux/platform_device.h>
24 #include <linux/fsl_devices.h>
28 /* FIXME: Power Managment is un-ported so temporarily disable it */
31 /* PCI-based HCs are common, but plenty of non-PCI HCs are used too */
33 /* configure so an HC device and id are always provided */
34 /* always called with process context; sleeping is OK */
37 * usb_hcd_fsl_probe - initialize FSL-based HCDs
38 * @drvier: Driver to be used for this HCD
39 * @pdev: USB Host Controller being probed
40 * Context: !in_interrupt()
42 * Allocates basic resources for this USB host controller.
45 int usb_hcd_fsl_probe(const struct hc_driver *driver,
46 struct platform_device *pdev)
48 struct fsl_usb2_platform_data *pdata;
55 pr_debug("initializing FSL-SOC USB Controller\n");
57 /* Need platform data for setup */
58 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
61 "No platform data for %s.\n", pdev->dev.bus_id);
66 * This is a host mode driver, verify that we're supposed to be
69 if (!((pdata->operating_mode == FSL_USB2_DR_HOST) ||
70 (pdata->operating_mode == FSL_USB2_MPH_HOST))) {
72 "Non Host Mode configured for %s. Wrong driver linked.\n",
77 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
80 "Found HC with no IRQ. Check %s setup!\n",
86 hcd = usb_create_hcd(driver, &pdev->dev, pdev->dev.bus_id);
92 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
95 "Found HC with no register addr. Check %s setup!\n",
100 hcd->rsrc_start = res->start;
101 hcd->rsrc_len = res->end - res->start + 1;
102 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
103 driver->description)) {
104 dev_dbg(&pdev->dev, "controller already in use\n");
108 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
110 if (hcd->regs == NULL) {
111 dev_dbg(&pdev->dev, "error mapping memory\n");
116 /* Enable USB controller */
117 temp = in_be32(hcd->regs + 0x500);
118 out_be32(hcd->regs + 0x500, temp | 0x4);
120 /* Set to Host mode */
121 temp = in_le32(hcd->regs + 0x1a8);
122 out_le32(hcd->regs + 0x1a8, temp | 0x3);
124 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
132 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
136 dev_err(&pdev->dev, "init %s fail, %d\n", pdev->dev.bus_id, retval);
140 /* may be called without controller electrically present */
141 /* may be called with controller, bus, and devices active */
144 * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
145 * @dev: USB Host Controller being removed
146 * Context: !in_interrupt()
148 * Reverses the effect of usb_hcd_fsl_probe().
151 void usb_hcd_fsl_remove(struct usb_hcd *hcd, struct platform_device *pdev)
155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
159 static void mpc83xx_setup_phy(struct ehci_hcd *ehci,
160 enum fsl_usb2_phy_modes phy_mode,
161 unsigned int port_offset)
165 case FSL_USB2_PHY_ULPI:
166 portsc |= PORT_PTS_ULPI;
168 case FSL_USB2_PHY_SERIAL:
169 portsc |= PORT_PTS_SERIAL;
171 case FSL_USB2_PHY_UTMI_WIDE:
172 portsc |= PORT_PTS_PTW;
174 case FSL_USB2_PHY_UTMI:
175 portsc |= PORT_PTS_UTMI;
177 case FSL_USB2_PHY_NONE:
180 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
183 static void mpc83xx_usb_setup(struct usb_hcd *hcd)
185 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
186 struct fsl_usb2_platform_data *pdata;
187 void __iomem *non_ehci = hcd->regs;
190 (struct fsl_usb2_platform_data *)hcd->self.controller->
192 /* Enable PHY interface in the control reg. */
193 out_be32(non_ehci + FSL_SOC_USB_CTRL, 0x00000004);
194 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
196 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
198 * Turn on cache snooping hardware, since some PowerPC platforms
199 * wholly rely on hardware to deal with cache coherent
202 /* Setup Snooping for all the 4GB space */
203 /* SNOOP1 starts from 0x0, size 2G */
204 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
205 /* SNOOP2 starts from 0x80000000, size 2G */
206 out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
209 if (pdata->operating_mode == FSL_USB2_DR_HOST)
210 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
212 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
213 unsigned int chip, rev, svr;
215 svr = mfspr(SPRN_SVR);
217 rev = (svr >> 4) & 0xf;
219 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
220 if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
221 ehci->has_fsl_port_bug = 1;
223 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
224 mpc83xx_setup_phy(ehci, pdata->phy_mode, 0);
225 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
226 mpc83xx_setup_phy(ehci, pdata->phy_mode, 1);
229 /* put controller in host mode. */
230 ehci_writel(ehci, 0x00000003, non_ehci + FSL_SOC_USB_USBMODE);
231 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
232 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
233 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
236 /* called after powerup, by probe or system-pm "wakeup" */
237 static int ehci_fsl_reinit(struct ehci_hcd *ehci)
239 mpc83xx_usb_setup(ehci_to_hcd(ehci));
240 ehci_port_power(ehci, 0);
245 /* called during probe() after chip reset completes */
246 static int ehci_fsl_setup(struct usb_hcd *hcd)
248 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
251 /* EHCI registers start at offset 0x100 */
252 ehci->caps = hcd->regs + 0x100;
253 ehci->regs = hcd->regs + 0x100 +
254 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
255 dbg_hcs_params(ehci, "reset");
256 dbg_hcc_params(ehci, "reset");
258 /* cache this readonly data; minimize chip reads */
259 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
261 retval = ehci_halt(ehci);
265 /* data structure init */
266 retval = ehci_init(hcd);
270 ehci->is_tdi_rh_tt = 1;
276 retval = ehci_fsl_reinit(ehci);
280 static const struct hc_driver ehci_fsl_hc_driver = {
281 .description = hcd_name,
282 .product_desc = "Freescale On-Chip EHCI Host Controller",
283 .hcd_priv_size = sizeof(struct ehci_hcd),
286 * generic hardware linkage
292 * basic lifecycle operations
294 .reset = ehci_fsl_setup,
297 .suspend = ehci_bus_suspend,
298 .resume = ehci_bus_resume,
301 .shutdown = ehci_shutdown,
304 * managing i/o requests and associated device resources
306 .urb_enqueue = ehci_urb_enqueue,
307 .urb_dequeue = ehci_urb_dequeue,
308 .endpoint_disable = ehci_endpoint_disable,
313 .get_frame_number = ehci_get_frame,
318 .hub_status_data = ehci_hub_status_data,
319 .hub_control = ehci_hub_control,
320 .bus_suspend = ehci_bus_suspend,
321 .bus_resume = ehci_bus_resume,
324 static int ehci_fsl_drv_probe(struct platform_device *pdev)
329 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
332 static int ehci_fsl_drv_remove(struct platform_device *pdev)
334 struct usb_hcd *hcd = platform_get_drvdata(pdev);
336 usb_hcd_fsl_remove(hcd, pdev);
341 MODULE_ALIAS("fsl-ehci");
343 static struct platform_driver ehci_fsl_driver = {
344 .probe = ehci_fsl_drv_probe,
345 .remove = ehci_fsl_drv_remove,
346 .shutdown = usb_hcd_platform_shutdown,