gpio: ml-ioh: Convert to dev_pm_ops
authorVaibhav Gupta <vaibhavgupta40@gmail.com>
Thu, 2 Apr 2020 15:50:58 +0000 (21:20 +0530)
committerAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Tue, 13 Jul 2021 08:58:22 +0000 (11:58 +0300)
Convert the legacy callback .suspend() and .resume()
to the generic ones.

While at it, replace ifdeffery by __maybe_unused attribute.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
drivers/gpio/gpio-ml-ioh.c

index 53d4abe..efa9acd 100644 (file)
@@ -155,11 +155,10 @@ static int ioh_gpio_direction_input(struct gpio_chip *gpio, unsigned nr)
        return 0;
 }
 
-#ifdef CONFIG_PM
 /*
  * Save register configuration and disable interrupts.
  */
-static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
+static void __maybe_unused ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
 {
        int i;
 
@@ -185,7 +184,7 @@ static void ioh_gpio_save_reg_conf(struct ioh_gpio *chip)
 /*
  * This function restores the register configuration of the GPIO device.
  */
-static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
+static void __maybe_unused ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
 {
        int i;
 
@@ -207,7 +206,6 @@ static void ioh_gpio_restore_reg_conf(struct ioh_gpio *chip)
                                  &chip->reg->ioh_sel_reg[i]);
        }
 }
-#endif
 
 static int ioh_gpio_to_irq(struct gpio_chip *gpio, unsigned offset)
 {
@@ -522,47 +520,23 @@ static void ioh_gpio_remove(struct pci_dev *pdev)
        kfree(chip);
 }
 
-#ifdef CONFIG_PM
-static int ioh_gpio_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused ioh_gpio_suspend(struct device *dev)
 {
-       s32 ret;
-       struct ioh_gpio *chip = pci_get_drvdata(pdev);
+       struct ioh_gpio *chip = dev_get_drvdata(dev);
        unsigned long flags;
 
        spin_lock_irqsave(&chip->spinlock, flags);
        ioh_gpio_save_reg_conf(chip);
        spin_unlock_irqrestore(&chip->spinlock, flags);
 
-       ret = pci_save_state(pdev);
-       if (ret) {
-               dev_err(&pdev->dev, "pci_save_state Failed-%d\n", ret);
-               return ret;
-       }
-       pci_disable_device(pdev);
-       pci_set_power_state(pdev, PCI_D0);
-       ret = pci_enable_wake(pdev, PCI_D0, 1);
-       if (ret)
-               dev_err(&pdev->dev, "pci_enable_wake Failed -%d\n", ret);
-
        return 0;
 }
 
-static int ioh_gpio_resume(struct pci_dev *pdev)
+static int __maybe_unused ioh_gpio_resume(struct device *dev)
 {
-       s32 ret;
-       struct ioh_gpio *chip = pci_get_drvdata(pdev);
+       struct ioh_gpio *chip = dev_get_drvdata(dev);
        unsigned long flags;
 
-       ret = pci_enable_wake(pdev, PCI_D0, 0);
-
-       pci_set_power_state(pdev, PCI_D0);
-       ret = pci_enable_device(pdev);
-       if (ret) {
-               dev_err(&pdev->dev, "pci_enable_device Failed-%d ", ret);
-               return ret;
-       }
-       pci_restore_state(pdev);
-
        spin_lock_irqsave(&chip->spinlock, flags);
        iowrite32(0x01, &chip->reg->srst);
        iowrite32(0x00, &chip->reg->srst);
@@ -571,10 +545,8 @@ static int ioh_gpio_resume(struct pci_dev *pdev)
 
        return 0;
 }
-#else
-#define ioh_gpio_suspend NULL
-#define ioh_gpio_resume NULL
-#endif
+
+static SIMPLE_DEV_PM_OPS(ioh_gpio_pm_ops, ioh_gpio_suspend, ioh_gpio_resume);
 
 static const struct pci_device_id ioh_gpio_pcidev_id[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_ROHM, 0x802E) },
@@ -587,8 +559,9 @@ static struct pci_driver ioh_gpio_driver = {
        .id_table = ioh_gpio_pcidev_id,
        .probe = ioh_gpio_probe,
        .remove = ioh_gpio_remove,
-       .suspend = ioh_gpio_suspend,
-       .resume = ioh_gpio_resume
+       .driver = {
+               .pm = &ioh_gpio_pm_ops,
+       },
 };
 
 module_pci_driver(ioh_gpio_driver);