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

fbdev: arkfb: 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 ark_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 "ark_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-13-vaibhavgupta40@gmail.com

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
a91df118 fb6e2db8

+17 -24
+17 -24
drivers/video/fbdev/arkfb.c
··· 1085 1085 } 1086 1086 1087 1087 1088 - #ifdef CONFIG_PM 1089 1088 /* PCI suspend */ 1090 1089 1091 - static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state) 1090 + static int __maybe_unused ark_pci_suspend(struct device *dev) 1092 1091 { 1093 - struct fb_info *info = pci_get_drvdata(dev); 1092 + struct fb_info *info = dev_get_drvdata(dev); 1094 1093 struct arkfb_info *par = info->par; 1095 1094 1096 1095 dev_info(info->device, "suspend\n"); ··· 1097 1098 console_lock(); 1098 1099 mutex_lock(&(par->open_lock)); 1099 1100 1100 - if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { 1101 + if (par->ref_count == 0) { 1101 1102 mutex_unlock(&(par->open_lock)); 1102 1103 console_unlock(); 1103 1104 return 0; 1104 1105 } 1105 1106 1106 1107 fb_set_suspend(info, 1); 1107 - 1108 - pci_save_state(dev); 1109 - pci_disable_device(dev); 1110 - pci_set_power_state(dev, pci_choose_state(dev, state)); 1111 1108 1112 1109 mutex_unlock(&(par->open_lock)); 1113 1110 console_unlock(); ··· 1114 1119 1115 1120 /* PCI resume */ 1116 1121 1117 - static int ark_pci_resume (struct pci_dev* dev) 1122 + static int __maybe_unused ark_pci_resume(struct device *dev) 1118 1123 { 1119 - struct fb_info *info = pci_get_drvdata(dev); 1124 + struct fb_info *info = dev_get_drvdata(dev); 1120 1125 struct arkfb_info *par = info->par; 1121 1126 1122 1127 dev_info(info->device, "resume\n"); ··· 1127 1132 if (par->ref_count == 0) 1128 1133 goto fail; 1129 1134 1130 - pci_set_power_state(dev, PCI_D0); 1131 - pci_restore_state(dev); 1132 - 1133 - if (pci_enable_device(dev)) 1134 - goto fail; 1135 - 1136 - pci_set_master(dev); 1137 - 1138 1135 arkfb_set_par(info); 1139 1136 fb_set_suspend(info, 0); 1140 1137 ··· 1135 1148 console_unlock(); 1136 1149 return 0; 1137 1150 } 1138 - #else 1139 - #define ark_pci_suspend NULL 1140 - #define ark_pci_resume NULL 1141 - #endif /* CONFIG_PM */ 1151 + 1152 + static const struct dev_pm_ops ark_pci_pm_ops = { 1153 + #ifdef CONFIG_PM_SLEEP 1154 + .suspend = ark_pci_suspend, 1155 + .resume = ark_pci_resume, 1156 + .freeze = NULL, 1157 + .thaw = ark_pci_resume, 1158 + .poweroff = ark_pci_suspend, 1159 + .restore = ark_pci_resume, 1160 + #endif 1161 + }; 1142 1162 1143 1163 /* List of boards that we are trying to support */ 1144 1164 ··· 1162 1168 .id_table = ark_devices, 1163 1169 .probe = ark_pci_probe, 1164 1170 .remove = ark_pci_remove, 1165 - .suspend = ark_pci_suspend, 1166 - .resume = ark_pci_resume, 1171 + .driver.pm = &ark_pci_pm_ops, 1167 1172 }; 1168 1173 1169 1174 /* Cleanup */