Skip to content

Commit 6d11118

Browse files
VARoDeKbzolnier
authored andcommitted
fbdev: nvidia: 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, - nvidiafb_suspend() had a "pm_message_t" type parameter as per legacy PCI PM framework that got deprecated in generic. - Rename the callback as nvidiafb_suspend_late() and preserve the parameter. - Define 3 new callbacks as: * nvidiafb_suspend() * nvidiafb_freeze() * nvidiafb_hibernate() which in turn call nvidiafb_suspend_late() by passing appropriate value for "pm_message_t" type parameter. - Bind the callbacks in "struct dev_pm_ops" type variable "nvidiafb_pm_ops". Signed-off-by: Vaibhav Gupta <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Bjorn Helgaas <[email protected]> Cc: Vaibhav Gupta <[email protected]> Cc: Sam Ravnborg <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Russell King <[email protected]> Cc: Andres Salomon <[email protected]> CC: Antonino Daplas <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Bartlomiej Zolnierkiewicz <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c1a4777 commit 6d11118

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

drivers/video/fbdev/nvidia/nvidia.c

+35-29
Original file line numberDiff line numberDiff line change
@@ -1037,10 +1037,9 @@ static struct fb_ops nvidia_fb_ops = {
10371037
.fb_sync = nvidiafb_sync,
10381038
};
10391039

1040-
#ifdef CONFIG_PM
1041-
static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg)
1040+
static int nvidiafb_suspend_late(struct device *dev, pm_message_t mesg)
10421041
{
1043-
struct fb_info *info = pci_get_drvdata(dev);
1042+
struct fb_info *info = dev_get_drvdata(dev);
10441043
struct nvidia_par *par = info->par;
10451044

10461045
if (mesg.event == PM_EVENT_PRETHAW)
@@ -1052,46 +1051,54 @@ static int nvidiafb_suspend(struct pci_dev *dev, pm_message_t mesg)
10521051
fb_set_suspend(info, 1);
10531052
nvidiafb_blank(FB_BLANK_POWERDOWN, info);
10541053
nvidia_write_regs(par, &par->SavedReg);
1055-
pci_save_state(dev);
1056-
pci_disable_device(dev);
1057-
pci_set_power_state(dev, pci_choose_state(dev, mesg));
10581054
}
1059-
dev->dev.power.power_state = mesg;
1055+
dev->power.power_state = mesg;
10601056

10611057
console_unlock();
10621058
return 0;
10631059
}
10641060

1065-
static int nvidiafb_resume(struct pci_dev *dev)
1061+
static int __maybe_unused nvidiafb_suspend(struct device *dev)
10661062
{
1067-
struct fb_info *info = pci_get_drvdata(dev);
1068-
struct nvidia_par *par = info->par;
1063+
return nvidiafb_suspend_late(dev, PMSG_SUSPEND);
1064+
}
10691065

1070-
console_lock();
1071-
pci_set_power_state(dev, PCI_D0);
1066+
static int __maybe_unused nvidiafb_hibernate(struct device *dev)
1067+
{
1068+
return nvidiafb_suspend_late(dev, PMSG_HIBERNATE);
1069+
}
10721070

1073-
if (par->pm_state != PM_EVENT_FREEZE) {
1074-
pci_restore_state(dev);
1071+
static int __maybe_unused nvidiafb_freeze(struct device *dev)
1072+
{
1073+
return nvidiafb_suspend_late(dev, PMSG_FREEZE);
1074+
}
10751075

1076-
if (pci_enable_device(dev))
1077-
goto fail;
1076+
static int __maybe_unused nvidiafb_resume(struct device *dev)
1077+
{
1078+
struct fb_info *info = dev_get_drvdata(dev);
1079+
struct nvidia_par *par = info->par;
10781080

1079-
pci_set_master(dev);
1080-
}
1081+
console_lock();
10811082

10821083
par->pm_state = PM_EVENT_ON;
10831084
nvidiafb_set_par(info);
10841085
fb_set_suspend (info, 0);
10851086
nvidiafb_blank(FB_BLANK_UNBLANK, info);
10861087

1087-
fail:
10881088
console_unlock();
10891089
return 0;
10901090
}
1091-
#else
1092-
#define nvidiafb_suspend NULL
1093-
#define nvidiafb_resume NULL
1094-
#endif
1091+
1092+
static const struct dev_pm_ops nvidiafb_pm_ops = {
1093+
#ifdef CONFIG_PM_SLEEP
1094+
.suspend = nvidiafb_suspend,
1095+
.resume = nvidiafb_resume,
1096+
.freeze = nvidiafb_freeze,
1097+
.thaw = nvidiafb_resume,
1098+
.poweroff = nvidiafb_hibernate,
1099+
.restore = nvidiafb_resume,
1100+
#endif /* CONFIG_PM_SLEEP */
1101+
};
10951102

10961103
static int nvidia_set_fbinfo(struct fb_info *info)
10971104
{
@@ -1492,12 +1499,11 @@ static int nvidiafb_setup(char *options)
14921499
#endif /* !MODULE */
14931500

14941501
static struct pci_driver nvidiafb_driver = {
1495-
.name = "nvidiafb",
1496-
.id_table = nvidiafb_pci_tbl,
1497-
.probe = nvidiafb_probe,
1498-
.suspend = nvidiafb_suspend,
1499-
.resume = nvidiafb_resume,
1500-
.remove = nvidiafb_remove,
1502+
.name = "nvidiafb",
1503+
.id_table = nvidiafb_pci_tbl,
1504+
.probe = nvidiafb_probe,
1505+
.driver.pm = &nvidiafb_pm_ops,
1506+
.remove = nvidiafb_remove,
15011507
};
15021508

15031509
/* ------------------------------------------------------------------------- *

0 commit comments

Comments
 (0)