linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nguyen Viet Dung <user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org
Subject: [PATCH v2 1/1] i2c: rcar: modify I2C driver
Date: Wed, 10 Jul 2013 18:15:18 +0900	[thread overview]
Message-ID: <1373447718-19382-2-git-send-email-user@jinso.co.jp> (raw)
In-Reply-To: <1373447718-19382-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>

From: Nguyen Viet Dung <nv-dung-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>

This patch modify calculate for clock in I2C driver.

Signed-off-by: Nguyen Viet Dung <nv-dung-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
---
 drivers/i2c/busses/i2c-rcar.c |   17 +++++++++++++++--
 include/linux/i2c/i2c-rcar.h  |    4 ++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c
index 4ba4a95..85987c1 100644
--- a/drivers/i2c/busses/i2c-rcar.c
+++ b/drivers/i2c/busses/i2c-rcar.c
@@ -221,15 +221,28 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
 				    struct device *dev)
 {
 	struct clk *clkp = clk_get(NULL, "peripheral_clk");
+	struct i2c_rcar_platform_data *pdata = dev->platform_data;
 	u32 scgd, cdf;
 	u32 round, ick;
 	u32 scl;
+	u32 cdf_width;
+	u32 flags = pdata ? pdata->flags : 0;
 
 	if (!clkp) {
 		dev_err(dev, "there is no peripheral_clk\n");
 		return -EIO;
 	}
 
+	switch (flags & I2C_RCAR_FLAGS_ICCCR_MASK) {
+	default:
+	case I2C_RCAR_FLAGS_ICCCR_IS_2BIT:
+		cdf_width = 2;
+		break;
+	case I2C_RCAR_FLAGS_ICCCR_IS_3BIT:
+		cdf_width = 3;
+		break;
+	}
+
 	/*
 	 * calculate SCL clock
 	 * see
@@ -245,7 +258,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv,
 	 * clkp : peripheral_clk
 	 * F[]  : integer up-valuation
 	 */
-	for (cdf = 0; cdf < 4; cdf++) {
+	for (cdf = 0; cdf < (1 << cdf_width); cdf++) {
 		ick = clk_get_rate(clkp) / (1 + cdf);
 		if (ick < 20000000)
 			goto ick_find;
@@ -287,7 +300,7 @@ scgd_find:
 	/*
 	 * keep icccr value
 	 */
-	priv->icccr = (scgd << 2 | cdf);
+	priv->icccr = (scgd << (cdf_width) | cdf);
 
 	return 0;
 }
diff --git a/include/linux/i2c/i2c-rcar.h b/include/linux/i2c/i2c-rcar.h
index 496f5c2..572a6e5 100644
--- a/include/linux/i2c/i2c-rcar.h
+++ b/include/linux/i2c/i2c-rcar.h
@@ -5,6 +5,10 @@
 
 struct i2c_rcar_platform_data {
 	u32 bus_speed;
+	u32 flags;
+#define I2C_RCAR_FLAGS_ICCCR_MASK	(0xF << 0)
+#define I2C_RCAR_FLAGS_ICCCR_IS_2BIT	(0 << 0) /* default */
+#define I2C_RCAR_FLAGS_ICCCR_IS_3BIT	(1 << 0)
 };
 
 #endif /* __I2C_R_CAR_H__ */
-- 
1.7.9.5

  parent reply	other threads:[~2013-07-10  9:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-10  9:15 [PATCH v2 0/1] ARM: shmobile: r8a7790: add I2C support Nguyen Viet Dung
     [not found] ` <1373447718-19382-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
2013-07-10  9:15   ` Nguyen Viet Dung [this message]
     [not found]     ` <1373447718-19382-2-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
2013-07-11  9:03       ` [PATCH v2 1/1] i2c: rcar: modify I2C driver Kuninori Morimoto
     [not found]         ` <8761whfoy1.wl%kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org>
2013-07-22  5:58           ` Nguyen Viet Dung
     [not found]             ` <51ECCA19.7030904-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
2013-07-22 11:41               ` Nguyen Viet Dung
     [not found]                 ` <51ED1A85.6090009-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
2013-07-23  6:28                   ` Nguyen Viet Dung

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=1373447718-19382-2-git-send-email-user@jinso.co.jp \
    --to=user-hef513clhfp3+qwdj9on6q@public.gmane.org \
    --cc=kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@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).