[PATCH 3/7][v4]usb:fsl:otg: Add support to add/remove usb host driver
From: Ramneek Mehresh
Date: Thu Aug 27 2015 - 12:32:34 EST
Add workqueue to add/remove host driver (outside
interrupt context) upon each id change, and to
remove host driver upon otg initialization by changing
have_hcd variable.
Signed-off-by: Li Yang <leoli@xxxxxxxxxxxxx>
Signed-off-by: Ramneek Mehresh <ramneek.mehresh@xxxxxxxxxxxxx>
---
Changes for v4:
- corrected reference to struct usb_bus inside
ehci_fsl_drv_resume() and ehci_fsl_drv_suspend().
Took pointer instead of structure.
- removed CONFIG_PM from inside struct ehci_fsl
in ehci-fsl.h
- added code to remove host drv upon otg init
by making have_hcd = 1 in probe()
drivers/usb/host/ehci-fsl.c | 73 ++++++++++++++++++++++++++++++++-------------
drivers/usb/host/ehci-fsl.h | 16 ++++++++++
2 files changed, 69 insertions(+), 20 deletions(-)
diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 202dafb..8870ff5 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -44,6 +44,31 @@
static struct hc_driver __read_mostly fsl_ehci_hc_driver;
+static struct ehci_fsl *hcd_to_ehci_fsl(struct usb_hcd *hcd)
+{
+ return (struct ehci_fsl *)hcd_to_ehci(hcd)->priv;
+}
+
+static void do_change_hcd(struct work_struct *work)
+{
+ struct ehci_fsl *ehci_fsl = container_of(work, struct ehci_fsl,
+ change_hcd_work);
+ struct usb_hcd *hcd = 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;
+ }
+}
+
/* configure so an HC device and id are always provided */
/* always called with process context; sleeping is OK */
@@ -147,11 +172,15 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
goto err2;
device_wakeup_enable(hcd->self.controller);
-#ifdef CONFIG_USB_OTG
if (pdata->operating_mode == FSL_USB2_DR_OTG) {
struct ehci_hcd *ehci = hcd_to_ehci(hcd);
+ struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
+ ehci_fsl->hcd = hcd;
hcd->usb_phy = usb_get_phy(USB_PHY_TYPE_USB2);
+
+ INIT_WORK(&ehci_fsl->change_hcd_work, do_change_hcd);
+
dev_dbg(&pdev->dev, "hcd=0x%p ehci=0x%p, phy=0x%p\n",
hcd, ehci, hcd->usb_phy);
@@ -167,8 +196,10 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
retval = -ENODEV;
goto err2;
}
+
+ ehci_fsl->have_hcd = 1;
}
-#endif
+
return retval;
err2:
@@ -371,15 +402,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
@@ -527,24 +549,26 @@ 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;
+ struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
+ struct usb_bus *host = &hcd->self;
if (of_device_is_compatible(dev->parent->of_node,
"fsl,mpc5121-usb2-dr")) {
return ehci_fsl_mpc512x_drv_suspend(dev);
}
+ if (host->is_otg) {
+ /* remove hcd */
+ ehci_fsl->hcd_add = 0;
+ schedule_work(&ehci_fsl->change_hcd_work);
+ host->is_otg = 0;
+ return 0;
+ }
+
ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd),
device_may_wakeup(dev));
if (!fsl_deep_sleep())
@@ -557,15 +581,24 @@ static int ehci_fsl_drv_suspend(struct device *dev)
static int ehci_fsl_drv_resume(struct device *dev)
{
struct usb_hcd *hcd = dev_get_drvdata(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;
+ struct ehci_fsl *ehci_fsl = hcd_to_ehci_fsl(hcd);
+ struct usb_bus *host = &hcd->self;
if (of_device_is_compatible(dev->parent->of_node,
"fsl,mpc5121-usb2-dr")) {
return ehci_fsl_mpc512x_drv_resume(dev);
}
+ if (host->is_otg) {
+ /* add hcd */
+ ehci_fsl->hcd_add = 1;
+ schedule_work(&ehci_fsl->change_hcd_work);
+ host->is_otg = 0;
+ return 0;
+ }
+
ehci_prepare_ports_for_controller_resume(ehci);
if (!fsl_deep_sleep())
return 0;
diff --git a/drivers/usb/host/ehci-fsl.h b/drivers/usb/host/ehci-fsl.h
index 1a8a60a..64538eb 100644
--- a/drivers/usb/host/ehci-fsl.h
+++ b/drivers/usb/host/ehci-fsl.h
@@ -63,4 +63,20 @@
#define UTMI_PHY_EN (1<<9)
#define ULPI_PHY_CLK_SEL (1<<10)
#define PHY_CLK_VALID (1<<17)
+
+struct ehci_fsl {
+ /* Save USB CTRL, need to restore after deep sleep. */
+ u32 usb_ctrl;
+ struct usb_hcd *hcd;
+ struct work_struct change_hcd_work;
+ /*
+ * 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;
+};
#endif /* _EHCI_FSL_H */
--
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/