diff options
author | Ramneek Mehresh <ramneek.mehresh@freescale.com> | 2013-04-18 10:13:33 (GMT) |
---|---|---|
committer | Fleming Andrew-AFLEMING <AFLEMING@freescale.com> | 2013-04-29 15:23:09 (GMT) |
commit | 3b60d871cca0abe1c72b81b43c84bd8fa0610497 (patch) | |
tree | 3479af1e2a6178aca18026df7495d668fd8ae392 /drivers | |
parent | 8674d9510f86cf78002f31692dcc3f5432257236 (diff) | |
download | linux-fsl-qoriq-3b60d871cca0abe1c72b81b43c84bd8fa0610497.tar.xz |
fsl/otg: Add support to add/remove usb host driver
Add workqueue to add/remove host driver (outside interrupt context)
upon each id change
Change-Id: Ic9c8330aad04e461be7f0792208ccb4609ab7929
Signed-off-by: Li Yang <leoli@freescale.com>
Signed-off-by: Ramneek Mehresh <ramneek.mehresh@freescale.com>
Reviewed-on: http://git.am.freescale.net:8181/1367
Reviewed-by: Fleming Andrew-AFLEMING <AFLEMING@freescale.com>
Tested-by: Fleming Andrew-AFLEMING <AFLEMING@freescale.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/host/ehci-fsl.c | 97 | ||||
-rw-r--r-- | drivers/usb/host/ehci.h | 3 | ||||
-rw-r--r-- | drivers/usb/otg/fsl_otg.c | 7 |
3 files changed, 89 insertions, 18 deletions
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c index 5e06c55..45d387c 100644 --- a/drivers/usb/host/ehci-fsl.c +++ b/drivers/usb/host/ehci-fsl.c @@ -34,6 +34,54 @@ #include "ehci-fsl.h" +struct ehci_fsl { + struct ehci_hcd ehci; + +#ifdef CONFIG_PM + /* Saved USB PHY settings, need to restore after deep sleep. */ + u32 usb_ctrl; +#endif + + /* store current hcd state for otg; + * have_hcd is true when host drv al already part of otg framework, + * otherwise false; + * hcd_add is true when otg framework wants to add host + * drv as part of otg;flase when it wants to remove it + */ + unsigned have_hcd:1; + unsigned hcd_add:1; +}; + +static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd) +{ + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + + return container_of(ehci, struct ehci_fsl, ehci); +} + +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) +static void do_change_hcd(struct work_struct *work) +{ + struct ehci_hcd *ehci = container_of(work, struct ehci_hcd, + change_hcd_work); + struct usb_hcd *hcd = ehci_to_hcd(ehci); + struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); + void __iomem *non_ehci = hcd->regs; + int retval; + + if (ehci_fsl->hcd_add && !ehci_fsl->have_hcd) { + writel(USBMODE_CM_HOST, non_ehci + FSL_SOC_USB_USBMODE); + /* host, gadget and otg share same int line */ + retval = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); + if (retval == 0) + ehci_fsl->have_hcd = 1; + } else if (!ehci_fsl->hcd_add && ehci_fsl->have_hcd) { + usb_remove_hcd(hcd); + ehci_fsl->have_hcd = 0; + } +} +#endif + /* configure so an HC device and id are always provided */ /* always called with process context; sleeping is OK */ @@ -140,11 +188,14 @@ static int usb_hcd_fsl_probe(const struct hc_driver *driver, if (retval != 0) goto err4; -#ifdef CONFIG_USB_OTG +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) if (pdata->operating_mode == FSL_USB2_DR_OTG) { struct ehci_hcd *ehci = hcd_to_ehci(hcd); hcd->phy = usb_get_phy(USB_PHY_TYPE_USB2); + + INIT_WORK(&ehci->change_hcd_work, do_change_hcd); + dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n", hcd, ehci, hcd->phy); @@ -392,15 +443,6 @@ static int ehci_fsl_setup(struct usb_hcd *hcd) return retval; } -struct ehci_fsl { - struct ehci_hcd ehci; - -#ifdef CONFIG_PM - /* Saved USB PHY settings, need to restore after deep sleep. */ - u32 usb_ctrl; -#endif -}; - #ifdef CONFIG_PM #ifdef CONFIG_PPC_MPC512x @@ -548,24 +590,31 @@ static inline int ehci_fsl_mpc512x_drv_resume(struct device *dev) } #endif /* CONFIG_PPC_MPC512x */ -static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd) -{ - struct ehci_hcd *ehci = hcd_to_ehci(hcd); - - return container_of(ehci, struct ehci_fsl, ehci); -} - static int ehci_fsl_drv_suspend(struct device *dev) { struct usb_hcd *hcd = dev_get_drvdata(dev); struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); void __iomem *non_ehci = hcd->regs; +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) + struct usb_bus host = hcd->self; +#endif if (of_device_is_compatible(dev->parent->of_node, "fsl,mpc5121-usb2-dr")) { return ehci_fsl_mpc512x_drv_suspend(dev); } +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) + if (host.is_otg) { + struct ehci_hcd *ehci = hcd_to_ehci(hcd); + + /* remove hcd */ + ehci_fsl->hcd_add = 0; + schedule_work(&ehci->change_hcd_work); + host.is_otg = 0; + return 0; + } +#endif mpc85xx_pmc_set_wake(dev, true); ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), @@ -583,12 +632,26 @@ static int ehci_fsl_drv_resume(struct device *dev) struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd); struct ehci_hcd *ehci = hcd_to_ehci(hcd); void __iomem *non_ehci = hcd->regs; +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) + struct usb_bus host = hcd->self; +#endif if (of_device_is_compatible(dev->parent->of_node, "fsl,mpc5121-usb2-dr")) { return ehci_fsl_mpc512x_drv_resume(dev); } +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) + if (host.is_otg) { + /* add hcd */ + ehci_fsl->hcd_add = 1; + schedule_work(&ehci->change_hcd_work); + usb_hcd_resume_root_hub(hcd); + host.is_otg = 0; + return 0; + } +#endif + mpc85xx_pmc_set_wake(dev, false); ehci_prepare_ports_for_controller_resume(ehci); diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h index 36c3a82..c204b81 100644 --- a/drivers/usb/host/ehci.h +++ b/drivers/usb/host/ehci.h @@ -153,6 +153,9 @@ struct ehci_hcd { /* one per controller */ unsigned periodic_count; /* periodic activity count */ unsigned uframe_periodic_max; /* max periodic time per uframe */ +#if defined(CONFIG_FSL_USB2_OTG) || defined(CONFIG_FSL_USB2_OTG_MODULE) + struct work_struct change_hcd_work; +#endif /* list of itds & sitds completed while now_frame was still active */ struct list_head cached_itd_list; diff --git a/drivers/usb/otg/fsl_otg.c b/drivers/usb/otg/fsl_otg.c index cd5a5fd..4d534eb 100644 --- a/drivers/usb/otg/fsl_otg.c +++ b/drivers/usb/otg/fsl_otg.c @@ -453,6 +453,7 @@ void otg_reset_controller(void) int fsl_otg_start_host(struct otg_fsm *fsm, int on) { struct usb_otg *otg = fsm->otg; + struct usb_bus *host = otg->host; struct device *dev; struct fsl_otg *otg_dev = container_of(otg->phy, struct fsl_otg, phy); u32 retval = 0; @@ -475,6 +476,7 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) otg_reset_controller(); VDBG("host on......\n"); if (dev->driver->pm && dev->driver->pm->resume) { + host->is_otg = 1; retval = dev->driver->pm->resume(dev); if (fsm->id) { /* default-b */ @@ -499,8 +501,11 @@ int fsl_otg_start_host(struct otg_fsm *fsm, int on) else { VDBG("host off......\n"); if (dev && dev->driver) { - if (dev->driver->pm && dev->driver->pm->suspend) + if (dev->driver->pm && + dev->driver->pm->suspend) { + host->is_otg = 1; retval = dev->driver->pm->suspend(dev); + } if (fsm->id) /* default-b */ fsl_otg_drv_vbus(0); |