MTK Camera驅動移植

對於MTK Camera驅動移植一般分為四部分:

1、硬體IO口配置;

2、Camera驅動移植;

3、上電時序;

4、修改i2c控制器;

硬體電路:

1、GPIO配置

開啟 mediatek\dct\DrvGen.exe 

選擇 mediatek\custom\xiaoxi\kernel\dct\dct\codegen.dws 配置檔案

設定前後攝像頭的CMRST和CMPDN引腳,這是跟上電時序有關;

2、Camera驅動移植(以SP5507 SP2509為例)

(1)將kernel層程式碼整個目錄sp5507_mipi_raw,sp2509_mipi_raw拷貝到mediatek/custom/common/kernel/imgsensor/目錄下;
(2)將hal層程式碼整個目錄sp5507_mipi_raw,sp2509_mipi_raw拷貝到mediatek/custom/common/hal/imgsensor/目錄下;
         SP5507晶片與VO5670是用一款晶片,所以驅動程式也是同一套,上電時序也是一致;

(3)開啟mediatek/custom/common/kernel/imgsensor/inc/kd_imgsensor.h檔案, 定義sensor id和sensor name

#define SP5507MIPI_SENSOR_ID                    0x5670  
#define SENSOR_DRVNAME_SP5507MIPI_RAW           “sp5507_mipi_raw”

#define SP2509MIPI_SENSOR_ID                    0x2509
#define SENSOR_DRVNAME_SP2509MIPI_RAW           “sp2509_mipi_raw”

id和name的定義建議跟系統其它資料格式保持一致;

(4)在mediatek/custom/common/kernel/imgsensor/src/kd_sensorlist.h檔案中宣告初始化函式;

UINT32 SP5507_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);  //該函式為kernel中的初始化函式;

UINT32 SP2509_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);  //該函式為kernel中的初始化函式;

在kdSensorList陣列中新增:

#if defined(SP5507_MIPI_RAW)    //該巨集為驅動目錄名大寫
    {SP5507MIPI_SENSOR_ID, SENSOR_DRVNAME_SP5507MIPI_RAW, SP5507_MIPI_RAW_SensorInit},
#endif

#if defined(SP2509_MIPI_RAW)  //該巨集為驅動目錄名大寫
    {SP2509MIPI_SENSOR_ID, SENSOR_DRVNAME_SP2509MIPI_RAW, SP2509_MIPI_RAW_SensorInit},
#endif

(5)在mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp檔案的SensorList陣列中新增
#if defined(SP5507_MIPI_RAW)
    RAW_INFO(SP5507MIPI_SENSOR_ID, SENSOR_DRVNAME_SP5507MIPI_RAW, NULL),
#endif

#if defined(SP2509_MIPI_RAW)
    RAW_INFO(SP2509MIPI_SENSOR_ID, SENSOR_DRVNAME_SP2509MIPI_RAW, NULL),
#endif

程式碼位置要跟kdSensorList陣列中的位置保持一致;

(6) 修改mediatek/config/pro/ProjectConfig.mk配置檔案
CUSTOM_HAL_IMGSENSOR=sp5507_mipi_raw
CUSTOM_HAL_MAIN_IMGSENSOR=sp5507_mipi_raw  //後攝像頭
CUSTOM_HAL_SUB_IMGSENSOR=sp2509_mipi_raw   //前攝像頭
 
CUSTOM_KERNEL_IMGSENSOR=sp5507_mipi_raw
CUSTOM_KERNEL_MAIN_IMGSENSOR =sp5507_mipi_raw  //後攝像頭
CUSTOM_KERNEL_SUB_IMGSENSOR=sp2509_mipi_raw  //前攝像頭

(7)驅動檔案的修改

修改kernel層中的XXXXmipiraw_Sensor.h檔案中的Sensor ID巨集為kd_imgsensor.h中定義的Sensor ID巨集:

#define OV5670_SENSOR_ID  SP5507MIPI_SENSOR_ID 

與供應商確認i2c讀寫地址;

再修改hal層中的camera_info_XXXXmipiraw.h中的SENSOR_ID和SENSOR_DRVNAME為kd_imgsensor.h中定義的巨集,修改config.ftbl.XXXX_mipi_raw.h中的FTABLE_DEFINITION(SENSOR_DRVNAME_XXXX_MIPI_RAW)的SENSOR_DRVNAME為kd_imgsensor.h中定義的sensor
name巨集;

(8)修改上電時序

開啟mediatek\custom\pro\kernel\camera\camera\kd_camera_hw.c檔案

修改kdCISModulePowerOn()函式;

SP5507上電時序

SP2509上電時序

int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSensorName, BOOL On, char* mode_name)
{
u32 pinSetIdx = 0;//default main sensor
#define IDX_PS_CMRST 0    //RST索引
#define IDX_PS_CMPDN 4    //PDN索引
#define IDX_PS_MODE 1
#define IDX_PS_ON   2
#define IDX_PS_OFF  3
u32 pinSet[2][8] = 
{
//for main sensor   //後攝像頭
{
GPIO_CAMERA_CMRST_PIN,
GPIO_CAMERA_CMRST_PIN_M_GPIO,   /* mode */
GPIO_OUT_ONE,                   /* ON state */
GPIO_OUT_ZERO,                  /* OFF state */
GPIO_CAMERA_CMPDN_PIN,
GPIO_CAMERA_CMPDN_PIN_M_GPIO,
GPIO_OUT_ONE, 
GPIO_OUT_ZERO,
},
//for sub sensor   //前攝像頭
{
GPIO_CAMERA_CMRST1_PIN,   //RST引腳
GPIO_CAMERA_CMRST1_PIN_M_GPIO,
GPIO_OUT_ONE,    //上電電平
GPIO_OUT_ZERO,   //下電電平
GPIO_CAMERA_CMPDN1_PIN,  //PDN引腳
GPIO_CAMERA_CMPDN1_PIN_M_GPIO, 
GPIO_OUT_ONE,    //上電電平
GPIO_OUT_ZERO,   //下電電平
}
};
if (DUAL_CAMERA_MAIN_SENSOR == SensorIdx){
pinSetIdx = 0;
searchMainSensor = KAL_TRUE;
}
else if (DUAL_CAMERA_SUB_SENSOR == SensorIdx) {
pinSetIdx = 1;
searchMainSensor = KAL_FALSE;
}
PK_DBG("[kdCISModulePowerOn]:pinSetIdx=%d\n",pinSetIdx);
//power ON
if (On)   //上電時序
{
PK_DBG("kdCISModulePowerOn -on:currSensorName=%s\n",currSensorName);
if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_SP2509MIPI_RAW,currSensorName))))
{
{
PK_DBG("kdCISModulePowerOn get in---  %s \n",currSensorName);
PK_DBG("[ON_general 2.8V]sensorIdx:%d \n",SensorIdx);
/* SP2509只有兩個電源 */						
if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name))  //VCAM_IO  先開啟DVDDIO電源
{
PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}			
mdelay(1);
if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name))  //再開啟AVDD電源
{
PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}			
mdelay(1);
if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST])
{										
/* RST和PDN先置為低電平 */	
//PDN/STBY pin   
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
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!! \n");}
//RST pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
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!! \n");}
mdelay(1);
//PDN/STBY pin   //PWD高電平脈衝 持續10ms
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!! \n");}
mdelay(10);	
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!! \n");}
mdelay(10);	
//RST pin   //然後RST置高電平
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!! \n");}
mdelay(10);	//
}
//disable inactive sensor   //關閉不使用的攝像頭
if(pinSetIdx == 0 ) {//disable sub
if (GPIO_CAMERA_INVALID != pinSet[1][IDX_PS_CMRST]) {
if(mt_set_gpio_mode(pinSet[1][IDX_PS_CMRST],pinSet[1][IDX_PS_CMRST IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
if(mt_set_gpio_mode(pinSet[1][IDX_PS_CMPDN],pinSet[1][IDX_PS_CMPDN IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
if(mt_set_gpio_dir(pinSet[1][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
if(mt_set_gpio_dir(pinSet[1][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
if(mt_set_gpio_out(pinSet[1][IDX_PS_CMRST],pinSet[1][IDX_PS_CMRST IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
if(mt_set_gpio_out(pinSet[1][IDX_PS_CMPDN],pinSet[1][IDX_PS_CMPDN IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
}
}
else {
if (GPIO_CAMERA_INVALID != pinSet[0][IDX_PS_CMRST]) {
if(mt_set_gpio_mode(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
if(mt_set_gpio_mode(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
if(mt_set_gpio_dir(pinSet[0][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
if(mt_set_gpio_dir(pinSet[0][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
if(mt_set_gpio_out(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
}
}
mdelay(50);
}
}
else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_SP5507MIPI_RAW,currSensorName))))
{
{
PK_DBG("kdCISModulePowerOn get in---  %s \n",currSensorName);
PK_DBG("[ON_general 2.8V]sensorIdx:%d \n",SensorIdx);
/* SP5507有三個電源 */							
if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D2, VOL_1800,mode_name))  //VCAM_IO  先開啟DOVDD電源
{
PK_DBG("[CAMERA SENSOR] Fail to enable digital power\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}			
if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_A, VOL_2800,mode_name))  //再開啟AVDD電源
{
PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}			
if(TRUE != hwPowerOn(CAMERA_POWER_VCAM_D, VOL_1200,mode_name))   //最後開啟DVDD電源
{
PK_DBG("[CAMERA SENSOR] Fail to enable analog power\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}			
mdelay(1);
if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST])
{	
/* 先把RET(SHUTDOWN)和PWDN置為低電平 */										
//PDN/STBY pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
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!! \n");}
//RST pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
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!! \n");}
mdelay(1);
//RST pin  
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!! \n");}
mdelay(2);		
//PDN/STBY pin
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!! \n");}
mdelay(20);	
}
//disable inactive sensor  //關閉其他攝像頭
if(pinSetIdx == 0 ) {//disable sub
if (GPIO_CAMERA_INVALID != pinSet[1][IDX_PS_CMRST]) {
if(mt_set_gpio_mode(pinSet[1][IDX_PS_CMRST],pinSet[1][IDX_PS_CMRST IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
if(mt_set_gpio_mode(pinSet[1][IDX_PS_CMPDN],pinSet[1][IDX_PS_CMPDN IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
if(mt_set_gpio_dir(pinSet[1][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
if(mt_set_gpio_dir(pinSet[1][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
if(mt_set_gpio_out(pinSet[1][IDX_PS_CMRST],pinSet[1][IDX_PS_CMRST IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
if(mt_set_gpio_out(pinSet[1][IDX_PS_CMPDN],pinSet[1][IDX_PS_CMPDN IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
}
}
else {
if (GPIO_CAMERA_INVALID != pinSet[0][IDX_PS_CMRST]) {
if(mt_set_gpio_mode(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST IDX_PS_MODE])){PK_DBG("[CAMERA SENSOR] set gpio mode failed!! \n");}
if(mt_set_gpio_mode(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN IDX_PS_MODE])){PK_DBG("[CAMERA LENS] set gpio mode failed!! \n");}
if(mt_set_gpio_dir(pinSet[0][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
if(mt_set_gpio_dir(pinSet[0][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST IDX_PS_OFF])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");} //low == reset sensor
if(mt_set_gpio_out(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");} //high == power down lens module
}
}
mdelay(50);
}
}
}
//power OFF
else    //下電時序
{
PK_DBG("kdCISModulePowerOn -off:currSensorName=%s\n",currSensorName);
if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_SP2509MIPI_RAW, currSensorName)))
{
PK_DBG("kdCISModulePowerOff, get in---SENSOR_DRVNAME_IMX219_MIPI_RAW \n");
if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {
//RST pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
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!! \n");} //low == reset sensor
mdelay(1);
//PDN/STBY pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
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!! \n");}
mdelay(1);		
}
if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
PK_DBG("[CAMERA SENSOR] Fail to OFF analog power:VCAM_A:VOL_2800\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}
if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2, mode_name)) {
PK_DBG("[CAMERA SENSOR] Fail to OFF digital power:VCAM_D:VOL_1200\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}
mdelay(1);	
//PDN pull down
if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMPDN]) {
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
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!! \n");}
mdelay(1);
}    
} 
else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_SP5507MIPI_RAW, currSensorName)))
{
PK_DBG("kdCISModulePowerOff, get in---SENSOR_DRVNAME_IMX219_MIPI_RAW \n");
if (GPIO_CAMERA_INVALID != pinSet[pinSetIdx][IDX_PS_CMRST]) {
//RST pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMRST],GPIO_DIR_OUT)){PK_DBG("[CAMERA SENSOR] set gpio dir failed!! \n");}
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!! \n");} //low == reset sensor
mdelay(2);
//PDN/STBY pin
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!! \n");}
if(mt_set_gpio_dir(pinSet[pinSetIdx][IDX_PS_CMPDN],GPIO_DIR_OUT)){PK_DBG("[CAMERA LENS] set gpio dir failed!! \n");}
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!! \n");}
mdelay(1);		
}
if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D, mode_name)) {
PK_DBG("[CAMERA SENSOR] Fail to OFF digital power:VCAM_D:VOL_1200\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}		
if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_A,mode_name)) {
PK_DBG("[CAMERA SENSOR] Fail to OFF analog power:VCAM_A:VOL_2800\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}
if(TRUE != hwPowerDown(CAMERA_POWER_VCAM_D2, mode_name)) {
PK_DBG("[CAMERA SENSOR] Fail to OFF digital power:VCAM_D:VOL_1200\n");
//return -EIO;
goto _kdCISModulePowerOn_exit_;
}		
mdelay(1);		   
} 
}
return 0;
_kdCISModulePowerOn_exit_:
return -EIO;
}

根據晶片的上電時序圖把大致的上電時序設定好就可以使攝像頭工作起來;這裡的上電時序沒有像協議時序那般嚴格,只需要大致配置好就可以了;

4、修改i2c控制器
開啟mediatek\custom\common\kernel\imgsensor\src\kd_sensorlist.c,修改 i2c_register_board_info(SUPPORT_I2C_BUS_NUM, &i2c_devs, 1);中的SUPPORT_I2C_BUS_NUM設定為實際電路使用的i2c控制器

如果開機後,相機無法起來,那就應該檢視系統log,判斷是否能夠獲取到Camera的ID,硬體上必須保證I2C能夠正常通訊;