Commit 59643c7b34415c6a23e0d73a8aed9145b0220a47

Authored by Gao Pan
Committed by Ye Li
1 parent 2c101b1d4c

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)

Showing 1 changed file with 9 additions and 4 deletions Side-by-side Diff

drivers/i2c/imx_lpi2c.c
... ... @@ -17,6 +17,7 @@
17 17  
18 18 DECLARE_GLOBAL_DATA_PTR;
19 19 #define LPI2C_FIFO_SIZE 4
  20 +#define LPI2C_NACK_TOUT_MS 1
20 21 #define LPI2C_TIMEOUT_MS 100
21 22  
22 23 /* Weak linked function for overridden by some SoC power function */
... ... @@ -191,6 +192,7 @@
191 192 struct imx_lpi2c_reg *regs = (struct imx_lpi2c_reg *)dev_get_addr(bus);
192 193 lpi2c_status_t result = LPI2C_SUCESS;
193 194 u32 status;
  195 + ulong start_time = get_timer(0);
194 196  
195 197 result = bus_i2c_wait_for_tx_ready(bus);
196 198 if (result) {
... ... @@ -201,7 +203,7 @@
201 203 /* send stop command */
202 204 writel(LPI2C_MTDR_CMD(0x2), &regs->mtdr);
203 205  
204   - while (result == LPI2C_SUCESS) {
  206 + while (1) {
205 207 status = readl(&regs->msr);
206 208 result = imx_lpci2c_check_clear_error(bus);
207 209 /* stop detect flag */
... ... @@ -211,6 +213,11 @@
211 213 writel(status, &regs->msr);
212 214 break;
213 215 }
  216 +
  217 + if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) {
  218 + debug("stop timeout\n");
  219 + return -ETIMEDOUT;
  220 + }
214 221 }
215 222  
216 223 return result;
217 224  
... ... @@ -366,10 +373,8 @@
366 373 }
367 374  
368 375 result = bus_i2c_stop(bus);
369   - if (result) {
  376 + if (result)
370 377 bus_i2c_init(bus, 100000);
371   - return -result;
372   - }
373 378  
374 379 return result;
375 380 }