Skip to content

Commit 2856bbc

Browse files
VARoDeKmchehab
authored andcommitted
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 <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent cc4fcf1 commit 2856bbc

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

drivers/media/pci/sta2x11/sta2x11_vip.c

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,21 +1167,18 @@ static void sta2x11_vip_remove_one(struct pci_dev *pdev)
11671167
*/
11681168
}
11691169

1170-
#ifdef CONFIG_PM
1171-
11721170
/**
11731171
* sta2x11_vip_suspend - set device into power save mode
1174-
* @pdev: PCI device
1175-
* @state: new state of device
1172+
* @dev_d: PCI device
11761173
*
11771174
* all relevant registers are saved and an attempt to set a new state is made.
11781175
*
11791176
* return value: 0 always indicate success,
11801177
* even if device could not be disabled. (workaround for hardware problem)
11811178
*/
1182-
static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
1179+
static int __maybe_unused sta2x11_vip_suspend(struct device *dev_d)
11831180
{
1184-
struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1181+
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
11851182
struct sta2x11_vip *vip =
11861183
container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
11871184
unsigned long flags;
@@ -1198,61 +1195,32 @@ static int sta2x11_vip_suspend(struct pci_dev *pdev, pm_message_t state)
11981195
vip->register_save_area[SAVE_COUNT + IRQ_COUNT + i] =
11991196
reg_read(vip, registers_to_save[i]);
12001197
spin_unlock_irqrestore(&vip->slock, flags);
1201-
/* save pci state */
1202-
pci_save_state(pdev);
1203-
if (pci_set_power_state(pdev, pci_choose_state(pdev, state))) {
1204-
/*
1205-
* do not call pci_disable_device on sta2x11 because it
1206-
* break all other Bus masters on this EP
1207-
*/
1208-
vip->disabled = 1;
1209-
}
1198+
1199+
vip->disabled = 1;
12101200

12111201
pr_info("VIP: suspend\n");
12121202
return 0;
12131203
}
12141204

12151205
/**
12161206
* sta2x11_vip_resume - resume device operation
1217-
* @pdev : PCI device
1218-
*
1219-
* re-enable device, set PCI state to powered and restore registers.
1220-
* resume normal device operation afterwards.
1207+
* @dev_d : PCI device
12211208
*
12221209
* return value: 0, no error.
12231210
*
12241211
* other, could not set device to power on state.
12251212
*/
1226-
static int sta2x11_vip_resume(struct pci_dev *pdev)
1213+
static int __maybe_unused sta2x11_vip_resume(struct device *dev_d)
12271214
{
1228-
struct v4l2_device *v4l2_dev = pci_get_drvdata(pdev);
1215+
struct v4l2_device *v4l2_dev = dev_get_drvdata(dev_d);
12291216
struct sta2x11_vip *vip =
12301217
container_of(v4l2_dev, struct sta2x11_vip, v4l2_dev);
12311218
unsigned long flags;
1232-
int ret, i;
1219+
int i;
12331220

12341221
pr_info("VIP: resume\n");
1235-
/* restore pci state */
1236-
if (vip->disabled) {
1237-
ret = pci_enable_device(pdev);
1238-
if (ret) {
1239-
pr_warn("VIP: Can't enable device.\n");
1240-
return ret;
1241-
}
1242-
vip->disabled = 0;
1243-
}
1244-
ret = pci_set_power_state(pdev, PCI_D0);
1245-
if (ret) {
1246-
/*
1247-
* do not call pci_disable_device on sta2x11 because it
1248-
* break all other Bus masters on this EP
1249-
*/
1250-
pr_warn("VIP: Can't enable device.\n");
1251-
vip->disabled = 1;
1252-
return ret;
1253-
}
12541222

1255-
pci_restore_state(pdev);
1223+
vip->disabled = 0;
12561224

12571225
spin_lock_irqsave(&vip->slock, flags);
12581226
for (i = 1; i < SAVE_COUNT; i++)
@@ -1266,22 +1234,21 @@ static int sta2x11_vip_resume(struct pci_dev *pdev)
12661234
return 0;
12671235
}
12681236

1269-
#endif
1270-
12711237
static const struct pci_device_id sta2x11_vip_pci_tbl[] = {
12721238
{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_VIP)},
12731239
{0,}
12741240
};
12751241

1242+
static SIMPLE_DEV_PM_OPS(sta2x11_vip_pm_ops,
1243+
sta2x11_vip_suspend,
1244+
sta2x11_vip_resume);
1245+
12761246
static struct pci_driver sta2x11_vip_driver = {
12771247
.name = KBUILD_MODNAME,
12781248
.probe = sta2x11_vip_init_one,
12791249
.remove = sta2x11_vip_remove_one,
12801250
.id_table = sta2x11_vip_pci_tbl,
1281-
#ifdef CONFIG_PM
1282-
.suspend = sta2x11_vip_suspend,
1283-
.resume = sta2x11_vip_resume,
1284-
#endif
1251+
.driver.pm = &sta2x11_vip_pm_ops,
12851252
};
12861253

12871254
static int __init sta2x11_vip_init_module(void)

0 commit comments

Comments
 (0)