diff mbox

i2c: omap: fix bus recovery setup

Message ID 1436366127-24756-1-git-send-email-jlu@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Lübbe July 8, 2015, 2:35 p.m. UTC
At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
allow direct access to the SCL and SDA pins. In addition to ST_EN, we
need to set the TMODE to 0b11 (Loop back & SDA/SCL IO mode select).
Also, as the reset values of SCL_O and SDA_O are 0 (which means "drive
low level"), we need to set them to 1 (which means "high-impedance") to
avoid unwanted changes on the pins.

As a precaution, reset all these bits to their default values after
recovery is complete.

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
---
 drivers/i2c/busses/i2c-omap.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Alexander Sverdlin July 12, 2015, 3:32 p.m. UTC | #1
On 08/07/15 16:35, Jan Luebbe wrote:
> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> allow direct access to the SCL and SDA pins. In addition to ST_EN, we
> need to set the TMODE to 0b11 (Loop back & SDA/SCL IO mode select).
> Also, as the reset values of SCL_O and SDA_O are 0 (which means "drive
> low level"), we need to set them to 1 (which means "high-impedance") to
> avoid unwanted changes on the pins.
> 
> As a precaution, reset all these bits to their default values after
> recovery is complete.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>

Tested with oscilloscope on Beagle Bone Black, without the patch nothing
meningful appears on SCL during recovery, with the patch I'm able to see
the recovery pulses.

Tested-by: Alexander Sverdlin <alexander.sverdlin@gmail.com>

> ---
>  drivers/i2c/busses/i2c-omap.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index d1c22e3fdd14..fc9bf7f30e35 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1247,7 +1247,14 @@ static void omap_i2c_prepare_recovery(struct i2c_adapter *adap)
>  	u32 reg;
>  
>  	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
> +	/* enable test mode */
>  	reg |= OMAP_I2C_SYSTEST_ST_EN;
> +	/* select SDA/SCL IO mode */
> +	reg |= 3 << OMAP_I2C_SYSTEST_TMODE_SHIFT;
> +	/* set SCL to high-impedance state (reset value is 0) */
> +	reg |= OMAP_I2C_SYSTEST_SCL_O;
> +	/* set SDA to high-impedance state (reset value is 0) */
> +	reg |= OMAP_I2C_SYSTEST_SDA_O;
>  	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>  }
>  
> @@ -1257,7 +1264,11 @@ static void omap_i2c_unprepare_recovery(struct i2c_adapter *adap)
>  	u32 reg;
>  
>  	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
> +	/* restore reset values */
>  	reg &= ~OMAP_I2C_SYSTEST_ST_EN;
> +	reg &= ~OMAP_I2C_SYSTEST_TMODE_MASK;
> +	reg &= ~OMAP_I2C_SYSTEST_SCL_O;
> +	reg &= ~OMAP_I2C_SYSTEST_SDA_O;
>  	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>  }
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wolfram Sang July 14, 2015, 11:10 a.m. UTC | #2
On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to

Felipe: it seems you did not need this; is this AM335x specific?

> allow direct access to the SCL and SDA pins. In addition to ST_EN, we
> need to set the TMODE to 0b11 (Loop back & SDA/SCL IO mode select).
> Also, as the reset values of SCL_O and SDA_O are 0 (which means "drive
> low level"), we need to set them to 1 (which means "high-impedance") to
> avoid unwanted changes on the pins.
> 
> As a precaution, reset all these bits to their default values after
> recovery is complete.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
> ---
>  drivers/i2c/busses/i2c-omap.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
> index d1c22e3fdd14..fc9bf7f30e35 100644
> --- a/drivers/i2c/busses/i2c-omap.c
> +++ b/drivers/i2c/busses/i2c-omap.c
> @@ -1247,7 +1247,14 @@ static void omap_i2c_prepare_recovery(struct i2c_adapter *adap)
>  	u32 reg;
>  
>  	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
> +	/* enable test mode */
>  	reg |= OMAP_I2C_SYSTEST_ST_EN;
> +	/* select SDA/SCL IO mode */
> +	reg |= 3 << OMAP_I2C_SYSTEST_TMODE_SHIFT;
> +	/* set SCL to high-impedance state (reset value is 0) */
> +	reg |= OMAP_I2C_SYSTEST_SCL_O;
> +	/* set SDA to high-impedance state (reset value is 0) */
> +	reg |= OMAP_I2C_SYSTEST_SDA_O;
>  	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>  }
>  
> @@ -1257,7 +1264,11 @@ static void omap_i2c_unprepare_recovery(struct i2c_adapter *adap)
>  	u32 reg;
>  
>  	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
> +	/* restore reset values */
>  	reg &= ~OMAP_I2C_SYSTEST_ST_EN;
> +	reg &= ~OMAP_I2C_SYSTEST_TMODE_MASK;
> +	reg &= ~OMAP_I2C_SYSTEST_SCL_O;
> +	reg &= ~OMAP_I2C_SYSTEST_SDA_O;
>  	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>  }
>  
> -- 
> 2.1.4
>
Grygorii Strashko July 14, 2015, 12:10 p.m. UTC | #3
Hi Wolfram,

On 07/14/2015 02:10 PM, Wolfram Sang wrote:
> On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
>> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> 
> Felipe: it seems you did not need this; is this AM335x specific?

We need it (Felipe's reply can be delayed).

It's not AM335x specific. TMODE has to be configured for all OMAP4+ SoCs too.

> 
>> allow direct access to the SCL and SDA pins. In addition to ST_EN, we
>> need to set the TMODE to 0b11 (Loop back & SDA/SCL IO mode select).
>> Also, as the reset values of SCL_O and SDA_O are 0 (which means "drive
>> low level"), we need to set them to 1 (which means "high-impedance") to
>> avoid unwanted changes on the pins.
>>
>> As a precaution, reset all these bits to their default values after
>> recovery is complete.

Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com> 

>>
>> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
>> ---
>>   drivers/i2c/busses/i2c-omap.c | 11 +++++++++++
>>   1 file changed, 11 insertions(+)
>>
>> diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
>> index d1c22e3fdd14..fc9bf7f30e35 100644
>> --- a/drivers/i2c/busses/i2c-omap.c
>> +++ b/drivers/i2c/busses/i2c-omap.c
>> @@ -1247,7 +1247,14 @@ static void omap_i2c_prepare_recovery(struct i2c_adapter *adap)
>>   	u32 reg;
>>   
>>   	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
>> +	/* enable test mode */
>>   	reg |= OMAP_I2C_SYSTEST_ST_EN;
>> +	/* select SDA/SCL IO mode */
>> +	reg |= 3 << OMAP_I2C_SYSTEST_TMODE_SHIFT;
>> +	/* set SCL to high-impedance state (reset value is 0) */
>> +	reg |= OMAP_I2C_SYSTEST_SCL_O;
>> +	/* set SDA to high-impedance state (reset value is 0) */
>> +	reg |= OMAP_I2C_SYSTEST_SDA_O;
>>   	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>>   }
>>   
>> @@ -1257,7 +1264,11 @@ static void omap_i2c_unprepare_recovery(struct i2c_adapter *adap)
>>   	u32 reg;
>>   
>>   	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
>> +	/* restore reset values */
>>   	reg &= ~OMAP_I2C_SYSTEST_ST_EN;
>> +	reg &= ~OMAP_I2C_SYSTEST_TMODE_MASK;
>> +	reg &= ~OMAP_I2C_SYSTEST_SCL_O;
>> +	reg &= ~OMAP_I2C_SYSTEST_SDA_O;
>>   	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
>>   }
>>   
>> -- 
>> 2.1.4
>>
Wolfram Sang July 14, 2015, 12:12 p.m. UTC | #4
On Tue, Jul 14, 2015 at 03:10:01PM +0300, Grygorii Strashko wrote:
> Hi Wolfram,
> 
> On 07/14/2015 02:10 PM, Wolfram Sang wrote:
> > On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
> >> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> > 
> > Felipe: it seems you did not need this; is this AM335x specific?
> 
> We need it (Felipe's reply can be delayed).

So, how did it work for him?

> It's not AM335x specific. TMODE has to be configured for all OMAP4+ SoCs too.

Okay, thanks for the stepping in!
Jan Lübbe July 29, 2015, 10:27 a.m. UTC | #5
On Di, 2015-07-14 at 14:12 +0200, Wolfram Sang wrote:
> On Tue, Jul 14, 2015 at 03:10:01PM +0300, Grygorii Strashko wrote:
> > Hi Wolfram,
> > 
> > On 07/14/2015 02:10 PM, Wolfram Sang wrote:
> > > On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
> > >> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> > > 
> > > Felipe: it seems you did not need this; is this AM335x specific?
> > 
> > We need it (Felipe's reply can be delayed).
> 
> So, how did it work for him?
> 
> > It's not AM335x specific. TMODE has to be configured for all OMAP4+ SoCs too.
> 
> Okay, thanks for the stepping in!

Wolfram, will you pick this as-is?

Regards,
Jan
Wolfram Sang July 31, 2015, 10:49 a.m. UTC | #6
On Wed, Jul 29, 2015 at 12:27:30PM +0200, Jan Lübbe wrote:
> On Di, 2015-07-14 at 14:12 +0200, Wolfram Sang wrote:
> > On Tue, Jul 14, 2015 at 03:10:01PM +0300, Grygorii Strashko wrote:
> > > Hi Wolfram,
> > > 
> > > On 07/14/2015 02:10 PM, Wolfram Sang wrote:
> > > > On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
> > > >> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> > > > 
> > > > Felipe: it seems you did not need this; is this AM335x specific?
> > > 
> > > We need it (Felipe's reply can be delayed).
> > 
> > So, how did it work for him?
> > 
> > > It's not AM335x specific. TMODE has to be configured for all OMAP4+ SoCs too.
> > 
> > Okay, thanks for the stepping in!
> 
> Wolfram, will you pick this as-is?

Yes, I was hoping for an answer to my above question to get a better
understanding, but we can still apply the patches meanwhile.
Wolfram Sang July 31, 2015, 10:51 a.m. UTC | #7
On Wed, Jul 08, 2015 at 04:35:27PM +0200, Jan Luebbe wrote:
> At least on the AM335x, enabling OMAP_I2C_SYSTEST_ST_EN is not enough to
> allow direct access to the SCL and SDA pins. In addition to ST_EN, we
> need to set the TMODE to 0b11 (Loop back & SDA/SCL IO mode select).
> Also, as the reset values of SCL_O and SDA_O are 0 (which means "drive
> low level"), we need to set them to 1 (which means "high-impedance") to
> avoid unwanted changes on the pins.
> 
> As a precaution, reset all these bits to their default values after
> recovery is complete.
> 
> Signed-off-by: Jan Luebbe <jlu@pengutronix.de>

Applied to for-current, thanks!
diff mbox

Patch

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index d1c22e3fdd14..fc9bf7f30e35 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -1247,7 +1247,14 @@  static void omap_i2c_prepare_recovery(struct i2c_adapter *adap)
 	u32 reg;
 
 	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
+	/* enable test mode */
 	reg |= OMAP_I2C_SYSTEST_ST_EN;
+	/* select SDA/SCL IO mode */
+	reg |= 3 << OMAP_I2C_SYSTEST_TMODE_SHIFT;
+	/* set SCL to high-impedance state (reset value is 0) */
+	reg |= OMAP_I2C_SYSTEST_SCL_O;
+	/* set SDA to high-impedance state (reset value is 0) */
+	reg |= OMAP_I2C_SYSTEST_SDA_O;
 	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
 }
 
@@ -1257,7 +1264,11 @@  static void omap_i2c_unprepare_recovery(struct i2c_adapter *adap)
 	u32 reg;
 
 	reg = omap_i2c_read_reg(dev, OMAP_I2C_SYSTEST_REG);
+	/* restore reset values */
 	reg &= ~OMAP_I2C_SYSTEST_ST_EN;
+	reg &= ~OMAP_I2C_SYSTEST_TMODE_MASK;
+	reg &= ~OMAP_I2C_SYSTEST_SCL_O;
+	reg &= ~OMAP_I2C_SYSTEST_SDA_O;
 	omap_i2c_write_reg(dev, OMAP_I2C_SYSTEST_REG, reg);
 }