Skip to content

Commit 59d026b

Browse files
VARoDeKbzolnier
authored andcommitted
fbdev: vt8623fb: 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 vt8623_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 "vt8623_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 <[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 805a5c4 commit 59d026b

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

drivers/video/fbdev/vt8623fb.c

+17-24
Original file line numberDiff line numberDiff line change
@@ -815,31 +815,26 @@ static void vt8623_pci_remove(struct pci_dev *dev)
815815
}
816816

817817

818-
#ifdef CONFIG_PM
819818
/* PCI suspend */
820819

821-
static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state)
820+
static int __maybe_unused vt8623_pci_suspend(struct device *dev)
822821
{
823-
struct fb_info *info = pci_get_drvdata(dev);
822+
struct fb_info *info = dev_get_drvdata(dev);
824823
struct vt8623fb_info *par = info->par;
825824

826825
dev_info(info->device, "suspend\n");
827826

828827
console_lock();
829828
mutex_lock(&(par->open_lock));
830829

831-
if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
830+
if (par->ref_count == 0) {
832831
mutex_unlock(&(par->open_lock));
833832
console_unlock();
834833
return 0;
835834
}
836835

837836
fb_set_suspend(info, 1);
838837

839-
pci_save_state(dev);
840-
pci_disable_device(dev);
841-
pci_set_power_state(dev, pci_choose_state(dev, state));
842-
843838
mutex_unlock(&(par->open_lock));
844839
console_unlock();
845840

@@ -849,9 +844,9 @@ static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state)
849844

850845
/* PCI resume */
851846

852-
static int vt8623_pci_resume(struct pci_dev* dev)
847+
static int __maybe_unused vt8623_pci_resume(struct device *dev)
853848
{
854-
struct fb_info *info = pci_get_drvdata(dev);
849+
struct fb_info *info = dev_get_drvdata(dev);
855850
struct vt8623fb_info *par = info->par;
856851

857852
dev_info(info->device, "resume\n");
@@ -862,14 +857,6 @@ static int vt8623_pci_resume(struct pci_dev* dev)
862857
if (par->ref_count == 0)
863858
goto fail;
864859

865-
pci_set_power_state(dev, PCI_D0);
866-
pci_restore_state(dev);
867-
868-
if (pci_enable_device(dev))
869-
goto fail;
870-
871-
pci_set_master(dev);
872-
873860
vt8623fb_set_par(info);
874861
fb_set_suspend(info, 0);
875862

@@ -879,10 +866,17 @@ static int vt8623_pci_resume(struct pci_dev* dev)
879866

880867
return 0;
881868
}
882-
#else
883-
#define vt8623_pci_suspend NULL
884-
#define vt8623_pci_resume NULL
885-
#endif /* CONFIG_PM */
869+
870+
static const struct dev_pm_ops vt8623_pci_pm_ops = {
871+
#ifdef CONFIG_PM_SLEEP
872+
.suspend = vt8623_pci_suspend,
873+
.resume = vt8623_pci_resume,
874+
.freeze = NULL,
875+
.thaw = vt8623_pci_resume,
876+
.poweroff = vt8623_pci_suspend,
877+
.restore = vt8623_pci_resume,
878+
#endif /* CONFIG_PM_SLEEP */
879+
};
886880

887881
/* List of boards that we are trying to support */
888882

@@ -898,8 +892,7 @@ static struct pci_driver vt8623fb_pci_driver = {
898892
.id_table = vt8623_devices,
899893
.probe = vt8623_pci_probe,
900894
.remove = vt8623_pci_remove,
901-
.suspend = vt8623_pci_suspend,
902-
.resume = vt8623_pci_resume,
895+
.driver.pm = &vt8623_pci_pm_ops,
903896
};
904897

905898
/* Cleanup */

0 commit comments

Comments
 (0)