public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] i2c-omap: Don't wait needlessly
@ 2008-10-21 16:19 Sakari Ailus
  2008-10-24 10:17 ` Jarkko Nikula
  0 siblings, 1 reply; 5+ messages in thread
From: Sakari Ailus @ 2008-10-21 16:19 UTC (permalink / raw)
  To: linux-omap

When the I2C controller is initialised, software reset is performed to
the controller. I've never seen that taking more than 1 ns while the
msleep call causes excessive delays in I2C transfers.

Tested on OMAP 3.

Signed-off-by: Sakari Ailus <sakari.ailus@nokia.com>
---
 drivers/i2c/busses/i2c-omap.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index b2b0e2f..b19b851 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -40,6 +40,8 @@
 
 /* timeout waiting for the controller to respond */
 #define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
+/* no more busyloop in ns */
+#define OMAP_I2C_MINOR_TIMEOUT		10
 
 #define OMAP_I2C_REV_REG		0x00
 #define OMAP_I2C_IE_REG			0x04
@@ -255,6 +257,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
 	unsigned long internal_clk = 0;
 
 	if (!dev->rev1) {
+		int delay = 0;
+
 		omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
 		/* For some reason we need to set the EN bit before the
 		 * reset done bit gets set. */
@@ -262,6 +266,14 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
 		omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
 		while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
 			 OMAP_I2C_SYSS_RDONE)) {
+			if (delay < OMAP_I2C_MINOR_TIMEOUT) {
+				ndelay(1);
+				delay++;
+				continue;
+			} else if (delay == OMAP_I2C_MINOR_TIMEOUT) {
+				dev_warn(dev->dev, "minor timeout not enough");
+				delay++;
+			}
 			if (time_after(jiffies, timeout)) {
 				dev_warn(dev->dev, "timeout waiting "
 						"for controller reset\n");
-- 
1.5.0.6


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

end of thread, other threads:[~2008-11-25  9:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-21 16:19 [RFC] i2c-omap: Don't wait needlessly Sakari Ailus
2008-10-24 10:17 ` Jarkko Nikula
2008-10-27 16:20   ` Sakari Ailus
2008-11-21 21:43     ` Tony Lindgren
2008-11-25  9:35       ` Sakari Ailus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox