Commit 53118db42d201d36ca9067b4bb0e2702399e100b

Authored by Fugang Duan
Committed by haibo.chen
1 parent 01996acd77

ENGR00328312 i2c: imx: Optimize the i2c device recovery solution

From i2c spec, if device pull down the SDA line that causes
i2c bus dead, host can send out 9 clock to let device release
SDA.

But for some special device like pfuze100, it pull down SDA line
and the solution cannot take effort.

The patch just add NACK and STOP signal after 8 dummy clock, and pmic
can release SDA line after the recovery. Test case catch 375 times of
i2c hang, and all are recovered.

Signed-off-by: Fugang Duan <B38611@freescale.com>

Showing 1 changed file with 25 additions and 2 deletions Side-by-side Diff

arch/arm/imx-common/i2c-mxv7.c
... ... @@ -32,13 +32,36 @@
32 32  
33 33 printf("%s: sda=%d scl=%d sda.gp=0x%x scl.gp=0x%x\n", __func__,
34 34 sda, scl, p->sda.gp, p->scl.gp);
  35 + gpio_direction_output(p->scl.gp, 1);
  36 + udelay(1000);
35 37 /* Send high and low on the SCL line */
36 38 for (i = 0; i < 9; i++) {
  39 + gpio_direction_output(p->scl.gp, 1);
  40 + udelay(50);
37 41 gpio_direction_output(p->scl.gp, 0);
38 42 udelay(50);
39   - gpio_direction_input(p->scl.gp);
40   - udelay(50);
41 43 }
  44 +
  45 + /* Simulate the NACK */
  46 + gpio_direction_output(p->sda.gp, 1);
  47 + udelay(50);
  48 + gpio_direction_output(p->scl.gp, 1);
  49 + udelay(50);
  50 + gpio_direction_output(p->scl.gp, 0);
  51 + udelay(50);
  52 +
  53 + /* Simulate the STOP signal */
  54 + gpio_direction_output(p->sda.gp, 0);
  55 + udelay(50);
  56 + gpio_direction_output(p->scl.gp, 1);
  57 + udelay(50);
  58 + gpio_direction_output(p->sda.gp, 1);
  59 + udelay(50);
  60 +
  61 + /* Get the bus status */
  62 + gpio_direction_input(p->sda.gp);
  63 + gpio_direction_input(p->scl.gp);
  64 +
42 65 start_time = get_timer(0);
43 66 for (;;) {
44 67 sda = gpio_get_value(p->sda.gp);