i.MX6DL uboot 中 i2c4 總線配置

i.MX6DL 有四條i2c總線,其中uboot中配置了3條總線,但實際測試只有一條總線(編號爲2)通信正常,其他都有問題,第4條總線在uboot中沒有支持。


由於使用的設備正好在第4條總線上,而且需要在uboot中使用,就研究了一下i.MX6DL uboot 中 i2c4 總線的配置並作一個簡單記錄。


修改的文件:

bootable/bootloader/uboot-imx/arch/arm/imx-common/i2c-mxv7.c

bootable/bootloader/uboot-imx/arch/arm/cpu/armv7/mx6/clock.c

bootable/bootloader/uboot-imx/board/freescale/mx6qsabreauto/mx6qsabreauto.c

bootable/bootloader/uboot-imx/drivers/i2c/mxc_i2c.c


uboot啓動過程中會 調用 setup_i2c 函數配置 i2c 總線。setup_i2c 會調用 enable_i2c_clk 函數,而該函數只配置前3個總線。


在i2c-mxv7.c中先添加i2c4的bases地址:

static void * const i2c_bases[] = {
    (void *)I2C1_BASE_ADDR,
    (void *)I2C2_BASE_ADDR,
#ifdef I2C3_BASE_ADDR
    (void *)I2C3_BASE_ADDR,
#endif
#if defined(CONFIG_MX6DL)
    (void *)I2C4_BASE_ADDR,  //注意定義可能需要 enable CONFIG_MXSX
#endif

};


在 clock.c 中添加如下代碼:

#ifdef CONFIG_MX6DL
int enable_i2c4_clk(unsigned char enable)
{
    u32 reg;
    u32 mask;

    mask = 0x11 << 9;
    reg = __raw_readl(&imx_ccm->CCGR1);
    if (enable)
        reg |= mask;
    else
        reg &= ~mask;
    __raw_writel(reg, &imx_ccm->CCGR1);

    reg = __raw_readl(&imx_ccm->CCGR1);

    return 0;
}
#endif


在enable_i2c_clk函數中添加如下代碼:

    if (i2c_num > 2){
        if(i2c_num == 3){
            enable_i2c4_clk(enable);
            return 0;
        }
        else

            return -EINVAL;
    }


在 mx6qsabreauto.c中添加 i2c_pad_info3 :

struct i2c_pads_info i2c_pad_info3 = {
    .scl = {
        .i2c_mode = MX6_PAD_GPIO_7__I2C4_SCL | PC,
        .gpio_mode = MX6_PAD_GPIO_7__GPIO1_IO07 | PC,
        .gp = IMX_GPIO_NR(1, 7)
    },
    .sda = {
        .i2c_mode = MX6_PAD_GPIO_8__I2C4_SDA | PC,
        .gpio_mode = MX6_PAD_GPIO_8__GPIO1_IO08 | PC,
        .gp = IMX_GPIO_NR(1, 8)
    }
};

在 board_late_init 函數中添加:

    setup_i2c(3, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info3);


在 mxc_i2c.c 中添加:

#ifndef CONFIG_SYS_MXC_I2C4_SPEED
#define CONFIG_SYS_MXC_I2C4_SPEED 100000
#endif

#ifndef CONFIG_SYS_MXC_I2C4_SLAVE
#define CONFIG_SYS_MXC_I2C4_SLAVE 0
#endif

static void * const i2c_bases[] = {
#if defined(CONFIG_MX25)
    (void *)IMX_I2C_BASE,
    (void *)IMX_I2C2_BASE,
    (void *)IMX_I2C3_BASE
#elif defined(CONFIG_MX27)
    (void *)IMX_I2C1_BASE,
    (void *)IMX_I2C2_BASE
#elif defined(CONFIG_MX31) || defined(CONFIG_MX35) || \
    defined(CONFIG_MX51) || defined(CONFIG_MX53) || \
    defined(CONFIG_MX6)
    (void *)I2C1_BASE_ADDR,
    (void *)I2C2_BASE_ADDR,
    (void *)I2C3_BASE_ADDR,
    (void *)I2C4_BASE_ADDR
#elif defined(CONFIG_VF610)
    (void *)I2C0_BASE_ADDR
#else
#error "architecture not supported"
#endif
};


#if defined(CONFIG_MX6DL)
U_BOOT_I2C_ADAP_COMPLETE(mxc3, mxc_i2c_init, mxc_i2c_probe,
                         mxc_i2c_read, mxc_i2c_write,
                         mxc_i2c_set_bus_speed,
                         CONFIG_SYS_MXC_I2C4_SPEED,
                         CONFIG_SYS_MXC_I2C4_SLAVE, 3)
#endif




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章