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

Configure Feed

Select the types of activity you want to include in your feed.

staging: sm750fb: use generic power management

Drivers using legacy power management .suspen()/.resume() callbacks
have to manage PCI states and device's PM states themselves. They also
need to take care of standard configuration registers.

Switch to generic power management framework using a single
"struct dev_pm_ops" variable to take the unnecessary load from the driver.
This also avoids the need for the driver to directly call most of the PCI
helper functions and device power state control functions, as through
the generic framework PCI Core takes care of the necessary operations,
and drivers are required to do only device-specific jobs.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Link: https://lore.kernel.org/r/20200728123349.1331679-1-vaibhavgupta40@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Vaibhav Gupta and committed by
Greg Kroah-Hartman
408a68c5 341a8f86

+17 -74
+17 -74
drivers/staging/sm750fb/sm750.c
··· 407 407 return chan << bf->offset; 408 408 } 409 409 410 - #ifdef CONFIG_PM 411 - static int lynxfb_suspend(struct pci_dev *pdev, pm_message_t mesg) 410 + static int __maybe_unused lynxfb_suspend(struct device *dev) 412 411 { 413 412 struct fb_info *info; 414 413 struct sm750_dev *sm750_dev; 415 - int ret; 416 - 417 - if (mesg.event == pdev->dev.power.power_state.event) 418 - return 0; 419 - 420 - ret = 0; 421 - sm750_dev = pci_get_drvdata(pdev); 422 - switch (mesg.event) { 423 - case PM_EVENT_FREEZE: 424 - case PM_EVENT_PRETHAW: 425 - pdev->dev.power.power_state = mesg; 426 - return 0; 427 - } 414 + sm750_dev = dev_get_drvdata(dev); 428 415 429 416 console_lock(); 430 - if (mesg.event & PM_EVENT_SLEEP) { 431 - info = sm750_dev->fbinfo[0]; 432 - if (info) 433 - /* 1 means do suspend */ 434 - fb_set_suspend(info, 1); 435 - info = sm750_dev->fbinfo[1]; 436 - if (info) 437 - /* 1 means do suspend */ 438 - fb_set_suspend(info, 1); 417 + info = sm750_dev->fbinfo[0]; 418 + if (info) 419 + /* 1 means do suspend */ 420 + fb_set_suspend(info, 1); 421 + info = sm750_dev->fbinfo[1]; 422 + if (info) 423 + /* 1 means do suspend */ 424 + fb_set_suspend(info, 1); 439 425 440 - ret = pci_save_state(pdev); 441 - if (ret) { 442 - dev_err(&pdev->dev, 443 - "error:%d occurred in pci_save_state\n", ret); 444 - goto lynxfb_suspend_err; 445 - } 446 - 447 - ret = pci_set_power_state(pdev, pci_choose_state(pdev, mesg)); 448 - if (ret) { 449 - dev_err(&pdev->dev, 450 - "error:%d occurred in pci_set_power_state\n", 451 - ret); 452 - goto lynxfb_suspend_err; 453 - } 454 - } 455 - 456 - pdev->dev.power.power_state = mesg; 457 - 458 - lynxfb_suspend_err: 459 426 console_unlock(); 460 - return ret; 427 + return 0; 461 428 } 462 429 463 - static int lynxfb_resume(struct pci_dev *pdev) 430 + static int __maybe_unused lynxfb_resume(struct device *dev) 464 431 { 432 + struct pci_dev *pdev = to_pci_dev(dev); 465 433 struct fb_info *info; 466 434 struct sm750_dev *sm750_dev; 467 435 ··· 437 469 struct lynxfb_crtc *crtc; 438 470 struct lynx_cursor *cursor; 439 471 440 - int ret; 441 - 442 - ret = 0; 443 472 sm750_dev = pci_get_drvdata(pdev); 444 473 445 474 console_lock(); 446 - 447 - ret = pci_set_power_state(pdev, PCI_D0); 448 - if (ret) { 449 - dev_err(&pdev->dev, 450 - "error:%d occurred in pci_set_power_state\n", ret); 451 - goto lynxfb_resume_err; 452 - } 453 - 454 - if (pdev->dev.power.power_state.event != PM_EVENT_FREEZE) { 455 - pci_restore_state(pdev); 456 - ret = pci_enable_device(pdev); 457 - if (ret) { 458 - dev_err(&pdev->dev, 459 - "error:%d occurred in pci_enable_device\n", 460 - ret); 461 - goto lynxfb_resume_err; 462 - } 463 - pci_set_master(pdev); 464 - } 465 475 466 476 hw_sm750_inithw(sm750_dev, pdev); 467 477 ··· 469 523 470 524 pdev->dev.power.power_state.event = PM_EVENT_RESUME; 471 525 472 - lynxfb_resume_err: 473 526 console_unlock(); 474 - return ret; 527 + return 0; 475 528 } 476 - #endif 477 529 478 530 static int lynxfb_ops_check_var(struct fb_var_screeninfo *var, 479 531 struct fb_info *info) ··· 1154 1210 1155 1211 MODULE_DEVICE_TABLE(pci, smi_pci_table); 1156 1212 1213 + static SIMPLE_DEV_PM_OPS(lynxfb_pm_ops, lynxfb_suspend, lynxfb_resume); 1214 + 1157 1215 static struct pci_driver lynxfb_driver = { 1158 1216 .name = "sm750fb", 1159 1217 .id_table = smi_pci_table, 1160 1218 .probe = lynxfb_pci_probe, 1161 1219 .remove = lynxfb_pci_remove, 1162 - #ifdef CONFIG_PM 1163 - .suspend = lynxfb_suspend, 1164 - .resume = lynxfb_resume, 1165 - #endif 1220 + .driver.pm = &lynxfb_pm_ops, 1166 1221 }; 1167 1222 1168 1223 static int __init lynxfb_init(void)