Skip to content

Commit a28b2ed

Browse files
VARoDeKmchehab
authored andcommitted
media: cx88: use generic power management
With legacy PM, drivers themselves were responsible for managing the device's power states and takes care of register states. After upgrading to the generic structure, PCI core will take care of required tasks and drivers should do only device-specific operations. The driver was invoking PCI helper functions like pci_save/restore_state(), pci_enable/disable_device() and pci_set_power_state(), which is not recommended. Compile-tested only. [hverkuil: fixes checkpatch alignment warning] Signed-off-by: Vaibhav Gupta <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent fc1f0e6 commit a28b2ed

File tree

1 file changed

+16
-44
lines changed

1 file changed

+16
-44
lines changed

drivers/media/pci/cx88/cx88-video.c

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,7 @@ static int start_video_dma(struct cx8800_dev *dev,
385385
return 0;
386386
}
387387

388-
#ifdef CONFIG_PM
389-
static int stop_video_dma(struct cx8800_dev *dev)
388+
static int __maybe_unused stop_video_dma(struct cx8800_dev *dev)
390389
{
391390
struct cx88_core *core = dev->core;
392391

@@ -402,8 +401,8 @@ static int stop_video_dma(struct cx8800_dev *dev)
402401
return 0;
403402
}
404403

405-
static int restart_video_queue(struct cx8800_dev *dev,
406-
struct cx88_dmaqueue *q)
404+
static int __maybe_unused restart_video_queue(struct cx8800_dev *dev,
405+
struct cx88_dmaqueue *q)
407406
{
408407
struct cx88_buffer *buf;
409408

@@ -415,7 +414,6 @@ static int restart_video_queue(struct cx8800_dev *dev,
415414
}
416415
return 0;
417416
}
418-
#endif
419417

420418
/* ------------------------------------------------------------------ */
421419

@@ -1551,10 +1549,9 @@ static void cx8800_finidev(struct pci_dev *pci_dev)
15511549
kfree(dev);
15521550
}
15531551

1554-
#ifdef CONFIG_PM
1555-
static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
1552+
static int __maybe_unused cx8800_suspend(struct device *dev_d)
15561553
{
1557-
struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1554+
struct cx8800_dev *dev = dev_get_drvdata(dev_d);
15581555
struct cx88_core *core = dev->core;
15591556
unsigned long flags;
15601557

@@ -1575,40 +1572,17 @@ static int cx8800_suspend(struct pci_dev *pci_dev, pm_message_t state)
15751572
/* FIXME -- shutdown device */
15761573
cx88_shutdown(core);
15771574

1578-
pci_save_state(pci_dev);
1579-
if (pci_set_power_state(pci_dev,
1580-
pci_choose_state(pci_dev, state)) != 0) {
1581-
pci_disable_device(pci_dev);
1582-
dev->state.disabled = 1;
1583-
}
1575+
dev->state.disabled = 1;
15841576
return 0;
15851577
}
15861578

1587-
static int cx8800_resume(struct pci_dev *pci_dev)
1579+
static int __maybe_unused cx8800_resume(struct device *dev_d)
15881580
{
1589-
struct cx8800_dev *dev = pci_get_drvdata(pci_dev);
1581+
struct cx8800_dev *dev = dev_get_drvdata(dev_d);
15901582
struct cx88_core *core = dev->core;
15911583
unsigned long flags;
1592-
int err;
15931584

1594-
if (dev->state.disabled) {
1595-
err = pci_enable_device(pci_dev);
1596-
if (err) {
1597-
pr_err("can't enable device\n");
1598-
return err;
1599-
}
1600-
1601-
dev->state.disabled = 0;
1602-
}
1603-
err = pci_set_power_state(pci_dev, PCI_D0);
1604-
if (err) {
1605-
pr_err("can't set power state\n");
1606-
pci_disable_device(pci_dev);
1607-
dev->state.disabled = 1;
1608-
1609-
return err;
1610-
}
1611-
pci_restore_state(pci_dev);
1585+
dev->state.disabled = 0;
16121586

16131587
/* FIXME: re-initialize hardware */
16141588
cx88_reset(core);
@@ -1631,7 +1605,6 @@ static int cx8800_resume(struct pci_dev *pci_dev)
16311605

16321606
return 0;
16331607
}
1634-
#endif
16351608

16361609
/* ----------------------------------------------------------- */
16371610

@@ -1647,15 +1620,14 @@ static const struct pci_device_id cx8800_pci_tbl[] = {
16471620
};
16481621
MODULE_DEVICE_TABLE(pci, cx8800_pci_tbl);
16491622

1623+
static SIMPLE_DEV_PM_OPS(cx8800_pm_ops, cx8800_suspend, cx8800_resume);
1624+
16501625
static struct pci_driver cx8800_pci_driver = {
1651-
.name = "cx8800",
1652-
.id_table = cx8800_pci_tbl,
1653-
.probe = cx8800_initdev,
1654-
.remove = cx8800_finidev,
1655-
#ifdef CONFIG_PM
1656-
.suspend = cx8800_suspend,
1657-
.resume = cx8800_resume,
1658-
#endif
1626+
.name = "cx8800",
1627+
.id_table = cx8800_pci_tbl,
1628+
.probe = cx8800_initdev,
1629+
.remove = cx8800_finidev,
1630+
.driver.pm = &cx8800_pm_ops,
16591631
};
16601632

16611633
module_pci_driver(cx8800_pci_driver);

0 commit comments

Comments
 (0)