和你一起终身学习,这里是程序员Android
经典好文推荐,通过阅读本文,您将收获以下知识点:
一 、ProjectConfig.mk文件配置
二、defconfig文件修改
三、kernel层驱动代码
四、hal层驱动代码
五、kernel层摄像头文件夹
六、hal层摄像头文件夹
七、sensor上下电代码
这里记录添加一个新的sensor需要注意的文件,以mt6779为例。
一 、ProjectConfig.mk文件配置
//device/mediatek/mt6779/ProjectConfig.mk
//sensorCUSTOM_HAL_IMGSENSOR = gc8034_mipi_raw hi846_mipi_raw gc5035_mipi_raw sc500cs_mipi_raw
CUSTOM_HAL_MAIN_IMGSENSOR =gc8034_mipi_raw hi846_mipi_raw
CUSTOM_HAL_SUB_IMGSENSOR = gc5035_mipi_raw sc500cs_mipi_raw
CUSTOM_KERNEL_IMGSENSOR = gc8034_mipi_raw hi846_mipi_raw gc5035_mipi_raw sc500cs_mipi_raw
CUSTOM_KERNEL_MAIN_IMGSENSOR = gc8034_mipi_raw hi846_mipi_raw
CUSTOM_KERNEL_SUB_IMGSENSOR = gc5035_mipi_raw sc500cs_mipi_raw//lensCUSTOM_HAL_LENS = fp5510e2af dummy_lens
CUSTOM_HAL_MAIN_LENS = fp5510e2af
CUSTOM_HAL_SUB_LENS = dummy_lens
CUSTOM_KERNEL_LENS = fp5510e2af dummy_lens
CUSTOM_KERNEL_MAIN_LENS = fp5510e2af
CUSTOM_KERNEL_SUB_LENS = dummy_lens//flashlight:支持flashlight则设置为constant_flashlight,不支持设置为 dummy_flashlightCUSTOM_HAL_FLASHLIGHT = dummy_flashlight
CUSTOM_KERNEL_FLASHLIGHT = constant_flashlight
二、defconfig文件修改
//kernel-4.19/arch/arm64/configs/
//k79v1_64_defconfig 和 k79v1_64_debug_defconfig
CONFIG_CUSTOM_KERNEL_IMGSENSOR="gc8034_mipi_raw hi846_mipi_raw gc5035_mipi_raw sc500cs_mipi_raw"
三、kernel层驱动代码
添加新的camera sensor ID定义,sensor ID 来自于对应的 datasheet
//device/mediatek/common/kernel-headers/kd_imgsensor.h
#define GC8034_SENSOR_ID 0x8044#define SENSOR_DRVNAME_GC8034_MIPI_RAW "gc8034_mipi_raw"#define SC500CS_SENSOR_ID 0xEE27#define SENSOR_DRVNAME_SC500CS_MIPI_RAW "sc500cs_mipi_raw"//kernel-4.19/drivers/misc/mediatek/imgsensor/inc/kd_imgsensor.h#define GC8034_SENSOR_ID 0x8044#define SENSOR_DRVNAME_GC8034_MIPI_RAW "gc8034_mipi_raw"#define SC500CS_SENSOR_ID 0xEE27#define SENSOR_DRVNAME_SC500CS_MIPI_RAW "sc500cs_mipi_raw"
//kernel-4.19/drivers/misc/mediatek/imgsensor/src/common/v1(v1_1)/imgsensor_sensor_list.h
extern struct IMGSENSOR_INIT_FUNC_LIST kdSensorList[];UINT32 GC8034_MIPI_RAW_SensorInit(struct SENSOR_FUNCTION_STRUCT **pfFunc);/*
第一个参数对应 Camera Snesor ID
第二个参数对应 Camera Sensor name
第三个参数对应 Camera Sensor init Function
*///kernel-4.19/drivers/misc/mediatek/imgsensor/src/common/v1(v1_1)/imgsensor_sensor_list.cstruct IMGSENSOR_INIT_FUNC_LIST kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR] = {//...#if defined(GC8034_MIPI_RAW)
{GC8034_SENSOR_ID,
SENSOR_DRVNAME_GC8034_MIPI_RAW,
GC8034_MIPI_RAW_SensorInit},#endif}//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw/gc8034mipi_Sensor.cUINT32 GC8034_MIPI_RAW_SensorInit(struct SENSOR_FUNCTION_STRUCT **pfFunc){
/* Check Sensor status here */
if (pfFunc != NULL)
*pfFunc = &sensor_func;
return ERROR_NONE;}
四、hal层驱动代码
在hal层的sensor列表添加新的sensor
//vendor/mediatek/proprietary/custom/mt6739/hal/imgsensor_src/sensorlist.cpp
MSDK_SENSOR_INIT_FUNCTION_STRUCT SensorList[] ={//...#if defined(GC8034_MIPI_RAW)
RAW_INFO_M(GC8034_SENSOR_ID, DEFAULT_MODULE_INDEX, DEFAULT_MODULE_ID, SENSOR_DRVNAME_GC8034_MIPI_RAW,NULL),#endif#if defined(SC500CS_MIPI_RAW)
RAW_INFO_M(SC500CS_SENSOR_ID, DEFAULT_MODULE_INDEX, DEFAULT_MODULE_ID, SENSOR_DRVNAME_SC500CS_MIPI_RAW, NULL),#endif}
注意:sensorlist.cpp 中的SensorList[] 与 kd_sensorlist.h 中的kdSensorList[]的sensor 顺序必须一致,否则 user space 和 kernel space 在通过 ioctl 传递命令 id 时会对应错误。
五、kernel层摄像头文件夹
(A)lens文件路径:kernel-4.19/drivers/misc/mediatek/lens/
(B)flashlight文件路径:kernel-4.19/drivers/misc/mediatek/flashlight/
(C)imgsensor文件路径:
把厂商提供的包含前摄像头驱动文件夹 sc500cs_mipi_raw 和后摄像头驱动文件夹 gc8034_mipi_raw 拷贝到对应目录下,这两个文件夹里存放着厂商写好的前后摄像头驱动代码。
//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/gc8034_mipi_raw
gc8034mipi_Sensor.h
gc8034mipi_Sensor.cMakefile//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6779/sc500cs_mipi_raw
sc500csmipiraw_Sensor.h
sc500csmipiraw_Sensor.cMakefile
六、hal层摄像头文件夹
(A)lens文件路径:/vendor/mediatek/proprietary/custom/mt6779/hal/lens/
(B)flashlight文件路径:/vendor/mediatek/proprietary/custom/mt6779/hal/flashlight/
(C)imgsensor文件路径:/vendor/mediatek/proprietary/custom/mt6779/hal/imgsensor/
(D)metadata文件路径:/vendor/mediatek/proprietary/custom/mt6779/hal/imgsensor_metadata/
七、sensor上下电代码
//该文件配置sensor的上下电
//kernel-4.19/dirvers/misc/mediateck/imgsensor/src/mt6739/camera_hw/imgsensor_cfg_table.c
struct IMGSENSOR_HW_POWER_SEQ sensor_power_sequence[] = {
//...
/*
第一个参数对应 PowerType
第二个参数对应 Voltage
第三个参数对应 Delay Time in ms
DVDD/DOVDD/AVDD/AFVDD 的电压支持情况可以参考 specific pmic datasheet 进行设置
*/
#if defined(GC8034_MIPI_RAW)
{
SENSOR_DRVNAME_GC8034_MIPI_RAW,
{
{PDN, Vol_Low, 0},
{RST, Vol_Low, 1},
{DOVDD, Vol_1800, 1},
{DVDD, Vol_1200, 1},
{AVDD, Vol_2800, 1},
{SensorMCLK, Vol_High, 2},
{PDN, Vol_High, 0},
{RST, Vol_High, 2}
},
},
#endif
#if defined(SC500CS_MIPI_RAW)
{
SENSOR_DRVNAME_SC500CS_MIPI_RAW,
{
{PDN, Vol_Low, 0},
{RST, Vol_Low, 1},
{DOVDD, Vol_1800, 1},
{DVDD, Vol_1200, 1},
{AVDD, Vol_2800, 1},
{SensorMCLK, Vol_High, 2},
{PDN, Vol_High, 0},
{RST, Vol_High, 2}
},
},
#endif}struct IMGSENSOR_HW_CFG imgsensor_custom_config[] = {
{
IMGSENSOR_SENSOR_IDX_MAIN,
IMGSENSOR_I2C_DEV_0,
{
{IMGSENSOR_HW_PIN_MCLK, IMGSENSOR_HW_ID_MCLK},
{IMGSENSOR_HW_PIN_AVDD, IMGSENSOR_HW_ID_GPIO},//GPIO上电逻辑
{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_GPIO},
{IMGSENSOR_HW_PIN_NONE, IMGSENSOR_HW_ID_NONE},
},
},
{
IMGSENSOR_SENSOR_IDX_SUB,
IMGSENSOR_I2C_DEV_1,
{
{IMGSENSOR_HW_PIN_MCLK, IMGSENSOR_HW_ID_MCLK},
{IMGSENSOR_HW_PIN_AVDD, IMGSENSOR_HW_ID_GPIO},
{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_GPIO},
{IMGSENSOR_HW_PIN_NONE, IMGSENSOR_HW_ID_NONE},
},
},}struct IMGSENSOR_HW_POWER_SEQ platform_power_sequence[] = {#ifdef MIPI_SWITCH
{
IMGSENSOR_TOSTRING(IMGSENSOR_SENSOR_IDX_SUB),
{
{
IMGSENSOR_HW_PIN_MIPI_SWITCH_EN,
IMGSENSOR_HW_PIN_STATE_LEVEL_0,
0,
IMGSENSOR_HW_PIN_STATE_LEVEL_HIGH,
0
},
{
IMGSENSOR_HW_PIN_MIPI_SWITCH_SEL,
IMGSENSOR_HW_PIN_STATE_LEVEL_HIGH,
0,
IMGSENSOR_HW_PIN_STATE_LEVEL_0,
0
},
}
},#endif
//kernel-4.19/drivers/misc/mediatek/imgsensor/src/mt6761/camera_hw/regulator/regulator.c
enum REGULATOR_VOLTAGE {
REGULATOR_VOLTAGE_0 = 0,
REGULATOR_VOLTAGE_1000 = 1000000,
REGULATOR_VOLTAGE_1100 = 1100000,
REGULATOR_VOLTAGE_1200 = 1200000,
REGULATOR_VOLTAGE_1210 = 1210000,
REGULATOR_VOLTAGE_1220 = 1220000,
REGULATOR_VOLTAGE_1500 = 1500000,
REGULATOR_VOLTAGE_1800 = 1800000,
REGULATOR_VOLTAGE_2500 = 2500000,
REGULATOR_VOLTAGE_2800 = 2800000,
REGULATOR_VOLTAGE_2900 = 2900000,};enum REGULATOR_TYPE {
REGULATOR_TYPE_VCAMA,
REGULATOR_TYPE_VCAMD,
REGULATOR_TYPE_VCAMIO,
REGULATOR_TYPE_MAX_NUM};static const int regulator_voltage[] = {
REGULATOR_VOLTAGE_0,
REGULATOR_VOLTAGE_1000,
REGULATOR_VOLTAGE_1100,
REGULATOR_VOLTAGE_1200,
REGULATOR_VOLTAGE_1210,
REGULATOR_VOLTAGE_1220,
REGULATOR_VOLTAGE_1500,
REGULATOR_VOLTAGE_1800,
REGULATOR_VOLTAGE_2500,
REGULATOR_VOLTAGE_2800,
REGULATOR_VOLTAGE_2900,};struct REGULATOR_CTRL regulator_control[REGULATOR_TYPE_MAX_NUM] = {
{"vcama"},
{"vcamd"},
{"vcamio"},};//然后通过regulator_init,regulator_set函数进行电压设置static struct IMGSENSOR_HW_DEVICE device = {
.id = IMGSENSOR_HW_ID_REGULATOR,
.pinstance = (void *)®_instance,
.init = regulator_init,
.set = regulator_set,
.release = regulator_release,
.dump = regulator_dump};enum IMGSENSOR_RETURN imgsensor_hw_regulator_open(
struct IMGSENSOR_HW_DEVICE **pdevice){
*pdevice = &device;
return IMGSENSOR_RETURN_SUCCESS;}
GPIO上电逻辑:主要配置GPIO的上电逻辑,把camera的上电管脚与平台管脚相关联
code:kernel-4.19/arch/arm64/boot/dts/mediatek/k79v1_64.dts
原文链接:https://blog.csdn.net/dongxianfei/article/details/121081576
友情推荐:
至此,本篇已结束。转载网络的文章,小编觉得很优秀,欢迎点击阅读原文,支持原创作者,如有侵权,恳请联系小编删除,欢迎您的建议与指正。同时期待您的关注,感谢您的阅读,谢谢!
点击阅读原文,为大佬点赞!