Skip to content

Commit 408a68c

Browse files
VARoDeKgregkh
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 341a8f8 commit 408a68c

File tree

1 file changed

+17
-74
lines changed

1 file changed

+17
-74
lines changed

drivers/staging/sm750fb/sm750.c

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -407,94 +407,40 @@ static inline unsigned int chan_to_field(unsigned int chan,
407407
return chan << bf->offset;
408408
}
409409

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)
412411
{
413412
struct fb_info *info;
414413
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);
428415

429416
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);
439-
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;
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);
457425

458-
lynxfb_suspend_err:
459426
console_unlock();
460-
return ret;
427+
return 0;
461428
}
462429

463-
static int lynxfb_resume(struct pci_dev *pdev)
430+
static int __maybe_unused lynxfb_resume(struct device *dev)
464431
{
432+
struct pci_dev *pdev = to_pci_dev(dev);
465433
struct fb_info *info;
466434
struct sm750_dev *sm750_dev;
467435

468436
struct lynxfb_par *par;
469437
struct lynxfb_crtc *crtc;
470438
struct lynx_cursor *cursor;
471439

472-
int ret;
473-
474-
ret = 0;
475440
sm750_dev = pci_get_drvdata(pdev);
476441

477442
console_lock();
478443

479-
ret = pci_set_power_state(pdev, PCI_D0);
480-
if (ret) {
481-
dev_err(&pdev->dev,
482-
"error:%d occurred in pci_set_power_state\n", ret);
483-
goto lynxfb_resume_err;
484-
}
485-
486-
if (pdev->dev.power.power_state.event != PM_EVENT_FREEZE) {
487-
pci_restore_state(pdev);
488-
ret = pci_enable_device(pdev);
489-
if (ret) {
490-
dev_err(&pdev->dev,
491-
"error:%d occurred in pci_enable_device\n",
492-
ret);
493-
goto lynxfb_resume_err;
494-
}
495-
pci_set_master(pdev);
496-
}
497-
498444
hw_sm750_inithw(sm750_dev, pdev);
499445

500446
info = sm750_dev->fbinfo[0];
@@ -523,11 +469,9 @@ static int lynxfb_resume(struct pci_dev *pdev)
523469

524470
pdev->dev.power.power_state.event = PM_EVENT_RESUME;
525471

526-
lynxfb_resume_err:
527472
console_unlock();
528-
return ret;
473+
return 0;
529474
}
530-
#endif
531475

532476
static int lynxfb_ops_check_var(struct fb_var_screeninfo *var,
533477
struct fb_info *info)
@@ -1210,15 +1154,14 @@ static const struct pci_device_id smi_pci_table[] = {
12101154

12111155
MODULE_DEVICE_TABLE(pci, smi_pci_table);
12121156

1157+
static SIMPLE_DEV_PM_OPS(lynxfb_pm_ops, lynxfb_suspend, lynxfb_resume);
1158+
12131159
static struct pci_driver lynxfb_driver = {
12141160
.name = "sm750fb",
12151161
.id_table = smi_pci_table,
12161162
.probe = lynxfb_pci_probe,
12171163
.remove = lynxfb_pci_remove,
1218-
#ifdef CONFIG_PM
1219-
.suspend = lynxfb_suspend,
1220-
.resume = lynxfb_resume,
1221-
#endif
1164+
.driver.pm = &lynxfb_pm_ops,
12221165
};
12231166

12241167
static int __init lynxfb_init(void)

0 commit comments

Comments
 (0)