提交 0b71026c 编写于 作者: W Wolfram Sang 提交者: Wolfram Sang

i2c: recovery: refactor recovery function

After exiting the while loop, we checked if recovery was successful and
sent a STOP to the clients. Meanwhile however, we send a STOP after
every pulse, so it is not needed after the loop. If we move the check
for a free bus to the end of the while loop, we can shorten and simplify
the logic. It is still ensured that at least one STOP will be sent to
the wire even if SDA was not stuck low.
Signed-off-by: NWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: NPeter Rosin <peda@axentia.se>
Signed-off-by: NWolfram Sang <wsa@the-dreams.de>
上级 ffc59c49
...@@ -191,9 +191,6 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap) ...@@ -191,9 +191,6 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
ret = -EBUSY; ret = -EBUSY;
break; break;
} }
/* Break if SDA is high */
if (bri->get_sda && bri->get_sda(adap))
break;
} }
val = !val; val = !val;
...@@ -209,22 +206,13 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap) ...@@ -209,22 +206,13 @@ int i2c_generic_scl_recovery(struct i2c_adapter *adap)
if (bri->set_sda) if (bri->set_sda)
bri->set_sda(adap, val); bri->set_sda(adap, val);
ndelay(RECOVERY_NDELAY / 2); ndelay(RECOVERY_NDELAY / 2);
}
/* check if recovery actually succeeded */
if (bri->get_sda && !bri->get_sda(adap))
ret = -EBUSY;
/* If all went well, send STOP for a sane bus state. */ /* Break if SDA is high */
if (ret == 0 && bri->set_sda) { if (val && bri->get_sda) {
bri->set_scl(adap, 0); ret = bri->get_sda(adap) ? 0 : -EBUSY;
ndelay(RECOVERY_NDELAY / 2); if (ret == 0)
bri->set_sda(adap, 0); break;
ndelay(RECOVERY_NDELAY / 2); }
bri->set_scl(adap, 1);
ndelay(RECOVERY_NDELAY / 2);
bri->set_sda(adap, 1);
ndelay(RECOVERY_NDELAY / 2);
} }
if (bri->unprepare_recovery) if (bri->unprepare_recovery)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册