media: tw68: use generic power management
authorVaibhav Gupta <vaibhavgupta40@gmail.com>
Fri, 17 Jul 2020 07:34:36 +0000 (09:34 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sun, 19 Jul 2020 12:24:57 +0000 (14:24 +0200)
With legacy PM, drivers themselves were responsible for managing the
device's power states and takes care of register states.

After upgrading to the generic structure, PCI core will take care of
required tasks and drivers should do only device-specific operations.

The driver was invoking PCI helper functions like pci_save/restore_state()
which is not recommended.

Compile-Tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/pci/tw68/tw68-core.c

index 30c1ea8..bf15fa7 100644 (file)
@@ -359,10 +359,9 @@ static void tw68_finidev(struct pci_dev *pci_dev)
        v4l2_device_unregister(&dev->v4l2_dev);
 }
 
-#ifdef CONFIG_PM
-
-static int tw68_suspend(struct pci_dev *pci_dev , pm_message_t state)
+static int __maybe_unused tw68_suspend(struct device *dev_d)
 {
+       struct pci_dev *pci_dev = to_pci_dev(dev_d);
        struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
        struct tw68_dev *dev = container_of(v4l2_dev,
                                struct tw68_dev, v4l2_dev);
@@ -373,24 +372,19 @@ static int tw68_suspend(struct pci_dev *pci_dev , pm_message_t state)
 
        synchronize_irq(pci_dev->irq);
 
-       pci_save_state(pci_dev);
-       pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state));
        vb2_discard_done(&dev->vidq);
 
        return 0;
 }
 
-static int tw68_resume(struct pci_dev *pci_dev)
+static int __maybe_unused tw68_resume(struct device *dev_d)
 {
-       struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev);
+       struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
        struct tw68_dev *dev = container_of(v4l2_dev,
                                            struct tw68_dev, v4l2_dev);
        struct tw68_buf *buf;
        unsigned long flags;
 
-       pci_set_power_state(pci_dev, PCI_D0);
-       pci_restore_state(pci_dev);
-
        /* Do things that are done in tw68_initdev ,
                except of initializing memory structures.*/
 
@@ -408,19 +402,17 @@ static int tw68_resume(struct pci_dev *pci_dev)
 
        return 0;
 }
-#endif
 
 /* ----------------------------------------------------------- */
 
+static SIMPLE_DEV_PM_OPS(tw68_pm_ops, tw68_suspend, tw68_resume);
+
 static struct pci_driver tw68_pci_driver = {
-       .name     = "tw68",
-       .id_table = tw68_pci_tbl,
-       .probe    = tw68_initdev,
-       .remove   = tw68_finidev,
-#ifdef CONFIG_PM
-       .suspend  = tw68_suspend,
-       .resume   = tw68_resume
-#endif
+       .name      = "tw68",
+       .id_table  = tw68_pci_tbl,
+       .probe     = tw68_initdev,
+       .remove    = tw68_finidev,
+       .driver.pm = &tw68_pm_ops,
 };
 
 module_pci_driver(tw68_pci_driver);