Skip to content

Commit

Permalink
i2c-i801: Restore the device state before leaving
Browse files Browse the repository at this point in the history
Restore the original host configuration on driver unload and on
suspend. In particular this returns the SMBus master in I2C mode if it
was originally in I2C mode, which should help with suspend/resume if
the BIOS expects to find the SMBus master in I2C mode.

This fixes bug #6449 (for real this time.)
http://bugzilla.kernel.org/show_bug.cgi?id=6449

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Tommi Kyntola <tommi.kyntola@ray.fi>
  • Loading branch information
Jean Delvare authored and Jean Delvare committed Mar 22, 2007
1 parent 58791fd commit a5aaea3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drivers/i2c/busses/i2c-i801.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
int command, int hwpec);

static unsigned long i801_smba;
static unsigned char i801_original_hstcfg;
static struct pci_driver i801_driver;
static struct pci_dev *I801_dev;
static int isich4;
Expand Down Expand Up @@ -510,6 +511,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
}

pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
i801_original_hstcfg = temp;
temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
if (!(temp & SMBHSTCFG_HST_EN)) {
dev_info(&dev->dev, "Enabling SMBus device\n");
Expand Down Expand Up @@ -543,18 +545,41 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
static void __devexit i801_remove(struct pci_dev *dev)
{
i2c_del_adapter(&i801_adapter);
pci_write_config_byte(I801_dev, SMBHSTCFG, i801_original_hstcfg);
pci_release_region(dev, SMBBAR);
/*
* do not call pci_disable_device(dev) since it can cause hard hangs on
* some systems during power-off (eg. Fujitsu-Siemens Lifebook E8010)
*/
}

#ifdef CONFIG_PM
static int i801_suspend(struct pci_dev *dev, pm_message_t mesg)
{
pci_save_state(dev);
pci_write_config_byte(dev, SMBHSTCFG, i801_original_hstcfg);
pci_set_power_state(dev, pci_choose_state(dev, mesg));
return 0;
}

static int i801_resume(struct pci_dev *dev)
{
pci_set_power_state(dev, PCI_D0);
pci_restore_state(dev);
return pci_enable_device(dev);
}
#else
#define i801_suspend NULL
#define i801_resume NULL
#endif

static struct pci_driver i801_driver = {
.name = "i801_smbus",
.id_table = i801_ids,
.probe = i801_probe,
.remove = __devexit_p(i801_remove),
.suspend = i801_suspend,
.resume = i801_resume,
};

static int __init i2c_i801_init(void)
Expand Down

0 comments on commit a5aaea3

Please sign in to comment.