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

fbdev: i740fb: 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 i740fb_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 "i740fb_pm_ops" const variable. This also avoids the
step of checking "if (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-10-vaibhavgupta40@gmail.com

authored by

Vaibhav Gupta and committed by
Bartlomiej Zolnierkiewicz
805a5c45 c62c0f57

+16 -24
+16 -24
drivers/video/fbdev/i740fb.c
··· 1175 1175 } 1176 1176 } 1177 1177 1178 - #ifdef CONFIG_PM 1179 - static int i740fb_suspend(struct pci_dev *dev, pm_message_t state) 1178 + static int __maybe_unused i740fb_suspend(struct device *dev) 1180 1179 { 1181 - struct fb_info *info = pci_get_drvdata(dev); 1180 + struct fb_info *info = dev_get_drvdata(dev); 1182 1181 struct i740fb_par *par = info->par; 1183 - 1184 - /* don't disable console during hibernation and wakeup from it */ 1185 - if (state.event == PM_EVENT_FREEZE || state.event == PM_EVENT_PRETHAW) 1186 - return 0; 1187 1182 1188 1183 console_lock(); 1189 1184 mutex_lock(&(par->open_lock)); ··· 1192 1197 1193 1198 fb_set_suspend(info, 1); 1194 1199 1195 - pci_save_state(dev); 1196 - pci_disable_device(dev); 1197 - pci_set_power_state(dev, pci_choose_state(dev, state)); 1198 - 1199 1200 mutex_unlock(&(par->open_lock)); 1200 1201 console_unlock(); 1201 1202 1202 1203 return 0; 1203 1204 } 1204 1205 1205 - static int i740fb_resume(struct pci_dev *dev) 1206 + static int __maybe_unused i740fb_resume(struct device *dev) 1206 1207 { 1207 - struct fb_info *info = pci_get_drvdata(dev); 1208 + struct fb_info *info = dev_get_drvdata(dev); 1208 1209 struct i740fb_par *par = info->par; 1209 1210 1210 1211 console_lock(); 1211 1212 mutex_lock(&(par->open_lock)); 1212 1213 1213 1214 if (par->ref_count == 0) 1214 - goto fail; 1215 - 1216 - pci_set_power_state(dev, PCI_D0); 1217 - pci_restore_state(dev); 1218 - if (pci_enable_device(dev)) 1219 1215 goto fail; 1220 1216 1221 1217 i740fb_set_par(info); ··· 1217 1231 console_unlock(); 1218 1232 return 0; 1219 1233 } 1220 - #else 1221 - #define i740fb_suspend NULL 1222 - #define i740fb_resume NULL 1223 - #endif /* CONFIG_PM */ 1234 + 1235 + static const struct dev_pm_ops i740fb_pm_ops = { 1236 + #ifdef CONFIG_PM_SLEEP 1237 + .suspend = i740fb_suspend, 1238 + .resume = i740fb_resume, 1239 + .freeze = NULL, 1240 + .thaw = i740fb_resume, 1241 + .poweroff = i740fb_suspend, 1242 + .restore = i740fb_resume, 1243 + #endif /* CONFIG_PM_SLEEP */ 1244 + }; 1224 1245 1225 1246 #define I740_ID_PCI 0x00d1 1226 1247 #define I740_ID_AGP 0x7800 ··· 1244 1251 .id_table = i740fb_id_table, 1245 1252 .probe = i740fb_probe, 1246 1253 .remove = i740fb_remove, 1247 - .suspend = i740fb_suspend, 1248 - .resume = i740fb_resume, 1254 + .driver.pm = &i740fb_pm_ops, 1249 1255 }; 1250 1256 1251 1257 #ifndef MODULE