I2C: adding new "i2c bus" Command to the I2C Subsystem.
PATCH 1/1 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 | 269 +++++++++++++++++++++++++++++++++++++++++++++- 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, 368 insertions(+), 3 deletions(-)
README +47 -0
@@ -1426,6 +1426,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 +268 -1
304 lines not on this page · raw message
cpu/mpc8260/i2c.c +14 -1
@@ -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
@@ -249,10 +249,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
@@ -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
@@ -373,6 +373,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
@@ -76,6 +76,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
PATCH 1/1 I2C: adding new "i2c bus" Command to the I2C Subsystem.
Dear Heiko Schocher,
Quoted 4 lines · In message <[email protected]> you wrote:
With this Command it is possible to add new I2C Busses, which are behind 1 .. n I2C Muxes. Details see README.
Signed-off-by Heiko Schocher <[email protected]>
Quoted 9 lines
--- README | 47 ++++++++ common/cmd_i2c.c | 269 +++++++++++++++++++++++++++++++++++++++++++++- 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, 368 insertions(+), 3 deletions(-)
Does not apply:
Applying I2C: adding new "i2c bus" Command to the I2C Subsystem. .dotest/patch:50: trailing whitespace.
=>
.dotest/patch:269: trailing whitespace.
.dotest/patch:271: trailing whitespace.
error: patch failed: include/configs/mgcoge.h:203
error: include/configs/mgcoge.h: patch does not apply
error: patch failed: include/configs/mgsuvd.h:373
error: include/configs/mgsuvd.h: patch does not apply
fatal: sha1 information is lacking or useless (drivers/i2c/soft_i2c.c). Repository lacks necessary blobs to fall back on 3-way merge. Cannot fall back to three-way merge.
Patch failed at 0006.
Please rebase and resubmit.
Best regards,
Wolfgang Denk
Signature · 6 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de We are all agreed that your theory is crazy. The question which divides us is whether it is crazy enough to have a chance of being correct. My own feeling is that it is not crazy enough. - Niels Bohr