i2c中i2c_add_driver中的一系列问题

kanwolf 2010-10-12 11:03:56
  static struct i2c_driver pca953x_driver = {

  .driver = {

  .name= "pca953x",

  },

  .probe= pca953x_probe, //当有i2c_client和i2c_driver匹配时调用

  .remove= pca953x_remove,//注销时调用

  .id_table= pca953x_id,//匹配规则

  };
i2c_add_driver()中加的是pca953x_driver类型的结构体指针,请问是当i2c_client->dev.platform_data和pca953x_id匹配的时候才调用pca953x_probe函数吗?pca953x_probe函数是否在设备驱动加载的过程中只调用一次?
假如真的是这样的话i2c_client->dev.platform_data是如何在client初始化的时候赋值的?
pca953x_probe(struct i2c_client *, const struct i2c_device_id *)函数中两个形参又是哪里来的呢?
...全文
2169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lr2131 2011-02-20
  • 打赏
  • 举报
回复
我也问过类似的问题,不过楼上的回答的都很清楚了
yuanlulu 2011-02-16
  • 打赏
  • 举报
回复
问是当i2c_client->dev.platform_data和pca953x_id匹配的时候才调用pca953x_probe函数吗?
=========================================
应该是i2c_driver注册之后,根据Linux驱动模型的driver、device原理,所有已经注册但未绑定i2c_driver的client都将与i2c_driver.id_table进行匹配,匹配成功一次就会调用一次i2c_bus_type的probe方法,也就是i2c_device_probe,从2楼列出的代码可以看出,i2c_device_probe会调用i2c_driver.probe,也就是pca953x_probe.因此pca953x_probe也可能被调用多次.
yuanlulu 2011-02-16
  • 打赏
  • 举报
回复
/* driver/i2c/i2c_core.c */
truct i2c_client *
i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
{
struct i2c_client *client;
int status;

client = kzalloc(sizeof *client, GFP_KERNEL);
if (!client)
return NULL;

client->adapter = adap;

client->dev.platform_data = info->platform_data;

client->flags = info->flags;
client->addr = info->addr;
client->irq = info->irq;

strlcpy(client->name, info->type, sizeof(client->name));

/* a new style driver may be bound to this device when we
* return from this function, or any later moment (e.g. maybe
* hotplugging will load the driver module). and the device
* refcount model is the standard driver model one.
*/
status = i2c_attach_client(client);
if (status < 0) {
kfree(client);
client = NULL;
}
return client;
}
yuanlulu 2011-02-16
  • 打赏
  • 举报
回复
问是当i2c_client->dev.platform_data和pca953x_id匹配的时候才调用pca953x_probe函数吗?
=========================================
应该是i2c_driver注册之后,根据Linux驱动模型的driver、device原理,所有已经注册但未绑定i2c_driver的client都将在i2c_device_probe中与i2c_driver.id_table进行匹配,匹配调用一次i2c_driver.probe,也就是pca953x_probe.因此pca953x_probe也可能被调用多次.
kangwenjiekk 2011-02-15
  • 打赏
  • 举报
回复
very good to deep_pro
deep_pro 2010-10-13
  • 打赏
  • 举报
回复
问是当i2c_client->dev.platform_data和pca953x_id匹配的时候才调用pca953x_probe函数吗?
=========================================
通过查看i2c_device_match() 可以得知比较的是id_table


pca953x_probe函数是否在设备驱动加载的过程中只调用一次
====================
就是一次

i2c_client->dev.platform_data是如何在client初始化的时候赋值的?
==============
不知道你的意思

pca953x_probe(struct i2c_client *, const struct i2c_device_id *)函数中两个形参又是哪里来的呢?
=============================
static int i2c_device_probe(struct device *dev)
{
struct i2c_client *client = i2c_verify_client(dev);
struct i2c_driver *driver;
int status;

if (!client)
return 0;

driver = to_i2c_driver(dev->driver);
if (!driver->probe || !driver->id_table)
return -ENODEV;
client->driver = driver;
if (!device_can_wakeup(&client->dev))
device_init_wakeup(&client->dev,
client->flags & I2C_CLIENT_WAKE);
dev_dbg(dev, "probe\n");

status = driver->probe(client, i2c_match_id(driver->id_table, client));
if (status) {
client->driver = NULL;
i2c_set_clientdata(client, NULL);
}
return status;
}
kanwolf 2010-10-12
  • 打赏
  • 举报
回复
自己先顶下

4,441

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧