From: <shubhrajyoti.datta@gmail.com>
To: <linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>, <michal.simek@xilinx.com>,
Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Subject: [PATCH] i2c: cadence: Implement timeout
Date: Wed, 24 Oct 2018 16:20:03 +0530 [thread overview]
Message-ID: <1540378203-1655-1-git-send-email-shubhrajyoti.datta@gmail.com> (raw)
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
next reply other threads:[~2018-10-24 10:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-24 10:50 shubhrajyoti.datta [this message]
2018-10-24 10:58 ` Russell King - ARM Linux
2019-12-18 11:01 ` Shubhrajyoti Datta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1540378203-1655-1-git-send-email-shubhrajyoti.datta@gmail.com \
--to=shubhrajyoti.datta@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.simek@xilinx.com \
--cc=shubhrajyoti.datta@xilinx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®