《CameraAF分析》
一、AFkernel代码分析:
涉及文件主要有:
mediatek/config/mt6592/init.rc
mediatek/config/huaqin92_wet_b2a_tdd/at808p/ProjectConfig.mk
mediatek/platform/mt6592/kernel/core/mt_devs.c
mediatek /custom/huaqin_bsp/at808p/base/kernel/lens/ov8865af/OV8865AF.c
mediatek/custom/common/kernel/lens/inc/OV8865AF.h
a) mediatek/config/mt6592/init.rc
作用是来修改文件的权限和将该文件的拥有者改为system用户,添加如下部分:
chmod 0660 /dev/OV8865AF
chown system camera /dev/OV8865AF
b) mediatek/config/huaqin92_wet_b2a_tdd/at808p/ProjectConfig.mk
修改部分如下图:
见附件11图片
c) mediatek/platform/mt6592/kernel/core/mt_devs.c
这个文件时用来注册平台设备的。
在mt_board_init函数中添加
2197 #if 1 //defined(CONFIG_ACTUATOR)
2198 retval = platform_device_register(&actuator_dev);
2199 if (retval != 0){
2200 return retval;
2201 }
2202 retval = platform_device_register(&actuator_dev1);
2203 if (retval != 0){
2204 return retval;
2205 }
2206 #endif
1533 staticstruct platform_device actuator_dev1 = {
1534 .name = "lens_actuator1",
1535 .id = -1,
1536 };
其中name “lens_actuator1”是用来和我们驱动文件中的name进行匹配的。
d) mediatek/custom/huaqin_bsp/at808p/base/kernel/lens/ov8865af/OV8865AF.c
重要说道驱动文件了,这个文件的头文件是:
mediatek/custom/common/kernel/lens/inc/OV8865AF.h
主要完成一下任务:
1. module_init(OV8865AF_i2C_init);——启动方式,也就是开机启动kernel后一段加载;
2. i2c_register_board_info(LENS_I2C_BUSNUM,&kd_lens_dev, 1);;——挂载到I2C总线上;
3. platform_driver_register(&g_stOV8865AF_Driver);——注册平台驱动;
491 static structplatform_driver g_stOV8865AF_Driver = {
492 .probe = OV8865AF_probe,
493 .remove = OV8865AF_remove,
494 .suspend = OV8865AF_suspend,
495 .resume = OV8865AF_resume,
496 .driver = {
497 .name = "lens_actuator1",
498 .owner = THIS_MODULE,
499 }
500 };
4. 然后进入OV8865AF_probe,加载i2c驱动:
469 static intOV8865AF_probe(struct platform_device *pdev)
470 {
471 returni2c_add_driver(&OV8865AF_i2c_driver);
472 }
423 struct i2c_driver OV8865AF_i2c_driver= {
424 .probe = OV8865AF_i2c_probe,
425 .remove = OV8865AF_i2c_remove,
426 .driver.name = OV8865AF_DRVNAME,
427 .id_table = OV8865AF_i2c_id,
428 };
5. 再就是OV8865AF_i2c_probe,就是注册字符驱动,以此就连接到我们的&g_stOV8865AF_fops,给上层提供Ioctl接口;
二、AFHAL层分析:
HAL层涉及的文件:
mediatek/custom/common/hal/inc/camera_custom_lens.h
mediatek/custom/huaqin92_wet_b2a_tdd/hal/lens/src/lenslist.cpp
mediatek/custom/huaqin_bsp/at808p/base/hal/lens/ov8865af/lens_para_OV8865AF.cpp
a) mediatek/custom/huaqin92_wet_b2a_tdd/hal/lens/src/lenslist.cpp
添加LensList:
70 #if defined(OV8865AF)
71{OV8865_SENSOR_ID, OV8865AF_LENS_ID,"OV8865AF", pOV8865AF_getDefaultData},
72 #endif
OV8865AF_LENS_ID 在camera_custom_lens.h加以定义,
如:#define OV8865AF_LENS_ID 0x0009
OV8865_SENSOR_ID 是kernel层定义的:
mediatek/custom/common /kernel/imgsensor/inc/kd_imgsensor.h
是跟我们的camera驱动进行匹配的。
pOV8865AF_getDefaultData是在lens_para_OV8865AF.cpp中完成的。