summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2011-11-08 00:34:07 +0100
committerWolfgang Denk <wd@denx.de>2011-11-08 00:34:07 +0100
commit36a9a15b7ab251b65a55a87a13d66b7d968e1d77 (patch)
treea3499c616539fcce9e3738b5cc193efe56e9ba26 /drivers
parent7346e385bc2ae30fea75ef00bd56062fefeab2fa (diff)
parentc9a8b25ef9de9368cbe5be80d59c29af8ad40113 (diff)
downloadu-boot-imx-36a9a15b7ab251b65a55a87a13d66b7d968e1d77.zip
u-boot-imx-36a9a15b7ab251b65a55a87a13d66b7d968e1d77.tar.gz
u-boot-imx-36a9a15b7ab251b65a55a87a13d66b7d968e1d77.tar.bz2
Merge branch 'master' of git://git.denx.de/u-boot-i2c
* 'master' of git://git.denx.de/u-boot-i2c: Powerpc/i2c: Use the same initialize codes
Diffstat (limited to 'drivers')
-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