summaryrefslogtreecommitdiff
path: root/drivers/i2c/fsl_i2c.c
diff options
context:
space:
mode:
authorJerry Huang <Chang-Ming.Huang@freescale.com>2011-10-26 15:29:38 +0000
committerHeiko Schocher <hs@denx.de>2011-11-04 06:21:26 +0100
commitc9a8b25ef9de9368cbe5be80d59c29af8ad40113 (patch)
tree953260f99c0bbb4e25ddf6b7a8d329d4ade3e1ab /drivers/i2c/fsl_i2c.c
parentfec79acc864bed049b6beae719ccbf2bbec5403a (diff)
downloadu-boot-imx-c9a8b25ef9de9368cbe5be80d59c29af8ad40113.zip
u-boot-imx-c9a8b25ef9de9368cbe5be80d59c29af8ad40113.tar.gz
u-boot-imx-c9a8b25ef9de9368cbe5be80d59c29af8ad40113.tar.bz2
Powerpc/i2c: Use the same initialize codes
Make the I2C2 and I2C1 use the same initialize codes. Signed-off-by: Jerry Huang <Chang-Ming.Huang@freescale.com>
Diffstat (limited to 'drivers/i2c/fsl_i2c.c')
-rw-r--r--drivers/i2c/fsl_i2c.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c
index cb13dee..258be0a 100644
--- a/drivers/i2c/fsl_i2c.c
+++ b/drivers/i2c/fsl_i2c.c
@@ -214,11 +214,20 @@ static unsigned int set_i2c_bus_speed(const struct fsl_i2c *dev,
return speed;
}
+unsigned int get_i2c_clock(int bus)
+{
+ if (bus)
+ return gd->i2c2_clk; /* I2C2 clock */
+ else
+ return gd->i2c1_clk; /* I2C1 clock */
+}
+
void
i2c_init(int speed, int slaveadd)
{
struct fsl_i2c *dev;
unsigned int temp;
+ int bus_num, i;
#ifdef CONFIG_SYS_I2C_INIT_BOARD
/* Call board specific i2c bus reset routine before accessing the
@@ -227,29 +236,23 @@ i2c_init(int speed, int slaveadd)
*/
i2c_init_board();
#endif
- dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C_OFFSET);
-
- writeb(0, &dev->cr); /* stop I2C controller */
- udelay(5); /* let it shutdown in peace */
- temp = set_i2c_bus_speed(dev, gd->i2c1_clk, speed);
- if (gd->flags & GD_FLG_RELOC)
- i2c_bus_speed[0] = temp;
- writeb(slaveadd << 1, &dev->adr); /* write slave address */
- writeb(0x0, &dev->sr); /* clear status register */
- writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */
-
-#ifdef CONFIG_SYS_I2C2_OFFSET
- dev = (struct fsl_i2c *) (CONFIG_SYS_IMMR + CONFIG_SYS_I2C2_OFFSET);
-
- writeb(0, &dev->cr); /* stop I2C controller */
- udelay(5); /* let it shutdown in peace */
- temp = set_i2c_bus_speed(dev, gd->i2c2_clk, speed);
- if (gd->flags & GD_FLG_RELOC)
- i2c_bus_speed[1] = temp;
- writeb(slaveadd << 1, &dev->adr); /* write slave address */
- writeb(0x0, &dev->sr); /* clear status register */
- writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */
+#ifdef CONFIG_SYS_I2C2_OFFSET
+ bus_num = 2;
+#else
+ bus_num = 1;
#endif
+ for (i = 0; i < bus_num; i++) {
+ dev = i2c_dev[i];
+
+ writeb(0, &dev->cr); /* stop I2C controller */
+ udelay(5); /* let it shutdown in peace */
+ temp = set_i2c_bus_speed(dev, get_i2c_clock(i), speed);
+ if (gd->flags & GD_FLG_RELOC)
+ i2c_bus_speed[i] = temp;
+ writeb(slaveadd << 1, &dev->adr);/* write slave address */
+ writeb(0x0, &dev->sr); /* clear status register */
+ writeb(I2C_CR_MEN, &dev->cr); /* start I2C controller */
+ }
#ifdef CONFIG_SYS_I2C_BOARD_LATE_INIT
/* Call board specific i2c bus reset routine AFTER the bus has been