From: Haibo Chen Date: Wed, 3 Sep 2014 05:52:07 +0000 (+0800) Subject: i2c: imx: Add arbitration lost check X-Git-Tag: firefly_0821_release~176^2~2995^2~13 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=639a26cf0771cb5a4d61a0f7777882cbda989753;p=firefly-linux-kernel-4.4.55.git i2c: imx: Add arbitration lost check According to the i.mx spec, for multimaster mode, if I2C is enabled when the bus is busy and asserts start, hardware inhibits the transmission, clears MSTA without signaling a stop, generate an interrupt, and set I2C_I2SR[IAL] to indicate a failed attempt to engage the bus, which means arbitration lost. In this case, we should first test I2C_I2SR[IAL], and clear this bit if it is set, and then I2C controller default to slave receive mode. This patch check the IAL bit every time before an I2c transmission. if IAL is set, clear it and make I2C controller to default mode. Signed-off-by: Haibo Chen Acked-by: Fugang Duan Signed-off-by: Wolfram Sang --- diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c index 613069bc561a..ceff87cec18e 100644 --- a/drivers/i2c/busses/i2c-imx.c +++ b/drivers/i2c/busses/i2c-imx.c @@ -268,6 +268,14 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy) while (1) { temp = imx_i2c_read_reg(i2c_imx, IMX_I2C_I2SR); + + /* check for arbitration lost */ + if (temp & I2SR_IAL) { + temp &= ~I2SR_IAL; + imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR); + return -EAGAIN; + } + if (for_busy && (temp & I2SR_IBB)) break; if (!for_busy && !(temp & I2SR_IBB))