1 From: Russell King <rmk+kernel@armlinux.org.uk>
2 Bcc: linux@mail.armlinux.org.uk
3 Subject: [PATCH 1/7] i2c: pxa: consolidate i2c_pxa_*xfer() implementations
5 Content-Disposition: inline
6 Content-Transfer-Encoding: 8bit
7 Content-Type: text/plain; charset="utf-8"
9 Most of i2c_pxa_pio_xfer() and i2c_pxa_xfer() are identical; the only
10 differences are that i2c_pxa_pio_xfer() may reset the bus, and they
11 use different underlying transfer functions. The retry loop is the
12 same. Consolidate these two functions.
14 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
16 drivers/i2c/busses/i2c-pxa.c | 36 ++++++++++++++++--------------------
17 1 file changed, 16 insertions(+), 20 deletions(-)
19 diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
20 index c1e50c0b9756..46f1cf97d955 100644
21 --- a/drivers/i2c/busses/i2c-pxa.c
22 +++ b/drivers/i2c/busses/i2c-pxa.c
23 @@ -1102,18 +1102,20 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
27 -static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
28 +static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c,
29 + struct i2c_msg *msgs, int num,
30 + int (*xfer)(struct pxa_i2c *,
31 + struct i2c_msg *, int num))
33 - struct pxa_i2c *i2c = adap->algo_data;
36 - for (i = adap->retries; i >= 0; i--) {
37 - ret = i2c_pxa_do_xfer(i2c, msgs, num);
38 + for (i = i2c->adap.retries; i >= 0; i--) {
39 + ret = xfer(i2c, msgs, num);
44 - dev_dbg(&adap->dev, "Retrying transmission\n");
45 + dev_dbg(&i2c->adap.dev, "Retrying transmission\n");
48 i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
49 @@ -1123,6 +1125,14 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num
53 +static int i2c_pxa_xfer(struct i2c_adapter *adap,
54 + struct i2c_msg msgs[], int num)
56 + struct pxa_i2c *i2c = adap->algo_data;
58 + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer);
61 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
63 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
64 @@ -1210,7 +1220,6 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
65 struct i2c_msg msgs[], int num)
67 struct pxa_i2c *i2c = adap->algo_data;
70 /* If the I2C controller is disabled we need to reset it
71 (probably due to a suspend/resume destroying state). We do
72 @@ -1219,20 +1228,7 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,
73 if (!(readl(_ICR(i2c)) & ICR_IUE))
76 - for (i = adap->retries; i >= 0; i--) {
77 - ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
78 - if (ret != I2C_RETRY)
82 - dev_dbg(&adap->dev, "Retrying transmission\n");
85 - i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
88 - i2c_pxa_set_slave(i2c, ret);
90 + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer);
93 static const struct i2c_algorithm i2c_pxa_pio_algorithm = {