linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Sverdlin <alexander.sverdlin-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
To: Sekhar Nori <nsekhar-l0cyMroinI0@public.gmane.org>,
	Kevin Hilman
	<khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>,
	Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: [PATCH] i2c: davinci: Fix bus rate calculation on Keystone SoC
Date: Thu, 18 Jun 2015 10:53:31 +0200	[thread overview]
Message-ID: <5582870B.7030304@nokia.com> (raw)

According to KeyStone Architecture I2C User Guide,

                         module clock frequency
master clock frequency = ----------------------
                         (ICCL + 6) + (ICCH + 6)

i.e. "d" in i2c_davinci_calc_clk_dividers() should be fixed and
not dependent from module clock prescaler PSC on these SoCs.

Signed-off-by: Alexander Sverdlin <alexander.sverdlin-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
---

RFC: If someone from TI has an idea how to improve the coverage of future Keystone
revisions -- hints/patches are welcome. The current ID check is based on
Davinci/Keystone datasheets and is at least working on real Keystone II.

 drivers/i2c/busses/i2c-davinci.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 4a110af..3d78f6a 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -60,6 +60,8 @@
 #define DAVINCI_I2C_IVR_REG	0x28
 #define DAVINCI_I2C_EMDR_REG	0x2c
 #define DAVINCI_I2C_PSC_REG	0x30
+#define DAVINCI_I2C_ICPID1_REG	0x34
+#define DAVINCI_I2C_ICPID2_REG	0x38
 #define DAVINCI_I2C_FUNC_REG	0x48
 #define DAVINCI_I2C_DIR_REG	0x4c
 #define DAVINCI_I2C_DIN_REG	0x50
@@ -203,6 +205,9 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
 	 * where if PSC == 0, d = 7,
 	 *       if PSC == 1, d = 6
 	 *       if PSC > 1 , d = 5
+	 *
+	 * Note:
+	 * d is always 6 on Keystone I2C controller
 	 */

 	/* get minimum of 7 MHz clock, but max of 12 MHz */
@@ -211,6 +216,11 @@ static void i2c_davinci_calc_clk_dividers(struct davinci_i2c_dev *dev)
 		psc++;	/* better to run under spec than over */
 	d = (psc >= 2) ? 5 : 7 - psc;

+	if (davinci_i2c_read_reg(dev, DAVINCI_I2C_ICPID2_REG) == 0x2206) {
+		dev_dbg(dev->dev, "Keystone SoC detected\n");
+		d = 6;
+	}
+
 	clk = ((input_clock / (psc + 1)) / (pdata->bus_freq * 1000));
 	/* Avoid driving the bus too fast because of rounding errors above */
 	if (input_clock / (psc + 1) / clk > pdata->bus_freq * 1000)

             reply	other threads:[~2015-06-18  8:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-18  8:53 Alexander Sverdlin [this message]
     [not found] ` <5582870B.7030304-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2015-06-18  9:00   ` [PATCH] i2c: davinci: Fix bus rate calculation on Keystone SoC Sekhar Nori
     [not found]     ` <558288B0.1020706-l0cyMroinI0@public.gmane.org>
2015-06-18  9:09       ` Alexander Sverdlin
     [not found]         ` <55828ADB.3080604-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2015-06-18  9:25           ` Sekhar Nori
     [not found]             ` <55828E7F.8060501-l0cyMroinI0@public.gmane.org>
2015-06-18  9:37               ` Alexander Sverdlin
     [not found]                 ` <55829159.8050707-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2015-06-18  9:47                   ` Sekhar Nori
     [not found]                     ` <558293C9.9050904-l0cyMroinI0@public.gmane.org>
2015-06-18 10:04                       ` Alexander Sverdlin
     [not found]                         ` <558297B3.2060406-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>
2015-06-18 11:12                           ` Sekhar Nori
     [not found]                             ` <5582A7AF.5030000-l0cyMroinI0@public.gmane.org>
2015-06-18 11:30                               ` Alexander Sverdlin
2015-06-18 16:22       ` Murali Karicheri
     [not found]         ` <5582F049.8070407-l0cyMroinI0@public.gmane.org>
2015-07-09 19:53           ` Wolfram Sang
2015-07-10 16:02             ` Sekhar Nori
     [not found]               ` <559FEC8C.9030603-l0cyMroinI0@public.gmane.org>
2015-07-10 18:26                 ` Grygorii Strashko
     [not found]                   ` <55A00E56.2020308-l0cyMroinI0@public.gmane.org>
2015-08-12  8:43                     ` Wolfram Sang
2015-08-13 10:29                       ` Alexander Sverdlin

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=5582870B.7030304@nokia.com \
    --to=alexander.sverdlin-xnzwkgviw5gavxtiumwx3w@public.gmane.org \
    --cc=khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=nsekhar-l0cyMroinI0@public.gmane.org \
    --cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.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;
as well as URLs for NNTP newsgroup(s).