fbdev: savagefb: use generic power management

Drivers should do only device-specific jobs. But in general, drivers using
legacy PCI PM framework for .suspend()/.resume() have to manage many PCI
PM-related tasks themselves which can be done by PCI Core itself. This
brings extra load on the driver and it directly calls PCI helper functions
to handle them.

Switch to the new generic framework by updating function signatures and
define a "struct dev_pm_ops" variable to bind PM callbacks. Also, remove
unnecessary calls to the PCI Helper functions along with the legacy
.suspend & .resume bindings.

Now,
- savagefb_suspend() had a "pm_message_t" type parameter as per legacy
  PCI PM framework that got deprecated in generic.
- Rename the callback as savagefb_suspend_late() and preserve the
  parameter.
- Define 3 new callbacks as:
        * savagefb_suspend()
        * savagefb_freeze()
        * savagefb_hibernate()
  which in turn call savagefb_suspend_late() by passing appropriate value
  for "pm_message_t" type parameter.
- Bind the callbacks in "struct dev_pm_ops" type variable
  "savagefb_pm_ops".

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Cc: Bjorn Helgaas <helgaas@kernel.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Bjorn Helgaas <bjorn@helgaas.com>
Cc: Vaibhav Gupta <vaibhav.varodek@gmail.com>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Andres Salomon <dilinger@queued.net>
CC: Antonino Daplas <adaplas@gmail.com>
Cc: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200819185654.151170-8-vaibhavgupta40@gmail.com
This commit is contained in:
Vaibhav Gupta 2020-08-20 00:26:49 +05:30 коммит произвёл Bartlomiej Zolnierkiewicz
Родитель 6d11118758
Коммит a4ba7df57e
1 изменённых файлов: 32 добавлений и 20 удалений

Просмотреть файл

@ -2347,9 +2347,9 @@ static void savagefb_remove(struct pci_dev *dev)
}
}
static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg)
static int savagefb_suspend_late(struct device *dev, pm_message_t mesg)
{
struct fb_info *info = pci_get_drvdata(dev);
struct fb_info *info = dev_get_drvdata(dev);
struct savagefb_par *par = info->par;
DBG("savagefb_suspend");
@ -2357,7 +2357,7 @@ static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg)
if (mesg.event == PM_EVENT_PRETHAW)
mesg.event = PM_EVENT_FREEZE;
par->pm_state = mesg.event;
dev->dev.power.power_state = mesg;
dev->power.power_state = mesg;
/*
* For PM_EVENT_FREEZE, do not power down so the console
@ -2375,17 +2375,29 @@ static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg)
savagefb_blank(FB_BLANK_POWERDOWN, info);
savage_set_default_par(par, &par->save);
savage_disable_mmio(par);
pci_save_state(dev);
pci_disable_device(dev);
pci_set_power_state(dev, pci_choose_state(dev, mesg));
console_unlock();
return 0;
}
static int savagefb_resume(struct pci_dev* dev)
static int __maybe_unused savagefb_suspend(struct device *dev)
{
struct fb_info *info = pci_get_drvdata(dev);
return savagefb_suspend_late(dev, PMSG_SUSPEND);
}
static int __maybe_unused savagefb_hibernate(struct device *dev)
{
return savagefb_suspend_late(dev, PMSG_HIBERNATE);
}
static int __maybe_unused savagefb_freeze(struct device *dev)
{
return savagefb_suspend_late(dev, PMSG_FREEZE);
}
static int __maybe_unused savagefb_resume(struct device *dev)
{
struct fb_info *info = dev_get_drvdata(dev);
struct savagefb_par *par = info->par;
int cur_state = par->pm_state;
@ -2397,20 +2409,11 @@ static int savagefb_resume(struct pci_dev* dev)
* The adapter was not powered down coming back from a
* PM_EVENT_FREEZE.
*/
if (cur_state == PM_EVENT_FREEZE) {
pci_set_power_state(dev, PCI_D0);
if (cur_state == PM_EVENT_FREEZE)
return 0;
}
console_lock();
pci_set_power_state(dev, PCI_D0);
pci_restore_state(dev);
if (pci_enable_device(dev))
DBG("err");
pci_set_master(dev);
savage_enable_mmio(par);
savage_init_hw(par);
savagefb_set_par(info);
@ -2421,6 +2424,16 @@ static int savagefb_resume(struct pci_dev* dev)
return 0;
}
static const struct dev_pm_ops savagefb_pm_ops = {
#ifdef CONFIG_PM_SLEEP
.suspend = savagefb_suspend,
.resume = savagefb_resume,
.freeze = savagefb_freeze,
.thaw = savagefb_resume,
.poweroff = savagefb_hibernate,
.restore = savagefb_resume,
#endif
};
static const struct pci_device_id savagefb_devices[] = {
{PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128,
@ -2501,8 +2514,7 @@ static struct pci_driver savagefb_driver = {
.name = "savagefb",
.id_table = savagefb_devices,
.probe = savagefb_probe,
.suspend = savagefb_suspend,
.resume = savagefb_resume,
.driver.pm = &savagefb_pm_ops,
.remove = savagefb_remove,
};