f66759f48beffac99d0ac5e2abefa2db57cfa4eb
[openwrt/staging/luka.git] / target / linux / generic / backport-5.4 / 815-v5.8-i2c-pxa-consolidate-i2c_pxa_-xfer-implementations.patch
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
4 MIME-Version: 1.0
5 Content-Disposition: inline
6 Content-Transfer-Encoding: 8bit
7 Content-Type: text/plain; charset="utf-8"
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.
13
14 Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
15 ---
16 drivers/i2c/busses/i2c-pxa.c | 36 ++++++++++++++++--------------------
17 1 file changed, 16 insertions(+), 20 deletions(-)
18
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)
24 return ret;
25 }
26
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))
32 {
33 - struct pxa_i2c *i2c = adap->algo_data;
34 int ret, i;
35
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);
40 if (ret != I2C_RETRY)
41 goto out;
42
43 if (i2c_debug)
44 - dev_dbg(&adap->dev, "Retrying transmission\n");
45 + dev_dbg(&i2c->adap.dev, "Retrying transmission\n");
46 udelay(100);
47 }
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
50 return ret;
51 }
52
53 +static int i2c_pxa_xfer(struct i2c_adapter *adap,
54 + struct i2c_msg msgs[], int num)
55 +{
56 + struct pxa_i2c *i2c = adap->algo_data;
57 +
58 + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer);
59 +}
60 +
61 static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
62 {
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)
66 {
67 struct pxa_i2c *i2c = adap->algo_data;
68 - int ret, i;
69
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))
74 i2c_pxa_reset(i2c);
75
76 - for (i = adap->retries; i >= 0; i--) {
77 - ret = i2c_pxa_do_pio_xfer(i2c, msgs, num);
78 - if (ret != I2C_RETRY)
79 - goto out;
80 -
81 - if (i2c_debug)
82 - dev_dbg(&adap->dev, "Retrying transmission\n");
83 - udelay(100);
84 - }
85 - i2c_pxa_scream_blue_murder(i2c, "exhausted retries");
86 - ret = -EREMOTEIO;
87 - out:
88 - i2c_pxa_set_slave(i2c, ret);
89 - return ret;
90 + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer);
91 }
92
93 static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
94 --
95 2.20.1
96