MT6739 Camera驱动移植文档

文章目录

  • 把厂商提供的驱动代码拷贝到对应路径
    • KERNEL层
    • HAL层
  • (1) 修改ProjectConfig.mk配置文件
      • 修改与imgsensor相关的配置信息
      • 修改与lens相关的配置信息
      • 修改flashlight相关配置信息
  • (2) 修改defconfig配置文件
  • (3) 修改内核驱动代码
      • 添加新的camera sensor ID定义
      • 添加新的Camera Sensor 初始化函数声明
  • (4) 修改HAL层驱动代码
      • 在HAL层的Sensor 列表添加新的Sensor
  • (5) 修改内核代码中关于上电时序的代码
  • (6) 设备树中的配置
      • cust.dtsi 中对camera的配置
      • 设置上下电用到的LDO GPIO
      • 确定Camera Sensor使用的供电方式
      • MIPI 上下电时序

平台 os版本 内核
MT6739 Android 9.0 kernel-4.4

把厂商提供的驱动代码拷贝到对应路径

KERNEL层

把厂商提供的包含前摄像头驱动文件夹 gc2385_mipi_raw 和后摄像头驱动文件夹 gc5035cmipi_raw 拷贝到目录 ./kernel-4.4/drivers/misc/mediatek/imgsensor/src/mt6739/
MT6739 Camera驱动移植文档_第1张图片
这两个文件夹里存放着厂商写好的前后摄像头驱动代码。

HAL层

lens文件路径:
./vendor/mediatek/proprietary/custom/mt6739/hal/lens/k39tv1_bsp_1g/dw9714af
MT6739 Camera驱动移植文档_第2张图片
imgsensor文件路径:
./vendor/mediatek/proprietary/custom/mt6739/hal/imgsensor/gc2385_mipi_raw
MT6739 Camera驱动移植文档_第3张图片
flashlight文件路径:
./vendor/mediatek/proprietary/custom/mt6739/hal/flashlight/k39tv1_bsp_1g
在这里插入图片描述
TSF文件路径:
./vendor/mediatek/proprietary/custom/mt6739/hal/imgsensor/
添加文件:
gc2385_mipi_raw/camera_tsf_para_gc2385mipiraw.h
​ gc2385_mipi_raw/camera_tsf_data_gc2385mipiraw.h


(1) 修改ProjectConfig.mk配置文件

文件路径:
./device/mediatek/k39tv1_bsp_1g/ProjectConfig.mk

修改与imgsensor相关的配置信息

CUSTOM_HAL_IMGSENSOR = gc5035cmipi_raw sp2509_mipi_raw gc2385_mipi_raw
CUSTOM_HAL_MAIN_IMGSENSOR = gc5035cmipi_raw
CUSTOM_HAL_SUB_IMGSENSOR = sp2509_mipi_raw gc2385_mipi_raw
CUSTOM_KERNEL_IMGSENSOR = gc5035cmipi_raw sp2509_mipi_raw gc2385_mipi_raw
CUSTOM_KERNEL_MAIN_IMGSENSOR = gc5035cmipi_raw
CUSTOM_KERNEL_SUB_IMGSENSOR = sp2509_mipi_raw gc2385_mipi_raw

修改与lens相关的配置信息

CUSTOM_HAL_LENS = dw9718saf dw9714af dummy_lens
CUSTOM_HAL_MAIN_LENS = dw9718saf dw9714af
CUSTOM_HAL_SUB_LENS = dummy_lens
CUSTOM_KERNEL_LENS = dw9718saf dw9714af dummy_lens
CUSTOM_KERNEL_MAIN_LENS = dw9718saf dw9714af
CUSTOM_KERNEL_SUB_LENS = dummy_lens

修改flashlight相关配置信息

支持 Flashlight 则将对应的CUSTOM_xxxx设置为 constant_flashlight ,不支持设置为 dummy_flashlight

CUSTOM_HAL_FLASHLIGHT = dummy_flashlight
CUSTOM_KERNEL_FLASHLIGHT = constant_flashlight

(2) 修改defconfig配置文件

文件路径:

./kernel-4.4/arch/arm/configs/k39tv1_bsp_1g_defconfig
./kernel-4.4/arch/arm/configs/k39tv1_bsp_1g_debug_defconfig

CONFIG_CUSTOM_KERNEL_IMGSENSOR="gc5035cmipi_raw sp2509_mipi_raw gc2385_mipi_raw"

(3) 修改内核驱动代码

添加新的camera sensor ID定义

文件路径:
./device/mediatek/common/kernel-headers/kd_imgsensor.h

#define GC2385_SENSOR_ID                        0x2385
#define GC5035CMIPI_SENSOR_ID                   0x5035

#define SENSOR_DRVNAME_GC2385_MIPI_RAW          "gc2385_mipi_raw"
#define SENSOR_DRVNAME_GC5035C_MIPI_RAW         "gc5035cmipi_raw"

上面定义的 sensor ID 来自于对应的 datasheet

文件路径:

./kernel-4.4/drivers/misc/mediatek/imgsensor/inc/kd_imgsensor.h

#define GC2385_SENSOR_ID                        0x2385
#define GC5035CMIPI_SENSOR_ID                   0x5035

#define SENSOR_DRVNAME_GC2385_MIPI_RAW          "gc2385_mipi_raw"
#define SENSOR_DRVNAME_GC5035C_MIPI_RAW         "gc5035cmipi_raw"

添加新的Camera Sensor 初始化函数声明

文件路径:
./kernel-4.4/drivers/misc/mediatek/imgsensor/src/common/v1/imgsensor_sensor_list.h

UINT32 GC2385_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);
UINT32 GC5035CMIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);

文件路径:
./kernel-4.4/drivers/misc/mediatek/imgsensor/src/common/v1/imgsensor_sensor_list.c

#if defined(GC2385_MIPI_RAW)
	{GC2385_SENSOR_ID, SENSOR_DRVNAME_GC2385_MIPI_RAW, GC2385_MIPI_RAW_SensorInit},
#endif

#if defined(GC5035CMIPI_RAW)
	{GC5035CMIPI_SENSOR_ID, SENSOR_DRVNAME_GC5035C_MIPI_RAW, GC5035CMIPI_RAW_SensorInit},
#endif

第一个参数对应 Camera Sensor ID
第二个参数对应 Camera Sensor name ;
第三个参数对应 Camera Sensor init Function


(4) 修改HAL层驱动代码

在HAL层的Sensor 列表添加新的Sensor

文件路径:
./vendor/mediatek/proprietary/custom/mt6739/hal/imgsensor_src/sensorlist.cpp

#if defined(GC2385_MIPI_RAW)
    RAW_INFO(GC2385_SENSOR_ID, SENSOR_DRVNAME_GC2385_MIPI_RAW, NULL),
#endif

#if defined(GC5035CMIPI_RAW)
	RAW_INFO(GC5035CMIPI_SENSOR_ID, SENSOR_DRVNAME_GC5035C_MIPI_RAW, NULL),
#endif

Note: sensorlist.cpp 中的 SensorList[] 与 kd_sensorlist.h 中的 kdSensorList[].sensor 的顺序必须一致,否则 user space 和 kernel space 在通过 ioctl 传递命令 id 时会对应错误。


(5) 修改内核代码中关于上电时序的代码

文件路径:
./kernel-4.4/drivers/misc/mediateck/imgsensor/src/mt6739/camera_hw/imgsensor_cfg_table.c

struct IMGSENSOR_HW_POWER_SEQ sensor_power_sequence[] = {
... /* 省略部分代码 */

#if defined(GC2385_MIPI_RAW)
	{
		SENSOR_DRVNAME_GC2385_MIPI_RAW,
		{
			{DOVDD, Vol_1800, 2},
			{DVDD, Vol_1200, 2},
			{AVDD, Vol_2800, 2},
			{SensorMCLK, Vol_High, 2},
			{PDN, Vol_Low, 2},
			{PDN, Vol_High, 2},
			{RST, Vol_Low, 2},
			{RST, Vol_High, 5},
		},
	},
#endif

#if defined(GC5035CMIPI_RAW)
	{
		SENSOR_DRVNAME_GC5035C_MIPI_RAW,
		{
			{DOVDD, Vol_1800, 2},
			{DVDD, Vol_1200, 2},
			{AVDD, Vol_2800, 2},
			{SensorMCLK, Vol_High, 2},
			{PDN, Vol_Low, 2},
			{PDN, Vol_High, 2},
			{RST, Vol_Low, 2},
			{RST, Vol_High, 5},
		#if defined(CONFIG_k39tv1_bsp_1g_PROJECT)
			//{AFVDD, Vol_2800, 1},
		#endif
		},
	},
#endif
    
...
    {NULL,},
};

第一个参数对应 PowerType
第二个参数对应 Voltage
第三个参数对应 Delay Time in ms

DVDD/DOVDD/AVDD/AFVDD 的电压支持情况可以参考 specific pmic datasheet 进行设置。

例如 mt6351:

Power Type voltage(v)
DVDD 0.9/0.95/1.0/1.05/1.1/1.2/1.21
DOVDD 0.9/0.95/1.0/1.05/1.2/1.5/1.8
AVDD 1.8/2.2/2.375/2.8
AFVDD 1.2/1.3/1.5/1.8/2.0/2.8/3.0/3.3

(6) 设备树中的配置

设备树里的 compatible 最开始是在哪里产生的呢?
答案: 通过 dws 工具匹配出来的,通过dws 工具修改,生成文件 k39tv1_bsp_1g.dws

dws 工具路径:
./vendor/mediatek/proprietary/scripts/dct/DrvGen.exe
MT6739 Camera驱动移植文档_第4张图片
dws 文件路径:
./kernel-4.4/drivers/misc/mediatek/dws/mt6739/k39tv1_bsp_1g.dws
MT6739 Camera驱动移植文档_第5张图片
通过 DrvGen.exe 这个工具可以修改 k39tv1_bsp_1g.dws 文件中各参数的配置。

通过上述截图可以发现,主摄像头 CAMERA_MAINI2C通讯地址是 0x37CAMERA_SUBI2C 通讯地址是 0x3C ,对应生成的文件是 cust.dtsi

cust.dtsi 中对camera的配置

文件路径:
./out/target/product/k39tv1_bsp_1g/obj/KERNEL_OBJ/arch/arm/boot/dts/k39tv1_bsp_1g/cust.dtsi

&i2c2 {
        #address-cells = <1>;
        #size-cells = <0>;
        clock-frequency = <400000>;
        mediatek,use-open-drain;
        camera_main_mtk:camera_main@37 {
                compatible = "mediatek,camera_main";
                reg = <0x37>;
                status = "okay";
        };

        camera_main_af_mtk:camera_main_af@0c {
                compatible = "mediatek,camera_main_af";
                reg = <0x0c>;
                status = "okay";
        };

        camera_sub_mtk:camera_sub@3c {
                compatible = "mediatek,camera_sub";
                reg = <0x3c>;
                status = "okay";
        };
};

代码中想要成功调用到后摄像头对应的 imgsensor_i2c_probe_1() 和前摄像头 imgsensor_i2c_probe_2() 函数需要分别匹配上 cust.dtsi 文件中的 compatible 节点 “mediatek,camera_main”"mediatek,camera_sub"

设置上下电用到的LDO GPIO

因为 mt6739 使用的是PMIC的方式进行供电,所以不需要配置 LDO 的供电方式。

文件路径:
./kernel-4.4/arch/arm/boot/dts/k39tv1_bsp_1g.dts

&pio {

    ... /* 省略无关代码 */
        
	camera_pins_cam_ldo_sub_vcamd_0: cam1@vcamd0 {
		pins_cmd_dat {
			pins = <PINMUX_GPIO9__FUNC_GPIO9>;
			slew-rate = <1>;
			output-low;
		};
	};
	camera_pins_cam_ldo_sub_vcamd_1: cam1@vcamd1 {
		pins_cmd_dat {
			pins = <PINMUX_GPIO9__FUNC_GPIO9>;
			slew-rate = <1>;
			output-high;
		};
	};

    ... /* 省略无关代码 */
        
	camera_pins_default: camdefault {
	};
};

&kd_camera_hw1 {
	pinctrl-names = "default",
			..., /* 省略无关代码 */
			"cam_ldo_sub_vcamd_0", "cam_ldo_sub_vcamd_1",
			...; /* 省略无关代码 */

	... /* 省略无关代码 */
        
	pinctrl-9 = <&camera_pins_cam_ldo_sub_vcamd_0>;
	pinctrl-10 = <&camera_pins_cam_ldo_sub_vcamd_1>;
	
    ... /* 省略无关代码 */
	status = "okay";
};

&camera_pins_cam0_rst0 {
	pins_cmd_dat {
		pins = <PINMUX_GPIO28__FUNC_GPIO28>;
		slew-rate = <1>; /*direction 0:in, 1:out*/
		output-low;/*direction out used only. output_low or high*/
	};
};

&camera_pins_cam0_rst1 {
	pins_cmd_dat {
		pins = <PINMUX_GPIO28__FUNC_GPIO28>;
		slew-rate = <1>; /*direction 0:in, 1:out*/
		output-high;/*direction out used only. output_low or high*/
	};
};

&camera_pins_cam1_pnd0 {
	pins_cmd_dat {
			pins = <PINMUX_GPIO31__FUNC_GPIO31>;
			slew-rate = <1>;
			output-low;
		};
};

&camera_pins_cam1_pnd1 {
	pins_cmd_dat {
			pins = <PINMUX_GPIO31__FUNC_GPIO31>;
			slew-rate = <1>;
			output-high;
		};
};

&camera_pins_cam_ldo_sub_vcamd_0 {
};

&camera_pins_cam_ldo_sub_vcamd_1 {
};

&camera_pins_cam1_mclk_on {
	pins_cmd_dat {
		pins = <PINMUX_GPIO127__FUNC_CMMCLK0>;
	};
};

&camera_pins_cam1_mclk_off {
	pins_cmd_dat {
		pins = <PINMUX_GPIO127__FUNC_GPIO127>;
	};
};

&kd_camera_hw1 {
	pinctrl-names = "default",
			"cam0_rst0", "cam0_rst1", "cam0_pnd0", "cam0_pnd1",
			"cam1_rst0", "cam1_rst1", "cam1_pnd0", "cam1_pnd1",
			"cam0_mclk_on", "cam0_mclk_off",
			"cam1_mclk_on", "cam1_mclk_off";

	pinctrl-0 = <&camera_pins_default>;
	pinctrl-1 = <&camera_pins_cam0_rst0>;
	pinctrl-2 = <&camera_pins_cam0_rst1>;
	pinctrl-3 = <&camera_pins_cam0_pnd0>;
	pinctrl-4 = <&camera_pins_cam0_pnd1>;
	pinctrl-5 = <&camera_pins_cam1_rst0>;
	pinctrl-6 = <&camera_pins_cam1_rst1>;
	pinctrl-7 = <&camera_pins_cam1_pnd0>;
	pinctrl-8 = <&camera_pins_cam1_pnd1>;
	pinctrl-9 = <&camera_pins_cam0_mclk_on>;
	pinctrl-10 = <&camera_pins_cam0_mclk_off>;
	pinctrl-11 = <&camera_pins_cam1_mclk_on>;
	pinctrl-12 = <&camera_pins_cam1_mclk_off>;

	camera0_mclk_gpio = <126>;
	camera1_mclk_gpio = <127>;

	status = "okay";

};

由上面代码可以发现有两个 kd_camera_hw1 ,这里遵循一种规则:

  • 如果第一个 kd_camera_hw1 中定义的属性在第二个 kd_camera_hw1 中也有定义则使用第二个 kd_camera_hw1 中定义的属性;
  • 如果第一个 kd_camera_hw1 中定义的属性在第二个 kd_camera_hw1 中没有定义,则使用第一个 kd_camera_hw1 中定义的属性;

确定Camera Sensor使用的供电方式

AVDD 引脚设置为 IMGSENSOR_HW_ID_REGULATOR 说明使用的是 PMIC 的方式供电。

文件路径:
./kernel-4.4/dirvers/misc/mediateck/imgsensor/src/mt6739/camera_hw/imgsensor_cfg_table.c

struct IMGSENSOR_HW_CFG imgsensor_custom_config[] = {
	{
		IMGSENSOR_SENSOR_IDX_MAIN, /* 主摄 */
		IMGSENSOR_I2C_DEV_0,
		{
			{IMGSENSOR_HW_ID_MCLK,      IMGSENSOR_HW_PIN_MCLK},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_AVDD},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_DOVDD},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_DVDD},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_AFVDD},
			{IMGSENSOR_HW_ID_GPIO,      IMGSENSOR_HW_PIN_PDN},
			{IMGSENSOR_HW_ID_GPIO,      IMGSENSOR_HW_PIN_RST},
			{IMGSENSOR_HW_ID_NONE,      IMGSENSOR_HW_PIN_NONE},
		},
	},
	{
		IMGSENSOR_SENSOR_IDX_SUB, /* 副摄 */
		IMGSENSOR_I2C_DEV_1,
		{
			{IMGSENSOR_HW_ID_MCLK,      IMGSENSOR_HW_PIN_MCLK},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_AVDD},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_DOVDD},
			{IMGSENSOR_HW_ID_REGULATOR, IMGSENSOR_HW_PIN_DVDD},
			{IMGSENSOR_HW_ID_GPIO,      IMGSENSOR_HW_PIN_PDN},
			{IMGSENSOR_HW_ID_GPIO,      IMGSENSOR_HW_PIN_RST},
			{IMGSENSOR_HW_ID_NONE,      IMGSENSOR_HW_PIN_NONE},
		},
	},

    ... /* 省略无关代码 */

	{IMGSENSOR_SENSOR_IDX_NONE}
};

MIPI 上下电时序

文件路径:

./kernel-4.4/drivers/misc/mediatek/imgsensor/src/mt6739/camera_hw/imgsensor_cfg_table.c

struct IMGSENSOR_HW_POWER_SEQ platform_power_sequence[] = {
#ifdef MIPI_SWITCH
	{
		IMGSENSOR_SENSOR_IDX_NAME_SUB, /* 操作sub sensor */
		{
			{
				IMGSENSOR_HW_PIN_MIPI_SWITCH_EN,    /* EN管脚 */
				IMGSENSOR_HW_PIN_STATE_LEVEL_HIGH,  /* 上电拉高 */
				0,									/* 下电延时 */
				IMGSENSOR_HW_PIN_STATE_LEVEL_0,		/* 下电拉高 */
				0									/* 下电延时 */
			},
			{
				IMGSENSOR_HW_PIN_MIPI_SWITCH_SEL,	/* SEL管脚 */
				IMGSENSOR_HW_PIN_STATE_LEVEL_0,		/* 上电拉高 */
				0,									/* 上电延时 */
				IMGSENSOR_HW_PIN_STATE_LEVEL_HIGH,	/* 下电拉低 */
				0									/* 下电延时 */
			},
		}
	},
	{
		... /* 省略无关代码 */
#endif

	{NULL}
};

你可能感兴趣的:(camera)