一、MTK平台Camera框架
& E9 I7 a+ |# T7 |; b7 q4 O MTK平台的Camera的架构见下图,
( j" C2 C, O( P, J& x " Y' e; U0 x" A; I, _: I
这里主要介绍kernel部分和HAL层部分。 1、Kernel 部分主要有两块: 1.1、image sensordriver,负责具体型号的 sensor 的 id 检测,上电,以及在preview、capture、初始化、3A等等功能设定时的寄存器配置。 1.2、isp driver,通过DMA将sensor数据流上传。
; k) r7 ~$ \) A. b2 e4 Y' F
2、HAL层部分主要有三部分组成: 2.1、imageio,主要负责数据buffer上传的pipe。 2.2、drv,包含imgsensor和isp的hal层控制。 2.3、feature io,包含各种3A等性能配置。. @+ i/ S& ?7 Y, I3 T' v
0 u* |) U+ Q' `& @( ^" B二、Camera打开流程分析 Camera开启流程图如下: 主要发生在两个时间点: 1、开机时:camera完成了sensor框架初始化,id检测并匹配sensor,以及上下电操作。 2、打开Camera应用时:camera会有上电,完成sensor的寄存器初始化配置,向上层传递基本参数和配置信息,以及preview和capture模式循环。/ l3 E( O: h' c' u
O# W; ]2 b' B5 z" c1、开机初始化过程 由于一开始不知道上电camera初始化从哪开始,我们可以借助抓取的mtk mobile log去分析。先看hal层log开始处: ) C* C/ D& C+ |/ P8 B
# Z" w5 U2 R! I$ V3 w3 g6 v+ I5 e0 `3 L, P, A8 v
- 12-24 10:02:07.601 148 148 D MtkCam/module: [instantiate_camera_module]
- 12-24 10:02:07.601 148 148 D MtkCam/Utils/Property: [clear] pid/tid=148/148
- 12-24 10:02:07.601 148 148 I CameraService: Loaded "MediaTek Camera Module" camera module
- 12-24 10:02:07.601 148 148 D MtkCam/MtkCamUtils: [CamDevMetaInfoMap::clear] pid/tid=148/148
- 12-24 10:02:07.601 148 148 D SensorHal: [getInstance][SensorHalImp] getInstance
- 12-24 10:02:07.601 148 148 D SensorHal: [createImp][createImp]: 0
- 12-24 10:02:07.601 148 148 D SeninfDrvImp: [getInstance][getInstance]
- 12-24 10:02:07.601 148 148 D SeninfDrvImp: [SeninfDrvImp][SeninfDrvImp]
- 12-24 10:02:07.601 148 148 D SeninfDrvImp: [init][init]: 0 / j4 z, c# N- H3 p! K) \
1 q# ]. k1 @2 Z0 M, X
! H. x: j. o& [; _- n
通过sourceinsight搜索发现开始是从CamDeviceManagerImp.cpp函数的enumDeviceLocked()开始。该函数的源代码如下: ===>mediatek/platform/mt6582/hardware/mtkcam/devicemgr/CamDeviceManagerImp.cpp - C U! X" i" l+ J2 w9 l
- /******************************************************************************
- *
- ******************************************************************************/
- int32_t
- CamDeviceManagerImp::
- enumDeviceLocked()
- {
- Utils::CamProfile _profile(__FUNCTION__, "CamDeviceManagerImp");
- //
- status_t status = OK;
- int32_t i4DeviceNum = 0;
- //
- mEnumMap.clear();
- //------------------------------------------------------------------------------
- #if '1'==MTKCAM_HAVE_SENSOR_HAL
-
- mEnumMap.clear();
- DevMetaInfo::clear();
- //
- int32_t isFakeOrientation = 0;
- int32_t i4DevSetupOrientation = 0;
- camera_info camInfo;
- camInfo.device_version = CAMERA_DEVICE_API_VERSION_1_0;
- camInfo.static_camera_characteristics = NULL;
- //
- SensorHal* pSensorHal = SensorHal::createInstance();//创建sensor对象
- if ( ! pSensorHal )
- {
- MY_LOGE("pSensorHal == NULL");
- return 0;
- }
- //
- int32_t const iSensorsList = pSensorHal->searchSensor();//此函数是入口,主要查找匹配的硬件sensor
- //
- //
- if ( (iSensorsList & SENSOR_DEV_MAIN_3D) == SENSOR_DEV_MAIN_3D )
- {
- MY_LOGI("Stereo 3D Camera found");
- #warning "[TODO] Stereo 3D Camera"
- }
- //
- if ( (iSensorsList & SENSOR_DEV_MAIN) == SENSOR_DEV_MAIN )
- {
- int32_t const deviceId = i4DeviceNum;
- //
- halSensorDev_e const eHalSensorDev = SENSOR_DEV_MAIN;
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
- camInfo.orientation = i4DevSetupOrientation;
- if ( isFakeOrientation )
- {
- camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
- MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
- }
- DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
- //
- sp<EnumInfo> pInfo = new EnumInfo;
- pInfo->uDeviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
- pInfo->pMetadata = NULL;
- pInfo->iFacing = camInfo.facing;
- pInfo->iWantedOrientation = camInfo.orientation;
- pInfo->iSetupOrientation = i4DevSetupOrientation;
- mEnumMap.add(deviceId, pInfo);
- //
- i4DeviceNum++;
- }
- //
- if ( (iSensorsList & SENSOR_DEV_SUB) == SENSOR_DEV_SUB )
- {
- int32_t const deviceId = i4DeviceNum;
- //
- halSensorDev_e const eHalSensorDev = SENSOR_DEV_SUB;
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_FAKE_ORIENTATION, (int)&isFakeOrientation);
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_ORIENTATION_ANGLE, (int)&i4DevSetupOrientation);
- pSensorHal->sendCommand(eHalSensorDev, SENSOR_CMD_GET_SENSOR_FACING_DIRECTION, (int)&camInfo.facing);
- camInfo.orientation = i4DevSetupOrientation;
- if ( isFakeOrientation )
- {
- camInfo.orientation = (0==camInfo.facing) ? 90 : 270;
- MY_LOGW("Fake orientation:%d instead of %d, facing=%d HalSensorDev=%#x", camInfo.orientation, i4DevSetupOrientation, camInfo.facing, eHalSensorDev);
- }
- DevMetaInfo::add(deviceId, camInfo, i4DevSetupOrientation, eDevId_ImgSensor, eHalSensorDev);
- //
- sp<EnumInfo> pInfo = new EnumInfo;
- pInfo->uDeviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
- pInfo->pMetadata = NULL;
- pInfo->iFacing = camInfo.facing;
- pInfo->iWantedOrientation = camInfo.orientation;
- pInfo->iSetupOrientation = i4DevSetupOrientation;
- mEnumMap.add(deviceId, pInfo);
- //
- i4DeviceNum++;
- }
- //
- // if ( (iSensorsList & SENSOR_DEV_ATV) == SENSOR_DEV_ATV )
- {
- int32_t const deviceId = 0xFF;
- //
- halSensorDev_e const eHalSensorDev = SENSOR_DEV_ATV;
- camInfo.facing = 0;
- camInfo.orientation = 0;
- DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, eHalSensorDev);
- //
- sp<EnumInfo> pInfo = new EnumInfo;
- pInfo->uDeviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
- pInfo->pMetadata = NULL;
- pInfo->iFacing = camInfo.facing;
- pInfo->iWantedOrientation = camInfo.orientation;
- pInfo->iSetupOrientation = i4DevSetupOrientation;
- mEnumMap.add(deviceId, pInfo);
- //
- // i4DeviceNum++;
- }
- //
- //
- if ( pSensorHal )
- {
- pSensorHal->destroyInstance();
- pSensorHal = NULL;
- }
- //
- MY_LOGI("iSensorsList=0x%08X, i4DeviceNum=%d", iSensorsList, i4DeviceNum);
- for (size_t i = 0; i < mEnumMap.size(); i++)
- {
- int32_t const deviceId = mEnumMap.keyAt(i);
- sp<EnumInfo> pInfo = mEnumMap.valueAt(i);
- uint32_t const uDeviceVersion = pInfo->uDeviceVersion;
- camera_metadata const*pMetadata = pInfo->pMetadata;
- int32_t const iFacing = pInfo->iFacing;
- int32_t const iWantedOrientation= pInfo->iWantedOrientation;
- int32_t const iSetupOrientation = pInfo->iSetupOrientation;
- MY_LOGI(
- "[0x%02x] orientation(wanted/setup)=(%d/%d) facing:%d metadata:%p DeviceVersion:0x%x",
- deviceId, iWantedOrientation, iSetupOrientation,
- iFacing, pMetadata, uDeviceVersion
- );
- }
-
- #else //----------------------------------------------------------------------
-
- #warning "[WARN] Simulation for CamDeviceManagerImp::enumDeviceLocked()"
-
- mEnumMap.clear();
- DevMetaInfo::clear();
- {
- int32_t const deviceId = 0;
- //
- camera_info camInfo;
- camInfo.device_version = CAMERA_DEVICE_API_VERSION_1_0;
- camInfo.static_camera_characteristics = NULL;
- camInfo.facing = 0;
- camInfo.orientation = 90;
- DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_ImgSensor, 0x01/*SENSOR_DEV_MAIN*/);
- //
- sp<EnumInfo> pInfo = new EnumInfo;
- pInfo->uDeviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
- pInfo->pMetadata = NULL;
- pInfo->iFacing = 0;
- pInfo->iWantedOrientation = 90;
- pInfo->iSetupOrientation = 90;
- mEnumMap.add(deviceId, pInfo);
- }
- //
- {
- int32_t const deviceId = 0xFF;
- //
- camera_info camInfo;
- camInfo.device_version = CAMERA_DEVICE_API_VERSION_1_0;
- camInfo.static_camera_characteristics = NULL;
- camInfo.facing = 0;
- camInfo.orientation = 0;
- DevMetaInfo::add(deviceId, camInfo, camInfo.orientation, eDevId_AtvSensor, 0x04/*SENSOR_DEV_ATV*/);
- //
- sp<EnumInfo> pInfo = new EnumInfo;
- pInfo->uDeviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
- pInfo->pMetadata = NULL;
- pInfo->iFacing = 0;
- pInfo->iWantedOrientation = 0;
- pInfo->iSetupOrientation = 0;
- mEnumMap.add(deviceId, pInfo);
- }
- //
- i4DeviceNum = 1;
-
- #endif
- //------------------------------------------------------------------------------
- //
- _profile.print("");
- return i4DeviceNum;
- }
0 o2 r7 l& R0 _" \ 2 b- s- Q4 [) r. O" }
; G2 u6 ^8 L2 Z" S* e3 {3 ] 函数pSensorHal->searchSensor()将调用SensorDrv::searchSensor(NULL)函数,该函数再调用ImgSensor_drv.cpp文件中中的ImgSensorDrv::impSearchSensor函数。 ===>mediatek/platform/mt6582/hardware/mtkcam/core/drv/imgsensor/ImgSensor_drv.cpp ' ^) `. G: p& d3 I
- /*******************************************************************************
- *
- ********************************************************************************/
-
- MINT32
- ImgSensorDrv::impSearchSensor(pfExIdChk pExIdChkCbf)
- {
- MUINT32 SensorEnum = (MUINT32) DUAL_CAMERA_MAIN_SENSOR;
- MUINT32 i,id[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
- MBOOL SensorConnect=TRUE;
- UCHAR cBuf[64];
- MINT32 err = SENSOR_NO_ERROR;
- MINT32 err2 = SENSOR_NO_ERROR;
- ACDK_SENSOR_INFO_STRUCT SensorInfo;
- ACDK_SENSOR_CONFIG_STRUCT SensorConfigData;
- ACDK_SENSOR_RESOLUTION_INFO_STRUCT SensorResolution;
- MINT32 sensorDevs = SENSOR_NONE;
- IMAGE_SENSOR_TYPE sensorType = IMAGE_SENSOR_TYPE_UNKNOWN;
- IMGSENSOR_SOCKET_POSITION_ENUM socketPos = IMGSENSOR_SOCKET_POS_NONE;
-
-
- //! If imp sensor search process already done before,
- //! only need to return the sensorDevs, not need to
- //! search again.
- if (SENSOR_DOES_NOT_EXIST != m_mainSensorId) {
- //been processed.
- LOG_MSG("[impSearchSensor] Already processed \n");
- if (BAD_SENSOR_INDEX != m_mainSensorIdx) {
- sensorDevs |= SENSOR_MAIN;
- }
-
- if (BAD_SENSOR_INDEX != m_subSensorIdx) {
- sensorDevs |= SENSOR_SUB;
- }
-
- #ifdef ATVCHIP_MTK_ENABLE
-
- sensorDevs |= SENSOR_ATV;
-
- #endif
-
-
- return sensorDevs;
- }
-
- GetSensorInitFuncList(&m_pstSensorInitFunc);//----(1)获取hal层的sensor列表
-
- LOG_MSG("SENSOR search start \n");
-
- if (-1 != m_fdSensor) {
- ::close(m_fdSensor);
- m_fdSensor = -1;
- }
- sprintf(cBuf,"/dev/%s",CAMERA_HW_DEVNAME);
- m_fdSensor = : : open(cBuf, O_RDWR);
- if (m_fdSensor < 0) {
- LOG_ERR("[impSearchSensor]: error opening %s: %s \n", cBuf, strerror(errno));
- return sensorDevs;
- }
- LOG_MSG("[impSearchSensor] m_fdSensor = %d \n", m_fdSensor);
-
- // search main/main_2/sub 3 sockets
- #ifdef MTK_SUB_IMGSENSOR
- for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum <= DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1) {
- LOG_MSG("impSearchSensor search to sub\n");
- #else
- for (SensorEnum = DUAL_CAMERA_MAIN_SENSOR; SensorEnum < DUAL_CAMERA_SUB_SENSOR; SensorEnum <<= 1) {
- LOG_MSG("impSearchSensor search to main\n");
- #endif
- //skip atv case
- if ( 0x04 == SensorEnum ) continue;
- //
- for (i = 0; i < MAX_NUM_OF_SUPPORT_SENSOR; i++) {
- //end of driver list
- if (m_pstSensorInitFunc.getCameraDefault == NULL) {
- LOG_MSG("m_pstSensorInitFunc.getCameraDefault is NULL: %d \n", i);
- break;
- }
- //set sensor driver
- id[KDIMGSENSOR_INVOKE_DRIVER_0] = (SensorEnum << KDIMGSENSOR_DUAL_SHIFT) | i;
- LOG_MSG("set sensor driver id =%x\n", id[KDIMGSENSOR_INVOKE_DRIVER_0]);
- err = ioctl(m_fdSensor, KDIMGSENSORIOC_X_SET_DRIVER,&id[KDIMGSENSOR_INVOKE_DRIVER_0] );//--(2)调用kernel层的kdSetDriver函数
- if (err < 0) {
- LOG_ERR("ERROR:KDCAMERAHWIOC_X_SET_DRIVER\n");
- }
-
-
-
- //err = open();
- err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE);//---(3)上下电camera并读取sensor的ID,如果匹配则成功
-
-
-
- if (err < 0) {
- LOG_MSG("[impSearchSensor] Err-ctrlCode (%s) \n", strerror(errno));//
- }
- //
- sensorType = this->getCurrentSensorType((SENSOR_DEV_ENUM)SensorEnum);
- //
- socketPos = this->getSocketPosition((CAMERA_DUAL_CAMERA_SENSOR_ENUM)SensorEnum);
- //check extra ID , from EEPROM maybe
- //may need to keep power here
- if (NULL != pExIdChkCbf) {
- err2 = pExIdChkCbf();
- if (err2 < 0) {
- LOG_ERR("Error:pExIdChkCbf() \n");
- }
- }
-
- //power off sensor
- close();
-
- if (err < 0 || err2 < 0) {
- LOG_MSG("sensor ID mismatch\n");
- }
- else {
- if (SensorEnum == DUAL_CAMERA_MAIN_SENSOR) {
- //m_mainSensorIdx = i;
- //m_mainSensorId = m_pstSensorInitFunc[m_mainSensorIdx].SensorId;
- m_mainSensorDrv.index[m_mainSensorDrv.number] = i;
- m_mainSensorDrv.type[m_mainSensorDrv.number] = sensorType;
- if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstRawIndex ) {
- m_mainSensorDrv.firstRawIndex = i;
- }
- else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_mainSensorDrv.firstYuvIndex ) {
- m_mainSensorDrv.firstYuvIndex = i;
- }
- m_mainSensorDrv.position = socketPos;
- m_mainSensorDrv.sensorID = m_pstSensorInitFunc[m_mainSensorDrv.index[m_mainSensorDrv.number]].SensorId;
- // LOG_MSG("MAIN sensor m_mainSensorDrv.number=%d, m_mainSensorDrv.index=%d\n",m_mainSensorDrv.number,m_mainSensorDrv.index[m_mainSensorDrv.number]);
- m_mainSensorDrv.number++;
- //
- m_pMainSensorInfo = m_pstSensorInitFunc.pSensorInfo;
- if ( m_pMainSensorInfo )
- {
- NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc.pSensorInfo;
- LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
- }
- else
- {
- LOG_WRN("m_pMainSensorInfo==NULL\n");
- }
- LOG_MSG("MAIN sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
- //break;
- }
- else if (SensorEnum == DUAL_CAMERA_SUB_SENSOR) {
- //m_subSensorIdx = i;
- //m_subSensorId = m_pstSensorInitFunc[m_subSensorIdx].SensorId;
- m_subSensorDrv.index[m_subSensorDrv.number] = i;
- m_subSensorDrv.type[m_subSensorDrv.number] = sensorType;
- if ( IMAGE_SENSOR_TYPE_RAW == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstRawIndex ) {
- m_subSensorDrv.firstRawIndex = i;
- }
- else if ( IMAGE_SENSOR_TYPE_YUV == sensorType && BAD_SENSOR_INDEX == m_subSensorDrv.firstYuvIndex ) {
- m_subSensorDrv.firstYuvIndex = i;
- }
- m_subSensorDrv.position = socketPos;
- m_subSensorDrv.sensorID = m_pstSensorInitFunc[m_subSensorDrv.index[m_subSensorDrv.number]].SensorId;
- //LOG_MSG("SUB sensor m_subSensorDrv.number=%d, m_subSensorDrv.index=%d\n",m_subSensorDrv.number,m_subSensorDrv.index[m_subSensorDrv.number]);
- m_subSensorDrv.number++;
- //
- m_pSubSensorInfo = m_pstSensorInitFunc.pSensorInfo;
- if ( m_pSubSensorInfo )
- {
- NSFeature::SensorInfoBase* pSensorInfo = m_pstSensorInitFunc.pSensorInfo;
- LOG_MSG("found <%#x/%s/%s>", pSensorInfo->GetID(), pSensorInfo->getDrvName(), pSensorInfo->getDrvMacroName());
- }
- else
- {
- LOG_WRN("m_pSubSensorInfo==NULL\n");
- }
- LOG_MSG("SUB sensor found:[%d]/[0x%x]/[%d]/[%d] \n",i,id[KDIMGSENSOR_INVOKE_DRIVER_0],sensorType,socketPos);
- //break;
- }
- }//
-
- }
- }
- //close system call may be off sensor power. check first!!!
- ::close(m_fdSensor);
- m_fdSensor = -1;
- //
- if (BAD_SENSOR_INDEX != m_mainSensorDrv.index[0]) {
- m_mainSensorId = m_mainSensorDrv.sensorID;
- //init to choose first
- m_mainSensorIdx = m_mainSensorDrv.index[0];
- sensorDevs |= SENSOR_MAIN;
- }
-
- if (BAD_SENSOR_INDEX != m_subSensorDrv.index[0]) {
- m_subSensorId = m_subSensorDrv.sensorID;
- //init to choose first
- m_subSensorIdx = m_subSensorDrv.index[0];
- sensorDevs |= SENSOR_SUB;
- }
-
- #ifdef ATVCHIP_MTK_ENABLE
-
- sensorDevs |= SENSOR_ATV;
-
- #endif
-
-
- if (sensorDevs == SENSOR_NONE) {
- LOG_ERR( "Error No sensor found!! \n");
- }
- //
- LOG_MSG("SENSOR search end: 0x%x /[0x%x][%d]/[0x%x][%d]\n", sensorDevs,
- m_mainSensorId,m_mainSensorIdx,m_subSensorId,m_subSensorIdx);
-
- return sensorDevs;
- }// : }4 y8 x5 G3 a
(1)、获取hal层sensor列表GetSensorInitFuncList(&m_pstSensorInitFunc); ===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp
# v! W3 E$ d6 Y. o- P- UINT32 GetSensorInitFuncList(MSDK_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
- {
- if (NULL == ppSensorList) {
- ALOGE("ERROR: NULL pSensorList\n");
- return MHAL_UNKNOWN_ERROR;
- }
- *ppSensorList = &SensorList[0];//这里直接调用hal层的sensor列表
- return MHAL_NO_ERROR;
- } // GetSensorInitFuncList()
$ E0 Q$ {. Z/ R3 ?/ ^3 {( g2 g2 k) v$ { e# P7 D/ K2 e7 |# Z3 z5 _0 d
===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp$ Z- r w) b1 f& A' D
: P+ j6 u1 F3 ]6 ^/ T. N, |
+ `* f: l% f# l! |7 L- MSDK_SENSOR_INIT_FUNCTION_STRUCT SensorList[] =
- {
- //add by zym
- #if defined(GC2235_MIPI_RAW)
- RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
- #endif
- // add by zhouzuoyu
- #if defined(GC2235_KOTECH_MIPI_RAW)
- RAW_INFO(GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, NULL),
- #endif
- #if defined(OV16825_MIPI_RAW)
- RAW_INFO(OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW,NULL),
- #endif
- #if defined(IMX135_MIPI_RAW)
- RAW_INFO(IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW,NULL),
- #endif
- #if defined(OV8830_RAW)
- RAW_INFO(OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, NULL),
- #endif
-
- /* ADD sensor driver before this line */
- {0,{0},NULL, NULL, NULL}//end of list
- }; , M( z( U/ n' I# V J' P
" J$ k9 G* B+ B* q" f, I! }
, R% o7 U. {2 e
4 f8 M9 y8 ~+ \2 J/ J' k+ I; @, r
' R3 b. s5 O" k(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 " l0 ]. U" |- m
. g, H" T% _0 S, ], H
- /*******************************************************************************
- * kdSetDriver
- ********************************************************************************/
- int kdSetDriver(unsigned int* pDrvIndex)
- {
- ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT *pSensorList = NULL;
- u32 drvIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS] = {0,0};
- u32 i;
-
- PK_XLOG_INFO("pDrvIndex:0x%08x/0x%08x \n",pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_0],pDrvIndex[KDIMGSENSOR_INVOKE_DRIVER_1]);
- //set driver for MAIN or SUB sensor
-
- if (0 != kdGetSensorInitFuncList(&pSensorList))//----(2.1)获取kernel层的sensor列表
- {
- PK_ERR("ERROR:kdGetSensorInitFuncList()\n");
- return -EIO;
- }
-
- for ( i = KDIMGSENSOR_INVOKE_DRIVER_0; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
- //
- spin_lock(&kdsensor_drv_lock);
- g_bEnableDriver = FALSE;
- g_invokeSocketIdx = (CAMERA_DUAL_CAMERA_SENSOR_ENUM)((pDrvIndex & KDIMGSENSOR_DUAL_MASK_MSB)>>KDIMGSENSOR_DUAL_SHIFT);
- spin_unlock(&kdsensor_drv_lock);
-
- drvIdx = (pDrvIndex & KDIMGSENSOR_DUAL_MASK_LSB);//----(2.2)g_invokeSocketIdx,drvIdx解释
- //
- if ( DUAL_CAMERA_NONE_SENSOR == g_invokeSocketIdx ) { continue; }
-
-
- //ToDo: remove print information
- PK_XLOG_INFO("[kdSetDriver] i,g_invokeSocketIdx[%d] = %d :\n",i,i,drvIdx);
- PK_XLOG_INFO("[kdSetDriver] i,drvIdx[%d] = %d :\n",i,i,drvIdx);
- //
- if ( MAX_NUM_OF_SUPPORT_SENSOR > drvIdx ) {
- if (NULL == pSensorList[drvIdx].SensorInit) {
- PK_ERR("ERROR:kdSetDriver()\n");
- return -EIO;
- }
-
- pSensorList[drvIdx].SensorInit(&g_pInvokeSensorFunc);//----(2.3)获取指定sensor的fun函数,例如ov5670的func
- if (NULL == g_pInvokeSensorFunc) {
- PK_ERR("ERROR:NULL g_pSensorFunc[%d]\n",i);
- return -EIO;
- }
- //
- spin_lock(&kdsensor_drv_lock);
- g_bEnableDriver = TRUE;
- spin_unlock(&kdsensor_drv_lock);
- //get sensor name
- memcpy((char*)g_invokeSensorNameStr,(char*)pSensorList[drvIdx].drvname,sizeof(pSensorList[drvIdx].drvname));
- //return sensor ID
- //pDrvIndex[0] = (unsigned int)pSensorList[drvIdx].SensorId;
- PK_XLOG_INFO("[kdSetDriver] :[%d][%d][%d][%s][%d]\n",i,g_bEnableDriver,g_invokeSocketIdx,g_invokeSensorNameStr,sizeof(pSensorList[drvIdx].drvname));
- }
- }
- return 0;
- }
' X' h4 E1 A2 \' N9 _6 c2 Z; S* z( c* h
6 y/ v/ b- x( t$ @, R; x2 A$ x! A u$ R8 k5 c1 p
$ a0 N" U) Y. e/ W6 N
(2.1)获取kernel层的sensor列表kdGetSensorInitFuncList(&pSensorList) ===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c
$ T H l/ P. t b5 o* n; ? F
6 c" m1 \) H, G
! a: J; c/ B9 b9 O4 O0 Q- /*******************************************************************************
- * general camera image sensor kernel driver
- *******************************************************************************/
- UINT32 kdGetSensorInitFuncList(ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT **ppSensorList)
- {
- if (NULL == ppSensorList)
- {
- PK_DBG("[kdGetSensorInitFuncList]ERROR: NULL ppSensorList\n");
- return 1;
- }
- *ppSensorList = &kdSensorList[0];
- return 0;
- } // kdGetSensorInitFuncList()
$ z: [* j; N" ^5 O6 m( W, D2 O7 X" z) M+ x* w8 y6 C
! g3 E1 q, k. y# N9 j3 e4 x+ r
===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.h; ^7 h( [ [1 ]
hal层和kernel层的sensor列表顺序必须保持一致
, j5 F# c9 a. w, p# A3 f/ h5 P8 Z8 P }
# s: y- @# `. O1 `0 S9 W
- ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
- {
- //add by zym
- #if defined(GC2235_MIPI_RAW)
- {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
- #endif
-
- // add by zhouzuoyu
- #if defined(GC2235_KOTECH_MIPI_RAW)
- {GC2235MIPI_SENSOR_ID, SENSOR_DRVNAME_GC2235_MIPI_RAW, GC2235MIPISensorInit},
- #endif
-
- #if defined(OV16825_MIPI_RAW)
- {OV16825MIPI_SENSOR_ID, SENSOR_DRVNAME_OV16825_MIPI_RAW, OV16825MIPISensorInit},
- #endif
- #if defined(IMX135_MIPI_RAW)
- {IMX135_SENSOR_ID, SENSOR_DRVNAME_IMX135_MIPI_RAW, IMX135_MIPI_RAW_SensorInit},
- #endif
- #if defined(OV8830_RAW)
- {OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, OV8830SensorInit},
- #endif
- /* ADD sensor driver before this line */
- {0,{0},NULL}, //end of list
- };
- //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;">
- </span></span> / V. ?9 I7 ]6 S* N4 ]/ B9 q' y
0 L7 G5 h, z" O/ n2 P+ `0 n
( T3 W1 M; @" |( @# m w8 ^ L% F( g9 q0 @
% L# \4 E9 s5 B) ?
(2.2)g_invokeSocketIdx,drvIdx解释 上层传下来的 id 参数解析成两部分 g_invokeSocketIdx 区分目前正在匹配的是 main 还是sub,drvIdx 是 sensor 列表的序列号 。
3 { y, @, i6 [( P l+ q. c(2.3)获取指定sensor的func函数,例如ov5670的func,pSensorList[drvIdx].SensorInit(&g_pInvokeSensorFunc); 调用的函数是OV5670_MIPI_RAW_SensorInit()。 4 F: Q, P. h$ k7 s2 |
- #if defined(OV5670_MIPI_RAW)
- {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit},
- #endif 2 j' y8 V, H0 F5 G: n; p5 b8 i6 E
; c: i1 K) [6 w 3 J; v: z. T" S- a
8 n, s3 o$ H+ Y7 t) w
===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw/ov5670mipiraw_Sensor.c 1 ^" R+ J0 D! @
% J- I [' J0 m- SENSOR_FUNCTION_STRUCT SensorFuncOV5670=
- {
- OV5670Open,
- OV5670GetInfo,
- OV5670GetResolution,
- OV5670FeatureControl,
- OV5670Control,
- OV5670Close
- };
-
- UINT32 OV5670_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)//---调用此函数
- {
- if (pfFunc!=NULL)
- *pfFunc=&SensorFuncOV5670;
-
- return ERROR_NONE;
- }
_9 j, n0 I9 H9 |3 }5 B 4 ]5 J6 [* K' J, Z* M) \
5670的sensorinit实现,主要是未了pfFunc这个函数指针的结构体指针赋值,这样我们就实现了驱动代码的分离,hal层只需要调用sensorlist.c这样一个虚拟设备的驱动,就可以和具体的Sensor Driver驱动通信。这样的做法与platform driver的设计思想差不多,在tp,lcm等驱动中也有体现。 8 }' L& y8 {9 F$ R9 j. `, D& T/ u" d
(3)上下电camera并读取ID,err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE); ===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c
( B6 ~" q1 U" ^$ z
# s w* e6 |7 |- /*******************************************************************************
- * adopt_CAMERA_HW_CheckIsAlive
- ********************************************************************************/
- inline static int adopt_CAMERA_HW_CheckIsAlive(void)
- {
- UINT32 err = 0;
- UINT32 err1 = 0;
- UINT32 i = 0;
- MUINT32 sensorID = 0;
- MUINT32 retLen = 0;
-
-
- KD_IMGSENSOR_PROFILE_INIT();
- //power on sensor
- kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);//----(3.1)sensor上电
- //wait for power stable
- mDELAY(10);
- KD_IMGSENSOR_PROFILE("kdModulePowerOn");
-
- if (g_pSensorFunc) {
- for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
- if(DUAL_CAMERA_NONE_SENSOR != g_invokeSocketIdx){
- err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx, SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);//---(3.2)获取sensor ID
- if (sensorID == 0) { //not implement this feature ID
- PK_DBG(" Not implement!!, use old open function to check\n");
- err = ERROR_SENSOR_CONNECT_FAIL;
- }
- else if (sensorID == 0xFFFFFFFF) { //fail to open the sensor
- PK_DBG(" No Sensor Found");
- err = ERROR_SENSOR_CONNECT_FAIL;
- }
- else {
-
- PK_DBG(" Sensor found ID = 0x%x\n", sensorID);
- err = ERROR_NONE;
- }
- if(ERROR_NONE != err)
- {
- PK_DBG("ERROR:adopt_CAMERA_HW_CheckIsAlive(), No imgsensor alive \n");
- }
- }
- }
- }
- else {
- PK_DBG("ERROR:NULL g_pSensorFunc\n");
- }
-
- //reset sensor state after power off
- err1 = g_pSensorFunc->SensorClose();
- if(ERROR_NONE != err1) {
- PK_DBG("SensorClose \n");
- }
- //
- kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr, false, CAMERA_HW_DRVNAME1);
- //
- KD_IMGSENSOR_PROFILE("CheckIsAlive");
-
- return err?-EIO:err;
- } /* adopt_CAMERA_HW_Open() */ 0 d; ~8 E! H" U" t. i$ _* P6 x3 _/ B) {
# M# E: P( I% z1 L
% t5 I! a: @( \0 b. J; O3 K4 N0 I(3.1)Sensor 上电, kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);4 A+ o& i. Z7 z! G3 e
1 v8 Q4 j6 N$ L L" G+ Z: O$ v
S j4 `0 N5 _
- /*******************************************************************************
- * kdModulePowerOn
- ********************************************************************************/
- int
- kdModulePowerOn(
- CAMERA_DUAL_CAMERA_SENSOR_ENUM socketIdx[KDIMGSENSOR_MAX_INVOKE_DRIVERS],
- char sensorNameStr[KDIMGSENSOR_MAX_INVOKE_DRIVERS][32],
- BOOL On,
- char* mode_name )
- {
- MINT32 ret = ERROR_NONE;
- u32 i = 0;
-
- for ( i = KDIMGSENSOR_INVOKE_DRIVER_0 ; i < KDIMGSENSOR_MAX_INVOKE_DRIVERS ; i++ ) {
- if ( g_bEnableDriver ) {
- //PK_XLOG_INFO("[%s][%d][%d][%s][%s]\r\n",__FUNCTION__,g_bEnableDriver,socketIdx,sensorNameStr,mode_name);
- ret = kdCISModulePowerOn(socketIdx,sensorNameStr,On,mode_name);//实际上电的func
- if ( ERROR_NONE != ret ) {
- PK_ERR("[%s]",__FUNCTION__);
- return ret;
- }
- }
- }
- return ERROR_NONE;
- } 6 p' x! J3 o1 {* @. G; b
: x9 r8 x0 L7 ^4 G5 ~9 e
2 W0 b0 i$ \* Q. f$ \9 h
===>mediatek/custom/huaqin82_slwt_2s_td/kernel/camera/camera/kd_camera_hw.c
: P7 l5 l9 y1 t& V
1 O+ C# o) H2 |6 |- o4 ?( i. t: w. M8 p0 x# e1 }$ K
- int kdCISModulePowerOn(CAMERA_DUAL_CAMERA_SENSOR_ENUM SensorIdx, char *currSensorName, BOOL On, char* mode_name)
- {
- PK_DBG("[camera] **kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
- //dump_stack();
- if (DUAL_CAMERA_MAIN_SENSOR == SensorIdx){
- if (currSensorName &&
- ((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV, currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName))
- //|| to add other main camera here
- ))
- pinSetIdx = 0;
- else
- {
- PK_DBG("[ryf-main]kdCISModulePowerOn get in--- sensorIdx not compare with sensor name: %s\n", currSensorName);
- //if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
- //{
- // pinSetIdx = 1;
- //}
- //else{
- goto _kdCISModulePowerOn_exit_;
- //}
- }
- }
- else if (DUAL_CAMERA_SUB_SENSOR == SensorIdx) {
- if (currSensorName &&
- ((0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW, currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_GC0312_YUV, currSensorName))
- ||(0 == strcmp(SENSOR_DRVNAME_HI704_YUV, currSensorName))
- //||(0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV, currSensorName))
- //|| to add other sub camera here
- ))
- pinSetIdx = 1;
- else
- {
- //if (currSensorName &&
- //((0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))
- //|| to add other main camera here
- //))
- //{
- // pinSetIdx = 0;
- //}
- PK_DBG("{ryf-sub}kdCISModulePowerOn get in--- sensorIdx not compare with sensro:%s\n",currSensorName);
- goto _kdCISModulePowerOn_exit_;
- }
- }
- else if (DUAL_CAMERA_MAIN_2_SENSOR == SensorIdx) {
- // pinSetIdx = 2;
- }
-
- PK_DBG("kdCISModulePowerOn:SensorIdx:%d,pinSetIdx:%d",SensorIdx,pinSetIdx);
- Rst_PDN_Init();
-
- //power ON
- if (On)
- {
- PK_DBG("kdCISModulePowerOn -on:currSensorName=%s\n",currSensorName);
- if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov5648mipi on\n");
- if (0 == pinSetIdx) {
- if (TRUE != kd_ov5648_main_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (1 == pinSetIdx) {
- if (TRUE != kd_ov5648_sub_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is s5k4e1ga on \n");
- if(TRUE != kd_s5k4e1gamipi_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is hi544 on \n");
- if(TRUE != kd_hi544raw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is gc2235 on\n");
- if(TRUE != kd_gc2235mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
- PK_DBG("is gc2235_raw on\n");
-
- if (TRUE != kd_gc2235raw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- /* else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
- {
- PK_DBG("is hi253 on\n");
- if(TRUE != kd_hi253yuv_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }*/
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov88251 on \n");
- if(TRUE != kd_ov88251mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov88252 on \n");
- if(TRUE != kd_ov88252mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov8858 on \n");
- kd_a5142mipiraw_sub_poweron(mode_name);
- kd_a5142mipiraw_sub_powerdown(mode_name);
- if(TRUE != kd_ov8858mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW,currSensorName))) {
- PK_DBG("is s5k4h5yx on \n");
- kd_a5142mipiraw_sub_poweron(mode_name);
- kd_a5142mipiraw_sub_powerdown(mode_name);
- if (TRUE != kd_s5k4h5yxmipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
- PK_DBG("is t4k35 on \n");
- if(TRUE != kd_t4k35mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName)))) {
- if(pinSetIdx==0)
- {
- if(TRUE != kd_s5k3h7ymipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else
- {
- if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName))) {
- PK_DBG("is gc2035 on\n");
- if(TRUE != kd_gc2035_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_ov5648a_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_ov5670_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_hi551_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_ov5648b_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
- {
- if(TRUE != kd_ov5648_main_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName))) {
- PK_DBG("is s5k3h72ymipi on\n");
- if(TRUE != kd_s5k3h72ymipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
- {
- PK_DBG("is gc0329 on\n");
- if(TRUE != kd_gc0329_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
- if (0 == pinSetIdx) {
- PK_DBG("is A5142 main on \n");
- if(TRUE != kd_a5142mipiraw_main_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else {
- PK_DBG("is A5142 sub on \n");
- if(TRUE != kd_a5142mipiraw_sub_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
-
- }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
- {
- PK_DBG("is gc0312 on\n");
- if(TRUE != kd_gc0312_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
- {
- PK_DBG("is hi704 on\n");
- if(TRUE != kd_hi704yuv_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
- {
- PK_DBG("is gc0310 on\n");
- if(TRUE != kd_gc0310_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
- PK_DBG("is gc2145 on\n");
-
- if (TRUE != kd_gc2145_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
- {
- PK_DBG("is hi258 on \n");
- if(TRUE != kd_hi258mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov2680 on \n");
- if(TRUE != kd_ov2680mipiraw_poweron(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else
- {
- PK_DBG("kdCISModulePowerOn get in--- other , please add the power on code!!!!!!\n");
- goto _kdCISModulePowerOn_exit_;
- }
- }
- else {//power OFF
-
- PK_DBG("kdCISModulePowerOn -off:currSensorName=%s\n",currSensorName);
-
-
- if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is ov5648_mipi_raw down\n");
- if (0 == pinSetIdx) {
- if(TRUE != kd_ov5648_main_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (1 == pinSetIdx) {
- if(TRUE != kd_ov5648_sub_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- } else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4E1GA_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is s5k4e1ga down\n");
- if(TRUE != kd_s5k4e1gamipi_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI544_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is hi544 down\n");
- if(TRUE != kd_hi544raw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88251_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is ov88251 down\n");
- if(TRUE != kd_ov88251mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
-
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5670_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is ov5670 down\n");
- if(TRUE != kd_ov5670mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
-
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI551_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is hi551 down\n");
- if(TRUE != kd_hi551mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
-
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV88252_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is ov88252 down\n");
- if(TRUE != kd_ov88252mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV8858_MIPI_RAW,currSensorName))) {
- PK_DBG("is ov8858 down\n");
- if(TRUE != kd_ov8858mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K4H5YX_MIPI_RAW, currSensorName))) {
- PK_DBG("is s5k4h5yx down\n");
- if (TRUE != kd_s5k4h5yxmipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_T4K35_MIPI_RAW,currSensorName))) {
- PK_DBG("is t4k35 down\n");
- if(TRUE != kd_t4k35mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is gc2235 down\n");
- if(TRUE != kd_gc2235mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2235_RAW,currSensorName))) {
- PK_DBG("is gc2235 down\n");
-
- if (TRUE != kd_gc2235raw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- /* else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI253_YUV,currSensorName)))
- {
- PK_DBG("is hi253 down\n");
- if(TRUE != kd_hi253yuv_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }*/
- else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_A5142_MIPI_RAW, currSensorName))) {
- if (0 == pinSetIdx) {
- PK_DBG("is A5142 main down \n");
- if (TRUE != kd_a5142mipiraw_main_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else {
- PK_DBG("is A5142 sub down \n");
- if (TRUE != kd_a5142mipiraw_sub_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- } else if (currSensorName && ((0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_MIPI_RAW,currSensorName))
- || (0 == strcmp(SENSOR_DRVNAME_S5K3H7Y_2LANE_MIPI_RAW,currSensorName))))
- {
- PK_DBG("is s5k3h7 down\n");
- if(pinSetIdx==0)
- {
- if(TRUE != kd_s5k3h7ymipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else {
- if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
-
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2035_YUV,currSensorName)))
- {
- PK_DBG("is gc2035 down\n");
- if(TRUE != kd_gc2035_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_S5K3H72Y_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is s5k3h72y_mipi_raw down\n");
- if(TRUE != kd_s5k3h72ymipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648A_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_ov5648a_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648B_MIPI_RAW,currSensorName)))
- {
- if(TRUE != kd_ov5648b_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV5648_LARGEN_MIPI_RAW,currSensorName))) //lili add
- {
- if(TRUE != kd_ov5648_main_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0329_YUV,currSensorName)))
- {
- PK_DBG("is gc0329 down\n");
- if(TRUE != kd_gc0329yuv_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0312_YUV,currSensorName)))
- {
- PK_DBG("is gc0312 down\n");
- if(TRUE != kd_gc0312_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI704_YUV,currSensorName)))
- {
- PK_DBG("is hi704 down\n");
- if(TRUE != kd_hi704yuv_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC0310_MIPI_YUV,currSensorName)))
- {
- PK_DBG("is gc0310 down\n");
- if(TRUE != kd_gc0310_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- } else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_GC2145_MIPI_YUV,currSensorName))) {
- PK_DBG("is gc2145 down\n");
-
- if (TRUE != kd_gc2145_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if(currSensorName && (0 == strcmp(SENSOR_DRVNAME_HI258MIPI_YUV,currSensorName)))
- {
- PK_DBG("is hi258 down\n");
- if(TRUE != kd_hi258mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else if (currSensorName && (0 == strcmp(SENSOR_DRVNAME_OV2680_MIPI_RAW,currSensorName)))
- {
- PK_DBG("is ov2680 down\n");
- if(TRUE != kd_ov2680mipiraw_powerdown(mode_name))
- goto _kdCISModulePowerOn_exit_;
- }
- else
- {
- PK_DBG("kdCISModulePowerDown get in--- other , please add the power down code!!!!!!\n");
- goto _kdCISModulePowerOn_exit_;
- }
-
- }
- return 0;
-
- _kdCISModulePowerOn_exit_:
- return -EIO;
- }
- EXPORT_SYMBOL(kdCISModulePowerOn); , R! v2 w6 L" p) [8 y) |$ K
, L1 d$ N; y1 A
- `8 X) [0 @) F0 ^& u1 i L. x b6 p. Y6 }
以ov5670为例,其上电code如下: ; W! l1 h- S+ E
- static int kd_ov5670_poweron( char *mode_name)
- {
- int ret;
- printk("kd_ov5670_poweron1 start..\n");
-
- ret = kd_poweron_main_devices(VOL_1800, VOL_2800, VOL_1200, VOL_2800, mode_name,0);//给camera上三路电
- PK_DBG("kd_ov88251mipiraw_poweron start..\n");
- mdelay(10);// wait power to be stable
- //disable_inactive_sensor();//disable inactive sensor
- if(mt_set_gpio_out(pinSet[0][IDX_PS_CMPDN],pinSet[0][IDX_PS_CMPDN+IDX_PS_OFF])){PK_DBG("[CAMERA LENS] set gpio failed!! \n");}
- mdelay(10);
- 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");}
- mdelay(1);
-
- 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");}
- 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");}
- mdelay(10);
- 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");}
- mdelay(5);
- poweronerr:
- return ret;
- }
+ v5 M# L* M2 _" @1 g/ U
" ?% y4 ?! ?5 t: ?: `0 t5 u3 l* }$ q7 ^4 A# z) `- r
(3.2)获取sensor ID,err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx, SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);' d0 x1 P% p; `3 N6 M9 N& L
此函数调用具体sensor的func,例如ov5670,则调用的
& F2 v, C9 a( g3 l/ g Q# g- OV5670FeatureControl 3 X4 Z( ^$ I& w# _3 h* }
6 c: x7 M0 q/ d* j5 c! @===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw& C8 }! q2 c/ I+ X& ^3 l0 e
( b9 j. _% A# s" b, A8 Q
* g T1 h! p% g0 r5 S
- UINT32 OV5670FeatureControl(MSDK_SENSOR_FEATURE_ENUM FeatureId,
- UINT8 *pFeaturePara,UINT32 *pFeatureParaLen)
- {
- UINT16 *pFeatureReturnPara16=(UINT16 *) pFeaturePara;
- UINT16 *pFeatureData16=(UINT16 *) pFeaturePara;
- UINT32 *pFeatureReturnPara32=(UINT32 *) pFeaturePara;
- UINT32 *pFeatureData32=(UINT32 *) pFeaturePara;
- UINT32 SensorRegNumber;
- UINT32 i;
- PNVRAM_SENSOR_DATA_STRUCT pSensorDefaultData=(PNVRAM_SENSOR_DATA_STRUCT) pFeaturePara;
- MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData=(MSDK_SENSOR_CONFIG_STRUCT *) pFeaturePara;
- MSDK_SENSOR_REG_INFO_STRUCT *pSensorRegData=(MSDK_SENSOR_REG_INFO_STRUCT *) pFeaturePara;
- MSDK_SENSOR_GROUP_INFO_STRUCT *pSensorGroupInfo=(MSDK_SENSOR_GROUP_INFO_STRUCT *) pFeaturePara;
- MSDK_SENSOR_ITEM_INFO_STRUCT *pSensorItemInfo=(MSDK_SENSOR_ITEM_INFO_STRUCT *) pFeaturePara;
- MSDK_SENSOR_ENG_INFO_STRUCT *pSensorEngInfo=(MSDK_SENSOR_ENG_INFO_STRUCT *) pFeaturePara;
-
- switch (FeatureId)
- {
- case SENSOR_FEATURE_GET_RESOLUTION:
- *pFeatureReturnPara16++= OV5670_IMAGE_SENSOR_FULL_WIDTH;
- *pFeatureReturnPara16= OV5670_IMAGE_SENSOR_FULL_HEIGHT;
- *pFeatureParaLen=4;
- break;
- case SENSOR_FEATURE_GET_PERIOD:
- *pFeatureReturnPara16++= OV5670_FeatureControl_PERIOD_PixelNum;
- *pFeatureReturnPara16= OV5670_FeatureControl_PERIOD_LineNum;
- *pFeatureParaLen=4;
- break;
- case SENSOR_FEATURE_GET_PIXEL_CLOCK_FREQ:
- switch(OV5670CurrentScenarioId)
- {
- case MSDK_SCENARIO_ID_CAMERA_PREVIEW:
- *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
- *pFeatureParaLen=4;
- break;
- case MSDK_SCENARIO_ID_VIDEO_PREVIEW:
- *pFeatureReturnPara32 = OV5670_VIDEO_PCLK;
- *pFeatureParaLen=4;
- break;
- case MSDK_SCENARIO_ID_CAMERA_CAPTURE_JPEG:
- case MSDK_SCENARIO_ID_CAMERA_ZSD:
- *pFeatureReturnPara32 = OV5670_CAPTURE_PCLK;
- *pFeatureParaLen=4;
- break;
- default:
- *pFeatureReturnPara32 = OV5670_PREVIEW_PCLK;
- *pFeatureParaLen=4;
- break;
- }
- break;
-
- case SENSOR_FEATURE_SET_ESHUTTER:
- OV5670_SetShutter(*pFeatureData16);
- break;
- case SENSOR_FEATURE_SET_NIGHTMODE:
- OV5670_NightMode((BOOL) *pFeatureData16);
- break;
- case SENSOR_FEATURE_SET_GAIN:
- OV5670_SetGain((UINT16) *pFeatureData16);
- break;
- case SENSOR_FEATURE_SET_FLASHLIGHT:
- break;
- case SENSOR_FEATURE_SET_ISP_MASTER_CLOCK_FREQ:
- //OV5670_isp_master_clock=*pFeatureData32;
- break;
- case SENSOR_FEATURE_SET_REGISTER:
- OV5670_write_cmos_sensor(pSensorRegData->RegAddr, pSensorRegData->RegData);
- break;
- case SENSOR_FEATURE_GET_REGISTER:
- pSensorRegData->RegData = OV5670_read_cmos_sensor(pSensorRegData->RegAddr);
- break;
- case SENSOR_FEATURE_SET_CCT_REGISTER:
- SensorRegNumber=FACTORY_END_ADDR;
- for (i=0;i<SensorRegNumber;i++)
- {
- spin_lock(&ov5670mipiraw_drv_lock);
- OV5670SensorCCT.Addr=*pFeatureData32++;
- OV5670SensorCCT.Para=*pFeatureData32++;
- spin_unlock(&ov5670mipiraw_drv_lock);
- }
- break;
- case SENSOR_FEATURE_GET_CCT_REGISTER:
- SensorRegNumber=FACTORY_END_ADDR;
- if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
- return FALSE;
- *pFeatureData32++=SensorRegNumber;
- for (i=0;i<SensorRegNumber;i++)
- {
- *pFeatureData32++=OV5670SensorCCT.Addr;
- *pFeatureData32++=OV5670SensorCCT.Para;
- }
- break;
- case SENSOR_FEATURE_SET_ENG_REGISTER:
- SensorRegNumber=ENGINEER_END;
- for (i=0;i<SensorRegNumber;i++)
- {
- spin_lock(&ov5670mipiraw_drv_lock);
- OV5670SensorReg.Addr=*pFeatureData32++;
- OV5670SensorReg.Para=*pFeatureData32++;
- spin_unlock(&ov5670mipiraw_drv_lock);
- }
- break;
- case SENSOR_FEATURE_GET_ENG_REGISTER:
- SensorRegNumber=ENGINEER_END;
- if (*pFeatureParaLen<(SensorRegNumber*sizeof(SENSOR_REG_STRUCT)+4))
- return FALSE;
- *pFeatureData32++=SensorRegNumber;
- for (i=0;i<SensorRegNumber;i++)
- {
- *pFeatureData32++=OV5670SensorReg.Addr;
- *pFeatureData32++=OV5670SensorReg.Para;
- }
- break;
- case SENSOR_FEATURE_GET_REGISTER_DEFAULT:
- if (*pFeatureParaLen>=sizeof(NVRAM_SENSOR_DATA_STRUCT))
- {
- pSensorDefaultData->Version=NVRAM_CAMERA_SENSOR_FILE_VERSION;
- pSensorDefaultData->SensorId=OV5670_SENSOR_ID;
- memcpy(pSensorDefaultData->SensorEngReg, OV5670SensorReg, sizeof(SENSOR_REG_STRUCT)*ENGINEER_END);
- memcpy(pSensorDefaultData->SensorCCTReg, OV5670SensorCCT, sizeof(SENSOR_REG_STRUCT)*FACTORY_END_ADDR);
- }
- else
- return FALSE;
- *pFeatureParaLen=sizeof(NVRAM_SENSOR_DATA_STRUCT);
- break;
- case SENSOR_FEATURE_GET_CONFIG_PARA:
- memcpy(pSensorConfigData, &OV5670SensorConfigData, sizeof(MSDK_SENSOR_CONFIG_STRUCT));
- *pFeatureParaLen=sizeof(MSDK_SENSOR_CONFIG_STRUCT);
- break;
- case SENSOR_FEATURE_CAMERA_PARA_TO_SENSOR:
- OV5670_camera_para_to_sensor();
- break;
-
- case SENSOR_FEATURE_SENSOR_TO_CAMERA_PARA:
- OV5670_sensor_to_camera_para();
- break;
- case SENSOR_FEATURE_GET_GROUP_COUNT:
- *pFeatureReturnPara32++=OV5670_get_sensor_group_count();
- *pFeatureParaLen=4;
- break;
- case SENSOR_FEATURE_GET_GROUP_INFO:
- OV5670_get_sensor_group_info(pSensorGroupInfo->GroupIdx, pSensorGroupInfo->GroupNamePtr, &pSensorGroupInfo->ItemCount);
- *pFeatureParaLen=sizeof(MSDK_SENSOR_GROUP_INFO_STRUCT);
- break;
- case SENSOR_FEATURE_GET_ITEM_INFO:
- OV5670_get_sensor_item_info(pSensorItemInfo->GroupIdx,pSensorItemInfo->ItemIdx, pSensorItemInfo);
- *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
- break;
-
- case SENSOR_FEATURE_SET_ITEM_INFO:
- OV5670_set_sensor_item_info(pSensorItemInfo->GroupIdx, pSensorItemInfo->ItemIdx, pSensorItemInfo->ItemValue);
- *pFeatureParaLen=sizeof(MSDK_SENSOR_ITEM_INFO_STRUCT);
- break;
-
- case SENSOR_FEATURE_GET_ENG_INFO:
- pSensorEngInfo->SensorId = 129;
- pSensorEngInfo->SensorType = CMOS_SENSOR;
- pSensorEngInfo->SensorOutputDataFormat=SENSOR_OUTPUT_FORMAT_RAW_Gb;
- *pFeatureParaLen=sizeof(MSDK_SENSOR_ENG_INFO_STRUCT);
- break;
- case SENSOR_FEATURE_GET_LENS_DRIVER_ID:
- // get the lens driver ID from EEPROM or just return LENS_DRIVER_ID_DO_NOT_CARE
- // if EEPROM does not exist in camera module.
- *pFeatureReturnPara32=LENS_DRIVER_ID_DO_NOT_CARE;
- *pFeatureParaLen=4;
- break;
-
- case SENSOR_FEATURE_INITIALIZE_AF:
- break;
- case SENSOR_FEATURE_CONSTANT_AF:
- break;
- case SENSOR_FEATURE_MOVE_FOCUS_LENS:
- break;
- case SENSOR_FEATURE_SET_VIDEO_MODE:
- OV5670SetVideoMode(*pFeatureData16);
- break;
- case SENSOR_FEATURE_CHECK_SENSOR_ID://-------------调用此处读取ID
- OV5670GetSensorID(pFeatureReturnPara32);
- break;
- case SENSOR_FEATURE_SET_AUTO_FLICKER_MODE:
- OV5670SetAutoFlickerMode((BOOL)*pFeatureData16, *(pFeatureData16+1));
- break;
- case SENSOR_FEATURE_SET_MAX_FRAME_RATE_BY_SCENARIO:
- OV5670MIPISetMaxFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, *(pFeatureData32+1));
- break;
- case SENSOR_FEATURE_GET_DEFAULT_FRAME_RATE_BY_SCENARIO:
- OV5670MIPIGetDefaultFramerateByScenario((MSDK_SCENARIO_ID_ENUM)*pFeatureData32, (MUINT32 *)(*(pFeatureData32+1)));
- break;
- case SENSOR_FEATURE_SET_TEST_PATTERN:
- OV5670SetTestPatternMode((BOOL)*pFeatureData16);
- break;
- case SENSOR_FEATURE_GET_TEST_PATTERN_CHECKSUM_VALUE://for factory mode auto testing
- *pFeatureReturnPara32=OV5670_TEST_PATTERN_CHECKSUM;
- *pFeatureParaLen=4;
- break;
- default:
- break;
- }
- return ERROR_NONE;
- }
' p! K$ H T. c# M
2 O% }, `& R" e+ _0 Z4 E/ K8 M6 A, t* U" n8 j& W$ V% m
( i% q0 q0 J" S8 h& |7 g
- UINT32 OV5670GetSensorID(UINT32 *sensorID)
- {
- int retry = 2;
-
- OV5670DB("OV5670GetSensorID enter :\n ");
- mdelay(5);
-
- do {
- *sensorID = (OV5670_read_cmos_sensor(0x300B)<<8)|OV5670_read_cmos_sensor(0x300C);
- if (*sensorID == OV5670_SENSOR_ID)
- {
- OV5670DB("Sensor ID = 0x%04x\n", *sensorID);
- break;
- }
- OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
- retry--;
- } while (retry > 0);
-
- if (*sensorID != OV5670_SENSOR_ID) {
- OV5670DB("Read Sensor ID Fail = 0x%04x\n", *sensorID);
-
- /*
- *sensorID = OV5670_SENSOR_ID;
- return ERROR_SENSOR_CONNECT_FAIL;
- */
- *sensorID = 0xFFFFFFFF;
- return ERROR_SENSOR_CONNECT_FAIL;
- }
- return ERROR_NONE;
- }
/ o. t8 s: `+ W) r
5 {7 d- l( }- N5 T; c; o- k2 F: j. H7 u5 i6 _
以上是ov5670获取ID的函数。: Z0 f4 a6 u6 a. C9 U8 Y
' J1 k# v8 \8 b9 j( i& J) W
7 x9 ~2 ?5 {9 Q: {, F
% O# J; P. a5 k' f" a. h3 s1 L
三、开机打开sensor总结
$ P2 |1 T6 z8 C. r5 O- 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下电
- a3 B( z; ^; }, m s3 Z; W- r( ~7 S- v8 r/ e0 D& K$ w
* d4 [) }% M8 \5 P3 q @
# ^& \ x5 Q, X" ^ A: B2 b3 {
# V5 h; c% ] z+ ` |