Further i2c-pxa cleanups
cover Further i2c-pxa cleanups
Hi,
This small series contains some further cleanups to i2c-pxa:
Patch 1 gets rid of the duplication between i2c_pxa_pio_xfer() and i2c_pxa_xfer(), which are mostly identical.
Patch 2 avoids the "exhausted retries" spamming the kernel log when running i2cdetect - this occurs when a slave does not respond. We keep the existing behaviour for all other retries.
Patch 3 changes the kernel messages printed when timeouts happen so they are unique - thus allowing identification of which one triggered.
Patch 4 removes an unnecessary show_state() while waiting for the bus to become free.
drivers/i2c/busses/i2c-pxa.c | 56 +++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 29 deletions(-)
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up
PATCH 1/4 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.
--- drivers/i2c/busses/i2c-pxa.c | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-)
drivers/i2c/busses/i2c-pxa.c +15 -19
@@ -1102,13 +1102,15 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)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; -for (i = adap->retries; i >=0 ; i--) { - ret =i2c_pxa_do_xfer (i2c, msgs, num); +for (i = i2c->adap.retries; i >=0 ; i--) { + ret =xfer (i2c, msgs, num);if (ret !=I2C_RETRY ) goto out;
@@ -1123,6 +1125,14 @@ static int i2c_pxa_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int numreturn 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) { return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL |
@@ -1210,7 +1220,6 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) {struct pxa_i2c *i2c = adap->algo_data; -int ret, i;/* If the I2C controller is disabled we need to reset it (probably due to a suspend/resume destroying state). We do
@@ -1219,20 +1228,7 @@ static int i2c_pxa_pio_xfer(struct i2c_adapter *adap,if (!(readl (_ICR (i2c)) &ICR_IUE ))i2c_pxa_reset (i2c); -for (i = adap->retries; i >=0 ; i--) { - 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; +return i2c_pxa_internal_xfer (i2c, msgs, num, i2c_pxa_do_pio_xfer); }static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
Signature · 1 line
2.20.1
PATCH 2/4 i2c: pxa: avoid complaints with non-responsive slaves
In reply to Russell King - ARM Linux adminRunning i2cdetect on a PXA I2C adapter is very noisy; it complains whenever a slave fails to respond to the address cycle. Since it is normal to probe for slaves in this way, we should not fill the kernel log. This is especially true with SFP modules that take a while to respond on the I2C bus, and probing via the I2C bus is the only way to detect that they are ready.
Fix this by changing the internal transfer return code from I2C_RETRY to a new NO_SLAVE code (mapped to -ENXIO, as per the I2C documentation for this condition, but we still return -EREMOTEIO to the I2C stack to maintain long established driver behaviour.)
--- drivers/i2c/busses/i2c-pxa.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-pxa.c +9 -5
@@ -90,6 +90,7 @@*/ #define DEF_TIMEOUT 32 +#define NO_SLAVE (-ENXIO)#define BUS_ERROR (-EREMOTEIO)#define XFER_NAKED (-ECONNREFUSED)#define I2C_RETRY (-2000)/* an error has occurred retry transmit */
@@ -881,7 +882,7 @@ static void i2c_pxa_irq_txempty(struct pxa_i2c *i2c, u32 isr)*/ if (isr &ISR_ACKNAK ) {if (i2c->msg_ptr ==0 && i2c->msg_idx ==0 ) - ret =I2C_RETRY ; + ret =NO_SLAVE ;else ret =XFER_NAKED ; }
@@ -1109,16 +1110,19 @@ static int i2c_pxa_internal_xfer(struct pxa_i2c *i2c, {int ret, i; -for (i = i2c->adap.retries; i >=0 ; i--) { +for (i =0 ; ; ) { ret =xfer (i2c, msgs, num); -if (ret !=I2C_RETRY ) +if (ret !=I2C_RETRY && ret !=NO_SLAVE ) goto out; +if (++i >= i2c->adap.retries) +break ;if (i2c_debug) -dev_dbg (&adap->dev,"Retrying transmission\n" ); +dev_dbg (&i2c->adap.dev,"Retrying transmission\n" );udelay (100 ); } -i2c_pxa_scream_blue_murder (i2c,"exhausted retries" ); +if (ret !=NO_SLAVE ) +i2c_pxa_scream_blue_murder (i2c,"exhausted retries" ); ret = -EREMOTEIO ; out:i2c_pxa_set_slave (i2c, ret);
Signature · 1 line
2.20.1
PATCH 3/4 i2c: pxa: ensure timeout messages are unique
In reply to Russell King - ARM Linux adminEnsure that the various timeout messages can identify where in the code they were produced from to aid debugging.
--- drivers/i2c/busses/i2c-pxa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-pxa.c +3 -3
@@ -1095,7 +1095,7 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num) ret = i2c->msg_idx;if (!timeout && i2c->msg_num) { -i2c_pxa_scream_blue_murder (i2c,"timeout" ); +i2c_pxa_scream_blue_murder (i2c,"timeout with active message" ); ret =I2C_RETRY ; }
@@ -1169,7 +1169,7 @@ static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)if (timeout <0 ) {show_state (i2c);dev_err (&i2c->adap.dev, -"i2c_pxa: timeout waiting for bus free\n" ); +"i2c_pxa: timeout waiting for bus free (set_master)\n" );return I2C_RETRY ; }
@@ -1213,7 +1213,7 @@ static int i2c_pxa_do_pio_xfer(struct pxa_i2c *i2c, out:if (timeout ==0 ) { -i2c_pxa_scream_blue_murder (i2c,"timeout" ); +i2c_pxa_scream_blue_murder (i2c,"timeout (do_pio_xfer)" ); ret =I2C_RETRY ; }
Signature · 1 line
2.20.1
PATCH 4/4 i2c: pxa: remove some unnecessary debug
In reply to Russell King - ARM Linux adminRemove unnecessary show_state() in the loop inside i2c_pxa_pio_set_master(), which can be unnecessarily verbose.
Remove the i2c_pxa_scream_blue_murder() in i2c_pxa_pio_xfer(), which will trigger if we are probing the I2C bus and a slave does not respond; this is a normal event, and not something to report.
--- drivers/i2c/busses/i2c-pxa.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/i2c/busses/i2c-pxa.c +1 -3
@@ -1161,10 +1161,8 @@ static int i2c_pxa_pio_set_master(struct pxa_i2c *i2c)/* * Wait for the bus to become free. */ -while (timeout-- &&readl (_ISR (i2c)) & (ISR_IBB |ISR_UB )) { +while (timeout-- &&readl (_ISR (i2c)) & (ISR_IBB |ISR_UB ))udelay (1000 ); -show_state (i2c); - }if (timeout <0 ) {show_state (i2c);
Signature · 1 line
2.20.1
Re: [PATCH 1/4] i2c: pxa: consolidate i2c_pxa_*xfer() implementations
In reply to Russell KingQuoted 6 lines · Russell King
Most of
i2c_pxa_pio_xfer()andi2c_pxa_xfer()are identical; the only differences are thati2c_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 Russell King <[email protected]>
Fails to build here:
In file included from ./include/linux/device.h:15,
from ./include/linux/acpi.h:15,
from ./include/linux/i2c.h:13,
from drivers/i2c/busses/i2c-pxa.c:23:
drivers/i2c/busses/i2c-pxa.c: In function ‘i2c_pxa_internal_xfer’:
drivers/i2c/busses/i2c-pxa.c:1118:13: error: ‘adap’ undeclared (first use in this function); did you mean ‘vmap’?
dev_dbg(&adap->dev, "Retrying transmission\n");Re: [PATCH 1/4] i2c: pxa: consolidate i2c_pxa_*xfer() implementations
Quoted 10 lines · Wolfram Sang
Quoted 6 lines · Russell King
Most of
i2c_pxa_pio_xfer()andi2c_pxa_xfer()are identical; the only differences are thati2c_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 Russell King <[email protected]>Fails to build here:
Quoted 8 lines
In file included from
./include/linux/device.h:15,from ./include/linux/acpi.h:15, from ./include/linux/i2c.h:13, from drivers/i2c/busses/i2c-pxa.c:23: drivers/i2c/busses/i2c-pxa.c: In function ‘i2c_pxa_internal_xfer’: drivers/i2c/busses/i2c-pxa.c:1118:13: error: ‘adap’ undeclared (first use in this function); did you mean ‘vmap’? dev_dbg(&adap->dev, "Retrying transmission\n");
I'll take a look at it - it's likely that some changes got missed while keeping all these patches on top of several different trees.
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 10.2Mbps down 587kbps up