手机版
你好,游客 登录 注册
背景:
阅读新闻

Linux PowerPC I2C驱动 之 I2C设备层的注册过程

[日期:2011-08-19] 来源:Linux社区  作者:lickylin [字体:大 中 小]

在really_probe()里,首先将drv赋值给dev->driver,然后会调用总线的probe函数,在i2c驱动里,

此时将会调用i2c总线的probe函数:i2c_device_probe

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

{

int ret = 0;

atomic_inc(&probe_count);

pr_debug("bus: '%s': %s: probing driver %s with device %s\n",

 drv->bus->name, __func__, drv->name, dev_name(dev));

WARN_ON(!list_empty(&dev->devres_head));

dev->driver = drv;

if (driver_sysfs_add(dev)) {

printk(KERN_ERR "%s: driver_sysfs_add(%s) failed\n",

__func__, dev_name(dev));

goto probe_failed;

}

if (dev->bus->probe) {//此处调用i2c总线的probe函数

ret = dev->bus->probe(dev);

if (ret)

goto probe_failed;

} else if (drv->probe) {

ret = drv->probe(dev);

if (ret)

goto probe_failed;

}

driver_bound(dev);

ret = 1;

pr_debug("bus: '%s': %s: bound device %s to driver %s\n",

 drv->bus->name, __func__, dev_name(dev), drv->name);

goto done;

probe_failed:

devres_release_all(dev);

driver_sysfs_remove(dev);

dev->driver = NULL;

if (ret != -ENODEV && ret != -ENXIO) {

/* driver matched but the probe failed */

printk(KERN_WARNING

       "%s: probe of %s failed with error %d\n",

       drv->name, dev_name(dev), ret);

}

/*

 * Ignore errors returned by ->probe so that the next driver can try

 * its luck.

 */

ret = 0;

done:

atomic_dec(&probe_count);

wake_up(&probe_waitqueue);

return ret;

}

在i2c_device_probe()里,会根据to_i2c_driver(dev->driver)获取i2c驱动,也就是我们编写的具体的i2c设备驱动的结构体i2c_driver,即

static struct i2c_driver XXX_driver = {

.driver = {

.name = "XXXX_name",

.owner = THIS_MODULE,

},

.probe = XXX_probe,

.remove = XXX_remove,

.id_table = XXX_id,

};

这样就调用了我们驱动的probe()了,这就是我们在驱动里调用i2c_add_driver(),通过driver_register()的一系列调用,最后执行我们所写的probe()

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));//执行我们写的probe函数

if (status)

client->driver = NULL;

return status;

}

linux
相关资讯       Linux驱动  PowerPC 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款