前些天在调试一组高通msm8926上的摄像头,之前ov5648+imx135已正常的点亮了,但是后续需要一个mini配置版本的方案,需要兼容ov2685+ov8865,于是先做好调试的前期准备,跟摄像头模组厂要模组spec和芯片的datasheet,先仔细阅读一下ic的datasheet,并仔细查看模组的打样图纸和模组spec,首先要确认的是ic的各路电压是可以正常的供出,一般需要注意的就是DVDD,IOVDD,AVDD,还有STANDBY和RESET,这些管脚的连接要和主板上兼容,确保在硬件上主板可以正常的兼容摄像头模组,我就开始被模组厂忽悠了,有一组DVDD电压说是可以不用去供电,ic也可以正常工作,我阅读ic的datasheet就发现不对,但是既然是模组厂已确认是可以兼容的,我开始居然天真的被相信了!冋阿,善良程序猿的悲哀,太容易相信别人了,!
模组厂提供了基本的ic驱动代码之后,首先需要在kernel中兼容这组摄像头,展讯去配置Camera的Kconfig和Makefile,以及sensorcfg就可以基本完成对新Camera senssor的兼容,高通上处理就有些不一样,由于目前高通平台引入了设备树dts来配置内核信息,关于设备树,各位童鞋可以查看我的相关博客-点击打开链接去了解更多相关知识,首先是在设备树中配置Camera ic的i2c从地址芯片和各个控制管脚的gpio和e2prom的配置信息,这个地方需要注意的是,模组手册对这个从设备地址没有统一的写法,有的给出8位地址,有的给出7位地址,一开始容易混淆。如果给出的是8位地址,那第8位是指Write-0或者Read-1,实际的I2C芯片地址是7位的,内核中配置的地址是真实地址,这个需要格外的注意,不然就会造成i2c不通,导致摄像头驱动加载失败。
配置完相关信息,开机进入摄像头测试,发现摄像头已停止,无法连接到设备,抓取相关的内核log,发现是match id失败,导致驱动加载不成功,这个我最开始怀疑的就是相关的电压没能正常起来,用电压表,测起,发现电压貌似正常,然后我再次怀疑是设备的从地址有问题,跟模组厂再三确认,他们依旧说这个从地址是没问题的,唉,这货简直是睁着眼睛说瞎话,众所周知,ov的FAE非常难请来现场调试,所以只能抄示波器自己先看看,果然示波器抓取驱动加载时的各路电压貌似出了问题,虽然驱动上电这个过程非常的短暂,但是还是在数次的抓取中,终于成功抓到了这个开机加载驱动转瞬即逝的上电时序波形,我再次分析一下这个加载驱动的log,log如下:
<6>[ 4.582687] synaptics_rmi4_i2c 5-0020: fwu_read_f34_queries perm:1, bl:1, display:0
<3>[ 4.594144] msm_camera_power_up type 2
<3>[ 4.599995] msm_camera_power_up index 1
<3>[ 4.602787] msm_camera_power_up type 2
<3>[ 4.608830] msm_camera_power_up index 2
<3>[ 4.611622] msm_camera_power_up type 2
<3>[ 4.617866] msm_camera_power_up index 3
<3>[ 4.620658] msm_camera_power_up type 2
<3>[ 4.630691] msm_camera_power_up index 4
<3>[ 4.633482] msm_camera_power_up type 1
<3>[ 4.637215] msm_camera_power_up index 5
<3>[ 4.641060] msm_camera_power_up type 1
<3>[ 4.644768] msm_camera_power_up:1023 gpio set val 37
<3>[ 4.655759] msm_camera_power_up index 6
<3>[ 4.658573] msm_camera_power_up type 1
<3>[ 4.662282] msm_camera_power_up index 7
<3>[ 4.666102] msm_camera_power_up type 1
<3>[ 4.669857] msm_camera_power_up index 8
<3>[ 4.673654] msm_camera_power_up type 1
<3>[ 4.677408] msm_camera_power_up:1023 gpio set val 37
<3>[ 4.693360] msm_camera_power_up index 9
<3>[ 4.696151] msm_camera_power_up type 1
<3>[ 4.699907] msm_camera_power_up index 10
<3>[ 4.703790] msm_camera_power_up type 0
<3>[ 4.718602] msm_camera_power_up index 11
<3>[ 4.721480] msm_camera_power_up type 3
<3>[ 4.725312] msm_camera_power_up exit
<3>[ 4.728945] msm_cci_irq:852 MASTER_0 error 10000000
<3>[ 4.733666] msm_cci_i2c_read:426 read_words = 0, exp words = 1
<3>[ 4.739474] msm_cci_i2c_read_bytes:504 failed rc -22
<3>[ 4.744398] msm_camera_cci_i2c_read: line 53 rc = -22
<3>[ 4.749454] msm_sensor_match_id: ov8865_q8v18a: read id failed
<3>[ 4.755249] msm_sensor_check_id:1055 match id failed rc -22
<3>[ 4.760824] msm_camera_power_down:1154
<3>[ 4.764581] msm_camera_power_down index 0
<3>[ 4.768552] msm_camera_power_down type 3
<3>[ 4.772434] msm_camera_power_down index 1
<3>[ 4.776427] msm_camera_power_down type 0
<3>[ 4.791392] msm_camera_power_down index 2
<3>[ 4.794358] msm_camera_power_down type 1
<3>[ 4.798288] msm_camera_power_down index 3
<3>[ 4.802256] msm_camera_power_down type 1
<3>[ 4.817189] msm_camera_power_down index 4
<3>[ 4.820213] msm_camera_power_down type 1
<3>[ 4.824060] msm_camera_power_down index 5
<3>[ 4.828076] msm_camera_power_down type 1
<3>[ 4.831959] msm_camera_power_down index 6
<3>[ 4.835951] msm_camera_power_down type 1
<3>[ 4.845902] msm_camera_power_down index 7
<3>[ 4.848890] msm_camera_power_down type 1
<3>[ 4.852773] msm_camera_power_down index 8
<3>[ 4.856766] msm_camera_power_down type 2
<3>[ 4.866952] msm_camera_power_down index 9
<3>[ 4.869942] msm_camera_power_down type 2
<3>[ 4.876452] msm_camera_power_down index 10
<3>[ 4.879527] msm_camera_power_down type 2
<3>[ 4.885664] msm_camera_power_down index 11
<3>[ 4.888740] msm_camera_power_down type 2
<3>[ 4.894707] msm_camera_power_down exit
<3>[ 4.897436] msm_sensor_platform_probe ov8865_q8v18a power up failed
<4>[ 4.903675] ovti,ov8865: probe of 20.qcom,camera failed with error -22
<3>[ 4.910245] ov8865_init_module:158 rc -19
<3>[ 4.915152] msm_sensor_platform_probe called data c0e98778
<3>[ 4.919663] msm_sensor_platform_probe pdev name (null)
<3>[ 4.924760] msm_sensor_get_dt_data qcom,sensor-name ov2685, rc 0
<3>[ 4.930771] msm_sensor_get_dt_data qcom,cci-master 0, rc 0
<3>[ 4.936217] msm_sensor_get_sub_module_index:125 src_node NULL
<3>[ 4.941968] msm_sensor_get_sub_module_index:141 eeprom src_node NULL
<3>[ 4.948305] msm_sensor_get_sub_module_index:169 src_node NULL
<3>[ 4.954014] msm_sensor_get_sub_module_index csiphy_core[0] = 1
<3>[ 4.959851] msm_sensor_get_sub_module_index csid_core[0] = 1
<3>[ 4.965469] msm_sensor_get_dt_data qcom,mount-angle 90, rc 0
<3>[ 4.971135] msm_sensor_get_dt_data qcom,sensor-position 1, rc 0
<3>[ 4.977014] msm_sensor_get_dt_data qcom,sensor-mode 1, rc 0
<3>[ 4.982594] msm_sensor_get_dt_csi_data qcom,csi-lane-assign 4320, rc 0
<3>[ 4.989102] msm_sensor_get_dt_csi_data qcom,csi-lane-mask 3, rc 0
<3>[ 4.995157] msm_camera_get_dt_vreg_data qcom,cam-vreg-name count 3
<3>[ 5.001343] msm_camera_get_dt_vreg_data reg_name[0] = cam_vdig
<3>[ 5.007136] msm_camera_get_dt_vreg_data reg_name[1] = cam_vio
<3>[ 5.012892] msm_camera_get_dt_vreg_data reg_name[2] = cam_vana
<3>[ 5.018704] msm_camera_get_dt_vreg_data cam_vreg[0].type = 0
<3>[ 5.024322] msm_camera_get_dt_vreg_data cam_vreg[1].type = 1
<3>[ 5.029987] msm_camera_get_dt_vreg_data cam_vreg[2].type = 0
<3>[ 5.035608] msm_camera_get_dt_vreg_data cam_vreg[0].min_voltage = 2050000
<3>[ 5.042399] msm_camera_get_dt_vreg_data cam_vreg[1].min_voltage = 2800000
<3>[ 5.049196] msm_camera_get_dt_vreg_data cam_vreg[2].min_voltage = 2850000
<3>[ 5.055921] msm_camera_get_dt_vreg_data cam_vreg[0].max_voltage = 2050000
<3>[ 5.062713] msm_camera_get_dt_vreg_data cam_vreg[1].max_voltage = 2800000
<3>[ 5.069519] msm_camera_get_dt_vreg_data cam_vreg[2].max_voltage = 2850000
<3>[ 5.076233] msm_camera_get_dt_vreg_data cam_vreg[0].op_mode = 200000
<3>[ 5.082592] msm_camera_get_dt_vreg_data cam_vreg[1].op_mode = 0
<3>[ 5.088493] msm_camera_get_dt_vreg_data cam_vreg[2].op_mode = 80000
<3>[ 5.094724] msm_camera_get_dt_power_setting_data qcom,cam-power-seq-type count -22
<3>[ 5.102345] msm_sensor_get_dt_data gpio count 2
<3>[ 5.106795] msm_sensor_get_dt_data gpio_array[0] = 26
<3>[ 5.111860] msm_sensor_get_dt_data gpio_array[1] = 35
<3>[ 5.116863] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[0].gpio = 26
<3>[ 5.123565] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[1].gpio = 35
<3>[ 5.130249] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[0].flags = 1
<3>[ 5.136909] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[1].flags = 0
<3>[ 5.143617] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[0].label = CAMIF_MCLK
<3>[ 5.151082] msm_camera_get_dt_gpio_req_tbl cam_gpio_req_tbl[1].label = CAM_STANDBY
<3>[ 5.158640] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[0].gpio = 35
<3>[ 5.165295] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[1].gpio = 35
<3>[ 5.172003] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[0].flags = 0
<3>[ 5.178684] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[1].flags = 2
<3>[ 5.185349] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[0].delay = 1000
<3>[ 5.192312] msm_camera_get_dt_gpio_set_tbl cam_gpio_set_tbl[1].delay = 4000
<3>[ 5.199265] msm_camera_init_gpio_pin_tbl qcom,gpio-reset 35
<3>[ 5.204797] msm_sensor_get_dt_actuator_data qcom,actuator-cam-name 0, rc -22
<3>[ 5.211848] msm_sensor_get_dt_data:291 slave addr 78 sensor reg 300a id 2685
<3>[ 5.218878] msm_sensor_get_dt_data qcom,misc_regulator (null), rc -22
<3>[ 5.225280] msm_camera_power_up:959
<3>[ 5.228782] msm_camera_power_up index 0
<3>[ 5.232568] msm_camera_power_up type 2
<3>[ 5.240940] msm_camera_power_up index 1
<3>[ 5.243731] msm_camera_power_up type 2
<3>[ 5.250775] msm_camera_power_up index 2
<3>[ 5.253566] msm_camera_power_up type 2
<3>[ 5.263427] msm_camera_power_up index 3
<3>[ 5.266218] msm_camera_power_up type 1
<3>[ 5.269976] msm_camera_power_up:1023 gpio set val 35
<3>[ 5.280925] msm_camera_power_up index 4
<3>[ 5.283716] msm_camera_power_up type 1
<3>[ 5.287473] msm_camera_power_up:1023 gpio set val 35
<3>[ 5.298422] msm_camera_power_up index 5
<3>[ 5.301212] msm_camera_power_up type 0
<3>[ 5.325996] msm_camera_power_up index 6
<3>[ 5.328812] msm_camera_power_up type 3
<3>[ 5.332624] msm_camera_power_up exit
<3>[ 5.427310] msm_cci_i2c_read: wait_for_completion_interruptible_timeout 410
<3>[ 5.527309] msm_cci_flush_queue:106 wait timeout
<3>[ 5.530899] msm_cci_i2c_read_bytes:504 failed rc -110
<3>[ 5.535916] msm_camera_cci_i2c_read: line 53 rc = -110
<3>[ 5.541063] msm_sensor_match_id: ov2685: read id failed
<3>[ 5.546247] msm_sensor_check_id:1055 match id failed rc -110
<3>[ 5.551911] msm_camera_power_down:1154
<3>[ 5.555665] msm_camera_power_down index 0
<3>[ 5.559638] msm_camera_power_down type 3
<3>[ 5.563521] msm_camera_power_down index 1
<3>[ 5.567571] msm_camera_power_down type 0
<3>[ 5.592458] msm_camera_power_down index 2
<3>[ 5.595424] msm_camera_power_down type 1
<5>[ 5.599370] fwu_start_reflash: Start of reflash process
仔细分析log,发现i2c地址应该是有问题,报着试试的态度,对地址进行了移位,转换成认为的真实地址,编译代码发现,还是无法打开设备,仔细检查原理图和打样图纸,让硬件把dvdd将上拉电阻接到一个PMIC的控制脚上,我想按照datasheet的上电时序再来一遍,编译烧写文件,怀着忐忑的心情打开摄像头,居然亮了,着实激动了一把,我擦,坑爹的模组厂,差点害我放弃点亮这颗摄像头了!
后摄还是无法打开摄像头,参考上电时序和电路原理图,将STANDBYf飞线到主板上一个不用gpio,我按照上电时序修改poweron代码,也正常点亮了--至此,已基本完成了在高通msm8926上对ov2685+ov8865的兼容!
得出的调试经验给大家分享一下:
1 Camera驱动加载失败的原因大部分就是i2c和电压不对,请确保这些是正常配置的。
2.仔细分析内核的调试log,在关键的地方加调试信息,善用示波器和电压表等辅助调试设备,分析失败的根本原因
3 严格按照spec和datasheet,当然要确保你的资料是正确的,不要轻易的相信别人的信息,特别是调试出现问题的时候,你需要逐步去排除各种可能的错误
希望这些能帮到那些正在痛苦调试的程序猿,大家共勉!