i2c: i801: Fix resume bug
PATCH 1/1 i2c: i801: Fix resume bug
From: Volker Rümelin <[email protected]>
On suspend the original host configuration gets restored. The resume routine has to undo this, otherwise the SMBus master may be left in disabled state or in i2c mode.
[JD: Rebased on v5.8, simplified a condition.]
---
I noticed this bug in a QEMU x86_64 q35 VM booted with OVMF. OVMF doesn't initialize the SMBus master. After 1s of SMBus inactivity autosuspend disables the SMBus master. To reproduce please note QEMU's ICH9 SMBus emulation does not handle interrupts and it's necessary to pass the parameter disable_features=0x10 to the i2c_i801 driver.
Note from JD: I can't test this.
drivers/i2c/busses/i2c-i801.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-i801.c +14 -7
@@ -1709,6 +1709,13 @@ static inline int i801_acpi_probe(structstatic inline void i801_acpi_remove (struct i801_priv *priv) { }#endif +static unsigned char i801_setup_hstcfg (unsigned char hstcfg) +{ + hstcfg &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ + hstcfg |=SMBHSTCFG_HST_EN ; +return hstcfg; +} +static int i801_probe (struct pci_dev *dev,const struct pci_device_id *id) {unsigned char temp;
@@ -1830,13 +1837,10 @@ static int i801_probe(struct pci_dev *dereturn err; } -pci_read_config_byte (priv->pci_dev,SMBHSTCFG , &temp); - priv->original_hstcfg = temp; - temp &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ -if (!(temp &SMBHSTCFG_HST_EN )) { +pci_read_config_byte (priv->pci_dev,SMBHSTCFG , &priv->original_hstcfg); + temp =i801_setup_hstcfg (priv->original_hstcfg); +if (!(priv->original_hstcfg &SMBHSTCFG_HST_EN ))dev_info (&dev->dev,"Enabling SMBus device\n" ); - temp |=SMBHSTCFG_HST_EN ; - }pci_write_config_byte (priv->pci_dev,SMBHSTCFG , temp);if (temp &SMBHSTCFG_SMB_SMI_EN ) {
@@ -1961,8 +1965,11 @@ static int i801_suspend(struct device *dstatic int i801_resume (struct device *dev) { -struct i801_priv *priv =dev_get_drvdata (dev); +struct pci_dev *pci_dev =to_pci_dev (dev); +struct i801_priv *priv =pci_get_drvdata (pci_dev); +unsigned char hstcfg =i801_setup_hstcfg (priv->original_hstcfg); +pci_write_config_byte (pci_dev,SMBHSTCFG , hstcfg);i801_enable_host_notify (&priv->adapter);return 0 ;
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 10 lines · Jean Delvare
From: Volker Rümelin <[email protected]>
On suspend the original host configuration gets restored. The resume routine has to undo this, otherwise the SMBus master may be left in disabled state or in i2c mode.
[JD: Rebased on v5.8, simplified a condition.]
Signed-off-by Volker Rümelin <[email protected]>Signed-off-by Jean Delvare <[email protected]>
Quoted 8 lines
---
I noticed this bug in a QEMUx86_64q35 VM booted with OVMF. OVMF doesn't initialize the SMBus master. After 1s of SMBus inactivity autosuspend disables the SMBus master. To reproduce please note QEMU's ICH9 SMBus emulation does not handle interrupts and it's necessary to pass the parameter disable_features=0x10 to thei2c_i801driver.Note from JD: I can't test this.
Thanks for keeping up with this one. I have one high level comment but I hope Volker, Bjorn, and Vaibhav have comments/tags, too.
drivers/i2c/busses/i2c-i801.c static inline int i801_acpi_probe(struct · line 1717
Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +6
-0+static unsigned char i801_setup_hstcfg (unsigned char hstcfg) +{ + hstcfg &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ + hstcfg |=SMBHSTCFG_HST_EN ; +return hstcfg; +}
What about putting the write to SMBHSTCFG here, too. When I read the function name, I assumed it will do that.
drivers/i2c/busses/i2c-i801.c static int i801_suspend(struct device *d · line 1972
Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +4
-1@@ -1961,8 +1965,11 @@ static int i801_suspend(struct device *dstatic int i801_resume (struct device *dev) { -struct i801_priv *priv =dev_get_drvdata (dev); +struct pci_dev *pci_dev =to_pci_dev (dev); +struct i801_priv *priv =pci_get_drvdata (pci_dev); +unsigned char hstcfg =i801_setup_hstcfg (priv->original_hstcfg); +pci_write_config_byte (pci_dev,SMBHSTCFG , hstcfg);
And on top of that, we could skip the 'hstcfg' variable here.
Quoted 23 lines · Wolfram Sang
Quoted 10 lines · Jean Delvare
From: Volker Rümelin <[email protected]>
On suspend the original host configuration gets restored. The resume routine has to undo this, otherwise the SMBus master may be left in disabled state or in i2c mode.
[JD: Rebased on v5.8, simplified a condition.]
Signed-off-by Volker Rümelin <[email protected]>Signed-off-by Jean Delvare <[email protected]>Quoted 8 lines
---
I noticed this bug in a QEMUx86_64q35 VM booted with OVMF. OVMF doesn't initialize the SMBus master. After 1s of SMBus inactivity autosuspend disables the SMBus master. To reproduce please note QEMU's ICH9 SMBus emulation does not handle interrupts and it's necessary to pass the parameter disable_features=0x10 to thei2c_i801driver.Note from JD: I can't test this.
Thanks for keeping up with this one. I have one high level comment but I hope Volker, Bjorn, and Vaibhav have comments/tags, too.
Quoted 9 lines
drivers/i2c/busses/i2c-i801.c static inline int i801_acpi_probe(struct · line 1717
Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +6
-0+static unsigned char i801_setup_hstcfg (unsigned char hstcfg) +{ + hstcfg &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ + hstcfg |=SMBHSTCFG_HST_EN ; +return hstcfg; +}What about putting the write to SMBHSTCFG here, too. When I read the function name, I assumed it will do that.
From the point of view of suspend/resume, I think it's nice to have a write in i801_resume() to match the one in i801_suspend().
Putting the write inside i801_setup_hstcfg() would mean i801_probe() would do *two* writes instead of the one it currently does.
But I don't really care other than that :)
Quoted 13 lines
drivers/i2c/busses/i2c-i801.c static int i801_suspend(struct device *d · line 1972
Quoted 10 lines
drivers/i2c/busses/i2c-i801.c +4
-1@@ -1961,8 +1965,11 @@ static int i801_suspend(struct device *dstatic int i801_resume (struct device *dev) { -struct i801_priv *priv =dev_get_drvdata (dev); +struct pci_dev *pci_dev =to_pci_dev (dev); +struct i801_priv *priv =pci_get_drvdata (pci_dev); +unsigned char hstcfg =i801_setup_hstcfg (priv->original_hstcfg); +pci_write_config_byte (pci_dev,SMBHSTCFG , hstcfg);And on top of that, we could skip the 'hstcfg' variable here.
Hi Bjorn, Wolfram,
Quoted 12 lines · Bjorn Helgaas
Quoted 10 lines · Wolfram Sang
drivers/i2c/busses/i2c-i801.c static inline int i801_acpi_probe(struct · line 1717
Quoted 6 lines · Jean Delvare
drivers/i2c/busses/i2c-i801.c +6
-0+static unsigned char i801_setup_hstcfg (unsigned char hstcfg) +{ + hstcfg &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ + hstcfg |=SMBHSTCFG_HST_EN ; +return hstcfg; +}What about putting the write to SMBHSTCFG here, too. When I read the function name, I assumed it will do that.
Quoted 2 lines
From the point of view of suspend/resume, I think it's nice to have a write in
i801_resume()to match the one ini801_suspend().
I agree that symmetry is nice in general, but I must agree with Wolfram, a function named "setup" which doesn't actually perform any action is kind of confusing. I believe that moving the write in there makes sense as both callers will do exactly that immediately after.
Quoted 2 lines
Putting the write inside
i801_setup_hstcfg()would meani801_probe()would do *two* writes instead of the one it currently does.
I can't see why that would be the case.
Signature · 2 lines
Jean Delvare SUSE L3 Support
Quoted 42 lines · Wolfram Sang
Quoted 10 lines · Jean Delvare
From: Volker Rümelin <[email protected]>
On suspend the original host configuration gets restored. The resume routine has to undo this, otherwise the SMBus master may be left in disabled state or in i2c mode.
[JD: Rebased on v5.8, simplified a condition.]
Signed-off-by Volker Rümelin <[email protected]>Signed-off-by Jean Delvare <[email protected]>Quoted 8 lines
---
I noticed this bug in a QEMUx86_64q35 VM booted with OVMF. OVMF doesn't initialize the SMBus master. After 1s of SMBus inactivity autosuspend disables the SMBus master. To reproduce please note QEMU's ICH9 SMBus emulation does not handle interrupts and it's necessary to pass the parameter disable_features=0x10 to thei2c_i801driver.Note from JD: I can't test this.
Thanks for keeping up with this one. I have one high level comment but I hope Volker, Bjorn, and Vaibhav have comments/tags, too.
drivers/i2c/busses/i2c-i801.c static inline int i801_acpi_probe(struct · line 1717
Quoted 6 lines
drivers/i2c/busses/i2c-i801.c +6
-0+static unsigned char i801_setup_hstcfg (unsigned char hstcfg) +{ + hstcfg &= ~SMBHSTCFG_I2C_EN ;/* SMBus timing */ + hstcfg |=SMBHSTCFG_HST_EN ; +return hstcfg; +}What about putting the write to SMBHSTCFG here, too. When I read the function name, I assumed it will do that.
Quoted 9 lines
drivers/i2c/busses/i2c-i801.c +3
-1@@ -1961,8 +1965,11 @@ static int i801_suspend(struct device *dstatic int i801_resume (struct device *dev) { -struct i801_priv *priv =dev_get_drvdata (dev); +struct pci_dev *pci_dev =to_pci_dev (dev); +struct i801_priv *priv =pci_get_drvdata (pci_dev); +unsigned char hstcfg =i801_setup_hstcfg (priv->original_hstcfg);
Quoted 4 lines
drivers/i2c/busses/i2c-i801.c static int i801_suspend(struct device *d · line 1972
Quoted 1 line
drivers/i2c/busses/i2c-i801.c +1
-0+pci_write_config_byte (pci_dev,SMBHSTCFG , hstcfg);And on top of that, we could skip the 'hstcfg' variable here.
Add extra parameter of "struct pci_dev*" type in i801_setup_hstcfg(). We can also skip the introduction of "struct pci_dev*" type variable in .resume() then. Just use to_pci_dev(dev) .
Thanks
Vaibhav Gupta
Quoted 11 lines · Vaibhav Gupta
Quoted 10 lines · Wolfram Sang
Quoted 9 lines · Jean Delvare
drivers/i2c/busses/i2c-i801.c +3
-1@@ -1961,8 +1965,11 @@ static int i801_suspend(struct device *dstatic int i801_resume (struct device *dev) { -struct i801_priv *priv =dev_get_drvdata (dev); +struct pci_dev *pci_dev =to_pci_dev (dev); +struct i801_priv *priv =pci_get_drvdata (pci_dev); +unsigned char hstcfg =i801_setup_hstcfg (priv->original_hstcfg);
Quoted 5 lines
Quoted 3 lines
drivers/i2c/busses/i2c-i801.c static int i801_suspend(struct device *d · line 1972
Quoted 1 line
drivers/i2c/busses/i2c-i801.c +1
-0+pci_write_config_byte (pci_dev,SMBHSTCFG , hstcfg);And on top of that, we could skip the 'hstcfg' variable here.
Add extra parameter of "struct pci_dev*" type in
i801_setup_hstcfg().
That was my first approach, yes. But then I tried passing the struct i801_priv * instead, and it looks even neater to me (but I'm biased because I did it). I'll post that for review shortly.
Quoted 3 lines
We can
also skip the introduction of "struct pci_dev*" type variable in .resume() then. Just useto_pci_dev(dev).
I don't really mind keeping the pci_dev variable, for symmetry with .suspend(), and the compiler will optimize it away anyway. There's a minor cleanup possible in this area though, to which I'll give a try.
Thanks,
Signature · 2 lines
Jean Delvare SUSE L3 Support