Skip to contentSkip to conversation

recover from davinci i2c time out conditions

PATCH In review Philby John 7 participants 15 messages Jul 15, 2009 – Nov 23, 2009 9 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 recover from davinci i2c time out conditions

Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

---
 drivers/i2c/busses/i2c-davinci.c |   98 +++++++++++++++++++++++++++++++++++--
 1 files changed, 92 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-davinci.c +92 -6
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 
 #include <mach/i2c.h>
+#include <mach/mux.h>
+#include <mach/cputype.h>
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT	(1*HZ)
+#define DAVINCI_I2C_MAX_TRIES	2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
 				 DAVINCI_I2C_IMR_SCD | \
 				 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */
+static void disable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		gpio_direction_input(15);
+		gpio_direction_output(14, 0);
+		gpio_set_value(14, 1);
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+	if (cpu_is_davinci_dm355()) {
+		gpio_set_value(14, 0);
+		udelay(20);
+		gpio_set_value(14, 1);
+		udelay(20);
+	}
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function
  * also gets called if I2C encounters any errors.
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
 					 char allow_sleep)
 {
 	unsigned long timeout;
+	u16 i;
+	static u16 to_cnt = 0;
+	u32 flag = 0;
 
 	timeout = jiffies + dev->adapter.timeout;
 	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-	       & DAVINCI_I2C_STR_BB) {
-		if (time_after(jiffies, timeout)) {
-			dev_warn(dev->dev,
-				 "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;
+			& DAVINCI_I2C_STR_BB) {
+
+		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+			if (time_after(jiffies, timeout)) {
+				dev_warn(dev->dev,
+					"timeout waiting for bus ready\n");
+				to_cnt++;
+				return -ETIMEDOUT;
+			}
+		} else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			to_cnt = 0;
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+			i2c_davinci_init(dev);
 		}
 		if (allow_sleep)
 			schedule_timeout(1);
@@ -309,7 +379,23 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 	r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
 						      dev->adapter.timeout);
 	if (r == 0) {
-		dev_err(dev->dev, "controller timed out\n");
+		u16 i;
+		u32 flag = 0;
+		if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			/* Send high and low on the SCL line */
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+		}
 		i2c_davinci_init(dev);
 		dev->buf_len = 0;
 		return -ETIMEDOUT;
Signature · 1 line
1.6.3.3.MVISTA

A message that is not in the archive (sent off-list or not yet received): 1247643267.5981.82.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

Hello.

Quoted 42 lines · Philby John
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

drivers/i2c/busses/i2c-davinci.c +6 -0
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 
 #include <mach/i2c.h>
+#include <mach/mux.h>
+#include <mach/cputype.h>
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT	(1*HZ)
+#define DAVINCI_I2C_MAX_TRIES	2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
 				 DAVINCI_I2C_IMR_SCD | \
 				 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 153

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +10 -0
+ */
+static void disable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		gpio_direction_input(15);
+		gpio_direction_output(14, 0);
+		gpio_set_value(14, 1);

Why not just:

		gpio_direction_output(14, 1);

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 155

Quoted 2 lines
drivers/i2c/busses/i2c-davinci.c +2 -0
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);

Why enable the pins here?

Quoted 53 lines
drivers/i2c/busses/i2c-davinci.c +38 -5
+	}
+	local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+	if (cpu_is_davinci_dm355()) {
+		gpio_set_value(14, 0);
+		udelay(20);
+		gpio_set_value(14, 1);
+		udelay(20);
+	}
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function
  * also gets called if I2C encounters any errors.
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
 					 char allow_sleep)
 {
 	unsigned long timeout;
+	u16 i;
+	static u16 to_cnt = 0;
+	u32 flag = 0;
 
 	timeout = jiffies + dev->adapter.timeout;
 	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-	       & DAVINCI_I2C_STR_BB) {
-		if (time_after(jiffies, timeout)) {
-			dev_warn(dev->dev,
-				 "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;
+			& DAVINCI_I2C_STR_BB) {
+
+		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+			if (time_after(jiffies, timeout)) {
+				dev_warn(dev->dev,

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 292

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +10 -0
+					"timeout waiting for bus ready\n");
+				to_cnt++;
+				return -ETIMEDOUT;
+			}
+		} else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			to_cnt = 0;
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;

Superflous space here...

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 294

Quoted 2 lines
drivers/i2c/busses/i2c-davinci.c +2 -0
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);

How come you're reading from the interrupt mask register but writing
into the mode register which has different layout? :-O

Quoted 12 lines
drivers/i2c/busses/i2c-davinci.c +7 -0
+			/* Disable i2c */
+			disable_i2c_pins();
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+			i2c_davinci_init(dev);
 		}
 		if (allow_sleep)
 			schedule_timeout(1);
@@ -309,7 +379,23 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 	r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,

drivers/i2c/busses/i2c-davinci.c i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) · line 388

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +7 -1
 						      dev->adapter.timeout);
 	if (r == 0) {
-		dev_err(dev->dev, "controller timed out\n");
+		u16 i;
+		u32 flag = 0;
+		if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;

... and here.

drivers/i2c/busses/i2c-davinci.c i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) · line 397

Quoted 9 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			/* Send high and low on the SCL line */
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();

Please factor out the completely identical recovery procedures into the

drivers/i2c/busses/i2c-davinci.c i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) · line 401

Quoted 4 lines
drivers/i2c/busses/i2c-davinci.c +1 -0
+		}
 		i2c_davinci_init(dev);
 		dev->buf_len = 0;
 		return -ETIMEDOUT;

WBR, Sergei

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

Hello Sergei,

Quoted 59 lines · Sergei Shtylyov

Hello.

Quoted 42 lines · Philby John
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

drivers/i2c/busses/i2c-davinci.c +6 -0
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 
 #include <mach/i2c.h>
+#include <mach/mux.h>
+#include <mach/cputype.h>
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT	(1*HZ)
+#define DAVINCI_I2C_MAX_TRIES	2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
 				 DAVINCI_I2C_IMR_SCD | \
 				 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 153

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +10 -0
+ */
+static void disable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		gpio_direction_input(15);
+		gpio_direction_output(14, 0);
+		gpio_set_value(14, 1);

Why not just:

Quoted 6 lines

gpio_direction_output(14, 1);

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 155

Quoted 2 lines
drivers/i2c/busses/i2c-davinci.c +2 -0
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);

Why enable the pins here?

Corrected.

Quoted 58 lines
Quoted 58 lines
drivers/i2c/busses/i2c-davinci.c +42 -5
+	}
+	local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+	if (cpu_is_davinci_dm355()) {
+		gpio_set_value(14, 0);
+		udelay(20);
+		gpio_set_value(14, 1);
+		udelay(20);
+	}
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function
  * also gets called if I2C encounters any errors.
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
 					 char allow_sleep)
 {
 	unsigned long timeout;
+	u16 i;
+	static u16 to_cnt = 0;
+	u32 flag = 0;
 
 	timeout = jiffies + dev->adapter.timeout;
 	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-	       & DAVINCI_I2C_STR_BB) {
-		if (time_after(jiffies, timeout)) {
-			dev_warn(dev->dev,
-				 "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;
+			& DAVINCI_I2C_STR_BB) {
+
+		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+			if (time_after(jiffies, timeout)) {
+				dev_warn(dev->dev,
+					"timeout waiting for bus ready\n");
+				to_cnt++;
+				return -ETIMEDOUT;
+			}
Quoted 8 lines

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 292

Quoted 6 lines
drivers/i2c/busses/i2c-davinci.c +6 -0
+		} else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			to_cnt = 0;
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;

Superflous space here...

Corrected!!

Quoted 23 lines

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 294

Quoted 3 lines
drivers/i2c/busses/i2c-davinci.c +2 -0
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);

How come you're reading from the interrupt mask register but writing
into the mode register which has different layout? :-O

Quoted 16 lines
drivers/i2c/busses/i2c-davinci.c +8 -1
+			/* Disable i2c */
+			disable_i2c_pins();
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+			i2c_davinci_init(dev);
 		}
 		if (allow_sleep)
 			schedule_timeout(1);
@@ -309,7 +379,23 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 	r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
 						      dev->adapter.timeout);
 	if (r == 0) {
-		dev_err(dev->dev, "controller timed out\n");
+		u16 i;
Quoted 8 lines

drivers/i2c/busses/i2c-davinci.c i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) · line 388

Quoted 6 lines
drivers/i2c/busses/i2c-davinci.c +6 -0
+		u32 flag = 0;
+		if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;
    ... and here.

Corrected!

Quoted 12 lines

drivers/i2c/busses/i2c-davinci.c i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop) · line 397

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +9 -0
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			/* Send high and low on the SCL line */
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();

Please factor out the completely identical recovery procedures into the

Understood what you meant to say, now corrected.

Thank you for your valuable comments.
Regards,
Philby

#5 lore raw
In reply to a message not in the archive

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 153

Quoted 13 lines · Philby John

 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */

drivers/i2c/busses/i2c-davinci.c +9 -0
+static void disable_i2c_pins(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (cpu_is_davinci_dm355()) {
+               gpio_direction_input(15);
+               gpio_direction_output(14, 0);
+               gpio_set_value(14, 1);

As noted: gpio_direction_output(14, 1) is better.

Quoted 21 lines

+               davinci_cfg_reg(DM355_I2C_SDA);
+               davinci_cfg_reg(DM355_I2C_SCL);
+       }
+       local_irq_restore(flags);

drivers/i2c/busses/i2c-davinci.c +17 -0
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (cpu_is_davinci_dm355()) {
+               davinci_cfg_reg(DM355_I2C_SDA);
+               davinci_cfg_reg(DM355_I2C_SCL);
+       }
+       local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 184

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +10 -0
+static void pulse_i2c_clock(void)
+{
+       if (cpu_is_davinci_dm355()) {
+               gpio_set_value(14, 0);
+               udelay(20);
+               gpio_set_value(14, 1);
+               udelay(20);
+       }
+}
+

The general problem with how that's done is that the SoC-specific bits should not be in this file. The mach-davinc/dm355.c file should hold that configuration; likewise for other SoCs.

Quoted 6 lines

+                       /* Disable i2c */ +                       disable_i2c_pins(); +                       for (i = 0; i < 10; i++) +                               pulse_i2c_clock(); +                       /* Re-enable i2c */ +                       enable_i2c_pins();

A better description of this is that you're trying to follow the I2Cv3 instructions about how to *reset* the bus, yes?

Quoted 2 lines

+                       i2c_davinci_init(dev);

A message that is not in the archive (sent off-list or not yet received): 200907151010.18709.david-b-yBeKhBN/[email protected]

#7 lore raw

Hello David,

Quoted 16 lines · David Brownell

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 153

Quoted 13 lines · Philby John

/*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */

drivers/i2c/busses/i2c-davinci.c +9 -0
+static void disable_i2c_pins(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (cpu_is_davinci_dm355()) {
+               gpio_direction_input(15);
+               gpio_direction_output(14, 0);
+               gpio_set_value(14, 1);

As noted: gpio_direction_output(14, 1) is better.

Now Corrected!

Quoted 28 lines
Quoted 28 lines
drivers/i2c/busses/i2c-davinci.c +27 -0
+               davinci_cfg_reg(DM355_I2C_SDA);
+               davinci_cfg_reg(DM355_I2C_SCL);
+       }
+       local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       if (cpu_is_davinci_dm355()) {
+               davinci_cfg_reg(DM355_I2C_SDA);
+               davinci_cfg_reg(DM355_I2C_SCL);
+       }
+       local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+       if (cpu_is_davinci_dm355()) {
+               gpio_set_value(14, 0);
+               udelay(20);
+               gpio_set_value(14, 1);
Quoted 8 lines

drivers/i2c/busses/i2c-davinci.c static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg) · line 184

Quoted 4 lines
drivers/i2c/busses/i2c-davinci.c +4 -0
+               udelay(20);
+       }
+}
+

The general problem with how that's done is that the SoC-specific bits should not be in this file. The mach-davinc/dm355.c file should hold that configuration; likewise for other SoCs.

Not quite sure what you were expecting here. What I could do is to set sda_pin and scl_pin in struct davinci_i2c_platform_data, for all davinci platforms there is, rather than make davinci specific changes to i2c-gpio.c I would also prefer not to make changes to board-dm646x-evm.c/board-dm365-evm.c/board-dm355-evm.c etc... Please let me know what you think.

Quoted 10 lines

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 300

Quoted 7 lines
drivers/i2c/busses/i2c-davinci.c +6 -0
+                       /* Disable i2c */
+                       disable_i2c_pins();
+                       for (i = 0; i < 10; i++)
+                               pulse_i2c_clock();
+                       /* Re-enable i2c */
+                       enable_i2c_pins();

A better description of this is that you're trying to follow the I2Cv3 instructions about how to *reset* the bus, yes?

This is correct. To be precise, I am following the bus recovery procedure as outlined in AN10216-01 I2C Manual. Reproducing here as general information.

•SDA line is then non usable anymore because of the “Slave-Transmitter”mode.
•Methods to recover the SDA line are:
–Reset the slave device (assuming the device has a Reset pin) –Use a bus recovery sequence to leave the “Slave-Transmitter” mode •Bus recovery sequence is done as following:
1-Send 9 clock pulses on SCL line
2-Ask the master to keep SDA High until the “Slave-Transmitter” releases the SDA line to perform the ACK operation
3-Keeping SDA High during the ACK means that the “Master-Receiver”does not acknowledge the previous byte receive
4-The “Slave-Transmitter” then goes in an idle state
5-The master then sends a STOP command initializing completely the bus

Thank you for your comments.
Regards,
Philby

#8 lore raw
In reply to a message not in the archive
Quoted 5 lines · Philby John
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Quoted 8 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

---

I personally like the idea behind this patch. But I have heard others argue against it. But it is not related to the ^C issue others have mentioned. That should not happen in the GIT kernel.

Quoted 92 lines
 drivers/i2c/busses/i2c-davinci.c |   98 +++++++++++++++++++++++++++++++++++--
 1 files changed, 92 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-davinci.c +51 -5
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 
 #include <mach/i2c.h>
+#include <mach/mux.h>
+#include <mach/cputype.h>
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT	(1*HZ)
+#define DAVINCI_I2C_MAX_TRIES	2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
 				 DAVINCI_I2C_IMR_SCD | \
 				 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */
+static void disable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		gpio_direction_input(15);
+		gpio_direction_output(14, 0);
+		gpio_set_value(14, 1);
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+	if (cpu_is_davinci_dm355()) {
+		gpio_set_value(14, 0);
+		udelay(20);
+		gpio_set_value(14, 1);
+		udelay(20);
+	}
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function
  * also gets called if I2C encounters any errors.
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
 					 char allow_sleep)
 {
 	unsigned long timeout;
+	u16 i;
+	static u16 to_cnt = 0;
+	u32 flag = 0;
 
 	timeout = jiffies + dev->adapter.timeout;
 	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-	       & DAVINCI_I2C_STR_BB) {
-		if (time_after(jiffies, timeout)) {
-			dev_warn(dev->dev,
-				 "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 287

Quoted 10 lines
drivers/i2c/busses/i2c-davinci.c +10 -0
+			& DAVINCI_I2C_STR_BB) {
+
+		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+			if (time_after(jiffies, timeout)) {
+				dev_warn(dev->dev,
+					"timeout waiting for bus ready\n");
+				to_cnt++;
+				return -ETIMEDOUT;
+			}
+		} else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {

I would not initiate recovery until a timeout occurs. This can be a multi master bus, so a busy condition
may be valid. Then, after multiple timeouts and recovery attempts, return -ETIMEDOUT

Quoted 42 lines
drivers/i2c/busses/i2c-davinci.c +31 -1
+			to_cnt = 0;
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+			i2c_davinci_init(dev);
 		}
 		if (allow_sleep)
 			schedule_timeout(1);
@@ -309,7 +379,23 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
 	r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
 						      dev->adapter.timeout);
 	if (r == 0) {
-		dev_err(dev->dev, "controller timed out\n");
+		u16 i;
+		u32 flag = 0;
+		if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+			dev_err(dev->dev, "initiating i2c bus recovery\n");
+			/* Send the NACK to the slave */
+			flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+			flag |=  DAVINCI_I2C_MDR_NACK;
+			/* write the data into mode register */
+			davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+			/* Disable i2c */
+			disable_i2c_pins();
+			/* Send high and low on the SCL line */
+			for (i = 0; i < 10; i++)
+				pulse_i2c_clock();
+			/* Re-enable i2c */
+			enable_i2c_pins();
+		}
 		i2c_davinci_init(dev);
 		dev->buf_len = 0;
 		return -ETIMEDOUT;

A message that is not in the archive (sent off-list or not yet received): 4A5E0E98.2030108-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org

#10 lore raw

Troy,

Quoted 1 line

<Snip>

Quoted 5 lines

I personally like the idea behind this patch. But I have heard others argue against it. But it is not related to the ^C issue others have mentioned.That should not happen in the GIT kernel.

I do get this ^c timeout issue in DM6446 and DM355. I have the video loopback application running that uses tvp5146 to capture from a video source. When I kill the application it starts giving the error while
the tvp5146 driver tries to send i2c commands to stop capture at tvp5146.
But in this case, it works again when the application is run again. But when I have mt9t031 connected and I do the same thing, it also fails with timeout when application is killed. But it never recovers and I have to reboot the board to recover from the error. So what you mean by "That should not happen in the GIT kernel" ?

Could you explain please?

Murali

A message that is not in the archive (sent off-list or not yet received): A69FA2915331DC488A831521EAE36FE40144FDB54B-UmuGNrFEPrGIQmiDNMet8wC/[email protected]

#12 lore raw
Quoted 8 lines · Muralidharan

Troy,
<Snip>

Quoted 5 lines

I personally like the idea behind this patch. But I have heard others argue against it. But it is not related to the ^C issue others have mentioned.That should not happen in the GIT kernel.

Quoted 8 lines

I do get this ^c timeout issue in DM6446 and DM355. I have the video loopback application running that uses tvp5146 to capture from a video source. When I kill the application it starts giving the error while
the tvp5146 driver tries to send i2c commands to stop capture at tvp5146.
But in this case, it works again when the application is run again. But when I have mt9t031 connected and I do the same thing, it also fails with timeout when application is killed. But it never recovers and I have to reboot the board to recover from the error. So what you mean by "That should not happen in the GIT kernel" ?

Could you explain please?

Murali

please see commit 5a0d5f5ffa5d294d895ef54fc220c6182db63998

I don't know if your issue has the same root cause.

#13 lore raw
In reply to a message not in the archive

Hello Troy,

Quoted 119 lines · Troy Kisky
Quoted 5 lines · Philby John
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Quoted 8 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

---

I personally like the idea behind this patch. But I have heard others argue against it. But it is not related to the ^C issue others have mentioned. That should not happen in the GIT kernel.

Quoted 99 lines
 drivers/i2c/busses/i2c-davinci.c |   98 +++++++++++++++++++++++++++++++++++--
 1 files changed, 92 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-davinci.c +58 -5
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 
 #include <mach/hardware.h>
 
 #include <mach/i2c.h>
+#include <mach/mux.h>
+#include <mach/cputype.h>
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT	(1*HZ)
+#define DAVINCI_I2C_MAX_TRIES	2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
 				 DAVINCI_I2C_IMR_SCD | \
 				 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */
+static void disable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		gpio_direction_input(15);
+		gpio_direction_output(14, 0);
+		gpio_set_value(14, 1);
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+	unsigned long flags;
+
+	local_irq_save(flags);
+	if (cpu_is_davinci_dm355()) {
+		davinci_cfg_reg(DM355_I2C_SDA);
+		davinci_cfg_reg(DM355_I2C_SCL);
+	}
+	local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+	if (cpu_is_davinci_dm355()) {
+		gpio_set_value(14, 0);
+		udelay(20);
+		gpio_set_value(14, 1);
+		udelay(20);
+	}
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function
  * also gets called if I2C encounters any errors.
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev,
 					 char allow_sleep)
 {
 	unsigned long timeout;
+	u16 i;
+	static u16 to_cnt = 0;
+	u32 flag = 0;
 
 	timeout = jiffies + dev->adapter.timeout;
 	while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-	       & DAVINCI_I2C_STR_BB) {
-		if (time_after(jiffies, timeout)) {
-			dev_warn(dev->dev,
-				 "timeout waiting for bus ready\n");
-			return -ETIMEDOUT;
+			& DAVINCI_I2C_STR_BB) {
+
+		if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+			if (time_after(jiffies, timeout)) {
+				dev_warn(dev->dev,
+					"timeout waiting for bus ready\n");
+				to_cnt++;
Quoted 8 lines

drivers/i2c/busses/i2c-davinci.c static int i2c_davinci_wait_bus_not_busy(struct davinci_i2c_dev *dev, · line 287

Quoted 3 lines
drivers/i2c/busses/i2c-davinci.c +3 -0
+				return -ETIMEDOUT;
+			}
+		} else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {

I would not initiate recovery until a timeout occurs. This can be a multi master bus, so a busy condition
may be valid. Then, after multiple timeouts and recovery attempts, return -ETIMEDOUT

Yes, I agree. I wait for a maximum of 2 tries when a timeout occurs before initiating bus recovery.

Regards,
Philby

#14 lore raw
In reply to a message not in the archive

Hello,

----- Original Message ----

Quoted 11 lines

From: Philby John <[email protected]>
To: [email protected]
Cc: [email protected]; davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org
Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out conditions

Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Quoted 7 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Signed-off-by Philby John

I tried this on DM6443 based board with 2.6.18 kernel. The result I am posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

regards

-Nitin

Quoted 147 lines

---
drivers/i2c/busses/i2c-davinci.c | 98 +++++++++++++++++++++++++++++++++++--

1 files changed, 92 insertions(+), 6 deletions(-)
drivers/i2c/busses/i2c-davinci.c +48 -0
index 17f2ee7..4ed1a4c 100755
@@ -35,14 +35,18 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
 #include 
+#include 
+#include 
 
 /* ----- global defines ----------------------------------------------- */
 
 #define DAVINCI_I2C_TIMEOUT    (1*HZ)
+#define DAVINCI_I2C_MAX_TRIES    2
 #define I2C_DAVINCI_INTR_ALL    (DAVINCI_I2C_IMR_AAS | \
                 DAVINCI_I2C_IMR_SCD | \
                 DAVINCI_I2C_IMR_ARDY | \
@@ -135,6 +139,50 @@ static inline u16 davinci_i2c_read_reg(struct 
 davinci_i2c_dev *i2c_dev, int reg)
 }
 
 /*
+ * Configure the i2c data pin as a GPIO input and the i2c clock pin as a
+ * high GPIO output.
+ */
+static void disable_i2c_pins(void)
+{
+    unsigned long flags;
+
+    local_irq_save(flags);
+    if (cpu_is_davinci_dm355()) {
+        gpio_direction_input(15);
+        gpio_direction_output(14, 0);
+        gpio_set_value(14, 1);
+        davinci_cfg_reg(DM355_I2C_SDA);
+        davinci_cfg_reg(DM355_I2C_SCL);
+    }
+    local_irq_restore(flags);
+}
+
+/* Connect the i2c pins to the i2c controller. */
+static void enable_i2c_pins(void)
+{
+    unsigned long flags;
+
+    local_irq_save(flags);
+    if (cpu_is_davinci_dm355()) {
+        davinci_cfg_reg(DM355_I2C_SDA);
+        davinci_cfg_reg(DM355_I2C_SCL);
+    }
+    local_irq_restore(flags);
+}
+
+
+/* Generate a pulse on the i2c clock pin. */
+static void pulse_i2c_clock(void)
+{
+    if (cpu_is_davinci_dm355()) {
+        gpio_set_value(14, 0);
+        udelay(20);
+        gpio_set_value(14, 1);
+        udelay(20);
+    }
+}
+
+/*
  * This functions configures I2C and brings I2C out of reset.
  * This function is called during I2C init function. This function

* also gets called if I2C encounters any errors.

drivers/i2c/busses/i2c-davinci.c +27 -5
@@ -221,14 +269,36 @@ static int i2c_davinci_wait_bus_not_busy(struct 
 davinci_i2c_dev *dev,
                     char allow_sleep)
 {
    unsigned long timeout;
+    u16 i;
+    static u16 to_cnt = 0;
+    u32 flag = 0;
 
    timeout = jiffies + dev->adapter.timeout;
    while (davinci_i2c_read_reg(dev, DAVINCI_I2C_STR_REG)
-           & DAVINCI_I2C_STR_BB) {
-        if (time_after(jiffies, timeout)) {
-            dev_warn(dev->dev,
-                 "timeout waiting for bus ready\n");
-            return -ETIMEDOUT;
+            & DAVINCI_I2C_STR_BB) {
+
+        if (to_cnt <= DAVINCI_I2C_MAX_TRIES) {
+            if (time_after(jiffies, timeout)) {
+                dev_warn(dev->dev,
+                    "timeout waiting for bus ready\n");
+                to_cnt++;
+                return -ETIMEDOUT;
+            }
+        } else if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+            to_cnt = 0;
+            dev_err(dev->dev, "initiating i2c bus recovery\n");
+            /* Send the NACK to the slave */
+            flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+            flag |=  DAVINCI_I2C_MDR_NACK;
+            /* write the data into mode register */
+            davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+            /* Disable i2c */
+            disable_i2c_pins();
+            for (i = 0; i < 10; i++)
+                pulse_i2c_clock();
+            /* Re-enable i2c */
+            enable_i2c_pins();
+            i2c_davinci_init(dev);
        }
        if (allow_sleep)
            schedule_timeout(1);
drivers/i2c/busses/i2c-davinci.c +17 -1
@@ -309,7 +379,23 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct 
 i2c_msg *msg, int stop)
    r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
                              dev->adapter.timeout);
    if (r == 0) {
-        dev_err(dev->dev, "controller timed out\n");
+        u16 i;
+        u32 flag = 0;
+        if (cpu_is_davinci_dm644x() || cpu_is_davinci_dm355()) {
+            dev_err(dev->dev, "initiating i2c bus recovery\n");
+            /* Send the NACK to the slave */
+            flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
+            flag |=  DAVINCI_I2C_MDR_NACK;
+            /* write the data into mode register */
+            davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
+            /* Disable i2c */
+            disable_i2c_pins();
+            /* Send high and low on the SCL line */
+            for (i = 0; i < 10; i++)
+                pulse_i2c_clock();
+            /* Re-enable i2c */
+            enable_i2c_pins();
+        }
        i2c_davinci_init(dev);
        dev->buf_len = 0;
Quoted 9 lines
        return -ETIMEDOUT;
Signature · 7 lines
1.6.3.3.MVISTA


_______________________________________________
Davinci-linux-open-source mailing list
Davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi+G/[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

New Email addresses available on Yahoo!
Get the Email name you&#39;ve always wanted on the new @ymail and @rocketmail. Hurry before someone else does!
http://mail.promotions.yahoo.com/newdomains/aa/

A message that is not in the archive (sent off-list or not yet received): 218571.29671.qm-LK+a5U5w+t2B9c0Qi4KiSl5cfvJIxWXgQQ4Iyu8u01E@public.gmane.org

#16 lore raw
Quoted 20 lines · Nitin Mahajan

Hello,

----- Original Message ----

Quoted 17 lines

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
To: [email protected]
Cc: [email protected]; davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org
Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out conditions

Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Quoted 8 lines
Quoted 1 line
Signed-off-by Philby John

I tried this on DM6443 based board with 2.6.18 kernel. The result I am posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

There is something gravely wrong about this patch and I would submit a fix shortly incorporating the review comments. But please be aware that I do not guarantee a definitive time line for a fix cause I have much at hand at the moment.

Regards,
Philby

A message that is not in the archive (sent off-list or not yet received): 1248261275.4077.4.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#18 lore raw

The patch submitted appears specific to the dm355. The changes are very similar to the 2.6.10 kernel from mv. If the correct gpio's and pinmux are disabled/enabled it should work for the dm644x.

I took the patch from Philby and tried it on our dm6443 platform (on a 2.6.28 kernel) and it appears to work for the problem we have when the i2c appears to lock up.

Craig

Quoted 47 lines · Philby John
Quoted 24 lines · Nitin Mahajan

Hello,

----- Original Message ----

Quoted 12 lines

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
To: [email protected]
Cc: [email protected]; davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org
Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out conditions

Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17 00:00:00 2001

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out conditions

Quoted 7 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Signed-off-by Philby John
Quoted 7 lines

I tried this on DM6443 based board with 2.6.18 kernel. The result I am posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

There is something gravely wrong about this patch and I would submit a fix shortly incorporating the review comments. But please be aware that I do not guarantee a definitive time line for a fix cause I have much at hand at the moment.

Regards,
Philby

_______________________________________________
Davinci-linux-open-source mailing list Davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Signature · 6 lines
Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199

A message that is not in the archive (sent off-list or not yet received): 200909182312.58018.cmatsuura-/SMLdF/PHsZWk0Htik3J/[email protected]

#20 lore raw

Hello Craig,

Good to know. With out any modifications on a DM6443?

Regards,
Philby

Quoted 91 lines · Craig Matsuura

The patch submitted appears specific to the dm355. The changes are very similar to the 2.6.10 kernel from mv. If the correct gpio's and pinmux are disabled/enabled it should work for the dm644x.

I took the patch from Philby and tried it on our dm6443 platform (on a 2.6.28 kernel) and it appears to work for the problem we have when the i2c appears to lock up.

Craig

Quoted 8 lines · Philby John
Quoted 7 lines · Nitin Mahajan

Hello,

----- Original Message ----

Quoted 3 lines

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
To: [email protected]
Cc: [email protected];

davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out

conditions

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17

00:00:00 2001

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out

conditions

Quoted 10 lines
Quoted 10 lines
Quoted 8 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Signed-off-by Philby John

I tried this on DM6443 based board with 2.6.18 kernel. The result

I am

Quoted 8 lines
Quoted 6 lines

posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

There is something gravely wrong about this patch and I would submit

a

Quoted 1 line

fix shortly incorporating the review comments. But please be aware

that

Quoted 1 line

I do not guarantee a definitive time line for a fix cause I have

much at

Quoted 11 lines

hand at the moment.

Regards,
Philby

_______________________________________________
Davinci-linux-open-source mailing list Davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Signature · 9 lines
______________________________________________________________________


Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199

A message that is not in the archive (sent off-list or not yet received): 1253514660.4507.2.camel-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#22 lore raw

i did modify the patch to work for the dm644x. I believe it is correct, I looked at the 2.6.10 kernel and made the changes to your the i2c-davinci.c after patching it with your patch.

It did nothing without the changes from the 2.6.10 kernel.

Craig

Quoted 108 lines · Philby John

Hello Craig,

Good to know. With out any modifications on a DM6443?

Regards,
Philby

Quoted 100 lines · Craig Matsuura

The patch submitted appears specific to the dm355. The changes are very similar to the 2.6.10 kernel from mv. If the correct gpio's and pinmux are disabled/enabled it should work for the dm644x.

I took the patch from Philby and tried it on our dm6443 platform (on a 2.6.28 kernel) and it appears to work for the problem we have when the i2c appears to lock up.

Craig

Quoted 8 lines · Philby John
Quoted 7 lines · Nitin Mahajan

Hello,

----- Original Message ----

Quoted 3 lines

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
To: [email protected]
Cc: [email protected];

davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out

conditions

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17

00:00:00 2001

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out

conditions

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Signed-off-by Philby John

I tried this on DM6443 based board with 2.6.18 kernel. The result

I am

Quoted 8 lines
Quoted 6 lines

posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

There is something gravely wrong about this patch and I would submit

a

Quoted 1 line

fix shortly incorporating the review comments. But please be aware

that

Quoted 1 line

I do not guarantee a definitive time line for a fix cause I have

much at

Quoted 10 lines

hand at the moment.

Regards,
Philby

_______________________________________________
Davinci-linux-open-source mailing list Davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

--

______________________________________________________________________

Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199

Signature · 6 lines
Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199
#23 lore raw
In reply to a message not in the archive

Philby,

Sorry, I forgot to mention, I did correct a problem with accessing a regs, it is where yo usend a NACK. I changed the read from DAVINCI_I2C_IMR_REG to DAVINCI_I2C_MDR_REG.

 +            flag = davinci_i2c_read_reg(dev, DAVINCI_I2C_IMR_REG);
 +            flag |=  DAVINCI_I2C_MDR_NACK;
 +            /* write the data into mode register */
 +            davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);

Craig

Quoted 108 lines · Philby John

Hello Craig,

Good to know. With out any modifications on a DM6443?

Regards,
Philby

Quoted 100 lines · Craig Matsuura

The patch submitted appears specific to the dm355. The changes are very similar to the 2.6.10 kernel from mv. If the correct gpio's and pinmux are disabled/enabled it should work for the dm644x.

I took the patch from Philby and tried it on our dm6443 platform (on a 2.6.28 kernel) and it appears to work for the problem we have when the i2c appears to lock up.

Craig

Quoted 8 lines · Philby John
Quoted 7 lines · Nitin Mahajan

Hello,

----- Original Message ----

Quoted 3 lines

From: Philby John <pjohn-k0rHJ+Hhz/[email protected]>
To: [email protected]
Cc: [email protected];

davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Sent: Wednesday, July 15, 2009 13:04:27
Subject: [PATCH/RFC 1/1] recover from davinci i2c time out

conditions

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

From dbe7e824d576636bb15b82a20fd2557fddc9a8f7 Mon Sep 17

00:00:00 2001

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

From: Philby John
Date: Tue, 14 Jul 2009 21:46:47 +0530
Subject: [PATCH] Reset i2c bus to come out of time out

conditions

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

Get out of i2c time out condition by resetting
the i2c bus. The kernel must be robust enough to gracefully recover from i2c bus failure without having to reset the machine. This is done by first NACKing the slave and then resetting the i2c bus after a certain timeout.

Signed-off-by Philby John

I tried this on DM6443 based board with 2.6.18 kernel. The result

I am

Quoted 8 lines
Quoted 6 lines

posting below. It gives controller time out again and again.

dhcppc9 login: i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery i2c_davinci i2c_davinci.1: controller timed out i2c_davinci i2c_davinci.1: initiating i2c bus recovery

There is something gravely wrong about this patch and I would submit

a

Quoted 1 line

fix shortly incorporating the review comments. But please be aware

that

Quoted 1 line

I do not guarantee a definitive time line for a fix cause I have

much at

Quoted 10 lines

hand at the moment.

Regards,
Philby

_______________________________________________
Davinci-linux-open-source mailing list Davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/@public.gmane.org

http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

--

______________________________________________________________________

Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199

Signature · 6 lines
Craig Matsuura - Principal Engineer
Control4
11734 South Election Road - Suite 200
Salt Lake City, UT 84020-6432
PH: 801-523-3161
FX: 801-523-3199