Skip to contentSkip to conversation

i2c: tegra: Add delay before reset the controller

PATCH In review Alok Chauhan 4 participants 9 messages Apr 2, 2012 – Apr 18, 2012

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

PATCH v2 1/1 i2c: tegra: Add delay before reset the controller

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period before reset the
controller in case of NACK error.

---
Added the more descriptive commit message about issue in case of NACK error condition. Changed the comment in code also

 drivers/i2c/busses/i2c-tegra.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-tegra.c +8 -0
index e978635..dfb850a8 100644
@@ -516,6 +516,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 	if (likely(i2c_dev->msg_err == I2C_ERR_NONE))
 		return 0;
 
+	/*
+	 * NACK interrupt generated before I2C controller generates the STOP
+	 * condition on bus. So wait for some time before reset the controller
+	 * so that STOP condition has delivered properly on bus.
+	 */
+	if (i2c_dev->msg_err == I2C_ERR_NO_ACK)
+		udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->bus_clk_rate));
+
 	tegra_i2c_init(i2c_dev);
 	if (i2c_dev->msg_err == I2C_ERR_NO_ACK) {
 		if (msg->flags & I2C_M_IGNORE_NAK)
Signature · 1 line
1.7.4.1
#1 lore raw

Stephen,

I've updated the commit message and comment in the code as per your suggestion. Tegra I2C controller doesn't have idle bit so delay is required before reset the controller in case of NACK error. This delay is calculated purely based on clock period of that particular i2c bus and not passed as hardcoded value. I2C SCL clock-stretching won't affect this calculated delay.

Thanks
Alok

-----Original Message-----
From: Alok Chauhan [mailto:[email protected]]
Sent: Monday, April 02, 2012 11:23 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; Stephen Warren; [email protected]; bones-s3s/[email protected]; [email protected]; [email protected]; Laxman Dewangan; [email protected]; [email protected]; [email protected]
Cc: Alok Chauhan; [email protected]
Subject: [PATCH v2] i2c: tegra: Add delay before reset the controller

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period before reset the controller in case of NACK error.

---
Added the more descriptive commit message about issue in case of NACK error condition. Changed the comment in code also

 drivers/i2c/busses/i2c-tegra.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
drivers/i2c/busses/i2c-tegra.c +8 -0
@@ -516,6 +516,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev,
 	if (likely(i2c_dev->msg_err == I2C_ERR_NONE))
 		return 0;
 
+	/*
+	 * NACK interrupt generated before I2C controller generates the STOP
+	 * condition on bus. So wait for some time before reset the controller
+	 * so that STOP condition has delivered properly on bus.
+	 */
+	if (i2c_dev->msg_err == I2C_ERR_NO_ACK)
+		udelay(DIV_ROUND_UP(2 * 1000000, i2c_dev->bus_clk_rate));
+
 	tegra_i2c_init(i2c_dev);
 	if (i2c_dev->msg_err == I2C_ERR_NO_ACK) {
 		if (msg->flags & I2C_M_IGNORE_NAK)

--
1.7.4.1

#2 lore raw

Hi Alok,
Few / doubts /questions.

Quoted 3 lines · Alok Chauhan

Stephen,

I've updated the commit message and comment in the code as per your suggestion. Tegra I2C controller doesn't have idle bit so delay is required before reset the controller in case of NACK error.  This delay is calculated purely based on clock period of that particular i2c bus and not passed as hardcoded value. I2C SCL clock-stretching won't affect this calculated delay.

Why is it clock cycle dependent?

Is it possible to poll if the stop is sent by controller ?

Quoted 12 lines

Thanks
Alok

-----Original Message-----
From: Alok Chauhan [mailto:[email protected]]
Sent: Monday, April 02, 2012 11:23 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; Stephen Warren; [email protected]; [email protected]; [email protected]; [email protected]; Laxman Dewangan; [email protected]; [email protected]; [email protected]
Cc: Alok Chauhan; [email protected]
Subject: [PATCH v2] i2c: tegra: Add delay before reset the controller

Quoted 3 lines

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period

How did you calculate the 2 clock cycles?

before reset the controller in case of NACK error.

Quoted 8 lines

---
Added the more descriptive commit message about issue in case of NACK error condition. Changed the comment in code also

 drivers/i2c/busses/i2c-tegra.c |    8 ++++++++

 1 files changed, 8 insertions(+), 0 deletions(-)
#3 lore raw

Hi Shubhrajyoti,

Quoted 1 line

Why is it clock cycle dependent?

I think you got me wrong. What I meant to say that delay is calculated based on clock period of that bus. So in this way I don't have to hardcode the delay value.

Quoted 1 line

Is it possible to poll if the stop is sent by controller ?

No, Tegra i2c controller doesn't have any register for STOP condition completion status bit. So delay is the only option here.

Thanks
Alok

-----Original Message-----
From: Shubhrajyoti Datta [mailto:[email protected]]
Sent: Monday, April 02, 2012 3:49 PM
To: Alok Chauhan
Cc: Stephen Warren; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Warren; [email protected]; bones-s3s/[email protected]; [email protected]; Laxman Dewangan; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2] i2c: tegra: Add delay before reset the controller

Hi Alok,
Few / doubts /questions.

Quoted 3 lines · Alok Chauhan

Stephen,

I've updated the commit message and comment in the code as per your suggestion. Tegra I2C controller doesn't have idle bit so delay is required before reset the controller in case of NACK error.  This delay is calculated purely based on clock period of that particular i2c bus and not passed as hardcoded value. I2C SCL clock-stretching won't affect this calculated delay.

Why is it clock cycle dependent?

Is it possible to poll if the stop is sent by controller ?

Quoted 12 lines

Thanks
Alok

-----Original Message-----
From: Alok Chauhan [mailto:[email protected]]
Sent: Monday, April 02, 2012 11:23 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; Stephen Warren; [email protected]; [email protected]; [email protected]; [email protected]; Laxman Dewangan; [email protected]; [email protected]; [email protected]
Cc: Alok Chauhan; [email protected]
Subject: [PATCH v2] i2c: tegra: Add delay before reset the controller

Quoted 3 lines

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period

How did you calculate the 2 clock cycles?

before reset the controller in case of NACK error.

Quoted 8 lines

---
Added the more descriptive commit message about issue in case of NACK error condition. Changed the comment in code also

 drivers/i2c/busses/i2c-tegra.c |    8 ++++++++

 1 files changed, 8 insertions(+), 0 deletions(-)
Acked-by on v2 1/1
#4 lore raw
In reply to Alok Chauhan
Quoted 10 lines · Alok Chauhan

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period before reset the
controller in case of NACK error.

#5 lore raw
Quoted 7 lines · Stephen Warren
Quoted 6 lines · Alok Chauhan

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Quoted 6 lines
Quoted 4 lines

Added delay of 2 clock period before reset the
controller in case of NACK error.

Wolfram, Ben, can this be picked up for 3.5?

#6 lore raw
In reply to Alok Chauhan
Quoted 10 lines · Alok Chauhan

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period before reset the
controller in case of NACK error.

Applied with Stephen's ACK and slightly reworded comment and commit msg.

Wondering a bit that you want it for 3.5, not for 3.4. Looks like a bugfix to me.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
#7 lore raw
Quoted 10 lines · Wolfram Sang
Quoted 9 lines · Alok Chauhan

NACK interrupt generated before I2C controller generates the STOP condition on bus. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition. So wait for some time before resetting the controller so that STOP condition has delivered properly on bus.

Added delay of 2 clock period before reset the
controller in case of NACK error.

Quoted 6 lines
Quoted 1 line

Applied with Stephen's ACK and slightly reworded comment and commit msg.

Wondering a bit that you want it for 3.5, not for 3.4. Looks like a bugfix to me.

Yes, applying this to 3.4 would make sense. When I said "for 3.5" earlier, I meant I'd like it to at least get into 3.5 not later.

Thanks.

#8 lore raw
Quoted 8 lines
Quoted 5 lines

Applied with Stephen's ACK and slightly reworded comment and commit msg.

Wondering a bit that you want it for 3.5, not for 3.4. Looks like a bugfix to me.

Yes, applying this to 3.4 would make sense. When I said "for 3.5" earlier, I meant I'd like it to at least get into 3.5 not later.

Done, thanks for clarifying.

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |