jackyard 发表于 2012-07-26 20:15

powerpc下I2C的问题?

所有的powerpc 的I2C适配器驱动都在/driver/i2c/busses/I2c-mpc.c文件中。
适配器的驱动是of_platform_driver,
/* Structure for a device driver */
static struct of_platform_driver mpc_i2c_driver = {
        .match_table        = mpc_i2c_of_match,
        .probe                = fsl_i2c_probe,
        .remove                = __devexit_p(fsl_i2c_remove),
        .driver                = {
                .owner        = THIS_MODULE,
                .name        = DRV_NAME,//mpc-i2c
        },
};
在这里我们看一下of_platform_bus_type,
struct bus_type of_platform_bus_type = {
       .uevent        = of_device_uevent,
};
可以看到,这里没有match方法。
module_init(fsl_i2c_init) -> fsl_i2c_init -> of_register_platform_driver(&mpc_i2c_driver)
在这里会调用of_platform总线的match函数of_platform_bus_match去做设备和驱动的匹配,
of_platform_bus_match函数在比较了驱动的match-table和设备node中的相关字段后( compatible = "fsl-i2c" ),若匹配,进入fsl_i2c_probe。但是我们看到在这里of_platform总线的结构体里没有match方法。是不是在注册适配器的时候是不要match设备的名子的?

zhuqing_739 发表于 2013-01-18 14:03

想问struct bus_type of_platform_bus_type = {
       .uevent      = of_device_uevent,
};
这里的uevent什么时候调用?

jackyard 发表于 2013-01-18 19:06

这是platform_bus 下的uevent函数,是在产生事件时才会调用。如在调用device_add函数时,在调用kobject_uevent(&dev->kobj, KOBJ_ADD)时会产生一个事件,这个函数中会调用相应的kset_uevent_ops的uevent函数,这里即为dev_uevent(),看一下这个函数的代码片段:
static int dev_uevent(struct kset *kset, struct kobject *kobj, struct kobj_uevent_env *env)
{
..............................

       /* have the bus specific function add its stuff */

       if (dev->bus && dev->bus->uevent) {

            retval = dev->bus->uevent(dev, env);

            if (retval)

                     pr_debug("device: '%s': %s: bus uevent() returned %d\n",

                           dev_name(dev), __func__, retval);

       }
.........................
}

从这里看到如果bus->uevent()函数存在则会调用它。也就是调用of_device_uevent.
页: [1]
查看完整版本: powerpc下I2C的问题?