mt76: mt7921: Let PCI core handle power state and use pm_sleep_ptr()
authorKai-Heng Feng <kai.heng.feng@canonical.com>
Tue, 5 Jul 2022 14:23:04 +0000 (22:23 +0800)
committerFelix Fietkau <nbd@nbd.name>
Mon, 11 Jul 2022 11:40:03 +0000 (13:40 +0200)
PCI power state and wakeup are already handled by PCI core, so it's not
necessary to handle them in the driver.

Also switch to use pm_sleep_ptr() to remove #ifdef guard.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/pci.c

index 06af352..ea3069d 100644 (file)
@@ -358,9 +358,9 @@ static void mt7921_pci_remove(struct pci_dev *pdev)
        pci_free_irq_vectors(pdev);
 }
 
-#ifdef CONFIG_PM
-static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+static int mt7921_pci_suspend(struct device *device)
 {
+       struct pci_dev *pdev = to_pci_dev(device);
        struct mt76_dev *mdev = pci_get_drvdata(pdev);
        struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
        struct mt76_connac_pm *pm = &dev->pm;
@@ -390,8 +390,6 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
                napi_disable(&mdev->napi[i]);
        }
 
-       pci_enable_wake(pdev, pci_choose_state(pdev, state), true);
-
        /* wait until dma is idle  */
        mt76_poll(dev, MT_WFDMA0_GLO_CFG,
                  MT_WFDMA0_GLO_CFG_TX_DMA_BUSY |
@@ -411,8 +409,6 @@ static int mt7921_pci_suspend(struct pci_dev *pdev, pm_message_t state)
        if (err)
                goto restore_napi;
 
-       pci_save_state(pdev);
-       err = pci_set_power_state(pdev, pci_choose_state(pdev, state));
        if (err)
                goto restore_napi;
 
@@ -435,19 +431,14 @@ restore_suspend:
        return err;
 }
 
-static int mt7921_pci_resume(struct pci_dev *pdev)
+static int mt7921_pci_resume(struct device *device)
 {
+       struct pci_dev *pdev = to_pci_dev(device);
        struct mt76_dev *mdev = pci_get_drvdata(pdev);
        struct mt7921_dev *dev = container_of(mdev, struct mt7921_dev, mt76);
        struct mt76_connac_pm *pm = &dev->pm;
        int i, err;
 
-       err = pci_set_power_state(pdev, PCI_D0);
-       if (err)
-               return err;
-
-       pci_restore_state(pdev);
-
        err = mt7921_mcu_drv_pmctrl(dev);
        if (err < 0)
                return err;
@@ -487,17 +478,15 @@ static int mt7921_pci_resume(struct pci_dev *pdev)
 
        return err;
 }
-#endif /* CONFIG_PM */
+
+static DEFINE_SIMPLE_DEV_PM_OPS(mt7921_pm_ops, mt7921_pci_suspend, mt7921_pci_resume);
 
 static struct pci_driver mt7921_pci_driver = {
        .name           = KBUILD_MODNAME,
        .id_table       = mt7921_pci_device_table,
        .probe          = mt7921_pci_probe,
        .remove         = mt7921_pci_remove,
-#ifdef CONFIG_PM
-       .suspend        = mt7921_pci_suspend,
-       .resume         = mt7921_pci_resume,
-#endif /* CONFIG_PM */
+       .driver.pm      = pm_sleep_ptr(&mt7921_pm_ops),
 };
 
 module_pci_driver(mt7921_pci_driver);