summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorGao Pan <pandy.gao@nxp.com>2017-04-14 15:51:44 +0800
committerYe Li <ye.li@nxp.com>2017-04-20 13:44:12 +0800
commit59643c7b34415c6a23e0d73a8aed9145b0220a47 (patch)
treeb4e07447cb91a382d2c9a10b947c8d14a031b691 /drivers
parent2c101b1d4cccee4eb711110ea19cf92014cf56d8 (diff)
downloadu-boot-imx-59643c7b34415c6a23e0d73a8aed9145b0220a47.zip
u-boot-imx-59643c7b34415c6a23e0d73a8aed9145b0220a47.tar.gz
u-boot-imx-59643c7b34415c6a23e0d73a8aed9145b0220a47.tar.bz2
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 dd139ee52b709c95af3e0c968bcbc3cf42cca408)
Diffstat (limited to 'drivers')
-rw-r--r--drivers/i2c/imx_lpi2c.c13
1 files 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), &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;
}