您的位置:首页 > 其它

How to load a camera module in kernel space

2014-09-25 19:42 253 查看
Loading sensor structure from kernel space, it is more familiar than loading from user space, first, we define the sensor’s related information in corresponding dtsi file, notice that “compatible” segment
is important, see the following sample,

qcom,camera@26 {

compatible = "qcom,imx214_R";

reg = <0x26>;

qcom,slave-id = <0x34 0x0016 0x0214>;

qcom,csiphy-sd-index = <1>;

qcom,csid-sd-index = <1>;

qcom,mount-angle = <90>;

qcom,sensor-name = "imx214_R";

qcom,actuator-src = <&actuator0>;

The section define a lot of fields, like i2c address, sensor-name, etc.

Turn to imx214_R.c, “imx214_R_platform_probe” function will be triggered by openfirmware function because the driver’s “compatible” field is the same as definition in the dtsi file. Then “msm_sensor_platform_probe”
function in msm_sensor.c will be called.

match = of_match_device(imx214_R_dt_match, &pdev->dev);

rc = msm_sensor_platform_probe(pdev, match->data);

Here we can get all the parameters through “msm_sensor_get_dt_data” function.

if (pdev->dev.of_node) {

rc = msm_sensor_get_dt_data(pdev->dev.of_node, s_ctrl);

assign function pointer for later use, so that user space can get all information it need through “msm_sensor_config” function.

if (!s_ctrl->func_tbl)

s_ctrl->func_tbl = &msm_sensor_func_tbl;

Power up sensor,

rc = s_ctrl->func_tbl->sensor_power_up(s_ctrl);

then initialize all the components of “s_ctrl”, finally create V4L2 node for user space.

How to modify for other sensor, for instance, changing one sensor to ov13850?

Modify dtsi file firstly,

//compatible = "qcom,imx214_R";

compatible = "qcom,ov13850";

// qcom,sensor-name = "imx214_R";

qcom,sensor-name = "ov13850"

Open imx214_R.c, change dt_match name to “ov13850”,

static const struct of_device_id imx214_R_dt_match[] = {

//{.compatible = "qcom,imx214_R", .data = &imx214_R_s_ctrl},

{.compatible = "qcom,ov13850", .data = &imx214_R_s_ctrl},

Open imx214_R_lib.c, modify function name from “imx214_R_open_lib” to “ov13850_open_lib”

//void* imx214_R_open_lib(void) {

void* ov13850_open_lib(void) {

return &sensor_lib_ptr;

}

Modify some dual camera related codes, see below,

In “msm_sensor_power_down” function,

if(!strcmp(s_ctrl->sensordata->sensor_name,"imx214_R")||!strcmp(s_ctrl->sensordata->sensor_name,"ov13850"))

{

camera_power_flag = (camera_power_flag&(~CAMERA0_UP))& CAMERA_FLAG_MASK ;

printk("[YLMJ]power_downimx214_R camera_power_flag is %d\n ",camera_power_flag);

}

In “msm_sensor_power_up” function,

if(!strcmp(sensor_name,"imx214_R")||!strcmp(s_ctrl->sensordata->sensor_name,"ov13850"))

{

camera_power_flag = (camera_power_flag&CAMERA_FLAG_MASK)|CAMERA0_UP;

printk("[YLMJ]imx214_R camera_power_flag is %d\n ",camera_power_flag);

}

After compiling imx214_R_lib.c, manually change the library name from “libmmcamera_imx214_R.so” to “libmmcamera_ov13850.so” and push it to “/system/vendor/lib” directory through ADB. Remember that it’s just
a test for understanding the camera work flow, if you want to modify completely, please take more effort to modify the whole code, including but not limited to sensor register/make file/ android.mk/ other names.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: