Browse Source

MLK-14698 imx: lpi2c: fix clock issue when NACK detected

For LPI2C IP, NACK is detected by the rising edge of the ninth clock.
In current uboot driver, once NACK is detected, it will reset and then
disable LPI2C master. As a result, we can never see the falling edge
of the ninth clock.

Signed-off-by: Gao Pan <pandy.gao@nxp.com>
Gao Pan 4 years ago
parent
commit
dd139ee52b
1 changed files with 10 additions and 4 deletions
  1. +10
    -4
      drivers/i2c/imx_lpi2c.c

+ 10
- 4
drivers/i2c/imx_lpi2c.c View File

@ -15,6 +15,7 @@
DECLARE_GLOBAL_DATA_PTR;
#define LPI2C_FIFO_SIZE 4
#define LPI2C_NACK_TOUT_MS 1
#define LPI2C_TIMEOUT_MS 100
#ifndef CONFIG_SYS_IMX_I2C1_SPEED
@ -190,6 +191,7 @@ static int bus_i2c_stop(struct i2c_adapter *adap)
struct imx_lpi2c_reg *regs = imx_lpi2c[adap->hwadapnr];
lpi2c_status_t result = LPI2C_SUCESS;
u32 status;
ulong start_time = get_timer(0);
result = bus_i2c_wait_for_tx_ready(adap);
if (result) {
@ -200,7 +202,7 @@ static int bus_i2c_stop(struct i2c_adapter *adap)
/* send stop command */
writel(LPI2C_MTDR_CMD(0x2), &regs->mtdr);
while (result == LPI2C_SUCESS) {
while (1) {
status = readl(&regs->msr);
result = imx_lpci2c_check_clear_error(adap);
/* stop detect flag */
@ -210,6 +212,11 @@ static int bus_i2c_stop(struct i2c_adapter *adap)
writel(status, &regs->msr);
break;
}
if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) {
debug("stop timeout\n");
return -ETIMEDOUT;
}
}
return result;
@ -469,10 +476,9 @@ static int imx_i2c_probe(struct i2c_adapter *adap, uint8_t chip)
}
result = bus_i2c_stop(adap);
if (result) {
if (result)
bus_i2c_init(adap, 100000);
return -result;
}
return result;
}


Loading…
Cancel
Save