diff mbox

[3/7] usb: dwc3: pci: add pm_runtime support

Message ID 1386884325-11440-4-git-send-email-balbi@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Felipe Balbi Dec. 12, 2013, 9:38 p.m. UTC
teach the PCI glue about pm_runtime so that
it's easier to teach dwc3 core about it
later.

No functional changes otherwise.

Signed-off-by: Felipe Balbi <balbi@ti.com>
---
 drivers/usb/dwc3/dwc3-pci.c | 66 ++++++++++++++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 15 deletions(-)

Comments

David Cohen Dec. 13, 2013, 1:56 a.m. UTC | #1
On Thu, Dec 12, 2013 at 03:38:41PM -0600, Felipe Balbi wrote:
> teach the PCI glue about pm_runtime so that
> it's easier to teach dwc3 core about it
> later.
> 
> No functional changes otherwise.
> 
> Signed-off-by: Felipe Balbi <balbi@ti.com>

I was able to test this one with Intel Merrifield:
Acked-by: David Cohen <david.a.cohen@linux.intel.com>
Felipe Balbi Dec. 13, 2013, 4:17 a.m. UTC | #2
On Thu, Dec 12, 2013 at 05:56:05PM -0800, David Cohen wrote:
> On Thu, Dec 12, 2013 at 03:38:41PM -0600, Felipe Balbi wrote:
> > teach the PCI glue about pm_runtime so that
> > it's easier to teach dwc3 core about it
> > later.
> > 
> > No functional changes otherwise.
> > 
> > Signed-off-by: Felipe Balbi <balbi@ti.com>
> 
> I was able to test this one with Intel Merrifield:
> Acked-by: David Cohen <david.a.cohen@linux.intel.com>

cool, thanks. Although that'd be a Tested-by. Is it ok to add your name
as Tested-by instead ?
David Cohen Dec. 13, 2013, 4:29 a.m. UTC | #3
On Thu, Dec 12, 2013 at 10:17:19PM -0600, Felipe Balbi wrote:
> On Thu, Dec 12, 2013 at 05:56:05PM -0800, David Cohen wrote:
> > On Thu, Dec 12, 2013 at 03:38:41PM -0600, Felipe Balbi wrote:
> > > teach the PCI glue about pm_runtime so that
> > > it's easier to teach dwc3 core about it
> > > later.
> > > 
> > > No functional changes otherwise.
> > > 
> > > Signed-off-by: Felipe Balbi <balbi@ti.com>
> > 
> > I was able to test this one with Intel Merrifield:
> > Acked-by: David Cohen <david.a.cohen@linux.intel.com>
> 
> cool, thanks. Although that'd be a Tested-by. Is it ok to add your name
> as Tested-by instead ?

Yeah :)

Br, David

> 
> -- 
> balbi
diff mbox

Patch

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 665686e..78cd0b0 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -109,18 +109,17 @@  static int dwc3_pci_probe(struct pci_dev *pci,
 
 	glue->dev = dev;
 
-	ret = pci_enable_device(pci);
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
 	if (ret) {
 		dev_err(dev, "failed to enable pci device\n");
 		return -ENODEV;
 	}
 
-	pci_set_master(pci);
-
 	ret = dwc3_pci_register_phys(glue);
 	if (ret) {
 		dev_err(dev, "couldn't register PHYs\n");
-		return ret;
+		goto err1;
 	}
 
 	dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
@@ -167,7 +166,8 @@  static int dwc3_pci_probe(struct pci_dev *pci,
 err3:
 	platform_device_put(dwc3);
 err1:
-	pci_disable_device(pci);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
 
 	return ret;
 }
@@ -175,11 +175,13 @@  err1:
 static void dwc3_pci_remove(struct pci_dev *pci)
 {
 	struct dwc3_pci	*glue = pci_get_drvdata(pci);
+	struct device *dev = &pci->dev;
 
 	platform_device_unregister(glue->dwc3);
 	platform_device_unregister(glue->usb2_phy);
 	platform_device_unregister(glue->usb3_phy);
-	pci_disable_device(pci);
+	pm_runtime_put_sync(dev);
+	pm_runtime_disable(dev);
 }
 
 static const struct pci_device_id dwc3_pci_id_table[] = {
@@ -193,24 +195,20 @@  static const struct pci_device_id dwc3_pci_id_table[] = {
 };
 MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
 
-#ifdef CONFIG_PM_SLEEP
-static int dwc3_pci_suspend(struct device *dev)
+static int __dwc3_pci_suspend(struct pci_dev *pci)
 {
-	struct pci_dev	*pci = to_pci_dev(dev);
-
 	pci_disable_device(pci);
 
 	return 0;
 }
 
-static int dwc3_pci_resume(struct device *dev)
+static int __dwc3_pci_resume(struct pci_dev *pci)
 {
-	struct pci_dev	*pci = to_pci_dev(dev);
-	int		ret;
+	int ret;
 
 	ret = pci_enable_device(pci);
 	if (ret) {
-		dev_err(dev, "can't re-enable device --> %d\n", ret);
+		dev_err(&pci->dev, "can't re-enable device --> %d\n", ret);
 		return ret;
 	}
 
@@ -218,10 +216,48 @@  static int dwc3_pci_resume(struct device *dev)
 
 	return 0;
 }
-#endif /* CONFIG_PM_SLEEP */
+
+static int dwc3_pci_suspend(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_suspend(pci);
+}
+
+static int dwc3_pci_resume(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+	int		ret;
+
+	ret = __dwc3_pci_resume(pci);
+	if (ret)
+		return ret;
+
+	pm_runtime_disable(dev);
+	pm_runtime_set_active(dev);
+	pm_runtime_disable(dev);
+
+	return 0;
+}
+
+static int dwc3_pci_runtime_suspend(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_suspend(pci);
+}
+
+static int dwc3_pci_runtime_resume(struct device *dev)
+{
+	struct pci_dev	*pci = to_pci_dev(dev);
+
+	return __dwc3_pci_resume(pci);
+}
 
 static const struct dev_pm_ops dwc3_pci_dev_pm_ops = {
 	SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)
+	SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume,
+			NULL)
 };
 
 static struct pci_driver dwc3_pci_driver = {