[PATCH v2 04/25] ehci: Support for Intel Moorestown MPH and OTG host

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The Intel Moorestown platform has EHCI MPH and EHCI OTG host. This patch adds
PCI probe part for them. The HNP part and SRAM part will be added in another
patch. This patch depends on patch which adds unified otg_notify function.

Signed-off-by: Jacob Pan <jacob.jun.pan@xxxxxxxxx>
Signed-off-by: Alek Du <alek.du@xxxxxxxxx>
Signed-off-by: Hao Wu <hao.wu@xxxxxxxxx>
---
 drivers/usb/core/hub.c                |   11 ++
 drivers/usb/host/ehci-hcd.c           |   18 +++
 drivers/usb/host/ehci-hub.c           |    6 +-
 drivers/usb/host/ehci-intel-mid-pci.c |  188 +++++++++++++++++++++++++++++++++
 drivers/usb/host/ehci-pci.c           |   14 +++
 5 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/host/ehci-intel-mid-pci.c

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 27115b4..46abdb8 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -21,6 +21,7 @@
 #include <linux/usbdevice_fs.h>
 #include <linux/usb/hcd.h>
 #include <linux/usb/quirks.h>
+#include <linux/usb/otg.h>
 #include <linux/kthread.h>
 #include <linux/mutex.h>
 #include <linux/freezer.h>
@@ -1607,6 +1608,11 @@ void usb_disconnect(struct usb_device **pdev)
 	 */
 	device_del(&udev->dev);
 
+	/* Notify OTG disconnect event, only for USB device which is
+	 * directly connected to root hub */
+	if (udev->parent && udev->parent->parent == NULL)
+		otg_notify_event(USB_OTG_DISCON);
+
 	/* Free the device number and delete the parent's children[]
 	 * (or root_hub) pointer.
 	 */
@@ -1830,6 +1836,11 @@ int usb_new_device(struct usb_device *udev)
 		goto fail;
 	}
 
+	/* Notify OTG connect event, only for USB device which is
+	 * directly connected to root hub */
+	if (udev->parent && udev->parent->parent == NULL)
+		otg_notify_event(USB_OTG_CONNECT);
+
 	(void) usb_create_ep_devs(&udev->dev, &udev->ep0, udev);
 	return err;
 
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 502a7e6..769a957 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -32,6 +32,7 @@
 #include <linux/interrupt.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/usb/otg.h>
 #include <linux/moduleparam.h>
 #include <linux/dma-mapping.h>
 #include <linux/debugfs.h>
@@ -1154,6 +1155,10 @@ MODULE_LICENSE ("GPL");
 #ifdef CONFIG_PCI
 #include "ehci-pci.c"
 #define	PCI_DRIVER		ehci_pci_driver
+#ifdef CONFIG_USB_LANGWELL_OTG
+#include "ehci-intel-mid-pci.c"
+#define INTEL_MID_OTG_HOST_DRIVER	ehci_otg_driver
+#endif
 #endif
 
 #ifdef CONFIG_USB_EHCI_FSL
@@ -1278,8 +1283,18 @@ static int __init ehci_hcd_init(void)
 	if (retval < 0)
 		goto clean4;
 #endif
+
+#ifdef INTEL_MID_OTG_HOST_DRIVER
+	retval = intel_mid_ehci_driver_register(&INTEL_MID_OTG_HOST_DRIVER);
+	if (retval < 0)
+		goto clean5;
+#endif
 	return retval;
 
+#ifdef INTEL_MID_OTG_HOST_DRIVER
+clean5:
+	intel_mid_ehci_driver_unregister(&INTEL_MID_OTG_HOST_DRIVER);
+#endif
 #ifdef XILINX_OF_PLATFORM_DRIVER
 	/* of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER); */
 clean4:
@@ -1312,6 +1327,9 @@ module_init(ehci_hcd_init);
 
 static void __exit ehci_hcd_cleanup(void)
 {
+#ifdef INTEL_MID_OTG_HOST_DRIVER
+	intel_mid_ehci_driver_unregister(&INTEL_MID_OTG_HOST_DRIVER);
+#endif
 #ifdef XILINX_OF_PLATFORM_DRIVER
 	of_unregister_platform_driver(&XILINX_OF_PLATFORM_DRIVER);
 #endif
diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
index 796ea0c..2477073 100644
--- a/drivers/usb/host/ehci-hub.c
+++ b/drivers/usb/host/ehci-hub.c
@@ -303,7 +303,8 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
 	 * want, and so we must delete any pending watchdog timer events.
 	 */
 	del_timer_sync(&ehci->watchdog);
-	return 0;
+
+	return otg_notify_event(USB_OTG_HOST_SUSP);
 }
 
 
@@ -430,7 +431,8 @@ static int ehci_bus_resume (struct usb_hcd *hcd)
 
 	spin_unlock_irq (&ehci->lock);
 	ehci_handover_companion_ports(ehci);
-	return 0;
+
+	return otg_notify_event(USB_OTG_HOST_RESU);
 }
 
 #else
diff --git a/drivers/usb/host/ehci-intel-mid-pci.c b/drivers/usb/host/ehci-intel-mid-pci.c
new file mode 100644
index 0000000..b05bc8a
--- /dev/null
+++ b/drivers/usb/host/ehci-intel-mid-pci.c
@@ -0,0 +1,188 @@
+/*
+ * Intel MID Platform Langwell/Penwell OTG EHCI Controller PCI Bus Glue.
+ *
+ * Copyright (c) 2008 - 2010, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License 2 as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/usb/intel_mid_otg.h>
+
+static int ehci_mid_probe(struct pci_dev *pdev,
+			const struct pci_device_id *id)
+{
+	struct hc_driver *driver;
+	struct otg_transceiver *otg;
+	struct intel_mid_otg_xceiv *iotg;
+	struct usb_hcd *hcd;
+	struct ehci_hcd *ehci;
+	int irq;
+	int retval;
+
+	pr_debug("initializing Intel MID USB OTG Host Controller\n");
+
+	/* we need not call pci_enable_dev since otg transceiver already take
+	 * the control of this device and this probe actaully gets called by
+	 * otg transceiver driver with HNP protocol.
+	 */
+	irq = pdev->irq;
+
+	if (!id)
+		return -EINVAL;
+	driver = (struct hc_driver *)id->driver_data;
+	if (!driver)
+		return -EINVAL;
+
+	hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
+	if (!hcd) {
+		retval = -ENOMEM;
+		goto err1;
+	}
+
+	hcd->self.otg_port = 1;
+	ehci = hcd_to_ehci(hcd);
+
+	otg = otg_get_transceiver();
+	if (otg == NULL) {
+		printk(KERN_ERR "%s Failed to get otg transceiver\n", __func__);
+		retval = -EINVAL;
+		goto err1;
+	}
+
+	iotg = otg_to_mid_xceiv(otg);
+	hcd->regs = iotg->base;
+
+	hcd->rsrc_start = pci_resource_start(pdev, 0);
+	hcd->rsrc_len = pci_resource_len(pdev, 0);
+
+	if (hcd->regs == NULL) {
+		dev_dbg(&pdev->dev, "error mapping memory\n");
+		retval = -EFAULT;
+		goto err2;
+	}
+	retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED);
+	if (retval != 0)
+		goto err2;
+	retval = otg_set_host(otg, &hcd->self);
+	if (!otg->default_a)
+		hcd->self.is_b_host = 1;
+	otg_put_transceiver(otg);
+	return retval;
+
+err2:
+	usb_put_hcd(hcd);
+err1:
+	dev_err(&pdev->dev, "init %s fail, %d\n", dev_name(&pdev->dev), retval);
+	return retval;
+}
+
+void ehci_mid_remove(struct pci_dev *dev)
+{
+	struct usb_hcd *hcd = pci_get_drvdata(dev);
+
+	if (!hcd)
+		return;
+	usb_remove_hcd(hcd);
+	usb_put_hcd(hcd);
+}
+
+/* Intel MID OTG EHCI driver */
+static struct pci_driver ehci_otg_driver = {
+	.name =		"ehci-intel-mid",
+	.id_table =	pci_ids,
+
+	.probe =	ehci_mid_probe,
+	.remove =	ehci_mid_remove,
+
+#ifdef CONFIG_PM_SLEEP
+	.driver =	{
+		.pm =   &usb_hcd_pci_pm_ops
+	},
+#endif
+	.shutdown =     usb_hcd_pci_shutdown,
+};
+
+static int ehci_mid_start_host(struct intel_mid_otg_xceiv *iotg)
+{
+	struct pci_dev	*pdev;
+	int		retval;
+
+	if (iotg == NULL)
+		return -EINVAL;
+
+	pdev = to_pci_dev(iotg->otg.dev);
+
+	retval = ehci_mid_probe(pdev, ehci_otg_driver.id_table);
+	if (retval)
+		dev_dbg(iotg->otg.dev, "Failed to start host\n");
+
+	return retval;
+}
+
+static int ehci_mid_stop_host(struct intel_mid_otg_xceiv *iotg)
+{
+	struct pci_dev	*pdev;
+
+	if (iotg == NULL)
+		return -EINVAL;
+
+	pdev = to_pci_dev(iotg->otg.dev);
+
+	ehci_mid_remove(pdev);
+
+	return 0;
+}
+
+static int intel_mid_ehci_driver_register(struct pci_driver *host_driver)
+{
+	struct otg_transceiver		*otg;
+	struct intel_mid_otg_xceiv	*iotg;
+
+	otg = otg_get_transceiver();
+	if (otg == NULL)
+		return -EINVAL;
+
+	iotg = otg_to_mid_xceiv(otg);
+	iotg->start_host = ehci_mid_start_host;
+	iotg->stop_host = ehci_mid_stop_host;
+
+	/* notify host driver is registered */
+	atomic_notifier_call_chain(&iotg->iotg_notifier,
+				MID_OTG_NOTIFY_HOSTADD, iotg);
+
+	otg_put_transceiver(otg);
+
+	return 0;
+}
+
+static void intel_mid_ehci_driver_unregister(struct pci_driver *host_driver)
+{
+	struct otg_transceiver		*otg;
+	struct intel_mid_otg_xceiv	*iotg;
+
+	otg = otg_get_transceiver();
+	if (otg == NULL)
+		return ;
+
+	iotg = otg_to_mid_xceiv(otg);
+	iotg->start_host = NULL;
+	iotg->stop_host = NULL;
+
+	/* notify host driver is unregistered */
+	atomic_notifier_call_chain(&iotg->iotg_notifier,
+				MID_OTG_NOTIFY_HOSTREMOVE, iotg);
+
+	otg_put_transceiver(otg);
+}
+
diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index a1e8d27..455f0aa 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -50,6 +50,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
 	u8			rev;
 	u32			temp;
 	int			retval;
+	int			force_otg_hc_mode = 0;
 
 	switch (pdev->vendor) {
 	case PCI_VENDOR_ID_TOSHIBA_2:
@@ -63,6 +64,17 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
 #endif
 		}
 		break;
+	case PCI_VENDOR_ID_INTEL:
+		if (pdev->device == 0x0811) {
+			ehci_info(ehci, "Detected Langwell OTG HC\n");
+			hcd->has_tt = 1;
+			ehci->has_hostpc = 1;
+			force_otg_hc_mode = 1;
+		} else if (pdev->device == 0x0806) {
+			ehci_info(ehci, "Detected Langwell MPH\n");
+			hcd->has_tt = 1;
+			ehci->has_hostpc = 1;
+		}
 	}
 
 	ehci->caps = hcd->regs;
@@ -98,6 +110,8 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
 
 	/* cache this readonly data; minimize chip reads */
 	ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
+	if (force_otg_hc_mode)
+		ehci_reset(ehci);
 
 	retval = ehci_halt(ehci);
 	if (retval)
-- 
1.6.0.6

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux