diff mbox series

[v4,2/5] i2c: nvidia-gpu: add runtime pm support

Message ID 20190603170545.24004-3-ajayg@nvidia.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: ucsi: ccg: add runtime pm support | expand

Commit Message

Ajay Gupta June 3, 2019, 5:05 p.m. UTC
From: Ajay Gupta <ajayg@nvidia.com>

Enable runtime pm support with autosuspend delay of three second.
This is to make sure I2C client device Cypress CCGx has completed
all transaction.

Signed-off-by: Ajay Gupta <ajayg@nvidia.com>
---
Changes from v3->v4:
	- Added comment on why stub gpu_i2c_suspend() is needed for
	runtime pm to work correctly.

 drivers/i2c/busses/i2c-nvidia-gpu.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

Comments

Wolfram Sang June 7, 2019, 8:33 a.m. UTC | #1
> +	pm_runtime_mark_last_busy(i2cd->dev);
> +	pm_runtime_put_autosuspend(i2cd->dev);

Much better to have this only once!

> +/*
> + * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
> + * correctly. Without it, lspci shows runtime pm status as "D0" for the card.
> + * Documentation/power/pci.txt also insists for driver to provide this:

I'd think the comment up to here is enough and the rest can go. However,
I leave this decision to you.
Ajay Gupta June 7, 2019, 3:47 p.m. UTC | #2
Hi Wolfram,

> -----Original Message-----
> From: linux-i2c-owner@vger.kernel.org <linux-i2c-owner@vger.kernel.org>
> On Behalf Of Wolfram Sang
> Sent: Friday, June 7, 2019 1:33 AM
> To: Ajay Gupta <ajaykuee@gmail.com>
> Cc: heikki.krogerus@linux.intel.com; linux-usb@vger.kernel.org; linux-
> i2c@vger.kernel.org; Ajay Gupta <ajayg@nvidia.com>
> Subject: Re: [PATCH v4 2/5] i2c: nvidia-gpu: add runtime pm support
> 
> 
> > +	pm_runtime_mark_last_busy(i2cd->dev);
> > +	pm_runtime_put_autosuspend(i2cd->dev);
> 
> Much better to have this only once!
> 
> > +/*
> > + * We need gpu_i2c_suspend() even if it is stub, for runtime pm to
> > +work
> > + * correctly. Without it, lspci shows runtime pm status as "D0" for the
> card.
> > + * Documentation/power/pci.txt also insists for driver to provide this:
> 
> I'd think the comment up to here is enough and the rest can go. However, I
> leave this decision to you.
Sure, will fix it.

Thanks
> nvpublic
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-nvidia-gpu.c b/drivers/i2c/busses/i2c-nvidia-gpu.c
index f1771beb75ea..ad1006e72a03 100644
--- a/drivers/i2c/busses/i2c-nvidia-gpu.c
+++ b/drivers/i2c/busses/i2c-nvidia-gpu.c
@@ -176,6 +176,7 @@  static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
 	 * The controller supports maximum 4 byte read due to known
 	 * limitation of sending STOP after every read.
 	 */
+	pm_runtime_get_sync(i2cd->dev);
 	for (i = 0; i < num; i++) {
 		if (msgs[i].flags & I2C_M_RD) {
 			/* program client address before starting read */
@@ -219,6 +220,8 @@  static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
 		if (status2 < 0)
 			dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
 	}
+	pm_runtime_mark_last_busy(i2cd->dev);
+	pm_runtime_put_autosuspend(i2cd->dev);
 	return status;
 }
 
@@ -338,6 +341,11 @@  static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto del_adapter;
 	}
 
+	pm_runtime_set_autosuspend_delay(&pdev->dev, 3000);
+	pm_runtime_use_autosuspend(&pdev->dev);
+	pm_runtime_put_autosuspend(&pdev->dev);
+	pm_runtime_allow(&pdev->dev);
+
 	return 0;
 
 del_adapter:
@@ -351,10 +359,26 @@  static void gpu_i2c_remove(struct pci_dev *pdev)
 {
 	struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev);
 
+	pm_runtime_get_noresume(i2cd->dev);
 	i2c_del_adapter(&i2cd->adapter);
 	pci_free_irq_vectors(pdev);
 }
 
+/*
+ * We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
+ * correctly. Without it, lspci shows runtime pm status as "D0" for the card.
+ * Documentation/power/pci.txt also insists for driver to provide this:
+ * "First, a PCI device is put into a low-power state, or suspended, with the
+ * help of pm_schedule_suspend() or pm_runtime_suspend() which for PCI devices
+ * call pci_pm_runtime_suspend() to do the actual job.  For this to work, the
+ * device's driver has to provide a pm->runtime_suspend() callback (see below),
+ * which is run by pci_pm_runtime_suspend() as the first action."
+ */
+static __maybe_unused int gpu_i2c_suspend(struct device *dev)
+{
+	return 0;
+}
+
 static __maybe_unused int gpu_i2c_resume(struct device *dev)
 {
 	struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev);
@@ -363,7 +387,8 @@  static __maybe_unused int gpu_i2c_resume(struct device *dev)
 	return 0;
 }
 
-static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, NULL, gpu_i2c_resume, NULL);
+static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, gpu_i2c_suspend, gpu_i2c_resume,
+			    NULL);
 
 static struct pci_driver gpu_i2c_driver = {
 	.name		= "nvidia-gpu",