Skip to content

Commit 3b0e209

Browse files
hkallweitwsakernel
authored andcommitted
i2c: i801: add helper i801_restore_regs
In few places relevant registers are reset to their initial value on driver load. Factor this out to new helper i801_restore_regs to avoid code duplication. Even though no actual problems are known, this patch may contribute to avoiding potential issues by: - restoring register values also in the error path of i2c_add_adapter - making restoring registers the last step (especially in i801_remove) Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Jean Delvare <jdelvare@suse.de> Acked-by: Andi Shyti <andi.shyti@kernel.org> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 9412664 commit 3b0e209

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

drivers/i2c/busses/i2c-i801.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,12 @@ static void i801_setup_hstcfg(struct i801_priv *priv)
16291629
pci_write_config_byte(priv->pci_dev, SMBHSTCFG, hstcfg);
16301630
}
16311631

1632+
static void i801_restore_regs(struct i801_priv *priv)
1633+
{
1634+
outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
1635+
pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg);
1636+
}
1637+
16321638
static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
16331639
{
16341640
int err, i;
@@ -1755,6 +1761,7 @@ static int i801_probe(struct pci_dev *dev, const struct pci_device_id *id)
17551761
if (err) {
17561762
platform_device_unregister(priv->tco_pdev);
17571763
i801_acpi_remove(priv);
1764+
i801_restore_regs(priv);
17581765
return err;
17591766
}
17601767

@@ -1779,19 +1786,19 @@ static void i801_remove(struct pci_dev *dev)
17791786
{
17801787
struct i801_priv *priv = pci_get_drvdata(dev);
17811788

1782-
outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
17831789
i801_disable_host_notify(priv);
17841790
i801_del_mux(priv);
17851791
i2c_del_adapter(&priv->adapter);
17861792
i801_acpi_remove(priv);
1787-
pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
17881793

17891794
platform_device_unregister(priv->tco_pdev);
17901795

17911796
/* if acpi_reserved is set then usage_count is incremented already */
17921797
if (!priv->acpi_reserved)
17931798
pm_runtime_get_noresume(&dev->dev);
17941799

1800+
i801_restore_regs(priv);
1801+
17951802
/*
17961803
* do not call pci_disable_device(dev) since it can cause hard hangs on
17971804
* some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
@@ -1802,18 +1809,17 @@ static void i801_shutdown(struct pci_dev *dev)
18021809
{
18031810
struct i801_priv *priv = pci_get_drvdata(dev);
18041811

1805-
/* Restore config registers to avoid hard hang on some systems */
1806-
outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
18071812
i801_disable_host_notify(priv);
1808-
pci_write_config_byte(dev, SMBHSTCFG, priv->original_hstcfg);
1813+
/* Restore config registers to avoid hard hang on some systems */
1814+
i801_restore_regs(priv);
18091815
}
18101816

18111817
static int i801_suspend(struct device *dev)
18121818
{
18131819
struct i801_priv *priv = dev_get_drvdata(dev);
18141820

1815-
outb_p(priv->original_hstcnt, SMBHSTCNT(priv));
1816-
pci_write_config_byte(priv->pci_dev, SMBHSTCFG, priv->original_hstcfg);
1821+
i801_restore_regs(priv);
1822+
18171823
return 0;
18181824
}
18191825

0 commit comments

Comments
 (0)