linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] spi: spi-topcliff-pch: use generic power management
@ 2020-07-20 15:57 Vaibhav Gupta
  2020-07-22 13:45 ` Mark Brown
  2020-07-24 10:51 ` Andy Shevchenko
  0 siblings, 2 replies; 21+ messages in thread
From: Vaibhav Gupta @ 2020-07-20 15:57 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta, Mark Brown
  Cc: Vaibhav Gupta, linux-spi, linux-kernel, linux-kernel-mentees, Shuah Khan

Drivers using legacy PM have to manage PCI states and device's PM states
themselves. They also need to take care of configuration registers.

With improved and powerful support of generic PM, PCI Core takes care of
above mentioned, device-independent, jobs.

This driver makes use of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), pci_enable_wake()
and pci_set_power_state() to do required operations. In generic mode, they
are no longer needed.

Change function parameter in both .suspend() and .resume() to
"struct device*" type. Use dev_get_drvdata() to get drv data.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/spi/spi-topcliff-pch.c | 51 +++++++++-------------------------
 1 file changed, 13 insertions(+), 38 deletions(-)

diff --git a/drivers/spi/spi-topcliff-pch.c b/drivers/spi/spi-topcliff-pch.c
index d7ea6af74743..281a90f1b5d8 100644
--- a/drivers/spi/spi-topcliff-pch.c
+++ b/drivers/spi/spi-topcliff-pch.c
@@ -1631,64 +1631,39 @@ static void pch_spi_remove(struct pci_dev *pdev)
 	kfree(pd_dev_save);
 }
 
-#ifdef CONFIG_PM
-static int pch_spi_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pch_spi_suspend(struct device *dev)
 {
-	int retval;
-	struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
+	struct pch_pd_dev_save *pd_dev_save = dev_get_drvdata(dev);
 
-	dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
+	dev_dbg(dev, "%s ENTRY\n", __func__);
 
 	pd_dev_save->board_dat->suspend_sts = true;
 
-	/* save config space */
-	retval = pci_save_state(pdev);
-	if (retval == 0) {
-		pci_enable_wake(pdev, PCI_D3hot, 0);
-		pci_disable_device(pdev);
-		pci_set_power_state(pdev, PCI_D3hot);
-	} else {
-		dev_err(&pdev->dev, "%s pci_save_state failed\n", __func__);
-	}
-
-	return retval;
+	return 0;
 }
 
-static int pch_spi_resume(struct pci_dev *pdev)
+static int __maybe_unused pch_spi_resume(struct device *dev)
 {
-	int retval;
-	struct pch_pd_dev_save *pd_dev_save = pci_get_drvdata(pdev);
-	dev_dbg(&pdev->dev, "%s ENTRY\n", __func__);
+	struct pch_pd_dev_save *pd_dev_save = dev_get_drvdata(dev);
 
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
+	dev_dbg(dev, "%s ENTRY\n", __func__);
 
-	retval = pci_enable_device(pdev);
-	if (retval < 0) {
-		dev_err(&pdev->dev,
-			"%s pci_enable_device failed\n", __func__);
-	} else {
-		pci_enable_wake(pdev, PCI_D3hot, 0);
+	device_wakeup_disable(dev);
 
-		/* set suspend status to false */
-		pd_dev_save->board_dat->suspend_sts = false;
-	}
+	/* set suspend status to false */
+	pd_dev_save->board_dat->suspend_sts = false;
 
-	return retval;
+	return 0;
 }
-#else
-#define pch_spi_suspend NULL
-#define pch_spi_resume NULL
 
-#endif
+static SIMPLE_DEV_PM_OPS(pch_spi_pm_ops, pch_spi_suspend, pch_spi_resume);
 
 static struct pci_driver pch_spi_pcidev_driver = {
 	.name = "pch_spi",
 	.id_table = pch_spi_pcidev_id,
 	.probe = pch_spi_probe,
 	.remove = pch_spi_remove,
-	.suspend = pch_spi_suspend,
-	.resume = pch_spi_resume,
+	.driver.pm = &pch_spi_pm_ops,
 };
 
 static int __init pch_spi_init(void)
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2020-07-28 16:32 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 15:57 [PATCH v1] spi: spi-topcliff-pch: use generic power management Vaibhav Gupta
2020-07-22 13:45 ` Mark Brown
2020-07-22 20:01   ` Vaibhav Gupta
2020-07-24 10:51 ` Andy Shevchenko
2020-07-24 15:16   ` Vaibhav Gupta
2020-07-24 20:16     ` Andy Shevchenko
2020-07-24 22:37       ` Bjorn Helgaas
2020-07-25 10:42         ` Andy Shevchenko
2020-07-25 10:44           ` Andy Shevchenko
2020-07-27  7:06             ` Vaibhav Gupta
2020-07-27 11:12               ` Andy Shevchenko
2020-07-27 13:08                 ` Vaibhav Gupta
2020-07-27 13:17       ` [PATCH v2] spi: spi-topcliff-pch: drop call to wakeup-disable Vaibhav Gupta
2020-07-27 13:38         ` Andy Shevchenko
2020-07-27 13:46           ` Vaibhav Gupta
2020-07-27 14:08             ` Andy Shevchenko
2020-07-27 14:17               ` Joe Perches
2020-07-27 17:29           ` [PATCH v3] " Vaibhav Gupta
2020-07-27 19:21             ` Andy Shevchenko
2020-07-28 16:31             ` Mark Brown
2020-07-28 16:31         ` [PATCH v2] " Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).