linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027
@ 2016-01-27  8:44 ying.zhang22455
  2016-01-27  8:44 ` [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery ying.zhang22455
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: ying.zhang22455 @ 2016-01-27  8:44 UTC (permalink / raw)
  To: linux-i2c; +Cc: xiaobo.xie, york.sun, Ying Zhang

From: Ying Zhang <b40530@freescale.com>

ERR010027/ERR008951: Attempting a start cycle while the
bus is busy may generate a short clock pulse.

Software must ensure that the I2C BUS is idle by checking the
bus busy before switching to master mode and attempting a Start
cycle.

Signed-off-by: Ying Zhang <b40530@freescale.com>
---
 drivers/i2c/busses/i2c-imx.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index a2b132c..f1fe599 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -889,6 +889,13 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
 
 	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
 
+	/* workround for ERR010027: ensure that the I2C BUS is idle
+	   before switching to master mode and attempting a Start cycle
+	 */
+	result =  i2c_imx_bus_busy(i2c_imx, 0);
+	if (result)
+		goto fail0;
+
 	result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
 	if (result < 0)
 		goto out;
-- 
2.1.0.27.g96db324

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

* [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery
  2016-01-27  8:44 [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 ying.zhang22455
@ 2016-01-27  8:44 ` ying.zhang22455
  2016-03-03 21:37   ` Wolfram Sang
  2016-04-26 21:29 ` [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 Wolfram Sang
  2016-04-26 21:30 ` Wolfram Sang
  2 siblings, 1 reply; 5+ messages in thread
From: ying.zhang22455 @ 2016-01-27  8:44 UTC (permalink / raw)
  To: linux-i2c; +Cc: xiaobo.xie, york.sun, Ying Zhang

From: Ying Zhang <b40530@freescale.com>

When a system reset does not cause all I2C devices to be reset, slave can
hold bus low to cause bus hang.
It is necessary to force the I2C module to become the I2C bus master out
of reset and drive SCL.

The patch fixup the bus if a hang has been detected.

Signed-off-by: Ying Zhang <b40530@freescale.com>
---
 drivers/i2c/busses/i2c-imx.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f1fe599..0e0db81 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -411,6 +411,32 @@ static void i2c_imx_dma_free(struct imx_i2c_struct *i2c_imx)
 	dma->chan_using = NULL;
 }
 
+/*
+ * When a system reset does not cause all I2C devices to be reset, it is
+ * sometimes necessary to force the I2C module to become the I2C bus master
+ * out of reset and drive SCL A slave can hold bus low to cause bus hang.
+ * Thus, SDA can be driven low by another I2C device while this I2C module
+ * is coming out of reset and will stay low indefinitely.
+ * The I2C master has to generate 9 clock pulses to get the bus free or idle.
+ */
+static void imx_i2c_fixup(struct imx_i2c_struct *i2c)
+{
+	int k;
+	u32 delay_val = 1000000 / i2c->real_clk + 1;
+
+	if (delay_val < 2)
+		delay_val = 2;
+
+	for (k = 9; k; k--) {
+		imx_i2c_write_reg(0, i2c_imx, IMX_I2C_I2CR);
+		imx_i2c_write_reg(I2CR_MSTA | I2CR_MTX | I2CR_IEN,
+				  i2c_imx, IMX_I2C_I2CR);
+		imx_i2c_read_reg(i2c_imx, IMX_I2C_I2DR);
+		imx_i2c_write_reg(I2CR_IEN, i2c_imx, IMX_I2C_I2CR);
+		udelay(delay_val << 1);
+	}
+}
+
 static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 {
 	unsigned long orig_jiffies = jiffies;
@@ -433,8 +459,15 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
 		if (!for_busy && !(temp & I2SR_IBB))
 			break;
 		if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
+			u8 status = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR);
+
 			dev_dbg(&i2c_imx->adapter.dev,
 				"<%s> I2C bus is busy\n", __func__);
+			if ((status & (I2SR_ICF | I2SR_IBB | I2CR_TXAK)) != 0) {
+				imx_i2c_write_reg(status & ~I2SR_IAL, i2c_imx,
+						  IMX_I2C_I2CR);
+				imx_i2c_fixup();
+			}
 			return -ETIMEDOUT;
 		}
 		schedule();
-- 
2.1.0.27.g96db324

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

* Re: [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery
  2016-01-27  8:44 ` [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery ying.zhang22455
@ 2016-03-03 21:37   ` Wolfram Sang
  0 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2016-03-03 21:37 UTC (permalink / raw)
  To: ying.zhang22455; +Cc: linux-i2c, xiaobo.xie, york.sun, Ying Zhang

[-- Attachment #1: Type: text/plain, Size: 552 bytes --]

On Wed, Jan 27, 2016 at 04:44:43PM +0800, ying.zhang22455@nxp.com wrote:
> From: Ying Zhang <b40530@freescale.com>
> 
> When a system reset does not cause all I2C devices to be reset, slave can
> hold bus low to cause bus hang.
> It is necessary to force the I2C module to become the I2C bus master out
> of reset and drive SCL.
> 
> The patch fixup the bus if a hang has been detected.
> 
> Signed-off-by: Ying Zhang <b40530@freescale.com>

Can't you make use of the generic recovery infrastructure using struct
i2c_bus_recovery_info?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027
  2016-01-27  8:44 [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 ying.zhang22455
  2016-01-27  8:44 ` [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery ying.zhang22455
@ 2016-04-26 21:29 ` Wolfram Sang
  2016-04-26 21:30 ` Wolfram Sang
  2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2016-04-26 21:29 UTC (permalink / raw)
  To: ying.zhang22455; +Cc: linux-i2c, xiaobo.xie, york.sun, Ying Zhang

[-- Attachment #1: Type: text/plain, Size: 1530 bytes --]

On Wed, Jan 27, 2016 at 04:44:42PM +0800, ying.zhang22455@nxp.com wrote:
> From: Ying Zhang <b40530@freescale.com>
> 
> ERR010027/ERR008951: Attempting a start cycle while the
> bus is busy may generate a short clock pulse.
> 
> Software must ensure that the I2C BUS is idle by checking the
> bus busy before switching to master mode and attempting a Start
> cycle.
> 
> Signed-off-by: Ying Zhang <b40530@freescale.com>
> ---
>  drivers/i2c/busses/i2c-imx.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index a2b132c..f1fe599 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -889,6 +889,13 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
>  
>  	dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
>  
> +	/* workround for ERR010027: ensure that the I2C BUS is idle
> +	   before switching to master mode and attempting a Start cycle
> +	 */

Please use kernel coding style for comments.


> +	result =  i2c_imx_bus_busy(i2c_imx, 0);
> +	if (result)
> +		goto fail0;

This is wrong! You need 'goto out'. Please be careful.

> +
>  	result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
>  	if (result < 0)
>  		goto out;
> -- 
> 2.1.0.27.g96db324
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027
  2016-01-27  8:44 [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 ying.zhang22455
  2016-01-27  8:44 ` [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery ying.zhang22455
  2016-04-26 21:29 ` [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 Wolfram Sang
@ 2016-04-26 21:30 ` Wolfram Sang
  2 siblings, 0 replies; 5+ messages in thread
From: Wolfram Sang @ 2016-04-26 21:30 UTC (permalink / raw)
  To: ying.zhang22455; +Cc: linux-i2c, xiaobo.xie, york.sun, Ying Zhang

[-- Attachment #1: Type: text/plain, Size: 60 bytes --]


And what does 'ls1/ls2' in the subject mean? Why not imx?


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2016-04-26 21:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-27  8:44 [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 ying.zhang22455
2016-01-27  8:44 ` [PATCH 2/2] drivers/i2c/i2c-imx.c: improve i2c bus error recovery ying.zhang22455
2016-03-03 21:37   ` Wolfram Sang
2016-04-26 21:29 ` [PATCH 1/2] i2c: ls1/ls2: add workaround for erratum ERR010027 Wolfram Sang
2016-04-26 21:30 ` 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).