i2c: tegra: Add delay before reset the controller
PATCH 1/1 i2c: tegra: Add delay before reset the controller
In NACK error condition, I2C controller violates clock-to-data setup time before stop. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition.
Added delay of 2 clock period before reset the controller in case of NACK error.
---
delay will be calculated based on clock frequency of the bus.
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 ; +/* +* In NACK error condition resetting of I2C controller happens +* before STOP condition is properly completed by I2C controller, +* so wait for 2 clock cycle to complete STOP condition. +*/ +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
Quoted 4 lines · Alok Chauhan
In NACK error condition, I2C controller violates clock-to-data setup time before stop. In Software, because of this reset of controller is happening before I2C controller could complete STOP condition.
I'm not quite sure this description is correct. Surely what's happening is simply that the controller raises the NACK interrupt as soon as it detects a NACK condition. Then, the controller generates the STOP condition on the bus correctly. The issue is that if software resets the controller as soon as the NACK interrupt is raised, this will happen before the controller has completely delivered the STOP condition onto the bus, so we need to pause and wait for that?
I think the commit description and comment in the code should be reworded to describe what I wrote above, assuming it's accurate.
Is there really no idle bit we can poll in the I2C controller to determine when the STOP has completed, rather than just delaying a "hard-coded" time? Can I2C SCL clock-stretching affect the amount of time that must be delayed?