All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org>
To: linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
	tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	Vikram Pandita <vikram.pandita-l0cyMroinI0@public.gmane.org>,
	Jon Hunter <jon-hunter-l0cyMroinI0@public.gmane.org>,
	Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org>
Subject: [PATCHv11 6/6] i2c: omap: Recover from Bus Busy condition
Date: Thu, 28 Jun 2012 20:41:32 +0530	[thread overview]
Message-ID: <1340896292-12112-7-git-send-email-shubhrajyoti@ti.com> (raw)
In-Reply-To: <1340896292-12112-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>

From: Vikram Pandita <vikram.pandita-l0cyMroinI0@public.gmane.org>

In case a peripheral is driving SDA bus low (ie. a start condition), provide
a constant clock output using the test mode of the OMAP I2C controller to
try and clear the bus. Soft reset I2C controller after attempting the bus clear
to ensure that controller is in a good state.

Based upon Vikram Pandita's patch from TI Android 3.0.
I acknowledge the contributions and suggestions of Jon and Hemant.

A couple differences from the original patch ...
1. Add a new function for bus clear
2. Ensure that the CON.I2C_EN bit is set when using the SYSTEST feature to
   output a permanent clock. This bit needs to be set and typically it would
   be set by the unidle function but this is not the case for all OMAP
   generations.
3. Program the SYSTEST setting only the bits we care about. However, restore
   SYSTEST registers to there original state as some OMAP generations do not
   implement perform a soft-reset.
4. Clear the CON register after performing the bus clear, so when we call the
   init function the controller is disabled and the init function will
   re-enable later.

Original patch can be found here:
http://git.omapzoom.org/?p=kernel/omap.git;a=commit;h=a2ab04192ba25e60f95ba1ff3af5601a2d7b5bd1

Signed-off-by: Vikram Pandita <vikram.pandita-l0cyMroinI0@public.gmane.org>
Signed-off-by: Jon Hunter <jon-hunter-l0cyMroinI0@public.gmane.org>
Signed-off-by: Shubhrajyoti D <shubhrajyoti-l0cyMroinI0@public.gmane.org>
---
 drivers/i2c/busses/i2c-omap.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 5058dfc..2500f19 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -148,16 +148,15 @@ enum {
 #define OMAP_I2C_SCLH_HSSCLH	8
 
 /* I2C System Test Register (OMAP_I2C_SYSTEST): */
-#ifdef DEBUG
 #define OMAP_I2C_SYSTEST_ST_EN		(1 << 15)	/* System test enable */
 #define OMAP_I2C_SYSTEST_FREE		(1 << 14)	/* Free running mode */
 #define OMAP_I2C_SYSTEST_TMODE_MASK	(3 << 12)	/* Test mode select */
-#define OMAP_I2C_SYSTEST_TMODE_SHIFT	(12)		/* Test mode select */
+#define OMAP_I2C_SYSTEST_TMODE_TEST	(2 << 12)	/* Test mode select */
+#define OMAP_I2C_SYSTEST_TMODE_LOOP	(3 << 12)	/* Test mode select */
 #define OMAP_I2C_SYSTEST_SCL_I		(1 << 3)	/* SCL line sense in */
 #define OMAP_I2C_SYSTEST_SCL_O		(1 << 2)	/* SCL line drive out */
 #define OMAP_I2C_SYSTEST_SDA_I		(1 << 1)	/* SDA line sense in */
 #define OMAP_I2C_SYSTEST_SDA_O		(1 << 0)	/* SDA line drive out */
-#endif
 
 /* OCP_SYSCONFIG bit definitions */
 #define SYSC_CLOCKACTIVITY_MASK		(0x3 << 8)
@@ -458,6 +457,29 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
 
 	return 0;
 }
+/*
+ * Bus Clear
+ */
+static int omap_i2c_bus_clear(struct omap_i2c_dev *dev)
+{
+	u16 w;
+
+	/*
+	 * Per the I2C specification, if we are stuck in a bus busy state
+	 * we can attempt a bus clear to try and recover the bus by sending
+	 * at least 9 clock pulses on SCL. Put the I2C in a test mode so it
+	 * will output a continuous clock on SCL.
+	 */
+	w = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
+	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
+	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, (OMAP_I2C_SYSTEST_ST_EN
+			   | OMAP_I2C_SYSTEST_TMODE_TEST));
+	msleep(1);
+	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, w);
+	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
+	omap_i2c_init(dev);
+	return omap_i2c_wait_for_bb(dev);
+}
 
 /*
  * Low level master read/write transaction.
@@ -584,6 +606,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
 	r = omap_i2c_wait_for_bb(dev);
 	if (r < 0)
+		r = omap_i2c_bus_clear(dev);
+	if (r < 0)
 		goto out;
 
 	if (dev->set_mpu_wkup_lat != NULL)
-- 
1.7.5.4

WARNING: multiple messages have this Message-ID (diff)
From: shubhrajyoti@ti.com (Shubhrajyoti D)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv11 6/6] i2c: omap: Recover from Bus Busy condition
Date: Thu, 28 Jun 2012 20:41:32 +0530	[thread overview]
Message-ID: <1340896292-12112-7-git-send-email-shubhrajyoti@ti.com> (raw)
In-Reply-To: <1340896292-12112-1-git-send-email-shubhrajyoti@ti.com>

From: Vikram Pandita <vikram.pandita@ti.com>

In case a peripheral is driving SDA bus low (ie. a start condition), provide
a constant clock output using the test mode of the OMAP I2C controller to
try and clear the bus. Soft reset I2C controller after attempting the bus clear
to ensure that controller is in a good state.

Based upon Vikram Pandita's patch from TI Android 3.0.
I acknowledge the contributions and suggestions of Jon and Hemant.

A couple differences from the original patch ...
1. Add a new function for bus clear
2. Ensure that the CON.I2C_EN bit is set when using the SYSTEST feature to
   output a permanent clock. This bit needs to be set and typically it would
   be set by the unidle function but this is not the case for all OMAP
   generations.
3. Program the SYSTEST setting only the bits we care about. However, restore
   SYSTEST registers to there original state as some OMAP generations do not
   implement perform a soft-reset.
4. Clear the CON register after performing the bus clear, so when we call the
   init function the controller is disabled and the init function will
   re-enable later.

Original patch can be found here:
http://git.omapzoom.org/?p=kernel/omap.git;a=commit;h=a2ab04192ba25e60f95ba1ff3af5601a2d7b5bd1

Signed-off-by: Vikram Pandita <vikram.pandita@ti.com>
Signed-off-by: Jon Hunter <jon-hunter@ti.com>
Signed-off-by: Shubhrajyoti D <shubhrajyoti@ti.com>
---
 drivers/i2c/busses/i2c-omap.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 5058dfc..2500f19 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -148,16 +148,15 @@ enum {
 #define OMAP_I2C_SCLH_HSSCLH	8
 
 /* I2C System Test Register (OMAP_I2C_SYSTEST): */
-#ifdef DEBUG
 #define OMAP_I2C_SYSTEST_ST_EN		(1 << 15)	/* System test enable */
 #define OMAP_I2C_SYSTEST_FREE		(1 << 14)	/* Free running mode */
 #define OMAP_I2C_SYSTEST_TMODE_MASK	(3 << 12)	/* Test mode select */
-#define OMAP_I2C_SYSTEST_TMODE_SHIFT	(12)		/* Test mode select */
+#define OMAP_I2C_SYSTEST_TMODE_TEST	(2 << 12)	/* Test mode select */
+#define OMAP_I2C_SYSTEST_TMODE_LOOP	(3 << 12)	/* Test mode select */
 #define OMAP_I2C_SYSTEST_SCL_I		(1 << 3)	/* SCL line sense in */
 #define OMAP_I2C_SYSTEST_SCL_O		(1 << 2)	/* SCL line drive out */
 #define OMAP_I2C_SYSTEST_SDA_I		(1 << 1)	/* SDA line sense in */
 #define OMAP_I2C_SYSTEST_SDA_O		(1 << 0)	/* SDA line drive out */
-#endif
 
 /* OCP_SYSCONFIG bit definitions */
 #define SYSC_CLOCKACTIVITY_MASK		(0x3 << 8)
@@ -458,6 +457,29 @@ static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
 
 	return 0;
 }
+/*
+ * Bus Clear
+ */
+static int omap_i2c_bus_clear(struct omap_i2c_dev *dev)
+{
+	u16 w;
+
+	/*
+	 * Per the I2C specification, if we are stuck in a bus busy state
+	 * we can attempt a bus clear to try and recover the bus by sending
+	 *@least 9 clock pulses on SCL. Put the I2C in a test mode so it
+	 * will output a continuous clock on SCL.
+	 */
+	w = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
+	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
+	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, (OMAP_I2C_SYSTEST_ST_EN
+			   | OMAP_I2C_SYSTEST_TMODE_TEST));
+	msleep(1);
+	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, w);
+	omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
+	omap_i2c_init(dev);
+	return omap_i2c_wait_for_bb(dev);
+}
 
 /*
  * Low level master read/write transaction.
@@ -584,6 +606,8 @@ omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 
 	r = omap_i2c_wait_for_bb(dev);
 	if (r < 0)
+		r = omap_i2c_bus_clear(dev);
+	if (r < 0)
 		goto out;
 
 	if (dev->set_mpu_wkup_lat != NULL)
-- 
1.7.5.4

  parent reply	other threads:[~2012-06-28 15:11 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-28 15:11 [PATCHv11 0/6] I2C cleanups Shubhrajyoti D
2012-06-28 15:11 ` Shubhrajyoti D
2012-06-28 15:11 ` [PATCHv11 1/6] i2c: omap: Optimise the remove code Shubhrajyoti D
2012-06-28 15:11   ` Shubhrajyoti D
     [not found]   ` <1340896292-12112-2-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-07-12 12:18     ` Wolfram Sang
2012-07-12 12:18       ` Wolfram Sang
2012-07-13 11:21       ` Shubhrajyoti
2012-07-13 11:21         ` Shubhrajyoti
2012-06-28 15:11 ` [PATCHv11 2/6] i2c: omap: Use SET_RUNTIME_PM_OPS Shubhrajyoti D
2012-06-28 15:11   ` Shubhrajyoti D
2012-07-12 12:19   ` Wolfram Sang
2012-07-12 12:19     ` Wolfram Sang
2012-06-28 15:11 ` [PATCHv11 3/6] i2c: omap: Do not initialise the completion everytime Shubhrajyoti D
2012-06-28 15:11   ` Shubhrajyoti D
     [not found]   ` <1340896292-12112-4-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-06-28 16:03     ` ABRAHAM, KISHON VIJAY
2012-06-28 16:03       ` ABRAHAM, KISHON VIJAY
     [not found]       ` <CAAe_U6Jtoj3mixvp+vqNmkr-RC28AfNqZ0syEE5voEr+Odv3zg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-06-29  1:34         ` Zhang, Shijie
2012-06-29  1:34           ` Zhang, Shijie
2012-07-12 12:19     ` Wolfram Sang
2012-07-12 12:19       ` Wolfram Sang
     [not found]       ` <20120712121928.GC2194-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-13 11:05         ` Shubhrajyoti
2012-07-13 11:05           ` Shubhrajyoti
     [not found] ` <1340896292-12112-1-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-06-28 15:11   ` [PATCHv11 4/6] i2c: omap: Remove the definition of SYSS_RESETDONE_MASK Shubhrajyoti D
2012-06-28 15:11     ` Shubhrajyoti D
     [not found]     ` <1340896292-12112-5-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-07-12 12:20       ` Wolfram Sang
2012-07-12 12:20         ` Wolfram Sang
     [not found]         ` <20120712122053.GD2194-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-13 11:05           ` Shubhrajyoti
2012-07-13 11:05             ` Shubhrajyoti
2012-06-28 15:11   ` Shubhrajyoti D [this message]
2012-06-28 15:11     ` [PATCHv11 6/6] i2c: omap: Recover from Bus Busy condition Shubhrajyoti D
     [not found]     ` <1340896292-12112-7-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-07-12 12:22       ` Wolfram Sang
2012-07-12 12:22         ` Wolfram Sang
     [not found]         ` <20120712122208.GF2194-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-13 11:04           ` Shubhrajyoti
2012-07-13 11:04             ` Shubhrajyoti
2012-06-28 15:11 ` [PATCHv11 5/6] i2c: omap: Correct I2C revision for OMAP3 Shubhrajyoti D
2012-06-28 15:11   ` Shubhrajyoti D
     [not found]   ` <1340896292-12112-6-git-send-email-shubhrajyoti-l0cyMroinI0@public.gmane.org>
2012-07-12 12:21     ` Wolfram Sang
2012-07-12 12:21       ` Wolfram Sang
2012-07-13 11:04       ` Shubhrajyoti
2012-07-13 11:04         ` Shubhrajyoti
2012-07-09 11:47 ` [PATCHv11 0/6] I2C cleanups Shubhrajyoti Datta
2012-07-09 11:47   ` Shubhrajyoti Datta
2012-07-12 12:52   ` Wolfram Sang
2012-07-12 12:52     ` Wolfram Sang
     [not found]     ` <20120712125229.GG2194-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2012-07-13 11:25       ` Shubhrajyoti
2012-07-13 11:25         ` Shubhrajyoti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1340896292-12112-7-git-send-email-shubhrajyoti@ti.com \
    --to=shubhrajyoti-l0cymroini0@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=jon-hunter-l0cyMroinI0@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-omap-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=tony-4v6yS6AI5VpBDgjK7y7TUQ@public.gmane.org \
    --cc=vikram.pandita-l0cyMroinI0@public.gmane.org \
    --cc=w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.