Skip to contentSkip to conversation

I2C: Add i2c_get/set_bus_speed() to mxc_i2c.c

PATCH Superseded Marek Vasut 3 participants 5 messages Sep 27, 2011 – Sep 30, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 I2C: Add i2c_get/set_bus_speed() to mxc_i2c.c

Cc Stefano Babic <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 drivers/i2c/mxc_i2c.c |   32 ++++++++++++++++++++++++--------
 1 files changed, 24 insertions(+), 8 deletions(-)
drivers/i2c/mxc_i2c.c +24 -8
index a805bf6..e12a08a 100644
@@ -95,7 +95,7 @@ static u16 i2c_clk_div[50][2] = {
 	{ 3072,	0x1E }, { 3840,	0x1F }
 };
 
-static u8 clk_idx;
+static u8 clk_div;
 
 /*
  * Calculate and set proper clock divider
@@ -105,7 +105,6 @@ static void i2c_imx_set_clk(unsigned int rate)
 	struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE;
 	unsigned int i2c_clk_rate;
 	unsigned int div;
-	int i;
 
 #if defined(CONFIG_MX31)
 	struct clock_control_regs *sc_regs =
@@ -120,16 +119,15 @@ static void i2c_imx_set_clk(unsigned int rate)
 	i2c_clk_rate = mxc_get_clock(MXC_IPG_PERCLK);
 	div = (i2c_clk_rate + rate - 1) / rate;
 	if (div < i2c_clk_div[0][0])
-		i = 0;
+		clk_div = 0;
 	else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0])
-		i = ARRAY_SIZE(i2c_clk_div) - 1;
+		clk_div = ARRAY_SIZE(i2c_clk_div) - 1;
 	else
-		for (i = 0; i2c_clk_div[i][0] < div; i++)
+		for (clk_div = 0; i2c_clk_div[clk_div][0] < div; clk_div++)
 			;
 
 	/* Store divider value */
-	clk_idx = i2c_clk_div[i][1];
-	writeb(clk_idx, &i2c_regs->ifdr);
+	writeb(i2c_clk_div[clk_div][1], &i2c_regs->ifdr);
 }
 
 /*
@@ -153,6 +151,24 @@ void i2c_init(int speed, int unused)
 }
 
 /*
+ * Set I2C Speed
+ */
+int i2c_set_bus_speed(unsigned int speed)
+{
+	i2c_init(speed, 0);
+	return 0;
+}
+
+/*
+ * Get I2C Speed
+ */
+unsigned int i2c_get_bus_speed(void)
+{
+	return mxc_get_clock(MXC_IPG_PERCLK) / i2c_clk_div[clk_div][0];
+
+}
+
+/*
  * Wait for bus to be busy (or free if for_busy = 0)
  *
  * for_busy = 1: Wait for IBB to be asserted
@@ -218,7 +234,7 @@ int i2c_imx_start(void)
 	unsigned int temp = 0;
 	int result;
 
-	writeb(clk_idx, &i2c_regs->ifdr);
+	writeb(i2c_clk_div[clk_div][1], &i2c_regs->ifdr);
 
 	/* Enable I2C controller */
 	writeb(0, &i2c_regs->i2sr);
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH v2 1/1 I2C: Add i2c_get/set_speed() to mxc_i2c.c

Cc Stefano Babic <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 drivers/i2c/mxc_i2c.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

V2: Drop redundant newline

drivers/i2c/mxc_i2c.c +23 -8
index a805bf6..2869d7c 100644
@@ -95,7 +95,7 @@ static u16 i2c_clk_div[50][2] = {
 	{ 3072,	0x1E }, { 3840,	0x1F }
 };
 
-static u8 clk_idx;
+static u8 clk_div;
 
 /*
  * Calculate and set proper clock divider
@@ -105,7 +105,6 @@ static void i2c_imx_set_clk(unsigned int rate)
 	struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE;
 	unsigned int i2c_clk_rate;
 	unsigned int div;
-	int i;
 
 #if defined(CONFIG_MX31)
 	struct clock_control_regs *sc_regs =
@@ -120,16 +119,15 @@ static void i2c_imx_set_clk(unsigned int rate)
 	i2c_clk_rate = mxc_get_clock(MXC_IPG_PERCLK);
 	div = (i2c_clk_rate + rate - 1) / rate;
 	if (div < i2c_clk_div[0][0])
-		i = 0;
+		clk_div = 0;
 	else if (div > i2c_clk_div[ARRAY_SIZE(i2c_clk_div) - 1][0])
-		i = ARRAY_SIZE(i2c_clk_div) - 1;
+		clk_div = ARRAY_SIZE(i2c_clk_div) - 1;
 	else
-		for (i = 0; i2c_clk_div[i][0] < div; i++)
+		for (clk_div = 0; i2c_clk_div[clk_div][0] < div; clk_div++)
 			;
 
 	/* Store divider value */
-	clk_idx = i2c_clk_div[i][1];
-	writeb(clk_idx, &i2c_regs->ifdr);
+	writeb(i2c_clk_div[clk_div][1], &i2c_regs->ifdr);
 }
 
 /*
@@ -153,6 +151,23 @@ void i2c_init(int speed, int unused)
 }
 
 /*
+ * Set I2C Speed
+ */
+int i2c_set_bus_speed(unsigned int speed)
+{
+	i2c_init(speed, 0);
+	return 0;
+}
+
+/*
+ * Get I2C Speed
+ */
+unsigned int i2c_get_bus_speed(void)
+{
+	return mxc_get_clock(MXC_IPG_PERCLK) / i2c_clk_div[clk_div][0];
+}
+
+/*
  * Wait for bus to be busy (or free if for_busy = 0)
  *
  * for_busy = 1: Wait for IBB to be asserted
@@ -218,7 +233,7 @@ int i2c_imx_start(void)
 	unsigned int temp = 0;
 	int result;
 
-	writeb(clk_idx, &i2c_regs->ifdr);
+	writeb(i2c_clk_div[clk_div][1], &i2c_regs->ifdr);
 
 	/* Enable I2C controller */
 	writeb(0, &i2c_regs->i2sr);
Signature · 1 line
1.7.5.4
#2 lore raw

PATCH v2 1/1 I2C: Add i2c_get/set_speed() to mxc_i2c.c

Hello Stefano,

Quoted 8 lines · Marek Vasut
Cc Stefano Babic <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 drivers/i2c/mxc_i2c.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)

V2: Drop redundant newline

Could you Ack this patch, or do you want to apply it, so you can add my:

bye,
Heiko

Signature · 2 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
#3 lore raw

PATCH v2 1/1 I2C: Add i2c_get/set_speed() to mxc_i2c.c

Quoted 10 lines · Heiko Schocher

Hello Stefano,

Quoted 7 lines · Marek Vasut
Cc Stefano Babic <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 drivers/i2c/mxc_i2c.c |   31 +++++++++++++++++++++++--------
 1 files changed, 23 insertions(+), 8 deletions(-)
Quoted 7 lines
Quoted 1 line

V2: Drop redundant newline

Could you Ack this patch, or do you want to apply it, so you can add my:

Thanks, Heiko - I will apply directly to u-boot-imx.

bye,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================
#4 lore raw

PATCH 1/1 I2C: Add i2c_get/set_bus_speed() to mxc_i2c.c

In reply to Marek Vasut
Quoted 4 lines · Marek Vasut
Cc Stefano Babic <[email protected]>
Cc Heiko Schocher <[email protected]>

---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
=====================================================================