
Signed-off-by: Sergey Kubushyn ksi@koi8.net --- diff --git a/include/configs/pdnb3.h b/include/configs/pdnb3.h index 4da401f..9ba0147 100644 --- a/include/configs/pdnb3.h +++ b/include/configs/pdnb3.h @@ -296,11 +296,12 @@
/* 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 CONFIG_SYS_I2C_SPEED 83000 /* 83 kHz is supposed to work */ -#define CONFIG_SYS_I2C_SLAVE 0xFE - +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 83000 /* 83 kHz is supposed to work */ +#define CONFIG_SYS_SOFT_I2C_SLAVE 0xFE +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* * Software (bit-bang) I2C driver configuration */ diff --git a/include/configs/rmu.h b/include/configs/rmu.h index d88ae81..15bf356 100644 --- a/include/configs/rmu.h +++ b/include/configs/rmu.h @@ -61,11 +61,12 @@
/* 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 CONFIG_SYS_I2C_SPEED 40000 /* 40 kHz is supposed to work */ -#define CONFIG_SYS_I2C_SLAVE 0xFE - +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 40000 /* 40 kHz is supposed to work */ +#define CONFIG_SYS_SOFT_I2C_SLAVE 0xFE +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* Software (bit-bang) I2C driver configuration */ #define PB_SCL 0x00000020 /* PB 26 */ #define PB_SDA 0x00000010 /* PB 27 */ diff --git a/include/configs/sacsng.h b/include/configs/sacsng.h index f4e08c6..1cab474 100644 --- a/include/configs/sacsng.h +++ b/include/configs/sacsng.h @@ -292,14 +292,15 @@ * configuration items that the driver uses to drive the port pins. */ #undef CONFIG_HARD_I2C /* I2C with hardware support */ -#define CONFIG_SOFT_I2C 1 /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F - +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 400000 +#define CONFIG_SYS_SOFT_I2C_SLAVE 0x7F +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* * Software (bit-bang) I2C driver configuration */ -#ifdef CONFIG_SOFT_I2C #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) @@ -309,7 +310,6 @@ #define I2C_SCL(bit) if(bit) iop->pdat |= 0x00020000; \ else iop->pdat &= ~0x00020000 #define I2C_DELAY udelay(20) /* 1/4 I2C clock duration */ -#endif /* CONFIG_SOFT_I2C */
/* Define this to reserve an entire FLASH sector for * environment variables. Otherwise, the environment will be diff --git a/include/configs/sbc8260.h b/include/configs/sbc8260.h index 26ed557..ec85929 100644 --- a/include/configs/sbc8260.h +++ b/include/configs/sbc8260.h @@ -250,14 +250,15 @@ * configuration items that the driver uses to drive the port pins. */ #undef CONFIG_HARD_I2C /* I2C with hardware support */ -#define CONFIG_SOFT_I2C 1 /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F - +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 400000 +#define CONFIG_SYS_SOFT_I2C_SLAVE 0x7F +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* * Software (bit-bang) I2C driver configuration */ -#ifdef CONFIG_SOFT_I2C #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) @@ -267,7 +268,6 @@ #define I2C_SCL(bit) if(bit) iop->pdat |= 0x00020000; \ else iop->pdat &= ~0x00020000 #define I2C_DELAY udelay(5) /* 1/4 I2C clock duration */ -#endif /* CONFIG_SOFT_I2C */
/* Define this to reserve an entire FLASH sector (256 KB) for diff --git a/include/configs/sbc8349.h b/include/configs/sbc8349.h index 0603e3c..5316df7 100644 --- a/include/configs/sbc8349.h +++ b/include/configs/sbc8349.h @@ -312,17 +312,13 @@ #define CONFIG_OF_STDOUT_VIA_ALIAS 1
/* I2C */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ +#define CONFIG_NEW_I2C #define CONFIG_FSL_I2C -#define CONFIG_I2C_CMD_TREE -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */ -#define CONFIG_SYS_I2C1_OFFSET 0x3000 -#define CONFIG_SYS_I2C2_OFFSET 0x3100 -#define CONFIG_SYS_I2C_OFFSET CONFIG_SYS_I2C2_OFFSET -/* could also use CONFIG_I2C_MULTI_BUS and CONFIG_SPD_BUS_NUM... */ +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3100 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]} +#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */
/* TSEC */ #define CONFIG_SYS_TSEC1_OFFSET 0x24000 diff --git a/include/configs/sbc8548.h b/include/configs/sbc8548.h index 8141a46..6826903 100644 --- a/include/configs/sbc8548.h +++ b/include/configs/sbc8548.h @@ -320,13 +320,13 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_NEW_I2C +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3000 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]} #define CONFIG_SYS_I2C_EEPROM_ADDR 0x50 -#define CONFIG_SYS_I2C_SLAVE 0x7F -#define CONFIG_SYS_I2C_OFFSET 0x3000
/* * General PCI diff --git a/include/configs/sbc8560.h b/include/configs/sbc8560.h index d4e9d74..3a0303a 100644 --- a/include/configs/sbc8560.h +++ b/include/configs/sbc8560.h @@ -222,13 +222,13 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */ -#define CONFIG_SYS_I2C_OFFSET 0x3000 +#define CONFIG_NEW_I2C +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3000 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]} +#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */
#define CONFIG_SYS_PCI_MEM_BASE 0xC0000000 #define CONFIG_SYS_PCI_MEM_PHYS 0xC0000000 diff --git a/include/configs/sbc8641d.h b/include/configs/sbc8641d.h index 1008812..aafdbf8 100644 --- a/include/configs/sbc8641d.h +++ b/include/configs/sbc8641d.h @@ -292,13 +292,13 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */ -#define CONFIG_SYS_I2C_OFFSET 0x3100 +#define CONFIG_NEW_I2C +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3100 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]} +#define CONFIG_SYS_I2C_NOPROBES {0x69} /* Don't probe these addrs */
/* * RapidIO MMU diff --git a/include/configs/socrates.h b/include/configs/socrates.h index becd13e..33aee21 100644 --- a/include/configs/socrates.h +++ b/include/configs/socrates.h @@ -235,16 +235,16 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support */ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 102124 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#define CONFIG_SYS_I2C_OFFSET 0x3000 - -#define CONFIG_I2C_MULTI_BUS -#define CONFIG_I2C_CMD_TREE -#define CONFIG_SYS_I2C2_OFFSET 0x3100 +#define CONFIG_NEW_I2C +#define CONFIG_SYS_NUM_I2C_ADAPTERS 2 +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 102124 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3000 +#define CONFIG_SYS_FSL_I2C2_SPEED 102124 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C2_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C2_OFFSET 0x3100 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0], &fsl_i2c_adap[1]}
/* I2C RTC */ #define CONFIG_RTC_RX8025 /* Use Epson rx8025 rtc via i2c */ diff --git a/include/configs/spc1920.h b/include/configs/spc1920.h index 1fe2a04..75f364b 100644 --- a/include/configs/spc1920.h +++ b/include/configs/spc1920.h @@ -208,12 +208,12 @@ #if defined(CONFIG_CMD_I2C) /* 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 CONFIG_SYS_I2C_SPEED 93000 /* 93 kHz is supposed to work */ -#define CONFIG_SYS_I2C_SLAVE 0xFE - -#ifdef CONFIG_SOFT_I2C +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 93000 /* 93 kHz is supposed to work */ +#define CONFIG_SYS_SOFT_I2C_SLAVE 0xFE +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* * Software (bit-bang) I2C driver configuration */ @@ -229,7 +229,6 @@ #define I2C_SCL(bit) if(bit) immr->im_cpm.cp_pbdat |= PB_SCL; \ else immr->im_cpm.cp_pbdat &= ~PB_SCL #define I2C_DELAY udelay(2) /* 1/4 I2C clock duration */ -#endif /* CONFIG_SOFT_I2C */ #endif
/*----------------------------------------------------------------------- diff --git a/include/configs/stxgp3.h b/include/configs/stxgp3.h index ae6f45a..bb9b773 100644 --- a/include/configs/stxgp3.h +++ b/include/configs/stxgp3.h @@ -180,18 +180,12 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#if 0 -#define CONFIG_SYS_I2C_NOPROBES {0x00} /* Don't probe these addrs */ -#else -/* I did the 'if 0' so we could keep the syntax above if ever needed. */ -#undef CONFIG_SYS_I2C_NOPROBES -#endif -#define CONFIG_SYS_I2C_OFFSET 0x3000 +#define CONFIG_NEW_I2C +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3000 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]}
/* RapdIO Map configuration, mapped 1:1. */ diff --git a/include/configs/stxssa.h b/include/configs/stxssa.h index c312f1a..e59e1e0 100644 --- a/include/configs/stxssa.h +++ b/include/configs/stxssa.h @@ -197,13 +197,12 @@ /* * I2C */ -#define CONFIG_FSL_I2C /* Use FSL common I2C driver */ -#define CONFIG_HARD_I2C /* I2C with hardware support*/ -#undef CONFIG_SOFT_I2C /* I2C bit-banged */ -#define CONFIG_SYS_I2C_SPEED 400000 /* I2C speed and slave address */ -#define CONFIG_SYS_I2C_SLAVE 0x7F -#undef CONFIG_SYS_I2C_NOPROBES -#define CONFIG_SYS_I2C_OFFSET 0x3000 +#define CONFIG_NEW_I2C +#define CONFIG_FSL_I2C +#define CONFIG_SYS_FSL_I2C_SPEED 400000 /* I2C speed and slave address */ +#define CONFIG_SYS_FSL_I2C_SLAVE 0x7F +#define CONFIG_SYS_FSL_I2C_OFFSET 0x3000 +#define CONFIG_SYS_I2C_ADAPTERS {&fsl_i2c_adap[0]}
/* I2C RTC */ #define CONFIG_RTC_DS1337 /* This is really a DS1339 RTC */ diff --git a/include/configs/uc100.h b/include/configs/uc100.h index 23f4c82..4019a80 100644 --- a/include/configs/uc100.h +++ b/include/configs/uc100.h @@ -468,12 +468,12 @@
/* 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 CONFIG_SYS_I2C_SPEED 93000 /* 93 kHz is supposed to work */ -#define CONFIG_SYS_I2C_SLAVE 0xFE - -#ifdef CONFIG_SOFT_I2C +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 93000 /* 93 kHz is supposed to work */ +#define CONFIG_SYS_SOFT_I2C_SLAVE 0xFE +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]} /* * Software (bit-bang) I2C driver configuration */ @@ -489,7 +489,6 @@ #define I2C_SCL(bit) if(bit) immr->im_cpm.cp_pbdat |= PB_SCL; \ else immr->im_cpm.cp_pbdat &= ~PB_SCL #define I2C_DELAY udelay(2) /* 1/4 I2C clock duration */ -#endif /* CONFIG_SOFT_I2C */
/*----------------------------------------------------------------------- * I2C EEPROM (24C164) diff --git a/include/configs/vct.h b/include/configs/vct.h index 391535e..173095a 100644 --- a/include/configs/vct.h +++ b/include/configs/vct.h @@ -235,11 +235,14 @@ * I2C/EEPROM */ #undef CONFIG_HARD_I2C /* I2C with hardware support */ -#define CONFIG_SOFT_I2C /* I2C bit-banged */ - -#define CONFIG_SYS_I2C_SPEED 83000 /* 83 kHz is supposed to work */ -#define CONFIG_SYS_I2C_SLAVE 0x7f +#define CONFIG_NEW_I2C +#define CONFIG_SOFT_I2C /* I2C bit-banged */ +#define I2C_SOFT_DECLARATIONS I2C_SOFT_DEFS +#define CONFIG_SYS_SOFT_I2C_SPEED 83000 /* 83 kHz is supposed to work */ +#define CONFIG_SYS_SOFT_I2C_SLAVE 0x7f +#define CONFIG_SYS_I2C_ADAPTERS {&soft_i2c_adap[0]}
+#define CONFIG_SOFT_I2C /* I2C bit-banged */ /* * Software (bit-bang) I2C driver configuration */ diff --git a/include/i2c.h b/include/i2c.h index fad2d57..6d33388 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -1,4 +1,7 @@ /* + * Copyright (C) 2009 Sergey Kubushyn ksi@koi8.net + * Changes for multibus/multiadapter I2C support. + * * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com. * @@ -46,14 +49,20 @@ */ #define I2C_RXTX_LEN 128 /* maximum tx/rx buffer length */
-#if defined(CONFIG_I2C_MULTI_BUS) -#define CONFIG_SYS_MAX_I2C_BUS 2 -#define I2C_GET_BUS() i2c_get_bus_num() -#define I2C_SET_BUS(a) i2c_set_bus_num(a) +#ifndef CONFIG_SYS_NUM_I2C_ADAPTERS +#define CONFIG_SYS_NUM_I2C_ADAPTERS 1 +#endif + +#if !defined(CONFIG_SYS_I2C_MAX_HOPS) || (CONFIG_SYS_I2C_MAX_HOPS == 0) +#define CONFIG_SYS_I2C_DIRECT_BUS 1 +#if !defined(CONFIG_SYS_NUM_I2C_BUSSES) || (CONFIG_SYS_NUM_I2C_BUSSES != CONFIG_SYS_NUM_I2C_ADAPTERS) +#define CONFIG_SYS_NUM_I2C_BUSSES CONFIG_SYS_NUM_I2C_ADAPTERS +#endif #else -#define CONFIG_SYS_MAX_I2C_BUS 1 -#define I2C_GET_BUS() 0 -#define I2C_SET_BUS(a) +#undef CONFIG_SYS_I2C_DIRECT_BUS +#ifndef CONFIG_SYS_NUM_I2C_BUSSES +#define CONFIG_SYS_NUM_I2C_BUSSES 1 +#endif #endif
/* define the I2C bus number for RTC and DTT if not already done */ @@ -67,66 +76,111 @@ #define CONFIG_SYS_SPD_BUS_NUM 0 #endif
-#ifndef I2C_SOFT_DECLARATIONS -# if defined(CONFIG_MPC8260) -# define I2C_SOFT_DECLARATIONS volatile ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, I2C_PORT); -# elif defined(CONFIG_8xx) -# define I2C_SOFT_DECLARATIONS volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; -# else -# define I2C_SOFT_DECLARATIONS -# endif +#ifndef CONFIG_SYS_I2C_DIRECT_BUS +#define ADAP(bus) i2c_adap[i2c_bus[(bus)].adapter] +#else +#define ADAP(bus) i2c_adap[(bus)] #endif
-#ifdef CONFIG_8xx -/* Set default values for the I2C bus speed and slave address on 8xx. In the - * future, we'll define these in all 8xx board config files. - */ -#ifndef CONFIG_SYS_I2C_SPEED -#define CONFIG_SYS_I2C_SPEED 50000 +typedef struct i2c_adapter { + void (*init)(int speed, int slaveaddr); + int (*probe)(u_int8_t chip); + int (*read)(u_int8_t chip, uint addr, int alen, + u_int8_t *buffer, int len); + int (*write)(u_int8_t chip, uint addr, int alen, + u_int8_t *buffer, int len); + uint (*set_bus_speed)(uint speed); + uint (*get_bus_speed)(void); + + int speed; + int slaveaddr; + int init_done; + char *name; +} i2c_adap_t; + + +#ifndef CONFIG_SYS_I2C_DIRECT_BUS +#define I2C_MUX_PCA9540_ID 1 +#define I2C_MUX_PCA9540 {I2C_MUX_PCA9540_ID, "PCA9540B"} +#define I2C_MUX_PCA9542_ID 2 +#define I2C_MUX_PCA9542 {I2C_MUX_PCA9542_ID, "PCA9542A"} +#define I2C_MUX_PCA9544_ID 3 +#define I2C_MUX_PCA9544 {I2C_MUX_PCA9544_ID, "PCA9544A"} +#define I2C_MUX_PCA9547_ID 4 +#define I2C_MUX_PCA9547 {I2C_MUX_PCA9547_ID, "PCA9547A"} + +typedef struct i2c_mux { + int id; + char name[16]; +} i2c_mux_t; + +typedef struct i2c_next_hop { + i2c_mux_t mux; + u_int8_t chip; + u_int8_t channel; +} i2c_next_hop_t; + + +typedef struct i2c_bus_hose { + int adapter; + i2c_next_hop_t next_hop[CONFIG_SYS_I2C_MAX_HOPS]; +} i2c_bus_t; + +#define I2C_NULL_HOP {{-1, ""}, 0, 0} + +extern i2c_bus_t i2c_bus[]; #endif
-#ifndef CONFIG_SYS_I2C_SLAVE -#define CONFIG_SYS_I2C_SLAVE 0xFE -#endif -#endif +extern i2c_adap_t *i2c_adap[];
/* - * Initialization, must be called once on start up, may be called - * repeatedly to change the speed and slave addresses. + * i2c_get_bus_num: + * + * Returns index of currently active I2C bus. Zero-based. */ -void i2c_init(int speed, int slaveaddr); -#ifdef CONFIG_SYS_I2C_INIT_BOARD -void i2c_init_board(void); -#endif +unsigned int i2c_get_bus_num(void);
-#if defined(CONFIG_I2C_MUX)
-typedef struct _mux { - uchar chip; - uchar channel; - char *name; - struct _mux *next; -} I2C_MUX; +/* + * i2c_set_bus_num: + * + * Change the active I2C bus. Subsequent read/write calls will + * go to this one. + * + * bus - bus index, zero based + * + * Returns: 0 on success, not 0 on failure + * + */ +int i2c_set_bus_num(unsigned int bus);
-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_init_bus() + * + * Initialization, must be called once on start up, may be called + * repeatedly to change the speed and slave addresses. This initializes + * a single current i2c bus. + */ +/* void i2c_init_bus(int speed, int slaveaddr); */ + + +/* + * i2c_init_all(): + * + * Initializes all I2C adapters in the system. All i2c_adap structures must + * be initialized beforehead with function pointers and data, including + * speed and slaveaddr. Returns 0 on success, non-0 on failure. + */ +void i2c_init_all(void);
-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. */ -int i2c_probe(uchar chip); +int i2c_probe(u_int8_t chip); +
/* * Read/Write interface: @@ -140,83 +194,25 @@ int i2c_probe(uchar chip); * * Returns: 0 on success, not 0 on failure */ -int i2c_read(uchar chip, uint addr, int alen, uchar *buffer, int len); -int i2c_write(uchar chip, uint addr, int alen, uchar *buffer, int len); +int i2c_read(u_int8_t chip, unsigned int addr, int alen, + u_int8_t *buffer, int len); + +int i2c_write(u_int8_t chip, unsigned int addr, int alen, + u_int8_t *buffer, int len); +
/* * Utility routines to read/write registers. */ -static inline u8 i2c_reg_read(u8 addr, u8 reg) -{ - u8 buf; - -#ifdef CONFIG_8xx - /* MPC8xx needs this. Maybe one day we can get rid of it. */ - i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); -#endif - -#ifdef DEBUG - printf("%s: addr=0x%02x, reg=0x%02x\n", __func__, addr, reg); -#endif - -#ifdef CONFIG_BLACKFIN - /* This ifdef will become unneccessary in a future version of the - * blackfin I2C driver. - */ - i2c_read(addr, reg, 0, &buf, 1); -#else - i2c_read(addr, reg, 1, &buf, 1); -#endif - - return buf; -} +u_int8_t i2c_reg_read(u_int8_t addr, u_int8_t reg);
-static inline void i2c_reg_write(u8 addr, u8 reg, u8 val) -{ -#ifdef CONFIG_8xx - /* MPC8xx needs this. Maybe one day we can get rid of it. */ - i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); -#endif +void i2c_reg_write(u_int8_t addr, u_int8_t reg, u_int8_t val);
-#ifdef DEBUG - printf("%s: addr=0x%02x, reg=0x%02x, val=0x%02x\n", - __func__, addr, reg, val); -#endif - -#ifdef CONFIG_BLACKFIN - /* This ifdef will become unneccessary in a future version of the - * blackfin I2C driver. - */ - i2c_write(addr, reg, 0, &val, 1); -#else - i2c_write(addr, reg, 1, &val, 1); -#endif -}
/* * Functions for setting the current I2C bus and its speed */
-/* - * i2c_set_bus_num: - * - * Change the active I2C bus. Subsequent read/write calls will - * go to this one. - * - * bus - bus index, zero based - * - * Returns: 0 on success, not 0 on failure - * - */ -int i2c_set_bus_num(unsigned int bus); - -/* - * i2c_get_bus_num: - * - * Returns index of currently active I2C bus. Zero-based. - */ - -unsigned int i2c_get_bus_num(void);
/* * i2c_set_bus_speed: @@ -225,10 +221,10 @@ unsigned int i2c_get_bus_num(void); * * speed - bus speed in Hz * - * Returns: 0 on success, not 0 on failure + * Returns: new bus speed * */ -int i2c_set_bus_speed(unsigned int); +unsigned int i2c_set_bus_speed(unsigned int speed);
/* * i2c_get_bus_speed: @@ -238,4 +234,45 @@ int i2c_set_bus_speed(unsigned int);
unsigned int i2c_get_bus_speed(void);
+/* + * i2c_reloc_fixup: + * + * Adjusts I2C pointers after U-Boot is relocated to DRAM + */ +void i2c_reloc_fixup(void); + +#ifndef I2C_SOFT_DEFS +# if defined(CONFIG_MPC8260) +# define I2C_SOFT_DEFS volatile ioport_t *iop = ioport_addr((immap_t *)CONFIG_SYS_IMMR, I2C_PORT); +# elif defined(CONFIG_8xx) +# define I2C_SOFT_DEFS volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; +# else +# define I2C_SOFT_DEFS +# endif + +#if 0 +# ifdef CONFIG_8xx +/* Set default values for the I2C bus speed and slave address on 8xx. In the + * future, we'll define these in all 8xx board config files. + */ +# ifndef CONFIG_SYS_I2C_SPEED +# define CONFIG_SYS_I2C_SPEED 50000 +# endif + +# ifndef CONFIG_SYS_I2C_SLAVE +# define CONFIG_SYS_I2C_SLAVE 0xFE +# endif +# endif +#endif +#endif + +/* + * Initialization, must be called once on start up, may be called + * repeatedly to change the speed and slave addresses. + */ +void i2c_init(unsigned int speed, int slaveaddr); +#ifdef CONFIG_SYS_I2C_INIT_BOARD +void i2c_init_board(void); +#endif + #endif /* _I2C_H_ */ diff --git a/lib_arm/board.c b/lib_arm/board.c index 964f5cc..2cd7334 100644 --- a/lib_arm/board.c +++ b/lib_arm/board.c @@ -81,7 +81,8 @@ extern void rtl8019_get_enetaddr (uchar * addr); #endif
#if defined(CONFIG_HARD_I2C) || \ - defined(CONFIG_SOFT_I2C) + defined(CONFIG_SOFT_I2C) || \ + defined(CONFIG_SYS_I2C_ADAPTERS) #include <i2c.h> #endif
@@ -211,11 +212,15 @@ static void display_flash_config (ulong size) } #endif /* CONFIG_SYS_NO_FLASH */
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) static int init_func_i2c (void) { puts ("I2C: "); +#ifdef CONFIG_NEW_I2C + i2c_init_all(); +#else i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); +#endif puts ("ready\n"); return (0); } @@ -272,7 +277,7 @@ init_fnc_t *init_sequence[] = { #if defined(CONFIG_DISPLAY_BOARDINFO) checkboard, /* display board info */ #endif -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) init_func_i2c, #endif dram_init, /* configure available RAM banks */ @@ -368,6 +373,10 @@ void start_armboot (void) /* initialize environment */ env_relocate ();
+#if defined(CONFIG_NEW_I2C) && defined(CONFIG_SYS_I2C_ADAPTERS) + i2c_reloc_fixup(); +#endif + #ifdef CONFIG_VFD /* must do this after the framebuffer is allocated */ drv_vfd_init(); diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c index c223711..d0e7120 100644 --- a/lib_blackfin/board.c +++ b/lib_blackfin/board.c @@ -31,6 +31,10 @@ int post_flag; #endif
+#if defined(CONFIG_SYS_I2C_ADAPTERS) +#include <i2c.h> +#endif + DECLARE_GLOBAL_DATA_PTR;
const char version_string[] = U_BOOT_VERSION " ("U_BOOT_DATE" - "U_BOOT_TIME")"; @@ -338,6 +342,10 @@ void board_init_r(gd_t * id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate();
+#if defined(CONFIG_SYS_I2C_ADAPTERS) + i2c_reloc_fixup(); +#endif + #ifdef CONFIG_CMD_NET /* board MAC address */ s = getenv("ethaddr"); diff --git a/lib_m68k/board.c b/lib_m68k/board.c index 583ce10..23f01a4 100644 --- a/lib_m68k/board.c +++ b/lib_m68k/board.c @@ -55,7 +55,8 @@ #include <version.h>
#if defined(CONFIG_HARD_I2C) || \ - defined(CONFIG_SOFT_I2C) + defined(CONFIG_SOFT_I2C) || \ + defined(CONFIG_SYS_I2C_ADAPTERS) #include <i2c.h> #endif
@@ -191,11 +192,15 @@ static int init_func_ram (void)
/***********************************************************************/
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) static int init_func_i2c (void) { puts ("I2C: "); +#ifdef CONFIG_NEW_I2C + i2c_init_all(); +#else i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); +#endif puts ("ready\n"); return (0); } @@ -227,7 +232,7 @@ init_fnc_t *init_sequence[] = { display_options, checkcpu, checkboard, -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) init_func_i2c, #endif #if defined(CONFIG_HARD_SPI) @@ -577,6 +582,11 @@ void board_init_r (gd_t *id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate ();
+#if defined(CONFIG_NEW_I2C) && defined(CONFIG_SYS_I2C_ADAPTERS) + /* Adjust I2C subsystem pointers after relocation */ + i2c_reloc_fixup(); +#endif + /* * Fill in missing fields of bd_info. * We do this here, where we have "normal" access to the diff --git a/lib_mips/board.c b/lib_mips/board.c index dfe6831..60ebaa9 100644 --- a/lib_mips/board.c +++ b/lib_mips/board.c @@ -33,6 +33,10 @@ #include <onenand_uboot.h> #include <spi.h>
+#if defined(CONFIG_SYS_I2C_ADAPTERS) +#include <i2c.h> +#endif + DECLARE_GLOBAL_DATA_PTR;
#if ( ((CONFIG_ENV_ADDR+CONFIG_ENV_SIZE) < CONFIG_SYS_MONITOR_BASE) || \ @@ -401,6 +405,10 @@ void board_init_r (gd_t *id, ulong dest_addr) /* relocate environment function pointers etc. */ env_relocate();
+#if defined(CONFIG_SYS_I2C_ADAPTERS) + i2c_reloc_fixup(); +#endif + /* board MAC address */ s = getenv ("ethaddr"); for (i = 0; i < 6; ++i) { diff --git a/lib_ppc/board.c b/lib_ppc/board.c index df1cf13..02aff5e 100644 --- a/lib_ppc/board.c +++ b/lib_ppc/board.c @@ -88,7 +88,8 @@ extern void sc3_read_eeprom(void); void doc_init (void); #endif #if defined(CONFIG_HARD_I2C) || \ - defined(CONFIG_SOFT_I2C) + defined(CONFIG_SOFT_I2C) || \ + defined(CONFIG_SYS_I2C_ADAPTERS) #include <i2c.h> #endif #include <spi.h> @@ -231,11 +232,15 @@ static int init_func_ram (void)
/***********************************************************************/
-#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) static int init_func_i2c (void) { puts ("I2C: "); +#ifdef CONFIG_NEW_I2C + i2c_init_all(); +#else i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); +#endif puts ("ready\n"); return (0); } @@ -330,7 +335,7 @@ init_fnc_t *init_sequence[] = { misc_init_f, #endif INIT_FUNC_WATCHDOG_RESET -#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) +#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) || defined(CONFIG_SYS_I2C_ADAPTERS) init_func_i2c, #endif #if defined(CONFIG_HARD_SPI) @@ -850,6 +855,11 @@ void board_init_r (gd_t *id, ulong dest_addr) * the environment is in EEPROM. */
+#if defined(CONFIG_NEW_I2C) && defined(CONFIG_SYS_I2C_ADAPTERS) + /* Adjust I2C subsystem pointers after relocation */ + i2c_reloc_fixup(); +#endif + #if defined(CONFIG_SYS_EXTBDINFO) #if defined(CONFIG_405GP) || defined(CONFIG_405EP) #if defined(CONFIG_I2CFAST)