Skip to contentSkip to conversation

i2c: imx: Add arbitration lost check

PATCH Superseded Haibo Chen 3 participants 3 messages Sep 1, 2014 – Sep 2, 2014 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Haibo Chen

author
#0 lore raw

PATCH 1/1 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.

---
 drivers/i2c/busses/i2c-imx.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/i2c/busses/i2c-imx.c +8 -0
index 613069b..144b620 100644
@@ -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 -EIO;
+		}
+
 		if (for_busy && (temp & I2SR_IBB))
 			break;
 		if (!for_busy && !(temp & I2SR_IBB))
Signature · 1 line
1.9.1
Acked-by Fugang Duan
#2 lore raw
In reply to a message not in the archive

From: Haibo Chen <[email protected]> Sent: Monday, September 01, 2014 4:59 PM

Quoted 40 lines

To: wsa-z923LK4zBo2bacvFa/[email protected]
Cc: [email protected]; Duan Fugang-B38611
Subject: [PATCH] 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.

---
drivers/i2c/busses/i2c-imx.c | 8 ++++++++

1 file changed, 8 insertions(+)
drivers/i2c/busses/i2c-imx.c +8 -0
index 613069b..144b620 100644
@@ -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 -EIO;
+		}
+
 		if (for_busy && (temp & I2SR_IBB))
 			break;
		if (!for_busy && !(temp & I2SR_IBB))
Quoted 2 lines

--
1.9.1

Thanks,
Andy

#3 lore raw
In reply to a message not in the archive

drivers/i2c/busses/i2c-imx.c static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy) · line 272

Quoted 8 lines
drivers/i2c/busses/i2c-imx.c +2 -0
@@ -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 **/

One '*' is enough on each side.

drivers/i2c/busses/i2c-imx.c static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy) · line 276

Quoted 4 lines
drivers/i2c/busses/i2c-imx.c +4 -0
+		if (temp & I2SR_IAL) {
+			temp &= ~I2SR_IAL;
+			imx_i2c_write_reg(temp, i2c_imx, IMX_I2C_I2SR);
+			return -EIO;

Documentation/i2c/fault-codes defines 'EAGAIN' for arbitration lost.

Quoted 8 lines
drivers/i2c/busses/i2c-imx.c +2 -0
+		}
+
 		if (for_busy && (temp & I2SR_IBB))
 			break;
 		if (!for_busy && !(temp & I2SR_IBB))
Signature · 1 line
1.9.1