MTK6735 camera 闪光灯Flashlight驱动调试流程学习
一、Flash驱动涉及到的文件包含:
kernel-3.10/drivers/misc/mediatek/flashlight/src/mt6735
├── constant_flashlight
│ ├── leds_strobe.c
│ └── Makefile
├── dummy_flashlight
│ ├── dummy_flashlight.c
│ └── Makefile
├── kd_flashlightlist.c
├── Makefile
├── out.txt
├── strobe_main_sid1_part2.c
├── strobe_main_sid2_part1.c
├── strobe_main_sid2_part2.c
├── strobe_part_id.c
├── strobe_sub_sid1_part2.c
├── strobe_sub_sid2_part1.c
├── strobe_sub_sid2_part2.c
└── sub_strobe.c
vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D2/core/featureio/drv/strobe
├── flashlight_drv.cpp
├── flashlight_drv.h
├── strobe_drv.cpp
├── strobe_global_driver.cpp
└── strobe_global_driver.h
vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D1/core/featureio/drv/strobe
├── flashlight_drv.cpp
├── flashlight_drv.h
├── strobe_drv.cpp
├── strobe_global_driver.cpp
└── strobe_global_driver.h
二、Flash驱动代码流程分析:
i. kernel-3.10/drivers/misc/mediatek/flashlight/src/mt6735/ kd_flashlightlist.c
主要完成设备的注册和初始化。
1.注册一个平台设备:名为”kd_camera_flashlight”;
2.注册一个平台驱动,name和我们的devices name同名,这个名字主要用来和HAL层的name做匹配用;
3.对IOCTL的一个填充,供HAL调用;
4.做一个接口主要跟我们实际使用的Flash驱动对接,以kdFlashlightList罗列出来;
ii. kernel-3.10/drivers/misc/mediatek/flashlight/src/mt6735/ constant_flashlight/leds_strobe.c
1. 这个文件就是我们实际性的使用的Flash驱动文件,从
/kernel-3.10/arch/arm64/configs/mtk6735_debug_defconfig:1035:CONFIG_CUSTOM_KERNEL_FLASHLIGHT=”constant_flashlight”
device/xxxxx/xxxxxx/ProjectConfig.mk:4: CUSTOM_KERNEL_MAIN_BACKUP_IMGSENSOR
CUSTOM_KERNEL_FLASHLIGHT
CUSTOM_KERNEL_SUB_IMGSENSOR
CUSTOM_KERNEL_MAIN2_IMGSENSOR
BOOT_LOGO
ProjectConfig.mk文件中CUSTOM_KERNEL_FLASHLIGHT配置获取具体使用的Flash驱动。
CUSTOM_KERNEL_FLASHLIGHT = constant_flashlight
如:
CUSTOM_HAL_FLASHLIGHT= constant_flashlight
CUSTOM_KERNEL_FLASHLIGHT = constant_flashlight
2. 该文件和kd_flashlightlist.c文件的对接函数为:
323 MUINT32constantFlashlightInit(PFLASHLIGHT_FUNCTION_STRUCT *pfFunc)
3. 这个文件完成的任务是填充以下几个函数:
- FLASHLIGHT_FUNCTION_STRUCT constantFlashlightFunc=
- {
- constant_flashlight_open,
- constant_flashlight_release,
- constant_flashlight_ioctl
- };
4. 我们主要分析的是constant_flashlight_ioctl,以为这是跟HAL实际握手的接口。
vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D2/core/featureio/drv/strobe/flashlight_drv.cpp
这个文件完成的任务比较多,主要是一些类的实现和定义。
- FlashlightDrv::FlashlightDrv()
- <span style=”white-space:pre”> </span> : StrobeDrv()
- , mUsers(0)
- , m_flashType((int)StrobeDrv::FLASHLIGHT_NONE)
- {
- logI(”FlashlightDrv()\n”);
- m_isOn=0;
- m_duty=0;
- m_step=0;
- m_bTempInit=0;
- mDutyNum=0;
- mTurnOnTime=0;
- mOnDuty = -1;
- }
vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D2/hal/aaa/flash_mgr/flash_mgr.h:90:
int cctFlashEnable(int senorDev, int en);
实现闪光灯模式的设置和获取、拍照/摄像预览的开启和终止、闪光灯设备的打开和关闭等等。
- void FlashMgr::setTorchOnOff(int en)
- int FlashMgr::setFlashMode(int mode)
调用lash_mgr.cpp中的函数来给cct_feature.cpp提供接口。
- int FlashMgr::cctFlashEnable(int en)
- {
- LogInfo(”cctFlashEnable(en=%d) line=%d”,en,__LINE__);
- if(en==1)
- {
- setFlashMode(FLASHLIGHT_FORCE_ON);
- }
- else
- {
- setFlashMode(FLASHLIGHT_FORCE_OFF);
- }
- return 0;
- }
vendor/mediatek/proprietary/platform/mt6735/hardware/mtkcam/D1/acdk/src/cct/if/cct_if.cpp:378:
调用flash_cct.cpp中的函数,并以IOCTL的形式进行封装,供更上一层次调用。具体的没有在继续跟下去,有兴趣的话,可以再往上分析分析。
- INT32 CctImp::aaaCCTFeatureControl
- case ACDK_CCT_OP_FLASH_ENABLE:
- err = FlashMgr::getInstance()->cctFlashEnable(1); //YosenFlash
- break;
- case ACDK_CCT_OP_FLASH_DISABLE:
- err = FlashMgr::getInstance()->cctFlashEnable(0); //YosenFlash