i2c initialization in U-Boot for i.MX6Solo

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i2c initialization in U-Boot for i.MX6Solo

Jump to solution
1,957 Views
abhishek25jun
Contributor I

Hello,

In continuation of Interface setup in U-Boot for i.Mx6Solo 

We want to initialize all 4 i2c buses of i.MX6Solo in U-Boot for our custom board.

We are using imx6qsabreauto as reference board.

The initialization of i2c2 and i2c3 is done in imx6qsabreauto as follows.

/* I2C2 PMIC, iPod, Tuner, Codec, Touch, HDMI EDID, MIPI CSI2 card */
 static struct i2c_pads_info i2c_pad_info1 = {
        .scl = {
                  .i2c_mode = MX6_PAD_EIM_EB2__I2C2_SCL | PC,
                 .gpio_mode = MX6_PAD_EIM_EB2__GPIO2_IO30 | PC,
                 .gp = IMX_GPIO_NR(2, 30)
         },
         .sda = {
                 .i2c_mode = MX6_PAD_KEY_ROW3__I2C2_SDA | PC,
                 .gpio_mode = MX6_PAD_KEY_ROW3__GPIO4_IO13 | PC,
                 .gp = IMX_GPIO_NR(4, 13)
         }
};
 
#ifndef CONFIG_SYS_FLASH_CFI
  /*
   * I2C3 MLB, Port Expanders (A, B, C), Video ADC, Light Sensor,
   * Compass Sensor, Accelerometer, Res Touch
   */
static struct i2c_pads_info i2c_pad_info2 = {
         .scl = {
                 .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC,
                 .gpio_mode = MX6_PAD_GPIO_3__GPIO1_IO03 | PC,
                 .gp = IMX_GPIO_NR(1, 3)
         },
         .sda = {/i2c
                  .i2c_mode = MX6_PAD_EIM_D18__I2C3_SDA | PC,
                 .gpio_mode = MX6_PAD_EIM_D18__GPIO3_IO18 | PC,
                 .gp = IMX_GPIO_NR(3, 18)
          }
};
 #endif

static iomux_v3_cfg_t const i2c3_pads[] = {
          MX6_PAD_EIM_A24__GPIO5_IO04             | MUX_PAD_CTRL(NO_PAD_CTRL),
};
 
static iomux_v3_cfg_t const port_exp[] = {
         MX6_PAD_SD2_DAT0__GPIO1_IO15            | MUX_PAD_CTRL(NO_PAD_CTRL),
};

 

We could not find GPIO2_IO30, GPIO4_IO13, GPIO1_IO03 and GPIO3_IO18  in MX6 Dual lite SABRE AI CPU card schematic. We assume these gpio modes have been implemented in code for future use. Is our understanding correct or do we also need to implement similar .gpio_mode and .gp in our board?

mx6qsabreauto.c also has following stub

static iomux_v3_cfg_t const i2c3_pads[] = {
        MX6_PAD_EIM_A24__GPIO5_IO04             | MUX_PAD_CTRL(NO_PAD_CTRL),
};
 
static iomux_v3_cfg_t const port_exp[] = {
        MX6_PAD_SD2_DAT0__GPIO1_IO15            | MUX_PAD_CTRL(NO_PAD_CTRL),
};

We assume that above code is related to port expander and we do not need to implement it in our board. Kindly confirm if this understanding is correct.

i2c connections in our board are as follows.

EIM_D21 -> I2C1_SCL

EIM_D28 -> I2C1_SDA

EIM_EB2 -> I2C2_SCL

EIM_D16 -> I2C2_SDA

GPIO_3 -> I2C3_SCL

GPIO_6 -> I2C3_SDA

GPIO_7 -> I2C4_SCL

GPIO_8 -> I2C4_SDA

We have implemented following code for i2c in our board file.

static struct i2c_pads_info i2c_pad_info1 = {
    .scl = {
        .i2c_mode = MX6_PAD_EIM_D21__I2C1_SCL | PC,
    },
    .sda = {
        .i2c_mode = MX6_PAD_EIM_D28__I2C1_SDA | PC,
    }
}

static struct i2c_pads_info i2c_pad_info2 = {
    .scl = {
        .i2c_mode = MX6_PAD_EIM_EB2__I2C2_SCL | PC,
    },
    .sda = {
        .i2c_mode = MX6_PAD_EIM_D16__I2C2_SDA | PC,
    }
}

static struct i2c_pads_info i2c_pad_info3 = {
    .scl = {
        .i2c_mode = MX6_PAD_GPIO_3__I2C3_SCL | PC,
    },
    .sda = {
        .i2c_mode = MX6_PAD_GPIO_6__I2C3_SDA | PC,
    }
}

static struct i2c_pads_info i2c_pad_info4 = {
    .scl = {
        .i2c_mode = MX6_PAD_GPIO_7__I2C4_SCL | PC,
    },
    .sda = {
        .i2c_mode = MX6_PAD_GPIO_8__I2C4_SDA | PC,
    }
}

int board_init(void)

{

   ......

   

    setup_i2c(1, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
    setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info2);
    setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3);
    setup_i2c(4, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info4);

.....

}

Kindly confirm if we need to implement anything else for i2c.

Moreover what is the significance of 0x7f as slave address.

Thanks,

Abhishek

Labels (2)
Tags (2)
0 Kudos
1 Solution
1,122 Views
igorpadykov
NXP Employee
NXP Employee

Hi Abhishek 

"gpio_mode" used with CONFIG_SOFT_I2C configures u-boot to use a software
(aka bit-banging) driver instead of hardware support for I2C.
https://casper.berkeley.edu/svn/trunk/roach/sw/uboot/README

So there is no need to implement similar .gpio_mode if i2c hardware is used.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
1 Reply
1,123 Views
igorpadykov
NXP Employee
NXP Employee

Hi Abhishek 

"gpio_mode" used with CONFIG_SOFT_I2C configures u-boot to use a software
(aka bit-banging) driver instead of hardware support for I2C.
https://casper.berkeley.edu/svn/trunk/roach/sw/uboot/README

So there is no need to implement similar .gpio_mode if i2c hardware is used.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos