高通mm-camera平台 Camera bring up基本調試思路


原文:https://www.cnblogs.com/thjfk/p/4086001.html

確定硬件

1、首先對照原理圖,檢查camera module的pin腳連接是否正確。

2、用示波器量Camera的MCLK管腳,看是否正確,如果MCLK正常,通常情況下PCLK也應該有波形;

MCLK 為camera提供時鍾,給模組內部的pll使用。qualcomm平台是24MHZ。broadcom平台是26MHZ。

3、用萬用表測量Camera的電源管腳,查看Camera的供電是否正常;

AVDD 模擬電路電源 2.8V ,正常情況下,AVDD需要單獨供電,電源紋波<=30mV.

IOVDD/DOVDD/VIF: Power support for IO circuits 1.8V

DVDD 數字電路供電電源 1.2V,如果IOVDD是1.8V的話,推薦使用sensor internal DVDD;硬件上就不要做external DVDD,否則將會導致豎條紋問題的出現。

如果IOVDD是使用2.8V的話,則使用external DVDD,上電時序將改變。

3、查看Camera的Spec文檔,檢查PWDN和RESET的管腳觸發是否正常;檢查代碼中camera power up時序是否與datasheet的一致。

RESET/XSHUTDOWN/XCLR:用來reset sensor;RESET一般是低有效,當脈沖為低時,reset sensor,而正常工作時,應該為高。注意reset的時間要求
PWDN/standby:power down引腳,切斷供電。即powerdown 有效時,camera 為不工作模式。PWDN一般是高有效,當脈沖為高時,進入省電模式,而正常工作時為低。、powe rdown 有效極性。pwdn高有效就是說pwdn為高電平的時候進入power down模式,所以在進入預覽界面的時候就要把pwdn拉低。這樣camera才能進入正常工作狀態
XCLR is reset input signal and power OFF of internal core, camera become standby situation.(Low active)
XCLR=”H”:Usually situation XCLR=”L”:Reset situation
XSHUTDOWN:reset and power down(active low with internal pull down resistor) hardware reset
sony sensor has the build in power on reset function.It automatically initializes the internal circuit by itself when XCLR pin is open and the power supplies are brought up.In addition,if XCLR pin is set to low and the power supplies are bring up.The sensor will skip executing the power on reset function.

4、在Camera的Datasheet中找出該設備的I2C地址,檢查I2C配置是否正確;通常Camera Sensor的Spec上所寫的I2C ID號,還包含了最后一位讀寫方向位。而這一位在I2C總線的定義中,嚴格來說,不屬於ID的一部分,所以Linux I2C的驅動API中的調用參數里的ID號,通常是不考慮這一位的,讀寫方向位會在具體的讀寫操作中,在寄存器中進行設置。

5、查看I2C通信是否正常,是否能正常進行讀寫,用示波器量出I2C的SCL和SDA的波形是否正常,未通信時都為高電平,通信時SCL為I2C時鍾信號,SDA為I2C數據通路信號;

6、讓Sensor FAE檢查Camera的寄存器列表的配置是否正確。

高通的Camera架構

高通平台對於camera的代碼組織,大體上還是遵循Android的框架:即上層應用和HAL層交互,高通平台在HAL層里面實現自己的一套管理策略;在kernel中實現sensor的底層驅動。對於最核心的sensor端的底層設置、ISP效果相關等代碼則是單獨進行了抽離,放在了一個daemon進程中進行管理。

圖1 kernel層camera主要代碼簡圖

如上圖,camera在kernel層的主文件為msm.c,負責設備的具體注冊及相關方法的填充;在msm_sensor.c文件中,主要維護高通自己的一個sensor相關結構體—msm_sensor_ctrl_t,同時把dts文件中的配置信息讀取出來;kernel層對於不同的sensor對應自己的一個驅動文件— xxsensor.c,主要是把power setting的設定填充到msm_sensor_ctrl_t中。

在vendor目錄下,高通把各個sensor實質性的代碼放置在此。一部分代碼是高通自己實現的daemon進程和kernel層及HAL層進行通訊的框架代碼;另一部分則是和sensor相關的chromatix效果代碼和sensor lib部分代碼(init setting、lens info、output info)。

圖2 vendor下主要camera代碼簡圖

如上圖,高通平台通過一個函數指針數組sub_module_init來管理sensor相關的組件;其中重要的是sensor_sub_module_init和chromatix_sub_module_init模塊,對於sensor模塊需要對應填充sensor_lib_t下的接口,對於chromatix模塊則是通過高通的chromatix工具生成。

從更高的層次來看,sensor部分的代碼只是camera子系統的一部分。打開高通vendor下面關於camera的源碼也可以看到,/mm-camera2/media-controller/modules目錄下面,sensors只是modules文件下面其中的一個子目錄。

主要移植步驟

假設camera是imx214

kernel層代碼移植

添加設備樹

在./kernel/arch/arm/boot/dts/msm8226-camera-sensor-qrd.dtsi中新增camera節點,重點關注

  • 節點中的IIC地址
  • sensro的ID信息
  • 電壓設定信息
qcom,camera@21 { //21 is the I2C slave Id of the imx214 

    compatible = "qcom,imx214"; //same as the sensor name used in the project

    reg = <0x21>;
    qcom,slave-id = <0x20 0x0016 0x0214>; //sensor id
    qcom,csiphy-sd-index = <0>;
    qcom,csid-sd-index = <0>;
    qcom,actuator-src = <&actuator1>;
    qcom,led-flash-src = <&led_flash0>;
    qcom,eeprom-src = <&eeprom4>;
    qcom,mount-angle = <90>; // 90 for rear camera and 270 for front camera
    qcom,sensor-name = "imx214";// unique sensor name to differentiate from other sensor

    cam_vdig-supply = <&pm8226_l5>;// defined in kernel/arch/arm/boot/dts/msm8226-regulator.dtsi
    cam_vana-supply = <&pm8226_l15>;
    cam_vio-supply = <&pm8226_lvs1>;
    cam_vaf-supply = <&pm8226_l18>;
    qcom,cam-vreg-name = "cam_vdig", "cam_vio", "cam_vana","cam_vaf";
    qcom,cam-vreg-type = <0 1 0 0>; // 0 for LDO and 1 for LVS
    qcom,cam-vreg-min-voltage = <1100000 1800000 2800000 2950000>;
    qcom,cam-vreg-max-voltage = <1100000 1800000 2800000 2950000>;
    qcom,cam-vreg-op-mode = <120000 0 200000 600000>;
    qcom,gpio-no-mux = <0>;
    gpios = <&msmgpio 26 0>,
    		<&msmgpio 37 0>,
    		<&msmgpio 36 0>,
    		<&msmgpio 15 0>;
    qcom,gpio-reset = <1>;
    qcom,gpio-standby = <2>;
    qcom,gpio-af-pwdm = <3>;
    qcom,gpio-req-tbl-num = <0 1 2 3>;
    qcom,gpio-req-tbl-flags = <1 0 0 0>;
    qcom,gpio-req-tbl-label = 	"CAMIF_MCLK",
    							"CAM_RESET1",
    							"CAM_STANDBY",
    							"CAM_AF_PWDM";
    qcom,csi-lane-assign = <0x4320>;
    qcom,csi-lane-mask = <0x1f>;
    qcom,sensor-position = <0>; // 0 for rear camea and 1 for front camera
    qcom,sensor-mode = <0>; // 0 for bayer format and 1 for yuv format
    qcom,cci-master = <0>;
    status = "ok";
}; 

詳細的文檔請參考 kernel/Documentation/devicetree/bindings/media/video/目錄。

添加sensor驅動

增加以下文件./kernel/drivers/media/platform/msm/camera_v2/sensor/imx214.c

static struct msm_sensor_power_setting imx214_power_setting[] = {
   {
       .seq_type = SENSOR_VREG,
       .seq_val = CAM_VIO,
       .config_val = 0,
       .delay = 1,
   },
   {
       .seq_type = SENSOR_VREG,
       .seq_val = CAM_VANA,
       .config_val = 0,
       .delay = 1,
   },
   {
       .seq_type = SENSOR_VREG,
       .seq_val = CAM_VDIG,
       .config_val = 0,
       .delay = 1,
   },
   {
       .seq_type = SENSOR_VREG,
       .seq_val = CAM_VAF,
       .config_val = 0,
       .delay = 5,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_STANDBY,
       .config_val = GPIO_OUT_LOW,
       .delay = 1,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_RESET,
       .config_val = GPIO_OUT_LOW,
       .delay = 5,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_AF_PWDM,
       .config_val = GPIO_OUT_LOW,
       .delay = 5,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_STANDBY,
       .config_val = GPIO_OUT_HIGH,
       .delay = 5,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_RESET,
       .config_val = GPIO_OUT_HIGH,
       .delay = 10,
   },
   {
       .seq_type = SENSOR_GPIO,
       .seq_val = SENSOR_GPIO_AF_PWDM,
       .config_val = GPIO_OUT_HIGH,
       .delay = 5,
   },
   {
       .seq_type = SENSOR_CLK,
       .seq_val = SENSOR_CAM_MCLK,
       .config_val = 24000000,
       .delay = 10,
   },
   {
       .seq_type = SENSOR_I2C_MUX,
       .seq_val = 0,
       .config_val = 0,
       .delay = 0,
   },
};

添加驅動進編譯系統

在以下文件中添加對imx214的支持

defconfig: ./kernel/arch/arm/configs/msm8226_defconfig

根據lunch 的信息可以找到

CONFIG_IMX214=y

Kconfig:kernel/drivers/media/platform/msm/camera_v2/Kconfig

config IMX214
 	bool "Sensor IMX214 (BAYER 13M)"
 	depends on MSMB_CAMERA
 	---help---
 	Sony 12 MP Bayer Sensor with auto focus, uses
 	4 mipi lanes, preview config = 2104 x 1560 at 49 fps,
 	snapshot config = 4208 x 3120 at 24 fps,
 	Video HDR support.

Makefile:./kernel/drivers/media/platform/msm/camera_v2/sensor/Makefile

obj-$(CONFIG_IMX214) += imx214.o

注冊時鍾./kernel/arch/arm/mach-msm/clock-8226.c

static struct clk_lookup msm_clocks_8226[] = {
CLK_LOOKUP("cam_clk", camss_mclk0_clk.c, "0.qcom,camera"),
CLK_LOOKUP("cam_clk", camss_mclk0_clk.c, "1.qcom,camera"),

+ CLK_LOOKUP("cam_clk", camss_mclk0_clk.c, "21.qcom,camera"),
+ CLK_LOOKUP("cam_src_clk", mclk0_clk_src.c, "21.qcom,camera"),

vendor下代碼移植

Vendor下面的代碼主要是兩部分,一個是sensor_libs目錄下的sensor具體設定、配置文件,

另一個是chromatix下面的ISP效果文件。

具體為:

1、sensor配置:./vendor/qcom/proprietary/mm-camera/mm-camera2/media-controller/modules/sensors/sensor_libs/imx214/imx214_lib.c

/*===========================================================================
 * FUNCTION - imx214_open_lib -
 *
 * DESCRIPTION:
 *==========================================================================*/
void *imx214_open_lib(void)
{
    return &sensor_lib_ptr;
}

This lib will be loaded when camera deamon process is started, kernel will find the handle based on the sensor name in dtb(device tree binary file), so please make sure the file name and function name follow the request for your sensor. 

    <your_sensor_name>/<your_sensor_name>_lib.c 
    void *<your_sensor_name>_open_lib(void)

sensor輸出設置

static struct sensor_lib_out_info_t sensor_out_info[] = { 
{ 
        /* vt_pixel_clk = .line_length_pclk* frame_length_lines*frame rate */
        /* op_pixel_clk = VFE working clk */
        ....
}

2、chromatix目錄下相關文件,在對應sensor目錄下包含4個目錄和一個Android文件,總共13個文件,這些文件都會由chromatix調試工具生成。

圖8 vendor下chromatix相關文件示例圖

3、vendor下還有eeprom文件,模組自帶的eeprom數據處理相關;AF相關文件,調試工具生成的關於AF的效果文件;配置文件,把需要編譯的模塊填進配置文件中。

Acuator porting


./kernel/drivers/media/video/msm/actuators/actuator.c

msm_actuator_ctrl_t contains all the information about the actuator setting related to sensors like 
i2c addr, set_info, focal length, etc. All the info is loaded from the chromatix file for the sensor.

In af header file, the driver engineer should take care of the structure of actuator_params_t, which contains the af drive ic address, register patten, etc. It is important for AF working.

調試常見問題

kernel和vendor下命名匹配

在參考其他代碼移植調試一個新sensor的過程中,要注意在對應的dts文件中給sensor配置節點信息的過程中,“qcom,sensor-name”字段的配置要和vendor下面的sensor lib代碼中的“xxx_open_lib”函數名以及對應的Android.mk中的“LOCAL_MODULE”名稱匹配,否則相應sensor的vendor下庫文件無法調用,這時打開camera會出現閃退現象。具體可參考平台代碼sensor.c中的sensor_load_library()函數。

圖10 camera name匹配詳圖

sensor lib中的sensor_lib_out_info_t填充

一般來說,每個sensor可以配置輸出不同大小的圖像。此時,除了進行對應的sensor setting來改變sensor自身的輸出及相關配置外;還需要將相關的輸出大小、幀率等信息通知平台端,即填充struct sensor_lib_out_info_t結構體。

圖11 高通平台獲取sensor信息框圖

填充的這個sensor_lib_out_info_t中的成員,最終會作為sensor基本信息的一部分被HAL層獲取到,上圖為高通平台獲取sensor信息的一個簡單框圖。

在調試過程中,需要注意的是這個結構體的成員max_fps需要填寫至少大於等於30;否則會因為在獲取capability時無法得到有效的previewsize、video size而無法進入預覽。具體可參考平台代碼mct_pipeline.c中的mct_pipeline_populate_query_cap_buffer()函數。

sensorlib中的exposure_table_size填寫

對於sensor端輸出RAW數據,平台端進行ISP處理的情形來說,sensor端除了基本的init配置外,另外一個就是根據平台端AEC計算出來的數據來對應調整sensor的曝光。在高通平台上將平台端的AEC和具體的sensor曝光設置聯系起來的是chromatix文件中的一個Exposure Table和sensor lib文件中的exposure對應接口。

這里的exposure_table_size對應着sensor lib中sensor_fill_exposure_array()接口寫入的sensor寄存器的個數,平台代碼中需要根據這個exposure_table_size來動態分配內存大小。如果這個值的填寫和sensor_fill_exposure_array()中實際寫入的值大小不一致,就會造成內存方面的crash。具體可參考平台代碼sensor.c中的sensor_apply_exposure()函數。

kernel 層非常規設定

對於一些sensor來說,對於電壓的設定或是MCLK的設定有非常規要求的時候,可能就需要修改平台上相關的默認設定。

對於sensor的幾路工作電壓 (AVDD、DVDD、IOVDD),平台端一般都是通過PMIC的相應regulator供電,而硬件上regulator的輸出能力一般都有限制,代碼上也會有體現。如果有sensor需要的電壓超過代碼上相應regulator的限制值,可以查看PMIC上的說明,如果代碼上的限制值並不是硬件的真正極限,可以修改平台代碼解決。

對於MCLK的設定,高通平台有一些常規的值設定。如果sensor有特殊要求,而這個MCLK不能被平台識別,這時候可以在平台的clock相關代碼中,通過配置平台的PLL參數來生成特定的MCLK時鍾給sensor使用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM