mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] i2c-imx: sync with kernel's driver
@ 2011-01-12 15:21 Eric Bénard
  2011-01-13 23:45 ` Marc Reilly
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Bénard @ 2011-01-12 15:21 UTC (permalink / raw)
  To: s.hauer; +Cc: barebox

strange behaviour was observed with actual driver : bus lock, probe of
absent adresses, wrong data read.
This patch sync the driver with linux's one and after a few tests, we
don't see anymore strange behaviour (tested on i.MX27).

Signed-off-by: Eric Bénard <eric@eukrea.com>
---
 drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
 1 files changed, 8 insertions(+), 27 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 266cb52..93e978e 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -151,7 +151,7 @@ static int i2c_imx_bus_busy(struct i2c_adapter *adapter, int for_busy)
 			break;
 		if (!for_busy && !(temp & I2SR_IBB))
 			break;
-		if (is_timeout(start, MSECOND)) {
+		if (is_timeout(start, 500 * MSECOND)) {
 			dev_err(adapter->dev,
 				 "<%s> timeout waiting for I2C bus %s\n",
 				 __func__,for_busy ? "busy" : "not busy");
@@ -170,34 +170,15 @@ static int i2c_imx_trx_complete(struct i2c_adapter *adapter)
 	start = get_time_ns();
 	while (1) {
 		unsigned int reg = readb(base + IMX_I2C_I2SR);
-		if (reg & I2SR_ICF)
-			break;
-
-		if (is_timeout(start, 100 * MSECOND)) {
-			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
-			return -EIO;
-		}
-	}
-
-	return 0;
-}
-
-static int i2c_imx_wait_iif(struct i2c_adapter *adapter)
-{
-	unsigned long base = adapter->dev->map_base;
-	uint64_t start;
-
-	start = get_time_ns();
-	while (1) {
-		unsigned int reg = readb(base + IMX_I2C_I2SR);
 		if (reg & I2SR_IIF)
 			break;
 
 		if (is_timeout(start, 100 * MSECOND)) {
-			dev_err(adapter->dev, "<%s> IIF timeout\n", __func__);
+			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
 			return -EIO;
 		}
 	}
+	writeb(0, base + IMX_I2C_I2SR);
 
 	return 0;
 }
@@ -277,9 +258,13 @@ static void i2c_imx_stop(struct i2c_adapter *adapter)
 		udelay(i2c_imx->disable_delay);
 	}
 
+	if (!i2c_imx->stopped) {
+		i2c_imx_bus_busy(adapter, 0);
+		i2c_imx->stopped = 1;
+	}
+
 	/* Disable I2C controller, and force our state to stopped */
 	writeb(0, base + IMX_I2C_I2CR);
-	i2c_imx->stopped = 1;
 }
 
 static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
@@ -379,10 +364,6 @@ static int i2c_imx_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
 	if (result)
 		return result;
 
-	result = i2c_imx_wait_iif(adapter);
-	if (result)
-		return result;
-
 	/* setup bus to read data */
 	temp = readb(base + IMX_I2C_I2CR);
 	temp &= ~I2CR_MTX;
-- 
1.7.3.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] i2c-imx: sync with kernel's driver
  2011-01-12 15:21 [PATCH] i2c-imx: sync with kernel's driver Eric Bénard
@ 2011-01-13 23:45 ` Marc Reilly
  2011-01-14  9:06   ` Sascha Hauer
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Reilly @ 2011-01-13 23:45 UTC (permalink / raw)
  To: barebox

On Thursday, January 13, 2011 02:21:37 am Eric Bénard wrote:
> strange behaviour was observed with actual driver : bus lock, probe of
> absent adresses, wrong data read.
> This patch sync the driver with linux's one and after a few tests, we
> don't see anymore strange behaviour (tested on i.MX27).
> 
> Signed-off-by: Eric Bénard <eric@eukrea.com>

FWIW, This patch doesn't seem to break anything for me, but I also wasn't 
seeing any problems (that I was aware of!).

Cheers,
Marc

> ---
>  drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
>  1 files changed, 8 insertions(+), 27 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> index 266cb52..93e978e 100644
> --- a/drivers/i2c/busses/i2c-imx.c
> +++ b/drivers/i2c/busses/i2c-imx.c
> @@ -151,7 +151,7 @@ static int i2c_imx_bus_busy(struct i2c_adapter
> *adapter, int for_busy) break;
>  		if (!for_busy && !(temp & I2SR_IBB))
>  			break;
> -		if (is_timeout(start, MSECOND)) {
> +		if (is_timeout(start, 500 * MSECOND)) {
>  			dev_err(adapter->dev,
>  				 "<%s> timeout waiting for I2C bus %s\n",
>  				 __func__,for_busy ? "busy" : "not busy");
> @@ -170,34 +170,15 @@ static int i2c_imx_trx_complete(struct i2c_adapter
> *adapter) start = get_time_ns();
>  	while (1) {
>  		unsigned int reg = readb(base + IMX_I2C_I2SR);
> -		if (reg & I2SR_ICF)
> -			break;
> -
> -		if (is_timeout(start, 100 * MSECOND)) {
> -			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
> -			return -EIO;
> -		}
> -	}
> -
> -	return 0;
> -}
> -
> -static int i2c_imx_wait_iif(struct i2c_adapter *adapter)
> -{
> -	unsigned long base = adapter->dev->map_base;
> -	uint64_t start;
> -
> -	start = get_time_ns();
> -	while (1) {
> -		unsigned int reg = readb(base + IMX_I2C_I2SR);
>  		if (reg & I2SR_IIF)
>  			break;
> 
>  		if (is_timeout(start, 100 * MSECOND)) {
> -			dev_err(adapter->dev, "<%s> IIF timeout\n", __func__);
> +			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
>  			return -EIO;
>  		}
>  	}
> +	writeb(0, base + IMX_I2C_I2SR);
> 
>  	return 0;
>  }
> @@ -277,9 +258,13 @@ static void i2c_imx_stop(struct i2c_adapter *adapter)
>  		udelay(i2c_imx->disable_delay);
>  	}
> 
> +	if (!i2c_imx->stopped) {
> +		i2c_imx_bus_busy(adapter, 0);
> +		i2c_imx->stopped = 1;
> +	}
> +
>  	/* Disable I2C controller, and force our state to stopped */
>  	writeb(0, base + IMX_I2C_I2CR);
> -	i2c_imx->stopped = 1;
>  }
> 
>  static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> @@ -379,10 +364,6 @@ static int i2c_imx_read(struct i2c_adapter *adapter,
> struct i2c_msg *msgs) if (result)
>  		return result;
> 
> -	result = i2c_imx_wait_iif(adapter);
> -	if (result)
> -		return result;
> -
>  	/* setup bus to read data */
>  	temp = readb(base + IMX_I2C_I2CR);
>  	temp &= ~I2CR_MTX;

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] i2c-imx: sync with kernel's driver
  2011-01-13 23:45 ` Marc Reilly
@ 2011-01-14  9:06   ` Sascha Hauer
  0 siblings, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2011-01-14  9:06 UTC (permalink / raw)
  To: Marc Reilly; +Cc: barebox

On Fri, Jan 14, 2011 at 10:45:18AM +1100, Marc Reilly wrote:
> On Thursday, January 13, 2011 02:21:37 am Eric Bénard wrote:
> > strange behaviour was observed with actual driver : bus lock, probe of
> > absent adresses, wrong data read.
> > This patch sync the driver with linux's one and after a few tests, we
> > don't see anymore strange behaviour (tested on i.MX27).
> > 
> > Signed-off-by: Eric Bénard <eric@eukrea.com>
> 
> FWIW, This patch doesn't seem to break anything for me, but I also wasn't 
> seeing any problems (that I was aware of!).

I'll interpret this as an Acked-by.

Sascha

> 
> Cheers,
> Marc
> 
> > ---
> >  drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
> >  1 files changed, 8 insertions(+), 27 deletions(-)
> > 
> > diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
> > index 266cb52..93e978e 100644
> > --- a/drivers/i2c/busses/i2c-imx.c
> > +++ b/drivers/i2c/busses/i2c-imx.c
> > @@ -151,7 +151,7 @@ static int i2c_imx_bus_busy(struct i2c_adapter
> > *adapter, int for_busy) break;
> >  		if (!for_busy && !(temp & I2SR_IBB))
> >  			break;
> > -		if (is_timeout(start, MSECOND)) {
> > +		if (is_timeout(start, 500 * MSECOND)) {
> >  			dev_err(adapter->dev,
> >  				 "<%s> timeout waiting for I2C bus %s\n",
> >  				 __func__,for_busy ? "busy" : "not busy");
> > @@ -170,34 +170,15 @@ static int i2c_imx_trx_complete(struct i2c_adapter
> > *adapter) start = get_time_ns();
> >  	while (1) {
> >  		unsigned int reg = readb(base + IMX_I2C_I2SR);
> > -		if (reg & I2SR_ICF)
> > -			break;
> > -
> > -		if (is_timeout(start, 100 * MSECOND)) {
> > -			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
> > -			return -EIO;
> > -		}
> > -	}
> > -
> > -	return 0;
> > -}
> > -
> > -static int i2c_imx_wait_iif(struct i2c_adapter *adapter)
> > -{
> > -	unsigned long base = adapter->dev->map_base;
> > -	uint64_t start;
> > -
> > -	start = get_time_ns();
> > -	while (1) {
> > -		unsigned int reg = readb(base + IMX_I2C_I2SR);
> >  		if (reg & I2SR_IIF)
> >  			break;
> > 
> >  		if (is_timeout(start, 100 * MSECOND)) {
> > -			dev_err(adapter->dev, "<%s> IIF timeout\n", __func__);
> > +			dev_err(adapter->dev, "<%s> TXR timeout\n", __func__);
> >  			return -EIO;
> >  		}
> >  	}
> > +	writeb(0, base + IMX_I2C_I2SR);
> > 
> >  	return 0;
> >  }
> > @@ -277,9 +258,13 @@ static void i2c_imx_stop(struct i2c_adapter *adapter)
> >  		udelay(i2c_imx->disable_delay);
> >  	}
> > 
> > +	if (!i2c_imx->stopped) {
> > +		i2c_imx_bus_busy(adapter, 0);
> > +		i2c_imx->stopped = 1;
> > +	}
> > +
> >  	/* Disable I2C controller, and force our state to stopped */
> >  	writeb(0, base + IMX_I2C_I2CR);
> > -	i2c_imx->stopped = 1;
> >  }
> > 
> >  static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
> > @@ -379,10 +364,6 @@ static int i2c_imx_read(struct i2c_adapter *adapter,
> > struct i2c_msg *msgs) if (result)
> >  		return result;
> > 
> > -	result = i2c_imx_wait_iif(adapter);
> > -	if (result)
> > -		return result;
> > -
> >  	/* setup bus to read data */
> >  	temp = readb(base + IMX_I2C_I2CR);
> >  	temp &= ~I2CR_MTX;
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2011-01-14  9:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-12 15:21 [PATCH] i2c-imx: sync with kernel's driver Eric Bénard
2011-01-13 23:45 ` Marc Reilly
2011-01-14  9:06   ` Sascha Hauer

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