Skip to content

Commit

Permalink
media: sta2x11: use generic power management
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Hans Verkuil <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
VARoDeK authored and sigmaris committed Aug 3, 2020
1 parent 960e0e6 commit f15d77a
Showing 1 changed file with 15 additions and 48 deletions.
63 changes: 15 additions & 48 deletions drivers/media/pci/sta2x11/sta2x11_vip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1198,61 +1195,32 @@ 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;
}

/**
* 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++)
Expand All @@ -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)
Expand Down

0 comments on commit f15d77a

Please sign in to comment.