MTK6735 Android之Camera驱动移植篇

来源:互联网 发布:2016淘宝双11抢红包 编辑:程序博客网 时间:2024/05/05 14:37
首先我们需要向sensor原厂拿到我们对应平台型号的驱动hal层和kernel层的代码。

1.拷贝hal层代码到\vendor\mediatek\proprietary\custom\mt6735\hal\D1\imgsensor\目录下。

2.拷贝kernel层代码到\kernel-3.10\drivers\misc\mediatek\imgsensor\src\mt6735\目录下。

3.添加Sensor_id:\vendor\mediatek\proprietary\custom\mt6735\hal\D1\imgsensor_src\sensorlist.cpp

我的摄像头型号是ov8858这款sensor所以对应应该

[cpp] view plain copy
  1. //800w  
  2. #if defined(OV8858_MIPI_RAW)  
  3.     RAW_INFO(OV8858_SENSOR_ID, SENSOR_DRVNAME_OV8858_MIPI_RAW,NULL),  
  4. #endif  

4.定义ID:\vendor\mediatek\proprietary\custom\common\kernel\imgsensor\inc\kd_imgsensor.h

[plain] view plain copy
  1. #define OV8858_SENSOR_ID                        0x8858  
  2. #define SENSOR_DRVNAME_OV8858_MIPI_RAW          "ov8858mipiraw"  
一般定义ID在这个文件差不多都定义了所以我们也不用去管,但是还是需要去看看

5.定义ID:\kernel-3.10\drivers\misc\mediatek\imgsensor/inc/kd_imgsensor.h和上面一样

6.绑定函数入口:\kernel-3.10\drivers\misc\mediatek\imgsensor\src\mt6735\kd_sensorlist.h

[plain] view plain copy
  1. //800w  
  2. #if defined(OV8858_MIPI_RAW)  
  3.     {OV8858_SENSOR_ID, SENSOR_DRVNAME_OV8858_MIPI_RAW,OV8858_MIPI_RAW_SensorInit},  
  4. #endif  

7./kernel-3.10/drivers/misc/mediatek/mach/mt6735/<project>/camera/camera/目录下
添加摄像头上电时序kd_camera_hw.c:
[cpp] view plain copy
  1. if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW, currSensorName)))  
  2. {  
  3. <span style="white-space:pre">  </span>printk("tangh SENSOR_DRVNAME_OV8858_MIPI_RAW \n ");  
  4.         //First Power Pin low and Reset Pin Low  
  5.         if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMPDN]) {  
  6.         <span style="white-space:pre">  </span>if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! (CMPDN)\n");}  
  7.         <span style="white-space:pre">  </span>if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! (CMPDN)\n");}  
  8.         <span style="white-space:pre">  </span>if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! (CMPDN)\n");}  
  9.         }  
  10.   
  11.         if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {  
  12.                 if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! (CMRST)\n");}  
  13.                 if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! (CMRST)\n");}  
  14.                 if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! (CMRST)\n");}  
  15.             }  
  16.   
  17.             //VCAM_IO  
  18.             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_IO, VOL_1800, mode_name))  
  19.             {  
  20.                 PK_DBG("[CAMERA SENSOR] Fail to enable digital power (VCAM_IO), power id = %d \n", CAMERA_POWER_VCAM_IO);  
  21.                 goto _kdCISModulePowerOn_exit_;  
  22.             }  
  23.   
  24.             //VCAM_A  
  25.             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name))  
  26.             {  
  27.                 PK_DBG("[CAMERA SENSOR] Fail to enable analog power (VCAM_A), power id = %d\n", CAMERA_POWER_VCAM_A);  
  28.                 goto _kdCISModulePowerOn_exit_;  
  29.             }  
  30.             //VCAM_D  
  31.             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1500,mode_name))  
  32.             {  
  33.                  PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");  
  34.                  goto _kdCISModulePowerOn_exit_;  
  35.             }  
  36.              //AF_VCC  
  37.             if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_AF, VOL_2800,mode_name))  
  38.             {  
  39.                 PK_DBG("[CAMERA SENSOR] Fail to enable analog power (VCAM_AF), power id = %d \n", CAMERA_POWER_VCAM_AF);  
  40.                 goto _kdCISModulePowerOn_exit_;  
  41.             }  
  42.   
  43.             mdelay(5);  
  44.   
  45.             //enable active sensor  
  46.             if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMPDN]) {  
  47.                 if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! (CMPDN)\n");}  
  48.                 if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! (CMPDN)\n");}  
  49.                 if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMPDN],pinSet[pinSetIdx][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! (CMPDN)\n");}  
  50.             }  
  51.   
  52.             mdelay(1);  
  53.   
  54.             if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {  
  55.                 if(mt_set_gpio_mode(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! (CMRST)\n");}  
  56.                 if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! (CMRST)\n");}  
  57.                 if(mt_set_gpio_out(pinSet[pinSetIdx][IDX_PS_CMRST],pinSet[pinSetIdx][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! (CMRST)\n");}  
  58.             }             
  59. }  
VCAM_IO、VCAM_A、VCAM_D和AF_VCC都是需要按照手册来修改


8.在ProjectConfig.mk中添加sensor

[cpp] view plain copy
  1. CUSTOM_HAL_IMGSENSOR=ov8858_mipi_raw  
  2. CUSTOM_HAL_MAIN_IMGSENSOR=ov8858_mipi_raw  
  3.   
  4.   
  5. CUSTOM_KERNEL_IMGSENSOR=ov8858_mipi_raw  
  6. CUSTOM_KERNEL_MAIN_IMGSENSOR=ov8858_mipi_raw  
在\kernel-3.10\arch\arm64\configs\<project>中增加

[cpp] view plain copy
  1. CONFIG_CUSTOM_KERNEL_IMGSENSOR=“ov8858_mipi_raw”  

现在我们编译下一般情况下是可以运行camera这个功能了,但是不免会遇到很多意外,例如我爬坑爬了挺久本来是一个很简单的移植,那现在就一起爬吧。

首先你可能会发现额怎么我的摄像功能不行?我的聚焦功能也没实现,闪光灯功能也没看到。运气好的话你可能也会遇到,当时找了很久都没发现问题后来请教了下大神帮我弄了下终于弄出来了但是还是云里雾里,在我的基础上也没怎么改。

我们当时直接把AF加上之后就正常,但是在ProjectConfig.mk把其它摄像头的驱动都屏蔽了,后面需要自己添加,这里有一点不明白就是添加两个兼容驱动写前和写后面的区别是什么可以互换不,如果哪位知道请评论下,感谢。

添加AF在ProjectConfig.mk:

[cpp] view plain copy
  1. CUSTOM_KERNEL_LENS = ad5820af fm50af dw9714af dummy_lens  

我使用的是fm50af。

在\vendor\mediatek\proprietary\custom\<project>\hal\sendepfeature下面新建一个你驱动对应名字的文件,添加config.ftbl.ov8858_mipi_raw.h这个文件到里面去,此文件在给你hal层代码里面有。把这些完成之后你重新new一把最后看到功能都出来了,如果还没出来你把ProjectConfig.mk里面的camera的其它关于摄像头的后置驱动全部去掉留下你正在移植那个试试,包括你kernel目录里面的deconfig里面。

现在差不多都搞定了。打开摄像头看到上下左右都反了,那我们就得看下寄存器改方向了查看了8858相关寄存器,发现修改方向的是0x3820和0x3821按照对应修改即可,.sensor_output_dataformat = SENSOR_OUTPUT_FORMAT_RAW_B这个是修改颜色的你们也应该会遇到问题,四种状态:B、Gb、R、Gr
原创粉丝点击