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

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

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
a4ba7df5 6d111187

+32 -20
+32 -20
drivers/video/fbdev/savage/savagefb_driver.c
··· 2347 2347 } 2348 2348 } 2349 2349 2350 - static int savagefb_suspend(struct pci_dev *dev, pm_message_t mesg) 2350 + static int savagefb_suspend_late(struct device *dev, pm_message_t mesg) 2351 2351 { 2352 - struct fb_info *info = pci_get_drvdata(dev); 2352 + struct fb_info *info = dev_get_drvdata(dev); 2353 2353 struct savagefb_par *par = info->par; 2354 2354 2355 2355 DBG("savagefb_suspend"); ··· 2357 2357 if (mesg.event == PM_EVENT_PRETHAW) 2358 2358 mesg.event = PM_EVENT_FREEZE; 2359 2359 par->pm_state = mesg.event; 2360 - dev->dev.power.power_state = mesg; 2360 + dev->power.power_state = mesg; 2361 2361 2362 2362 /* 2363 2363 * For PM_EVENT_FREEZE, do not power down so the console ··· 2375 2375 savagefb_blank(FB_BLANK_POWERDOWN, info); 2376 2376 savage_set_default_par(par, &par->save); 2377 2377 savage_disable_mmio(par); 2378 - pci_save_state(dev); 2379 - pci_disable_device(dev); 2380 - pci_set_power_state(dev, pci_choose_state(dev, mesg)); 2381 2378 console_unlock(); 2382 2379 2383 2380 return 0; 2384 2381 } 2385 2382 2386 - static int savagefb_resume(struct pci_dev* dev) 2383 + static int __maybe_unused savagefb_suspend(struct device *dev) 2387 2384 { 2388 - struct fb_info *info = pci_get_drvdata(dev); 2385 + return savagefb_suspend_late(dev, PMSG_SUSPEND); 2386 + } 2387 + 2388 + static int __maybe_unused savagefb_hibernate(struct device *dev) 2389 + { 2390 + return savagefb_suspend_late(dev, PMSG_HIBERNATE); 2391 + } 2392 + 2393 + static int __maybe_unused savagefb_freeze(struct device *dev) 2394 + { 2395 + return savagefb_suspend_late(dev, PMSG_FREEZE); 2396 + } 2397 + 2398 + static int __maybe_unused savagefb_resume(struct device *dev) 2399 + { 2400 + struct fb_info *info = dev_get_drvdata(dev); 2389 2401 struct savagefb_par *par = info->par; 2390 2402 int cur_state = par->pm_state; 2391 2403 ··· 2409 2397 * The adapter was not powered down coming back from a 2410 2398 * PM_EVENT_FREEZE. 2411 2399 */ 2412 - if (cur_state == PM_EVENT_FREEZE) { 2413 - pci_set_power_state(dev, PCI_D0); 2400 + if (cur_state == PM_EVENT_FREEZE) 2414 2401 return 0; 2415 - } 2416 2402 2417 2403 console_lock(); 2418 2404 2419 - pci_set_power_state(dev, PCI_D0); 2420 - pci_restore_state(dev); 2421 - 2422 - if (pci_enable_device(dev)) 2423 - DBG("err"); 2424 - 2425 - pci_set_master(dev); 2426 2405 savage_enable_mmio(par); 2427 2406 savage_init_hw(par); 2428 2407 savagefb_set_par(info); ··· 2424 2421 return 0; 2425 2422 } 2426 2423 2424 + static const struct dev_pm_ops savagefb_pm_ops = { 2425 + #ifdef CONFIG_PM_SLEEP 2426 + .suspend = savagefb_suspend, 2427 + .resume = savagefb_resume, 2428 + .freeze = savagefb_freeze, 2429 + .thaw = savagefb_resume, 2430 + .poweroff = savagefb_hibernate, 2431 + .restore = savagefb_resume, 2432 + #endif 2433 + }; 2427 2434 2428 2435 static const struct pci_device_id savagefb_devices[] = { 2429 2436 {PCI_VENDOR_ID_S3, PCI_CHIP_SUPSAV_MX128, ··· 2514 2501 .name = "savagefb", 2515 2502 .id_table = savagefb_devices, 2516 2503 .probe = savagefb_probe, 2517 - .suspend = savagefb_suspend, 2518 - .resume = savagefb_resume, 2504 + .driver.pm = &savagefb_pm_ops, 2519 2505 .remove = savagefb_remove, 2520 2506 }; 2521 2507