public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: ext-eero.nurkkala@nokia.com
To: linux-omap@vger.kernel.org
Cc: Eero Nurkkala <ext-eero.nurkkala@nokia.com>
Subject: [PATCH] i2c: i2c-omap: Fix standard and fast mode prescalers
Date: Fri, 14 Nov 2008 10:41:57 +0200	[thread overview]
Message-ID: <12266521173159-git-send-email-ext-eero.nurkkala@nokia.com> (raw)

From: Eero Nurkkala <ext-eero.nurkkala@nokia.com>

The prescalers for 100 kHz and 400 kHz mode
are wrong. The internal clock is the fclock
divided by the prescaler. The PSC is an 8 bit
field in omap3430. 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 <ext-eero.nurkkala@nokia.com>
---
 drivers/i2c/busses/i2c-omap.c |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index e708ebd..a42003a 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -288,7 +288,17 @@ 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 (cpu_is_omap34xx()) {
+			if (dev->speed > 400)
+				internal_clk = 19200;
+			else if (dev->speed > 100)
+				internal_clk = 9600;
+			else
+				internal_clk = 4000;
+		} else {
+			internal_clk = 19200;
+		}
+
 		fclk_rate = clk_get_rate(dev->fclk) / 1000;
 
 		/* Compute prescaler divisor */
@@ -306,8 +316,13 @@ 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;
+			if (cpu_is_omap34xx()) {
+				fsscll = internal_clk / (dev->speed * 2) - 7;
+				fssclh = internal_clk / (dev->speed * 2) - 5;
+			} else {
+				fsscll = internal_clk / (dev->speed * 2) - 6;
+				fssclh = internal_clk / (dev->speed * 2) - 6;
+			}
 		}
 		scll = (hsscll << OMAP_I2C_SCLL_HSSCLL) | fsscll;
 		sclh = (hssclh << OMAP_I2C_SCLH_HSSCLH) | fssclh;
-- 
1.6.0


             reply	other threads:[~2008-11-14  8:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-14  8:41 ext-eero.nurkkala [this message]
2008-11-14 19:45 ` [PATCH] i2c: i2c-omap: Fix standard and fast mode prescalers David Brownell
2008-11-14 20:02   ` Felipe Balbi
2008-11-14 20:08     ` David Brownell
2008-11-14 21:46       ` Felipe Balbi
2008-11-17  2:46         ` shekhar, chandra
2008-11-18  5:36           ` David Brownell
2008-11-14 20:38   ` Steve Sakoman
2008-11-19 12:07   ` Eero Nurkkala
2008-11-21 22:08 ` Tony Lindgren
  -- strict thread matches above, loose matches on Subject: below --
2009-01-13  6:06 Eero Nurkkala
2009-01-23  2:04 ` Tony Lindgren
2008-11-26 13:44 ext-eero.nurkkala
2008-11-27  8:38 ` Eero Nurkkala
2009-01-08 13:39   ` Tony Lindgren
2009-01-09 20:27 ` Kainan Cha
2009-01-12  6:29   ` Eero Nurkkala
2008-11-25  6:56 ext-eero.nurkkala
2008-11-11  6:52 ext-eero.nurkkala
2008-11-11 13:21 ` shekhar, chandra
2008-11-10 10:46 ext-eero.nurkkala

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=12266521173159-git-send-email-ext-eero.nurkkala@nokia.com \
    --to=ext-eero.nurkkala@nokia.com \
    --cc=linux-omap@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox