一、MTK平台Camera框架8 ?: k4 F$ h- u& [# _
MTK平台的Camera的架构见下图, & X) A) L: m3 e* X! A G
* J# z9 x* ~: B/ U: Q9 p这里主要介绍kernel部分和HAL层部分。 1、Kernel 部分主要有两块: 1.1、image sensordriver,负责具体型号的 sensor 的 id 检测,上电,以及在preview、capture、初始化、3A等等功能设定时的寄存器配置。 1.2、isp driver,通过DMA将sensor数据流上传。
6 `! r9 o! E# n0 J
2、HAL层部分主要有三部分组成: 2.1、imageio,主要负责数据buffer上传的pipe。 2.2、drv,包含imgsensor和isp的hal层控制。 2.3、feature io,包含各种3A等性能配置。
# ^4 O s# T/ i0 q( X* r
4 w; c9 C* n& a D3 F二、Camera打开流程分析 Camera开启流程图如下: 主要发生在两个时间点: 1、开机时:camera完成了sensor框架初始化,id检测并匹配sensor,以及上下电操作。 2、打开Camera应用时:camera会有上电,完成sensor的寄存器初始化配置,向上层传递基本参数和配置信息,以及preview和capture模式循环。+ ~1 ~' ` M4 I& D7 g- F- E
: T, ^$ s# s8 k$ P: \1、开机初始化过程 由于一开始不知道上电camera初始化从哪开始,我们可以借助抓取的mtk mobile log去分析。先看hal层log开始处: {0 r+ S) {% i4 J. z. G, S- {" i
" S- w* y8 A! q4 z
$ J; A( n+ ~* B) p! e% N
- 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 1 n! o; q; b' I. j# K* D
, d) u* j ~) Z$ T' R! u, M
. R1 B) {% ^+ V* O' q4 \* g
通过sourceinsight搜索发现开始是从CamDeviceManagerImp.cpp函数的enumDeviceLocked()开始。该函数的源代码如下: ===>mediatek/platform/mt6582/hardware/mtkcam/devicemgr/CamDeviceManagerImp.cpp
& b! E2 z% L) L! l$ z5 s% Y, x- /******************************************************************************
- *
- ******************************************************************************/
- 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;
- } : j$ g. t3 U8 ~; u6 }) l
- R* w# `1 b/ f( S& T9 ~, T+ V
* v6 N9 L* Z- }# @3 H- U 函数pSensorHal->searchSensor()将调用SensorDrv::searchSensor(NULL)函数,该函数再调用ImgSensor_drv.cpp文件中中的ImgSensorDrv::impSearchSensor函数。 ===>mediatek/platform/mt6582/hardware/mtkcam/core/drv/imgsensor/ImgSensor_drv.cpp
* k# w6 K) l- B- z- /*******************************************************************************
- *
- ********************************************************************************/
-
- 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;
- }//
, U$ P6 t G _; A
(1)、获取hal层sensor列表GetSensorInitFuncList(&m_pstSensorInitFunc); ===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp
2 d5 e) S+ Z/ [8 c" y5 G5 H) I& f- 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() * i; C% I: h$ F, f J
$ ^3 T% }. K& D7 |; `) W7 I===>mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp
8 t9 Y' A) E: C0 j. P `; Y9 q/ ~ Y0 i
/ i: I" ~6 S+ K! {# H1 d/ I" i- 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
- }; / Z. P2 \# [& i3 j, L) J
: z' k8 G2 |4 q# G' f2 O / {, E5 g0 l( s
7 O1 W9 u( d2 |: {. ~: n0 ~2 I! J. i4 a* Z: a' ^
(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
* N/ t e7 K' i \* p k9 E7 L3 T& s8 S
- /*******************************************************************************
- * 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;
- }
, v- Q% L& |9 o5 \/ I0 L1 p) Z% @
% u, r( E- a1 z ; g- M. B; R0 e, q* \ u6 |9 r6 q: d
# p/ |5 X4 t8 g) V# V) [+ M" t
/ N' n! b- O& }# r
(2.1)获取kernel层的sensor列表kdGetSensorInitFuncList(&pSensorList) ===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c
# w6 B) H( W2 h, G, Z 7 R# ]& g1 W' }( w0 ~
( z# v- z e* J& K- /*******************************************************************************
- * 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() 4 f' b7 c- j" M k
# L3 ^7 X" S" _: |4 I
" S! E: t2 [# @8 O1 w# ]$ o===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.h! U! _ y( ~8 b8 K, ^
hal层和kernel层的sensor列表顺序必须保持一致 ! T6 h( H" A- J5 v. m. X
& s/ R& W6 H1 M5 ~7 U, |
) J, v0 I( w w# {/ c- 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>
' d- o5 ?5 s7 v1 n, l
9 f; q) E2 e! B( N) [7 e/ p
7 V* R% ~* s" |
, h8 b# K$ R& [2 E" a4 {' }
2 S$ z' d) O/ @& U, [0 ^1 ]' E
(2.2)g_invokeSocketIdx,drvIdx解释 上层传下来的 id 参数解析成两部分 g_invokeSocketIdx 区分目前正在匹配的是 main 还是sub,drvIdx 是 sensor 列表的序列号 。
5 B6 d# u, R7 i# p/ r: [(2.3)获取指定sensor的func函数,例如ov5670的func,pSensorList[drvIdx].SensorInit(&g_pInvokeSensorFunc); 调用的函数是OV5670_MIPI_RAW_SensorInit()。 1 V8 }1 |! L/ j) o
- #if defined(OV5670_MIPI_RAW)
- {OV5670_SENSOR_ID, SENSOR_DRVNAME_OV5670_MIPI_RAW, OV5670_MIPI_RAW_SensorInit},
- #endif
" i9 X. R, B- ?6 t# I! h / Z" K6 `( n1 B' x
' @ @6 j" E+ j, j, V, M6 w
1 C3 r9 w s' N W+ a" o7 {===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw/ov5670mipiraw_Sensor.c 7 J6 P' u4 `7 u# {. I- `& e
( ? p/ R. ]% Z& b! g
- 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;
- }
6 H9 \0 M! L4 E- A. O f4 X2 A/ `4 \# }6 q
5670的sensorinit实现,主要是未了pfFunc这个函数指针的结构体指针赋值,这样我们就实现了驱动代码的分离,hal层只需要调用sensorlist.c这样一个虚拟设备的驱动,就可以和具体的Sensor Driver驱动通信。这样的做法与platform driver的设计思想差不多,在tp,lcm等驱动中也有体现。 * q0 a" H$ e5 u/ h8 c1 A
(3)上下电camera并读取ID,err = ioctl(m_fdSensor, KDIMGSENSORIOC_T_CHECK_IS_ALIVE); ===>mediatek/custom/mt6582/kernel/imgsensor/src/kd_sensorlist.c
' j3 w- c N) R, O1 O* i D% x
2 ^0 y) R5 Z7 C, U3 n8 v R- /*******************************************************************************
- * 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() */
8 x- y$ e$ i" ^+ [
' J- N; u; G" E3 o8 L( i
/ v7 k! }9 I# r q(3.1)Sensor 上电, kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*)g_invokeSocketIdx, g_invokeSensorNameStr,true, CAMERA_HW_DRVNAME1);
1 {8 A3 o+ N4 T4 z1 b1 h5 ]- z; i0 }" G. F
& k) F, ^1 [0 @9 U8 `; G5 J- /*******************************************************************************
- * 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;
- }
7 K3 L, F: l- z! k0 N 9 W$ P# g0 T5 ?7 _% C( d
& h' ~) e' J7 `2 B5 ~' ^===>mediatek/custom/huaqin82_slwt_2s_td/kernel/camera/camera/kd_camera_hw.c
, A7 f9 m1 C4 E. [7 ^ X x, e3 m: G9 |) k
% i; y# `+ I8 k! Q [
- 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); " \; \* K1 h% X
4 I1 [/ J' o( T3 e; x4 H
9 S* B, b6 @7 x9 D }7 U* g) H+ _- i
以ov5670为例,其上电code如下:
5 { s, w" q3 E4 n; o( p- 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;
- }
5 c& s, K- [! v+ D5 o h$ N
! A0 g* o/ G( y7 u, G w: ?5 p' O) T1 u1 r% L2 G8 {2 s
(3.2)获取sensor ID,err = g_pSensorFunc->SensorFeatureControl(g_invokeSocketIdx, SENSOR_FEATURE_CHECK_SENSOR_ID, (MUINT8*)&sensorID, &retLen);
6 t8 [9 ^) w2 U7 O1 d4 v* ~' T# a 此函数调用具体sensor的func,例如ov5670,则调用的 5 @ w% F R' r8 t: I* v
- OV5670FeatureControl - ?( r) @, H. A0 S8 M
! P E2 m- a1 t1 h& j: l; y% V4 V2 q
===>mediatek/custom/common/kernel/imgsensor/ov5670_mipi_raw* P4 \6 M$ D8 Q
1 n5 ^) c c) H- z5 B6 f# {9 J8 E3 | A8 M3 [3 b
- 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;
- } 1 S+ V2 a7 ~8 i; {8 y
! L0 C1 a! @6 b# {4 ?. ^. S0 j
! J b' t% R6 M7 }5 E; P5 l! }! W) P& C( N
- 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;
- } * x: V' |5 ~3 t9 K/ Y
I9 i, w; ?: P2 j% d- C3 [( e* c* y
7 P/ d; u7 _( x" t i- k
以上是ov5670获取ID的函数。
' W+ k8 {4 p) b/ D
& c7 n5 g4 m& Y$ h6 J% q& o" E# H, m2 i; E$ n
/ I! X5 F. p4 g8 l* e1 k- _三、开机打开sensor总结
2 V' }+ I$ v: b! @- 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下电
" S6 Q4 ]) f) u- e: A" \/ J* @1 q- q& I0 V2 O0 p
G* @2 f1 [0 A& F8 F8 g& ^5 W& h' ?5 x1 j, J p- V
/ N4 G/ R5 u$ H2 p% Z |