Commit d4a4f927 authored by Ajay Gupta's avatar Ajay Gupta Committed by Wolfram Sang

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: default avatarAjay Gupta <ajayg@nvidia.com>
Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent cb7302fb
...@@ -176,6 +176,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -176,6 +176,7 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
* The controller supports maximum 4 byte read due to known * The controller supports maximum 4 byte read due to known
* limitation of sending STOP after every read. * limitation of sending STOP after every read.
*/ */
pm_runtime_get_sync(i2cd->dev);
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
if (msgs[i].flags & I2C_M_RD) { if (msgs[i].flags & I2C_M_RD) {
/* program client address before starting read */ /* program client address before starting read */
...@@ -217,6 +218,8 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap, ...@@ -217,6 +218,8 @@ static int gpu_i2c_master_xfer(struct i2c_adapter *adap,
if (status2 < 0) if (status2 < 0)
dev_err(i2cd->dev, "i2c stop failed %d\n", status2); 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; return status;
} }
...@@ -336,6 +339,11 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -336,6 +339,11 @@ static int gpu_i2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto del_adapter; 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; return 0;
del_adapter: del_adapter:
...@@ -349,10 +357,21 @@ static void gpu_i2c_remove(struct pci_dev *pdev) ...@@ -349,10 +357,21 @@ static void gpu_i2c_remove(struct pci_dev *pdev)
{ {
struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev); struct gpu_i2c_dev *i2cd = dev_get_drvdata(&pdev->dev);
pm_runtime_get_noresume(i2cd->dev);
i2c_del_adapter(&i2cd->adapter); i2c_del_adapter(&i2cd->adapter);
pci_free_irq_vectors(pdev); 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.
*/
static __maybe_unused int gpu_i2c_suspend(struct device *dev)
{
return 0;
}
static __maybe_unused int gpu_i2c_resume(struct device *dev) static __maybe_unused int gpu_i2c_resume(struct device *dev)
{ {
struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev); struct gpu_i2c_dev *i2cd = dev_get_drvdata(dev);
...@@ -361,7 +380,8 @@ static __maybe_unused int gpu_i2c_resume(struct device *dev) ...@@ -361,7 +380,8 @@ static __maybe_unused int gpu_i2c_resume(struct device *dev)
return 0; 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 = { static struct pci_driver gpu_i2c_driver = {
.name = "nvidia-gpu", .name = "nvidia-gpu",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment