b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 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 | --- a/drivers/i2c/busses/i2c-pxa.c |
| 20 | +++ b/drivers/i2c/busses/i2c-pxa.c |
| 21 | @@ -1059,18 +1059,20 @@ static int i2c_pxa_do_xfer(struct pxa_i2 |
| 22 | return ret; |
| 23 | } |
| 24 | |
| 25 | -static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) |
| 26 | +static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c, |
| 27 | + struct i2c_msg *msgs, int num, |
| 28 | + int (*xfer)(struct pxa_i2c *, |
| 29 | + struct i2c_msg *, int num)) |
| 30 | { |
| 31 | - struct pxa_i2c *i2c = adap->algo_data; |
| 32 | int ret, i; |
| 33 | |
| 34 | - for (i = adap->retries; i >= 0; i--) { |
| 35 | - ret = i2c_pxa_do_xfer(i2c, msgs, num); |
| 36 | + for (i = i2c->adap.retries; i >= 0; i--) { |
| 37 | + ret = xfer(i2c, msgs, num); |
| 38 | if (ret != I2C_RETRY) |
| 39 | goto out; |
| 40 | |
| 41 | if (i2c_debug) |
| 42 | - dev_dbg(&adap->dev, "Retrying transmission\n"); |
| 43 | + dev_dbg(&i2c->adap.dev, "Retrying transmission\n"); |
| 44 | udelay(100); |
| 45 | } |
| 46 | i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); |
| 47 | @@ -1080,6 +1082,14 @@ static int i2c_pxa_xfer(struct i2c_adapt |
| 48 | return ret; |
| 49 | } |
| 50 | |
| 51 | +static int i2c_pxa_xfer(struct i2c_adapter *adap, |
| 52 | + struct i2c_msg msgs[], int num) |
| 53 | +{ |
| 54 | + struct pxa_i2c *i2c = adap->algo_data; |
| 55 | + |
| 56 | + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_xfer); |
| 57 | +} |
| 58 | + |
| 59 | static u32 i2c_pxa_functionality(struct i2c_adapter *adap) |
| 60 | { |
| 61 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | |
| 62 | @@ -1163,7 +1173,6 @@ static int i2c_pxa_pio_xfer(struct i2c_a |
| 63 | struct i2c_msg msgs[], int num) |
| 64 | { |
| 65 | struct pxa_i2c *i2c = adap->algo_data; |
| 66 | - int ret, i; |
| 67 | |
| 68 | /* If the I2C controller is disabled we need to reset it |
| 69 | (probably due to a suspend/resume destroying state). We do |
| 70 | @@ -1172,20 +1181,7 @@ static int i2c_pxa_pio_xfer(struct i2c_a |
| 71 | if (!(readl(_ICR(i2c)) & ICR_IUE)) |
| 72 | i2c_pxa_reset(i2c); |
| 73 | |
| 74 | - for (i = adap->retries; i >= 0; i--) { |
| 75 | - ret = i2c_pxa_do_pio_xfer(i2c, msgs, num); |
| 76 | - if (ret != I2C_RETRY) |
| 77 | - goto out; |
| 78 | - |
| 79 | - if (i2c_debug) |
| 80 | - dev_dbg(&adap->dev, "Retrying transmission\n"); |
| 81 | - udelay(100); |
| 82 | - } |
| 83 | - i2c_pxa_scream_blue_murder(i2c, "exhausted retries"); |
| 84 | - ret = -EREMOTEIO; |
| 85 | - out: |
| 86 | - i2c_pxa_set_slave(i2c, ret); |
| 87 | - return ret; |
| 88 | + return i2c_pxa_internal_xfer(i2c, msgs, num, i2c_pxa_do_pio_xfer); |
| 89 | } |
| 90 | |
| 91 | static const struct i2c_algorithm i2c_pxa_pio_algorithm = { |