Commit 0f03c088 authored by Russell King's avatar Russell King Committed by Wolfram Sang

i2c: pxa: consolidate i2c_pxa_*xfer() implementations

Most of i2c_pxa_pio_xfer() and i2c_pxa_xfer() are identical; the only
differences are that i2c_pxa_pio_xfer() may reset the bus, and they
use different underlying transfer functions. The retry loop is the
same. Consolidate these two functions.
Signed-off-by: default avatarRussell King <rmk+kernel@armlinux.org.uk>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 40e31f0e
...@@ -1102,18 +1102,20 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) ...@@ -1102,18 +1102,20 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
return ret; return ret;
} }
static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c,
struct i2c_msg *msgs, int num,
int (*xfer)(struct pxa_i2c *,
struct i2c_msg *, int num))
{ {
struct pxa_i2c *i2c = adap->algo_data;
int ret, i; int ret, i;
for (i = adap->retries; i >= 0; i--) { for (i = i2c->adap.retries; i >= 0; i--) {
ret = i2c_pxa_do_xfer(i2c, msgs, num); ret = xfer(i2c, msgs, num);
if (ret != I2C_RETRY) if (ret != I2C_RETRY)
goto out; goto out;
if (i2c_debug) if (i2c_debug)
dev_dbg(&adap->dev, "Retrying transmission\n"); dev_dbg(&i2c->adap.dev, "Retrying transmission\n");
udelay(100); udelay(100);
} }
i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
...@@ -1123,6 +1125,14 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num ...@@ -1123,6 +1125,14 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
return ret; return ret;
} }
static int i2c_pxa_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num)
{
struct pxa_i2c *i2c = adap->algo_data;
return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer);
}
static u32 i2c_pxa_functionality(struct i2c_adapter *adap) static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
{ {
return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
...@@ -1210,7 +1220,6 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, ...@@ -1210,7 +1220,6 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
struct i2c_msg msgs[], int num) struct i2c_msg msgs[], int num)
{ {
struct pxa_i2c *i2c = adap->algo_data; struct pxa_i2c *i2c = adap->algo_data;
int ret, i;
/* If the I2C controller is disabled we need to reset it /* If the I2C controller is disabled we need to reset it
(probably due to a suspend/resume destroying state). We do (probably due to a suspend/resume destroying state). We do
...@@ -1219,20 +1228,7 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, ...@@ -1219,20 +1228,7 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
if (!(readl(_ICR(i2c)) & ICR_IUE)) if (!(readl(_ICR(i2c)) & ICR_IUE))
i2c_pxa_reset(i2c); i2c_pxa_reset(i2c);
for (i = adap->retries; i >= 0; i--) { return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer);
ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
if (ret != I2C_RETRY)
goto out;
if (i2c_debug)
dev_dbg(&adap->dev, "Retrying transmission\n");
udelay(100);
}
i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
ret = -EREMOTEIO;
out:
i2c_pxa_set_slave(i2c, ret);
return ret;
} }
static const struct i2c_algorithm i2c_pxa_pio_algorithm = { static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
......
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