Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1376099

[PATCH v6 13/19] i2c: octeon: Add workaround for broken irqs on CN3860

From Jan Glauber <jglauber@cavium.com>
Newsgroups linux.kernel
Subject [PATCH v6 13/19] i2c: octeon: Add workaround for broken irqs on CN3860
Date 2016-04-11 17:40 +0200
Message-ID <rmM6v-87k-41@gated-at.bofh.it> (permalink)
References <rmLWN-81T-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: David Daney <david.daney@cavium.com>

CN3860 does not interrupt the CPU when the i2c status changes. If
we get a timeout, and see the status has in fact changed, we know we
have this problem, and drop back to polling.

Signed-off-by: David Daney <ddaney@caviumnetworks.com>
Signed-off-by: Jan Glauber <jglauber@cavium.com>
---
 drivers/i2c/busses/i2c-octeon.c | 55 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index bad49cf..bfaee37 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -119,6 +119,8 @@ struct octeon_i2c {
 	void __iomem *twsi_base;
 	struct device *dev;
 	bool hlc_enabled;
+	bool broken_irq_mode;
+	bool broken_irq_check;
 	void (*int_en)(struct octeon_i2c *);
 	void (*int_dis)(struct octeon_i2c *);
 	void (*hlc_int_en)(struct octeon_i2c *);
@@ -378,10 +380,33 @@ static int octeon_i2c_wait(struct octeon_i2c *i2c)
 	long time_left;
 	int first = 1;
 
+	if (i2c->broken_irq_mode) {
+		/*
+		 * Some chip revisions seem to not assert the irq in
+		 * the interrupt controller.  So we must poll for the
+		 * IFLG change.
+		 */
+		u64 end = get_jiffies_64() + i2c->adap.timeout;
+
+		while (!octeon_i2c_test_iflg(i2c) &&
+		       time_before64(get_jiffies_64(), end))
+			udelay(50);
+
+		return octeon_i2c_test_iflg(i2c) ? 0 : -ETIMEDOUT;
+	}
+
 	i2c->int_en(i2c);
 	time_left = wait_event_timeout(i2c->queue, poll_iflg(i2c, &first),
 				       i2c->adap.timeout);
 	i2c->int_dis(i2c);
+
+	if (time_left <= 0 && i2c->broken_irq_check &&
+	    octeon_i2c_test_iflg(i2c)) {
+		dev_err(i2c->dev,
+			"broken irq connection detected, switching to polling mode.\n");
+		i2c->broken_irq_mode = true;
+		return 0;
+	}
 	if (!time_left) {
 		dev_dbg(i2c->dev, "%s: timeout\n", __func__);
 		return -ETIMEDOUT;
@@ -477,17 +502,40 @@ static int octeon_i2c_hlc_wait(struct octeon_i2c *i2c)
 {
 	int time_left;
 
+	if (i2c->broken_irq_mode) {
+		/*
+		 * Some cn38xx boards did not assert the irq in
+		 * the interrupt controller.  So we must poll for the
+		 * IFLG change.
+		 */
+		u64 end = get_jiffies_64() + i2c->adap.timeout;
+
+		while (!octeon_i2c_hlc_test_ready(i2c) &&
+		       time_before64(get_jiffies_64(), end))
+			udelay(50);
+
+		return octeon_i2c_hlc_test_ready(i2c) ? 0 : -ETIMEDOUT;
+	}
+
 	i2c->hlc_int_en(i2c);
 	time_left = wait_event_interruptible_timeout(i2c->queue,
 					octeon_i2c_hlc_test_ready(i2c),
 					i2c->adap.timeout);
 	i2c->hlc_int_dis(i2c);
-	if (!time_left) {
+	if (!time_left)
 		octeon_i2c_hlc_int_clear(i2c);
+
+	if (time_left <= 0 && i2c->broken_irq_check &&
+	    octeon_i2c_hlc_test_ready(i2c)) {
+		dev_err(i2c->dev, "broken irq connection detected, switching to polling mode.\n");
+			i2c->broken_irq_mode = true;
+			return 0;
+	}
+
+	if (!time_left) {
 		dev_dbg(i2c->dev, "%s: timeout\n", __func__);
 		return -ETIMEDOUT;
 	}
-
 	if (time_left < 0) {
 		dev_dbg(i2c->dev, "%s: wait interrupted\n", __func__);
 		return time_left;
@@ -1143,6 +1191,9 @@ static int octeon_i2c_probe(struct platform_device *pdev)
 		goto out;
 	}
 
+	if (OCTEON_IS_MODEL(OCTEON_CN38XX))
+		i2c->broken_irq_check = true;
+
 	result = octeon_i2c_init_lowlevel(i2c);
 	if (result) {
 		dev_err(i2c->dev, "init low level failed\n");
-- 
1.9.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v6 00/19] i2c-octeon and i2c-thunderx drivers Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:30 +0200
  [PATCH v6 14/19] i2c: octeon: Move read function before write Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:30 +0200
  [PATCH v6 06/19] i2c: octeon: Improve error status checking Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:30 +0200
    Re: [PATCH v6 06/19] i2c: octeon: Improve error status checking Wolfram Sang <wsa@the-dreams.de> - 2016-04-13 11:00 +0200
      Re: [PATCH v6 06/19] i2c: octeon: Improve error status checking Jan Glauber <jan.glauber@caviumnetworks.com> - 2016-04-14 10:20 +0200
        Re: [PATCH v6 06/19] i2c: octeon: Improve error status checking Wolfram Sang <wsa@the-dreams.de> - 2016-04-14 11:10 +0200
  [PATCH v6 10/19] i2c: octeon: Add support for cn78xx chips Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:30 +0200
  [PATCH v6 11/19] i2c: octeon: Flush TWSI writes with readback Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 15/19] i2c: octeon: Rename driver to prepare for split Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 17/19] i2c: thunderx: Add i2c driver for ThunderX SOC Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 02/19] i2c: octeon: Move set-clock and init-lowlevel upward Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
    Re: [PATCH v6 02/19] i2c: octeon: Move set-clock and init-lowlevel  upward Wolfram Sang <wsa@the-dreams.de> - 2016-04-13 10:50 +0200
  [PATCH v6 19/19] i2c: thunderx: Add smbus alert support Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 03/19] i2c: octeon: Rename [read|write]_sw to reg_[read|write] Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
    Re: [PATCH v6 03/19] i2c: octeon: Rename [read|write]_sw to  reg_[read|write] Wolfram Sang <wsa@the-dreams.de> - 2016-04-13 10:50 +0200
      Re: [PATCH v6 03/19] i2c: octeon: Rename [read|write]_sw to  reg_[read|write] Jan Glauber <jan.glauber@caviumnetworks.com> - 2016-04-14 10:00 +0200
        Re: [PATCH v6 03/19] i2c: octeon: Rename [read|write]_sw to  reg_[read|write] Wolfram Sang <wsa@the-dreams.de> - 2016-04-14 11:00 +0200
  [PATCH v6 13/19] i2c: octeon: Add workaround for broken irqs on CN3860 Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 07/19] i2c: octeon: Use i2c recovery framework Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
  [PATCH v6 05/19] i2c: octeon: Remove superfluous check in octeon_i2c_test_iflg Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
    Re: [PATCH v6 05/19] i2c: octeon: Remove superfluous check in  octeon_i2c_test_iflg Wolfram Sang <wsa@the-dreams.de> - 2016-04-14 11:00 +0200
  [PATCH v6 04/19] i2c: octeon: Introduce helper functions for register access Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200
    Re: [PATCH v6 04/19] i2c: octeon: Introduce helper functions for  register access Wolfram Sang <wsa@the-dreams.de> - 2016-04-13 10:50 +0200
      Re: [PATCH v6 04/19] i2c: octeon: Introduce helper functions for  register access Jan Glauber <jan.glauber@caviumnetworks.com> - 2016-04-14 10:20 +0200
        Re: [PATCH v6 04/19] i2c: octeon: Introduce helper functions for  register access Wolfram Sang <wsa@the-dreams.de> - 2016-04-14 11:00 +0200
  [PATCH v6 08/19] i2c: octeon: Enable High-Level Controller Jan Glauber <jglauber@cavium.com> - 2016-04-11 17:40 +0200

csiph-web