linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] ARM: shmobile: r8a7790: add I2C support
@ 2013-07-01 10:00 Nguyen Viet Dung
       [not found] ` <1372672810-20609-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Nguyen Viet Dung @ 2013-07-01 10:00 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ

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

Hello,
CC Morimoto

Please consider the following patches for the r8a7790 Soc.
These patches add I2C support for the r8a7790 Soc.
These patches was developed base on the renesas-next-20130528 branch.
Input clock of I2C is peripheral module clock.
It is named peripheral_clk in clock code. 
These patches have tested on the lager board.

Thanks,
Nguyen viet Dung

Nguyen Viet Dung (4):
  i2c: rcar: modify I2C driver
  ARM: shmobile: r8a7790: add I2C setup
  ARM: shmobile: r8a7790: add I2C clock
  ARM: shmobile: lager: register channels of I2C

 arch/arm/mach-shmobile/board-lager.c          |   11 ++++++++++
 arch/arm/mach-shmobile/clock-r8a7790.c        |   11 ++++++++++
 arch/arm/mach-shmobile/include/mach/r8a7790.h |    3 +++
 arch/arm/mach-shmobile/setup-r8a7790.c        |   28 +++++++++++++++++++++++++
 drivers/i2c/busses/i2c-rcar.c                 |   17 +++++++++++++--
 include/linux/i2c/i2c-rcar.h                  |    4 ++++
 6 files changed, 72 insertions(+), 2 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/4] i2c: rcar: modify I2C driver
       [not found] ` <1372672810-20609-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
@ 2013-07-01 10:00   ` Nguyen Viet Dung
  2013-07-01 10:00   ` [PATCH 2/4] ARM: shmobile: r8a7790: add I2C setup Nguyen Viet Dung
  2013-07-01 10:00   ` [PATCH 3/4] ARM: shmobile: r8a7790: add I2C clock Nguyen Viet Dung
  2 siblings, 0 replies; 4+ messages in thread
From: Nguyen Viet Dung @ 2013-07-01 10:00 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] ARM: shmobile: r8a7790: add I2C setup
       [not found] ` <1372672810-20609-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
  2013-07-01 10:00   ` [PATCH 1/4] i2c: rcar: modify I2C driver Nguyen Viet Dung
@ 2013-07-01 10:00   ` Nguyen Viet Dung
  2013-07-01 10:00   ` [PATCH 3/4] ARM: shmobile: r8a7790: add I2C clock Nguyen Viet Dung
  2 siblings, 0 replies; 4+ messages in thread
From: Nguyen Viet Dung @ 2013-07-01 10:00 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ

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

This patch add setup for I2C bus.

Signed-off-by: Nguyen Viet Dung <nv-dung-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
---
 arch/arm/mach-shmobile/include/mach/r8a7790.h |    3 +++
 arch/arm/mach-shmobile/setup-r8a7790.c        |   28 +++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/arch/arm/mach-shmobile/include/mach/r8a7790.h b/arch/arm/mach-shmobile/include/mach/r8a7790.h
index 2e919e6..85d3567 100644
--- a/arch/arm/mach-shmobile/include/mach/r8a7790.h
+++ b/arch/arm/mach-shmobile/include/mach/r8a7790.h
@@ -1,7 +1,10 @@
 #ifndef __ASM_R8A7790_H__
 #define __ASM_R8A7790_H__
 
+#include <linux/i2c/i2c-rcar.h>
+
 void r8a7790_add_standard_devices(void);
+void r8a7790_add_i2c_device(int idx, struct i2c_rcar_platform_data *pdata);
 void r8a7790_clock_init(void);
 void r8a7790_pinmux_init(void);
 void r8a7790_timer_init(void);
diff --git a/arch/arm/mach-shmobile/setup-r8a7790.c b/arch/arm/mach-shmobile/setup-r8a7790.c
index ed7ee24..0ab912b 100644
--- a/arch/arm/mach-shmobile/setup-r8a7790.c
+++ b/arch/arm/mach-shmobile/setup-r8a7790.c
@@ -24,6 +24,7 @@
 #include <linux/serial_sci.h>
 #include <linux/platform_data/gpio-rcar.h>
 #include <linux/platform_data/irq-renesas-irqc.h>
+#include <linux/i2c/i2c-rcar.h>
 #include <mach/common.h>
 #include <mach/irqs.h>
 #include <mach/r8a7790.h>
@@ -137,6 +138,33 @@ static struct resource irqc0_resources[] = {
 					  &irqc##idx##_data,		\
 					  sizeof(struct renesas_irqc_config))
 
+/* I2C */
+static struct resource rcar_i2c_res[] __initdata = {
+	/* I2C0 */
+	DEFINE_RES_MEM(0xe6508000, 0x10000),
+	DEFINE_RES_IRQ(gic_spi(287)),
+	/* I2C1 */
+	DEFINE_RES_MEM(0xe6518000, 0x10000),
+	DEFINE_RES_IRQ(gic_spi(288)),
+	/* I2C2 */
+	DEFINE_RES_MEM(0xe6530000, 0x10000),
+	DEFINE_RES_IRQ(gic_spi(286)),
+	/* I2C3 */
+	DEFINE_RES_MEM(0xe6540000, 0x10000),
+	DEFINE_RES_IRQ(gic_spi(290)),
+};
+
+void __init r8a7790_add_i2c_device(int idx,
+				   struct i2c_rcar_platform_data *pdata)
+{
+	BUG_ON(idx < 0 || idx > 3);
+
+	platform_device_register_resndata(
+			&platform_bus, "i2c-rcar", idx,
+			rcar_i2c_res + (2*idx), 2,
+			pdata, sizeof(*pdata));
+}
+
 void __init r8a7790_add_standard_devices(void)
 {
 	r8a7790_register_scif(SCIFA0);
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] ARM: shmobile: r8a7790: add I2C clock
       [not found] ` <1372672810-20609-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
  2013-07-01 10:00   ` [PATCH 1/4] i2c: rcar: modify I2C driver Nguyen Viet Dung
  2013-07-01 10:00   ` [PATCH 2/4] ARM: shmobile: r8a7790: add I2C setup Nguyen Viet Dung
@ 2013-07-01 10:00   ` Nguyen Viet Dung
  2 siblings, 0 replies; 4+ messages in thread
From: Nguyen Viet Dung @ 2013-07-01 10:00 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	kuninori.morimoto.gx-zM6kxYcvzFBBDgjK7y7TUQ

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

This patch add clock for I2C bus.

Signed-off-by: Nguyen Viet Dung <nv-dung-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
---
 arch/arm/mach-shmobile/clock-r8a7790.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/mach-shmobile/clock-r8a7790.c b/arch/arm/mach-shmobile/clock-r8a7790.c
index b393592..f4b0f2b 100644
--- a/arch/arm/mach-shmobile/clock-r8a7790.c
+++ b/arch/arm/mach-shmobile/clock-r8a7790.c
@@ -50,6 +50,7 @@
 #define SMSTPCR2 0xe6150138
 #define SMSTPCR3 0xe615013c
 #define SMSTPCR7 0xe615014c
+#define SMSTPCR9 0xE6150994
 
 #define MODEMR		0xE6160060
 #define SDCKCR		0xE6150074
@@ -180,6 +181,7 @@ static struct clk div6_clks[DIV6_NR] = {
 
 /* MSTP */
 enum {
+	MSTP931, MSTP930, MSTP929, MSTP928,
 	MSTP721, MSTP720,
 	MSTP304,
 	MSTP216, MSTP207, MSTP206, MSTP204, MSTP203, MSTP202,
@@ -187,6 +189,10 @@ enum {
 };
 
 static struct clk mstp_clks[MSTP_NR] = {
+	[MSTP931] = SH_CLK_MSTP32(&hp_clk, SMSTPCR9, 31, 0), /* I2C0 */
+	[MSTP930] = SH_CLK_MSTP32(&hp_clk, SMSTPCR9, 30, 0), /* I2C1 */
+	[MSTP929] = SH_CLK_MSTP32(&hp_clk, SMSTPCR9, 29, 0), /* I2C2 */
+	[MSTP928] = SH_CLK_MSTP32(&hp_clk, SMSTPCR9, 28, 0), /* I2C3 */
 	[MSTP721] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 21, 0), /* SCIF0 */
 	[MSTP720] = SH_CLK_MSTP32(&p_clk, SMSTPCR7, 20, 0), /* SCIF1 */
 	[MSTP304] = SH_CLK_MSTP32(&cp_clk, SMSTPCR3, 4, 0), /* TPU0 */
@@ -226,6 +232,7 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_CON_ID("mp",		&mp_clk),
 	CLKDEV_CON_ID("qspi",		&qspi_clk),
 	CLKDEV_CON_ID("cp",		&cp_clk),
+	CLKDEV_CON_ID("peripheral_clk",	&hp_clk),
 
 	/* DIV4 */
 	CLKDEV_CON_ID("sdh",		&div4_clks[DIV4_SDH]),
@@ -249,6 +256,10 @@ static struct clk_lookup lookups[] = {
 	CLKDEV_DEV_ID("sh-sci.5", &mstp_clks[MSTP202]),
 	CLKDEV_DEV_ID("sh-sci.6", &mstp_clks[MSTP721]),
 	CLKDEV_DEV_ID("sh-sci.7", &mstp_clks[MSTP720]),
+	CLKDEV_DEV_ID("i2c-rcar.0", &mstp_clks[MSTP931]),
+	CLKDEV_DEV_ID("i2c-rcar.1", &mstp_clks[MSTP930]),
+	CLKDEV_DEV_ID("i2c-rcar.2", &mstp_clks[MSTP929]),
+	CLKDEV_DEV_ID("i2c-rcar.3", &mstp_clks[MSTP928]),
 };
 
 #define R8A7790_CLOCK_ROOT(e, m, p0, p1, p30, p31)		\
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-01 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-01 10:00 [PATCH 0/4] ARM: shmobile: r8a7790: add I2C support Nguyen Viet Dung
     [not found] ` <1372672810-20609-1-git-send-email-user-HEF513clHfp3+QwDJ9on6Q@public.gmane.org>
2013-07-01 10:00   ` [PATCH 1/4] i2c: rcar: modify I2C driver Nguyen Viet Dung
2013-07-01 10:00   ` [PATCH 2/4] ARM: shmobile: r8a7790: add I2C setup Nguyen Viet Dung
2013-07-01 10:00   ` [PATCH 3/4] ARM: shmobile: r8a7790: add I2C clock Nguyen Viet Dung

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).