media: sta2x11: 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.

Thus, there is no need to call the PCI helper functions like
pci_enable_device(), pci_save/restore_sate(), etc.

Compile-tested only.

Signed-off-by: Vaibhav Gupta <vaibhavgupta40@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
Vaibhav Gupta 2020-07-17 09:34:31 +02:00 committed by Mauro Carvalho Chehab
parent cc4fcf11a8
commit 2856bbc55b
1 changed files with 15 additions and 48 deletions

View File

@ -1167,21 +1167,18 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
*/
}
#ifdef CONFIG_PM
/**
* sta2x11_vip_suspend - set device into power save mode
* @pdev: PCI device
* @state: new state of device
* @dev_d: PCI device
*
* all relevant registers are saved and an attempt to set a new state is made.
*
* return value: 0 always indicate success,
* even if device could not be disabled. (workaround for hardware problem)
*/
static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
static int __maybe_unused sta2x11_vip_suspend(struct device *dev_d)
{
struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
struct sta2x11_vip *vip =
container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
unsigned long flags;
@ -1198,15 +1195,8 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
reg_read(vip, registers_to_save[i]);
spin_unlock_irqrestore(&vip->slock, flags);
/* save pci state */
pci_save_state(pdev);
if (pci_set_power_state(pdev, pci_choose_state(pdev, state))) {
/*
* do not call pci_disable_device on sta2x11 because it
* break all other Bus masters on this EP
*/
vip->disabled = 1;
}
vip->disabled = 1;
pr_info("VIP: suspend\n");
return 0;
@ -1214,45 +1204,23 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
/**
* sta2x11_vip_resume - resume device operation
* @pdev : PCI device
*
* re-enable device, set PCI state to powered and restore registers.
* resume normal device operation afterwards.
* @dev_d : PCI device
*
* return value: 0, no error.
*
* other, could not set device to power on state.
*/
static int sta2x11_vip_resume(struct pci_dev *pdev)
static int __maybe_unused sta2x11_vip_resume(struct device *dev_d)
{
struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
struct sta2x11_vip *vip =
container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
unsigned long flags;
int ret, i;
int i;
pr_info("VIP: resume\n");
/* restore pci state */
if (vip->disabled) {
ret = pci_enable_device(pdev);
if (ret) {
pr_warn("VIP: Can't enable device.\n");
return ret;
}
vip->disabled = 0;
}
ret = pci_set_power_state(pdev, PCI_D0);
if (ret) {
/*
* do not call pci_disable_device on sta2x11 because it
* break all other Bus masters on this EP
*/
pr_warn("VIP: Can't enable device.\n");
vip->disabled = 1;
return ret;
}
pci_restore_state(pdev);
vip->disabled = 0;
spin_lock_irqsave(&vip->slock, flags);
for (i = 1; i < SAVE_COUNT; i++)
@ -1266,22 +1234,21 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
return 0;
}
#endif
static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
{0,}
};
static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops,
sta2x11_vip_suspend,
sta2x11_vip_resume);
static struct pci_driver sta2x11_vip_driver = {
.name = KBUILD_MODNAME,
.probe = sta2x11_vip_init_one,
.remove = sta2x11_vip_remove_one,
.id_table = sta2x11_vip_pci_tbl,
#ifdef CONFIG_PM
.suspend = sta2x11_vip_suspend,
.resume = sta2x11_vip_resume,
#endif
.driver.pm = &sta2x11_vip_pm_ops,
};
static int __init sta2x11_vip_init_module(void)