linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management
@ 2020-06-29  8:15 Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 1/5] cb710/core.c: " Vaibhav Gupta
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Linux Kernel Mentee: Remove Legacy Power Management.

The purpose of this patch series is to remove legacy power management callbacks
from amd ethernet drivers.

The callbacks performing suspend() and resume() operations are still calling
pci_save_state(), pci_set_power_state(), etc. and handling the power management
themselves, which is not recommended.

The conversion requires the removal of the those function calls and change the
callback definition accordingly and make use of dev_pm_ops structure.

All patches are compile-tested only.

Vaibhav Gupta (5):
  cb710/core.c: use generic power management
  cardreader/rtsx_pcr.c: use generic power management
  misc/tifm_7xx1.c: use generic power management
  misc/phantom.c: use generic power management
  misc/pch_phub.c: use generic power management

 drivers/misc/cardreader/rtsx_pcr.c | 27 +++++++----------
 drivers/misc/cb710/core.c          | 28 +++++------------
 drivers/misc/pch_phub.c            | 48 ++++++------------------------
 drivers/misc/phantom.c             | 20 +++++--------
 drivers/misc/tifm_7xx1.c           | 30 +++++--------------
 5 files changed, 42 insertions(+), 111 deletions(-)

-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH v1 1/5] cb710/core.c: use generic power management
  2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
@ 2020-06-29  8:15 ` Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 2/5] cardreader/rtsx_pcr.c: " Vaibhav Gupta
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Drivers should not use legacy power management as they have to manage power
states and related operations, for the device, themselves. This driver was
handling them with the help of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), etc.

With generic PM, all essentials will be handled by the PCI core. Driver
needs to do only device-specific operations.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/misc/cb710/core.c | 28 +++++++---------------------
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/misc/cb710/core.c b/drivers/misc/cb710/core.c
index b290bc2ee240..55b7ee0e8f93 100644
--- a/drivers/misc/cb710/core.c
+++ b/drivers/misc/cb710/core.c
@@ -166,37 +166,24 @@ void cb710_set_irq_handler(struct cb710_slot *slot,
 }
 EXPORT_SYMBOL_GPL(cb710_set_irq_handler);
 
-#ifdef CONFIG_PM
-
-static int cb710_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused cb710_suspend(struct device *dev_d)
 {
+	struct pci_dev *pdev = to_pci_dev(dev_d);
 	struct cb710_chip *chip = pci_get_drvdata(pdev);
 
 	devm_free_irq(&pdev->dev, pdev->irq, chip);
-	pci_save_state(pdev);
-	pci_disable_device(pdev);
-	if (state.event & PM_EVENT_SLEEP)
-		pci_set_power_state(pdev, PCI_D3hot);
 	return 0;
 }
 
-static int cb710_resume(struct pci_dev *pdev)
+static int __maybe_unused cb710_resume(struct device *dev_d)
 {
+	struct pci_dev *pdev = to_pci_dev(dev_d);
 	struct cb710_chip *chip = pci_get_drvdata(pdev);
-	int err;
-
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
-	err = pcim_enable_device(pdev);
-	if (err)
-		return err;
 
 	return devm_request_irq(&pdev->dev, pdev->irq,
 		cb710_irq_handler, IRQF_SHARED, KBUILD_MODNAME, chip);
 }
 
-#endif /* CONFIG_PM */
-
 static int cb710_probe(struct pci_dev *pdev,
 	const struct pci_device_id *ent)
 {
@@ -312,15 +299,14 @@ static const struct pci_device_id cb710_pci_tbl[] = {
 	{ 0, }
 };
 
+static SIMPLE_DEV_PM_OPS(cb710_pm_ops, cb710_suspend, cb710_resume);
+
 static struct pci_driver cb710_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = cb710_pci_tbl,
 	.probe = cb710_probe,
 	.remove = cb710_remove_one,
-#ifdef CONFIG_PM
-	.suspend = cb710_suspend,
-	.resume = cb710_resume,
-#endif
+	.driver.pm = &cb710_pm_ops,
 };
 
 static int __init cb710_init_module(void)
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH v1 2/5] cardreader/rtsx_pcr.c: use generic power management
  2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 1/5] cb710/core.c: " Vaibhav Gupta
@ 2020-06-29  8:15 ` Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 3/5] misc/tifm_7xx1.c: " Vaibhav Gupta
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Drivers should not use legacy power management as they have to manage power
states and related operations, for the device, themselves. This driver was
handling them with the help of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), etc.

With generic PM, all essentials will be handled by the  PCI core. Driver
needs to do only device-specific operations.

The driver was also using pci_enable_wake(...,..., 0) to disable wake. Use
device_wakeup_disable() instead.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/misc/cardreader/rtsx_pcr.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/misc/cardreader/rtsx_pcr.c b/drivers/misc/cardreader/rtsx_pcr.c
index 0d5928bc1b6d..ca5212cba1c0 100644
--- a/drivers/misc/cardreader/rtsx_pcr.c
+++ b/drivers/misc/cardreader/rtsx_pcr.c
@@ -1604,10 +1604,9 @@ static void rtsx_pci_remove(struct pci_dev *pcidev)
 		pci_name(pcidev), (int)pcidev->vendor, (int)pcidev->device);
 }
 
-#ifdef CONFIG_PM
-
-static int rtsx_pci_suspend(struct pci_dev *pcidev, pm_message_t state)
+static int __maybe_unused rtsx_pci_suspend(struct device *dev_d)
 {
+	struct pci_dev *pcidev = to_pci_dev(dev_d);
 	struct pcr_handle *handle;
 	struct rtsx_pcr *pcr;
 
@@ -1623,17 +1622,15 @@ static int rtsx_pci_suspend(struct pci_dev *pcidev, pm_message_t state)
 
 	rtsx_pci_power_off(pcr, HOST_ENTER_S3);
 
-	pci_save_state(pcidev);
-	pci_enable_wake(pcidev, pci_choose_state(pcidev, state), 0);
-	pci_disable_device(pcidev);
-	pci_set_power_state(pcidev, pci_choose_state(pcidev, state));
+	device_wakeup_disable(dev_d);
 
 	mutex_unlock(&pcr->pcr_mutex);
 	return 0;
 }
 
-static int rtsx_pci_resume(struct pci_dev *pcidev)
+static int __maybe_unused rtsx_pci_resume(struct device *dev_d)
 {
+	struct pci_dev *pcidev = to_pci_dev(dev_d);
 	struct pcr_handle *handle;
 	struct rtsx_pcr *pcr;
 	int ret = 0;
@@ -1645,11 +1642,6 @@ static int rtsx_pci_resume(struct pci_dev *pcidev)
 
 	mutex_lock(&pcr->pcr_mutex);
 
-	pci_set_power_state(pcidev, PCI_D0);
-	pci_restore_state(pcidev);
-	ret = pci_enable_device(pcidev);
-	if (ret)
-		goto out;
 	pci_set_master(pcidev);
 
 	ret = rtsx_pci_write_register(pcr, HOST_SLEEP_STATE, 0x03, 0x00);
@@ -1667,6 +1659,8 @@ static int rtsx_pci_resume(struct pci_dev *pcidev)
 	return ret;
 }
 
+#ifdef CONFIG_PM
+
 static void rtsx_pci_shutdown(struct pci_dev *pcidev)
 {
 	struct pcr_handle *handle;
@@ -1686,19 +1680,18 @@ static void rtsx_pci_shutdown(struct pci_dev *pcidev)
 
 #else /* CONFIG_PM */
 
-#define rtsx_pci_suspend NULL
-#define rtsx_pci_resume NULL
 #define rtsx_pci_shutdown NULL
 
 #endif /* CONFIG_PM */
 
+static SIMPLE_DEV_PM_OPS(rtsx_pci_pm_ops, rtsx_pci_suspend, rtsx_pci_resume);
+
 static struct pci_driver rtsx_pci_driver = {
 	.name = DRV_NAME_RTSX_PCI,
 	.id_table = rtsx_pci_ids,
 	.probe = rtsx_pci_probe,
 	.remove = rtsx_pci_remove,
-	.suspend = rtsx_pci_suspend,
-	.resume = rtsx_pci_resume,
+	.driver.pm = &rtsx_pci_pm_ops,
 	.shutdown = rtsx_pci_shutdown,
 };
 module_pci_driver(rtsx_pci_driver);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH v1 3/5] misc/tifm_7xx1.c: use generic power management
  2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 1/5] cb710/core.c: " Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 2/5] cardreader/rtsx_pcr.c: " Vaibhav Gupta
@ 2020-06-29  8:15 ` Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: " Vaibhav Gupta
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 5/5] misc/pch_phub.c: " Vaibhav Gupta
  4 siblings, 0 replies; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Drivers should not use legacy power management as they have to manage power
states and related operations, for the device, themselves. This driver was
handling them with the help of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), etc.

With generic PM, all essentials will be handled by the PCI core. Driver
needs to do only device-specific operations.

The driver was also using pci_enable_wake(...,..., 0) to disable wake. Use
device_wakeup_disable() instead.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/misc/tifm_7xx1.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index e6b40aa8fb42..228f2eb1d476 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -207,10 +207,9 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
 	spin_unlock_irqrestore(&fm->lock, flags);
 }
 
-#ifdef CONFIG_PM
-
-static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
+static int __maybe_unused tifm_7xx1_suspend(struct device *dev_d)
 {
+	struct pci_dev *dev = to_pci_dev(dev_d);
 	struct tifm_adapter *fm = pci_get_drvdata(dev);
 	int cnt;
 
@@ -221,15 +220,13 @@ static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
 			tifm_7xx1_sock_power_off(fm->sockets[cnt]->addr);
 	}
 
-	pci_save_state(dev);
-	pci_enable_wake(dev, pci_choose_state(dev, state), 0);
-	pci_disable_device(dev);
-	pci_set_power_state(dev, pci_choose_state(dev, state));
+	device_wakeup_disable(dev_d);
 	return 0;
 }
 
-static int tifm_7xx1_resume(struct pci_dev *dev)
+static int __maybe_unused tifm_7xx1_resume(struct device *dev_d)
 {
+	struct pci_dev *dev = to_pci_dev(dev_d);
 	struct tifm_adapter *fm = pci_get_drvdata(dev);
 	int rc;
 	unsigned long timeout;
@@ -242,11 +239,6 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
 	if (WARN_ON(fm->num_sockets > ARRAY_SIZE(new_ids)))
 		return -ENXIO;
 
-	pci_set_power_state(dev, PCI_D0);
-	pci_restore_state(dev);
-	rc = pci_enable_device(dev);
-	if (rc)
-		return rc;
 	pci_set_master(dev);
 
 	dev_dbg(&dev->dev, "resuming host\n");
@@ -297,13 +289,6 @@ static int tifm_7xx1_resume(struct pci_dev *dev)
 	return 0;
 }
 
-#else
-
-#define tifm_7xx1_suspend NULL
-#define tifm_7xx1_resume NULL
-
-#endif /* CONFIG_PM */
-
 static int tifm_7xx1_dummy_has_ms_pif(struct tifm_adapter *fm,
 				      struct tifm_dev *sock)
 {
@@ -424,13 +409,14 @@ static const struct pci_device_id tifm_7xx1_pci_tbl[] = {
 	{ }
 };
 
+static SIMPLE_DEV_PM_OPS(tifm_7xx1_pm_ops, tifm_7xx1_suspend, tifm_7xx1_resume);
+
 static struct pci_driver tifm_7xx1_driver = {
 	.name = DRIVER_NAME,
 	.id_table = tifm_7xx1_pci_tbl,
 	.probe = tifm_7xx1_probe,
 	.remove = tifm_7xx1_remove,
-	.suspend = tifm_7xx1_suspend,
-	.resume = tifm_7xx1_resume,
+	.driver.pm = &tifm_7xx1_pm_ops,
 };
 
 module_pci_driver(tifm_7xx1_driver);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: use generic power management
  2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
                   ` (2 preceding siblings ...)
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 3/5] misc/tifm_7xx1.c: " Vaibhav Gupta
@ 2020-06-29  8:15 ` Vaibhav Gupta
  2020-06-30  8:19   ` Jiri Slaby
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 5/5] misc/pch_phub.c: " Vaibhav Gupta
  4 siblings, 1 reply; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

With the support of generic PM callbacks, drivers no longer need to use
legacy .suspend() and .resume() in which they had to maintain PCI states
changes and device's power state themselves. All required operations are
done by PCI core.

Driver needs to do only device-specific operations.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/misc/phantom.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index 6a5ed0e25ff1..ce72e46a2e73 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -457,31 +457,26 @@ static void phantom_remove(struct pci_dev *pdev)
 	pci_disable_device(pdev);
 }
 
-#ifdef CONFIG_PM
-static int phantom_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused phantom_suspend(struct device *dev_d)
 {
-	struct phantom_device *dev = pci_get_drvdata(pdev);
+	struct phantom_device *dev = dev_get_drvdata(dev_d);
 
 	iowrite32(0, dev->caddr + PHN_IRQCTL);
 	ioread32(dev->caddr + PHN_IRQCTL); /* PCI posting */
 
-	synchronize_irq(pdev->irq);
+	synchronize_irq(to_pci_dev(dev_d)->irq);
 
 	return 0;
 }
 
-static int phantom_resume(struct pci_dev *pdev)
+static int __maybe_unused phantom_resume(struct device *dev_d)
 {
-	struct phantom_device *dev = pci_get_drvdata(pdev);
+	struct phantom_device *dev = dev_get_drvdata(dev_d);
 
 	iowrite32(0, dev->caddr + PHN_IRQCTL);
 
 	return 0;
 }
-#else
-#define phantom_suspend	NULL
-#define phantom_resume	NULL
-#endif
 
 static struct pci_device_id phantom_pci_tbl[] = {
 	{ .vendor = PCI_VENDOR_ID_PLX, .device = PCI_DEVICE_ID_PLX_9050,
@@ -491,13 +486,14 @@ static struct pci_device_id phantom_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, phantom_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(phantom_pm_ops, phantom_suspend, phantom_resume);
+
 static struct pci_driver phantom_pci_driver = {
 	.name = "phantom",
 	.id_table = phantom_pci_tbl,
 	.probe = phantom_probe,
 	.remove = phantom_remove,
-	.suspend = phantom_suspend,
-	.resume = phantom_resume
+	.driver.pm = &phantom_pm_ops,
 };
 
 static CLASS_ATTR_STRING(version, 0444, PHANTOM_VERSION);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* [Linux-kernel-mentees] [PATCH v1 5/5] misc/pch_phub.c: use generic power management
  2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
                   ` (3 preceding siblings ...)
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: " Vaibhav Gupta
@ 2020-06-29  8:15 ` Vaibhav Gupta
  4 siblings, 0 replies; 7+ messages in thread
From: Vaibhav Gupta @ 2020-06-29  8:15 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, bjorn, Vaibhav Gupta,
	Arnd Bergmann, Greg Kroah-Hartman, Jiri Slaby, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel, Vaibhav Gupta

Drivers should not use legacy power management as they have to manage power
states and related operations, for the device, themselves. This driver was
handling them with the help of PCI helper functions like
pci_save/restore_state(), pci_enable/disable_device(), etc.

With generic PM, all essentials will be handled by the PCI core. Driver
needs to do only device-specific operations.

The driver was also using pci_enable_wake(...,..., 0) to disable wake. Use
device_wakeup_disable() instead. It was also saving device register
configuration using pch_phub_save/restore_reg_conf() which is not
recommended.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/misc/pch_phub.c | 48 ++++++++---------------------------------
 1 file changed, 9 insertions(+), 39 deletions(-)

diff --git a/drivers/misc/pch_phub.c b/drivers/misc/pch_phub.c
index 60828af7506a..9321d4239932 100644
--- a/drivers/misc/pch_phub.c
+++ b/drivers/misc/pch_phub.c
@@ -147,9 +147,8 @@ static void pch_phub_read_modify_write_reg(struct pch_phub_reg *chip,
 	iowrite32(((ioread32(reg_addr) & ~mask)) | data, reg_addr);
 }
 
-#ifdef CONFIG_PM
 /* pch_phub_save_reg_conf - saves register configuration */
-static void pch_phub_save_reg_conf(struct pci_dev *pdev)
+static void __maybe_unused pch_phub_save_reg_conf(struct pci_dev *pdev)
 {
 	unsigned int i;
 	struct pch_phub_reg *chip = pci_get_drvdata(pdev);
@@ -210,7 +209,7 @@ static void pch_phub_save_reg_conf(struct pci_dev *pdev)
 }
 
 /* pch_phub_restore_reg_conf - restore register configuration */
-static void pch_phub_restore_reg_conf(struct pci_dev *pdev)
+static void __maybe_unused pch_phub_restore_reg_conf(struct pci_dev *pdev)
 {
 	unsigned int i;
 	struct pch_phub_reg *chip = pci_get_drvdata(pdev);
@@ -270,7 +269,6 @@ static void pch_phub_restore_reg_conf(struct pci_dev *pdev)
 	if ((chip->ioh_type == 2) || (chip->ioh_type == 4))
 		iowrite32(chip->funcsel_reg, p + FUNCSEL_REG_OFFSET);
 }
-#endif
 
 /**
  * pch_phub_read_serial_rom() - Reading Serial ROM
@@ -835,48 +833,19 @@ static void pch_phub_remove(struct pci_dev *pdev)
 	kfree(chip);
 }
 
-#ifdef CONFIG_PM
-
-static int pch_phub_suspend(struct pci_dev *pdev, pm_message_t state)
+static int __maybe_unused pch_phub_suspend(struct device *dev_d)
 {
-	int ret;
-
-	pch_phub_save_reg_conf(pdev);
-	ret = pci_save_state(pdev);
-	if (ret) {
-		dev_err(&pdev->dev,
-			" %s -pci_save_state returns %d\n", __func__, ret);
-		return ret;
-	}
-	pci_enable_wake(pdev, PCI_D3hot, 0);
-	pci_disable_device(pdev);
-	pci_set_power_state(pdev, pci_choose_state(pdev, state));
+	device_wakeup_disable(dev_d);
 
 	return 0;
 }
 
-static int pch_phub_resume(struct pci_dev *pdev)
+static int __maybe_unused pch_phub_resume(struct device *dev_d)
 {
-	int ret;
-
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
-	ret = pci_enable_device(pdev);
-	if (ret) {
-		dev_err(&pdev->dev,
-		"%s-pci_enable_device failed(ret=%d) ", __func__, ret);
-		return ret;
-	}
-
-	pci_enable_wake(pdev, PCI_D3hot, 0);
-	pch_phub_restore_reg_conf(pdev);
+	device_wakeup_disable(dev_d);
 
 	return 0;
 }
-#else
-#define pch_phub_suspend NULL
-#define pch_phub_resume NULL
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id pch_phub_pcidev_id[] = {
 	{ PCI_VDEVICE(INTEL, PCI_DEVICE_ID_PCH1_PHUB),       1,  },
@@ -888,13 +857,14 @@ static const struct pci_device_id pch_phub_pcidev_id[] = {
 };
 MODULE_DEVICE_TABLE(pci, pch_phub_pcidev_id);
 
+static SIMPLE_DEV_PM_OPS(pch_phub_pm_ops, pch_phub_suspend, pch_phub_resume);
+
 static struct pci_driver pch_phub_driver = {
 	.name = "pch_phub",
 	.id_table = pch_phub_pcidev_id,
 	.probe = pch_phub_probe,
 	.remove = pch_phub_remove,
-	.suspend = pch_phub_suspend,
-	.resume = pch_phub_resume
+	.driver.pm = &pch_phub_pm_ops,
 };
 
 module_pci_driver(pch_phub_driver);
-- 
2.27.0

_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

* Re: [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: use generic power management
  2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: " Vaibhav Gupta
@ 2020-06-30  8:19   ` Jiri Slaby
  0 siblings, 0 replies; 7+ messages in thread
From: Jiri Slaby @ 2020-06-30  8:19 UTC (permalink / raw)
  To: Vaibhav Gupta, Bjorn Helgaas, Bjorn Helgaas, bjorn,
	Vaibhav Gupta, Arnd Bergmann, Greg Kroah-Hartman, Alex Dubov
  Cc: linux-kernel-mentees, linux-kernel

On 29. 06. 20, 10:15, Vaibhav Gupta wrote:
> With the support of generic PM callbacks, drivers no longer need to use
> legacy .suspend() and .resume() in which they had to maintain PCI states
> changes and device's power state themselves. All required operations are
> done by PCI core.
> 
> Driver needs to do only device-specific operations.
> 
> Compile-tested only.
> 
> Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>

From the driver's POV:
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>

> ---
>  drivers/misc/phantom.c | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
> index 6a5ed0e25ff1..ce72e46a2e73 100644
> --- a/drivers/misc/phantom.c
> +++ b/drivers/misc/phantom.c
> @@ -457,31 +457,26 @@ static void phantom_remove(struct pci_dev *pdev)
>  	pci_disable_device(pdev);
>  }
>  
> -#ifdef CONFIG_PM
> -static int phantom_suspend(struct pci_dev *pdev, pm_message_t state)
> +static int __maybe_unused phantom_suspend(struct device *dev_d)
>  {
> -	struct phantom_device *dev = pci_get_drvdata(pdev);
> +	struct phantom_device *dev = dev_get_drvdata(dev_d);
>  
>  	iowrite32(0, dev->caddr + PHN_IRQCTL);
>  	ioread32(dev->caddr + PHN_IRQCTL); /* PCI posting */
>  
> -	synchronize_irq(pdev->irq);
> +	synchronize_irq(to_pci_dev(dev_d)->irq);
>  
>  	return 0;
>  }
>  
> -static int phantom_resume(struct pci_dev *pdev)
> +static int __maybe_unused phantom_resume(struct device *dev_d)
>  {
> -	struct phantom_device *dev = pci_get_drvdata(pdev);
> +	struct phantom_device *dev = dev_get_drvdata(dev_d);
>  
>  	iowrite32(0, dev->caddr + PHN_IRQCTL);
>  
>  	return 0;
>  }
> -#else
> -#define phantom_suspend	NULL
> -#define phantom_resume	NULL
> -#endif
>  
>  static struct pci_device_id phantom_pci_tbl[] = {
>  	{ .vendor = PCI_VENDOR_ID_PLX, .device = PCI_DEVICE_ID_PLX_9050,
> @@ -491,13 +486,14 @@ static struct pci_device_id phantom_pci_tbl[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, phantom_pci_tbl);
>  
> +static SIMPLE_DEV_PM_OPS(phantom_pm_ops, phantom_suspend, phantom_resume);
> +
>  static struct pci_driver phantom_pci_driver = {
>  	.name = "phantom",
>  	.id_table = phantom_pci_tbl,
>  	.probe = phantom_probe,
>  	.remove = phantom_remove,
> -	.suspend = phantom_suspend,
> -	.resume = phantom_resume
> +	.driver.pm = &phantom_pm_ops,
>  };
>  
>  static CLASS_ATTR_STRING(version, 0444, PHANTOM_VERSION);
> 


-- 
js
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

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

end of thread, other threads:[~2020-06-30  8:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  8:15 [Linux-kernel-mentees] [PATCH v1 0/5] misc: use generic power management Vaibhav Gupta
2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 1/5] cb710/core.c: " Vaibhav Gupta
2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 2/5] cardreader/rtsx_pcr.c: " Vaibhav Gupta
2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 3/5] misc/tifm_7xx1.c: " Vaibhav Gupta
2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 4/5] misc/phantom.c: " Vaibhav Gupta
2020-06-30  8:19   ` Jiri Slaby
2020-06-29  8:15 ` [Linux-kernel-mentees] [PATCH v1 5/5] misc/pch_phub.c: " Vaibhav Gupta

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).