Lines Matching +full:usb +full:- +full:ehci
1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2005-2009 MontaVista Software, Inc.
9 * Jerry Huang <Chang-Ming.Huang@freescale.com> and
19 #include <linux/usb.h>
20 #include <linux/usb/ehci_def.h>
21 #include <linux/usb/hcd.h>
22 #include <linux/usb/otg.h>
28 #include "ehci.h"
29 #include "ehci-fsl.h"
31 #define DRIVER_DESC "Freescale EHCI Host controller driver"
32 #define DRV_NAME "fsl-ehci"
40 * fsl_ehci_drv_probe - initialize FSL-based HCDs
41 * @pdev: USB Host Controller being probed
45 * Allocates basic resources for this USB host controller.
56 pr_debug("initializing FSL-SOC USB Controller\n"); in fsl_ehci_drv_probe()
59 pdata = dev_get_platdata(&pdev->dev); in fsl_ehci_drv_probe()
61 dev_err(&pdev->dev, in fsl_ehci_drv_probe()
62 "No platform data for %s.\n", dev_name(&pdev->dev)); in fsl_ehci_drv_probe()
63 return -ENODEV; in fsl_ehci_drv_probe()
70 if (!((pdata->operating_mode == FSL_USB2_DR_HOST) || in fsl_ehci_drv_probe()
71 (pdata->operating_mode == FSL_USB2_MPH_HOST) || in fsl_ehci_drv_probe()
72 (pdata->operating_mode == FSL_USB2_DR_OTG))) { in fsl_ehci_drv_probe()
73 dev_err(&pdev->dev, in fsl_ehci_drv_probe()
75 dev_name(&pdev->dev)); in fsl_ehci_drv_probe()
76 return -ENODEV; in fsl_ehci_drv_probe()
83 hcd = __usb_create_hcd(&fsl_ehci_hc_driver, pdev->dev.parent, in fsl_ehci_drv_probe()
84 &pdev->dev, dev_name(&pdev->dev), NULL); in fsl_ehci_drv_probe()
86 retval = -ENOMEM; in fsl_ehci_drv_probe()
90 hcd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in fsl_ehci_drv_probe()
91 if (IS_ERR(hcd->regs)) { in fsl_ehci_drv_probe()
92 retval = PTR_ERR(hcd->regs); in fsl_ehci_drv_probe()
96 hcd->rsrc_start = res->start; in fsl_ehci_drv_probe()
97 hcd->rsrc_len = resource_size(res); in fsl_ehci_drv_probe()
99 pdata->regs = hcd->regs; in fsl_ehci_drv_probe()
101 if (pdata->power_budget) in fsl_ehci_drv_probe()
102 hcd->power_budget = pdata->power_budget; in fsl_ehci_drv_probe()
107 if (pdata->init && pdata->init(pdev)) { in fsl_ehci_drv_probe()
108 retval = -ENODEV; in fsl_ehci_drv_probe()
112 /* Enable USB controller, 83xx or 8536 */ in fsl_ehci_drv_probe()
113 if (pdata->have_sysif_regs && pdata->controller_ver < FSL_USB_VER_1_6) { in fsl_ehci_drv_probe()
114 tmp = ioread32be(hcd->regs + FSL_SOC_USB_CTRL); in fsl_ehci_drv_probe()
117 iowrite32be(tmp, hcd->regs + FSL_SOC_USB_CTRL); in fsl_ehci_drv_probe()
120 /* Set USB_EN bit to select ULPI phy for USB controller version 2.5 */ in fsl_ehci_drv_probe()
121 if (pdata->controller_ver == FSL_USB_VER_2_5 && in fsl_ehci_drv_probe()
122 pdata->phy_mode == FSL_USB2_PHY_ULPI) in fsl_ehci_drv_probe()
123 iowrite32be(USB_CTRL_USB_EN, hcd->regs + FSL_SOC_USB_CTRL); in fsl_ehci_drv_probe()
127 * controller reset for USB Controller version 2.5 in fsl_ehci_drv_probe()
129 if (pdata->has_fsl_erratum_a007792) { in fsl_ehci_drv_probe()
130 tmp = ioread32be(hcd->regs + FSL_SOC_USB_CTRL); in fsl_ehci_drv_probe()
133 iowrite32be(tmp, hcd->regs + FSL_SOC_USB_CTRL); in fsl_ehci_drv_probe()
135 writel(PORT_PTS_UTMI, hcd->regs + FSL_SOC_USB_PORTSC1); in fsl_ehci_drv_probe()
143 device_wakeup_enable(hcd->self.controller); in fsl_ehci_drv_probe()
146 if (pdata->operating_mode == FSL_USB2_DR_OTG) { in fsl_ehci_drv_probe()
147 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in fsl_ehci_drv_probe() local
149 hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2); in fsl_ehci_drv_probe()
150 dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n", in fsl_ehci_drv_probe()
151 hcd, ehci, hcd->usb_phy); in fsl_ehci_drv_probe()
153 if (!IS_ERR_OR_NULL(hcd->usb_phy)) { in fsl_ehci_drv_probe()
154 retval = otg_set_host(hcd->usb_phy->otg, in fsl_ehci_drv_probe()
155 &ehci_to_hcd(ehci)->self); in fsl_ehci_drv_probe()
157 usb_put_phy(hcd->usb_phy); in fsl_ehci_drv_probe()
161 dev_err(&pdev->dev, "can't find phy\n"); in fsl_ehci_drv_probe()
162 retval = -ENODEV; in fsl_ehci_drv_probe()
166 hcd->skip_phy_initialization = 1; in fsl_ehci_drv_probe()
174 dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval); in fsl_ehci_drv_probe()
175 if (pdata->exit) in fsl_ehci_drv_probe()
176 pdata->exit(pdev); in fsl_ehci_drv_probe()
182 void __iomem *non_ehci = hcd->regs; in usb_phy_clk_valid()
196 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_fsl_setup_phy() local
197 void __iomem *non_ehci = hcd->regs; in ehci_fsl_setup_phy()
198 struct device *dev = hcd->self.controller; in ehci_fsl_setup_phy()
201 if (pdata->controller_ver < 0) { in ehci_fsl_setup_phy()
202 dev_warn(hcd->self.controller, "Could not get controller version\n"); in ehci_fsl_setup_phy()
203 return -ENODEV; in ehci_fsl_setup_phy()
206 portsc = ehci_readl(ehci, &ehci->regs->port_status[port_offset]); in ehci_fsl_setup_phy()
211 if (pdata->have_sysif_regs && pdata->controller_ver) { in ehci_fsl_setup_phy()
218 /* then turn on ULPI and enable USB controller */ in ehci_fsl_setup_phy()
234 * in device-tree is used to stop USB controller in ehci_fsl_setup_phy()
237 if (pdata->has_fsl_erratum_a006918) { in ehci_fsl_setup_phy()
238 dev_warn(dev, "USB PHY clock invalid\n"); in ehci_fsl_setup_phy()
239 return -EINVAL; in ehci_fsl_setup_phy()
243 /* PHY_CLK_VALID bit is de-featured from all controller in ehci_fsl_setup_phy()
247 if (pdata->controller_ver > FSL_USB_VER_2_4 && in ehci_fsl_setup_phy()
248 pdata->have_sysif_regs && !usb_phy_clk_valid(hcd)) { in ehci_fsl_setup_phy()
249 dev_err(dev, "USB PHY clock invalid\n"); in ehci_fsl_setup_phy()
250 return -EINVAL; in ehci_fsl_setup_phy()
253 if (pdata->have_sysif_regs && pdata->controller_ver) { in ehci_fsl_setup_phy()
261 become stable - 10ms*/ in ehci_fsl_setup_phy()
264 if (pdata->have_sysif_regs) { in ehci_fsl_setup_phy()
276 if (pdata->have_sysif_regs && in ehci_fsl_setup_phy()
277 pdata->controller_ver > FSL_USB_VER_1_6 && in ehci_fsl_setup_phy()
279 dev_warn(hcd->self.controller, "USB PHY clock invalid\n"); in ehci_fsl_setup_phy()
280 return -EINVAL; in ehci_fsl_setup_phy()
283 ehci_writel(ehci, portsc, &ehci->regs->port_status[port_offset]); in ehci_fsl_setup_phy()
285 if (phy_mode != FSL_USB2_PHY_ULPI && pdata->have_sysif_regs) { in ehci_fsl_setup_phy()
295 static int ehci_fsl_usb_setup(struct ehci_hcd *ehci) in ehci_fsl_usb_setup() argument
297 struct usb_hcd *hcd = ehci_to_hcd(ehci); in ehci_fsl_usb_setup()
299 void __iomem *non_ehci = hcd->regs; in ehci_fsl_usb_setup()
301 pdata = dev_get_platdata(hcd->self.controller); in ehci_fsl_usb_setup()
303 if (pdata->have_sysif_regs) { in ehci_fsl_usb_setup()
318 /* Deal with USB erratum A-005275 */ in ehci_fsl_usb_setup()
319 if (pdata->has_fsl_erratum_a005275 == 1) in ehci_fsl_usb_setup()
320 ehci->has_fsl_hs_errata = 1; in ehci_fsl_usb_setup()
322 if (pdata->has_fsl_erratum_a005697 == 1) in ehci_fsl_usb_setup()
323 ehci->has_fsl_susp_errata = 1; in ehci_fsl_usb_setup()
325 if ((pdata->operating_mode == FSL_USB2_DR_HOST) || in ehci_fsl_usb_setup()
326 (pdata->operating_mode == FSL_USB2_DR_OTG)) in ehci_fsl_usb_setup()
327 if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0)) in ehci_fsl_usb_setup()
328 return -EINVAL; in ehci_fsl_usb_setup()
330 if (pdata->operating_mode == FSL_USB2_MPH_HOST) { in ehci_fsl_usb_setup()
332 /* Deal with USB Erratum #14 on MPC834x Rev 1.0 & 1.1 chips */ in ehci_fsl_usb_setup()
333 if (pdata->has_fsl_erratum_14 == 1) in ehci_fsl_usb_setup()
334 ehci->has_fsl_port_bug = 1; in ehci_fsl_usb_setup()
336 if (pdata->port_enables & FSL_USB2_PORT0_ENABLED) in ehci_fsl_usb_setup()
337 if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 0)) in ehci_fsl_usb_setup()
338 return -EINVAL; in ehci_fsl_usb_setup()
340 if (pdata->port_enables & FSL_USB2_PORT1_ENABLED) in ehci_fsl_usb_setup()
341 if (ehci_fsl_setup_phy(hcd, pdata->phy_mode, 1)) in ehci_fsl_usb_setup()
342 return -EINVAL; in ehci_fsl_usb_setup()
345 if (pdata->have_sysif_regs) { in ehci_fsl_usb_setup()
359 /* called after powerup, by probe or system-pm "wakeup" */
360 static int ehci_fsl_reinit(struct ehci_hcd *ehci) in ehci_fsl_reinit() argument
362 if (ehci_fsl_usb_setup(ehci)) in ehci_fsl_reinit()
363 return -EINVAL; in ehci_fsl_reinit()
371 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_fsl_setup() local
376 dev = hcd->self.controller; in ehci_fsl_setup()
377 pdata = dev_get_platdata(hcd->self.controller); in ehci_fsl_setup()
378 ehci->big_endian_desc = pdata->big_endian_desc; in ehci_fsl_setup()
379 ehci->big_endian_mmio = pdata->big_endian_mmio; in ehci_fsl_setup()
381 /* EHCI registers start at offset 0x100 */ in ehci_fsl_setup()
382 ehci->caps = hcd->regs + 0x100; in ehci_fsl_setup()
390 ehci->need_oc_pp_cycle = 1; in ehci_fsl_setup()
393 hcd->has_tt = 1; in ehci_fsl_setup()
399 if (of_device_is_compatible(dev->parent->of_node, in ehci_fsl_setup()
400 "fsl,mpc5121-usb2-dr")) { in ehci_fsl_setup()
405 ehci_writel(ehci, SBUSCFG_INCR8, in ehci_fsl_setup()
406 hcd->regs + FSL_SOC_USB_SBUSCFG); in ehci_fsl_setup()
409 retval = ehci_fsl_reinit(ehci); in ehci_fsl_setup()
414 struct ehci_hcd ehci; member
417 /* Saved USB PHY settings, need to restore after deep sleep. */
428 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_fsl_mpc512x_drv_suspend() local
433 u32 mode = ehci_readl(ehci, hcd->regs + FSL_SOC_USB_USBMODE); in ehci_fsl_mpc512x_drv_suspend()
435 tmp = ehci_readl(ehci, hcd->regs + 0x140); /* usbcmd */ in ehci_fsl_mpc512x_drv_suspend()
438 "mode=%d usbcmd %08x\n", pdata->suspended, in ehci_fsl_mpc512x_drv_suspend()
439 pdata->already_suspended, mode, tmp); in ehci_fsl_mpc512x_drv_suspend()
447 if (pdata->suspended) { in ehci_fsl_mpc512x_drv_suspend()
449 pdata->already_suspended = 1; in ehci_fsl_mpc512x_drv_suspend()
455 ehci->rh_state = EHCI_RH_SUSPENDED; in ehci_fsl_mpc512x_drv_suspend()
456 dev->power.power_state = PMSG_SUSPEND; in ehci_fsl_mpc512x_drv_suspend()
458 /* ignore non-host interrupts */ in ehci_fsl_mpc512x_drv_suspend()
459 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in ehci_fsl_mpc512x_drv_suspend()
462 tmp = ehci_readl(ehci, &ehci->regs->command); in ehci_fsl_mpc512x_drv_suspend()
464 ehci_writel(ehci, tmp, &ehci->regs->command); in ehci_fsl_mpc512x_drv_suspend()
466 /* save EHCI registers */ in ehci_fsl_mpc512x_drv_suspend()
467 pdata->pm_command = ehci_readl(ehci, &ehci->regs->command); in ehci_fsl_mpc512x_drv_suspend()
468 pdata->pm_command &= ~CMD_RUN; in ehci_fsl_mpc512x_drv_suspend()
469 pdata->pm_status = ehci_readl(ehci, &ehci->regs->status); in ehci_fsl_mpc512x_drv_suspend()
470 pdata->pm_intr_enable = ehci_readl(ehci, &ehci->regs->intr_enable); in ehci_fsl_mpc512x_drv_suspend()
471 pdata->pm_frame_index = ehci_readl(ehci, &ehci->regs->frame_index); in ehci_fsl_mpc512x_drv_suspend()
472 pdata->pm_segment = ehci_readl(ehci, &ehci->regs->segment); in ehci_fsl_mpc512x_drv_suspend()
473 pdata->pm_frame_list = ehci_readl(ehci, &ehci->regs->frame_list); in ehci_fsl_mpc512x_drv_suspend()
474 pdata->pm_async_next = ehci_readl(ehci, &ehci->regs->async_next); in ehci_fsl_mpc512x_drv_suspend()
475 pdata->pm_configured_flag = in ehci_fsl_mpc512x_drv_suspend()
476 ehci_readl(ehci, &ehci->regs->configured_flag); in ehci_fsl_mpc512x_drv_suspend()
477 pdata->pm_portsc = ehci_readl(ehci, &ehci->regs->port_status[0]); in ehci_fsl_mpc512x_drv_suspend()
478 pdata->pm_usbgenctrl = ehci_readl(ehci, in ehci_fsl_mpc512x_drv_suspend()
479 hcd->regs + FSL_SOC_USB_USBGENCTRL); in ehci_fsl_mpc512x_drv_suspend()
482 pdata->pm_portsc &= cpu_to_hc32(ehci, ~PORT_RWC_BITS); in ehci_fsl_mpc512x_drv_suspend()
484 pdata->suspended = 1; in ehci_fsl_mpc512x_drv_suspend()
487 tmp = ehci_readl(ehci, &ehci->regs->port_status[0]); in ehci_fsl_mpc512x_drv_suspend()
489 ehci_writel(ehci, tmp, &ehci->regs->port_status[0]); in ehci_fsl_mpc512x_drv_suspend()
497 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_fsl_mpc512x_drv_resume() local
502 pdata->suspended, pdata->already_suspended); in ehci_fsl_mpc512x_drv_resume()
508 if (pdata->already_suspended) { in ehci_fsl_mpc512x_drv_resume()
510 pdata->already_suspended = 0; in ehci_fsl_mpc512x_drv_resume()
514 if (!pdata->suspended) { in ehci_fsl_mpc512x_drv_resume()
519 pdata->suspended = 0; in ehci_fsl_mpc512x_drv_resume()
524 tmp = USBMODE_CM_HOST | (pdata->es ? USBMODE_ES : 0); in ehci_fsl_mpc512x_drv_resume()
525 ehci_writel(ehci, tmp, hcd->regs + FSL_SOC_USB_USBMODE); in ehci_fsl_mpc512x_drv_resume()
527 ehci_writel(ehci, pdata->pm_usbgenctrl, in ehci_fsl_mpc512x_drv_resume()
528 hcd->regs + FSL_SOC_USB_USBGENCTRL); in ehci_fsl_mpc512x_drv_resume()
529 ehci_writel(ehci, ISIPHYCTRL_PXE | ISIPHYCTRL_PHYE, in ehci_fsl_mpc512x_drv_resume()
530 hcd->regs + FSL_SOC_USB_ISIPHYCTRL); in ehci_fsl_mpc512x_drv_resume()
532 ehci_writel(ehci, SBUSCFG_INCR8, hcd->regs + FSL_SOC_USB_SBUSCFG); in ehci_fsl_mpc512x_drv_resume()
534 /* restore EHCI registers */ in ehci_fsl_mpc512x_drv_resume()
535 ehci_writel(ehci, pdata->pm_command, &ehci->regs->command); in ehci_fsl_mpc512x_drv_resume()
536 ehci_writel(ehci, pdata->pm_intr_enable, &ehci->regs->intr_enable); in ehci_fsl_mpc512x_drv_resume()
537 ehci_writel(ehci, pdata->pm_frame_index, &ehci->regs->frame_index); in ehci_fsl_mpc512x_drv_resume()
538 ehci_writel(ehci, pdata->pm_segment, &ehci->regs->segment); in ehci_fsl_mpc512x_drv_resume()
539 ehci_writel(ehci, pdata->pm_frame_list, &ehci->regs->frame_list); in ehci_fsl_mpc512x_drv_resume()
540 ehci_writel(ehci, pdata->pm_async_next, &ehci->regs->async_next); in ehci_fsl_mpc512x_drv_resume()
541 ehci_writel(ehci, pdata->pm_configured_flag, in ehci_fsl_mpc512x_drv_resume()
542 &ehci->regs->configured_flag); in ehci_fsl_mpc512x_drv_resume()
543 ehci_writel(ehci, pdata->pm_portsc, &ehci->regs->port_status[0]); in ehci_fsl_mpc512x_drv_resume()
545 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); in ehci_fsl_mpc512x_drv_resume()
546 ehci->rh_state = EHCI_RH_RUNNING; in ehci_fsl_mpc512x_drv_resume()
547 dev->power.power_state = PMSG_ON; in ehci_fsl_mpc512x_drv_resume()
549 tmp = ehci_readl(ehci, &ehci->regs->command); in ehci_fsl_mpc512x_drv_resume()
551 ehci_writel(ehci, tmp, &ehci->regs->command); in ehci_fsl_mpc512x_drv_resume()
571 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in hcd_to_ehci_fsl() local
573 return container_of(ehci, struct ehci_fsl, ehci); in hcd_to_ehci_fsl()
580 void __iomem *non_ehci = hcd->regs; in ehci_fsl_drv_suspend()
582 if (of_device_is_compatible(dev->parent->of_node, in ehci_fsl_drv_suspend()
583 "fsl,mpc5121-usb2-dr")) { in ehci_fsl_drv_suspend()
592 ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL); in ehci_fsl_drv_suspend()
600 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_fsl_drv_resume() local
601 void __iomem *non_ehci = hcd->regs; in ehci_fsl_drv_resume()
603 if (of_device_is_compatible(dev->parent->of_node, in ehci_fsl_drv_resume()
604 "fsl,mpc5121-usb2-dr")) { in ehci_fsl_drv_resume()
608 ehci_prepare_ports_for_controller_resume(ehci); in ehci_fsl_drv_resume()
612 usb_root_hub_lost_power(hcd->self.root_hub); in ehci_fsl_drv_resume()
614 /* Restore USB PHY settings and enable the controller. */ in ehci_fsl_drv_resume()
615 iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL); in ehci_fsl_drv_resume()
617 ehci_reset(ehci); in ehci_fsl_drv_resume()
618 ehci_fsl_reinit(ehci); in ehci_fsl_drv_resume()
627 usb_root_hub_lost_power(hcd->self.root_hub); in ehci_fsl_drv_restore()
645 struct ehci_hcd *ehci = hcd_to_ehci(hcd); in ehci_start_port_reset() local
649 return -EINVAL; in ehci_start_port_reset()
651 port--; in ehci_start_port_reset()
654 status = readl(&ehci->regs->port_status[port]); in ehci_start_port_reset()
656 return -ENODEV; in ehci_start_port_reset()
659 if (ehci_is_TDI(ehci)) { in ehci_start_port_reset()
662 &ehci->regs->port_status[port]); in ehci_start_port_reset()
664 writel(PORT_RESET, &ehci->regs->port_status[port]); in ehci_start_port_reset()
679 * fsl_ehci_drv_remove - shutdown processing for FSL-based HCDs
680 * @pdev: USB Host Controller being removed
688 struct fsl_usb2_platform_data *pdata = dev_get_platdata(&pdev->dev); in fsl_ehci_drv_remove()
691 if (!IS_ERR_OR_NULL(hcd->usb_phy)) { in fsl_ehci_drv_remove()
692 otg_set_host(hcd->usb_phy->otg, NULL); in fsl_ehci_drv_remove()
693 usb_put_phy(hcd->usb_phy); in fsl_ehci_drv_remove()
699 * do platform specific un-initialization: in fsl_ehci_drv_remove()
702 if (pdata->exit) in fsl_ehci_drv_remove()
703 pdata->exit(pdev); in fsl_ehci_drv_remove()
720 return -ENODEV; in ehci_fsl_init()
725 "Freescale On-Chip EHCI Host Controller"; in ehci_fsl_init()