How to load a camera module in kernel space

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值