linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/5] i2c: Don't start transfers when suspended
@ 2014-07-17 14:48 Bastian Hecht
  2014-07-17 14:48 ` [PATCH v2 2/5] i2c: eg20t: Remove suspension check Bastian Hecht
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Bastian Hecht @ 2014-07-17 14:48 UTC (permalink / raw)
  To: linux-arm-kernel

i2c transfer requests come in very uncontrolled, like from interrupt routines.
We might be suspended when this happens. To avoid i2c timeouts caused by
powered down busses we check for suspension.

Several bus drivers handle this problem on their own. We can clean things up
by moving the protection mechanism into the core.

Signed-off-by: Bastian Hecht <hechtb@gmail.com>
---
changelog v2:

- commit message extended.
- initialization added for adap->suspended
- swapped branch for increased performance


 drivers/i2c/i2c-core.c | 25 ++++++++++++++++++++++++-
 include/linux/i2c.h    |  1 +
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7c7f4b8..b15dc20 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -343,6 +343,13 @@ static int i2c_legacy_resume(struct device *dev)
 static int i2c_device_pm_suspend(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
+	struct i2c_adapter *adap = i2c_verify_adapter(dev);
+
+	if (adap) {
+		i2c_lock_adapter(adap);
+		adap->suspended = true;
+		i2c_unlock_adapter(adap);
+	}
 
 	if (pm)
 		return pm_generic_suspend(dev);
@@ -353,6 +360,13 @@ static int i2c_device_pm_suspend(struct device *dev)
 static int i2c_device_pm_resume(struct device *dev)
 {
 	const struct dev_pm_ops *pm = dev->driver ? dev->driver->pm : NULL;
+	struct i2c_adapter *adap = i2c_verify_adapter(dev);
+
+	if (adap) {
+		i2c_lock_adapter(adap);
+		adap->suspended = false;
+		i2c_unlock_adapter(adap);
+	}
 
 	if (pm)
 		return pm_generic_resume(dev);
@@ -1243,6 +1257,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
 	dev_set_name(&adap->dev, "i2c-%d", adap->nr);
 	adap->dev.bus = &i2c_bus_type;
 	adap->dev.type = &i2c_adapter_type;
+	adap->suspended = false;
 	res = device_register(&adap->dev);
 	if (res)
 		goto out_list;
@@ -1819,7 +1834,10 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 			i2c_lock_adapter(adap);
 		}
 
-		ret = __i2c_transfer(adap, msgs, num);
+		if (!adap->suspended)
+			ret = __i2c_transfer(adap, msgs, num);
+		else
+			ret = -EIO;
 		i2c_unlock_adapter(adap);
 
 		return ret;
@@ -2577,6 +2595,10 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
 
 	if (adapter->algo->smbus_xfer) {
 		i2c_lock_adapter(adapter);
+		if (adapter->suspended) {
+			res = -EIO;
+			goto unlock;
+		}
 
 		/* Retry automatically on arbitration loss */
 		orig_jiffies = jiffies;
@@ -2590,6 +2612,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
 				       orig_jiffies + adapter->timeout))
 				break;
 		}
+unlock:
 		i2c_unlock_adapter(adapter);
 
 		if (res != -EOPNOTSUPP || !adapter->algo->master_xfer)
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index b556e0a..af08c75 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -434,6 +434,7 @@ struct i2c_adapter {
 	int timeout;			/* in jiffies */
 	int retries;
 	struct device dev;		/* the adapter device */
+	unsigned int suspended:1;
 
 	int nr;
 	char name[48];
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-09-19 17:18 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-17 14:48 [PATCH v2 1/5] i2c: Don't start transfers when suspended Bastian Hecht
2014-07-17 14:48 ` [PATCH v2 2/5] i2c: eg20t: Remove suspension check Bastian Hecht
2014-07-17 14:48 ` [PATCH v3 3/5] i2c: exynos5: " Bastian Hecht
2014-07-17 16:54   ` Bastian Hecht
2014-07-17 14:48 ` [PATCH v2 4/5] i2c: sc3c2410: " Bastian Hecht
2014-07-17 14:48 ` [PATCH v2 5/5] i2c: tegra: " Bastian Hecht
2014-07-17 14:59   ` Thierry Reding
2014-07-17 16:52     ` Bastian Hecht
2014-07-17 14:58 ` [PATCH v2 1/5] i2c: Don't start transfers when suspended Bastian Hecht
2014-07-17 15:09   ` Wolfram Sang
2014-07-22 18:01 ` Grygorii Strashko
2014-07-22 21:20   ` Russell King - ARM Linux
2014-09-19 17:18 ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).