Skip to contentSkip to conversation

i2c: i801: use i2c_mark_adapter_suspended/resumed

PATCH Applied Heiner Kallweit 4 participants 4 messages Sep 20, 2023 – Sep 22, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: i801: use i2c_mark_adapter_suspended/resumed

When entering the suspend callback, at first we should ensure that transfers are finished and I2C core can't start further transfers. Use i2c_mark_adapter_suspended() for this purpose, and complement it with a call to i2c_mark_adapter_resumed() in the resume path.

---
Rebased version of a previously discussed patch, now w/o touching the remove and shutdown path.

---
 drivers/i2c/busses/i2c-i801.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-i801.c +2 -0
index 6d02a8b88..26f132277 100644
@@ -1818,6 +1818,7 @@ static int i801_suspend(struct device *dev)
 {
 	struct i801_priv *priv = dev_get_drvdata(dev);
 
+	i2c_mark_adapter_suspended(&priv->adapter);
 	i801_restore_regs(priv);
 
 	return 0;
@@ -1829,6 +1830,7 @@ static int i801_resume(struct device *dev)
 
 	i801_setup_hstcfg(priv);
 	i801_enable_host_notify(&priv->adapter);
+	i2c_mark_adapter_resumed(&priv->adapter);
 
 	return 0;
 }
Signature · 1 line
2.42.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Heiner, Wolrfam,

Quoted 26 lines · Heiner Kallweit

When entering the suspend callback, at first we should ensure that transfers are finished and I2C core can't start further transfers. Use i2c_mark_adapter_suspended() for this purpose, and complement it with a call to i2c_mark_adapter_resumed() in the resume path.

---
Rebased version of a previously discussed patch, now w/o touching the remove and shutdown path.

---
 drivers/i2c/busses/i2c-i801.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-i801.c +1 -0
index 6d02a8b88..26f132277 100644
@@ -1818,6 +1818,7 @@ static int i801_suspend(struct device *dev)
 {
 	struct i801_priv *priv = dev_get_drvdata(dev);
 
+	i2c_mark_adapter_suspended(&priv->adapter);
 	i801_restore_regs(priv);
 
 	return 0;

drivers/i2c/busses/i2c-i801.c static int i801_resume(struct device *dev) · line 1836

Quoted 7 lines
drivers/i2c/busses/i2c-i801.c +1 -0
@@ -1829,6 +1830,7 @@ static int i801_resume(struct device *dev)
 
 	i801_setup_hstcfg(priv);
 	i801_enable_host_notify(&priv->adapter);
+	i2c_mark_adapter_resumed(&priv->adapter);
 
 	return 0;
 }

As I said before, I wish this was handled by the driver core instead of device drivers individually, but until that is implemented, I'm fine with this patch, only because other drivers are already doing the same, so it can't be that bad.

To be honest, I'm not even sure why this is necessary. I thought that the driver core was already suspending the device tree from the leafs to the root, and resuming from the root to the leafs, so a child would never be active when its parent isn't. So I just can't see how an I2C transfer can be initiated by an I2C device driver (child) to a suspended I2C adapter (parent). But I'm probably missing something in the driver model. Power management has become so complex over the years...

Signature · 2 lines
Jean Delvare
SUSE L3 Support
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Heiner Kallweit

Hi Heiner,

Quoted 26 lines · Heiner Kallweit

When entering the suspend callback, at first we should ensure that transfers are finished and I2C core can't start further transfers. Use i2c_mark_adapter_suspended() for this purpose, and complement it with a call to i2c_mark_adapter_resumed() in the resume path.

---
Rebased version of a previously discussed patch, now w/o touching the remove and shutdown path.

---
 drivers/i2c/busses/i2c-i801.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-i801.c +1 -0
index 6d02a8b88..26f132277 100644
@@ -1818,6 +1818,7 @@ static int i801_suspend(struct device *dev)
 {
 	struct i801_priv *priv = dev_get_drvdata(dev);
 
+	i2c_mark_adapter_suspended(&priv->adapter);
 	i801_restore_regs(priv);
 
 	return 0;

drivers/i2c/busses/i2c-i801.c static int i801_resume(struct device *dev) · line 1833

Quoted 4 lines
drivers/i2c/busses/i2c-i801.c +1 -0
@@ -1829,6 +1830,7 @@ static int i801_resume(struct device *dev)
 
 	i801_setup_hstcfg(priv);
 	i801_enable_host_notify(&priv->adapter);
+	i2c_mark_adapter_resumed(&priv->adapter);

I think I already reviewed this patch previously and I had same concerns as Jean, anyway,

Andi

Applied
#3 lore raw
In reply to Heiner Kallweit
Quoted 6 lines · Heiner Kallweit

When entering the suspend callback, at first we should ensure that transfers are finished and I2C core can't start further transfers. Use i2c_mark_adapter_suspended() for this purpose, and complement it with a call to i2c_mark_adapter_resumed() in the resume path.

Applied to for-next, thanks!