Skip to contentSkip to conversation

I2C: adding new "i2c bus" Command to the I2C Subsystem.

PATCH New Heiko Schocher 2 participants 4 messages Oct 15, 2008 – Oct 16, 2008 I2C

lore
Share & tools
lore
#0 lore raw

PATCH v2 13/16 I2C: adding new "i2c bus" Command to the I2C Subsystem.

With this Command it is possible to add new I2C Busses, which are behind 1 .. n I2C Muxes. Details see README.

---
 README                   |   47 ++++++++
 common/cmd_i2c.c         |  267 ++++++++++++++++++++++++++++++++++++++++++++++
 cpu/mpc8260/i2c.c        |   15 +++-
 drivers/i2c/soft_i2c.c   |   15 +++-
 include/configs/mgcoge.h |    1 +
 include/configs/mgsuvd.h |    1 +
 include/i2c.h            |   23 ++++
 7 files changed, 367 insertions(+), 2 deletions(-)
README +47 -0
index b10b539..46353f4 100644
@@ -1429,6 +1429,53 @@ The following options need to be configured:
 		Define this option if you want to use Freescale's I2C driver in
 		drivers/i2c/fsl_i2c.c.
 
+		CONFIG_I2C_MUX
+
+		Define this option if you have I2C devices reached over 1 .. n
+		I2C Muxes like the pca9544a. This option addes a new I2C
+		Command "i2c bus [muxtype:muxaddr:muxchannel]" which adds a
+		new I2C Bus to the existing I2C Busses. If you select the
+		new Bus with "i2c dev", u-bbot sends first the commandos for
+		the muxes to activate this new "bus".
+
+		CONFIG_I2C_MULTI_BUS must be also defined, to use this
+		feature!
+
+		Example:
+		Adding a new I2C Bus reached over 2 pca9544a muxes
+			The First mux with address 70 and channel 6
+			The Second mux with address 71 and channel 4
+
+		=> i2c bus pca9544a:70:6:pca9544a:71:4
+
+		Use the "i2c bus" command without parameter, to get a list
+		of I2C Busses with muxes:
+
+		=> i2c bus
+		Busses reached over muxes:
+		Bus ID: 2
+		  reached over Mux(es):
+		    pca9544a at 70 ch: 4
+		Bus ID: 3
+		  reached over Mux(es):
+		    pca9544a at 70 ch: 6
+		    pca9544a at 71 ch: 4
+		=>	
+
+		If you now switch to the new I2C Bus 3 with "i2c dev 3"
+		u-boot sends First the Commando to the mux at 70 to enable
+		channel 6, and then the Commando to the mux at 71 to enable
+		the channel 4.
+
+		After that, you can use the "normal" i2c commands as
+		usual, to communicate with your I2C devices behind
+		the 2 muxes.
+
+		This option is actually implemented for the bitbanging
+		algorithm in common/soft_i2c.c and for the Hardware I2C
+		Bus on the MPC8260. But it should be not so difficult
+		to add this option to other architectures.
+
 
 - SPI Support:	CONFIG_SPI
 
common/cmd_i2c.c +267 -0

301 lines not on this page · raw message

cpu/mpc8260/i2c.c +14 -1
index 335177f..a96fbf8 100644
@@ -780,10 +780,23 @@ unsigned int i2c_get_bus_num(void)
 
 int i2c_set_bus_num(unsigned int bus)
 {
+#if defined(CONFIG_I2C_MUX)
+	if (bus < CFG_MAX_I2C_BUS) {
+		i2c_bus_num = bus;
+	} else {
+		int	ret;
+
+		ret = i2x_mux_select_mux(bus);
+		if (ret == 0)
+			i2c_bus_num = bus;
+		else
+			return ret;
+	}
+#else
 	if (bus >= CFG_MAX_I2C_BUS)
 		return -1;
 	i2c_bus_num = bus;
-
+#endif
 	return 0;
 }
 /* TODO: add 100/400k switching */
drivers/i2c/soft_i2c.c +14 -1
index 63e6a7b..0a9feb6 100644
@@ -223,10 +223,23 @@ unsigned int i2c_get_bus_num(void)
 
 int i2c_set_bus_num(unsigned int bus)
 {
+#if defined(CONFIG_I2C_MUX)
+	if (bus < CFG_MAX_I2C_BUS) {
+		i2c_bus_num = bus;
+	} else {
+		int	ret;
+
+		ret = i2x_mux_select_mux(bus);
+		if (ret == 0)
+			i2c_bus_num = bus;
+		else
+			return ret;
+	}
+#else
 	if (bus >= CFG_MAX_I2C_BUS)
 		return -1;
 	i2c_bus_num = bus;
-
+#endif
 	return 0;
 }
 
include/configs/mgcoge.h +1 -0
index 398e092..6564c15 100644
@@ -203,6 +203,7 @@
 #define CONFIG_I2C_CMD_TREE	1
 #define CFG_MAX_I2C_BUS		2
 #define CFG_I2C_INIT_BOARD	1
+#define CONFIG_I2C_MUX		1
 
 /* EEprom support */
 #define CFG_I2C_EEPROM_ADDR_LEN	1
include/configs/mgsuvd.h +1 -0
index 2048575..e2a7c07 100644
@@ -374,6 +374,7 @@
 #define CONFIG_I2C_CMD_TREE	1
 #define CFG_MAX_I2C_BUS		2
 #define CFG_I2C_INIT_BOARD	1
+#define CONFIG_I2C_MUX		1
 
 /* EEprom support */
 #define CFG_I2C_EEPROM_ADDR_LEN	1
include/i2c.h +23 -0
index a6e797a..9f771dd 100644
@@ -85,6 +85,29 @@ void i2c_init(int speed, int slaveaddr);
 void i2c_init_board(void);
 #endif
 
+#if defined(CONFIG_I2C_MUX)
+
+typedef struct _mux {
+	uchar	chip;
+	uchar	channel;
+	char	*name;
+	struct _mux	*next;
+} I2C_MUX;
+
+typedef struct _mux_device {
+	int	busid;
+	I2C_MUX	*mux;	/* List of muxes, to reach the device */
+	struct _mux_device	*next;
+} I2C_MUX_DEVICE;
+
+int	i2c_mux_add_device(I2C_MUX_DEVICE *dev);
+
+I2C_MUX_DEVICE	*i2c_mux_search_device(int id);
+I2C_MUX_DEVICE *i2c_mux_ident_muxstring (uchar *buf);
+int i2x_mux_select_mux(int bus);
+int i2c_mux_ident_muxstring_f (uchar *buf);
+#endif
+
 /*
  * Probe the given I2C chip address.  Returns 0 if a chip responded,
  * not 0 on failure.
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
#1 lore raw

PATCH v2 13/16 I2C: adding new "i2c bus" Command to the I2C Subsystem.

Quoted 3 lines · Heiko Schocher

With this Command it is possible to add new I2C Busses, which are behind 1 .. n I2C Muxes. Details see README.

While this is pretty cool, I'm curious what circumstances lead to needing to add I2C buses at run-time via command line. Presumably you have a real business need for this in a bootloader?

regards,
Ben

#2 lore raw

PATCH v2 13/16 I2C: adding new "i2c bus" Command to the I2C Subsystem.

Hello Ben,

Quoted 7 lines · Ben Warren
Quoted 3 lines · Heiko Schocher

With this Command it is possible to add new I2C Busses, which are behind 1 .. n I2C Muxes. Details see README.

While this is pretty cool, I'm curious what circumstances lead to needing to add I2C buses at run-time via command line. Presumably you have a real business need for this in a bootloader?

Yes. This boardmanufacturer has a lot of hardwareversions with different I2C bus wirings, but has for example always one EEProm with configdata. Now, he can use one u-boot image for all this boards and has just to define in the environment, in which way he can reach this EEprom.

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 13/16 I2C: adding new "i2c bus" Command to the I2C Subsystem.

Hi Heiko,

Quoted 15 lines · Heiko Schocher

Hello Ben,

Quoted 10 lines · Ben Warren
Quoted 4 lines · Heiko Schocher

With this Command it is possible to add new I2C Busses, which are behind 1 .. n I2C Muxes. Details see README.

While this is pretty cool, I'm curious what circumstances lead to needing to add I2C buses at run-time via command line. Presumably you have a real business need for this in a bootloader?

Quoted 9 lines

Yes. This boardmanufacturer has a lot of hardwareversions with different I2C bus wirings, but has for example always one EEProm with configdata. Now, he can use one u-boot image for all this boards and has just to define in the environment, in which way he can reach this EEprom.

bye
Heiko

Interesting. Thank you.

regards,
Ben