--- linux-2.6.37.bak/drivers/usb/otg/langwell_otg.c	2011-03-02 10:09:10.921569451 +0800
+++ linux-2.6.37/drivers/usb/otg/langwell_otg.c	2011-03-14 17:33:11.812500000 +0800
@@ -35,6 +35,7 @@
 #include <linux/usb/hcd.h>
 #include <linux/notifier.h>
 #include <linux/delay.h>
+#include <linux/pm_runtime.h>
 #include <asm/intel_scu_ipc.h>
 
 #include <linux/usb/langwell_otg.h>
@@ -61,27 +62,6 @@ static int langwell_otg_set_peripheral(s
 				struct usb_gadget *gadget);
 static int langwell_otg_start_srp(struct otg_transceiver *otg);
 
-static const struct pci_device_id pci_ids[] = {{
-	.class =        ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
-	.class_mask =   ~0,
-	.vendor =	0x8086,
-	.device =	0x0811,
-	.subvendor =	PCI_ANY_ID,
-	.subdevice =	PCI_ANY_ID,
-}, { /* end: all zeroes */ }
-};
-
-static struct pci_driver otg_pci_driver = {
-	.name =		(char *) driver_name,
-	.id_table =	pci_ids,
-
-	.probe =	langwell_otg_probe,
-	.remove =	langwell_otg_remove,
-
-	.suspend =	langwell_otg_suspend,
-	.resume =	langwell_otg_resume,
-};
-
 static const char *state_string(enum usb_otg_state state)
 {
 	switch (state) {
@@ -970,6 +950,8 @@ static void langwell_otg_work(struct wor
 	dev_dbg(lnw->dev, "%s: old state = %s\n", __func__,
 			state_string(iotg->otg.state));
 
+	pm_runtime_get_sync(lnw->dev);
+
 	switch (iotg->otg.state) {
 	case OTG_STATE_UNDEFINED:
 	case OTG_STATE_B_IDLE:
@@ -1702,6 +1684,8 @@ static void langwell_otg_work(struct wor
 		;
 	}
 
+	pm_runtime_put_sync(lnw->dev);
+
 	dev_dbg(lnw->dev, "%s: new state = %s\n", __func__,
 			state_string(iotg->otg.state));
 }
@@ -2368,6 +2352,153 @@ error:
 	return ret;
 }
 
+#ifdef CONFIG_PM_RUNTIME
+/* Runtime PM */
+static int langwell_otg_runtime_suspend(struct device *dev)
+{
+	struct langwell_otg	*lnw = the_transceiver;
+	struct pci_dev		*pdev;
+	int			ret = 0;
+
+	dev_dbg(dev, "%s --->\n", __func__);
+
+	pdev = to_pci_dev(dev);
+
+	switch (lnw->iotg.otg.state) {
+	case OTG_STATE_A_IDLE:
+	case OTG_STATE_B_IDLE:
+		/* Transceiver handle it itself */
+		langwell_otg_phy_low_power(1);
+		pci_save_state(pdev);
+		pci_disable_device(pdev);
+		pci_set_power_state(pdev, PCI_D3hot);
+		break;
+	case OTG_STATE_A_WAIT_BCON:
+	case OTG_STATE_A_HOST:
+	case OTG_STATE_A_SUSPEND:
+		if (lnw->iotg.runtime_suspend_host)
+			ret = lnw->iotg.runtime_suspend_host(&lnw->iotg);
+		break;
+	case OTG_STATE_A_PERIPHERAL:
+	case OTG_STATE_B_PERIPHERAL:
+		if (lnw->iotg.runtime_suspend_peripheral)
+			ret = lnw->iotg.runtime_suspend_peripheral(&lnw->iotg);
+		break;
+	default:
+		break;
+	}
+
+	dev_dbg(dev, "%s <---\n", __func__);
+	return ret;
+}
+
+static int langwell_otg_runtime_resume(struct device *dev)
+{
+	struct langwell_otg	*lnw = the_transceiver;
+	struct pci_dev		*pdev;
+	int			ret = 0;
+
+	dev_dbg(dev, "%s --->\n", __func__);
+
+	pdev = to_pci_dev(dev);
+
+	langwell_otg_intr(1);
+	langwell_otg_phy_low_power(0);
+
+	switch (lnw->iotg.otg.state) {
+	case OTG_STATE_A_IDLE:
+	case OTG_STATE_B_IDLE:
+		/* Transceiver handle it itself */
+		pci_set_power_state(pdev, PCI_D0);
+		pci_restore_state(pdev);
+		ret = pci_enable_device(pdev);
+		if (ret)
+			dev_err(&pdev->dev, "device cant be enabled\n");
+		langwell_otg_phy_low_power(0);
+		break;
+	case OTG_STATE_A_WAIT_BCON:
+	case OTG_STATE_A_HOST:
+	case OTG_STATE_A_SUSPEND:
+		if (lnw->iotg.runtime_resume_host)
+			ret = lnw->iotg.runtime_resume_host(&lnw->iotg);
+		break;
+	case OTG_STATE_A_PERIPHERAL:
+	case OTG_STATE_B_PERIPHERAL:
+		if (lnw->iotg.runtime_resume_peripheral)
+			ret = lnw->iotg.runtime_resume_peripheral(&lnw->iotg);
+		break;
+	default:
+		break;
+	}
+
+	dev_dbg(dev, "%s <---\n", __func__);
+	return 0;
+}
+
+static int langwell_otg_runtime_idle(struct device *dev)
+{
+	struct langwell_otg	*lnw = the_transceiver;
+
+	dev_dbg(dev, "%s --->\n", __func__);
+
+	switch (lnw->iotg.otg.state) {
+	case OTG_STATE_A_WAIT_VRISE:
+	case OTG_STATE_A_WAIT_VFALL:
+	case OTG_STATE_A_VBUS_ERR:
+	case OTG_STATE_B_WAIT_ACON:
+	case OTG_STATE_B_HOST:
+		dev_dbg(dev, "Keep in active\n");
+		return -EBUSY;
+	default:
+		break;
+	}
+
+	dev_dbg(dev, "%s <---\n", __func__);
+
+	return 0;
+}
+
+#else
+
+#define penwell_otg_runtime_suspend NULL
+#define penwell_otg_runtime_resume NULL
+#define penwell_otg_runtime_idle NULL
+
+#endif
+
+/*----------------------------------------------------------*/
+
+static const struct pci_device_id pci_ids[] = {{
+	.class =        ((PCI_CLASS_SERIAL_USB << 8) | 0xfe),
+	.class_mask =   ~0,
+	.vendor =	0x8086,
+	.device =	0x0811,
+	.subvendor =	PCI_ANY_ID,
+	.subdevice =	PCI_ANY_ID,
+}, { /* end: all zeroes */ }
+};
+
+static const struct dev_pm_ops langwell_otg_pm_ops = {
+	.runtime_suspend = langwell_otg_runtime_suspend,
+	.runtime_resume = langwell_otg_runtime_resume,
+	.runtime_idle = langwell_otg_runtime_idle,
+};
+
+static struct pci_driver otg_pci_driver = {
+	.name =		(char *) driver_name,
+	.id_table =	pci_ids,
+
+	.probe =	langwell_otg_probe,
+	.remove =	langwell_otg_remove,
+
+	.suspend =	langwell_otg_suspend,
+	.resume =	langwell_otg_resume,
+
+	.driver = {
+		.pm =	&langwell_otg_pm_ops
+	},
+};
+
 static int __init langwell_otg_init(void)
 {
 	return pci_register_driver(&otg_pci_driver);
