Skip to content

Commit abe4118

Browse files
Wolfram SangWolfram Sang
authored andcommitted
i2c: recovery: if possible send STOP with recovery pulses
I2C clients may misunderstand recovery pulses if they can't read SDA to bail out early. In the worst case, as a write operation. To avoid that and if we can write SDA, try to send STOP to avoid the misinterpretation. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Peter Rosin <peda@axentia.se> Signed-off-by: Wolfram Sang <wsa@the-dreams.de> Cc: stable@kernel.org
1 parent 54836e2 commit abe4118

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,16 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
198198

199199
val = !val;
200200
bri->set_scl(adap, val);
201-
ndelay(RECOVERY_NDELAY);
201+
202+
/*
203+
* If we can set SDA, we will always create STOP here to ensure
204+
* the additional pulses will do no harm. This is achieved by
205+
* letting SDA follow SCL half a cycle later.
206+
*/
207+
ndelay(RECOVERY_NDELAY / 2);
208+
if (bri->set_sda)
209+
bri->set_sda(adap, val);
210+
ndelay(RECOVERY_NDELAY / 2);
202211
}
203212

204213
/* check if recovery actually succeeded */

0 commit comments

Comments
 (0)