Commit c1a47776 authored by Vaibhav Gupta's avatar Vaibhav Gupta Committed by Bartlomiej Zolnierkiewicz

fbdev: aty128fb: 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,
- aty128_pci_suspend() had a "pm_message_t" type parameter as per legacy
  PCI PM framework that got deprecated in generic.
- Rename the callback as aty128_pci_suspend_late() and preserve the
  parameter.
- Define 3 new callbacks as:
        * aty128_pci_suspend()
        * aty128_pci_freeze()
        * aty128_pci_hibernate()
  which in turn call aty128_pci_suspend_late() by passing appropriate
  value for "pm_message_t" type parameter.
- Bind the callbacks in "struct dev_pm_ops" type variable
  "aty128_pci_pm_ops".
Signed-off-by: default avatarVaibhav 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: default avatarBartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200819185654.151170-6-vaibhavgupta40@gmail.com
parent 348b2956
......@@ -162,10 +162,22 @@ static char * const r128_family[] = {
static int aty128_probe(struct pci_dev *pdev,
const struct pci_device_id *ent);
static void aty128_remove(struct pci_dev *pdev);
static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state);
static int aty128_pci_resume(struct pci_dev *pdev);
static int aty128_pci_suspend_late(struct device *dev, pm_message_t state);
static int __maybe_unused aty128_pci_suspend(struct device *dev);
static int __maybe_unused aty128_pci_hibernate(struct device *dev);
static int __maybe_unused aty128_pci_freeze(struct device *dev);
static int __maybe_unused aty128_pci_resume(struct device *dev);
static int aty128_do_resume(struct pci_dev *pdev);
static const struct dev_pm_ops aty128_pci_pm_ops = {
.suspend = aty128_pci_suspend,
.resume = aty128_pci_resume,
.freeze = aty128_pci_freeze,
.thaw = aty128_pci_resume,
.poweroff = aty128_pci_hibernate,
.restore = aty128_pci_resume,
};
/* supported Rage128 chipsets */
static const struct pci_device_id aty128_pci_tbl[] = {
{ PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RAGE128_LE,
......@@ -272,8 +284,7 @@ static struct pci_driver aty128fb_driver = {
.id_table = aty128_pci_tbl,
.probe = aty128_probe,
.remove = aty128_remove,
.suspend = aty128_pci_suspend,
.resume = aty128_pci_resume,
.driver.pm = &aty128_pci_pm_ops,
};
/* packed BIOS settings */
......@@ -2316,7 +2327,6 @@ static int aty128fb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
{
u32 pmgt;
struct pci_dev *pdev = par->pdev;
if (!par->pdev->pm_cap)
return;
......@@ -2343,23 +2353,15 @@ static void aty128_set_suspend(struct aty128fb_par *par, int suspend)
aty_st_le32(BUS_CNTL1, 0x00000010);
aty_st_le32(MEM_POWER_MISC, 0x0c830000);
msleep(100);
/* Switch PCI power management to D2 */
pci_set_power_state(pdev, PCI_D2);
}
}
static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
static int aty128_pci_suspend_late(struct device *dev, pm_message_t state)
{
struct pci_dev *pdev = to_pci_dev(dev);
struct fb_info *info = pci_get_drvdata(pdev);
struct aty128fb_par *par = info->par;
/* Because we may change PCI D state ourselves, we need to
* first save the config space content so the core can
* restore it properly on resume.
*/
pci_save_state(pdev);
/* We don't do anything but D2, for now we return 0, but
* we may want to change that. How do we know if the BIOS
* can properly take care of D3 ? Also, with swsusp, we
......@@ -2418,6 +2420,21 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
return 0;
}
static int __maybe_unused aty128_pci_suspend(struct device *dev)
{
return aty128_pci_suspend_late(dev, PMSG_SUSPEND);
}
static int __maybe_unused aty128_pci_hibernate(struct device *dev)
{
return aty128_pci_suspend_late(dev, PMSG_HIBERNATE);
}
static int __maybe_unused aty128_pci_freeze(struct device *dev)
{
return aty128_pci_suspend_late(dev, PMSG_FREEZE);
}
static int aty128_do_resume(struct pci_dev *pdev)
{
struct fb_info *info = pci_get_drvdata(pdev);
......@@ -2464,12 +2481,12 @@ static int aty128_do_resume(struct pci_dev *pdev)
return 0;
}
static int aty128_pci_resume(struct pci_dev *pdev)
static int __maybe_unused aty128_pci_resume(struct device *dev)
{
int rc;
console_lock();
rc = aty128_do_resume(pdev);
rc = aty128_do_resume(to_pci_dev(dev));
console_unlock();
return rc;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment