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个总线。


扫描二维码关注公众号,回复: 3158338 查看本文章

在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




猜你喜欢

转载自blog.csdn.net/yh2869/article/details/58615241