Skip to content

Commit d4a4f92

Browse files
Ajay GuptaWolfram Sang
authored andcommitted
i2c: nvidia-gpu: add runtime pm support
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> Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
1 parent cb7302f commit d4a4f92

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

drivers/i2c/busses/i2c-nvidia-gpu.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
176176
* The controller supports maximum 4 byte read due to known
177177
* limitation of sending STOP after every read.
178178
*/
179+
pm_runtime_get_sync(i2cd->dev);
179180
for (i = 0; i < num; i++) {
180181
if (msgs[i].flags & I2C_M_RD) {
181182
/* program client address before starting read */
@@ -217,6 +218,8 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
217218
if (status2 < 0)
218219
dev_err(i2cd->dev, "i2c stop failed %d\n", status2);
219220
}
221+
pm_runtime_mark_last_busy(i2cd->dev);
222+
pm_runtime_put_autosuspend(i2cd->dev);
220223
return status;
221224
}
222225

@@ -336,6 +339,11 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
336339
goto del_adapter;
337340
}
338341

342+
pm_runtime_set_autosuspend_delay(&pdev->dev, 3000);
343+
pm_runtime_use_autosuspend(&pdev->dev);
344+
pm_runtime_put_autosuspend(&pdev->dev);
345+
pm_runtime_allow(&pdev->dev);
346+
339347
return 0;
340348

341349
del_adapter:
@@ -349,10 +357,21 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
349357
{
350358
struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev);
351359

360+
pm_runtime_get_noresume(i2cd->dev);
352361
i2c_del_adapter(&i2cd->adapter);
353362
pci_free_irq_vectors(pdev);
354363
}
355364

365+
/*
366+
* We need gpu_i2c_suspend() even if it is stub, for runtime pm to work
367+
* correctly. Without it, lspci shows runtime pm status as "D0" for the card.
368+
* Documentation/power/pci.txt also insists for driver to provide this.
369+
*/
370+
static __maybe_unused int gpu_i2c_suspend(struct device *dev)
371+
{
372+
return 0;
373+
}
374+
356375
static __maybe_unused int gpu_i2c_resume(struct device *dev)
357376
{
358377
struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev);
@@ -361,7 +380,8 @@ static __maybe_unused int gpu_i2c_resume(struct device *dev)
361380
return 0;
362381
}
363382

364-
static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, NULL, gpu_i2c_resume, NULL);
383+
static UNIVERSAL_DEV_PM_OPS(gpu_i2c_driver_pm, gpu_i2c_suspend, gpu_i2c_resume,
384+
NULL);
365385

366386
static struct pci_driver gpu_i2c_driver = {
367387
.name = "nvidia-gpu",

0 commit comments

Comments
 (0)