]> git.sur5r.net Git - u-boot/blobdiff - drivers/i2c/mxc_i2c.c
EXYNOS: Resolve the i2c compilation error
[u-boot] / drivers / i2c / mxc_i2c.c
index ead6e209b25441d9d2422c68d14a3aa64f03f89a..a73b10b9c49f662c167276f3d97abcc7517e75dd 100644 (file)
@@ -98,7 +98,7 @@ static uint8_t i2c_imx_get_clk(unsigned int rate)
 #endif
 
        /* Divider value calculation */
-       i2c_clk_rate = mxc_get_clock(MXC_IPG_PERCLK);
+       i2c_clk_rate = mxc_get_clock(MXC_I2C_CLK);
        div = (i2c_clk_rate + rate - 1) / rate;
        if (div < i2c_clk_div[0][0])
                clk_div = 0;
@@ -115,7 +115,7 @@ static uint8_t i2c_imx_get_clk(unsigned int rate)
 /*
  * Set I2C Bus speed
  */
-int bus_i2c_set_bus_speed(void *base, int speed)
+static int bus_i2c_set_bus_speed(void *base, int speed)
 {
        struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)base;
        u8 clk_idx = i2c_imx_get_clk(speed);
@@ -133,7 +133,7 @@ int bus_i2c_set_bus_speed(void *base, int speed)
 /*
  * Get I2C Speed
  */
-unsigned int bus_i2c_get_bus_speed(void *base)
+static unsigned int bus_i2c_get_bus_speed(void *base)
 {
        struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)base;
        u8 clk_idx = readb(&i2c_regs->ifdr);
@@ -142,7 +142,7 @@ unsigned int bus_i2c_get_bus_speed(void *base)
        for (clk_div = 0; i2c_clk_div[clk_div][1] != clk_idx; clk_div++)
                ;
 
-       return mxc_get_clock(MXC_IPG_PERCLK) / i2c_clk_div[clk_div][0];
+       return mxc_get_clock(MXC_I2C_CLK) / i2c_clk_div[clk_div][0];
 }
 
 #define ST_BUS_IDLE (0 | (I2SR_IBB << 8))
@@ -251,6 +251,8 @@ static int i2c_init_transfer_(struct mxc_i2c_regs *i2c_regs,
        return 0;
 }
 
+static int i2c_idle_bus(void *base);
+
 static int i2c_init_transfer(struct mxc_i2c_regs *i2c_regs,
                uchar chip, uint addr, int alen)
 {
@@ -269,6 +271,8 @@ static int i2c_init_transfer(struct mxc_i2c_regs *i2c_regs,
                if (ret != -ERESTART)
                        writeb(0, &i2c_regs->i2cr);     /* Disable controller */
                udelay(100);
+               if (i2c_idle_bus(i2c_regs) < 0)
+                       break;
        }
        printf("%s: give up i2c_regs=%p\n", __func__, i2c_regs);
        return ret;
@@ -390,6 +394,45 @@ void *get_base(void)
 #endif
 }
 
+static struct i2c_parms *i2c_get_parms(void *base)
+{
+       int i = 0;
+       struct i2c_parms *p = srdata.i2c_data;
+       while (i < ARRAY_SIZE(srdata.i2c_data)) {
+               if (p->base == base)
+                       return p;
+               p++;
+               i++;
+       }
+       printf("Invalid I2C base: %p\n", base);
+       return NULL;
+}
+
+static int i2c_idle_bus(void *base)
+{
+       struct i2c_parms *p = i2c_get_parms(base);
+       if (p && p->idle_bus_fn)
+               return p->idle_bus_fn(p->idle_bus_data);
+       return 0;
+}
+
+#ifdef CONFIG_I2C_MULTI_BUS
+unsigned int i2c_get_bus_num(void)
+{
+       return srdata.curr_i2c_bus;
+}
+
+int i2c_set_bus_num(unsigned bus_idx)
+{
+       if (bus_idx >= ARRAY_SIZE(srdata.i2c_data))
+               return -1;
+       if (!srdata.i2c_data[bus_idx].base)
+               return -1;
+       srdata.curr_i2c_bus = bus_idx;
+       return 0;
+}
+#endif
+
 int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len)
 {
        return bus_i2c_read(get_base(), chip, addr, alen, buf, len);