閱讀Linux的ov2655的驅動程序時,並沒有發現I2C驅動的初始化函數i2c_add_driver,只是定義了
static struct v4l2_i2c_driver_data v4l2_i2c_data =
{
.name = S5K4BA_DRIVER_NAME,
.probe = ov2655_probe,
.remove = __devexit_p(ov2655_remove),
.id_table = ov2655_id,
};
其實相關I2C初始化函數在v4l2-i2c-drv.h裡
I2C攝像頭驅動程序都會包含該文件
#include <media/v4l2-i2c-drv.h>
該文件代碼很簡單,I2C驅動初始化如下:
static int __init v4l2_i2c_drv_init(void)
{
//其中的v4l2_i2c_data就是前面提到的在ov2655驅動裡定義結構體。
v4l2_i2c_driver.driver.name = v4l2_i2c_data.name;
v4l2_i2c_driver.command = v4l2_i2c_data.command;
v4l2_i2c_driver.probe = v4l2_i2c_data.probe;
v4l2_i2c_driver.remove = v4l2_i2c_data.remove;
v4l2_i2c_driver.suspend = v4l2_i2c_data.suspend;
v4l2_i2c_driver.resume = v4l2_i2c_data.resume;
v4l2_i2c_driver.id_table = v4l2_i2c_data.id_table;
return i2c_add_driver(&v4l2_i2c_driver);
}
static void __exit v4l2_i2c_drv_cleanup(void)
{
i2c_del_driver(&v4l2_i2c_driver);
}
module_init(v4l2_i2c_drv_init);
module_exit(v4l2_i2c_drv_cleanup);