[PATCH] [RFC] i2c-imx: send a soft bus reset during probe

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Fri Sep 28 10:19:15 EDT 2012


Hello,

On Thu, Sep 27, 2012 at 11:53:12AM +0200, Sascha Hauer wrote:
> Sounds good. We often have this problem.
> 
> I wonder if it's worth to have this as a general callback in the i2c
> layer.
Unfortunately my patch doesn't work. The problem is that if an i2c slave
is stuck with sda low the imx diagnoses a loss of arbitration before
even trying to start pulling SDA low to create a start indication.

So I have to use gpio bitbanging and there is no chance to implement
this in generic code only.

> On Thu, Sep 27, 2012 at 12:56:46AM +0200, Uwe Kleine-König wrote:
> > If an i2c slave pulls SDA low when the SoC wants to start a transfer, it
> > cannot get the bus. This can happen for example if the SoC is reset when
> > it just successfully addressed a slave but before it rises SCL for the
> > slave to ack. Currently this makes the driver refuse to do anything. You
> > can force this situation with the following code assuming you have a
> > device on address 0x50:
> > 
BTW, part of the reason I first thought my patch would help is that this
recipe is wrong...

> > 	/* generate a start condition */
> > 	gpio_direction_input(I2CSCL);
> > 	gpio_direction_input(I2CSDA);
> > 	mdelay(1);
> > 	gpio_direction_output(I2CSDA, 0);
> > 
> > 	mdelay(1);
> > 
> > 	/* address device 0x50 */
> > 	for (i = 0; i < 8; ++i) {
> > 		gpio_direction_output(I2CSCL, 0);
> > 		mdelay(1);
> > 		if ((0x50 << 1) >> (7 - i))
... This has to read: if ((0x50 << 1) & (1 << (7 - i))) to actually
stuck the device with address 0x50.

> > 			gpio_direction_input(I2CSDA);
> > 		else
> > 			gpio_direction_output(I2CSDA, 0);
> > 		mdelay(1);
> > 		gpio_direction_input(I2CSCL);
> > 		mdelay(1);
> > 	}
> > 	gpio_direction_output(I2CSCL, 0);
> > 
> > 	reset_cpu(0);
> > 
(And my bus reset used to help because I asserted that the pinmuxing is
right before the reset but not after this stuck recipe, sigh ⊙_◎.)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |



More information about the barebox mailing list