Skip to content

Commit 82c8eb2

Browse files
VARoDeKwsakernel
authored andcommitted
i2c: eg20t: 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]> Reviewed-by: Bjorn Helgaas <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 536e785 commit 82c8eb2

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

drivers/i2c/busses/i2c-eg20t.c

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -846,11 +846,10 @@ static void pch_i2c_remove(struct pci_dev *pdev)
846846
kfree(adap_info);
847847
}
848848

849-
#ifdef CONFIG_PM
850-
static int pch_i2c_suspend(struct pci_dev *pdev, pm_message_t state)
849+
static int __maybe_unused pch_i2c_suspend(struct device *dev)
851850
{
852-
int ret;
853851
int i;
852+
struct pci_dev *pdev = to_pci_dev(dev);
854853
struct adapter_info *adap_info = pci_get_drvdata(pdev);
855854
void __iomem *p = adap_info->pch_data[0].pch_base_address;
856855

@@ -872,31 +871,13 @@ static int pch_i2c_suspend(struct pci_dev *pdev, pm_message_t state)
872871
ioread32(p + PCH_I2CSR), ioread32(p + PCH_I2CBUFSTA),
873872
ioread32(p + PCH_I2CESRSTA));
874873

875-
ret = pci_save_state(pdev);
876-
877-
if (ret) {
878-
pch_pci_err(pdev, "pci_save_state\n");
879-
return ret;
880-
}
881-
882-
pci_disable_device(pdev);
883-
pci_set_power_state(pdev, pci_choose_state(pdev, state));
884-
885874
return 0;
886875
}
887876

888-
static int pch_i2c_resume(struct pci_dev *pdev)
877+
static int __maybe_unused pch_i2c_resume(struct device *dev)
889878
{
890879
int i;
891-
struct adapter_info *adap_info = pci_get_drvdata(pdev);
892-
893-
pci_set_power_state(pdev, PCI_D0);
894-
pci_restore_state(pdev);
895-
896-
if (pci_enable_device(pdev) < 0) {
897-
pch_pci_err(pdev, "pch_i2c_resume:pci_enable_device FAILED\n");
898-
return -EIO;
899-
}
880+
struct adapter_info *adap_info = dev_get_drvdata(dev);
900881

901882
for (i = 0; i < adap_info->ch_num; i++)
902883
pch_i2c_init(&adap_info->pch_data[i]);
@@ -905,18 +886,15 @@ static int pch_i2c_resume(struct pci_dev *pdev)
905886

906887
return 0;
907888
}
908-
#else
909-
#define pch_i2c_suspend NULL
910-
#define pch_i2c_resume NULL
911-
#endif
889+
890+
static SIMPLE_DEV_PM_OPS(pch_i2c_pm_ops, pch_i2c_suspend, pch_i2c_resume);
912891

913892
static struct pci_driver pch_pcidriver = {
914893
.name = KBUILD_MODNAME,
915894
.id_table = pch_pcidev_id,
916895
.probe = pch_i2c_probe,
917896
.remove = pch_i2c_remove,
918-
.suspend = pch_i2c_suspend,
919-
.resume = pch_i2c_resume
897+
.driver.pm = &pch_i2c_pm_ops,
920898
};
921899

922900
module_pci_driver(pch_pcidriver);

0 commit comments

Comments
 (0)