X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fi2c%2Fmxc_i2c.c;h=8e10fbb21ca96b207dce0b3660a0e415b2e85a38;hb=1a4106dd207c1e3a20d8cc587822637026d5e196;hp=3c2a9cf180cfaf9b841437ae48ef4bd867f8bf18;hpb=a1b215e2a2a013327693f2fb990957b746f26cf5;p=u-boot diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index 3c2a9cf180..8e10fbb21c 100644 --- a/drivers/i2c/mxc_i2c.c +++ b/drivers/i2c/mxc_i2c.c @@ -24,7 +24,7 @@ #include -#if defined(CONFIG_HARD_I2C) && defined(CONFIG_I2C_MXC) +#if defined(CONFIG_HARD_I2C) #include #include @@ -47,14 +47,17 @@ #define I2SR_IIF (1 << 1) #define I2SR_RX_NO_AK (1 << 0) -#ifdef CFG_I2C_MX31_PORT1 +#ifdef CONFIG_SYS_I2C_MX31_PORT1 #define I2C_BASE 0x43f80000 -#elif defined(CFG_I2C_MX31_PORT2) +#define I2C_CLK_OFFSET 26 +#elif defined (CONFIG_SYS_I2C_MX31_PORT2) #define I2C_BASE 0x43f98000 -#elif defined(CFG_I2C_MX31_PORT3) +#define I2C_CLK_OFFSET 28 +#elif defined (CONFIG_SYS_I2C_MX31_PORT3) #define I2C_BASE 0x43f84000 +#define I2C_CLK_OFFSET 30 #else -#error "define CFG_I2C_MX31_PORTx to use the mx31 I2C driver" +#error "define CONFIG_SYS_I2C_MX31_PORTx to use the mx31 I2C driver" #endif #ifdef DEBUG @@ -64,19 +67,22 @@ #endif static u16 div[] = { 30, 32, 36, 42, 48, 52, 60, 72, 80, 88, 104, 128, 144, - 160, 192, 240, 288, 320, 384, 480, 576, 640, 768, 960, - 1152, 1280, 1536, 1920, 2304, 2560, 3072, 3840}; + 160, 192, 240, 288, 320, 384, 480, 576, 640, 768, 960, + 1152, 1280, 1536, 1920, 2304, 2560, 3072, 3840}; void i2c_init(int speed, int unused) { int freq = mx31_get_ipg_clk(); int i; + /* start the required I2C clock */ + __REG(CCM_CGR0) = __REG(CCM_CGR0) | (3 << I2C_CLK_OFFSET); + for (i = 0; i < 0x1f; i++) if (freq / div[i] <= speed) break; - DPRINTF("%s: speed: %d\n", __FUNCTION__, speed); + DPRINTF("%s: speed: %d\n",__FUNCTION__, speed); __REG16(I2C_BASE + I2CR) = 0; /* Reset module */ __REG16(I2C_BASE + IFDR) = i; @@ -145,22 +151,19 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) int timeout = 10000; int ret; - DPRINTF("%s chip: 0x%02x addr: 0x%04x alen: %d len: +%d\n", \ - __FUNCTION__, chip, addr, alen, len); + DPRINTF("%s chip: 0x%02x addr: 0x%04x alen: %d len: %d\n",__FUNCTION__, chip, addr, alen, len); if (i2c_addr(chip, addr, alen)) { printf("i2c_addr failed\n"); return -1; } - __REG16(I2C_BASE + I2CR) = I2CR_IEN | I2CR_MSTA | \ - I2CR_MTX | I2CR_RSTA; + __REG16(I2C_BASE + I2CR) = I2CR_IEN | I2CR_MSTA | I2CR_MTX | I2CR_RSTA; if (tx_byte(chip << 1 | 1)) return -1; - __REG16(I2C_BASE + I2CR) = I2CR_IEN | I2CR_MSTA | ((len == 1) \ - ? I2CR_TX_NO_AK : 0); + __REG16(I2C_BASE + I2CR) = I2CR_IEN | I2CR_MSTA | ((len == 1) ? I2CR_TX_NO_AK : 0); ret = __REG16(I2C_BASE + I2DR); @@ -169,8 +172,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) return -1; *buf++ = ret; if (len <= 1) - __REG16(I2C_BASE + I2CR) = I2CR_IEN | \ - I2CR_MSTA | I2CR_TX_NO_AK; + __REG16(I2C_BASE + I2CR) = I2CR_IEN | I2CR_MSTA | I2CR_TX_NO_AK; } wait_busy(); @@ -186,8 +188,7 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len) { int timeout = 10000; - DPRINTF("%s chip: 0x%02x addr: 0x%04x alen: %d len: %d\n", \ - __FUNCTION__, chip, addr, alen, len); + DPRINTF("%s chip: 0x%02x addr: 0x%04x alen: %d len: %d\n",__FUNCTION__, chip, addr, alen, len); if (i2c_addr(chip, addr, alen)) return -1;