Camera驅(qū)動(dòng)分析
Linux版本:4.19
Sensor: OV13850
(1)裝載和卸載函數(shù)
//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接口進(jìn)行控制,所以使用i2c_driver進(jìn)行注冊(cè)。
(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); //填充時(shí)序信息
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;
}
上面主要是根據(jù)全局變量ov13850_custom_config中的信息填充時(shí)序信息。然后初始化v4l2_subdev, ov13850是I2C接口,所以使用v4l2_i2c_subdev_init 進(jìn)行初始化。v4l2_i2c_subdev_init就是對(duì)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開始輸出數(shù)據(jù)流
.stop_streaming = ov13850_stop_streaming, //sensor停止輸出數(shù)據(jù)流
.s_ctrl = ov13850_s_ctrl,
.s_ext_ctrls = ov13850_s_ext_ctrls, //sensor控制(設(shè)置自動(dòng)曝光控制)
.g_ctrl = ov13850_g_ctrl,
.g_timings = ov13850_g_timings, //獲取sensor時(shí)序
.check_camera_id = ov13850_check_camera_id, //讀取Sensor ID
.s_vts = ov13850_auto_adjust_fps, //自動(dòng)調(diào)節(jié)刷新率
.set_flip = ov13850_set_flip, //設(shè)置sensor鏡像
#ifdef OV13850_ONE_LANE
.configs = ov13850_onelane_configs, //單lane的配置信息(分辨率,刷新率等)
.num_configs = ARRAY_SIZE(ov13850_onelane_configs),
#else
.configs = ov13850_configs, //多l(xiāng)ane的配置信息
.num_configs = ARRAY_SIZE(ov13850_configs),
#endif
.power_up_delays_ms = {5, 20, 0},
/*
*0: Exposure time valid fileds; 曝光時(shí)間
*1: Exposure gain valid fileds; 曝光增益
*(2 fileds == 1 frames)
*/
.exposure_valid_frame = {4, 4}
};
上面設(shè)置的回調(diào)基本都是去設(shè)置寄存器。
(3)打開數(shù)據(jù)流
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;
}
主要就是操作寄存器,開啟數(shù)據(jù)流傳輸。其他的一些操作函數(shù)也基本類似。
總結(jié)
我們從上面的內(nèi)容中可以看出,sensor端的驅(qū)動(dòng)沒有特別復(fù)雜,主要是一些參數(shù)和控制相關(guān)的內(nèi)容。sensor主要是生產(chǎn)數(shù)據(jù),而數(shù)據(jù)的處理主要交給ISP。
審核編輯:劉清
-
Linux
+關(guān)注
關(guān)注
87文章
11232瀏覽量
208938 -
LINUX內(nèi)核
+關(guān)注
關(guān)注
1文章
316瀏覽量
21619 -
I2C接口
+關(guān)注
關(guān)注
1文章
124瀏覽量
25141 -
OV13850
+關(guān)注
關(guān)注
0文章
2瀏覽量
2321
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論