一、MTK平台Camera框架

MTK平台的Camera的架构见下图,

MTK Camera 开机启动流程(转载)-LMLPHP

这里主要介绍kernel部分和HAL层部分。

1、Kernel 部分主要有两块:

1.1、image sensordriver,负责具体型号的 sensor 的 id 检测,上电,以及在preview、capture、初始化、3A等等功能设定时的寄存器配置。

1.2、isp driver,通过DMA将sensor数据流上传。

2、HAL层部分主要有三部分组成:

2.1、imageio,主要负责数据buffer上传的pipe。

2.2、drv,包含imgsensor和isp的hal层控制。

2.3、feature io,包含各种3A等性能配置。

二、Camera打开流程分析

Camera开启流程图如下:

MTK Camera 开机启动流程(转载)-LMLPHP

主要发生在两个时间点:

1、开机时:camera完成了sensor框架初始化,id检测并匹配sensor,以及上下电操作。

2、打开Camera应用时:camera会有上电,完成sensor的寄存器初始化配置,向上层传递基本参数和配置信息,以及preview和capture模式循环。

1、开机初始化过程

由于一开始不知道上电camera初始化从哪开始,我们可以借助抓取的mtk mobile log去分析。先看hal层log开始处:

  1. 12-24 10:02:07.601   148   148 D MtkCam/module: [instantiate_camera_module]
  2. 12-24 10:02:07.601   148   148 D MtkCam/Utils/Property: [clear] pid/tid=148/148
  3. 12-24 10:02:07.601   148   148 I CameraService: Loaded "MediaTek Camera Module" camera module
  4. 12-24 10:02:07.601   148   148 D MtkCam/MtkCamUtils: [CamDevMetaInfoMap::clear] pid/tid=148/148
  5. 12-24 10:02:07.601   148   148 D SensorHal: [getInstance][SensorHalImp] getInstance
  6. 12-24 10:02:07.601   148   148 D SensorHal: [createImp][createImp]: 0
  7. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [getInstance][getInstance]
  8. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [SeninfDrvImp][SeninfDrvImp]
  9. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [init][init]: 0

通过sourceinsight搜索发现开始是从CamDeviceManagerImp.cpp函数的enumDeviceLocked()开始。该函数的源代码如下:

===>mediatek/platform/mt6582/hardware/mtkcam/devicemgr/CamDeviceManagerImp.cpp

  1. /******************************************************************************
  2. *
  3. ******************************************************************************/
  4. int32_t
  5. CamDeviceManagerImp::
  6. enumDeviceLocked()
  7. {
  8. Utils::CamProfile _profile(__FUNCTION__, "CamDeviceManagerImp");
  9. //
  10. status_t status = OK;
  11. int32_t i4DeviceNum = 0;
  12. //
  13. mEnumMap.clear();
  14. //------------------------------------------------------------------------------
  15. #if '1'==MTKCAM_HAVE_SENSOR_HAL
  16. mEnumMap.clear();
  17. DevMetaInfo::clear();
  18. //
  19. int32_t isFakeOrientation = 0;
  20. int32_t i4DevSetupOrientation = 0;
  21. camera_info camInfo;
  22. camInfo.device_version = CAMERA_DEVICE_API_VERSION_1_0;
  23. camInfo.static_camera_characteristics = NULL;
  24. //
  25. SensorHal* pSensorHal = SensorHal::createInstance();//创建sensor对象
  26. if  ( ! pSensorHal )
  27. {
  28. MY_LOGE("pSensorHal == NULL");
  29. return 0;
  30. }
  31. //
  32. int32_t const iSensorsList = pSensorHal->searchSensor();//此函数是入口,主要查找匹配的硬件sensor
  33. //
  34. //
  35. if  ( (iSensorsList & SENSOR_DEV_MAIN_3D) == SENSOR_DEV_MAIN_3D )
  36. {
  37. MY_LOGI("Stereo 3D Camera found");
  38. #warning "[TODO] Stereo 3D Camera"
  39. }
  40. //
  41. if  ( (iSensorsList & SENSOR_DEV_MAIN) == SENSOR_DEV_MAIN )
  42. {
  43. int32_t const deviceId = i4DeviceNum;
  44. //
  45. halSensorDev_e const eHalSensorDev = SENSOR_DEV_MAIN;
  46. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
  47. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
  48. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
  49. camInfo.orientation = i4DevSetupOrientation;
  50. if  ( isFakeOrientation )
  51. {
  52. camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
  53. MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
  54. }
  55. DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
  56. //
  57. sp<EnumInfo> pInfo = new EnumInfo;
  58. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  59. pInfo->pMetadata            = NULL;
  60. pInfo->iFacing              = camInfo.facing;
  61. pInfo->iWantedOrientation   = camInfo.orientation;
  62. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  63. mEnumMap.add(deviceId, pInfo);
  64. //
  65. i4DeviceNum++;
  66. }
  67. //
  68. if  ( (iSensorsList & SENSOR_DEV_SUB) == SENSOR_DEV_SUB )
  69. {
  70. int32_t const deviceId = i4DeviceNum;
  71. //
  72. halSensorDev_e const eHalSensorDev = SENSOR_DEV_SUB;
  73. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
  74. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
  75. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
  76. camInfo.orientation = i4DevSetupOrientation;
  77. if  ( isFakeOrientation )
  78. {
  79. camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
  80. MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
  81. }
  82. DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
  83. //
  84. sp<EnumInfo> pInfo = new EnumInfo;
  85. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  86. pInfo->pMetadata            = NULL;
  87. pInfo->iFacing              = camInfo.facing;
  88. pInfo->iWantedOrientation   = camInfo.orientation;
  89. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  90. mEnumMap.add(deviceId, pInfo);
  91. //
  92. i4DeviceNum++;
  93. }
  94. //
  95. //    if  ( (iSensorsList & SENSOR_DEV_ATV) == SENSOR_DEV_ATV )
  96. {
  97. int32_t const deviceId = 0xFF;
  98. //
  99. halSensorDev_e const eHalSensorDev = SENSOR_DEV_ATV;
  100. camInfo.facing = 0;
  101. camInfo.orientation = 0;
  102. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, eHalSensorDev);
  103. //
  104. sp<EnumInfo> pInfo = new EnumInfo;
  105. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  106. pInfo->pMetadata            = NULL;
  107. pInfo->iFacing              = camInfo.facing;
  108. pInfo->iWantedOrientation   = camInfo.orientation;
  109. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  110. mEnumMap.add(deviceId, pInfo);
  111. //
  112. //        i4DeviceNum++;
  113. }
  114. //
  115. //
  116. if  ( pSensorHal )
  117. {
  118. pSensorHal->destroyInstance();
  119. pSensorHal = NULL;
  120. }
  121. //
  122. MY_LOGI("iSensorsList=0x%08X, i4DeviceNum=%d", iSensorsList, i4DeviceNum);
  123. for (size_t i = 0; i < mEnumMap.size(); i++)
  124. {
  125. int32_t const deviceId = mEnumMap.keyAt(i);
  126. sp<EnumInfo> pInfo = mEnumMap.valueAt(i);
  127. uint32_t const uDeviceVersion   = pInfo->uDeviceVersion;
  128. camera_metadata const*pMetadata = pInfo->pMetadata;
  129. int32_t const iFacing           = pInfo->iFacing;
  130. int32_t const iWantedOrientation= pInfo->iWantedOrientation;
  131. int32_t const iSetupOrientation = pInfo->iSetupOrientation;
  132. MY_LOGI(
  133. "[0x%02x] orientation(wanted/setup)=(%d/%d) facing:%d metadata:%p DeviceVersion:0x%x",
  134. deviceId, iWantedOrientation, iSetupOrientation,
  135. iFacing, pMetadata, uDeviceVersion
  136. );
  137. }
  138. #else   //----------------------------------------------------------------------
  139. #warning "[WARN] Simulation for CamDeviceManagerImp::enumDeviceLocked()"
  140. mEnumMap.clear();
  141. DevMetaInfo::clear();
  142. {
  143. int32_t const deviceId = 0;
  144. //
  145. camera_info camInfo;
  146. camInfo.device_version  = CAMERA_DEVICE_API_VERSION_1_0;
  147. camInfo.static_camera_characteristics = NULL;
  148. camInfo.facing      = 0;
  149. camInfo.orientation = 90;
  150. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_ImgSensor, 0x01/*SENSOR_DEV_MAIN*/);
  151. //
  152. sp<EnumInfo> pInfo = new EnumInfo;
  153. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  154. pInfo->pMetadata            = NULL;
  155. pInfo->iFacing              = 0;
  156. pInfo->iWantedOrientation   = 90;
  157. pInfo->iSetupOrientation    = 90;
  158. mEnumMap.add(deviceId, pInfo);
  159. }
  160. //
  161. {
  162. int32_t const deviceId = 0xFF;
  163. //
  164. camera_info camInfo;
  165. camInfo.device_version  = CAMERA_DEVICE_API_VERSION_1_0;
  166. camInfo.static_camera_characteristics = NULL;
  167. camInfo.facing      = 0;
  168. camInfo.orientation = 0;
  169. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, 0x04/*SENSOR_DEV_ATV*/);
  170. //
  171. sp<EnumInfo> pInfo = new EnumInfo;
  172. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  173. pInfo->pMetadata            = NULL;
  174. pInfo->iFacing              = 0;
  175. pInfo->iWantedOrientation   = 0;
  176. pInfo->iSetupOrientation    = 0;
  177. mEnumMap.add(deviceId, pInfo);
  178. }
  179. //
  180. i4DeviceNum = 1;
  181. #endif
  182. //------------------------------------------------------------------------------
  183. //
  184. _profile.print("");
  185. return  i4DeviceNum;
  186. }

函数pSensorHal->searchSensor()将调用SensorDrv::searchSensor(NULL)函数,该函数再调用ImgSensor_drv.cpp文件中中的ImgSensorDrv::impSearchSensor函数。

===>mediatek/platform/mt6582/hardware/mtkcam/core/drv/imgsensor/ImgSensor_drv.cpp

  1. /*******************************************************************************
  2. *
  3. ********************************************************************************/
  4. MINT32
  5. ImgSensorDrv::impSearchSensor(pfExIdChk pExIdChkCbf)
  6. {
  7. MUINT32 SensorEnum = (MUINT32) DUAL_CAMERA_MAIN_SENSOR;
  8. MUINT32 i,id[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
  9. MBOOL SensorConnect=TRUE;
  10. UCHAR cBuf[64];
  11. MINT32 err = SENSOR_NO_ERROR;
  12. MINT32 err2 = SENSOR_NO_ERROR;
  13. ACDK_SENSOR_INFO_STRUCT SensorInfo;
  14. ACDK_SENSOR_CONFIG_STRUCT SensorConfigData;
  15. ACDK_SENSOR_RESOLUTION_INFO_STRUCT SensorResolution;
  16. MINT32 sensorDevs = SENSOR_NONE;
  17. IMAGE_SENSOR_TYPE sensorType = IMAGE_SENSOR_TYPE_UNKNOWN;
  18. IMGSENSOR_SOCKET_POSITION_ENUM socketPos = IMGSENSOR_SOCKET_POS_NONE;
  19. //! If imp sensor search process already done before,
  20. //! only need to return the sensorDevs, not need to
  21. //! search again.
  22. if (SENSOR_DOES_NOT_EXIST != m_mainSensorId) {
  23. //been processed.
  24. LOG_MSG("[impSearchSensor] Already processed \n");
  25. if (BAD_SENSOR_INDEX != m_mainSensorIdx) {
  26. sensorDevs |= SENSOR_MAIN;
  27. }
  28. if (BAD_SENSOR_INDEX != m_subSensorIdx) {
  29. sensorDevs |= SENSOR_SUB;
  30. }
  31. #ifdef  ATVCHIP_MTK_ENABLE
  32. sensorDevs |= SENSOR_ATV;
  33. #endif
  34. return sensorDevs;
  35. }
  36. GetSensorInitFuncList(&m_pstSensorInitFunc);//----(1)获取hal层的sensor列表
  37. LOG_MSG("SENSOR search start \n");
  38. if (-1 != m_fdSensor) {
  39. ::close(m_fdSensor);
  40. m_fdSensor = -1;
  41. }
  42. sprintf(cBuf,"/dev/%s",CAMERA_HW_DEVNAME);
  43. m_fdSensor = ::open(cBuf, O_RDWR);
  44. if (m_fdSensor < 0) {
  45. LOG_ERR("[impSearchSensor]: error opening %s: %s \n", cBuf, strerror(errno));
  46. return sensorDevs;
  47. }
  48. LOG_MSG("[impSearchSensor] m_fdSensor = %d  \n", m_fdSensor);
  49. // search main/main_2/sub 3 sockets
  50. #ifdef MTK_SUB_IMGSENSOR
  51. for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum <= DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1)  {
  52. LOG_MSG("impSearchSensor search to sub\n");
  53. #else
  54. for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum < DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1)  {
  55. LOG_MSG("impSearchSensor search to main\n");
  56. #endif
  57. //skip atv case
  58. if ( 0x04 == SensorEnum ) continue;
  59. //
  60. for (i = 0; i < MAX_NUM_OF_SUPPORT_SENSOR; i++) {
  61. //end of driver list
  62. if (m_pstSensorInitFunc[i].getCameraDefault == NULL) {
  63. LOG_MSG("m_pstSensorInitFunc[i].getCameraDefault is NULL: %d \n", i);
  64. break;
  65. }
  66. //set sensor driver
  67. id[KDIMGSENSOR_INVOKE_DRIVER_0] = (SensorEnum << KDIMGSENSOR_DUAL_SHIFT) | i;
  68. LOG_MSG("set sensor driver id =%x\n", id[KDIMGSENSOR_INVOKE_DRIVER_0]);
  69. err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,&id[KDIMGSENSOR_INVOKE_DRIVER_0] );//--(2)调用kernel层的kdSetDriver函数
  70. if (err < 0) {
  71. LOG_ERR("ERROR:KDCAMERAHWIOC_X_SET_DRIVER\n");
  72. }
  73. //err = open();
  74. err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE);//---(3)上下电camera并读取sensor的ID,如果匹配则成功
  75. if (err < 0) {
  76. LOG_MSG("[impSearchSensor] Err-ctrlCode (%s) \n", strerror(errno));//
  77. }
  78. //
  79. sensorType = this->getCurrentSensorType((SENSOR_DEV_ENUM)SensorEnum);
  80. //
  81. socketPos = this->getSocketPosition((CAMERA_DUAL_CAMERA_SENSOR_ENUM)SensorEnum);
  82. //check extra ID , from EEPROM maybe
  83. //may need to keep power here
  84. if (NULL != pExIdChkCbf) {
  85. err2 = pExIdChkCbf();
  86. if (err2 < 0) {
  87. LOG_ERR("Error:pExIdChkCbf() \n");
  88. }
  89. }
  90. //power off sensor
  91. close();
  92. if (err < 0 || err2 < 0) {
  93. LOG_MSG("sensor ID mismatch\n");
  94. }
  95. else {
  96. if (SensorEnum == DUAL_CAMERA_MAIN_SENSOR) {
  97. //m_mainSensorIdx = i;
  98. //m_mainSensorId = m_pstSensorInitFunc[m_mainSensorIdx].SensorId;
  99. m_mainSensorDrv.index[m_mainSensorDrv.number] = i;
  100. m_mainSensorDrv.type[m_mainSensorDrv.number] = sensorType;
  101. if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstRawIndex ) {
  102. m_mainSensorDrv.firstRawIndex = i;
  103. }
  104. else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstYuvIndex ) {
  105. m_mainSensorDrv.firstYuvIndex = i;
  106. }
  107. m_mainSensorDrv.position = socketPos;
  108. m_mainSensorDrv.sensorID = m_pstSensorInitFunc[m_mainSensorDrv.index[m_mainSensorDrv.number]].SensorId;
  109. // LOG_MSG("MAIN sensor m_mainSensorDrv.number=%d, m_mainSensorDrv.index=%d\n",m_mainSensorDrv.number,m_mainSensorDrv.index[m_mainSensorDrv.number]);
  110. m_mainSensorDrv.number++;
  111. //
  112. m_pMainSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  113. if  ( m_pMainSensorInfo )
  114. {
  115. NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  116. LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
  117. }
  118. else
  119. {
  120. LOG_WRN("m_pMainSensorInfo==NULL\n");
  121. }
  122. LOG_MSG("MAIN sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
  123. //break;
  124. }
  125. else if (SensorEnum == DUAL_CAMERA_SUB_SENSOR) {
  126. //m_subSensorIdx = i;
  127. //m_subSensorId = m_pstSensorInitFunc[m_subSensorIdx].SensorId;
  128. m_subSensorDrv.index[m_subSensorDrv.number] = i;
  129. m_subSensorDrv.type[m_subSensorDrv.number] = sensorType;
  130. if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstRawIndex ) {
  131. m_subSensorDrv.firstRawIndex = i;
  132. }
  133. else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstYuvIndex ) {
  134. m_subSensorDrv.firstYuvIndex = i;
  135. }
  136. m_subSensorDrv.position = socketPos;
  137. m_subSensorDrv.sensorID = m_pstSensorInitFunc[m_subSensorDrv.index[m_subSensorDrv.number]].SensorId;
  138. //LOG_MSG("SUB sensor m_subSensorDrv.number=%d, m_subSensorDrv.index=%d\n",m_subSensorDrv.number,m_subSensorDrv.index[m_subSensorDrv.number]);
  139. m_subSensorDrv.number++;
  140. //
  141. m_pSubSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  142. if  ( m_pSubSensorInfo )
  143. {
  144. NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  145. LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
  146. }
  147. else
  148. {
  149. LOG_WRN("m_pSubSensorInfo==NULL\n");
  150. }
  151. LOG_MSG("SUB sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
  152. //break;
  153. }
  154. }//
  155. }
  156. }
  157. //close system call may be off sensor power. check first!!!
  158. ::close(m_fdSensor);
  159. m_fdSensor = -1;
  160. //
  161. if (BAD_SENSOR_INDEX != m_mainSensorDrv.index[0]) {
  162. m_mainSensorId = m_mainSensorDrv.sensorID;
  163. //init to choose first
  164. m_mainSensorIdx = m_mainSensorDrv.index[0];
  165. sensorDevs |= SENSOR_MAIN;
  166. }
  167. if (BAD_SENSOR_INDEX != m_subSensorDrv.index[0]) {
  168. m_subSensorId = m_subSensorDrv.sensorID;
  169. //init to choose first
  170. m_subSensorIdx = m_subSensorDrv.index[0];
  171. sensorDevs |= SENSOR_SUB;
  172. }
  173. #ifdef  ATVCHIP_MTK_ENABLE
  174. sensorDevs |= SENSOR_ATV;
  175. #endif
  176. if (sensorDevs == SENSOR_NONE) {
  177. LOG_ERR( "Error No sensor found!! \n");
  178. }
  179. //
  180. LOG_MSG("SENSOR search end: 0x%x /[0x%x][%d]/[0x%x][%d]\n", sensorDevs,
  181. m_mainSensorId,m_mainSensorIdx,m_subSensorId,m_subSensorIdx);
  182. return sensorDevs;
  183. }//

(1)、获取hal层sensor列表GetSensorInitFuncList(&m_pstSensorInitFunc);

===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp

  1. UINT32 GetSensorInitFuncList(MSDK_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
  2. {
  3. if (NULL == ppSensorList) {
  4. ALOGE("ERROR: NULL pSensorList\n");
  5. return MHAL_UNKNOWN_ERROR;
  6. }
  7. *ppSensorList = &SensorList[0];//这里直接调用hal层的sensor列表
  8. return MHAL_NO_ERROR;
  9. } // GetSensorInitFuncList()

===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp

  1. MSDK_SENSOR_INIT_FUNCTION_STRUCT SensorList[] =
  2. {
  3. //add by zym
  4. #if defined(GC2235_MIPI_RAW)
  5. RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
  6. #endif
  7. // add by zhouzuoyu
  8. #if defined(GC2235_KOTECH_MIPI_RAW)
  9. RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
  10. #endif
  11. #if defined(OV16825_MIPI_RAW)
  12. RAW_INFO(OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW,NULL),
  13. #endif
  14. #if defined(IMX135_MIPI_RAW)
  15. RAW_INFO(IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW,NULL),
  16. #endif
  17. #if defined(OV8830_RAW)
  18. RAW_INFO(OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, NULL),
  19. #endif
  20. /*  ADD sensor driver before this line */
  21. {0,{0},NULL, NULL, NULL}//end of list
  22. };

(2)、获取kernel层的kdSetDriver函数err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,&id[KDIMGSENSOR_INVOKE_DRIVER_0] );

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * kdSetDriver
  3. ********************************************************************************/
  4. int kdSetDriver(unsigned int* pDrvIndex)
  5. {
  6. ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT *pSensorList = NULL;
  7. u32 drvIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
  8. u32 i;
  9. PK_XLOG_INFO("pDrvIndex:0x%08x/0x%08x \n",pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_0],pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_1]);
  10. //set driver for MAIN or SUB sensor
  11. if (0 != kdGetSensorInitFuncList(&pSensorList))//----(2.1)获取kernel层的sensor列表
  12. {
  13. PK_ERR("ERROR:kdGetSensorInitFuncList()\n");
  14. return -EIO;
  15. }
  16. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  17. //
  18. spin_lock(&kdsensor_drv_lock);
  19. g_bEnableDriver[i] = FALSE;
  20. g_invokeSocketIdx[i] = (CAMERA_DUAL_CAMERA_SENSOR_ENUM)((pDrvIndex[i] & KDIMGSENSOR_DUAL_MASK_MSB)>>KDIMGSENSOR_DUAL_SHIFT);
  21. spin_unlock(&kdsensor_drv_lock);
  22. drvIdx[i] = (pDrvIndex[i] & KDIMGSENSOR_DUAL_MASK_LSB);//----(2.2)g_invokeSocketIdx,drvIdx解释
  23. //
  24. if ( DUAL_CAMERA_NONE_SENSOR == g_invokeSocketIdx[i] ) { continue; }
  25. //ToDo: remove print information
  26. PK_XLOG_INFO("[kdSetDriver] i,g_invokeSocketIdx[%d] = %d :\n",i,i,drvIdx[i]);
  27. PK_XLOG_INFO("[kdSetDriver] i,drvIdx[%d] = %d :\n",i,i,drvIdx[i]);
  28. //
  29. if ( MAX_NUM_OF_SUPPORT_SENSOR > drvIdx[i] ) {
  30. if (NULL == pSensorList[drvIdx[i]].SensorInit) {
  31. PK_ERR("ERROR:kdSetDriver()\n");
  32. return -EIO;
  33. }
  34. pSensorList[drvIdx[i]].SensorInit(&g_pInvokeSensorFunc[i]);//----(2.3)获取指定sensor的fun函数,例如ov5670的func
  35. if (NULL == g_pInvokeSensorFunc[i]) {
  36. PK_ERR("ERROR:NULL g_pSensorFunc[%d]\n",i);
  37. return -EIO;
  38. }
  39. //
  40. spin_lock(&kdsensor_drv_lock);
  41. g_bEnableDriver[i] = TRUE;
  42. spin_unlock(&kdsensor_drv_lock);
  43. //get sensor name
  44. memcpy((char*)g_invokeSensorNameStr[i],(char*)pSensorList[drvIdx[i]].drvname,sizeof(pSensorList[drvIdx[i]].drvname));
  45. //return sensor ID
  46. //pDrvIndex[0] = (unsigned int)pSensorList[drvIdx].SensorId;
  47. PK_XLOG_INFO("[kdSetDriver] :[%d][%d][%d][%s][%d]\n",i,g_bEnableDriver[i],g_invokeSocketIdx[i],g_invokeSensorNameStr[i],sizeof(pSensorList[drvIdx[i]].drvname));
  48. }
  49. }
  50. return 0;
  51. }

(2.1)获取kernel层的sensor列表kdGetSensorInitFuncList(&pSensorList)

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * general camera image sensor kernel driver
  3. *******************************************************************************/
  4. UINT32 kdGetSensorInitFuncList(ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
  5. {
  6. if (NULL == ppSensorList)
  7. {
  8. PK_DBG("[kdGetSensorInitFuncList]ERROR: NULL ppSensorList\n");
  9. return 1;
  10. }
  11. *ppSensorList = &kdSensorList[0];
  12. return 0;
  13. } // kdGetSensorInitFuncList()

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.h

hal层和kernel层的sensor列表顺序必须保持一致

  1. ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
  2. {
  3. //add by zym
  4. #if defined(GC2235_MIPI_RAW)
  5. {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
  6. #endif
  7. // add by zhouzuoyu
  8. #if defined(GC2235_KOTECH_MIPI_RAW)
  9. {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
  10. #endif
  11. #if defined(OV16825_MIPI_RAW)
  12. {OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW, OV16825MIPISensorInit},
  13. #endif
  14. #if defined(IMX135_MIPI_RAW)
  15. {IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW, IMX135_MIPI_RAW_SensorInit},
  16. #endif
  17. #if defined(OV8830_RAW)
  18. {OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, OV8830SensorInit},
  19. #endif
  20. /*  ADD sensor driver before this line */
  21. {0,{0},NULL}, //end of list
  22. };
  23. //e_add new sensor driver here<span style="font-size:18px;"><span style="font-size:18px;">         </span>   </span>   <span style="font-size:18px;"><span style="font-size:18px;">
  24. </span></span>

(2.2)g_invokeSocketIdx,drvIdx解释

上层传下来的 id 参数解析成两部分 g_invokeSocketIdx 区分目前正在匹配的是 main 还是sub,drvIdx 是 sensor 列表的序列号 。

(2.3)获取指定sensor的func函数,例如ov5670的func,pSensorList[drvIdx[i]].SensorInit(&g_pInvokeSensorFunc[i]);

调用的函数是OV5670_MIPI_RAW_SensorInit()。

  1. #if defined(OV5670_MIPI_RAW)
  2. {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit},
  3. #endif

===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw/ov5670mipiraw_Sensor.c

  1. SENSOR_FUNCTION_STRUCT  SensorFuncOV5670=
  2. {
  3. OV5670Open,
  4. OV5670GetInfo,
  5. OV5670GetResolution,
  6. OV5670FeatureControl,
  7. OV5670Control,
  8. OV5670Close
  9. };
  10. UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)//---调用此函数
  11. {
  12. if (pfFunc!=NULL)
  13. *pfFunc=&SensorFuncOV5670;
  14. return ERROR_NONE;
  15. }

5670的sensorinit实现,主要是未了pfFunc这个函数指针的结构体指针赋值,这样我们就实现了驱动代码的分离,hal层只需要调用sensorlist.c这样一个虚拟设备的驱动,就可以和具体的Sensor Driver驱动通信。这样的做法与platform driver的设计思想差不多,在tp,lcm等驱动中也有体现。

(3)上下电camera并读取ID,err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE);

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * adopt_CAMERA_HW_CheckIsAlive
  3. ********************************************************************************/
  4. inline static int adopt_CAMERA_HW_CheckIsAlive(void)
  5. {
  6. UINT32 err = 0;
  7. UINT32 err1 = 0;
  8. UINT32 i = 0;
  9. MUINT32 sensorID = 0;
  10. MUINT32 retLen = 0;
  11. KD_IMGSENSOR_PROFILE_INIT();
  12. //power on sensor
  13. kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);//----(3.1)sensor上电
  14. //wait for power stable
  15. mDELAY(10);
  16. KD_IMGSENSOR_PROFILE("kdModulePowerOn");
  17. if (g_pSensorFunc) {
  18. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  19. if(DUAL_CAMERA_NONE_SENSOR != g_invokeSocketIdx[i]){
  20. err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx[i], SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);//---(3.2)获取sensor ID
  21. if (sensorID == 0) {    //not implement this feature ID
  22. PK_DBG(" Not implement!!, use old open function to check\n");
  23. err = ERROR_SENSOR_CONNECT_FAIL;
  24. }
  25. else if (sensorID == 0xFFFFFFFF) {    //fail to open the sensor
  26. PK_DBG(" No Sensor Found");
  27. err = ERROR_SENSOR_CONNECT_FAIL;
  28. }
  29. else {
  30. PK_DBG(" Sensor found ID = 0x%x\n", sensorID);
  31. err = ERROR_NONE;
  32. }
  33. if(ERROR_NONE != err)
  34. {
  35. PK_DBG("ERROR:adopt_CAMERA_HW_CheckIsAlive(), No imgsensor alive \n");
  36. }
  37. }
  38. }
  39. }
  40. else {
  41. PK_DBG("ERROR:NULL g_pSensorFunc\n");
  42. }
  43. //reset sensor state after power off
  44. err1 = g_pSensorFunc->SensorClose();
  45. if(ERROR_NONE != err1) {
  46. PK_DBG("SensorClose \n");
  47. }
  48. //
  49. kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr, false, CAMERA_HW_DRVNAME1);
  50. //
  51. KD_IMGSENSOR_PROFILE("CheckIsAlive");
  52. return err?-EIO:err;
  53. }   /* adopt_CAMERA_HW_Open() */

(3.1)Sensor 上电, kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);

  1. /*******************************************************************************
  2. * kdModulePowerOn
  3. ********************************************************************************/
  4. int
  5. kdModulePowerOn(
  6. CAMERA_DUAL_CAMERA_SENSOR_ENUM socketIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS],
  7. char sensorNameStr[KDIMGSENSOR_MAX_INVOKE_DRIVERS][32],
  8. BOOL On,
  9. char* mode_name )
  10. {
  11. MINT32 ret = ERROR_NONE;
  12. u32 i = 0;
  13. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  14. if ( g_bEnableDriver[i] ) {
  15. //PK_XLOG_INFO("[%s][%d][%d][%s][%s]\r\n",__FUNCTION__,g_bEnableDriver[i],socketIdx[i],sensorNameStr[i],mode_name);
  16. ret = kdCISModulePowerOn(socketIdx[i],sensorNameStr[i],On,mode_name);//实际上电的func
  17. if ( ERROR_NONE != ret ) {
  18. PK_ERR("[%s]",__FUNCTION__);
  19. return ret;
  20. }
  21. }
  22. }
  23. return ERROR_NONE;
  24. }

===>mediatek/custom/huaqin82_slwt_2s_td/kernel/camera/camera/kd_camera_hw.c

  1. int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSensorName, BOOL On, char* mode_name)
  2. {
  3. PK_DBG("[camera] **kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
  4. //dump_stack();
  5. if (DUAL_CAMERA_MAIN_SENSOR == SensorIdx){
  6. if (currSensorName &&
  7. ((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  8. ||(0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))
  9. ||(0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))
  10. ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  11. ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))
  12. ||(0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName))
  13. ||(0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
  14. ||(0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName))
  15. || (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))
  16. || (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))
  17. ||(0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName))
  18. ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
  19. ||(0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))
  20. ||(0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))
  21. ||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
  22. || (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV, currSensorName))
  23. ||(0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))
  24. ||(0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName))
  25. ||(0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName))
  26. //|| to add other main camera here
  27. ))
  28. pinSetIdx = 0;
  29. else
  30. {
  31. PK_DBG("[ryf-main]kdCISModulePowerOn get in---  sensorIdx not compare with sensor name: %s\n", currSensorName);
  32. //if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
  33. //{
  34. //      pinSetIdx = 1;
  35. //}
  36. //else{
  37. goto _kdCISModulePowerOn_exit_;
  38. //}
  39. }
  40. }
  41. else if (DUAL_CAMERA_SUB_SENSOR == SensorIdx) {
  42. if (currSensorName &&
  43. ((0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))
  44. || (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))
  45. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW, currSensorName))
  46. || (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName))
  47. || (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName))
  48. || (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName))
  49. || (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
  50. || (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  51. || (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))
  52. ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
  53. ||(0 == strcmp(SENSOR_DRVNAME_GC0312_YUV, currSensorName))
  54. ||(0 == strcmp(SENSOR_DRVNAME_HI704_YUV, currSensorName))
  55. //||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
  56. //|| to add other sub camera here
  57. ))
  58. pinSetIdx = 1;
  59. else
  60. {
  61. //if (currSensorName &&
  62. //((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  63. //|| to add other main camera here
  64. //))
  65. //{
  66. //  pinSetIdx = 0;
  67. //}
  68. PK_DBG("{ryf-sub}kdCISModulePowerOn get in---  sensorIdx not compare with sensro:%s\n",currSensorName);
  69. goto _kdCISModulePowerOn_exit_;
  70. }
  71. }
  72. else if (DUAL_CAMERA_MAIN_2_SENSOR == SensorIdx) {
  73. // pinSetIdx = 2;
  74. }
  75. PK_DBG("kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
  76. Rst_PDN_Init();
  77. //power ON
  78. if (On)
  79. {
  80. PK_DBG("kdCISModulePowerOn -on:currSensorName=%s\n",currSensorName);
  81. if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))) {
  82. PK_DBG("is ov5648mipi on\n");
  83. if (0 == pinSetIdx) {
  84. if (TRUE != kd_ov5648_main_poweron(mode_name))
  85. goto _kdCISModulePowerOn_exit_;
  86. } else if (1 == pinSetIdx) {
  87. if (TRUE != kd_ov5648_sub_poweron(mode_name))
  88. goto _kdCISModulePowerOn_exit_;
  89. }
  90. }
  91. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
  92. {
  93. PK_DBG("is s5k4e1ga on \n");
  94. if(TRUE != kd_s5k4e1gamipi_poweron(mode_name))
  95. goto _kdCISModulePowerOn_exit_;
  96. }
  97. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
  98. {
  99. PK_DBG("is hi544 on \n");
  100. if(TRUE != kd_hi544raw_poweron(mode_name))
  101. goto _kdCISModulePowerOn_exit_;
  102. }
  103. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
  104. {
  105. PK_DBG("is gc2235 on\n");
  106. if(TRUE != kd_gc2235mipiraw_poweron(mode_name))
  107. goto _kdCISModulePowerOn_exit_;
  108. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
  109. PK_DBG("is gc2235_raw on\n");
  110. if (TRUE != kd_gc2235raw_poweron(mode_name))
  111. goto _kdCISModulePowerOn_exit_;
  112. }
  113. /*  else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
  114. {
  115. PK_DBG("is hi253 on\n");
  116. if(TRUE != kd_hi253yuv_poweron(mode_name))
  117. goto _kdCISModulePowerOn_exit_;
  118. }*/
  119. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))) {
  120. PK_DBG("is ov88251 on \n");
  121. if(TRUE != kd_ov88251mipiraw_poweron(mode_name))
  122. goto _kdCISModulePowerOn_exit_;
  123. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))) {
  124. PK_DBG("is ov88252 on \n");
  125. if(TRUE != kd_ov88252mipiraw_poweron(mode_name))
  126. goto _kdCISModulePowerOn_exit_;
  127. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
  128. PK_DBG("is ov8858 on \n");
  129. kd_a5142mipiraw_sub_poweron(mode_name);
  130. kd_a5142mipiraw_sub_powerdown(mode_name);
  131. if(TRUE != kd_ov8858mipiraw_poweron(mode_name))
  132. goto _kdCISModulePowerOn_exit_;
  133. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW,currSensorName))) {
  134. PK_DBG("is s5k4h5yx on \n");
  135. kd_a5142mipiraw_sub_poweron(mode_name);
  136. kd_a5142mipiraw_sub_powerdown(mode_name);
  137. if (TRUE != kd_s5k4h5yxmipiraw_poweron(mode_name))
  138. goto _kdCISModulePowerOn_exit_;
  139. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
  140. PK_DBG("is t4k35 on \n");
  141. if(TRUE != kd_t4k35mipiraw_poweron(mode_name))
  142. goto _kdCISModulePowerOn_exit_;
  143. } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  144. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName)))) {
  145. if(pinSetIdx==0)
  146. {
  147. if(TRUE != kd_s5k3h7ymipiraw_poweron(mode_name))
  148. goto _kdCISModulePowerOn_exit_;
  149. }
  150. else
  151. {
  152. if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
  153. goto _kdCISModulePowerOn_exit_;
  154. }
  155. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))) {
  156. PK_DBG("is gc2035 on\n");
  157. if(TRUE != kd_gc2035_poweron(mode_name))
  158. goto _kdCISModulePowerOn_exit_;
  159. }
  160. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
  161. {
  162. if(TRUE != kd_ov5648a_poweron(mode_name))
  163. goto _kdCISModulePowerOn_exit_;
  164. }
  165. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
  166. {
  167. if(TRUE != kd_ov5670_poweron(mode_name))
  168. goto _kdCISModulePowerOn_exit_;
  169. }
  170. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
  171. {
  172. if(TRUE != kd_hi551_poweron(mode_name))
  173. goto _kdCISModulePowerOn_exit_;
  174. }
  175. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
  176. {
  177. if(TRUE != kd_ov5648b_poweron(mode_name))
  178. goto _kdCISModulePowerOn_exit_;
  179. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
  180. {
  181. if(TRUE != kd_ov5648_main_poweron(mode_name))
  182. goto _kdCISModulePowerOn_exit_;
  183. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))) {
  184. PK_DBG("is s5k3h72ymipi on\n");
  185. if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
  186. goto _kdCISModulePowerOn_exit_;
  187. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
  188. {
  189. PK_DBG("is gc0329 on\n");
  190. if(TRUE != kd_gc0329_poweron(mode_name))
  191. goto _kdCISModulePowerOn_exit_;
  192. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
  193. if (0 == pinSetIdx) {
  194. PK_DBG("is A5142 main on \n");
  195. if(TRUE != kd_a5142mipiraw_main_poweron(mode_name))
  196. goto _kdCISModulePowerOn_exit_;
  197. } else {
  198. PK_DBG("is A5142 sub on \n");
  199. if(TRUE != kd_a5142mipiraw_sub_poweron(mode_name))
  200. goto _kdCISModulePowerOn_exit_;
  201. }
  202. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
  203. {
  204. PK_DBG("is gc0312 on\n");
  205. if(TRUE != kd_gc0312_poweron(mode_name))
  206. goto _kdCISModulePowerOn_exit_;
  207. }
  208. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
  209. {
  210. PK_DBG("is hi704 on\n");
  211. if(TRUE != kd_hi704yuv_poweron(mode_name))
  212. goto _kdCISModulePowerOn_exit_;
  213. }
  214. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
  215. {
  216. PK_DBG("is gc0310 on\n");
  217. if(TRUE != kd_gc0310_poweron(mode_name))
  218. goto _kdCISModulePowerOn_exit_;
  219. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
  220. PK_DBG("is gc2145 on\n");
  221. if (TRUE != kd_gc2145_poweron(mode_name))
  222. goto _kdCISModulePowerOn_exit_;
  223. }
  224. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
  225. {
  226. PK_DBG("is hi258 on \n");
  227. if(TRUE != kd_hi258mipiraw_poweron(mode_name))
  228. goto _kdCISModulePowerOn_exit_;
  229. }
  230. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))) {
  231. PK_DBG("is ov2680 on \n");
  232. if(TRUE != kd_ov2680mipiraw_poweron(mode_name))
  233. goto _kdCISModulePowerOn_exit_;
  234. }
  235. else
  236. {
  237. PK_DBG("kdCISModulePowerOn get in---  other , please add the power on code!!!!!!\n");
  238. goto _kdCISModulePowerOn_exit_;
  239. }
  240. }
  241. else {//power OFF
  242. PK_DBG("kdCISModulePowerOn -off:currSensorName=%s\n",currSensorName);
  243. if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName)))
  244. {
  245. PK_DBG("is ov5648_mipi_raw down\n");
  246. if (0 == pinSetIdx) {
  247. if(TRUE != kd_ov5648_main_powerdown(mode_name))
  248. goto _kdCISModulePowerOn_exit_;
  249. } else if (1 == pinSetIdx) {
  250. if(TRUE != kd_ov5648_sub_powerdown(mode_name))
  251. goto _kdCISModulePowerOn_exit_;
  252. }
  253. } else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
  254. {
  255. PK_DBG("is s5k4e1ga down\n");
  256. if(TRUE != kd_s5k4e1gamipi_powerdown(mode_name))
  257. goto _kdCISModulePowerOn_exit_;
  258. }
  259. else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
  260. {
  261. PK_DBG("is hi544 down\n");
  262. if(TRUE != kd_hi544raw_powerdown(mode_name))
  263. goto _kdCISModulePowerOn_exit_;
  264. }
  265. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName)))
  266. {
  267. PK_DBG("is ov88251 down\n");
  268. if(TRUE != kd_ov88251mipiraw_powerdown(mode_name))
  269. goto _kdCISModulePowerOn_exit_;
  270. }
  271. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
  272. {
  273. PK_DBG("is ov5670 down\n");
  274. if(TRUE != kd_ov5670mipiraw_powerdown(mode_name))
  275. goto _kdCISModulePowerOn_exit_;
  276. }
  277. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
  278. {
  279. PK_DBG("is hi551 down\n");
  280. if(TRUE != kd_hi551mipiraw_powerdown(mode_name))
  281. goto _kdCISModulePowerOn_exit_;
  282. }
  283. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName)))
  284. {
  285. PK_DBG("is ov88252 down\n");
  286. if(TRUE != kd_ov88252mipiraw_powerdown(mode_name))
  287. goto _kdCISModulePowerOn_exit_;
  288. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
  289. PK_DBG("is ov8858 down\n");
  290. if(TRUE != kd_ov8858mipiraw_powerdown(mode_name))
  291. goto _kdCISModulePowerOn_exit_;
  292. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))) {
  293. PK_DBG("is s5k4h5yx down\n");
  294. if (TRUE != kd_s5k4h5yxmipiraw_powerdown(mode_name))
  295. goto _kdCISModulePowerOn_exit_;
  296. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
  297. PK_DBG("is t4k35 down\n");
  298. if(TRUE != kd_t4k35mipiraw_powerdown(mode_name))
  299. goto _kdCISModulePowerOn_exit_;
  300. }
  301. else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
  302. {
  303. PK_DBG("is gc2235 down\n");
  304. if(TRUE != kd_gc2235mipiraw_powerdown(mode_name))
  305. goto _kdCISModulePowerOn_exit_;
  306. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
  307. PK_DBG("is gc2235 down\n");
  308. if (TRUE != kd_gc2235raw_powerdown(mode_name))
  309. goto _kdCISModulePowerOn_exit_;
  310. }
  311. /*  else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
  312. {
  313. PK_DBG("is hi253 down\n");
  314. if(TRUE != kd_hi253yuv_powerdown(mode_name))
  315. goto _kdCISModulePowerOn_exit_;
  316. }*/
  317. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
  318. if (0 == pinSetIdx) {
  319. PK_DBG("is A5142 main down \n");
  320. if (TRUE != kd_a5142mipiraw_main_powerdown(mode_name))
  321. goto _kdCISModulePowerOn_exit_;
  322. } else {
  323. PK_DBG("is A5142 sub down \n");
  324. if (TRUE != kd_a5142mipiraw_sub_powerdown(mode_name))
  325. goto _kdCISModulePowerOn_exit_;
  326. }
  327. } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  328. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))))
  329. {
  330. PK_DBG("is s5k3h7 down\n");
  331. if(pinSetIdx==0)
  332. {
  333. if(TRUE != kd_s5k3h7ymipiraw_powerdown(mode_name))
  334. goto _kdCISModulePowerOn_exit_;
  335. }
  336. else {
  337. if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
  338. goto _kdCISModulePowerOn_exit_;
  339. }
  340. }
  341. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
  342. {
  343. PK_DBG("is gc2035 down\n");
  344. if(TRUE != kd_gc2035_powerdown(mode_name))
  345. goto _kdCISModulePowerOn_exit_;
  346. }
  347. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName)))
  348. {
  349. PK_DBG("is s5k3h72y_mipi_raw down\n");
  350. if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
  351. goto _kdCISModulePowerOn_exit_;
  352. }
  353. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
  354. {
  355. if(TRUE != kd_ov5648a_powerdown(mode_name))
  356. goto _kdCISModulePowerOn_exit_;
  357. }
  358. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
  359. {
  360. if(TRUE != kd_ov5648b_powerdown(mode_name))
  361. goto _kdCISModulePowerOn_exit_;
  362. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
  363. {
  364. if(TRUE != kd_ov5648_main_powerdown(mode_name))
  365. goto _kdCISModulePowerOn_exit_;
  366. }
  367. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
  368. {
  369. PK_DBG("is gc0329 down\n");
  370. if(TRUE != kd_gc0329yuv_powerdown(mode_name))
  371. goto _kdCISModulePowerOn_exit_;
  372. }
  373. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
  374. {
  375. PK_DBG("is gc0312 down\n");
  376. if(TRUE != kd_gc0312_powerdown(mode_name))
  377. goto _kdCISModulePowerOn_exit_;
  378. }
  379. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
  380. {
  381. PK_DBG("is hi704 down\n");
  382. if(TRUE != kd_hi704yuv_powerdown(mode_name))
  383. goto _kdCISModulePowerOn_exit_;
  384. }
  385. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
  386. {
  387. PK_DBG("is gc0310 down\n");
  388. if(TRUE != kd_gc0310_powerdown(mode_name))
  389. goto _kdCISModulePowerOn_exit_;
  390. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
  391. PK_DBG("is gc2145 down\n");
  392. if (TRUE != kd_gc2145_powerdown(mode_name))
  393. goto _kdCISModulePowerOn_exit_;
  394. }
  395. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
  396. {
  397. PK_DBG("is hi258 down\n");
  398. if(TRUE != kd_hi258mipiraw_powerdown(mode_name))
  399. goto _kdCISModulePowerOn_exit_;
  400. }
  401. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName)))
  402. {
  403. PK_DBG("is ov2680 down\n");
  404. if(TRUE != kd_ov2680mipiraw_powerdown(mode_name))
  405. goto _kdCISModulePowerOn_exit_;
  406. }
  407. else
  408. {
  409. PK_DBG("kdCISModulePowerDown get in---  other , please add the power down code!!!!!!\n");
  410. goto _kdCISModulePowerOn_exit_;
  411. }
  412. }
  413. return 0;
  414. _kdCISModulePowerOn_exit_:
  415. return -EIO;
  416. }
  417. EXPORT_SYMBOL(kdCISModulePowerOn);

以ov5670为例,其上电code如下:

  1. static int kd_ov5670_poweron( char *mode_name)
  2. {
  3. int ret;
  4. printk("kd_ov5670_poweron1 start..\n");
  5. ret = kd_poweron_main_devices(VOL_1800, VOL_2800, VOL_1200, VOL_2800, mode_name,0);//给camera上三路电
  6. PK_DBG("kd_ov88251mipiraw_poweron start..\n");
  7. mdelay(10);// wait power to be stable
  8. //disable_inactive_sensor();//disable inactive sensor
  9. 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");}
  10. mdelay(10);
  11. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
  12. mdelay(1);
  13. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
  14. 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");}
  15. mdelay(10);
  16. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
  17. mdelay(5);
  18. poweronerr:
  19. return ret;
  20. }

(3.2)获取sensor ID,err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx[i], SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);

此函数调用具体sensor的func,例如ov5670,则调用的

  1. OV5670FeatureControl

===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw

  1. UINT32 OV5670FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
  2. UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
  3. {
  4. UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
  5. UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
  6. UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
  7. UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
  8. UINT32 SensorRegNumber;
  9. UINT32 i;
  10. PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
  11. MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
  12. MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
  13. MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
  14. MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
  15. MSDK_SENSOR_ENG_INFO_STRUCT *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
  16. switch (FeatureId)
  17. {
  18. case SENSOR_FEATURE_GET_RESOLUTION:
  19. *pFeatureReturnPara16++= OV5670_IMAGE_SENSOR_FULL_WIDTH;
  20. *pFeatureReturnPara16= OV5670_IMAGE_SENSOR_FULL_HEIGHT;
  21. *pFeatureParaLen=4;
  22. break;
  23. case SENSOR_FEATURE_GET_PERIOD:
  24. *pFeatureReturnPara16++= OV5670_FeatureControl_PERIOD_PixelNum;
  25. *pFeatureReturnPara16= OV5670_FeatureControl_PERIOD_LineNum;
  26. *pFeatureParaLen=4;
  27. break;
  28. case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
  29. switch(OV5670CurrentScenarioId)
  30. {
  31. case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
  32. *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
  33. *pFeatureParaLen=4;
  34. break;
  35. case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
  36. *pFeatureReturnPara32 = OV5670_VIDEO_PCLK;
  37. *pFeatureParaLen=4;
  38. break;
  39. case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
  40. case MSDK_SCENARIO_ID_CAMERA_ZSD:
  41. *pFeatureReturnPara32 = OV5670_CAPTURE_PCLK;
  42. *pFeatureParaLen=4;
  43. break;
  44. default:
  45. *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
  46. *pFeatureParaLen=4;
  47. break;
  48. }
  49. break;
  50. case SENSOR_FEATURE_SET_ESHUTTER:
  51. OV5670_SetShutter(*pFeatureData16);
  52. break;
  53. case SENSOR_FEATURE_SET_NIGHTMODE:
  54. OV5670_NightMode((BOOL) *pFeatureData16);
  55. break;
  56. case SENSOR_FEATURE_SET_GAIN:
  57. OV5670_SetGain((UINT16) *pFeatureData16);
  58. break;
  59. case SENSOR_FEATURE_SET_FLASHLIGHT:
  60. break;
  61. case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
  62. //OV5670_isp_master_clock=*pFeatureData32;
  63. break;
  64. case SENSOR_FEATURE_SET_REGISTER:
  65. OV5670_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
  66. break;
  67. case SENSOR_FEATURE_GET_REGISTER:
  68. pSensorRegData->RegData = OV5670_read_cmos_sensor(pSensorRegData->RegAddr);
  69. break;
  70. case SENSOR_FEATURE_SET_CCT_REGISTER:
  71. SensorRegNumber=FACTORY_END_ADDR;
  72. for (i=0;i<SensorRegNumber;i++)
  73. {
  74. spin_lock(&ov5670mipiraw_drv_lock);
  75. OV5670SensorCCT[i].Addr=*pFeatureData32++;
  76. OV5670SensorCCT[i].Para=*pFeatureData32++;
  77. spin_unlock(&ov5670mipiraw_drv_lock);
  78. }
  79. break;
  80. case SENSOR_FEATURE_GET_CCT_REGISTER:
  81. SensorRegNumber=FACTORY_END_ADDR;
  82. if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
  83. return FALSE;
  84. *pFeatureData32++=SensorRegNumber;
  85. for (i=0;i<SensorRegNumber;i++)
  86. {
  87. *pFeatureData32++=OV5670SensorCCT[i].Addr;
  88. *pFeatureData32++=OV5670SensorCCT[i].Para;
  89. }
  90. break;
  91. case SENSOR_FEATURE_SET_ENG_REGISTER:
  92. SensorRegNumber=ENGINEER_END;
  93. for (i=0;i<SensorRegNumber;i++)
  94. {
  95. spin_lock(&ov5670mipiraw_drv_lock);
  96. OV5670SensorReg[i].Addr=*pFeatureData32++;
  97. OV5670SensorReg[i].Para=*pFeatureData32++;
  98. spin_unlock(&ov5670mipiraw_drv_lock);
  99. }
  100. break;
  101. case SENSOR_FEATURE_GET_ENG_REGISTER:
  102. SensorRegNumber=ENGINEER_END;
  103. if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
  104. return FALSE;
  105. *pFeatureData32++=SensorRegNumber;
  106. for (i=0;i<SensorRegNumber;i++)
  107. {
  108. *pFeatureData32++=OV5670SensorReg[i].Addr;
  109. *pFeatureData32++=OV5670SensorReg[i].Para;
  110. }
  111. break;
  112. case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
  113. if (*pFeatureParaLen>=sizeof(NVRAM_SENSOR_DATA_STRUCT))
  114. {
  115. pSensorDefaultData->Version=NVRAM_CAMERA_SENSOR_FILE_VERSION;
  116. pSensorDefaultData->SensorId=OV5670_SENSOR_ID;
  117. memcpy(pSensorDefaultData->SensorEngReg, OV5670SensorReg, sizeof(SENSOR_REG_STRUCT)*ENGINEER_END);
  118. memcpy(pSensorDefaultData->SensorCCTReg, OV5670SensorCCT, sizeof(SENSOR_REG_STRUCT)*FACTORY_END_ADDR);
  119. }
  120. else
  121. return FALSE;
  122. *pFeatureParaLen=sizeof(NVRAM_SENSOR_DATA_STRUCT);
  123. break;
  124. case SENSOR_FEATURE_GET_CONFIG_PARA:
  125. memcpy(pSensorConfigData, &OV5670SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
  126. *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
  127. break;
  128. case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
  129. OV5670_camera_para_to_sensor();
  130. break;
  131. case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
  132. OV5670_sensor_to_camera_para();
  133. break;
  134. case SENSOR_FEATURE_GET_GROUP_COUNT:
  135. *pFeatureReturnPara32++=OV5670_get_sensor_group_count();
  136. *pFeatureParaLen=4;
  137. break;
  138. case SENSOR_FEATURE_GET_GROUP_INFO:
  139. OV5670_get_sensor_group_info(pSensorGroupInfo->GroupIdx, pSensorGroupInfo->GroupNamePtr, &pSensorGroupInfo->ItemCount);
  140. *pFeatureParaLen=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
  141. break;
  142. case SENSOR_FEATURE_GET_ITEM_INFO:
  143. OV5670_get_sensor_item_info(pSensorItemInfo->GroupIdx,pSensorItemInfo->ItemIdx, pSensorItemInfo);
  144. *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
  145. break;
  146. case SENSOR_FEATURE_SET_ITEM_INFO:
  147. OV5670_set_sensor_item_info(pSensorItemInfo->GroupIdx, pSensorItemInfo->ItemIdx, pSensorItemInfo->ItemValue);
  148. *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
  149. break;
  150. case SENSOR_FEATURE_GET_ENG_INFO:
  151. pSensorEngInfo->SensorId = 129;
  152. pSensorEngInfo->SensorType = CMOS_SENSOR;
  153. pSensorEngInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_RAW_Gb;
  154. *pFeatureParaLen=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT);
  155. break;
  156. case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
  157. // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
  158. // if EEPROM does not exist in camera module.
  159. *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
  160. *pFeatureParaLen=4;
  161. break;
  162. case SENSOR_FEATURE_INITIALIZE_AF:
  163. break;
  164. case SENSOR_FEATURE_CONSTANT_AF:
  165. break;
  166. case SENSOR_FEATURE_MOVE_FOCUS_LENS:
  167. break;
  168. case SENSOR_FEATURE_SET_VIDEO_MODE:
  169. OV5670SetVideoMode(*pFeatureData16);
  170. break;
  171. case SENSOR_FEATURE_CHECK_SENSOR_ID://-------------调用此处读取ID
  172. OV5670GetSensorID(pFeatureReturnPara32);
  173. break;
  174. case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
  175. OV5670SetAutoFlickerMode((BOOL)*pFeatureData16, *(pFeatureData16+1));
  176. break;
  177. case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO:
  178. OV5670MIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, *(pFeatureData32+1));
  179. break;
  180. case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO:
  181. OV5670MIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, (MUINT32 *)(*(pFeatureData32+1)));
  182. break;
  183. case SENSOR_FEATURE_SET_TEST_PATTERN:
  184. OV5670SetTestPatternMode((BOOL)*pFeatureData16);
  185. break;
  186. case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE://for factory mode auto testing
  187. *pFeatureReturnPara32=OV5670_TEST_PATTERN_CHECKSUM;
  188. *pFeatureParaLen=4;
  189. break;
  190. default:
  191. break;
  192. }
  193. return ERROR_NONE;
  194. }
  1. UINT32 OV5670GetSensorID(UINT32 *sensorID)
  2. {
  3. int  retry = 2;
  4. OV5670DB("OV5670GetSensorID enter :\n ");
  5. mdelay(5);
  6. do {
  7. *sensorID = (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
  8. if (*sensorID == OV5670_SENSOR_ID)
  9. {
  10. OV5670DB("Sensor ID = 0x%04x\n", *sensorID);
  11. break;
  12. }
  13. OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
  14. retry--;
  15. } while (retry > 0);
  16. if (*sensorID != OV5670_SENSOR_ID) {
  17. OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
  18. /*
  19. *sensorID = OV5670_SENSOR_ID;
  20. return ERROR_SENSOR_CONNECT_FAIL;
  21. */
  22. *sensorID = 0xFFFFFFFF;
  23. return ERROR_SENSOR_CONNECT_FAIL;
  24. }
  25. return ERROR_NONE;
  26. }

以上是ov5670获取ID的函数。

一、MTK平台Camera框架

MTK平台的Camera的架构见下图,

MTK Camera 开机启动流程(转载)-LMLPHP

这里主要介绍kernel部分和HAL层部分。

1、Kernel 部分主要有两块:

1.1、image sensordriver,负责具体型号的 sensor 的 id 检测,上电,以及在preview、capture、初始化、3A等等功能设定时的寄存器配置。

1.2、isp driver,通过DMA将sensor数据流上传。

2、HAL层部分主要有三部分组成:

2.1、imageio,主要负责数据buffer上传的pipe。

2.2、drv,包含imgsensor和isp的hal层控制。

2.3、feature io,包含各种3A等性能配置。

二、Camera打开流程分析

Camera开启流程图如下:

MTK Camera 开机启动流程(转载)-LMLPHP

主要发生在两个时间点:

1、开机时:camera完成了sensor框架初始化,id检测并匹配sensor,以及上下电操作。

2、打开Camera应用时:camera会有上电,完成sensor的寄存器初始化配置,向上层传递基本参数和配置信息,以及preview和capture模式循环。

1、开机初始化过程

由于一开始不知道上电camera初始化从哪开始,我们可以借助抓取的mtk mobile log去分析。先看hal层log开始处:

  1. 12-24 10:02:07.601   148   148 D MtkCam/module: [instantiate_camera_module]
  2. 12-24 10:02:07.601   148   148 D MtkCam/Utils/Property: [clear] pid/tid=148/148
  3. 12-24 10:02:07.601   148   148 I CameraService: Loaded "MediaTek Camera Module" camera module
  4. 12-24 10:02:07.601   148   148 D MtkCam/MtkCamUtils: [CamDevMetaInfoMap::clear] pid/tid=148/148
  5. 12-24 10:02:07.601   148   148 D SensorHal: [getInstance][SensorHalImp] getInstance
  6. 12-24 10:02:07.601   148   148 D SensorHal: [createImp][createImp]: 0
  7. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [getInstance][getInstance]
  8. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [SeninfDrvImp][SeninfDrvImp]
  9. 12-24 10:02:07.601   148   148 D SeninfDrvImp: [init][init]: 0

通过sourceinsight搜索发现开始是从CamDeviceManagerImp.cpp函数的enumDeviceLocked()开始。该函数的源代码如下:

===>mediatek/platform/mt6582/hardware/mtkcam/devicemgr/CamDeviceManagerImp.cpp

  1. /******************************************************************************
  2. *
  3. ******************************************************************************/
  4. int32_t
  5. CamDeviceManagerImp::
  6. enumDeviceLocked()
  7. {
  8. Utils::CamProfile _profile(__FUNCTION__, "CamDeviceManagerImp");
  9. //
  10. status_t status = OK;
  11. int32_t i4DeviceNum = 0;
  12. //
  13. mEnumMap.clear();
  14. //------------------------------------------------------------------------------
  15. #if '1'==MTKCAM_HAVE_SENSOR_HAL
  16. mEnumMap.clear();
  17. DevMetaInfo::clear();
  18. //
  19. int32_t isFakeOrientation = 0;
  20. int32_t i4DevSetupOrientation = 0;
  21. camera_info camInfo;
  22. camInfo.device_version = CAMERA_DEVICE_API_VERSION_1_0;
  23. camInfo.static_camera_characteristics = NULL;
  24. //
  25. SensorHal* pSensorHal = SensorHal::createInstance();//创建sensor对象
  26. if  ( ! pSensorHal )
  27. {
  28. MY_LOGE("pSensorHal == NULL");
  29. return 0;
  30. }
  31. //
  32. int32_t const iSensorsList = pSensorHal->searchSensor();//此函数是入口,主要查找匹配的硬件sensor
  33. //
  34. //
  35. if  ( (iSensorsList & SENSOR_DEV_MAIN_3D) == SENSOR_DEV_MAIN_3D )
  36. {
  37. MY_LOGI("Stereo 3D Camera found");
  38. #warning "[TODO] Stereo 3D Camera"
  39. }
  40. //
  41. if  ( (iSensorsList & SENSOR_DEV_MAIN) == SENSOR_DEV_MAIN )
  42. {
  43. int32_t const deviceId = i4DeviceNum;
  44. //
  45. halSensorDev_e const eHalSensorDev = SENSOR_DEV_MAIN;
  46. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
  47. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
  48. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
  49. camInfo.orientation = i4DevSetupOrientation;
  50. if  ( isFakeOrientation )
  51. {
  52. camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
  53. MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
  54. }
  55. DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
  56. //
  57. sp<EnumInfo> pInfo = new EnumInfo;
  58. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  59. pInfo->pMetadata            = NULL;
  60. pInfo->iFacing              = camInfo.facing;
  61. pInfo->iWantedOrientation   = camInfo.orientation;
  62. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  63. mEnumMap.add(deviceId, pInfo);
  64. //
  65. i4DeviceNum++;
  66. }
  67. //
  68. if  ( (iSensorsList & SENSOR_DEV_SUB) == SENSOR_DEV_SUB )
  69. {
  70. int32_t const deviceId = i4DeviceNum;
  71. //
  72. halSensorDev_e const eHalSensorDev = SENSOR_DEV_SUB;
  73. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
  74. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
  75. pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
  76. camInfo.orientation = i4DevSetupOrientation;
  77. if  ( isFakeOrientation )
  78. {
  79. camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
  80. MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
  81. }
  82. DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
  83. //
  84. sp<EnumInfo> pInfo = new EnumInfo;
  85. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  86. pInfo->pMetadata            = NULL;
  87. pInfo->iFacing              = camInfo.facing;
  88. pInfo->iWantedOrientation   = camInfo.orientation;
  89. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  90. mEnumMap.add(deviceId, pInfo);
  91. //
  92. i4DeviceNum++;
  93. }
  94. //
  95. //    if  ( (iSensorsList & SENSOR_DEV_ATV) == SENSOR_DEV_ATV )
  96. {
  97. int32_t const deviceId = 0xFF;
  98. //
  99. halSensorDev_e const eHalSensorDev = SENSOR_DEV_ATV;
  100. camInfo.facing = 0;
  101. camInfo.orientation = 0;
  102. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, eHalSensorDev);
  103. //
  104. sp<EnumInfo> pInfo = new EnumInfo;
  105. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  106. pInfo->pMetadata            = NULL;
  107. pInfo->iFacing              = camInfo.facing;
  108. pInfo->iWantedOrientation   = camInfo.orientation;
  109. pInfo->iSetupOrientation    = i4DevSetupOrientation;
  110. mEnumMap.add(deviceId, pInfo);
  111. //
  112. //        i4DeviceNum++;
  113. }
  114. //
  115. //
  116. if  ( pSensorHal )
  117. {
  118. pSensorHal->destroyInstance();
  119. pSensorHal = NULL;
  120. }
  121. //
  122. MY_LOGI("iSensorsList=0x%08X, i4DeviceNum=%d", iSensorsList, i4DeviceNum);
  123. for (size_t i = 0; i < mEnumMap.size(); i++)
  124. {
  125. int32_t const deviceId = mEnumMap.keyAt(i);
  126. sp<EnumInfo> pInfo = mEnumMap.valueAt(i);
  127. uint32_t const uDeviceVersion   = pInfo->uDeviceVersion;
  128. camera_metadata const*pMetadata = pInfo->pMetadata;
  129. int32_t const iFacing           = pInfo->iFacing;
  130. int32_t const iWantedOrientation= pInfo->iWantedOrientation;
  131. int32_t const iSetupOrientation = pInfo->iSetupOrientation;
  132. MY_LOGI(
  133. "[0x%02x] orientation(wanted/setup)=(%d/%d) facing:%d metadata:%p DeviceVersion:0x%x",
  134. deviceId, iWantedOrientation, iSetupOrientation,
  135. iFacing, pMetadata, uDeviceVersion
  136. );
  137. }
  138. #else   //----------------------------------------------------------------------
  139. #warning "[WARN] Simulation for CamDeviceManagerImp::enumDeviceLocked()"
  140. mEnumMap.clear();
  141. DevMetaInfo::clear();
  142. {
  143. int32_t const deviceId = 0;
  144. //
  145. camera_info camInfo;
  146. camInfo.device_version  = CAMERA_DEVICE_API_VERSION_1_0;
  147. camInfo.static_camera_characteristics = NULL;
  148. camInfo.facing      = 0;
  149. camInfo.orientation = 90;
  150. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_ImgSensor, 0x01/*SENSOR_DEV_MAIN*/);
  151. //
  152. sp<EnumInfo> pInfo = new EnumInfo;
  153. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  154. pInfo->pMetadata            = NULL;
  155. pInfo->iFacing              = 0;
  156. pInfo->iWantedOrientation   = 90;
  157. pInfo->iSetupOrientation    = 90;
  158. mEnumMap.add(deviceId, pInfo);
  159. }
  160. //
  161. {
  162. int32_t const deviceId = 0xFF;
  163. //
  164. camera_info camInfo;
  165. camInfo.device_version  = CAMERA_DEVICE_API_VERSION_1_0;
  166. camInfo.static_camera_characteristics = NULL;
  167. camInfo.facing      = 0;
  168. camInfo.orientation = 0;
  169. DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, 0x04/*SENSOR_DEV_ATV*/);
  170. //
  171. sp<EnumInfo> pInfo = new EnumInfo;
  172. pInfo->uDeviceVersion       = CAMERA_DEVICE_API_VERSION_1_0;
  173. pInfo->pMetadata            = NULL;
  174. pInfo->iFacing              = 0;
  175. pInfo->iWantedOrientation   = 0;
  176. pInfo->iSetupOrientation    = 0;
  177. mEnumMap.add(deviceId, pInfo);
  178. }
  179. //
  180. i4DeviceNum = 1;
  181. #endif
  182. //------------------------------------------------------------------------------
  183. //
  184. _profile.print("");
  185. return  i4DeviceNum;
  186. }

函数pSensorHal->searchSensor()将调用SensorDrv::searchSensor(NULL)函数,该函数再调用ImgSensor_drv.cpp文件中中的ImgSensorDrv::impSearchSensor函数。

===>mediatek/platform/mt6582/hardware/mtkcam/core/drv/imgsensor/ImgSensor_drv.cpp

  1. /*******************************************************************************
  2. *
  3. ********************************************************************************/
  4. MINT32
  5. ImgSensorDrv::impSearchSensor(pfExIdChk pExIdChkCbf)
  6. {
  7. MUINT32 SensorEnum = (MUINT32) DUAL_CAMERA_MAIN_SENSOR;
  8. MUINT32 i,id[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
  9. MBOOL SensorConnect=TRUE;
  10. UCHAR cBuf[64];
  11. MINT32 err = SENSOR_NO_ERROR;
  12. MINT32 err2 = SENSOR_NO_ERROR;
  13. ACDK_SENSOR_INFO_STRUCT SensorInfo;
  14. ACDK_SENSOR_CONFIG_STRUCT SensorConfigData;
  15. ACDK_SENSOR_RESOLUTION_INFO_STRUCT SensorResolution;
  16. MINT32 sensorDevs = SENSOR_NONE;
  17. IMAGE_SENSOR_TYPE sensorType = IMAGE_SENSOR_TYPE_UNKNOWN;
  18. IMGSENSOR_SOCKET_POSITION_ENUM socketPos = IMGSENSOR_SOCKET_POS_NONE;
  19. //! If imp sensor search process already done before,
  20. //! only need to return the sensorDevs, not need to
  21. //! search again.
  22. if (SENSOR_DOES_NOT_EXIST != m_mainSensorId) {
  23. //been processed.
  24. LOG_MSG("[impSearchSensor] Already processed \n");
  25. if (BAD_SENSOR_INDEX != m_mainSensorIdx) {
  26. sensorDevs |= SENSOR_MAIN;
  27. }
  28. if (BAD_SENSOR_INDEX != m_subSensorIdx) {
  29. sensorDevs |= SENSOR_SUB;
  30. }
  31. #ifdef  ATVCHIP_MTK_ENABLE
  32. sensorDevs |= SENSOR_ATV;
  33. #endif
  34. return sensorDevs;
  35. }
  36. GetSensorInitFuncList(&m_pstSensorInitFunc);//----(1)获取hal层的sensor列表
  37. LOG_MSG("SENSOR search start \n");
  38. if (-1 != m_fdSensor) {
  39. ::close(m_fdSensor);
  40. m_fdSensor = -1;
  41. }
  42. sprintf(cBuf,"/dev/%s",CAMERA_HW_DEVNAME);
  43. m_fdSensor = ::open(cBuf, O_RDWR);
  44. if (m_fdSensor < 0) {
  45. LOG_ERR("[impSearchSensor]: error opening %s: %s \n", cBuf, strerror(errno));
  46. return sensorDevs;
  47. }
  48. LOG_MSG("[impSearchSensor] m_fdSensor = %d  \n", m_fdSensor);
  49. // search main/main_2/sub 3 sockets
  50. #ifdef MTK_SUB_IMGSENSOR
  51. for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum <= DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1)  {
  52. LOG_MSG("impSearchSensor search to sub\n");
  53. #else
  54. for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum < DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1)  {
  55. LOG_MSG("impSearchSensor search to main\n");
  56. #endif
  57. //skip atv case
  58. if ( 0x04 == SensorEnum ) continue;
  59. //
  60. for (i = 0; i < MAX_NUM_OF_SUPPORT_SENSOR; i++) {
  61. //end of driver list
  62. if (m_pstSensorInitFunc[i].getCameraDefault == NULL) {
  63. LOG_MSG("m_pstSensorInitFunc[i].getCameraDefault is NULL: %d \n", i);
  64. break;
  65. }
  66. //set sensor driver
  67. id[KDIMGSENSOR_INVOKE_DRIVER_0] = (SensorEnum << KDIMGSENSOR_DUAL_SHIFT) | i;
  68. LOG_MSG("set sensor driver id =%x\n", id[KDIMGSENSOR_INVOKE_DRIVER_0]);
  69. err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,&id[KDIMGSENSOR_INVOKE_DRIVER_0] );//--(2)调用kernel层的kdSetDriver函数
  70. if (err < 0) {
  71. LOG_ERR("ERROR:KDCAMERAHWIOC_X_SET_DRIVER\n");
  72. }
  73. //err = open();
  74. err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE);//---(3)上下电camera并读取sensor的ID,如果匹配则成功
  75. if (err < 0) {
  76. LOG_MSG("[impSearchSensor] Err-ctrlCode (%s) \n", strerror(errno));//
  77. }
  78. //
  79. sensorType = this->getCurrentSensorType((SENSOR_DEV_ENUM)SensorEnum);
  80. //
  81. socketPos = this->getSocketPosition((CAMERA_DUAL_CAMERA_SENSOR_ENUM)SensorEnum);
  82. //check extra ID , from EEPROM maybe
  83. //may need to keep power here
  84. if (NULL != pExIdChkCbf) {
  85. err2 = pExIdChkCbf();
  86. if (err2 < 0) {
  87. LOG_ERR("Error:pExIdChkCbf() \n");
  88. }
  89. }
  90. //power off sensor
  91. close();
  92. if (err < 0 || err2 < 0) {
  93. LOG_MSG("sensor ID mismatch\n");
  94. }
  95. else {
  96. if (SensorEnum == DUAL_CAMERA_MAIN_SENSOR) {
  97. //m_mainSensorIdx = i;
  98. //m_mainSensorId = m_pstSensorInitFunc[m_mainSensorIdx].SensorId;
  99. m_mainSensorDrv.index[m_mainSensorDrv.number] = i;
  100. m_mainSensorDrv.type[m_mainSensorDrv.number] = sensorType;
  101. if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstRawIndex ) {
  102. m_mainSensorDrv.firstRawIndex = i;
  103. }
  104. else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstYuvIndex ) {
  105. m_mainSensorDrv.firstYuvIndex = i;
  106. }
  107. m_mainSensorDrv.position = socketPos;
  108. m_mainSensorDrv.sensorID = m_pstSensorInitFunc[m_mainSensorDrv.index[m_mainSensorDrv.number]].SensorId;
  109. // LOG_MSG("MAIN sensor m_mainSensorDrv.number=%d, m_mainSensorDrv.index=%d\n",m_mainSensorDrv.number,m_mainSensorDrv.index[m_mainSensorDrv.number]);
  110. m_mainSensorDrv.number++;
  111. //
  112. m_pMainSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  113. if  ( m_pMainSensorInfo )
  114. {
  115. NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  116. LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
  117. }
  118. else
  119. {
  120. LOG_WRN("m_pMainSensorInfo==NULL\n");
  121. }
  122. LOG_MSG("MAIN sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
  123. //break;
  124. }
  125. else if (SensorEnum == DUAL_CAMERA_SUB_SENSOR) {
  126. //m_subSensorIdx = i;
  127. //m_subSensorId = m_pstSensorInitFunc[m_subSensorIdx].SensorId;
  128. m_subSensorDrv.index[m_subSensorDrv.number] = i;
  129. m_subSensorDrv.type[m_subSensorDrv.number] = sensorType;
  130. if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstRawIndex ) {
  131. m_subSensorDrv.firstRawIndex = i;
  132. }
  133. else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstYuvIndex ) {
  134. m_subSensorDrv.firstYuvIndex = i;
  135. }
  136. m_subSensorDrv.position = socketPos;
  137. m_subSensorDrv.sensorID = m_pstSensorInitFunc[m_subSensorDrv.index[m_subSensorDrv.number]].SensorId;
  138. //LOG_MSG("SUB sensor m_subSensorDrv.number=%d, m_subSensorDrv.index=%d\n",m_subSensorDrv.number,m_subSensorDrv.index[m_subSensorDrv.number]);
  139. m_subSensorDrv.number++;
  140. //
  141. m_pSubSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  142. if  ( m_pSubSensorInfo )
  143. {
  144. NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc[i].pSensorInfo;
  145. LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
  146. }
  147. else
  148. {
  149. LOG_WRN("m_pSubSensorInfo==NULL\n");
  150. }
  151. LOG_MSG("SUB sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
  152. //break;
  153. }
  154. }//
  155. }
  156. }
  157. //close system call may be off sensor power. check first!!!
  158. ::close(m_fdSensor);
  159. m_fdSensor = -1;
  160. //
  161. if (BAD_SENSOR_INDEX != m_mainSensorDrv.index[0]) {
  162. m_mainSensorId = m_mainSensorDrv.sensorID;
  163. //init to choose first
  164. m_mainSensorIdx = m_mainSensorDrv.index[0];
  165. sensorDevs |= SENSOR_MAIN;
  166. }
  167. if (BAD_SENSOR_INDEX != m_subSensorDrv.index[0]) {
  168. m_subSensorId = m_subSensorDrv.sensorID;
  169. //init to choose first
  170. m_subSensorIdx = m_subSensorDrv.index[0];
  171. sensorDevs |= SENSOR_SUB;
  172. }
  173. #ifdef  ATVCHIP_MTK_ENABLE
  174. sensorDevs |= SENSOR_ATV;
  175. #endif
  176. if (sensorDevs == SENSOR_NONE) {
  177. LOG_ERR( "Error No sensor found!! \n");
  178. }
  179. //
  180. LOG_MSG("SENSOR search end: 0x%x /[0x%x][%d]/[0x%x][%d]\n", sensorDevs,
  181. m_mainSensorId,m_mainSensorIdx,m_subSensorId,m_subSensorIdx);
  182. return sensorDevs;
  183. }//

(1)、获取hal层sensor列表GetSensorInitFuncList(&m_pstSensorInitFunc);

===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp

  1. UINT32 GetSensorInitFuncList(MSDK_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
  2. {
  3. if (NULL == ppSensorList) {
  4. ALOGE("ERROR: NULL pSensorList\n");
  5. return MHAL_UNKNOWN_ERROR;
  6. }
  7. *ppSensorList = &SensorList[0];//这里直接调用hal层的sensor列表
  8. return MHAL_NO_ERROR;
  9. } // GetSensorInitFuncList()

===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp

  1. MSDK_SENSOR_INIT_FUNCTION_STRUCT SensorList[] =
  2. {
  3. //add by zym
  4. #if defined(GC2235_MIPI_RAW)
  5. RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
  6. #endif
  7. // add by zhouzuoyu
  8. #if defined(GC2235_KOTECH_MIPI_RAW)
  9. RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
  10. #endif
  11. #if defined(OV16825_MIPI_RAW)
  12. RAW_INFO(OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW,NULL),
  13. #endif
  14. #if defined(IMX135_MIPI_RAW)
  15. RAW_INFO(IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW,NULL),
  16. #endif
  17. #if defined(OV8830_RAW)
  18. RAW_INFO(OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, NULL),
  19. #endif
  20. /*  ADD sensor driver before this line */
  21. {0,{0},NULL, NULL, NULL}//end of list
  22. };

(2)、获取kernel层的kdSetDriver函数err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,&id[KDIMGSENSOR_INVOKE_DRIVER_0] );

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * kdSetDriver
  3. ********************************************************************************/
  4. int kdSetDriver(unsigned int* pDrvIndex)
  5. {
  6. ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT *pSensorList = NULL;
  7. u32 drvIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
  8. u32 i;
  9. PK_XLOG_INFO("pDrvIndex:0x%08x/0x%08x \n",pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_0],pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_1]);
  10. //set driver for MAIN or SUB sensor
  11. if (0 != kdGetSensorInitFuncList(&pSensorList))//----(2.1)获取kernel层的sensor列表
  12. {
  13. PK_ERR("ERROR:kdGetSensorInitFuncList()\n");
  14. return -EIO;
  15. }
  16. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  17. //
  18. spin_lock(&kdsensor_drv_lock);
  19. g_bEnableDriver[i] = FALSE;
  20. g_invokeSocketIdx[i] = (CAMERA_DUAL_CAMERA_SENSOR_ENUM)((pDrvIndex[i] & KDIMGSENSOR_DUAL_MASK_MSB)>>KDIMGSENSOR_DUAL_SHIFT);
  21. spin_unlock(&kdsensor_drv_lock);
  22. drvIdx[i] = (pDrvIndex[i] & KDIMGSENSOR_DUAL_MASK_LSB);//----(2.2)g_invokeSocketIdx,drvIdx解释
  23. //
  24. if ( DUAL_CAMERA_NONE_SENSOR == g_invokeSocketIdx[i] ) { continue; }
  25. //ToDo: remove print information
  26. PK_XLOG_INFO("[kdSetDriver] i,g_invokeSocketIdx[%d] = %d :\n",i,i,drvIdx[i]);
  27. PK_XLOG_INFO("[kdSetDriver] i,drvIdx[%d] = %d :\n",i,i,drvIdx[i]);
  28. //
  29. if ( MAX_NUM_OF_SUPPORT_SENSOR > drvIdx[i] ) {
  30. if (NULL == pSensorList[drvIdx[i]].SensorInit) {
  31. PK_ERR("ERROR:kdSetDriver()\n");
  32. return -EIO;
  33. }
  34. pSensorList[drvIdx[i]].SensorInit(&g_pInvokeSensorFunc[i]);//----(2.3)获取指定sensor的fun函数,例如ov5670的func
  35. if (NULL == g_pInvokeSensorFunc[i]) {
  36. PK_ERR("ERROR:NULL g_pSensorFunc[%d]\n",i);
  37. return -EIO;
  38. }
  39. //
  40. spin_lock(&kdsensor_drv_lock);
  41. g_bEnableDriver[i] = TRUE;
  42. spin_unlock(&kdsensor_drv_lock);
  43. //get sensor name
  44. memcpy((char*)g_invokeSensorNameStr[i],(char*)pSensorList[drvIdx[i]].drvname,sizeof(pSensorList[drvIdx[i]].drvname));
  45. //return sensor ID
  46. //pDrvIndex[0] = (unsigned int)pSensorList[drvIdx].SensorId;
  47. PK_XLOG_INFO("[kdSetDriver] :[%d][%d][%d][%s][%d]\n",i,g_bEnableDriver[i],g_invokeSocketIdx[i],g_invokeSensorNameStr[i],sizeof(pSensorList[drvIdx[i]].drvname));
  48. }
  49. }
  50. return 0;
  51. }

(2.1)获取kernel层的sensor列表kdGetSensorInitFuncList(&pSensorList)

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * general camera image sensor kernel driver
  3. *******************************************************************************/
  4. UINT32 kdGetSensorInitFuncList(ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
  5. {
  6. if (NULL == ppSensorList)
  7. {
  8. PK_DBG("[kdGetSensorInitFuncList]ERROR: NULL ppSensorList\n");
  9. return 1;
  10. }
  11. *ppSensorList = &kdSensorList[0];
  12. return 0;
  13. } // kdGetSensorInitFuncList()

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.h

hal层和kernel层的sensor列表顺序必须保持一致

  1. ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
  2. {
  3. //add by zym
  4. #if defined(GC2235_MIPI_RAW)
  5. {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
  6. #endif
  7. // add by zhouzuoyu
  8. #if defined(GC2235_KOTECH_MIPI_RAW)
  9. {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
  10. #endif
  11. #if defined(OV16825_MIPI_RAW)
  12. {OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW, OV16825MIPISensorInit},
  13. #endif
  14. #if defined(IMX135_MIPI_RAW)
  15. {IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW, IMX135_MIPI_RAW_SensorInit},
  16. #endif
  17. #if defined(OV8830_RAW)
  18. {OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, OV8830SensorInit},
  19. #endif
  20. /*  ADD sensor driver before this line */
  21. {0,{0},NULL}, //end of list
  22. };
  23. //e_add new sensor driver here<span style="font-size:18px;"><span style="font-size:18px;">         </span>   </span>   <span style="font-size:18px;"><span style="font-size:18px;">
  24. </span></span>

(2.2)g_invokeSocketIdx,drvIdx解释

上层传下来的 id 参数解析成两部分 g_invokeSocketIdx 区分目前正在匹配的是 main 还是sub,drvIdx 是 sensor 列表的序列号 。

(2.3)获取指定sensor的func函数,例如ov5670的func,pSensorList[drvIdx[i]].SensorInit(&g_pInvokeSensorFunc[i]);

调用的函数是OV5670_MIPI_RAW_SensorInit()。

  1. #if defined(OV5670_MIPI_RAW)
  2. {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit},
  3. #endif

===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw/ov5670mipiraw_Sensor.c

  1. SENSOR_FUNCTION_STRUCT  SensorFuncOV5670=
  2. {
  3. OV5670Open,
  4. OV5670GetInfo,
  5. OV5670GetResolution,
  6. OV5670FeatureControl,
  7. OV5670Control,
  8. OV5670Close
  9. };
  10. UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)//---调用此函数
  11. {
  12. if (pfFunc!=NULL)
  13. *pfFunc=&SensorFuncOV5670;
  14. return ERROR_NONE;
  15. }

5670的sensorinit实现,主要是未了pfFunc这个函数指针的结构体指针赋值,这样我们就实现了驱动代码的分离,hal层只需要调用sensorlist.c这样一个虚拟设备的驱动,就可以和具体的Sensor Driver驱动通信。这样的做法与platform driver的设计思想差不多,在tp,lcm等驱动中也有体现。

(3)上下电camera并读取ID,err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE);

===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c

  1. /*******************************************************************************
  2. * adopt_CAMERA_HW_CheckIsAlive
  3. ********************************************************************************/
  4. inline static int adopt_CAMERA_HW_CheckIsAlive(void)
  5. {
  6. UINT32 err = 0;
  7. UINT32 err1 = 0;
  8. UINT32 i = 0;
  9. MUINT32 sensorID = 0;
  10. MUINT32 retLen = 0;
  11. KD_IMGSENSOR_PROFILE_INIT();
  12. //power on sensor
  13. kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);//----(3.1)sensor上电
  14. //wait for power stable
  15. mDELAY(10);
  16. KD_IMGSENSOR_PROFILE("kdModulePowerOn");
  17. if (g_pSensorFunc) {
  18. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  19. if(DUAL_CAMERA_NONE_SENSOR != g_invokeSocketIdx[i]){
  20. err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx[i], SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);//---(3.2)获取sensor ID
  21. if (sensorID == 0) {    //not implement this feature ID
  22. PK_DBG(" Not implement!!, use old open function to check\n");
  23. err = ERROR_SENSOR_CONNECT_FAIL;
  24. }
  25. else if (sensorID == 0xFFFFFFFF) {    //fail to open the sensor
  26. PK_DBG(" No Sensor Found");
  27. err = ERROR_SENSOR_CONNECT_FAIL;
  28. }
  29. else {
  30. PK_DBG(" Sensor found ID = 0x%x\n", sensorID);
  31. err = ERROR_NONE;
  32. }
  33. if(ERROR_NONE != err)
  34. {
  35. PK_DBG("ERROR:adopt_CAMERA_HW_CheckIsAlive(), No imgsensor alive \n");
  36. }
  37. }
  38. }
  39. }
  40. else {
  41. PK_DBG("ERROR:NULL g_pSensorFunc\n");
  42. }
  43. //reset sensor state after power off
  44. err1 = g_pSensorFunc->SensorClose();
  45. if(ERROR_NONE != err1) {
  46. PK_DBG("SensorClose \n");
  47. }
  48. //
  49. kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr, false, CAMERA_HW_DRVNAME1);
  50. //
  51. KD_IMGSENSOR_PROFILE("CheckIsAlive");
  52. return err?-EIO:err;
  53. }   /* adopt_CAMERA_HW_Open() */

(3.1)Sensor 上电, kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);

  1. /*******************************************************************************
  2. * kdModulePowerOn
  3. ********************************************************************************/
  4. int
  5. kdModulePowerOn(
  6. CAMERA_DUAL_CAMERA_SENSOR_ENUM socketIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS],
  7. char sensorNameStr[KDIMGSENSOR_MAX_INVOKE_DRIVERS][32],
  8. BOOL On,
  9. char* mode_name )
  10. {
  11. MINT32 ret = ERROR_NONE;
  12. u32 i = 0;
  13. for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
  14. if ( g_bEnableDriver[i] ) {
  15. //PK_XLOG_INFO("[%s][%d][%d][%s][%s]\r\n",__FUNCTION__,g_bEnableDriver[i],socketIdx[i],sensorNameStr[i],mode_name);
  16. ret = kdCISModulePowerOn(socketIdx[i],sensorNameStr[i],On,mode_name);//实际上电的func
  17. if ( ERROR_NONE != ret ) {
  18. PK_ERR("[%s]",__FUNCTION__);
  19. return ret;
  20. }
  21. }
  22. }
  23. return ERROR_NONE;
  24. }

===>mediatek/custom/huaqin82_slwt_2s_td/kernel/camera/camera/kd_camera_hw.c

  1. int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSensorName, BOOL On, char* mode_name)
  2. {
  3. PK_DBG("[camera] **kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
  4. //dump_stack();
  5. if (DUAL_CAMERA_MAIN_SENSOR == SensorIdx){
  6. if (currSensorName &&
  7. ((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  8. ||(0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))
  9. ||(0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))
  10. ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  11. ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))
  12. ||(0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName))
  13. ||(0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
  14. ||(0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName))
  15. || (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))
  16. || (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))
  17. ||(0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName))
  18. ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
  19. ||(0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))
  20. ||(0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))
  21. ||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
  22. || (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV, currSensorName))
  23. ||(0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))
  24. ||(0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName))
  25. ||(0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName))
  26. //|| to add other main camera here
  27. ))
  28. pinSetIdx = 0;
  29. else
  30. {
  31. PK_DBG("[ryf-main]kdCISModulePowerOn get in---  sensorIdx not compare with sensor name: %s\n", currSensorName);
  32. //if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
  33. //{
  34. //      pinSetIdx = 1;
  35. //}
  36. //else{
  37. goto _kdCISModulePowerOn_exit_;
  38. //}
  39. }
  40. }
  41. else if (DUAL_CAMERA_SUB_SENSOR == SensorIdx) {
  42. if (currSensorName &&
  43. ((0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))
  44. || (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))
  45. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW, currSensorName))
  46. || (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName))
  47. || (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName))
  48. || (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName))
  49. || (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
  50. || (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  51. || (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))
  52. ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
  53. ||(0 == strcmp(SENSOR_DRVNAME_GC0312_YUV, currSensorName))
  54. ||(0 == strcmp(SENSOR_DRVNAME_HI704_YUV, currSensorName))
  55. //||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
  56. //|| to add other sub camera here
  57. ))
  58. pinSetIdx = 1;
  59. else
  60. {
  61. //if (currSensorName &&
  62. //((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
  63. //|| to add other main camera here
  64. //))
  65. //{
  66. //  pinSetIdx = 0;
  67. //}
  68. PK_DBG("{ryf-sub}kdCISModulePowerOn get in---  sensorIdx not compare with sensro:%s\n",currSensorName);
  69. goto _kdCISModulePowerOn_exit_;
  70. }
  71. }
  72. else if (DUAL_CAMERA_MAIN_2_SENSOR == SensorIdx) {
  73. // pinSetIdx = 2;
  74. }
  75. PK_DBG("kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
  76. Rst_PDN_Init();
  77. //power ON
  78. if (On)
  79. {
  80. PK_DBG("kdCISModulePowerOn -on:currSensorName=%s\n",currSensorName);
  81. if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))) {
  82. PK_DBG("is ov5648mipi on\n");
  83. if (0 == pinSetIdx) {
  84. if (TRUE != kd_ov5648_main_poweron(mode_name))
  85. goto _kdCISModulePowerOn_exit_;
  86. } else if (1 == pinSetIdx) {
  87. if (TRUE != kd_ov5648_sub_poweron(mode_name))
  88. goto _kdCISModulePowerOn_exit_;
  89. }
  90. }
  91. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
  92. {
  93. PK_DBG("is s5k4e1ga on \n");
  94. if(TRUE != kd_s5k4e1gamipi_poweron(mode_name))
  95. goto _kdCISModulePowerOn_exit_;
  96. }
  97. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
  98. {
  99. PK_DBG("is hi544 on \n");
  100. if(TRUE != kd_hi544raw_poweron(mode_name))
  101. goto _kdCISModulePowerOn_exit_;
  102. }
  103. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
  104. {
  105. PK_DBG("is gc2235 on\n");
  106. if(TRUE != kd_gc2235mipiraw_poweron(mode_name))
  107. goto _kdCISModulePowerOn_exit_;
  108. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
  109. PK_DBG("is gc2235_raw on\n");
  110. if (TRUE != kd_gc2235raw_poweron(mode_name))
  111. goto _kdCISModulePowerOn_exit_;
  112. }
  113. /*  else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
  114. {
  115. PK_DBG("is hi253 on\n");
  116. if(TRUE != kd_hi253yuv_poweron(mode_name))
  117. goto _kdCISModulePowerOn_exit_;
  118. }*/
  119. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))) {
  120. PK_DBG("is ov88251 on \n");
  121. if(TRUE != kd_ov88251mipiraw_poweron(mode_name))
  122. goto _kdCISModulePowerOn_exit_;
  123. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))) {
  124. PK_DBG("is ov88252 on \n");
  125. if(TRUE != kd_ov88252mipiraw_poweron(mode_name))
  126. goto _kdCISModulePowerOn_exit_;
  127. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
  128. PK_DBG("is ov8858 on \n");
  129. kd_a5142mipiraw_sub_poweron(mode_name);
  130. kd_a5142mipiraw_sub_powerdown(mode_name);
  131. if(TRUE != kd_ov8858mipiraw_poweron(mode_name))
  132. goto _kdCISModulePowerOn_exit_;
  133. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW,currSensorName))) {
  134. PK_DBG("is s5k4h5yx on \n");
  135. kd_a5142mipiraw_sub_poweron(mode_name);
  136. kd_a5142mipiraw_sub_powerdown(mode_name);
  137. if (TRUE != kd_s5k4h5yxmipiraw_poweron(mode_name))
  138. goto _kdCISModulePowerOn_exit_;
  139. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
  140. PK_DBG("is t4k35 on \n");
  141. if(TRUE != kd_t4k35mipiraw_poweron(mode_name))
  142. goto _kdCISModulePowerOn_exit_;
  143. } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  144. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName)))) {
  145. if(pinSetIdx==0)
  146. {
  147. if(TRUE != kd_s5k3h7ymipiraw_poweron(mode_name))
  148. goto _kdCISModulePowerOn_exit_;
  149. }
  150. else
  151. {
  152. if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
  153. goto _kdCISModulePowerOn_exit_;
  154. }
  155. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))) {
  156. PK_DBG("is gc2035 on\n");
  157. if(TRUE != kd_gc2035_poweron(mode_name))
  158. goto _kdCISModulePowerOn_exit_;
  159. }
  160. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
  161. {
  162. if(TRUE != kd_ov5648a_poweron(mode_name))
  163. goto _kdCISModulePowerOn_exit_;
  164. }
  165. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
  166. {
  167. if(TRUE != kd_ov5670_poweron(mode_name))
  168. goto _kdCISModulePowerOn_exit_;
  169. }
  170. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
  171. {
  172. if(TRUE != kd_hi551_poweron(mode_name))
  173. goto _kdCISModulePowerOn_exit_;
  174. }
  175. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
  176. {
  177. if(TRUE != kd_ov5648b_poweron(mode_name))
  178. goto _kdCISModulePowerOn_exit_;
  179. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
  180. {
  181. if(TRUE != kd_ov5648_main_poweron(mode_name))
  182. goto _kdCISModulePowerOn_exit_;
  183. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))) {
  184. PK_DBG("is s5k3h72ymipi on\n");
  185. if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
  186. goto _kdCISModulePowerOn_exit_;
  187. } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
  188. {
  189. PK_DBG("is gc0329 on\n");
  190. if(TRUE != kd_gc0329_poweron(mode_name))
  191. goto _kdCISModulePowerOn_exit_;
  192. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
  193. if (0 == pinSetIdx) {
  194. PK_DBG("is A5142 main on \n");
  195. if(TRUE != kd_a5142mipiraw_main_poweron(mode_name))
  196. goto _kdCISModulePowerOn_exit_;
  197. } else {
  198. PK_DBG("is A5142 sub on \n");
  199. if(TRUE != kd_a5142mipiraw_sub_poweron(mode_name))
  200. goto _kdCISModulePowerOn_exit_;
  201. }
  202. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
  203. {
  204. PK_DBG("is gc0312 on\n");
  205. if(TRUE != kd_gc0312_poweron(mode_name))
  206. goto _kdCISModulePowerOn_exit_;
  207. }
  208. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
  209. {
  210. PK_DBG("is hi704 on\n");
  211. if(TRUE != kd_hi704yuv_poweron(mode_name))
  212. goto _kdCISModulePowerOn_exit_;
  213. }
  214. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
  215. {
  216. PK_DBG("is gc0310 on\n");
  217. if(TRUE != kd_gc0310_poweron(mode_name))
  218. goto _kdCISModulePowerOn_exit_;
  219. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
  220. PK_DBG("is gc2145 on\n");
  221. if (TRUE != kd_gc2145_poweron(mode_name))
  222. goto _kdCISModulePowerOn_exit_;
  223. }
  224. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
  225. {
  226. PK_DBG("is hi258 on \n");
  227. if(TRUE != kd_hi258mipiraw_poweron(mode_name))
  228. goto _kdCISModulePowerOn_exit_;
  229. }
  230. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))) {
  231. PK_DBG("is ov2680 on \n");
  232. if(TRUE != kd_ov2680mipiraw_poweron(mode_name))
  233. goto _kdCISModulePowerOn_exit_;
  234. }
  235. else
  236. {
  237. PK_DBG("kdCISModulePowerOn get in---  other , please add the power on code!!!!!!\n");
  238. goto _kdCISModulePowerOn_exit_;
  239. }
  240. }
  241. else {//power OFF
  242. PK_DBG("kdCISModulePowerOn -off:currSensorName=%s\n",currSensorName);
  243. if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName)))
  244. {
  245. PK_DBG("is ov5648_mipi_raw down\n");
  246. if (0 == pinSetIdx) {
  247. if(TRUE != kd_ov5648_main_powerdown(mode_name))
  248. goto _kdCISModulePowerOn_exit_;
  249. } else if (1 == pinSetIdx) {
  250. if(TRUE != kd_ov5648_sub_powerdown(mode_name))
  251. goto _kdCISModulePowerOn_exit_;
  252. }
  253. } else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
  254. {
  255. PK_DBG("is s5k4e1ga down\n");
  256. if(TRUE != kd_s5k4e1gamipi_powerdown(mode_name))
  257. goto _kdCISModulePowerOn_exit_;
  258. }
  259. else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
  260. {
  261. PK_DBG("is hi544 down\n");
  262. if(TRUE != kd_hi544raw_powerdown(mode_name))
  263. goto _kdCISModulePowerOn_exit_;
  264. }
  265. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName)))
  266. {
  267. PK_DBG("is ov88251 down\n");
  268. if(TRUE != kd_ov88251mipiraw_powerdown(mode_name))
  269. goto _kdCISModulePowerOn_exit_;
  270. }
  271. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
  272. {
  273. PK_DBG("is ov5670 down\n");
  274. if(TRUE != kd_ov5670mipiraw_powerdown(mode_name))
  275. goto _kdCISModulePowerOn_exit_;
  276. }
  277. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
  278. {
  279. PK_DBG("is hi551 down\n");
  280. if(TRUE != kd_hi551mipiraw_powerdown(mode_name))
  281. goto _kdCISModulePowerOn_exit_;
  282. }
  283. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName)))
  284. {
  285. PK_DBG("is ov88252 down\n");
  286. if(TRUE != kd_ov88252mipiraw_powerdown(mode_name))
  287. goto _kdCISModulePowerOn_exit_;
  288. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
  289. PK_DBG("is ov8858 down\n");
  290. if(TRUE != kd_ov8858mipiraw_powerdown(mode_name))
  291. goto _kdCISModulePowerOn_exit_;
  292. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))) {
  293. PK_DBG("is s5k4h5yx down\n");
  294. if (TRUE != kd_s5k4h5yxmipiraw_powerdown(mode_name))
  295. goto _kdCISModulePowerOn_exit_;
  296. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
  297. PK_DBG("is t4k35 down\n");
  298. if(TRUE != kd_t4k35mipiraw_powerdown(mode_name))
  299. goto _kdCISModulePowerOn_exit_;
  300. }
  301. else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
  302. {
  303. PK_DBG("is gc2235 down\n");
  304. if(TRUE != kd_gc2235mipiraw_powerdown(mode_name))
  305. goto _kdCISModulePowerOn_exit_;
  306. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
  307. PK_DBG("is gc2235 down\n");
  308. if (TRUE != kd_gc2235raw_powerdown(mode_name))
  309. goto _kdCISModulePowerOn_exit_;
  310. }
  311. /*  else  if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
  312. {
  313. PK_DBG("is hi253 down\n");
  314. if(TRUE != kd_hi253yuv_powerdown(mode_name))
  315. goto _kdCISModulePowerOn_exit_;
  316. }*/
  317. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
  318. if (0 == pinSetIdx) {
  319. PK_DBG("is A5142 main down \n");
  320. if (TRUE != kd_a5142mipiraw_main_powerdown(mode_name))
  321. goto _kdCISModulePowerOn_exit_;
  322. } else {
  323. PK_DBG("is A5142 sub down \n");
  324. if (TRUE != kd_a5142mipiraw_sub_powerdown(mode_name))
  325. goto _kdCISModulePowerOn_exit_;
  326. }
  327. } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
  328. || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))))
  329. {
  330. PK_DBG("is s5k3h7 down\n");
  331. if(pinSetIdx==0)
  332. {
  333. if(TRUE != kd_s5k3h7ymipiraw_powerdown(mode_name))
  334. goto _kdCISModulePowerOn_exit_;
  335. }
  336. else {
  337. if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
  338. goto _kdCISModulePowerOn_exit_;
  339. }
  340. }
  341. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
  342. {
  343. PK_DBG("is gc2035 down\n");
  344. if(TRUE != kd_gc2035_powerdown(mode_name))
  345. goto _kdCISModulePowerOn_exit_;
  346. }
  347. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName)))
  348. {
  349. PK_DBG("is s5k3h72y_mipi_raw down\n");
  350. if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
  351. goto _kdCISModulePowerOn_exit_;
  352. }
  353. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
  354. {
  355. if(TRUE != kd_ov5648a_powerdown(mode_name))
  356. goto _kdCISModulePowerOn_exit_;
  357. }
  358. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
  359. {
  360. if(TRUE != kd_ov5648b_powerdown(mode_name))
  361. goto _kdCISModulePowerOn_exit_;
  362. }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
  363. {
  364. if(TRUE != kd_ov5648_main_powerdown(mode_name))
  365. goto _kdCISModulePowerOn_exit_;
  366. }
  367. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
  368. {
  369. PK_DBG("is gc0329 down\n");
  370. if(TRUE != kd_gc0329yuv_powerdown(mode_name))
  371. goto _kdCISModulePowerOn_exit_;
  372. }
  373. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
  374. {
  375. PK_DBG("is gc0312 down\n");
  376. if(TRUE != kd_gc0312_powerdown(mode_name))
  377. goto _kdCISModulePowerOn_exit_;
  378. }
  379. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
  380. {
  381. PK_DBG("is hi704 down\n");
  382. if(TRUE != kd_hi704yuv_powerdown(mode_name))
  383. goto _kdCISModulePowerOn_exit_;
  384. }
  385. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
  386. {
  387. PK_DBG("is gc0310 down\n");
  388. if(TRUE != kd_gc0310_powerdown(mode_name))
  389. goto _kdCISModulePowerOn_exit_;
  390. } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
  391. PK_DBG("is gc2145 down\n");
  392. if (TRUE != kd_gc2145_powerdown(mode_name))
  393. goto _kdCISModulePowerOn_exit_;
  394. }
  395. else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
  396. {
  397. PK_DBG("is hi258 down\n");
  398. if(TRUE != kd_hi258mipiraw_powerdown(mode_name))
  399. goto _kdCISModulePowerOn_exit_;
  400. }
  401. else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName)))
  402. {
  403. PK_DBG("is ov2680 down\n");
  404. if(TRUE != kd_ov2680mipiraw_powerdown(mode_name))
  405. goto _kdCISModulePowerOn_exit_;
  406. }
  407. else
  408. {
  409. PK_DBG("kdCISModulePowerDown get in---  other , please add the power down code!!!!!!\n");
  410. goto _kdCISModulePowerOn_exit_;
  411. }
  412. }
  413. return 0;
  414. _kdCISModulePowerOn_exit_:
  415. return -EIO;
  416. }
  417. EXPORT_SYMBOL(kdCISModulePowerOn);

以ov5670为例,其上电code如下:

  1. static int kd_ov5670_poweron( char *mode_name)
  2. {
  3. int ret;
  4. printk("kd_ov5670_poweron1 start..\n");
  5. ret = kd_poweron_main_devices(VOL_1800, VOL_2800, VOL_1200, VOL_2800, mode_name,0);//给camera上三路电
  6. PK_DBG("kd_ov88251mipiraw_poweron start..\n");
  7. mdelay(10);// wait power to be stable
  8. //disable_inactive_sensor();//disable inactive sensor
  9. 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");}
  10. mdelay(10);
  11. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN+IDX_PS_ON])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
  12. mdelay(1);
  13. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
  14. 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");}
  15. mdelay(10);
  16. if(mt_set_gpio_out(pinSet[0][IDX_PS_CMRST],pinSet[0][IDX_PS_CMRST+IDX_PS_ON])){PK_DBG("[CAMERA SENSOR] set gpio failed!! \n");}
  17. mdelay(5);
  18. poweronerr:
  19. return ret;
  20. }

(3.2)获取sensor ID,err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx[i], SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);

此函数调用具体sensor的func,例如ov5670,则调用的

  1. OV5670FeatureControl

===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw

  1. UINT32 OV5670FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
  2. UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
  3. {
  4. UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
  5. UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
  6. UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
  7. UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
  8. UINT32 SensorRegNumber;
  9. UINT32 i;
  10. PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
  11. MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
  12. MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
  13. MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
  14. MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
  15. MSDK_SENSOR_ENG_INFO_STRUCT *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
  16. switch (FeatureId)
  17. {
  18. case SENSOR_FEATURE_GET_RESOLUTION:
  19. *pFeatureReturnPara16++= OV5670_IMAGE_SENSOR_FULL_WIDTH;
  20. *pFeatureReturnPara16= OV5670_IMAGE_SENSOR_FULL_HEIGHT;
  21. *pFeatureParaLen=4;
  22. break;
  23. case SENSOR_FEATURE_GET_PERIOD:
  24. *pFeatureReturnPara16++= OV5670_FeatureControl_PERIOD_PixelNum;
  25. *pFeatureReturnPara16= OV5670_FeatureControl_PERIOD_LineNum;
  26. *pFeatureParaLen=4;
  27. break;
  28. case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
  29. switch(OV5670CurrentScenarioId)
  30. {
  31. case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
  32. *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
  33. *pFeatureParaLen=4;
  34. break;
  35. case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
  36. *pFeatureReturnPara32 = OV5670_VIDEO_PCLK;
  37. *pFeatureParaLen=4;
  38. break;
  39. case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
  40. case MSDK_SCENARIO_ID_CAMERA_ZSD:
  41. *pFeatureReturnPara32 = OV5670_CAPTURE_PCLK;
  42. *pFeatureParaLen=4;
  43. break;
  44. default:
  45. *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
  46. *pFeatureParaLen=4;
  47. break;
  48. }
  49. break;
  50. case SENSOR_FEATURE_SET_ESHUTTER:
  51. OV5670_SetShutter(*pFeatureData16);
  52. break;
  53. case SENSOR_FEATURE_SET_NIGHTMODE:
  54. OV5670_NightMode((BOOL) *pFeatureData16);
  55. break;
  56. case SENSOR_FEATURE_SET_GAIN:
  57. OV5670_SetGain((UINT16) *pFeatureData16);
  58. break;
  59. case SENSOR_FEATURE_SET_FLASHLIGHT:
  60. break;
  61. case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
  62. //OV5670_isp_master_clock=*pFeatureData32;
  63. break;
  64. case SENSOR_FEATURE_SET_REGISTER:
  65. OV5670_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
  66. break;
  67. case SENSOR_FEATURE_GET_REGISTER:
  68. pSensorRegData->RegData = OV5670_read_cmos_sensor(pSensorRegData->RegAddr);
  69. break;
  70. case SENSOR_FEATURE_SET_CCT_REGISTER:
  71. SensorRegNumber=FACTORY_END_ADDR;
  72. for (i=0;i<SensorRegNumber;i++)
  73. {
  74. spin_lock(&ov5670mipiraw_drv_lock);
  75. OV5670SensorCCT[i].Addr=*pFeatureData32++;
  76. OV5670SensorCCT[i].Para=*pFeatureData32++;
  77. spin_unlock(&ov5670mipiraw_drv_lock);
  78. }
  79. break;
  80. case SENSOR_FEATURE_GET_CCT_REGISTER:
  81. SensorRegNumber=FACTORY_END_ADDR;
  82. if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
  83. return FALSE;
  84. *pFeatureData32++=SensorRegNumber;
  85. for (i=0;i<SensorRegNumber;i++)
  86. {
  87. *pFeatureData32++=OV5670SensorCCT[i].Addr;
  88. *pFeatureData32++=OV5670SensorCCT[i].Para;
  89. }
  90. break;
  91. case SENSOR_FEATURE_SET_ENG_REGISTER:
  92. SensorRegNumber=ENGINEER_END;
  93. for (i=0;i<SensorRegNumber;i++)
  94. {
  95. spin_lock(&ov5670mipiraw_drv_lock);
  96. OV5670SensorReg[i].Addr=*pFeatureData32++;
  97. OV5670SensorReg[i].Para=*pFeatureData32++;
  98. spin_unlock(&ov5670mipiraw_drv_lock);
  99. }
  100. break;
  101. case SENSOR_FEATURE_GET_ENG_REGISTER:
  102. SensorRegNumber=ENGINEER_END;
  103. if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
  104. return FALSE;
  105. *pFeatureData32++=SensorRegNumber;
  106. for (i=0;i<SensorRegNumber;i++)
  107. {
  108. *pFeatureData32++=OV5670SensorReg[i].Addr;
  109. *pFeatureData32++=OV5670SensorReg[i].Para;
  110. }
  111. break;
  112. case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
  113. if (*pFeatureParaLen>=sizeof(NVRAM_SENSOR_DATA_STRUCT))
  114. {
  115. pSensorDefaultData->Version=NVRAM_CAMERA_SENSOR_FILE_VERSION;
  116. pSensorDefaultData->SensorId=OV5670_SENSOR_ID;
  117. memcpy(pSensorDefaultData->SensorEngReg, OV5670SensorReg, sizeof(SENSOR_REG_STRUCT)*ENGINEER_END);
  118. memcpy(pSensorDefaultData->SensorCCTReg, OV5670SensorCCT, sizeof(SENSOR_REG_STRUCT)*FACTORY_END_ADDR);
  119. }
  120. else
  121. return FALSE;
  122. *pFeatureParaLen=sizeof(NVRAM_SENSOR_DATA_STRUCT);
  123. break;
  124. case SENSOR_FEATURE_GET_CONFIG_PARA:
  125. memcpy(pSensorConfigData, &OV5670SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
  126. *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
  127. break;
  128. case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
  129. OV5670_camera_para_to_sensor();
  130. break;
  131. case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
  132. OV5670_sensor_to_camera_para();
  133. break;
  134. case SENSOR_FEATURE_GET_GROUP_COUNT:
  135. *pFeatureReturnPara32++=OV5670_get_sensor_group_count();
  136. *pFeatureParaLen=4;
  137. break;
  138. case SENSOR_FEATURE_GET_GROUP_INFO:
  139. OV5670_get_sensor_group_info(pSensorGroupInfo->GroupIdx, pSensorGroupInfo->GroupNamePtr, &pSensorGroupInfo->ItemCount);
  140. *pFeatureParaLen=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
  141. break;
  142. case SENSOR_FEATURE_GET_ITEM_INFO:
  143. OV5670_get_sensor_item_info(pSensorItemInfo->GroupIdx,pSensorItemInfo->ItemIdx, pSensorItemInfo);
  144. *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
  145. break;
  146. case SENSOR_FEATURE_SET_ITEM_INFO:
  147. OV5670_set_sensor_item_info(pSensorItemInfo->GroupIdx, pSensorItemInfo->ItemIdx, pSensorItemInfo->ItemValue);
  148. *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
  149. break;
  150. case SENSOR_FEATURE_GET_ENG_INFO:
  151. pSensorEngInfo->SensorId = 129;
  152. pSensorEngInfo->SensorType = CMOS_SENSOR;
  153. pSensorEngInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_RAW_Gb;
  154. *pFeatureParaLen=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT);
  155. break;
  156. case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
  157. // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
  158. // if EEPROM does not exist in camera module.
  159. *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
  160. *pFeatureParaLen=4;
  161. break;
  162. case SENSOR_FEATURE_INITIALIZE_AF:
  163. break;
  164. case SENSOR_FEATURE_CONSTANT_AF:
  165. break;
  166. case SENSOR_FEATURE_MOVE_FOCUS_LENS:
  167. break;
  168. case SENSOR_FEATURE_SET_VIDEO_MODE:
  169. OV5670SetVideoMode(*pFeatureData16);
  170. break;
  171. case SENSOR_FEATURE_CHECK_SENSOR_ID://-------------调用此处读取ID
  172. OV5670GetSensorID(pFeatureReturnPara32);
  173. break;
  174. case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
  175. OV5670SetAutoFlickerMode((BOOL)*pFeatureData16, *(pFeatureData16+1));
  176. break;
  177. case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO:
  178. OV5670MIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, *(pFeatureData32+1));
  179. break;
  180. case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO:
  181. OV5670MIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, (MUINT32 *)(*(pFeatureData32+1)));
  182. break;
  183. case SENSOR_FEATURE_SET_TEST_PATTERN:
  184. OV5670SetTestPatternMode((BOOL)*pFeatureData16);
  185. break;
  186. case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE://for factory mode auto testing
  187. *pFeatureReturnPara32=OV5670_TEST_PATTERN_CHECKSUM;
  188. *pFeatureParaLen=4;
  189. break;
  190. default:
  191. break;
  192. }
  193. return ERROR_NONE;
  194. }
  1. UINT32 OV5670GetSensorID(UINT32 *sensorID)
  2. {
  3. int  retry = 2;
  4. OV5670DB("OV5670GetSensorID enter :\n ");
  5. mdelay(5);
  6. do {
  7. *sensorID = (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
  8. if (*sensorID == OV5670_SENSOR_ID)
  9. {
  10. OV5670DB("Sensor ID = 0x%04x\n", *sensorID);
  11. break;
  12. }
  13. OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
  14. retry--;
  15. } while (retry > 0);
  16. if (*sensorID != OV5670_SENSOR_ID) {
  17. OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
  18. /*
  19. *sensorID = OV5670_SENSOR_ID;
  20. return ERROR_SENSOR_CONNECT_FAIL;
  21. */
  22. *sensorID = 0xFFFFFFFF;
  23. return ERROR_SENSOR_CONNECT_FAIL;
  24. }
  25. return ERROR_NONE;
  26. }

以上是ov5670获取ID的函数。

三、开机打开sensor总结

    • HAL层运行Search sensor这个线程
    • HAL层遍历sensorlist列表并挂载HAL层性能3A等一些参数获取的接口
    • HAL层下达setDriver的cmd,并下传正在遍历的sensorlist列表中的ID
    • Driver层根据这个ID,挂载Driver层sensorlist中对应的Sensorlist中对应的Sensor和具体Sensor底层操作接口
    • HAL层对正确遍历的sensor下达check ID的指令
    • Driver层为对应sensor上电,通过I2C读取预存在寄存器中的sensor id
    • 比较读取结果,不匹配,return error,继续遍历
    • 匹配,HAL层下达其他指令收集sensor信息
    • sensor下电

三、开机打开sensor总结

    • HAL层运行Search sensor这个线程
    • HAL层遍历sensorlist列表并挂载HAL层性能3A等一些参数获取的接口
    • HAL层下达setDriver的cmd,并下传正在遍历的sensorlist列表中的ID
    • Driver层根据这个ID,挂载Driver层sensorlist中对应的Sensorlist中对应的Sensor和具体Sensor底层操作接口
    • HAL层对正确遍历的sensor下达check ID的指令
    • Driver层为对应sensor上电,通过I2C读取预存在寄存器中的sensor id
    • 比较读取结果,不匹配,return error,继续遍历
    • 匹配,HAL层下达其他指令收集sensor信息
    • sensor下电
05-11 10:50