Skip to contentSkip to conversation

mgcoge, mgsuvd: add I2C support.

PATCH New Heiko Schocher 1 participant 1 message Oct 15, 2008

lore
Share & tools
lore
#0 lore raw

PATCH v2 6/16 mgcoge, mgsuvd: add I2C support.

---
 board/keymile/mgcoge/mgcoge.c |   14 +++++++++++-
 board/keymile/mgsuvd/mgsuvd.c |   11 ++++++++++
 include/configs/mgcoge.h      |   25 +++++++++++++++++++++++
 include/configs/mgsuvd.h      |   43 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 91 insertions(+), 2 deletions(-)
board/keymile/mgcoge/mgcoge.c +12 -2
index a6bf9bc..d3e46f5 100644
@@ -24,11 +24,16 @@
 #include <common.h>
 #include <mpc8260.h>
 #include <ioports.h>
+#include <malloc.h>
 
 #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
 #include <libfdt.h>
 #endif
 
+#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+#include <i2c.h>
+#endif
+
 /*
  * I/O Port configuration table
  *
@@ -163,8 +168,13 @@ const iop_conf_t iop_conf_tab[4][32] = {
 	/* PD18 */ { 0,          0,   0,   0,   0,   0 }, /* PD18            */
 	/* PD17 */ { 0,          0,   0,   0,   0,   0 }, /* PD17            */
 	/* PD16 */ { 0,          0,   0,   0,   0,   0 }, /* PD16            */
-	/* PD15 */ { 0,          0,   0,   0,   0,   0 }, /* PD15            */
-	/* PD14 */ { 0,          0,   0,   0,   0,   0 }, /* PD14            */
+#if defined(CONFIG_HARD_I2C)
+	/* PD15 */ { 1,          1,   1,   0,   1,   0 }, /* I2C SDA         */
+	/* PD14 */ { 1,          1,   1,   0,   1,   0 }, /* I2C SCL         */
+#else
+	/* PD15 */ { 1,          0,   0,   0,   1,   1 }, /* PD15            */
+	/* PD14 */ { 1,          0,   0,   1,   1,   1 }, /* PD14            */
+#endif
 	/* PD13 */ { 0,          0,   0,   0,   0,   0 }, /* PD13            */
 	/* PD12 */ { 0,          0,   0,   0,   0,   0 }, /* PD12            */
 	/* PD11 */ { 0,          0,   0,   0,   0,   0 }, /* PD11            */
board/keymile/mgsuvd/mgsuvd.c +11 -0
index c51ea7e..62df832 100644
@@ -225,3 +225,14 @@ void ft_board_setup(void *blob, bd_t *bd)
 	ft_blob_update(blob, bd);
 }
 #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */
+
+int i2c_soft_read_pin (void)
+{
+	int val;
+
+	*(unsigned short *)(I2C_BASE_DIR) &=  ~SDA_CONF;	
+	udelay(1);
+	val = *(unsigned char *)(I2C_BASE_PORT);
+	
+	return ((val & SDA_BIT) == SDA_BIT);
+}
include/configs/mgcoge.h +25 -0
index 23af3ec..159eeae 100644
@@ -82,6 +82,7 @@
 #include <config_cmd_default.h>
 
 #define CONFIG_CMD_ECHO
+#define CONFIG_CMD_I2C
 #define CONFIG_CMD_IMMAP
 #define CONFIG_CMD_MII
 #define CONFIG_CMD_PING
@@ -176,6 +177,30 @@
 #define CONFIG_ENV_ADDR		(CFG_MONITOR_BASE + CFG_MONITOR_LEN)
 #endif /* CONFIG_ENV_IS_IN_FLASH */
 
+/* enable I2C and select the hardware/software driver */
+#undef	CONFIG_HARD_I2C			/* I2C with hardware support	*/
+#define	CONFIG_SOFT_I2C		1	/* I2C bit-banged		*/
+#define CFG_I2C_SPEED		50000	/* I2C speed and slave address	*/
+#define CFG_I2C_SLAVE		0x7F
+
+/*
+ * Software (bit-bang) I2C driver configuration
+ */
+
+#define I2C_PORT	3		/* Port A=0, B=1, C=2, D=3 */
+#define I2C_ACTIVE	(iop->pdir |=  0x00010000)
+#define I2C_TRISTATE	(iop->pdir &= ~0x00010000)
+#define I2C_READ	((iop->pdat & 0x00010000) != 0)
+#define I2C_SDA(bit)	if(bit) iop->pdat |=  0x00010000; \
+			else    iop->pdat &= ~0x00010000
+#define I2C_SCL(bit)	if(bit) iop->pdat |=  0x00020000; \
+			else    iop->pdat &= ~0x00020000
+#define I2C_DELAY	udelay(5)	/* 1/4 I2C clock duration */
+
+#define CONFIG_I2C_MULTI_BUS	1
+#define CONFIG_I2C_CMD_TREE	1
+#define CFG_MAX_I2C_BUS		2
+
 #define CFG_IMMR		0xF0000000
 
 #define CFG_INIT_RAM_ADDR	CFG_IMMR
include/configs/mgsuvd.h +43 -0

53 lines not on this page · raw message

Signature · 5 lines
1.5.6.1

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