i2c: i2c-omap: Fix standard and fast mode prescalers
Subsystems (4)
PATCH 1/1 i2c: i2c-omap: Fix standard and fast mode prescalers
From: Eero Nurkkala <[email protected]>
The prescalers for 100 kHz and 400 kHz mode are wrong for omap 3430 and omap 2430. The internal clock is the fclock divided by the prescaler. The PSC is an 8 bit field in omap3430 and omap2430. Moreover, the scll and sclh values should be adjusted properly. Having the correct prescaler is important in the process of getting a finite i2c clock. In addition, the prescaler is used in the process of activating the correct noise filter and thus, lets more error resilient i2c communications.
--- drivers/i2c/busses/i2c-omap.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
drivers/i2c/busses/i2c-omap.c +9 -3
@@ -337,7 +337,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)if (cpu_is_omap2430 () ||cpu_is_omap34xx ()) {/* HSI2C controller internal clk rate should be 19.2 Mhz */ - internal_clk =19200 ; +if (dev->speed >400 ) + internal_clk =19200 ; +else if (dev->speed >100 ) + internal_clk =9600 ; +else + internal_clk =4000 ; + fclk_rate =clk_get_rate (dev->fclk) /1000 ;/* Compute prescaler divisor */
@@ -355,8 +361,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) hssclh = fclk_rate / (dev->speed *2 ) -6 ; }else {/* To handle F/S modes */ - fsscll = internal_clk / (dev->speed *2 ) -6 ; - fssclh = internal_clk / (dev->speed *2 ) -6 ; + fsscll = internal_clk / (dev->speed *2 ) -3 ; + fssclh = internal_clk / (dev->speed *2 ) -9 ; } scll = (hsscll <<OMAP_I2C_SCLL_HSSCLL ) | fsscll; sclh = (hssclh <<OMAP_I2C_SCLH_HSSCLH ) | fssclh;
Signature · 1 line
1.6.0
We scope-verified these scl and sch values for 100 and 400 kHz busses. Now they're in the specs.
Quoted 49 lines · On Wed, 2008-11-26 at 15:44 +0200, [email protected] wrote:
From: Eero Nurkkala <[email protected]>
The prescalers for 100 kHz and 400 kHz mode are wrong for omap 3430 and omap 2430. The internal clock is the fclock divided by the prescaler. The PSC is an 8 bit field in omap3430 and omap2430. Moreover, the scll and sclh values should be adjusted properly. Having the correct prescaler is important in the process of getting a finite i2c clock. In addition, the prescaler is used in the process of activating the correct noise filter and thus, lets more error resilient i2c communications.
Signed-off-by Eero Nurkkala <[email protected]>--- drivers/i2c/busses/i2c-omap.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-omap.c +9
-3@@ -337,7 +337,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)if (cpu_is_omap2430 () ||cpu_is_omap34xx ()) {/* HSI2C controller internal clk rate should be 19.2 Mhz */ - internal_clk =19200 ; +if (dev->speed >400 ) + internal_clk =19200 ; +else if (dev->speed >100 ) + internal_clk =9600 ; +else + internal_clk =4000 ; + fclk_rate =clk_get_rate (dev->fclk) /1000 ;/* Compute prescaler divisor */ @@ -355,8 +361,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) hssclh = fclk_rate / (dev->speed *2 ) -6 ; }else {/* To handle F/S modes */ - fsscll = internal_clk / (dev->speed *2 ) -6 ; - fssclh = internal_clk / (dev->speed *2 ) -6 ; + fsscll = internal_clk / (dev->speed *2 ) -3 ; + fssclh = internal_clk / (dev->speed *2 ) -9 ; } scll = (hsscll <<OMAP_I2C_SCLL_HSSCLL ) | fsscll; sclh = (hssclh <<OMAP_I2C_SCLH_HSSCLH ) | fssclh;
Tony Lindgren
maintainerQuoted 2 lines · Eero Nurkkala
We scope-verified these scl and sch values for 100 and 400 kHz busses. Now they're in the specs.
Pushing to l-o tree and adding to omap-fixes queue for mainline.
Tony
Quoted 55 lines · On Wed, 2008-11-26 at 15:44 +0200, [email protected] wrote:
Quoted 39 lines
From: Eero Nurkkala <[email protected]>
The prescalers for 100 kHz and 400 kHz mode are wrong for omap 3430 and omap 2430. The internal clock is the fclock divided by the prescaler. The PSC is an 8 bit field in omap3430 and omap2430. Moreover, the scll and sclh values should be adjusted properly. Having the correct prescaler is important in the process of getting a finite i2c clock. In addition, the prescaler is used in the process of activating the correct noise filter and thus, lets more error resilient i2c communications.
Signed-off-by Eero Nurkkala <[email protected]>--- drivers/i2c/busses/i2c-omap.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-omap.c +7
-1@@ -337,7 +337,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)if (cpu_is_omap2430 () ||cpu_is_omap34xx ()) {/* HSI2C controller internal clk rate should be 19.2 Mhz */ - internal_clk =19200 ; +if (dev->speed >400 ) + internal_clk =19200 ; +else if (dev->speed >100 ) + internal_clk =9600 ; +else + internal_clk =4000 ; + fclk_rate =clk_get_rate (dev->fclk) /1000 ;/* Compute prescaler divisor */ drivers/i2c/busses/i2c-omap.c static int omap_i2c_init(struct omap_i2c_dev *dev) · line 368
Quoted 10 lines
drivers/i2c/busses/i2c-omap.c +2
-2@@ -355,8 +361,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) hssclh = fclk_rate / (dev->speed *2 ) -6 ; }else {/* To handle F/S modes */ - fsscll = internal_clk / (dev->speed *2 ) -6 ; - fssclh = internal_clk / (dev->speed *2 ) -6 ; + fsscll = internal_clk / (dev->speed *2 ) -3 ; + fssclh = internal_clk / (dev->speed *2 ) -9 ; } scll = (hsscll <<OMAP_I2C_SCLL_HSSCLL ) | fsscll; sclh = (hssclh <<OMAP_I2C_SCLH_HSSCLH ) | fssclh;--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Eero,
Quoted 14 lines · On Wed, Nov 26, 2008 at 7:44 AM, <[email protected]> wrote:
From: Eero Nurkkala <[email protected]>
The prescalers for 100 kHz and 400 kHz mode are wrong for omap 3430 and omap 2430. The internal clock is the fclock divided by the prescaler. The PSC is an 8 bit field in omap3430 and omap2430. Moreover, the scll and sclh values should be adjusted properly. Having the correct prescaler is important in the process of getting a finite i2c clock. In addition, the prescaler is used in the process of activating the correct noise filter and thus, lets more error resilient i2c communications.
This patch looks fine for omap3430. But when referring to omap2430 manual, the internal_clk does not seem to depend on the i2c modes. Can you verify? My brief testing shows that i2c clock is broken for omap2430 with this patch.
Also, in my manual for both omap2430 and omap3430, scll and sclh values should be set like so:
fsscll = internal_clk / (dev->speed * 2) - 7;
fssclh = internal_clk / (dev->speed * 2) - 5;Could you explain where you got your values from?
Regards,
Kainan Cha
Quoted 43 lines
Signed-off-by Eero Nurkkala <[email protected]>--- drivers/i2c/busses/i2c-omap.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)drivers/i2c/busses/i2c-omap.c +9
-4@@ -337,7 +337,13 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)if (cpu_is_omap2430 () ||cpu_is_omap34xx ()) {/* HSI2C controller internal clk rate should be 19.2 Mhz */ - internal_clk =19200 ; +if (dev->speed >400 ) + internal_clk =19200 ; +else if (dev->speed >100 ) + internal_clk =9600 ; +else + internal_clk =4000 ; + fclk_rate =clk_get_rate (dev->fclk) /1000 ;/* Compute prescaler divisor */ @@ -355,8 +361,8 @@ static int omap_i2c_init(struct omap_i2c_dev *dev) hssclh = fclk_rate / (dev->speed *2 ) -6 ; }else {/* To handle F/S modes */ - fsscll = internal_clk / (dev->speed *2 ) -6 ; - fssclh = internal_clk / (dev->speed *2 ) -6 ; + fsscll = internal_clk / (dev->speed *2 ) -3 ; + fssclh = internal_clk / (dev->speed *2 ) -9 ; } scll = (hsscll <<OMAP_I2C_SCLL_HSSCLL ) | fsscll; sclh = (hssclh <<OMAP_I2C_SCLH_HSSCLH ) | fssclh; --1.6.0
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 9 lines · ext Kainan Cha
This patch looks fine for omap3430. But when referring to omap2430 manual, the
internal_clkdoes not seem to depend on the i2c modes. Can you verify? My brief testing shows that i2c clock is broken for omap2430 with this patch.Also, in my manual for both omap2430 and omap3430, scll and sclh values should be set like so:
Quoted 7 lines
fsscll = internal_clk / (dev->speed * 2) - 7; fssclh = internal_clk / (dev->speed * 2) - 5;Could you explain where you got your values from?
Regards,
Kainan Cha
Hello!
I'm very sorry for breaking the 2430 i2c bus. I have had definitely no access to 2430 TRM or boards, so all help is much appreciated. That needs to be fixed.
Our values for fsscll and fssclh (-3, -9) come from the i2c standard. We scoped out the activity of 100khz and 400khz signals, and by having the (-6, -6) or TRM's (-7, -5) we found out that the i2c clock signal does not get into the i2c standard. If I recall correctly, the clock down time, referred to as "LOW period of the SCL clock, tLOW" in the i2c standard, was well below the minimum. Taken from the standard, the 400khz mode tLOW is min 1.3uS, and tHIGH is min 0.6uS. You see that the tLOW needs to be a lot greater than tHIGH, so that would suggest we're in the right track with the (-3, -9) values ;)
Indeed, with values (-3, -9) we got everything within the i2c standard for 100 and 400 khz busses, and still having the correct frequency.
If TRM was to be obeyed, and the minimum values were really the (-7, -5), then it becomes impossible to get the clock frequency to 400 or
100. (I think it went closer to 300 khz, as the tLOW value needed to be adjusted quite a bit).
However, I would suggest you and everybody who uses the i2c bus, to scope the bus, and measure everything (rise/fall times, setup times, tLOW, tHIGH and everything mentioned in the i2c standard). Just to check that you actually have a reliable i2c driver.