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

fbdev: via-core: 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.

The via_suspend() is designed to function only in the case of Suspend.
Thus, the code checked for "if (state.event != PM_EVENT_SUSPEND)". This is
because, in the legacy framework, this callback was invoked even in the
event of Freeze and Hibernate. Hence, added the load of unnecessary
function-calls.

The goal can be achieved by binding the callback with only
"via_pm_ops.suspend" in the new framework. This also avoids the step of
checking "if (state.event != PM_EVENT_SUSPEND)" 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-4-vaibhavgupta40@gmail.com

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
ab5fe88a df7a9ec3

+16 -25
+16 -23
drivers/video/fbdev/via/via-core.c
··· 558 558 /* 559 559 * Power management functions 560 560 */ 561 - #ifdef CONFIG_PM 562 - static LIST_HEAD(viafb_pm_hooks); 563 - static DEFINE_MUTEX(viafb_pm_hooks_lock); 561 + static __maybe_unused LIST_HEAD(viafb_pm_hooks); 562 + static __maybe_unused DEFINE_MUTEX(viafb_pm_hooks_lock); 564 563 565 564 void viafb_pm_register(struct viafb_pm_hooks *hooks) 566 565 { ··· 579 580 } 580 581 EXPORT_SYMBOL_GPL(viafb_pm_unregister); 581 582 582 - static int via_suspend(struct pci_dev *pdev, pm_message_t state) 583 + static int __maybe_unused via_suspend(struct device *dev) 583 584 { 584 585 struct viafb_pm_hooks *hooks; 585 586 586 - if (state.event != PM_EVENT_SUSPEND) 587 - return 0; 588 587 /* 589 588 * "I've occasionally hit a few drivers that caused suspend 590 589 * failures, and each and every time it was a driver bug, and ··· 597 600 hooks->suspend(hooks->private); 598 601 mutex_unlock(&viafb_pm_hooks_lock); 599 602 600 - pci_save_state(pdev); 601 - pci_disable_device(pdev); 602 - pci_set_power_state(pdev, pci_choose_state(pdev, state)); 603 603 return 0; 604 604 } 605 605 606 - static int via_resume(struct pci_dev *pdev) 606 + static int __maybe_unused via_resume(struct device *dev) 607 607 { 608 608 struct viafb_pm_hooks *hooks; 609 - 610 - /* Get the bus side powered up */ 611 - pci_set_power_state(pdev, PCI_D0); 612 - pci_restore_state(pdev); 613 - if (pci_enable_device(pdev)) 614 - return 0; 615 - 616 - pci_set_master(pdev); 617 609 618 610 /* Now bring back any subdevs */ 619 611 mutex_lock(&viafb_pm_hooks_lock); ··· 612 626 613 627 return 0; 614 628 } 615 - #endif /* CONFIG_PM */ 616 629 617 630 static int via_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 618 631 { ··· 697 712 }; 698 713 MODULE_DEVICE_TABLE(pci, via_pci_table); 699 714 715 + static const struct dev_pm_ops via_pm_ops = { 716 + #ifdef CONFIG_PM_SLEEP 717 + .suspend = via_suspend, 718 + .resume = via_resume, 719 + .freeze = NULL, 720 + .thaw = via_resume, 721 + .poweroff = NULL, 722 + .restore = via_resume, 723 + #endif 724 + }; 725 + 700 726 static struct pci_driver via_driver = { 701 727 .name = "viafb", 702 728 .id_table = via_pci_table, 703 729 .probe = via_pci_probe, 704 730 .remove = via_pci_remove, 705 - #ifdef CONFIG_PM 706 - .suspend = via_suspend, 707 - .resume = via_resume, 708 - #endif 731 + .driver.pm = &via_pm_ops, 709 732 }; 710 733 711 734 static int __init via_core_init(void)
-2
include/linux/via-core.h
··· 47 47 /* 48 48 * Allow subdevs to register suspend/resume hooks. 49 49 */ 50 - #ifdef CONFIG_PM 51 50 struct viafb_pm_hooks { 52 51 struct list_head list; 53 52 int (*suspend)(void *private); ··· 56 57 57 58 void viafb_pm_register(struct viafb_pm_hooks *hooks); 58 59 void viafb_pm_unregister(struct viafb_pm_hooks *hooks); 59 - #endif /* CONFIG_PM */ 60 60 61 61 /* 62 62 * This is the global viafb "device" containing stuff needed by