* [PATCH] i2c: cadence: Implement timeout
@ 2018-10-24 10:50 shubhrajyoti.datta
2018-10-24 10:58 ` Russell King - ARM Linux
0 siblings, 1 reply; 3+ messages in thread
From: shubhrajyoti.datta @ 2018-10-24 10:50 UTC (permalink / raw)
To: linux-i2c, linux-kernel
Cc: linux-arm-kernel, michal.simek, Shubhrajyoti Datta
From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
In some cases we are waiting in a loop. Replace the infinite wait with
the timeout.
Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
---
drivers/i2c/busses/i2c-cadence.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index b136057..9c38278 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -209,6 +209,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
struct cdns_i2c *id = ptr;
/* Signal completion only after everything is updated */
int done_flag = 0;
+ unsigned int timeout;
irqreturn_t status = IRQ_NONE;
isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
@@ -235,6 +236,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
((isr_status & CDNS_I2C_IXR_COMP) ||
(isr_status & CDNS_I2C_IXR_DATA))) {
/* Read data if receive data valid is set */
+ timeout = 1000;
while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) &
CDNS_I2C_SR_RXDV) {
/*
@@ -253,6 +255,16 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
if (cdns_is_holdquirk(id, hold_quirk))
break;
+ timeout--;
+ if (timeout)
+ mdelay(1);
+ else
+ break;
+ }
+ if (!timeout) {
+ id->err_status = -ETIMEDOUT;
+ complete(&id->xfer_done);
+ return IRQ_HANDLED;
}
/*
@@ -262,12 +274,22 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
* maintain transfer size non-zero while performing a large
* receive operation.
*/
+ timeout = 1000;
if (cdns_is_holdquirk(id, hold_quirk)) {
/* wait while fifo is full */
- while (cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) !=
- (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH))
- ;
-
+ while ((cdns_i2c_readreg(CDNS_I2C_XFER_SIZE_OFFSET) !=
+ (id->curr_recv_count - CDNS_I2C_FIFO_DEPTH))) {
+ timeout--;
+ if (timeout)
+ mdelay(1);
+ else
+ break;
+ }
+ if (!timeout) {
+ id->err_status = -ETIMEDOUT;
+ complete(&id->xfer_done);
+ return IRQ_HANDLED;
+ }
/*
* Check number of bytes to be received against maximum
* transfer size and update register accordingly.
--
2.1.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: cadence: Implement timeout
2018-10-24 10:50 [PATCH] i2c: cadence: Implement timeout shubhrajyoti.datta
@ 2018-10-24 10:58 ` Russell King - ARM Linux
2019-12-18 11:01 ` Shubhrajyoti Datta
0 siblings, 1 reply; 3+ messages in thread
From: Russell King - ARM Linux @ 2018-10-24 10:58 UTC (permalink / raw)
To: shubhrajyoti.datta
Cc: linux-i2c, linux-kernel, Shubhrajyoti Datta, michal.simek,
linux-arm-kernel
On Wed, Oct 24, 2018 at 04:20:03PM +0530, shubhrajyoti.datta@gmail.com wrote:
> From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
>
> In some cases we are waiting in a loop. Replace the infinite wait with
> the timeout.
>
> Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> ---
> drivers/i2c/busses/i2c-cadence.c | 30 ++++++++++++++++++++++++++----
> 1 file changed, 26 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> index b136057..9c38278 100644
> --- a/drivers/i2c/busses/i2c-cadence.c
> +++ b/drivers/i2c/busses/i2c-cadence.c
> @@ -209,6 +209,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
> struct cdns_i2c *id = ptr;
> /* Signal completion only after everything is updated */
> int done_flag = 0;
> + unsigned int timeout;
> irqreturn_t status = IRQ_NONE;
>
> isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
> @@ -235,6 +236,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
> ((isr_status & CDNS_I2C_IXR_COMP) ||
> (isr_status & CDNS_I2C_IXR_DATA))) {
> /* Read data if receive data valid is set */
> + timeout = 1000;
> while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) &
> CDNS_I2C_SR_RXDV) {
> /*
> @@ -253,6 +255,16 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
>
> if (cdns_is_holdquirk(id, hold_quirk))
> break;
> + timeout--;
> + if (timeout)
> + mdelay(1);
> + else
> + break;
> + }
> + if (!timeout) {
> + id->err_status = -ETIMEDOUT;
> + complete(&id->xfer_done);
> + return IRQ_HANDLED;
Good kernel programming principle: Always check for the success
condition when exiting due to timeout rather than the fact that we
timed out.
Also, is this _really_ a loop that needs a timeout condition? Looking
at the original code, it looks like the purpose of the loop is to read
more than one byte, and you are introducing a 1ms delay between the
read of each byte.
--
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] i2c: cadence: Implement timeout
2018-10-24 10:58 ` Russell King - ARM Linux
@ 2019-12-18 11:01 ` Shubhrajyoti Datta
0 siblings, 0 replies; 3+ messages in thread
From: Shubhrajyoti Datta @ 2019-12-18 11:01 UTC (permalink / raw)
To: Russell King - ARM Linux
Cc: linux-i2c, linux-kernel, Shubhrajyoti Datta, Michal Simek,
linux-arm-kernel
On Wed, Oct 24, 2018 at 4:29 PM Russell King - ARM Linux
<linux@armlinux.org.uk> wrote:
>
> On Wed, Oct 24, 2018 at 04:20:03PM +0530, shubhrajyoti.datta@gmail.com wrote:
> > From: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> >
> > In some cases we are waiting in a loop. Replace the infinite wait with
> > the timeout.
> >
> > Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
> > ---
> > drivers/i2c/busses/i2c-cadence.c | 30 ++++++++++++++++++++++++++----
> > 1 file changed, 26 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
> > index b136057..9c38278 100644
> > --- a/drivers/i2c/busses/i2c-cadence.c
> > +++ b/drivers/i2c/busses/i2c-cadence.c
> > @@ -209,6 +209,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
> > struct cdns_i2c *id = ptr;
> > /* Signal completion only after everything is updated */
> > int done_flag = 0;
> > + unsigned int timeout;
> > irqreturn_t status = IRQ_NONE;
> >
> > isr_status = cdns_i2c_readreg(CDNS_I2C_ISR_OFFSET);
> > @@ -235,6 +236,7 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
> > ((isr_status & CDNS_I2C_IXR_COMP) ||
> > (isr_status & CDNS_I2C_IXR_DATA))) {
> > /* Read data if receive data valid is set */
> > + timeout = 1000;
> > while (cdns_i2c_readreg(CDNS_I2C_SR_OFFSET) &
> > CDNS_I2C_SR_RXDV) {
> > /*
> > @@ -253,6 +255,16 @@ static irqreturn_t cdns_i2c_isr(int irq, void *ptr)
> >
> > if (cdns_is_holdquirk(id, hold_quirk))
> > break;
> > + timeout--;
> > + if (timeout)
> > + mdelay(1);
> > + else
> > + break;
> > + }
> > + if (!timeout) {
> > + id->err_status = -ETIMEDOUT;
> > + complete(&id->xfer_done);
> > + return IRQ_HANDLED;
>
> Good kernel programming principle: Always check for the success
> condition when exiting due to timeout rather than the fact that we
> timed out.
>
> Also, is this _really_ a loop that needs a timeout condition? Looking
> at the original code, it looks like the purpose of the loop is to read
> more than one byte, and you are introducing a 1ms delay between the
> read of each byte.
Thanks for the review.
I agree will skip this patch.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-18 11:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24 10:50 [PATCH] i2c: cadence: Implement timeout shubhrajyoti.datta
2018-10-24 10:58 ` Russell King - ARM Linux
2019-12-18 11:01 ` Shubhrajyoti Datta
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).