szlff 发表于 2013-05-26 21:57

刚接触驱动,求教关于I2C的问题

最近看s3c2410的I2c的驱动,master_xfer()函数是如何体现I2C的时序图的呀?求高人解答。

Yan_2013 发表于 2013-05-27 11:22

你需要实现I2C时序?I2C标准接口linux I2C sub-system早就标准化了。不需要我们关心!


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

回头吧,孩子!;P

szlff 发表于 2013-05-27 21:44

学东西不仅要知其然,更要知其所以然。既然想了解某一块的知识,就要完全搞懂,搞透彻。

xfortune 发表于 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);

ptostrike 发表于 2013-05-28 13:48

时序不是硬件会保证的吗?
除非是想用GPIO模拟I2C的操作

geek-linux 发表于 2013-07-08 18:13

硬件保证时序,软件保证操作过程
页: [1]
查看完整版本: 刚接触驱动,求教关于I2C的问题