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

fbdev: s3fb: 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.

The s3_pci_suspend() is not designed to function in the case of Freeze.
Thus, the code checked for "if (state.event == PM_EVENT_FREEZE....)". This
is because, in the legacy framework, this callback was invoked even in the
event of Freeze. Hence, added the load of unnecessary function-call.

The goal can be achieved by binding the callback with only ".suspend" and
".poweroff" in the "s3_pci_pm_ops" const variable. This also avoids the
step of checking "state.event == PM_EVENT_FREEZE" every time the callback
is invoked.

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

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
fb6e2db8 59d026b1

+16 -23
+16 -23
drivers/video/fbdev/s3fb.c
··· 1410 1410 1411 1411 /* PCI suspend */ 1412 1412 1413 - static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state) 1413 + static int __maybe_unused s3_pci_suspend(struct device *dev) 1414 1414 { 1415 - struct fb_info *info = pci_get_drvdata(dev); 1415 + struct fb_info *info = dev_get_drvdata(dev); 1416 1416 struct s3fb_info *par = info->par; 1417 1417 1418 1418 dev_info(info->device, "suspend\n"); ··· 1420 1420 console_lock(); 1421 1421 mutex_lock(&(par->open_lock)); 1422 1422 1423 - if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { 1423 + if (par->ref_count == 0) { 1424 1424 mutex_unlock(&(par->open_lock)); 1425 1425 console_unlock(); 1426 1426 return 0; 1427 1427 } 1428 1428 1429 1429 fb_set_suspend(info, 1); 1430 - 1431 - pci_save_state(dev); 1432 - pci_disable_device(dev); 1433 - pci_set_power_state(dev, pci_choose_state(dev, state)); 1434 1430 1435 1431 mutex_unlock(&(par->open_lock)); 1436 1432 console_unlock(); ··· 1437 1441 1438 1442 /* PCI resume */ 1439 1443 1440 - static int s3_pci_resume(struct pci_dev* dev) 1444 + static int __maybe_unused s3_pci_resume(struct device *dev) 1441 1445 { 1442 - struct fb_info *info = pci_get_drvdata(dev); 1446 + struct fb_info *info = dev_get_drvdata(dev); 1443 1447 struct s3fb_info *par = info->par; 1444 - int err; 1445 1448 1446 1449 dev_info(info->device, "resume\n"); 1447 1450 ··· 1453 1458 return 0; 1454 1459 } 1455 1460 1456 - pci_set_power_state(dev, PCI_D0); 1457 - pci_restore_state(dev); 1458 - err = pci_enable_device(dev); 1459 - if (err) { 1460 - mutex_unlock(&(par->open_lock)); 1461 - console_unlock(); 1462 - dev_err(info->device, "error %d enabling device for resume\n", err); 1463 - return err; 1464 - } 1465 - pci_set_master(dev); 1466 - 1467 1461 s3fb_set_par(info); 1468 1462 fb_set_suspend(info, 0); 1469 1463 ··· 1462 1478 return 0; 1463 1479 } 1464 1480 1481 + static const struct dev_pm_ops s3_pci_pm_ops = { 1482 + #ifdef CONFIG_PM_SLEEP 1483 + .suspend = s3_pci_suspend, 1484 + .resume = s3_pci_resume, 1485 + .freeze = NULL, 1486 + .thaw = s3_pci_resume, 1487 + .poweroff = s3_pci_suspend, 1488 + .restore = s3_pci_resume, 1489 + #endif 1490 + }; 1465 1491 1466 1492 /* List of boards that we are trying to support */ 1467 1493 ··· 1504 1510 .id_table = s3_devices, 1505 1511 .probe = s3_pci_probe, 1506 1512 .remove = s3_pci_remove, 1507 - .suspend = s3_pci_suspend, 1508 - .resume = s3_pci_resume, 1513 + .driver.pm = &s3_pci_pm_ops, 1509 1514 }; 1510 1515 1511 1516 /* Parse user specified options */