linux-kernel-mentees.lists.linuxfoundation.org archive mirror
 help / color / mirror / Atom feed
* [Linux-kernel-mentees] [PATCH v1] mmc: via-sdmmc: use generic power management
@ 2020-07-20 14:26 Vaibhav Gupta
  2020-08-05  6:34 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Vaibhav Gupta @ 2020-07-20 14:26 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas, Bjorn Helgaas, Vaibhav Gupta,
	Bruce Chang, Harald Welte, Ulf Hansson
  Cc: linux-kernel-mentees, linux-mmc, linux-kernel, Vaibhav Gupta

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() and 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/mmc/host/via-sdmmc.c | 33 ++++++++-------------------------
 1 file changed, 8 insertions(+), 25 deletions(-)

diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
index ef95bce50889..49dab9f42b6d 100644
--- a/drivers/mmc/host/via-sdmmc.c
+++ b/drivers/mmc/host/via-sdmmc.c
@@ -1220,9 +1220,7 @@ static void via_sd_remove(struct pci_dev *pcidev)
 		pci_name(pcidev), (int)pcidev->vendor, (int)pcidev->device);
 }
 
-#ifdef CONFIG_PM
-
-static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
+static void __maybe_unused via_init_sdc_pm(struct via_crdr_mmc_host *host)
 {
 	struct sdhcreg *pm_sdhcreg;
 	void __iomem *addrbase;
@@ -1256,30 +1254,27 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
 	via_print_sdchc(host);
 }
 
-static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
+static int __maybe_unused via_sd_suspend(struct device *dev)
 {
 	struct via_crdr_mmc_host *host;
 
-	host = pci_get_drvdata(pcidev);
+	host = dev_get_drvdata(dev);
 
 	via_save_pcictrlreg(host);
 	via_save_sdcreg(host);
 
-	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_enable(dev);
 
 	return 0;
 }
 
-static int via_sd_resume(struct pci_dev *pcidev)
+static int __maybe_unused via_sd_resume(struct device *dev)
 {
 	struct via_crdr_mmc_host *sdhost;
 	int ret = 0;
 	u8 gatt;
 
-	sdhost = pci_get_drvdata(pcidev);
+	sdhost = dev_get_drvdata(dev);
 
 	gatt = VIA_CRDR_PCICLKGATT_PAD_PWRON;
 	if (sdhost->power == MMC_VDD_165_195)
@@ -1294,32 +1289,20 @@ static int via_sd_resume(struct pci_dev *pcidev)
 
 	msleep(100);
 
-	pci_set_power_state(pcidev, PCI_D0);
-	pci_restore_state(pcidev);
-	ret = pci_enable_device(pcidev);
-	if (ret)
-		return ret;
-
 	via_restore_pcictrlreg(sdhost);
 	via_init_sdc_pm(sdhost);
 
 	return ret;
 }
 
-#else /* CONFIG_PM */
-
-#define via_sd_suspend NULL
-#define via_sd_resume NULL
-
-#endif /* CONFIG_PM */
+static SIMPLE_DEV_PM_OPS(via_sd_pm_ops, via_sd_suspend, via_sd_resume);
 
 static struct pci_driver via_sd_driver = {
 	.name = DRV_NAME,
 	.id_table = via_ids,
 	.probe = via_sd_probe,
 	.remove = via_sd_remove,
-	.suspend = via_sd_suspend,
-	.resume = via_sd_resume,
+	.driver.pm = &via_sd_pm_ops,
 };
 
 module_pci_driver(via_sd_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] 2+ messages in thread

* Re: [Linux-kernel-mentees] [PATCH v1] mmc: via-sdmmc: use generic power management
  2020-07-20 14:26 [Linux-kernel-mentees] [PATCH v1] mmc: via-sdmmc: use generic power management Vaibhav Gupta
@ 2020-08-05  6:34 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2020-08-05  6:34 UTC (permalink / raw)
  To: Vaibhav Gupta
  Cc: Vaibhav Gupta, linux-mmc, Harald Welte, Bruce Chang,
	Bjorn Helgaas, Bjorn Helgaas, linux-kernel-mentees,
	Linux Kernel Mailing List

On Mon, 20 Jul 2020 at 16:28, 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_enable_wake() and pci_set_power_state() and 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>

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


> ---
>  drivers/mmc/host/via-sdmmc.c | 33 ++++++++-------------------------
>  1 file changed, 8 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/mmc/host/via-sdmmc.c b/drivers/mmc/host/via-sdmmc.c
> index ef95bce50889..49dab9f42b6d 100644
> --- a/drivers/mmc/host/via-sdmmc.c
> +++ b/drivers/mmc/host/via-sdmmc.c
> @@ -1220,9 +1220,7 @@ static void via_sd_remove(struct pci_dev *pcidev)
>                 pci_name(pcidev), (int)pcidev->vendor, (int)pcidev->device);
>  }
>
> -#ifdef CONFIG_PM
> -
> -static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
> +static void __maybe_unused via_init_sdc_pm(struct via_crdr_mmc_host *host)
>  {
>         struct sdhcreg *pm_sdhcreg;
>         void __iomem *addrbase;
> @@ -1256,30 +1254,27 @@ static void via_init_sdc_pm(struct via_crdr_mmc_host *host)
>         via_print_sdchc(host);
>  }
>
> -static int via_sd_suspend(struct pci_dev *pcidev, pm_message_t state)
> +static int __maybe_unused via_sd_suspend(struct device *dev)
>  {
>         struct via_crdr_mmc_host *host;
>
> -       host = pci_get_drvdata(pcidev);
> +       host = dev_get_drvdata(dev);
>
>         via_save_pcictrlreg(host);
>         via_save_sdcreg(host);
>
> -       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_enable(dev);
>
>         return 0;
>  }
>
> -static int via_sd_resume(struct pci_dev *pcidev)
> +static int __maybe_unused via_sd_resume(struct device *dev)
>  {
>         struct via_crdr_mmc_host *sdhost;
>         int ret = 0;
>         u8 gatt;
>
> -       sdhost = pci_get_drvdata(pcidev);
> +       sdhost = dev_get_drvdata(dev);
>
>         gatt = VIA_CRDR_PCICLKGATT_PAD_PWRON;
>         if (sdhost->power == MMC_VDD_165_195)
> @@ -1294,32 +1289,20 @@ static int via_sd_resume(struct pci_dev *pcidev)
>
>         msleep(100);
>
> -       pci_set_power_state(pcidev, PCI_D0);
> -       pci_restore_state(pcidev);
> -       ret = pci_enable_device(pcidev);
> -       if (ret)
> -               return ret;
> -
>         via_restore_pcictrlreg(sdhost);
>         via_init_sdc_pm(sdhost);
>
>         return ret;
>  }
>
> -#else /* CONFIG_PM */
> -
> -#define via_sd_suspend NULL
> -#define via_sd_resume NULL
> -
> -#endif /* CONFIG_PM */
> +static SIMPLE_DEV_PM_OPS(via_sd_pm_ops, via_sd_suspend, via_sd_resume);
>
>  static struct pci_driver via_sd_driver = {
>         .name = DRV_NAME,
>         .id_table = via_ids,
>         .probe = via_sd_probe,
>         .remove = via_sd_remove,
> -       .suspend = via_sd_suspend,
> -       .resume = via_sd_resume,
> +       .driver.pm = &via_sd_pm_ops,
>  };
>
>  module_pci_driver(via_sd_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	[flat|nested] 2+ messages in thread

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-20 14:26 [Linux-kernel-mentees] [PATCH v1] mmc: via-sdmmc: use generic power management Vaibhav Gupta
2020-08-05  6:34 ` 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).