summaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-imx.c
diff options
context:
space:
mode:
authorEric Bénard <eric@eukrea.com>2011-01-12 16:21:37 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2011-01-14 10:05:12 +0100
commit2f07c8f41526ba4df44d4e9de339cbebf9c832d4 (patch)
tree5cccc18f39fdad7e56c4a362a169c4b3dd0e647a /drivers/i2c/busses/i2c-imx.c
parent00cf17c9576fd6329627106ac7bcc58b1b53e8e3 (diff)
downloadbarebox-2f07c8f41526ba4df44d4e9de339cbebf9c832d4.tar.gz
barebox-2f07c8f41526ba4df44d4e9de339cbebf9c832d4.tar.xz
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). Signed-off-by: Eric Bénard <eric@eukrea.com> Acked-by: Marc Reilly <marc@cpdesign.com.au> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/i2c/busses/i2c-imx.c')
-rw-r--r--drivers/i2c/busses/i2c-imx.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 266cb52c0c..93e978ed6c 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;