S3C2440内核IIC设备驱动建立流程:
由内核打印信息,追索驱动流程:
参考的内核版本为: linux-2.6.22.6
----------------------------------------
内核注册流程:
由打印信息:
1. 先注册 i2c_driver:i2cdev_driver --- \drivers\i2c\i2c-dev.c
前面分析过,内核启动初始化会执行函数:i2c_dev_init
i2c_dev_init(void)
register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops); // 注册字符设备,主设备号为:I2C_MAJOR,应用层统一的操作接口为 i2cdev_fops
i2c_dev_class = class_create(THIS_MODULE, "i2c-dev"); // 构建一个class:i2c_dev_class
i2c_add_driver(&i2cdev_driver);
i2c_register_driver(THIS_MODULE, driver);
driver_register(&driver->driver);
list_add_tail(&driver->list,&drivers); // 这里将 i2cdev_driver 挂接到 drivers 链表上
// 遍历adapters链表中的adapter,调用函数 i2cdev_attach_adapter(adapter)
if (driver->attach_adapter) { // 这里 driver->attach_adapter = i2cdev_attach_adapter
struct i2c_adapter *adapter;
// 在系统初始化的时候,adapters链表上,还没有初始化adapter元素,所以找不到adapter
list_for_each_entry(adapter, &adapters, list) {
driver->attach_adapter(adapter); // 初始化的时候,找不到adapter,所以该句不会执行。
}
}
static struct i2c_driver i2cdev_driver = {
.driver = {
.name = "dev_driver",
},
.id = I2C_DRIVERID_I2CDEV,
.attach_adapter = i2cdev_attach_adapter,
.detach_adapter = i2cdev_detach_adapter,
.detach_client = i2cdev_detach_client,
};
注:
这个代码是linux内核做好的框架,内核启动,就会注册一个i2c字符设备以及类,i2c-driver链表。
并且为这个i2c字符设备提供了统一的应用层的操作接口函数。
打印信息:
i2c /dev entries driver
i2c_dev_init, i2c_add_driver: i2cdev_driver
-------------------------------------------------
2. 然后注册i2c_adapter: s3c24xx_i2c.adap --- \drivers\i2c\busses\i2c-s3c2410.c
注:这里就是针对不同的Soc注册i2c adapter,adapter是针对硬件i2c设备来说的。
在S3C2440中,使用平台总线驱动来注册I2C设备的。
2.1 初始化注册i2c平台设备资源:<