Chinaunix首页 | 论坛 | 博客
  • 博客访问: 901693
  • 博文数量: 453
  • 博客积分: 7865
  • 博客等级: 少将
  • 技术积分: 5673
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-29 16:21
个人简介

时光荏苒..

文章分类
文章存档

2015年(46)

2014年(22)

2013年(68)

2012年(218)

2011年(99)

分类: LINUX

2012-03-09 17:21:27

内核源代码 Documentation/i2c/upgrading-clients:
new style:
static struct i2c_driver example_driver = {
    .driver     = {
        .owner      = THIS_MODULE,
        .name       = "example",
    },
    .id_table   = example_idtable,
    .probe      = example_probe
,
    .remove     = __devexit_p(example_remove),
    .suspend    = example_suspend,
    .resume     = example_resume,
};
 
old style:
static struct i2c_driver example_driver = {
    .driver     = {
        .owner      = THIS_MODULE,
        .name       = "example",
    },
    .attach_adapter = example_attach_adapter,
    .detach_client  = __devexit_p(example_detach),
    .suspend    = example_suspend,
    .resume     = example_resume,
};
3.1.8 kernel code:
struct i2c_driver {
 unsigned int class;
 /* Notifies the driver that a new bus has appeared or is about to be
  * removed. You should avoid using this if you can, it will probably
  * be removed in a near future.
  */
 int (*attach_adapter)(struct i2c_adapter *);
 int (*detach_adapter)(struct i2c_adapter *);
 /* Standard driver model interfaces */  标准驱动模型 接口
 int (*probe)(struct i2c_client *, const struct i2c_device_id *);
 int (*remove)(struct i2c_client *);
 。。。
 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg);
 struct device_driver driver;
 const struct i2c_device_id *id_table;
 /* Device detection callback for automatic device creation */
 int (*detect)(struct i2c_client *, struct i2c_board_info *);
 const unsigned short *address_list;
 struct list_head clients;
};
 
旧方式:  分析:
Match对应的操作函数为i2c_device_match()()。代码如下

    static int i2c_device_match(struct device *dev, struct device_driver *drv)

    {

    struct i2c_client   *client = to_i2c_client(dev);

    struct i2c_driver   *driver = to_i2c_driver(drv);

    /* make legacy i2c drivers bypass driver model probing entirely;

    * such drivers scan each i2c adapter/bus themselves.

    */

    if (!is_newstyle_driver(driver))

    return 0;

    /* match on an id table if there is one */

    if (driver->id_table)

    return i2c_match_id(driver->id_table, client) != NULL;

    return 0;

    }

    如果该驱动不是一个new-style形式的。或者driver没有定义匹配的id_table.都会匹配失败。

    继续跟踪进i2c_match_id():

    static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id,

    const struct i2c_client *client)

    {

    while (id->name[0]) {

    if (strcmp(client->name, id->name) == 0)

    return id;

    id++;

    }

    return NULL;

    }

    由此可见。如果client的名字和driver->id_table[]中的名称匹配即为成功

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
阅读(681) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~