【问题标题】:Where to find the general definition of i2c "master_xfer" function?在哪里可以找到 i2c“master_xfer”函数的一般定义?
【发布时间】:2013-08-02 02:00:17
【问题描述】:

struct i2c_algorithm 具有用于 i2c 总线实现的 master_xfer 的函数指针模板。我在哪里可以找到linux内核源码中master_xfer的默认函数例程? 请有人指导我..

【问题讨论】:

    标签: linux-kernel linux-device-driver


    【解决方案1】:

    master_xfer 的设置取决于您的平台和总线。在 drivers/i2c/busses/ 下查找该函数指针的设置位置。请注意,它可以设置为 NULL。

    在drivers/i2c/busses/i2c-pxa.c 中设置的一个示例:

    static const struct i2c_algorithm i2c_pxa_algorithm = {
            .master_xfer    = i2c_pxa_xfer,
            .functionality  = i2c_pxa_functionality,
    };
    

    另外看看include/linux/i2c.h:

    struct i2c_algorithm {
            /* If an adapter algorithm can't do I2C-level access, set master_xfer
               to NULL. If an adapter algorithm can do SMBus access, set
               smbus_xfer. If set to NULL, the SMBus protocol is simulated
               using common I2C messages */
            /* master_xfer should return the number of messages successfully
               processed, or a negative value on error */
            int (*master_xfer)(struct i2c_adapter *adap, struct i2c_msg *msgs,
                               int num);
            int (*smbus_xfer) (struct i2c_adapter *adap, u16 addr,
                               unsigned short flags, char read_write,
                               u8 command, int size, union i2c_smbus_data *data);
    
            /* To determine what the adapter supports */
            u32 (*functionality) (struct i2c_adapter *);
    };
    

     * An i2c_msg is the low level representation of one segment of an I2C
     * transaction.  It is visible to drivers in the @i2c_transfer() procedure,
     * to userspace from i2c-dev, and to I2C adapter drivers through the
     * @i2c_adapter.@master_xfer() method.
     *
    

    【讨论】:

    • 感谢您的澄清。很有用...但假设我使用的是 I2c-gpio,请在哪里参考。
    • @kzs 看起来有点敲击 i2c-gpio 接口只使用了 i2c_adapter 结构,而不是 i2c_algorithm。
    • 没有彼得,实际上它确实使用,在同一路径中有 i2c-gpio.c。因为我们正在用 bit_xfer 填充 master_xfer 函数。感谢您的参考。
    【解决方案2】:

    /driver/i2c/busses/ 中有 i2c-gpio.c 文件。我们用bit_xfer 填充master_xfer 函数。它确实有点敲击实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多