From 59643c7b34415c6a23e0d73a8aed9145b0220a47 Mon Sep 17 00:00:00 2001 From: Gao Pan Date: Fri, 14 Apr 2017 15:51:44 +0800 Subject: 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 (cherry picked from commit dd139ee52b709c95af3e0c968bcbc3cf42cca408) --- drivers/i2c/imx_lpi2c.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c index a434ecf..b36186e 100644 --- a/drivers/i2c/imx_lpi2c.c +++ b/drivers/i2c/imx_lpi2c.c @@ -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), ®s->mtdr); - while (result == LPI2C_SUCESS) { + while (1) { status = readl(®s->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, ®s->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; } -- cgit v1.1