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>
(cherry picked from commit dd139ee52b)
imx_v2017.03_4.9.11_1.0.0_ga
Gao Pan 4 years ago
committed by Ye Li
parent
commit
59643c7b34
1 changed files with 9 additions and 4 deletions
  1. +9
    -4
      drivers/i2c/imx_lpi2c.c

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

@ -17,6 +17,7 @@
DECLARE_GLOBAL_DATA_PTR;
#define LPI2C_FIFO_SIZE 4
#define LPI2C_NACK_TOUT_MS 1
#define LPI2C_TIMEOUT_MS 100
/* Weak linked function for overridden by some SoC power function */
@ -191,6 +192,7 @@ static int bus_i2c_stop(struct udevice *bus)
struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)dev_get_addr(bus);
lpi2c_status_t result = LPI2C_SUCESS;
u32 status;
ulong start_time = get_timer(0);
result = bus_i2c_wait_for_tx_ready(bus);
if (result) {
@ -201,7 +203,7 @@ static int bus_i2c_stop(struct udevice *bus)
/* 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(bus);
/* stop detect flag */
@ -211,6 +213,11 @@ static int bus_i2c_stop(struct udevice *bus)
writel(status, &regs->msr);
break;
}
if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) {
debug("stop timeout\n");
return -ETIMEDOUT;
}
}
return result;
@ -366,10 +373,8 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip,
}
result = bus_i2c_stop(bus);
if (result) {
if (result)
bus_i2c_init(bus, 100000);
return -result;
}
return result;
}


Loading…
Cancel
Save