Skip to content

Commit

Permalink
i2c: recovery: if possible send STOP with recovery pulses
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Wolfram Sang authored and Wolfram Sang committed Jul 12, 2018
1 parent 54836e2 commit abe4118
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/i2c/i2c-core-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,16 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)

val = !val;
bri->set_scl(adap, val);
ndelay(RECOVERY_NDELAY);

/*
* If we can set SDA, we will always create STOP here to ensure
* the additional pulses will do no harm. This is achieved by
* letting SDA follow SCL half a cycle later.
*/
ndelay(RECOVERY_NDELAY / 2);
if (bri->set_sda)
bri->set_sda(adap, val);
ndelay(RECOVERY_NDELAY / 2);
}

/* check if recovery actually succeeded */
Expand Down

0 comments on commit abe4118

Please sign in to comment.