2 * Copyright 2005-2009 MontaVista Software, Inc.
3 * Copyright 2008 Freescale Semiconductor, Inc.
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.
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/delay.h>
30 #include <linux/platform_device.h>
31 #include <linux/fsl_devices.h>
35 /* configure so an HC device and id are always provided */
36 /* always called with process context; sleeping is OK */
39 * usb_hcd_fsl_probe - initialize FSL-based HCDs
40 * @drvier: Driver to be used for this HCD
41 * @pdev: USB Host Controller being probed
42 * Context: !in_interrupt()
44 * Allocates basic resources for this USB host controller.
47 static int usb_hcd_fsl_probe(const struct hc_driver *driver,
48 struct platform_device *pdev)
50 struct fsl_usb2_platform_data *pdata;
57 pr_debug("initializing FSL-SOC USB Controller\n");
59 /* Need platform data for setup */
60 pdata = (struct fsl_usb2_platform_data *)pdev->dev.platform_data;
63 "No platform data for %s.\n", dev_name(&pdev->dev));
68 * This is a host mode driver, verify that we're supposed to be
71 if (!((pdata->operating_mode == FSL_USB2_DR_HOST) ||
72 (pdata->operating_mode == FSL_USB2_MPH_HOST) ||
73 (pdata->operating_mode == FSL_USB2_DR_OTG))) {
75 "Non Host Mode configured for %s. Wrong driver linked.\n",
76 dev_name(&pdev->dev));
80 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
83 "Found HC with no IRQ. Check %s setup!\n",
84 dev_name(&pdev->dev));
89 hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
95 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98 "Found HC with no register addr. Check %s setup!\n",
99 dev_name(&pdev->dev));
103 hcd->rsrc_start = res->start;
104 hcd->rsrc_len = res->end - res->start + 1;
105 if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len,
106 driver->description)) {
107 dev_dbg(&pdev->dev, "controller already in use\n");
111 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
113 if (hcd->regs == NULL) {
114 dev_dbg(&pdev->dev, "error mapping memory\n");
119 pdata->regs = hcd->regs;
122 * do platform specific init: check the clock, grab/config pins, etc.
124 if (pdata->init && pdata->init(pdev)) {
130 * Check if it is MPC5121 SoC, otherwise set pdata->have_sysif_regs
131 * flag for 83xx or 8536 system interface registers.
133 if (pdata->big_endian_mmio)
134 temp = in_be32(hcd->regs + FSL_SOC_USB_ID);
136 temp = in_le32(hcd->regs + FSL_SOC_USB_ID);
138 if ((temp & ID_MSK) != (~((temp & NID_MSK) >> 8) & ID_MSK))
139 pdata->have_sysif_regs = 1;
141 /* Enable USB controller, 83xx or 8536 */
142 if (pdata->have_sysif_regs)
143 setbits32(hcd->regs + FSL_SOC_USB_CTRL, 0x4);
145 /* Don't need to set host mode here. It will be done by tdi_reset() */
147 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
159 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
165 /* may be called without controller electrically present */
166 /* may be called with controller, bus, and devices active */
169 * usb_hcd_fsl_remove - shutdown processing for FSL-based HCDs
170 * @dev: USB Host Controller being removed
171 * Context: !in_interrupt()
173 * Reverses the effect of usb_hcd_fsl_probe().
176 static void usb_hcd_fsl_remove(struct usb_hcd *hcd,
177 struct platform_device *pdev)
179 struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
184 * do platform specific un-initialization:
185 * release iomux pins, disable clock, etc.
190 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
194 static void ehci_fsl_setup_phy(struct ehci_hcd *ehci,
195 enum fsl_usb2_phy_modes phy_mode,
196 unsigned int port_offset)
200 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]);
201 portsc &= ~(PORT_PTS_MSK | PORT_PTS_PTW);
204 case FSL_USB2_PHY_ULPI:
205 portsc |= PORT_PTS_ULPI;
207 case FSL_USB2_PHY_SERIAL:
208 portsc |= PORT_PTS_SERIAL;
210 case FSL_USB2_PHY_UTMI_WIDE:
211 portsc |= PORT_PTS_PTW;
213 case FSL_USB2_PHY_UTMI:
214 portsc |= PORT_PTS_UTMI;
216 case FSL_USB2_PHY_NONE:
219 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]);
222 static void ehci_fsl_usb_setup(struct ehci_hcd *ehci)
224 struct usb_hcd *hcd = ehci_to_hcd(ehci);
225 struct fsl_usb2_platform_data *pdata;
226 void __iomem *non_ehci = hcd->regs;
229 pdata = hcd->self.controller->platform_data;
231 /* Enable PHY interface in the control reg. */
232 if (pdata->have_sysif_regs) {
233 temp = in_be32(non_ehci + FSL_SOC_USB_CTRL);
234 out_be32(non_ehci + FSL_SOC_USB_CTRL, temp | 0x00000004);
235 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0000001b);
238 #if defined(CONFIG_PPC32) && !defined(CONFIG_NOT_COHERENT_CACHE)
240 * Turn on cache snooping hardware, since some PowerPC platforms
241 * wholly rely on hardware to deal with cache coherent
244 /* Setup Snooping for all the 4GB space */
245 /* SNOOP1 starts from 0x0, size 2G */
246 out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
247 /* SNOOP2 starts from 0x80000000, size 2G */
248 out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
251 if ((pdata->operating_mode == FSL_USB2_DR_HOST) ||
252 (pdata->operating_mode == FSL_USB2_DR_OTG))
253 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0);
255 if (pdata->operating_mode == FSL_USB2_MPH_HOST) {
256 unsigned int chip, rev, svr;
258 svr = mfspr(SPRN_SVR);
260 rev = (svr >> 4) & 0xf;
262 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */
263 if ((rev == 1) && (chip >= 0x8050) && (chip <= 0x8055))
264 ehci->has_fsl_port_bug = 1;
266 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED)
267 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 0);
268 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED)
269 ehci_fsl_setup_phy(ehci, pdata->phy_mode, 1);
272 if (pdata->have_sysif_regs) {
273 #ifdef CONFIG_PPC_85xx
274 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
275 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
277 out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
278 out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
280 out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
284 /* called after powerup, by probe or system-pm "wakeup" */
285 static int ehci_fsl_reinit(struct ehci_hcd *ehci)
287 ehci_fsl_usb_setup(ehci);
288 ehci_port_power(ehci, 0);
293 /* called during probe() after chip reset completes */
294 static int ehci_fsl_setup(struct usb_hcd *hcd)
296 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
298 struct fsl_usb2_platform_data *pdata;
300 pdata = hcd->self.controller->platform_data;
301 ehci->big_endian_desc = pdata->big_endian_desc;
302 ehci->big_endian_mmio = pdata->big_endian_mmio;
304 /* EHCI registers start at offset 0x100 */
305 ehci->caps = hcd->regs + 0x100;
306 ehci->regs = hcd->regs + 0x100 +
307 HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase));
308 dbg_hcs_params(ehci, "reset");
309 dbg_hcc_params(ehci, "reset");
311 /* cache this readonly data; minimize chip reads */
312 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
316 retval = ehci_halt(ehci);
320 /* data structure init */
321 retval = ehci_init(hcd);
329 retval = ehci_fsl_reinit(ehci);
334 struct ehci_hcd ehci;
337 /* Saved USB PHY settings, need to restore after deep sleep. */
344 static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
346 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
348 return container_of(ehci, struct ehci_fsl, ehci);
351 static int ehci_fsl_drv_suspend(struct device *dev)
353 struct usb_hcd *hcd = dev_get_drvdata(dev);
354 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
355 void __iomem *non_ehci = hcd->regs;
357 ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
358 device_may_wakeup(dev));
359 if (!fsl_deep_sleep())
362 ehci_fsl->usb_ctrl = in_be32(non_ehci + FSL_SOC_USB_CTRL);
366 static int ehci_fsl_drv_resume(struct device *dev)
368 struct usb_hcd *hcd = dev_get_drvdata(dev);
369 struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
370 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
371 void __iomem *non_ehci = hcd->regs;
373 ehci_prepare_ports_for_controller_resume(ehci);
374 if (!fsl_deep_sleep())
377 usb_root_hub_lost_power(hcd->self.root_hub);
379 /* Restore USB PHY settings and enable the controller. */
380 out_be32(non_ehci + FSL_SOC_USB_CTRL, ehci_fsl->usb_ctrl);
383 ehci_fsl_reinit(ehci);
388 static int ehci_fsl_drv_restore(struct device *dev)
390 struct usb_hcd *hcd = dev_get_drvdata(dev);
392 usb_root_hub_lost_power(hcd->self.root_hub);
396 static struct dev_pm_ops ehci_fsl_pm_ops = {
397 .suspend = ehci_fsl_drv_suspend,
398 .resume = ehci_fsl_drv_resume,
399 .restore = ehci_fsl_drv_restore,
402 #define EHCI_FSL_PM_OPS (&ehci_fsl_pm_ops)
404 #define EHCI_FSL_PM_OPS NULL
405 #endif /* CONFIG_PM */
407 static const struct hc_driver ehci_fsl_hc_driver = {
408 .description = hcd_name,
409 .product_desc = "Freescale On-Chip EHCI Host Controller",
410 .hcd_priv_size = sizeof(struct ehci_fsl),
413 * generic hardware linkage
416 .flags = HCD_USB2 | HCD_MEMORY,
419 * basic lifecycle operations
421 .reset = ehci_fsl_setup,
424 .shutdown = ehci_shutdown,
427 * managing i/o requests and associated device resources
429 .urb_enqueue = ehci_urb_enqueue,
430 .urb_dequeue = ehci_urb_dequeue,
431 .endpoint_disable = ehci_endpoint_disable,
432 .endpoint_reset = ehci_endpoint_reset,
437 .get_frame_number = ehci_get_frame,
442 .hub_status_data = ehci_hub_status_data,
443 .hub_control = ehci_hub_control,
444 .bus_suspend = ehci_bus_suspend,
445 .bus_resume = ehci_bus_resume,
446 .relinquish_port = ehci_relinquish_port,
447 .port_handed_over = ehci_port_handed_over,
449 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
452 static int ehci_fsl_drv_probe(struct platform_device *pdev)
457 /* FIXME we only want one one probe() not two */
458 return usb_hcd_fsl_probe(&ehci_fsl_hc_driver, pdev);
461 static int ehci_fsl_drv_remove(struct platform_device *pdev)
463 struct usb_hcd *hcd = platform_get_drvdata(pdev);
465 /* FIXME we only want one one remove() not two */
466 usb_hcd_fsl_remove(hcd, pdev);
470 MODULE_ALIAS("platform:fsl-ehci");
472 static struct platform_driver ehci_fsl_driver = {
473 .probe = ehci_fsl_drv_probe,
474 .remove = ehci_fsl_drv_remove,
475 .shutdown = usb_hcd_platform_shutdown,
478 .pm = EHCI_FSL_PM_OPS,