Skip to contentSkip to conversation

i2c, mpc83xx: add CONFIG_SYS_I2C_INIT_BOARD for fsl_i2c

PATCH New Heiko Schocher 1 participant 2 messages Jul 9, 2009 – Jul 21, 2009 I2C

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 i2c, mpc83xx: add CONFIG_SYS_I2C_INIT_BOARD for fsl_i2c

This patch adds the possibility to call a board specific i2c bus reset routine for the fsl_i2c bus driver, and adds this option for the keymile kmeter1 board.

The deblock sequence for this board is implemented and tested in the following way:

CR = 0x20 (release SDA and SCL pin)
CR = 0xa0 (start read)
dummy read
dummy read
if 2. dummy read == 0x00
3. dummy read

CR = 0x80 (SDA and SCL now 1 SR = 0x86)
CR = 0x00 (Modul reset SR=0x81)
CR = 0x80 (SDA and SCL = 1, SR = 0x81)

---
 board/keymile/common/common.c |   20 ++++++++++++++++++++
 drivers/i2c/fsl_i2c.c         |    6 ++++++
 include/configs/kmeter1.h     |    1 -
 3 files changed, 26 insertions(+), 1 deletions(-)
board/keymile/common/common.c +20 -0
index 2594623..ec27bda 100644
@@ -424,6 +424,7 @@ static int get_scl (void)
 
 #endif
 
+#if !defined(CONFIG_KMETER1)
 static void writeStartSeq (void)
 {
 	set_sda (1);
@@ -474,6 +475,7 @@ static int i2c_make_abort (void)
 	get_sda ();
 	return ret;
 }
+#endif
 
 /**
  * i2c_init_board - reset i2c bus. When the board is powercycled during a
@@ -481,6 +483,23 @@ static int i2c_make_abort (void)
  */
 void i2c_init_board(void)
 {
+#if defined(CONFIG_KMETER1)
+	struct fsl_i2c *dev;
+	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
+	uchar	dummy;
+
+	out_8 (&dev->cr, (I2C_CR_MSTA));
+	out_8 (&dev->cr, (I2C_CR_MEN | I2C_CR_MSTA));
+	dummy = in_8(&dev->dr);
+	dummy = in_8(&dev->dr);
+	if (dummy != 0xff) {
+		dummy = in_8(&dev->dr);
+	}
+	out_8 (&dev->cr, (I2C_CR_MEN));
+	out_8 (&dev->cr, 0x00);
+	out_8 (&dev->cr, (I2C_CR_MEN));
+
+#else
 #if defined(CONFIG_HARD_I2C)
 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR ;
 	volatile i2c8260_t *i2c	= (i2c8260_t *)&immap->im_i2c;
@@ -500,6 +519,7 @@ void i2c_init_board(void)
 	/* Set the PortPins back to use for I2C */
 	setports (0);
 #endif
+#endif
 }
 #endif
 #endif
drivers/i2c/fsl_i2c.c +6 -0
index 6ab7d3d..ce0f301 100644
@@ -178,6 +178,12 @@ i2c_init(int speed, int slaveadd)
 	struct fsl_i2c *dev;
 	unsigned int temp;
 
+#ifdef CONFIG_SYS_I2C_INIT_BOARD
+	/* call board specific i2c bus reset routine before accessing the   */
+	/* environment, which might be in a chip on that bus. For details   */
+	/* about this problem see doc/I2C_Edge_Conditions.                  */
+	i2c_init_board();
+#endif
 	dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
 
 	writeb(0, &dev->cr);			/* stop I2C controller */
include/configs/kmeter1.h +0 -1
index 1735683..811ba88 100644
@@ -33,7 +33,6 @@
 /* include common defines/options for all Keymile boards */
 #include "keymile-common.h"
 
-#undef CONFIG_SYS_I2C_INIT_BOARD
 #define CONFIG_MISC_INIT_R	1
 /*
  * System Clock Setup
Signature · 5 lines
1.6.0.6

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

PATCH 2/3 i2c, mpc83xx: add CONFIG_SYS_I2C_INIT_BOARD for fsl_i2c

Hello Heiko

Quoted 18 lines · Heiko Schocher

This patch adds the possibility to call a board specific i2c bus reset routine for the fsl_i2c bus driver, and adds this option for the keymile kmeter1 board.

The deblock sequence for this board is implemented and tested in the following way:

CR = 0x20 (release SDA and SCL pin)
CR = 0xa0 (start read)
dummy read
dummy read
if 2. dummy read == 0x00
3. dummy read

CR = 0x80 (SDA and SCL now 1 SR = 0x86)
CR = 0x00 (Modul reset SR=0x81)
CR = 0x80 (SDA and SCL = 1, SR = 0x81)

Quoted 6 lines
---
 board/keymile/common/common.c |   20 ++++++++++++++++++++
 drivers/i2c/fsl_i2c.c         |    6 ++++++
 include/configs/kmeter1.h     |    1 -
 3 files changed, 26 insertions(+), 1 deletions(-)

Applied to u-boot-i2c.git

bye
heiko

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