Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <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-7-vaibhavgupta40@gmail.com

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
6d111187 c1a47776

+36 -30
+36 -30
drivers/video/fbdev/nvidia/nvidia.c
··· 1037 1037 .fb_sync = nvidiafb_sync, 1038 1038 }; 1039 1039 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) 1042 1041 { 1043 - struct fb_info *info = pci_get_drvdata(dev); 1042 + struct fb_info *info = dev_get_drvdata(dev); 1044 1043 struct nvidia_par *par = info->par; 1045 1044 1046 1045 if (mesg.event == PM_EVENT_PRETHAW) ··· 1051 1052 fb_set_suspend(info, 1); 1052 1053 nvidiafb_blank(FB_BLANK_POWERDOWN, info); 1053 1054 nvidia_write_regs(par, &par->SavedReg); 1054 - pci_save_state(dev); 1055 - pci_disable_device(dev); 1056 - pci_set_power_state(dev, pci_choose_state(dev, mesg)); 1057 1055 } 1058 - dev->dev.power.power_state = mesg; 1056 + dev->power.power_state = mesg; 1059 1057 1060 1058 console_unlock(); 1061 1059 return 0; 1062 1060 } 1063 1061 1064 - static int nvidiafb_resume(struct pci_dev *dev) 1062 + static int __maybe_unused nvidiafb_suspend(struct device *dev) 1065 1063 { 1066 - struct fb_info *info = pci_get_drvdata(dev); 1064 + return nvidiafb_suspend_late(dev, PMSG_SUSPEND); 1065 + } 1066 + 1067 + static int __maybe_unused nvidiafb_hibernate(struct device *dev) 1068 + { 1069 + return nvidiafb_suspend_late(dev, PMSG_HIBERNATE); 1070 + } 1071 + 1072 + static int __maybe_unused nvidiafb_freeze(struct device *dev) 1073 + { 1074 + return nvidiafb_suspend_late(dev, PMSG_FREEZE); 1075 + } 1076 + 1077 + static int __maybe_unused nvidiafb_resume(struct device *dev) 1078 + { 1079 + struct fb_info *info = dev_get_drvdata(dev); 1067 1080 struct nvidia_par *par = info->par; 1068 1081 1069 1082 console_lock(); 1070 - pci_set_power_state(dev, PCI_D0); 1071 - 1072 - if (par->pm_state != PM_EVENT_FREEZE) { 1073 - pci_restore_state(dev); 1074 - 1075 - if (pci_enable_device(dev)) 1076 - goto fail; 1077 - 1078 - pci_set_master(dev); 1079 - } 1080 1083 1081 1084 par->pm_state = PM_EVENT_ON; 1082 1085 nvidiafb_set_par(info); 1083 1086 fb_set_suspend (info, 0); 1084 1087 nvidiafb_blank(FB_BLANK_UNBLANK, info); 1085 1088 1086 - fail: 1087 1089 console_unlock(); 1088 1090 return 0; 1089 1091 } 1090 - #else 1091 - #define nvidiafb_suspend NULL 1092 - #define nvidiafb_resume NULL 1093 - #endif 1092 + 1093 + static const struct dev_pm_ops nvidiafb_pm_ops = { 1094 + #ifdef CONFIG_PM_SLEEP 1095 + .suspend = nvidiafb_suspend, 1096 + .resume = nvidiafb_resume, 1097 + .freeze = nvidiafb_freeze, 1098 + .thaw = nvidiafb_resume, 1099 + .poweroff = nvidiafb_hibernate, 1100 + .restore = nvidiafb_resume, 1101 + #endif /* CONFIG_PM_SLEEP */ 1102 + }; 1094 1103 1095 1104 static int nvidia_set_fbinfo(struct fb_info *info) 1096 1105 { ··· 1499 1492 #endif /* !MODULE */ 1500 1493 1501 1494 static struct pci_driver nvidiafb_driver = { 1502 - .name = "nvidiafb", 1503 - .id_table = nvidiafb_pci_tbl, 1504 - .probe = nvidiafb_probe, 1505 - .suspend = nvidiafb_suspend, 1506 - .resume = nvidiafb_resume, 1507 - .remove = nvidiafb_remove, 1495 + .name = "nvidiafb", 1496 + .id_table = nvidiafb_pci_tbl, 1497 + .probe = nvidiafb_probe, 1498 + .driver.pm = &nvidiafb_pm_ops, 1499 + .remove = nvidiafb_remove, 1508 1500 }; 1509 1501 1510 1502 /* ------------------------------------------------------------------------- *