armv7: add reset timeout to identify_nand_chip
[oweals/u-boot.git] / arch / arm / imx-common / i2c-mxv7.c
index 70cff5cc8d3a8865bcc7cc4ded88590e11c37c3e..ff72b1a1fc8101984ae50ea39a46a5dc342a04fe 100644 (file)
@@ -4,6 +4,7 @@
  * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
+#include <malloc.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/errno.h>
@@ -11,7 +12,7 @@
 #include <asm/imx-common/mxc_i2c.h>
 #include <watchdog.h>
 
-static int force_idle_bus(void *priv)
+int force_idle_bus(void *priv)
 {
        int i;
        int sda, scl;
@@ -66,16 +67,31 @@ static void * const i2c_bases[] = {
 #ifdef I2C3_BASE_ADDR
        (void *)I2C3_BASE_ADDR,
 #endif
+#ifdef I2C4_BASE_ADDR
+       (void *)I2C4_BASE_ADDR,
+#endif
 };
 
-/* i2c_index can be from 0 - 2 */
+/* i2c_index can be from 0 - 3 */
 int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
              struct i2c_pads_info *p)
 {
+       char name[9];
        int ret;
 
        if (i2c_index >= ARRAY_SIZE(i2c_bases))
                return -EINVAL;
+
+       snprintf(name, sizeof(name), "i2c_sda%01d", i2c_index);
+       ret = gpio_request(p->sda.gp, name);
+       if (ret)
+               return ret;
+
+       snprintf(name, sizeof(name), "i2c_scl%01d", i2c_index);
+       ret = gpio_request(p->scl.gp, name);
+       if (ret)
+               goto err_req;
+
        /* Enable i2c clock */
        ret = enable_i2c_clk(1, i2c_index);
        if (ret)
@@ -86,12 +102,17 @@ int setup_i2c(unsigned i2c_index, int speed, int slave_addr,
        if (ret)
                goto err_idle;
 
-       bus_i2c_init(i2c_bases[i2c_index], speed, slave_addr,
-                       force_idle_bus, p);
+#ifndef CONFIG_DM_I2C
+       bus_i2c_init(i2c_index, speed, slave_addr, force_idle_bus, p);
+#endif
 
        return 0;
 
 err_idle:
 err_clk:
+       gpio_free(p->scl.gp);
+err_req:
+       gpio_free(p->sda.gp);
+
        return ret;
 }