驱动中id_table的分析(Input/I2C)

驱动中id_table的分析

一、I2C驱动probe

***i2c_device_id用于devicedrive配对

static const struct i2c_device_id tps65010_id[] = {

    { "tps65010", TPS65010 },

    { "tps65011", TPS65011 },

    { "tps65012", TPS65012 },

    { "tps65013", TPS65013 },

    { "tps65014", TPS65011 },   /* tps65011 charging at 6.5V max */

    { }

};

MODULE_DEVICE_TABLE(i2c, tps65010_id);

 

static struct i2c_driver tps65010_driver = {

    .driver = {

       .name  = "tps65010",

    },

    .probe = tps65010_probe,  /* bus->match成功后调用 */

    .remove    = __exit_p(tps65010_remove),

    .id_table = tps65010_id,  /* 用于I2C driverprobe函数调用 */

};

 

struct bus_type i2c_bus_type = {

    .name      = "i2c",

    .match     = i2c_device_match,

    .probe     = i2c_device_probe,

    .remove       = i2c_device_remove,

    .shutdown  = i2c_device_shutdown,

    .pm    = &i2c_device_pm_ops,

};

 

int device_add(struct device *dev)-> bus_probe_device(dev)->

device_attach(dev)-> __device_attach->driver_match_device(drv, dev)

 

static inline int driver_match_device(struct device_driver *drv,

                    struct device *dev)

{

    return drv->bus->match ? drv->bus->match(dev, drv) : 1;

}

 

->driver_probe_device->really_probe->dev->bus->probe(dev)

 

二、  input driver probe机制

input driverinput handler配对机制

static struct input_handler evbug_handler = {

    .event =   evbug_event,

    .connect = evbug_connect,

    .disconnect = evbug_disconnect,

    .name =       "evbug",

    .id_table =   evbug_ids,

};

 

static int __init evbug_init(void)

{

    return input_register_handler(&evbug_handler);

}

input_attach_handler(dev, handler)-> input_match_device(handler, dev)-> handler->connect(handler, dev, id)

***handler & input driver连接成功



id_table作用:

先看一下函数定义, 第二个参数为const struct i2c_device_id, id_table作用所在

static int tps65010_probe(struct i2c_client *client,
 const struct i2c_device_id *id)

根据匹配的参数来确定型号

switch (tps->model) {
case TPS65010:
case TPS65012:
tps->por = 1;
break;
/* else CHGCONFIG.POR is replaced by AUA, enabling a WAIT mode */
}


Author : Woodpecker <pecker.hu@gmail.com>

南京 2010-09-25 21:06

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值