免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1835 | 回复: 5
打印 上一主题 下一主题

刚接触驱动,求教关于I2C的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-26 21:57 |只看该作者 |倒序浏览
最近看s3c2410的I2c的驱动,master_xfer()函数是如何体现I2C的时序图的呀?求高人解答。

论坛徽章:
0
2 [报告]
发表于 2013-05-27 11:22 |只看该作者
你需要实现I2C时序?I2C标准接口linux I2C sub-system早就标准化了。不需要我们关心!


一般我们需要关心I2C时序应该是i2c设备时序。

回头吧,孩子!

论坛徽章:
0
3 [报告]
发表于 2013-05-27 21:44 |只看该作者
学东西不仅要知其然,更要知其所以然。既然想了解某一块的知识,就要完全搞懂,搞透彻。

论坛徽章:
0
4 [报告]
发表于 2013-05-28 09:19 |只看该作者
回复 3# szlff


    追根求源是好的。但是确实没有去操作时序。而是操作了处理器的硬件i2c寄存器函数如下:
     ret = adap->algo->master_xfer(adap,msgs,num);
   调用的是driver/i2c/bus/i2c-s3c2440.c文件中的
static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
        .master_xfer                = s3c24xx_i2c_xfer,
        .functionality                = s3c24xx_i2c_func,
};

static int s3c24xx_i2c_xfer(struct i2c_adapter *adap,
                        struct i2c_msg *msgs, int num)
{
       ...
        for (retry = 0; retry < adap->retries; retry++) {

                ret = s3c24xx_i2c_doxfer(i2c, msgs, num);

       ...
}
最终则是这个

static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
                                      struct i2c_msg *msg)
{
        unsigned int addr = (msg->addr & 0x7f) << 1;
        unsigned long stat;
        unsigned long iiccon;

        stat = 0;
        stat |=  S3C2410_IICSTAT_TXRXEN;

        if (msg->flags & I2C_M_RD) {
                stat |= S3C2410_IICSTAT_MASTER_RX;
                addr |= 1;
        } else
                stat |= S3C2410_IICSTAT_MASTER_TX;

        if (msg->flags & I2C_M_REV_DIR_ADDR)
                addr ^= 1;

        /* todo - check for wether ack wanted or not */
        s3c24xx_i2c_enable_ack(i2c);

        iiccon = readl(i2c->regs + S3C2410_IICCON);
        writel(stat, i2c->regs + S3C2410_IICSTAT);

        dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
        writeb(addr, i2c->regs + S3C2410_IICDS);

        /* delay here to ensure the data byte has gotten onto the bus
         * before the transaction is started */

        ndelay(i2c->tx_setup);

        dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
        writel(iiccon, i2c->regs + S3C2410_IICCON);

        stat |= S3C2410_IICSTAT_START;
        writel(stat, i2c->regs + S3C2410_IICSTAT);

论坛徽章:
0
5 [报告]
发表于 2013-05-28 13:48 |只看该作者
时序不是硬件会保证的吗?
除非是想用GPIO模拟I2C的操作

论坛徽章:
0
6 [报告]
发表于 2013-07-08 18:13 |只看该作者
硬件保证时序,软件保证操作过程
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP