Linux摄像头I2C驱动初始化

阅读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);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/76e513e5ad69eafcfcf5a46bea8f79ee.html