[U-Boot] [PATCH 2/5] i2c: omap24xx: Fix waitdelay value for I2C HS

Christophe Ricard christophe.ricard at gmail.com
Sun Jan 17 12:09:49 CET 2016


After several testings and experiment, it appears that waitdelay calculation
formula was giving different behavior on the i2c status registers.

Experiment shows waitdelay needs to be extended at least 4 times to get
proper results.

Signed-off-by: Christophe Ricard <christophe-h.ricard at st.com>
---

 drivers/i2c/omap24xx_i2c.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/i2c/omap24xx_i2c.c b/drivers/i2c/omap24xx_i2c.c
index f3a4d96..d6e5fe9 100644
--- a/drivers/i2c/omap24xx_i2c.c
+++ b/drivers/i2c/omap24xx_i2c.c
@@ -168,6 +168,13 @@ static int omap24_i2c_setspeed(struct udevice *adap, unsigned int speed)
 		scll = (unsigned int)hsscll << 8 | (unsigned int)fsscll;
 		sclh = (unsigned int)hssclh << 8 | (unsigned int)fssclh;
 
+#ifdef CONFIG_SYS_I2C
+		adap->speed	= speed;
+		adap->waitdelay = (10000000 / speed) * 8; /* wait for 20 clkperiods */
+#else
+		i2c_bus->clock_frequency = speed;
+		i2c_bus->waitdelay = (10000000 / speed) * 8; /* wait for 20 clkperiods */
+#endif
 	} else {
 		/* Standard and fast speed */
 		psc = omap24_i2c_findpsc(&scll, &sclh, speed);
@@ -175,15 +182,15 @@ static int omap24_i2c_setspeed(struct udevice *adap, unsigned int speed)
 			puts("Error : I2C initializing clock\n");
 			return -1;
 		}
-	}
 
 #ifdef CONFIG_SYS_I2C
-	adap->speed	= speed;
-	adap->waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
+		adap->speed	= speed;
+		adap->waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
 #else
-	i2c_bus->clock_frequency = speed;
-	i2c_bus->waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
+		i2c_bus->clock_frequency = speed;
+		i2c_bus->waitdelay = (10000000 / speed) * 2; /* wait for 20 clkperiods */
 #endif
+	}
 
 	writew(0, &i2c_base->con);
 	writew(psc, &i2c_base->psc);
@@ -467,7 +474,6 @@ static int omap24_i2c_read(struct udevice *adap, uchar chip, uint addr,
 	i2c_bus = dev_get_priv(adap);
 	i2c_base = i2c_bus->i2c_base;
 #endif
-
 	if (alen < 0) {
 		puts("I2C read: addr len < 0\n");
 		return 1;
-- 
2.5.0



More information about the U-Boot mailing list