linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] memstick: jmb38x_ms: use generic power management
@ 2020-07-20 11:16 Vaibhav Gupta
  2020-08-05  6:33 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Vaibhav Gupta @ 2020-07-20 11:16 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Maxim Levitsky, Alex Dubov, Ulf Hansson
  Cc: Vaibhav Gupta, Shuah Khan, linux-kernel, linux-kernel-mentees, linux-mmc

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_set_power_state() and pci_set_master() 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 to_pci_dev() and dev_get_drvdata() to get
"struct pci_dev*" variable and drv data.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
---
 drivers/memstick/host/jmb38x_ms.c | 38 +++++++++----------------------
 1 file changed, 11 insertions(+), 27 deletions(-)

diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index 0a9c5ddf2f59..2aa9592917d9 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -793,11 +793,10 @@ static int jmb38x_ms_pmos(struct pci_dev *pdev, int flag)
         return 0;
 }
 
-#ifdef CONFIG_PM
-
-static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
+static int __maybe_unused jmb38x_ms_suspend(struct device *dev)
 {
-	struct jmb38x_ms *jm = pci_get_drvdata(dev);
+	struct jmb38x_ms *jm = dev_get_drvdata(dev);
+
 	int cnt;
 
 	for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
@@ -806,26 +805,17 @@ static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
 		memstick_suspend_host(jm->hosts[cnt]);
 	}
 
-	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);
+
 	return 0;
 }
 
-static int jmb38x_ms_resume(struct pci_dev *dev)
+static int __maybe_unused jmb38x_ms_resume(struct device *dev)
 {
-	struct jmb38x_ms *jm = pci_get_drvdata(dev);
+	struct jmb38x_ms *jm = dev_get_drvdata(dev);
 	int rc;
 
-	pci_set_power_state(dev, PCI_D0);
-	pci_restore_state(dev);
-	rc = pci_enable_device(dev);
-	if (rc)
-		return rc;
-	pci_set_master(dev);
-
-	jmb38x_ms_pmos(dev, 1);
+	jmb38x_ms_pmos(to_pci_dev(dev), 1);
 
 	for (rc = 0; rc < jm->host_cnt; ++rc) {
 		if (!jm->hosts[rc])
@@ -837,13 +827,6 @@ static int jmb38x_ms_resume(struct pci_dev *dev)
 	return 0;
 }
 
-#else
-
-#define jmb38x_ms_suspend NULL
-#define jmb38x_ms_resume NULL
-
-#endif /* CONFIG_PM */
-
 static int jmb38x_ms_count_slots(struct pci_dev *pdev)
 {
 	int cnt, rc = 0;
@@ -1030,13 +1013,14 @@ static struct pci_device_id jmb38x_ms_id_tbl [] = {
 	{ }
 };
 
+static SIMPLE_DEV_PM_OPS(jmb38x_ms_pm_ops, jmb38x_ms_suspend, jmb38x_ms_resume);
+
 static struct pci_driver jmb38x_ms_driver = {
 	.name = DRIVER_NAME,
 	.id_table = jmb38x_ms_id_tbl,
 	.probe = jmb38x_ms_probe,
 	.remove = jmb38x_ms_remove,
-	.suspend = jmb38x_ms_suspend,
-	.resume = jmb38x_ms_resume
+	.driver.pm = &jmb38x_ms_pm_ops,
 };
 
 module_pci_driver(jmb38x_ms_driver);
-- 
2.27.0


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

* Re: [PATCH v1] memstick: jmb38x_ms: use generic power management
  2020-07-20 11:16 [PATCH v1] memstick: jmb38x_ms: use generic power management Vaibhav Gupta
@ 2020-08-05  6:33 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2020-08-05  6:33 UTC (permalink / raw)
  To: Vaibhav Gupta
  Cc: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Maxim Levitsky, Alex Dubov, Shuah Khan,
	Linux Kernel Mailing List, linux-kernel-mentees, linux-mmc

On Mon, 20 Jul 2020 at 13:19, Vaibhav Gupta <vaibhavgupta40@gmail.com> wrote:
>
> 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_set_power_state() and pci_set_master() 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 to_pci_dev() and dev_get_drvdata() to get
> "struct pci_dev*" variable and drv data.
>
> Compile-tested only.
>
> Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>

Applied for next (a while ago), thanks!
Kind regards
Uffe


> ---
>  drivers/memstick/host/jmb38x_ms.c | 38 +++++++++----------------------
>  1 file changed, 11 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
> index 0a9c5ddf2f59..2aa9592917d9 100644
> --- a/drivers/memstick/host/jmb38x_ms.c
> +++ b/drivers/memstick/host/jmb38x_ms.c
> @@ -793,11 +793,10 @@ static int jmb38x_ms_pmos(struct pci_dev *pdev, int flag)
>          return 0;
>  }
>
> -#ifdef CONFIG_PM
> -
> -static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
> +static int __maybe_unused jmb38x_ms_suspend(struct device *dev)
>  {
> -       struct jmb38x_ms *jm = pci_get_drvdata(dev);
> +       struct jmb38x_ms *jm = dev_get_drvdata(dev);
> +
>         int cnt;
>
>         for (cnt = 0; cnt < jm->host_cnt; ++cnt) {
> @@ -806,26 +805,17 @@ static int jmb38x_ms_suspend(struct pci_dev *dev, pm_message_t state)
>                 memstick_suspend_host(jm->hosts[cnt]);
>         }
>
> -       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);
> +
>         return 0;
>  }
>
> -static int jmb38x_ms_resume(struct pci_dev *dev)
> +static int __maybe_unused jmb38x_ms_resume(struct device *dev)
>  {
> -       struct jmb38x_ms *jm = pci_get_drvdata(dev);
> +       struct jmb38x_ms *jm = dev_get_drvdata(dev);
>         int rc;
>
> -       pci_set_power_state(dev, PCI_D0);
> -       pci_restore_state(dev);
> -       rc = pci_enable_device(dev);
> -       if (rc)
> -               return rc;
> -       pci_set_master(dev);
> -
> -       jmb38x_ms_pmos(dev, 1);
> +       jmb38x_ms_pmos(to_pci_dev(dev), 1);
>
>         for (rc = 0; rc < jm->host_cnt; ++rc) {
>                 if (!jm->hosts[rc])
> @@ -837,13 +827,6 @@ static int jmb38x_ms_resume(struct pci_dev *dev)
>         return 0;
>  }
>
> -#else
> -
> -#define jmb38x_ms_suspend NULL
> -#define jmb38x_ms_resume NULL
> -
> -#endif /* CONFIG_PM */
> -
>  static int jmb38x_ms_count_slots(struct pci_dev *pdev)
>  {
>         int cnt, rc = 0;
> @@ -1030,13 +1013,14 @@ static struct pci_device_id jmb38x_ms_id_tbl [] = {
>         { }
>  };
>
> +static SIMPLE_DEV_PM_OPS(jmb38x_ms_pm_ops, jmb38x_ms_suspend, jmb38x_ms_resume);
> +
>  static struct pci_driver jmb38x_ms_driver = {
>         .name = DRIVER_NAME,
>         .id_table = jmb38x_ms_id_tbl,
>         .probe = jmb38x_ms_probe,
>         .remove = jmb38x_ms_remove,
> -       .suspend = jmb38x_ms_suspend,
> -       .resume = jmb38x_ms_resume
> +       .driver.pm = &jmb38x_ms_pm_ops,
>  };
>
>  module_pci_driver(jmb38x_ms_driver);
> --
> 2.27.0
>

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

end of thread, other threads:[~2020-08-05  6:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 11:16 [PATCH v1] memstick: jmb38x_ms: use generic power management Vaibhav Gupta
2020-08-05  6:33 ` Ulf Hansson

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