Revert "usb: ehci-msm-hsic: replace wakelock with wakeup source"

This reverts commit dd5ad79f501c462fbee8e36c57747883d2317d29.

Conflicts:

	drivers/usb/host/ehci-msm-hsic.c

Signed-off-by: Ajay Dudani <adudani@codeaurora.org>
Signed-off-by: Iliyan Malchev <malchev@google.com>
diff --git a/drivers/usb/host/ehci-msm-hsic.c b/drivers/usb/host/ehci-msm-hsic.c
index 8003464..ea265c8 100644
--- a/drivers/usb/host/ehci-msm-hsic.c
+++ b/drivers/usb/host/ehci-msm-hsic.c
@@ -27,6 +27,7 @@
 #include <linux/err.h>
 #include <linux/debugfs.h>
 #include <linux/seq_file.h>
+#include <linux/wakelock.h>
 #include <linux/pm_runtime.h>
 #include <linux/regulator/consumer.h>
 
@@ -58,13 +59,14 @@
 	struct clk		*phy_clk;
 	struct clk		*cal_clk;
 	struct regulator	*hsic_vddcx;
+	bool			async_int;
 	atomic_t                in_lpm;
+	struct wake_lock	wlock;
 	int			peripheral_status_irq;
 	int			wakeup_irq;
 	int			wakeup_gpio;
 	bool			wakeup_irq_enabled;
-	bool			irq_enabled;
-	bool			async_int;
+	atomic_t		pm_usage_cnt;
 	uint32_t		bus_perf_client;
 	uint32_t		wakeup_int_cnt;
 	enum usb_vdd_type	vdd_type;
@@ -602,15 +604,13 @@
 
 	disable_irq(hcd->irq);
 
-	/* make sure we don't race against the root hub being resumed */
-	if (HCD_RH_RUNNING(hcd) || HCD_WAKEUP_PENDING(hcd) ||
+	/* make sure we don't race against a remote wakeup */
+	if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) ||
 	    readl_relaxed(USB_PORTSC) & PORT_RESUME) {
-		dev_warn(mehci->dev, "%s: Root hub is not suspended\n",
-				__func__);
+		dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n");
 		enable_irq(hcd->irq);
 		return -EBUSY;
 	}
-	mehci->irq_enabled = false;
 
 	/*
 	 * PHY may take some time or even fail to enter into low power
@@ -668,13 +668,14 @@
 	}
 
 	atomic_set(&mehci->in_lpm, 1);
-	mehci->irq_enabled = true;
 	enable_irq(hcd->irq);
 
 	mehci->wakeup_irq_enabled = 1;
 	enable_irq_wake(mehci->wakeup_irq);
 	enable_irq(mehci->wakeup_irq);
 
+	wake_unlock(&mehci->wlock);
+
 	dev_dbg(mehci->dev, "HSIC-USB in low power mode\n");
 
 	return 0;
@@ -698,6 +699,8 @@
 		mehci->wakeup_irq_enabled = 0;
 	}
 
+	wake_lock(&mehci->wlock);
+
 	if (mehci->bus_perf_client && debug_bus_voting_enabled) {
 		mehci->bus_vote = true;
 		queue_work(ehci_wq, &mehci->bus_vote_w);
@@ -753,14 +756,13 @@
 	if (mehci->async_int) {
 		mehci->async_int = false;
 		pm_runtime_put_noidle(mehci->dev);
-	}
-
-	if (!mehci->irq_enabled) {
 		enable_irq(hcd->irq);
-		mehci->irq_enabled = true;
 	}
 
-	pm_relax(mehci->dev);
+	if (atomic_read(&mehci->pm_usage_cnt)) {
+		atomic_set(&mehci->pm_usage_cnt, 0);
+		pm_runtime_put_noidle(mehci->dev);
+	}
 
 	dev_dbg(mehci->dev, "HSIC-USB exited from low power mode\n");
 
@@ -787,11 +789,9 @@
 
 	if (atomic_read(&mehci->in_lpm)) {
 		disable_irq_nosync(hcd->irq);
-		mehci->irq_enabled = false;
 		dev_dbg(mehci->dev, "phy async intr\n");
 		mehci->async_int = true;
 		pm_runtime_get(mehci->dev);
-		pm_stay_awake(mehci->dev);
 		return IRQ_HANDLED;
 	}
 
@@ -1008,9 +1008,7 @@
 	dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n",
 			__func__, mehci->wakeup_int_cnt);
 
-	mehci->async_int = true;
-	pm_runtime_get(mehci->dev);
-	pm_stay_awake(mehci->dev);
+	wake_lock(&mehci->wlock);
 
 	if (mehci->wakeup_irq_enabled) {
 		mehci->wakeup_irq_enabled = 0;
@@ -1018,6 +1016,11 @@
 		disable_irq_nosync(irq);
 	}
 
+	if (!atomic_read(&mehci->pm_usage_cnt)) {
+		atomic_set(&mehci->pm_usage_cnt, 1);
+		pm_runtime_get(mehci->dev);
+	}
+
 	return IRQ_HANDLED;
 }
 
@@ -1321,8 +1324,9 @@
 		goto unconfig_gpio;
 	}
 
-	mehci->irq_enabled = true;
 	device_init_wakeup(&pdev->dev, 1);
+	wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
+	wake_lock(&mehci->wlock);
 
 	if (mehci->peripheral_status_irq) {
 		ret = request_threaded_irq(mehci->peripheral_status_irq,
@@ -1437,6 +1441,7 @@
 	msm_hsic_init_vddcx(mehci, 0);
 
 	msm_hsic_init_clocks(mehci, 0);
+	wake_lock_destroy(&mehci->wlock);
 	iounmap(hcd->regs);
 	usb_put_hcd(hcd);