阅读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 该文件代码很简单,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);
之后调用v4l2_i2c_driver.probe,也就是v4l2_i2c_data.probe,即ov2655_probe。
注册子设备
v4l2_i2c_subdev_init(sd, client, &ov2655_ops);
ov2655_ops包含了操作接口函数的结构体
static const struct v4l2_subdev_core_ops ov2655_core_ops =
{
.init = ov2655_init, /* initializing API */
.s_config = ov2655_s_config, /* Fetch platform data */
.queryctrl = ov2655_queryctrl,
.querymenu = ov2655_querymenu,
.g_ctrl = ov2655_g_ctrl,
.s_ctrl = ov2655_s_ctrl,
};
static const struct v4l2_subdev_video_ops ov2655_video_ops =
{
.g_fmt = ov2655_g_fmt,
.s_fmt = ov2655_s_fmt,
.enum_framesizes = ov2655_enum_framesizes,
.enum_frameintervals = ov2655_enum_frameintervals,
.enum_fmt = ov2655_enum_fmt,
.try_fmt = ov2655_try_fmt,
.g_parm = ov2655_g_parm,
.s_parm = ov2655_s_parm,
};
static const struct v4l2_subdev_ops ov2655_ops =
{
.core = &ov2655_core_ops,
.video = &ov2655_video_ops,
};
最后调用ov2655_init完成摄像头初始化。
阅读(1050) | 评论(0) | 转发(0) |