Commit 9374ed1d authored by Wolfram Sang's avatar Wolfram Sang Committed by Wolfram Sang

i2c: rcar: improve bus busy detection

I2C doesn't define a timeout for bus busy, so an arbitrary value like
LOOP_TIMEOUT is not a good idea. Let's use the timeout value in struct
adapter which is meant for such cases and is user-configurable (via
IOCTL). To reduce the load, wait 10us instead of 1us which is good
enough for the slow frequencies used by I2C. Finally, use the
poll_timeout helper instead of open coding it.
Signed-off-by: default avatarWolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: default avatarNiklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 6af07719
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
...@@ -221,18 +222,18 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv) ...@@ -221,18 +222,18 @@ static void rcar_i2c_init(struct rcar_i2c_priv *priv)
static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv) static int rcar_i2c_bus_barrier(struct rcar_i2c_priv *priv)
{ {
int i; int ret;
u32 val;
for (i = 0; i < LOOP_TIMEOUT; i++) { ret = readl_poll_timeout(priv->io + ICMCR, val, !(val & FSDA), 10,
/* make sure that bus is not busy */ priv->adap.timeout);
if (!(rcar_i2c_read(priv, ICMCR) & FSDA)) if (ret) {
return 0; /* Waiting did not help, try to recover */
udelay(1); priv->recovery_icmcr = MDBS | OBPC | FSDA | FSCL;
ret = i2c_recover_bus(&priv->adap);
} }
/* Waiting did not help, try to recover */ return ret;
priv->recovery_icmcr = MDBS | OBPC | FSDA | FSCL;
return i2c_recover_bus(&priv->adap);
} }
static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment