Skip to contentSkip to conversation

i2c-imx: sync with kernel's driver

PATCH In review Eric Bénard 3 participants 3 messages Jan 12, 2011 – Jan 14, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-imx: sync with kernel's driver

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).

---
 drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
 1 files changed, 8 insertions(+), 27 deletions(-)
drivers/i2c/busses/i2c-imx.c +8 -27
index 266cb52..93e978e 100644
@@ -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;
Signature · 7 lines
1.7.3.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw
Quoted 6 lines · Eric Bénard

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).

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

Quoted 70 lines
---
 drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
 1 files changed, 8 insertions(+), 27 deletions(-)
drivers/i2c/busses/i2c-imx.c +8 -23
index 266cb52..93e978e 100644
@@ -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,

drivers/i2c/busses/i2c-imx.c static int i2c_imx_read(struct i2c_adapter *adapter, · line 369

Quoted 10 lines
drivers/i2c/busses/i2c-imx.c +0 -4
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#2 lore raw
Quoted 10 lines · Marc Reilly
Quoted 6 lines · Eric Bénard

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).

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

Quoted 89 lines

Cheers,
Marc

Quoted 70 lines
---
 drivers/i2c/busses/i2c-imx.c |   35 ++++++++---------------------------
 1 files changed, 8 insertions(+), 27 deletions(-)
drivers/i2c/busses/i2c-imx.c +8 -23
index 266cb52..93e978e 100644
@@ -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,

drivers/i2c/busses/i2c-imx.c static int i2c_imx_read(struct i2c_adapter *adapter, · line 369

Quoted 10 lines
drivers/i2c/busses/i2c-imx.c +0 -4
@@ -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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox