海思Hi3519AV100sensor移植之二-- imx586 sensor

  • 请先下载文档sensor 移植指南,以及imx586规格书,imx586寄存器excel。读一遍
  • 跟厂商要一份imx586的初始化序列
  • 驱动代码(只是能驱动, 并不包含isa调节功能)

 

由于本次的sensor转接板是公司自制, 所以先测试硬件通信。 

1. I2C通信

i2c_write 0x1 0x34 0x0100  0x01 2 1 
i2c_read 0x1 0x34 0x0100  0x0100 2 1 1

先写后读, 就可以判断I2C是不是写成功

2. 驱动修改

2.1  基于imx291的驱动(imx291_sensor_ctl.c )进行修改, 遵循FAE给的初始化序列修改寄存器即可,示意代码如下(太长了只能截取部分)

const unsigned short IMX291_SETTING_SHORT[]=
{
  //6000*8000 change on 20200225 , receive documents from the saler 
//EXCK_FREQ 24MHZ ==    
0x0136, 0x18,
0x0137, 0x00,
//EXCK_FREQ 24MHZ ==
0x3C7E, 0x01,
0x3C7F, 0x03,
0x0111, 0x02,
//not in the handbook
0x3702, 0x1F,
0x3706, 0x17,
0x3707, 0x6F,
0x3C00, 0x10,
0x3C01, 0x10,
0x3C02, 0x10,
0x3C03, 0x10,
0x3C04, 0x10,
0x3C05, 0x01,
0x3C06, 0x00,
0x3C07, 0x00,
0x3C08, 0x03,
0x3C09, 0xFF,
0x3C0A, 0x01,
0x3C0B, 0x00,
0x3C0C, 0x00,
0x3C0D, 0x03,
0x3C0E, 0xFF,
0x3C0F, 0x20,
0x4D14, 0xA6,
0x4D29, 0xB0,
0x4D45, 0x56,
0x4D49, 0x00,
0x4D53, 0xCF,
0x4D55, 0x00,
0x4D5C, 0xA6,
0x4D71, 0xB0,
0x4D8D, 0x86,
0x4D91, 0x00,
0x4D99, 0x3C,
0x4D9B, 0x17,
0x4D9D, 

...

2.2按照《sensor调试指南》修改文件,主要集中在sample_comm_vi.c , sample_comm_isp.c

  • 下面为驱动程序分析

原文件为sample_comm_isp.c

HI_S32 SAMPLE_COMM_ISP_Sensor_Regiter_callback(ISP_DEV IspDev, HI_U32 u32SnsId)
{
    ALG_LIB_S stAeLib;
    ALG_LIB_S stAwbLib;
    const ISP_SNS_OBJ_S* pstSnsObj;
    HI_S32    s32Ret = -1;

    if (MAX_SENSOR_NUM <= u32SnsId)
    {
        SAMPLE_PRT("invalid sensor id: %d\n", u32SnsId);
        return HI_FAILURE;
    }

    pstSnsObj = SAMPLE_COMM_ISP_GetSnsObj(u32SnsId);

    if (HI_NULL == pstSnsObj)
    {
        SAMPLE_PRT("sensor %d not exist!\n", u32SnsId);
        return HI_FAILURE;
    }

 

跳入SAMPLE_COMM_ISP_GetSnsObj,发现原来是缺少了stSnsImx586Obj;所以我在这里添加了相应的代码

    switch (enSnsType)
    {

        
        case SONY_IMX290_MIPI_2M_30FPS_12BIT:
        case SONY_IMX290_MIPI_2M_30FPS_12BIT_WDR2TO1:
            return &stSnsImx290Obj;
       /*添加的代码*/
        case SONY_IMX586_MIPI_2M_30FPS_12BIT:            
            return &stSnsImx586Obj;
        ...
    }

该结构体定义在

imx290_cmos.c ; 添加stSnsImx586Obj

ISP_SNS_OBJ_S stSnsImx586Obj =
{
    .pfnRegisterCallback    = sensor_register_callback,
    .pfnUnRegisterCallback  = sensor_unregister_callback,
    .pfnStandby             = imx291_standby,
    .pfnRestart             = imx291_restart,
    .pfnMirrorFlip          = HI_NULL,
    .pfnWriteReg            = imx291_write_register,
    .pfnReadReg             = imx291_read_register,
    .pfnSetBusInfo          = imx291_set_bus_info,
    .pfnSetInit             = sensor_set_init
};

定义在.c文件所有肯定是外部引用,extern , 位置

hi_sns_ctrl.h ; 同理添加 extern ISP_SNS_OBJ_S stSnsImx586Obj

extern ISP_SNS_OBJ_S stSnsMn34220Obj;
extern ISP_SNS_OBJ_S stSnsImx377Obj;
extern ISP_SNS_OBJ_S stSnsImx299Obj;
extern ISP_SNS_OBJ_S stSnsImx477Obj;
extern ISP_SNS_OBJ_S stSnsImx299SlvsObj;
extern ISP_SNS_OBJ_S stSnsImx290Obj;
extern ISP_SNS_OBJ_S stSnsImx327Obj;
extern ISP_SNS_OBJ_S stSnsImx334Obj;
extern ISP_SNS_OBJ_S stSnsOV2718Obj;
extern ISP_SNS_OBJ_S stSnsCmv50000Obj;
extern ISP_SNS_OBJ_S stSnsImx277SlvsObj;
extern ISP_SNS_OBJ_S stSnsImx117Obj;
extern ISP_SNS_OBJ_S stSnsImx290SlaveObj;
extern ISP_SNS_OBJ_S stSnsImx334SlaveObj;
extern ISP_SNS_OBJ_S stSnsImx226Obj;
extern ISP_SNS_OBJ_S stSnsImx335Obj;
extern ISP_SNS_OBJ_S stSnsImx458Obj;
/*添加的代码*/
extern ISP_SNS_OBJ_S stSnsImx586Obj;

3. 使用示波器测量 Power信号, VANA, VDIG, VIF, 三个信号电平符合要求

4. 输入时钟信号INCK, 按照文档,该时钟输入应为6-27MHz.

4.1修改sys_config.c,  我这里用的是27M.

static BUS_TYPE parse_sensor_bus_type(char *name)
{
    unsigned int len;
    BUS_TYPE bus_type = BUS_TYPE_I2C;

    len = SENSOR_NAME_LEN;

    if (   (0 == strncmp("imx377", name, len))
        || (0 == strncmp("imx334", name, len))
        || (0 == strncmp("imx477", name, len))
        || (0 == strncmp("imx290", name, len))
        || (0 == strncmp("imx290_slave", name, len))
        || (0 == strncmp("imx299", name, len))
        || (0 == strncmp("imx117", name, len))
//添加代码
        || (0 == strncmp("imx586", name, len)))
    {
        bus_type = BUS_TYPE_I2C;
    }
    else if ((0 == strncmp("imx299_slvs", name, len))
          || (0 == strncmp("cmv50000", name, len))
          || (0 == strncmp("imx277_slvs", name, len))
          || (0 == strncmp("imx117", name, len))
          || (0 == strncmp("imx226", name, len)))
    {
        bus_type = BUS_TYPE_SPI;
    }
    else
    {
        printk("FUNC:%s line:%d  SNS:[%s] is not supported !\n", __FUNCTION__,__LINE__, name);
        bus_type = BUS_TYPE_I2C;
    }

    return bus_type;
}
/*
0x0: 74.25MHz; 0x1: 72MHz;0x2: 54MHz;0x3: 50MHz;0x4: 24MHz;0x6: 32.4MHz;
0x8: 37.125MHz;0x9: 36MHz;0xA: 27MHz;0xB: 25MHz;0xC: 12MHz;
*/
static unsigned int parse_sensor_clock(char *name)
{
    unsigned int clock = 0x0;
    unsigned int len;

    len = SENSOR_NAME_LEN;

    if ( (0 == strncmp("imx377", name, len))
         || (0 == strncmp("imx334", name, len))
         || (0 == strncmp("imx477", name, len))
         || (0 == strncmp("imx299", name, len))
         || (0 == strncmp("cmv50000", name, len)))
    {
        clock = 0x4;
    }
    else if (0 == strncmp("imx290", name, len))
    {
        clock = 0x8;
    }
    else if (0 == strncmp("imx290_slave", name, len))
    {
        clock = 0x0;
    }
    else if ( (0 == strncmp("imx299_slvs", name, len))
              || (0 == strncmp("imx277_slvs", name, len))
              || (0 == strncmp("imx117", name, len))
              || (0 == strncmp("imx226", name, len)))
    {
        clock = 0x1;
    }
//
    else if(0 == strncmp("imx586", name, len))
    {	//27M
    	clock = 0xA;
    }
    else
    {
        printk("FUNC:%s line:%d  SNS:[%s] is not supported !\n", __FUNCTION__, __LINE__, name);
        return clock;
    }

    return clock;
}

将编译好的sys_config.ko 拷贝到海思的/usr/ko目录下

4.2 运行脚本

cd /usr/ko
./load3519av100 -r
./load3519av100 -i sensor0 imx586

 

5 使用示波器测量复位信号:CMOS_RSTN,  mipi data信号

6. isa 算法调节

你可能感兴趣的:(相机开发)