全球最实用的IT互联网信息网站!

AI人工智能P2P分享&下载搜索网页发布信息网站地图

当前位置:诺佳网 > 电子/半导体 > 接口/总线/驱动 >

Linux内核之Camera驱动分析

时间:2022-08-07 16:08

人气:

作者:admin

标签: Linux  I2C接口  OV1  LINUX内核 

导读:上面主要是根据全局变量ov13850_custom_config中的信息填充时序信息。然后初始化v4l2_subdev, ov13850是I2C接口,所以使用v4l2_i2c_subdev_init 进行初始化。...

Camera驱动分析

Linux版本:4.19

Sensor: OV13850

(1)装载和卸载函数

//DTS匹配表
static const struct of_device_id ov13850_of_match[] = {
{.compatible = "omnivision,ov13850-v4l2-i2c-subdev"},
{},
};

MODULE_DEVICE_TABLE(i2c, ov13850_id);

static struct i2c_driver ov13850_i2c_driver = {
.driver = {
.name = ov13850_DRIVER_NAME,
.owner = THIS_MODULE,
.of_match_table = ov13850_of_match
},
.probe = ov13850_probe,
.remove = ov13850_remove,
.id_table = ov13850_id,
};

module_i2c_driver(ov13850_i2c_driver);
OV13850是使用I2C接口进行控制,所以使用i2c_driver进行注册。

(2)probe()

static int ov13850_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
dev_info(&client->dev, "probing...\n");

ov13850_filltimings(&ov13850_custom_config); //填充时序信息
v4l2_i2c_subdev_init(&ov13850.sd, client, &ov13850_camera_module_ops); //初始化v4l2_subdev
ov13850.sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
ov13850.custom = ov13850_custom_config;

mutex_init(&ov13850.lock);
dev_info(&client->dev, "probing successful\n");
return 0;
}
上面主要是根据全局变量ov13850_custom_config中的信息填充时序信息。然后初始化v4l2_subdev, ov13850是I2C接口,所以使用v4l2_i2c_subdev_init 进行初始化。v4l2_i2c_subdev_init就是对v4l2_subdev_init的封装。

//v4l2_subdev_ops
static struct v4l2_subdev_ops ov13850_camera_module_ops = {
.core = &ov13850_camera_module_core_ops, //核心操作
.video = &ov13850_camera_module_video_ops, //video操作
.pad = &ov13850_camera_module_pad_ops
};

static struct ov_camera_module_custom_config ov13850_custom_config = {
.start_streaming = ov13850_start_streaming, //sensor开始输出数据流
.stop_streaming = ov13850_stop_streaming, //sensor停止输出数据流
.s_ctrl = ov13850_s_ctrl,
.s_ext_ctrls = ov13850_s_ext_ctrls, //sensor控制(设置自动曝光控制)
.g_ctrl = ov13850_g_ctrl,
.g_timings = ov13850_g_timings, //获取sensor时序
.check_camera_id = ov13850_check_camera_id, //读取Sensor ID
.s_vts = ov13850_auto_adjust_fps, //自动调节刷新率
.set_flip = ov13850_set_flip, //设置sensor镜像
#ifdef OV13850_ONE_LANE
.configs = ov13850_onelane_configs, //单lane的配置信息(分辨率,刷新率等)
.num_configs = ARRAY_SIZE(ov13850_onelane_configs),

#else
.configs = ov13850_configs, //多lane的配置信息
.num_configs = ARRAY_SIZE(ov13850_configs),
#endif
.power_up_delays_ms = {5, 20, 0},
/*
*0: Exposure time valid fileds; 曝光时间
*1: Exposure gain valid fileds; 曝光增益
*(2 fileds == 1 frames)
*/
.exposure_valid_frame = {4, 4}
};
上面设置的回调基本都是去设置寄存器

(3)打开数据流

static int ov13850_start_streaming(struct ov_camera_module *cam_mod)
{
int ret = 0;

ov_camera_module_pr_debug(cam_mod,
"active config=%s\n", cam_mod->active_config->name);

ret = ov13850_g_VTS(cam_mod, &cam_mod->vts_min);
if (IS_ERR_VALUE(ret))
goto err;

mutex_lock(&cam_mod->lock);
ret = ov_camera_module_write_reg(cam_mod, 0x0100, 1); //写0x0100寄存器, 选择streaming模式 0:standby 1:streaming
mutex_unlock(&cam_mod->lock);
if (IS_ERR_VALUE(ret))
goto err;

msleep(25);

return 0;
err:
ov_camera_module_pr_err(cam_mod, "failed with error (%d)\n",
ret);
return ret;
}
主要就是操作寄存器,开启数据流传输。其他的一些操作函数也基本类似。

总结

我们从上面的内容中可以看出,sensor端的驱动没有特别复杂,主要是一些参数和控制相关的内容。sensor主要是生产数据,而数据的处理主要交给ISP。



审核编辑:刘清

温馨提示:以上内容整理于网络,仅供参考,如果对您有帮助,留下您的阅读感言吧!
相关阅读
本类排行
相关标签
本类推荐

CPU | 内存 | 硬盘 | 显卡 | 显示器 | 主板 | 电源 | 键鼠 | 网站地图

Copyright © 2025-2035 诺佳网 版权所有 备案号:赣ICP备2025066733号
本站资料均来源互联网收集整理,作品版权归作者所有,如果侵犯了您的版权,请跟我们联系。

关注微信