[U-Boot] PATCH 1/8 Multi-adapter multi-bus I2C

ksi at koi8.net ksi at koi8.net
Sat Feb 7 02:03:28 CET 2009


Signed-off-by: Sergey Kubushyn <ksi at koi8.net>
---
 board/keymile/common/common.c   |   40 ++-
 board/keymile/mgcoge/mgcoge.c   |    4 -
 board/keymile/mgsuvd/mgsuvd.c   |   11 -
 board/lwmon/lwmon.c             |    2 +-
 board/lwmon/pcmcia.c            |    4 +-
 common/cmd_date.c               |    9 +
 common/cmd_dtt.c                |    9 +
 common/cmd_i2c.c                |  340 ++++--------------
 common/devices.c                |   12 +-
 cpu/mpc8xx/video.c              |    4 +
 drivers/hwmon/adm1021.c         |    4 +
 drivers/hwmon/lm75.c            |    9 +
 drivers/i2c/Makefile            |    2 +
 drivers/i2c/fsl_i2c.c           |  266 +++++++++------
 drivers/i2c/soft_i2c.c          |  736 +++++++++++++++++++++++----------------
 include/configs/ATUM8548.h      |   16 +-
 include/configs/CPU86.h         |   10 +-
 include/configs/CPU87.h         |   10 +-
 include/configs/GEN860T.h       |    5 +
 include/configs/HIDDEN_DRAGON.h |    5 +
 include/configs/HMI10.h         |   12 +-
 include/configs/IAD210.h        |   12 +-
 include/configs/ICU862.h        |   14 +-
 include/configs/IDS8247.h       |   10 +-
 include/configs/IP860.h         |   10 +-
 include/configs/IPHASE4539.h    |   12 +-
 include/configs/KUP4K.h         |   13 +-
 include/configs/M52277EVB.h     |   12 +-
 include/configs/M5235EVB.h      |   10 +-
 include/configs/M5253DEMO.h     |    9 +-
 include/configs/M5271EVB.h      |   10 +-
 include/configs/M5275EVB.h      |   10 +-
 include/configs/M53017EVB.h     |   10 +-
 include/configs/M5329EVB.h      |   10 +-
 include/configs/M5373EVB.h      |   10 +-
 include/configs/M54451EVB.h     |   10 +-
 include/configs/M54455EVB.h     |   10 +-
 include/configs/M5475EVB.h      |   10 +-
 include/configs/M5485EVB.h      |   10 +-
 include/configs/MHPC.h          |    9 +-
 include/configs/MPC8313ERDB.h   |   18 +-
 include/configs/MPC8315ERDB.h   |   12 +-
 include/configs/MPC8323ERDB.h   |   12 +-
 include/configs/MPC832XEMDS.h   |   12 +-
 include/configs/MPC8349EMDS.h   |   19 +-
 include/configs/MPC8349ITX.h    |   38 +--
 include/configs/MPC8360EMDS.h   |   13 +-
 include/configs/MPC8360ERDK.h   |   19 +-
 include/configs/MPC837XEMDS.h   |   13 +-
 include/configs/MPC837XERDB.h   |   13 +-
 include/configs/MPC8536DS.h     |   21 +-
 include/configs/MPC8540ADS.h    |   14 +-
 include/configs/MPC8540EVAL.h   |   14 +-
 include/configs/MPC8541CDS.h    |   14 +-
 include/configs/MPC8544DS.h     |   14 +-
 include/configs/MPC8548CDS.h    |  119 +++++--
 include/configs/MPC8555CDS.h    |   14 +-
 include/configs/MPC8560ADS.h    |   14 +-
 include/configs/MPC8568MDS.h    |   21 +-
 include/configs/MPC8572DS.h     |   21 +-
 include/configs/MPC8610HPCD.h   |   14 +-
 include/configs/MPC8641HPCN.h   |   14 +-
 include/configs/MVBLM7.h        |   19 +-
 include/configs/NC650.h         |   10 +-
 include/configs/PM826.h         |    9 +-
 include/configs/PM828.h         |    9 +-
 include/configs/PM854.h         |   14 +-
 include/configs/PM856.h         |   14 +-
 include/configs/RRvision.h      |   13 +-
 include/configs/SBC8540.h       |   14 +-
 include/configs/SCM.h           |   11 +-
 include/configs/SIMPC8313.h     |   16 +-
 include/configs/SMN42.h         |   22 +-
 include/configs/SXNI855T.h      |    9 +-
 include/configs/Sandpoint8240.h |    5 +
 include/configs/Sandpoint8245.h |    5 +
 include/configs/TASREG.h        |   28 +-
 include/configs/TK885D.h        |   13 +-
 include/configs/TOP5200.h       |   11 +-
 include/configs/TOP860.h        |   12 +-
 include/configs/TQM8260.h       |    9 +-
 include/configs/TQM8272.h       |   10 +-
 include/configs/TQM834x.h       |   10 +-
 include/configs/TQM855M.h       |   13 +-
 include/configs/TQM85xx.h       |   14 +-
 include/configs/TQM866M.h       |   13 +-
 include/configs/TQM885D.h       |   13 +-
 include/configs/XPEDITE5200.h   |   18 +-
 include/configs/XPEDITE5370.h   |   18 +-
 include/configs/barco.h         |    5 +
 include/configs/bf533-ezkit.h   |   10 +-
 include/configs/bf533-stamp.h   |   83 ++---
 include/configs/debris.h        |    5 +
 include/configs/ep8260.h        |   10 +-
 include/configs/lwmon.h         |   13 +-
 include/configs/mgcoge.h        |   28 +-
 include/configs/mgsuvd.h        |   27 +-
 include/configs/pdnb3.h         |   11 +-
 include/configs/rmu.h           |   11 +-
 include/configs/sacsng.h        |   12 +-
 include/configs/sbc8260.h       |   12 +-
 include/configs/sbc8349.h       |   16 +-
 include/configs/sbc8548.h       |   12 +-
 include/configs/sbc8560.h       |   14 +-
 include/configs/sbc8641d.h      |   14 +-
 include/configs/socrates.h      |   20 +-
 include/configs/spc1920.h       |   13 +-
 include/configs/stxgp3.h        |   18 +-
 include/configs/stxssa.h        |   13 +-
 include/configs/uc100.h         |   13 +-
 include/configs/vct.h           |   11 +-
 include/i2c.h                   |  273 ++++++++-------
 lib_arm/board.c                 |   15 +-
 lib_blackfin/board.c            |    8 +
 lib_m68k/board.c                |   16 +-
 lib_mips/board.c                |    8 +
 lib_ppc/board.c                 |   16 +-
 117 files changed, 1737 insertions(+), 1496 deletions(-)

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 1338950..501d168 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -35,11 +35,9 @@
 #include <libfdt.h>
 #endif
 
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
+#if defined(CONFIG_SYS_I2C_ADAPTERS)
 #include <i2c.h>
 
-extern int i2c_soft_read_pin (void);
-
 int ivm_calc_crc (unsigned char *buf, int len)
 {
 	const unsigned short crc_tab[16] = {
@@ -295,32 +293,36 @@ int ivm_analyze_eeprom (unsigned char *buf, int len)
 
 int ivm_read_eeprom (void)
 {
-	I2C_MUX_DEVICE *dev = NULL;
 	uchar i2c_buffer[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
+	uint	tmp = 0xffff;
+#if !defined(CONFIG_SYS_IVM_EEPROM_BUS_NUM) || !defined(CONFIG_SYS_IVM_EEPROM_ADR)
 	uchar	*buf;
-	unsigned dev_addr = CONFIG_SYS_IVM_EEPROM_ADR;
+#endif
 
 	/* First init the Bus, select the Bus */
-#if defined(CONFIG_SYS_I2C_IVM_BUS)
-	dev = i2c_mux_ident_muxstring ((uchar *)CONFIG_SYS_I2C_IVM_BUS);
+#if defined(CONFIG_SYS_IVM_EEPROM_BUS_NUM)
+	tmp = CONFIG_SYS_IVM_EEPROM_BUS_NUM;
 #else
-	buf = (unsigned char *) getenv ("EEprom_ivm");
+	buf = (unsigned char *) getenv ("EEprom_ivm_bus");
 	if (buf != NULL)
-		dev = i2c_mux_ident_muxstring (buf);
+		tmp = (uint)simple_strtoul((char *)buf, NULL, 16);
 #endif
-	if (dev == NULL) {
-		printf ("Error couldnt add Bus for IVM\n");
-		return -1;
+	if (i2c_set_bus_num(tmp)) {
+		printf ("Error couldnt set Bus (%x) for IVM\n", tmp);
+		return(-1);
 	}
-	i2c_set_bus_num (dev->busid);
 
-	buf = (unsigned char *) getenv ("EEprom_ivm_addr");
-	if (buf != NULL)
-		dev_addr = simple_strtoul ((char *)buf, NULL, 16);
+#if defined(CONFIG_SYS_IVM_EEPROM_ADR)
+		tmp = CONFIG_SYS_IVM_EEPROM_ADR;
+#else
+		buf = (unsigned char *) getenv ("EEprom_ivm_addr");
+		if (buf != NULL)
+			tmp = (uint)simple_strtoul((char *)buf, NULL, 16);
+#endif
 
-	if (eeprom_read (dev_addr, 0, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) {
-		printf ("Error reading EEprom\n");
-		return -2;
+	if (eeprom_read (tmp, 0, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) {
+		printf("Error reading EEprom\n");
+		return(-2);
 	}
 
 	return ivm_analyze_eeprom (i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
diff --git a/board/keymile/mgcoge/mgcoge.c b/board/keymile/mgcoge/mgcoge.c
index 5c50739..2150cd8 100644
--- a/board/keymile/mgcoge/mgcoge.c
+++ b/board/keymile/mgcoge/mgcoge.c
@@ -32,10 +32,6 @@
 #include <libfdt.h>
 #endif
 
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
-#include <i2c.h>
-#endif
-
 #include "../common/common.h"
 
 /*
diff --git a/board/keymile/mgsuvd/mgsuvd.c b/board/keymile/mgsuvd/mgsuvd.c
index 02baf62..232c3e5 100644
--- a/board/keymile/mgsuvd/mgsuvd.c
+++ b/board/keymile/mgsuvd/mgsuvd.c
@@ -195,14 +195,3 @@ 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);
-}
diff --git a/board/lwmon/lwmon.c b/board/lwmon/lwmon.c
index 1b665a9..421009c 100644
--- a/board/lwmon/lwmon.c
+++ b/board/lwmon/lwmon.c
@@ -481,7 +481,7 @@ static void kbd_init (void)
 	uchar val, errcd;
 	int i;
 
-	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+	i2c_init_all();
 
 	gd->kbd_status = 0;
 
diff --git a/board/lwmon/pcmcia.c b/board/lwmon/pcmcia.c
index ad2e60d..3268426 100644
--- a/board/lwmon/pcmcia.c
+++ b/board/lwmon/pcmcia.c
@@ -108,7 +108,7 @@ int pcmcia_hardware_enable(int slot)
 
 	/*  switch VCC on */
 	val |= MAX1604_OP_SUS | MAX1604_VCCBON;
-	i2c_init  (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+	i2c_init_all();
 	i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
 
 	udelay(500000);
@@ -199,7 +199,7 @@ int pcmcia_voltage_set(int slot, int vcc, int vpp)
 	 */
 	debug ("PCMCIA power OFF\n");
 	val  = MAX1604_VCCBHIZ | MAX1604_VPPBHIZ;
-	i2c_init  (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+	i2c_init_all();
 	i2c_write (CONFIG_SYS_I2C_POWER_A_ADDR, 0, 0, &val, 1);
 
 	val = 0;
diff --git a/common/cmd_date.c b/common/cmd_date.c
index 3d78be2..847ec27 100644
--- a/common/cmd_date.c
+++ b/common/cmd_date.c
@@ -46,8 +46,13 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	int old_bus;
 
 	/* switch to correct I2C bus */
+#ifdef CONFIG_NEW_I2C
+	old_bus = i2c_get_bus_num();
+	i2c_set_bus_num(CONFIG_SYS_RTC_BUS_NUM);
+#else
 	old_bus = I2C_GET_BUS();
 	I2C_SET_BUS(CONFIG_SYS_RTC_BUS_NUM);
+#endif
 
 	switch (argc) {
 	case 2:			/* set date & time */
@@ -94,7 +99,11 @@ int do_date (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 	}
 
 	/* switch back to original I2C bus */
+#ifdef CONFIG_NEW_I2C
+	i2c_set_bus_num(old_bus);
+#else
 	I2C_SET_BUS(old_bus);
+#endif
 
 	return rcode;
 }
diff --git a/common/cmd_dtt.c b/common/cmd_dtt.c
index 7783c88..00f091e 100644
--- a/common/cmd_dtt.c
+++ b/common/cmd_dtt.c
@@ -35,8 +35,13 @@ int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 	int old_bus;
 
 	/* switch to correct I2C bus */
+#ifdef CONFIG_NEW_I2C
+	old_bus = i2c_get_bus_num();
+	i2c_set_bus_num(CONFIG_SYS_DTT_BUS_NUM);
+#else
 	old_bus = I2C_GET_BUS();
 	I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
+#endif
 
 	/*
 	 * Loop through sensors, read
@@ -46,7 +51,11 @@ int do_dtt (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 		printf ("DTT%d: %i C\n", i + 1, dtt_get_temp (sensors[i]));
 
 	/* switch back to original I2C bus */
+#ifdef CONFIG_NEW_I2C
+	i2c_set_bus_num(old_bus);
+#else
 	I2C_SET_BUS(old_bus);
+#endif
 
 	return 0;
 }	/* do_dtt() */
diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index 16439ac..1a5f79f 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -1,4 +1,9 @@
 /*
+ * (C) Copyright 2009
+ * Sergey Kubushyn, himself, ksi at koi8.net
+ *
+ * Changes for unified multibus/multiadapter I2C support.
+ *
  * (C) Copyright 2001
  * Gerald Van Baren, Custom IDEAS, vanbaren at cideas.com.
  *
@@ -106,7 +111,7 @@ static uint	i2c_mm_last_alen;
  * pairs.  The following macros take care of this */
 
 #if defined(CONFIG_SYS_I2C_NOPROBES)
-#if defined(CONFIG_I2C_MULTI_BUS)
+#if CONFIG_SYS_NUM_I2C_BUSSES > 1
 static struct
 {
 	uchar	bus;
@@ -122,19 +127,11 @@ static uchar i2c_no_probes[] = CONFIG_SYS_I2C_NOPROBES;
 #define COMPARE_BUS(b,i)	((b) == 0)	/* Make compiler happy */
 #define COMPARE_ADDR(a,i)	(i2c_no_probes[(i)] == (a))
 #define NO_PROBE_ADDR(i)	i2c_no_probes[(i)]
-#endif	/* CONFIG_MULTI_BUS */
+#endif	/* CONFIG_SYS_NUM_I2C_BUSSES > 1 */
 
 #define NUM_ELEMENTS_NOPROBE (sizeof(i2c_no_probes)/sizeof(i2c_no_probes[0]))
 #endif
 
-#if defined(CONFIG_I2C_MUX)
-static I2C_MUX_DEVICE	*i2c_mux_devices = NULL;
-static	int	i2c_mux_busid = CONFIG_SYS_MAX_I2C_BUS;
-
-DECLARE_GLOBAL_DATA_PTR;
-
-#endif
-
 static int
 mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[]);
 
@@ -548,10 +545,10 @@ mod_i2c_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char *argv[])
  */
 int do_i2c_probe (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-	int j;
+	int		j;
 #if defined(CONFIG_SYS_I2C_NOPROBES)
-	int k, skip;
-	uchar bus = GET_BUS_NUM;
+	int		k, skip;
+	unsigned int	bus = GET_BUS_NUM;
 #endif	/* NOPROBES */
 
 	puts ("Valid chip addresses:");
@@ -1189,59 +1186,79 @@ int do_sdram (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 #if defined(CONFIG_I2C_CMD_TREE)
 int do_i2c_reset(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
-	i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
+	i2c_init (ADAP(i2c_get_bus_num())->speed, ADAP(i2c_get_bus_num())->slaveaddr);
 	return 0;
 }
 
-#if defined(CONFIG_I2C_MUX)
-int do_i2c_add_bus(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
+int do_i2c_show_bus(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
-	int ret=0;
+	int	i;
+#ifndef CONFIG_SYS_I2C_DIRECT_BUS
+	int	j;
+#endif
 
 	if (argc == 1) {
 		/* show all busses */
-		I2C_MUX		*mux;
-		I2C_MUX_DEVICE	*device = i2c_mux_devices;
-
-		printf ("Busses reached over muxes:\n");
-		while (device != NULL) {
-			printf ("Bus ID: %x\n", device->busid);
-			printf ("  reached over Mux(es):\n");
-			mux = device->mux;
-			while (mux != NULL) {
-				printf ("    %s@%x ch: %x\n", mux->name, mux->chip, mux->channel);
-				mux = mux->next;
+		for (i = 0; i < CONFIG_SYS_NUM_I2C_BUSSES; i++) {
+			printf("Bus %d:\t%s", i, ADAP(i)->name);
+#ifndef CONFIG_SYS_I2C_DIRECT_BUS
+			for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
+				if (i2c_bus[i].next_hop[j].chip == 0) break;
+				printf("->%s at 0x%2x:%d",
+					i2c_bus[i].next_hop[j].mux.name,
+					i2c_bus[i].next_hop[j].chip,
+					i2c_bus[i].next_hop[j].channel);
 			}
-			device = device->next;
+#endif
+			printf("\n");
 		}
-	} else {
-		I2C_MUX_DEVICE *dev;
 
-		dev = i2c_mux_ident_muxstring ((uchar *)argv[1]);
-		ret = 0;
+	} else {
+		/* show specific bus */
+		i = simple_strtoul(argv[1], NULL, 10);
+		if (i >= CONFIG_SYS_NUM_I2C_BUSSES) {
+			printf("Invalid bus %d\n", i);
+			return(-1);
+		}
+		printf("Bus %d:\t%s", i, ADAP(i)->name);
+#ifndef CONFIG_SYS_I2C_DIRECT_BUS
+			for (j = 0; j < CONFIG_SYS_I2C_MAX_HOPS; j++) {
+				if (i2c_bus[i].next_hop[j].chip == 0) break;
+				printf("->%s at 0x%2x:%d",
+					i2c_bus[i].next_hop[j].mux.name,
+					i2c_bus[i].next_hop[j].chip,
+					i2c_bus[i].next_hop[j].channel);
+			}
+#endif
+		printf("\n");
 	}
-	return ret;
+
+	return(0);
 }
-#endif  /* CONFIG_I2C_MUX */
 
-#if defined(CONFIG_I2C_MULTI_BUS)
+#if CONFIG_SYS_NUM_I2C_BUSSES > 1
 int do_i2c_bus_num(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
-	int bus_idx, ret=0;
+	int		ret=0;
+	unsigned int	bus_no;
 
 	if (argc == 1)
 		/* querying current setting */
 		printf("Current bus is %d\n", i2c_get_bus_num());
 	else {
-		bus_idx = simple_strtoul(argv[1], NULL, 10);
-		printf("Setting bus to %d\n", bus_idx);
-		ret = i2c_set_bus_num(bus_idx);
+		bus_no = simple_strtoul(argv[1], NULL, 10);
+		if (bus_no >= CONFIG_SYS_NUM_I2C_BUSSES) {
+			printf("Invalid bus %d\n", bus_no);
+			return(-1);
+		}
+		printf("Setting bus to %d\n", bus_no);
+		ret = i2c_set_bus_num(bus_no);
 		if (ret)
 			printf("Failure changing bus number (%d)\n", ret);
 	}
 	return ret;
 }
-#endif  /* CONFIG_I2C_MULTI_BUS */
+#endif  /* CONFIG_SYS_NUM_I2C_BUSSES > 1 */
 
 int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
@@ -1262,16 +1279,16 @@ int do_i2c_bus_speed(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 
 int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 {
-#if defined(CONFIG_I2C_MUX)
+#if CONFIG_SYS_NUM_I2C_BUSSES > 1
 	if (!strncmp(argv[1], "bu", 2))
-		return do_i2c_add_bus(cmdtp, flag, --argc, ++argv);
-#endif  /* CONFIG_I2C_MUX */
+		return do_i2c_show_bus(cmdtp, flag, --argc, ++argv);
+#endif  /* CONFIG_SYS_NUM_I2C_BUSSES > 1 */
 	if (!strncmp(argv[1], "sp", 2))
 		return do_i2c_bus_speed(cmdtp, flag, --argc, ++argv);
-#if defined(CONFIG_I2C_MULTI_BUS)
+#if CONFIG_SYS_NUM_I2C_BUSSES > 1
 	if (!strncmp(argv[1], "de", 2))
 		return do_i2c_bus_num(cmdtp, flag, --argc, ++argv);
-#endif  /* CONFIG_I2C_MULTI_BUS */
+#endif  /* CONFIG_SYS_NUM_I2C_BUSSES > 1 */
 	if (!strncmp(argv[1], "md", 2))
 		return do_i2c_md(cmdtp, flag, --argc, ++argv);
 	if (!strncmp(argv[1], "mm", 2))
@@ -1304,13 +1321,11 @@ int do_i2c(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
 U_BOOT_CMD(
 	i2c, 6, 1, do_i2c,
 	"I2C sub-system",
-#if defined(CONFIG_I2C_MUX)
-	"bus [muxtype:muxaddr:muxchannel] - add a new bus reached over muxes.\n"
-#endif  /* CONFIG_I2C_MUX */
-	"speed [speed] - show or set I2C bus speed\n"
-#if defined(CONFIG_I2C_MULTI_BUS)
+#if CONFIG_SYS_NUM_I2C_BUSSES > 1
+	"bus [bus_no] - show I2C bus info.\n"
 	"i2c dev [dev] - show or set current I2C bus\n"
-#endif  /* CONFIG_I2C_MULTI_BUS */
+#endif  /* CONFIG_SYS_NUM_I2C_BUSSES > 1 */
+	"i2c speed [speed] - show or set I2C bus speed\n"
 	"i2c md chip address[.0, .1, .2] [# of objects] - read from I2C device\n"
 	"i2c mm chip address[.0, .1, .2] - write to I2C device (auto-incrementing)\n"
 	"i2c mw chip address[.0, .1, .2] value [count] - write to I2C device (fill)\n"
@@ -1323,7 +1338,7 @@ U_BOOT_CMD(
 	"i2c sdram chip - print SDRAM configuration information\n"
 #endif
 );
-#endif /* CONFIG_I2C_CMD_TREE */
+#else /* CONFIG_I2C_CMD_TREE */
 U_BOOT_CMD(
 	imd,	4,	1,	do_i2c_md,		\
 	"i2c memory display",				\
@@ -1378,221 +1393,4 @@ U_BOOT_CMD(
 	"      (valid chip values 50..57)\n"
 );
 #endif
-
-#if defined(CONFIG_I2C_MUX)
-
-int i2c_mux_add_device(I2C_MUX_DEVICE *dev)
-{
-	I2C_MUX_DEVICE	*devtmp = i2c_mux_devices;
-
-	if (i2c_mux_devices == NULL) {
-		i2c_mux_devices = dev;
-		return 0;
-	}
-	while (devtmp->next != NULL)
-		devtmp = devtmp->next;
-
-	devtmp->next = dev;
-	return 0;
-}
-
-I2C_MUX_DEVICE	*i2c_mux_search_device(int id)
-{
-	I2C_MUX_DEVICE	*device = i2c_mux_devices;
-
-	while (device != NULL) {
-		if (device->busid == id)
-			return device;
-		device = device->next;
-	}
-	return NULL;
-}
-
-/* searches in the buf from *pos the next ':'.
- * returns:
- *     0 if found (with *pos = where)
- *   < 0 if an error occured
- *   > 0 if the end of buf is reached
- */
-static int i2c_mux_search_next (int *pos, uchar	*buf, int len)
-{
-	while ((buf[*pos] != ':') && (*pos < len)) {
-		*pos += 1;
-	}
-	if (*pos >= len)
-		return 1;
-	if (buf[*pos] != ':')
-		return -1;
-	return 0;
-}
-
-static int i2c_mux_get_busid (void)
-{
-	int	tmp = i2c_mux_busid;
-
-	i2c_mux_busid ++;
-	return tmp;
-}
-
-/* Analyses a Muxstring and sends immediately the
-   Commands to the Muxes. Runs from Flash.
- */
-int i2c_mux_ident_muxstring_f (uchar *buf)
-{
-	int	pos = 0;
-	int	oldpos;
-	int	ret = 0;
-	int	len = strlen((char *)buf);
-	int	chip;
-	uchar	channel;
-	int	was = 0;
-
-	while (ret == 0) {
-		oldpos = pos;
-		/* search name */
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret != 0)
-			printf ("ERROR\n");
-		/* search address */
-		pos ++;
-		oldpos = pos;
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret != 0)
-			printf ("ERROR\n");
-		buf[pos] = 0;
-		chip = simple_strtoul((char *)&buf[oldpos], NULL, 16);
-		buf[pos] = ':';
-		/* search channel */
-		pos ++;
-		oldpos = pos;
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret < 0)
-			printf ("ERROR\n");
-		was = 0;
-		if (buf[pos] != 0) {
-			buf[pos] = 0;
-			was = 1;
-		}
-		channel = simple_strtoul((char *)&buf[oldpos], NULL, 16);
-		if (was)
-			buf[pos] = ':';
-		if (i2c_write(chip, 0, 0, &channel, 1) != 0) {
-			printf ("Error setting Mux: chip:%x channel: \
-				%x\n", chip, channel);
-			return -1;
-		}
-		pos ++;
-		oldpos = pos;
-
-	}
-
-	return 0;
-}
-
-/* Analyses a Muxstring and if this String is correct
- * adds a new I2C Bus.
- */
-I2C_MUX_DEVICE *i2c_mux_ident_muxstring (uchar *buf)
-{
-	I2C_MUX_DEVICE	*device;
-	I2C_MUX		*mux;
-	int	pos = 0;
-	int	oldpos;
-	int	ret = 0;
-	int	len = strlen((char *)buf);
-	int	was = 0;
-
-	device = (I2C_MUX_DEVICE *)malloc (sizeof(I2C_MUX_DEVICE));
-	device->mux = NULL;
-	device->busid = i2c_mux_get_busid ();
-	device->next = NULL;
-	while (ret == 0) {
-		mux = (I2C_MUX *)malloc (sizeof(I2C_MUX));
-		mux->next = NULL;
-		/* search name of mux */
-		oldpos = pos;
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret != 0)
-			printf ("%s no name.\n", __FUNCTION__);
-		mux->name = (char *)malloc (pos - oldpos + 1);
-		memcpy (mux->name, &buf[oldpos], pos - oldpos);
-		mux->name[pos - oldpos] = 0;
-		/* search address */
-		pos ++;
-		oldpos = pos;
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret != 0)
-			printf ("%s no mux address.\n", __FUNCTION__);
-		buf[pos] = 0;
-		mux->chip = simple_strtoul((char *)&buf[oldpos], NULL, 16);
-		buf[pos] = ':';
-		/* search channel */
-		pos ++;
-		oldpos = pos;
-		ret = i2c_mux_search_next(&pos, buf, len);
-		if (ret < 0)
-			printf ("%s no mux channel.\n", __FUNCTION__);
-		was = 0;
-		if (buf[pos] != 0) {
-			buf[pos] = 0;
-			was = 1;
-		}
-		mux->channel = simple_strtoul((char *)&buf[oldpos], NULL, 16);
-		if (was)
-			buf[pos] = ':';
-		if (device->mux == NULL)
-			device->mux = mux;
-		else {
-			I2C_MUX		*muxtmp = device->mux;
-			while (muxtmp->next != NULL) {
-				muxtmp = muxtmp->next;
-			}
-			muxtmp->next = mux;
-		}
-		pos ++;
-		oldpos = pos;
-	}
-	if (ret > 0) {
-		/* Add Device */
-		i2c_mux_add_device (device);
-		return device;
-	}
-
-	return NULL;
-}
-
-int i2x_mux_select_mux(int bus)
-{
-	I2C_MUX_DEVICE  *dev;
-	I2C_MUX		*mux;
-
-	if ((gd->flags & GD_FLG_RELOC) != GD_FLG_RELOC) {
-		/* select Default Mux Bus */
-#if defined(CONFIG_SYS_I2C_IVM_BUS)
-		i2c_mux_ident_muxstring_f ((uchar *)CONFIG_SYS_I2C_IVM_BUS);
-#else
-		{
-		unsigned char *buf;
-		buf = (unsigned char *) getenv("EEprom_ivm");
-		if (buf != NULL)
-			i2c_mux_ident_muxstring_f (buf);
-		}
-#endif
-		return 0;
-	}
-	dev = i2c_mux_search_device(bus);
-	if (dev == NULL)
-		return -1;
-
-	mux = dev->mux;
-	while (mux != NULL) {
-		if (i2c_write(mux->chip, 0, 0, &mux->channel, 1) != 0) {
-			printf ("Error setting Mux: chip:%x channel: \
-				%x\n", mux->chip, mux->channel);
-			return -1;
-		}
-		mux = mux->next;
-	}
-	return 0;
-}
-#endif /* CONFIG_I2C_MUX */
+#endif /* CONFIG_I2C_CMD_TREE */


More information about the U-Boot mailing list