A20平台增加camera

驱动采用模块加载的方式
1) 模块加载的文件在android中配置(修改点)
\A20-T2\android\device\softwinner\wing-n71j\init.sun7i.rc

# csi module
    insmod /system/vendor/modules/videobuf-core.ko
    insmod /system/vendor/modules/videobuf-dma-contig.ko
    insmod /system/vendor/modules/camera.ko
    # insmod_modules camera
    insmod /system/vendor/modules/nt99141.ko //需要修改的设备驱动
    insmod /system/vendor/modules/sunxi_csi0.ko //csi驱动

2) 修改android使用权限,video1 值可以变化,可能是video0 (一般不用修改)
\A20-T2\android\device\softwinner wing-n71j\ueventd.sun7i.rcA20平台增加camera_第1张图片
这里写图片描述
3) 修改camera.cfg配置文件,设置摄像头的属性 (一般不用修改)
板子上的地址/system/etc/camera.cfg
系统地址:device/softwinner/wing-k70/configs/camera.cfg

;——————————————————————————-
; driver device name
;——————————————————————————-
camera_device = /dev/video0
摄像头挂载的设备节点
4) 修改media_profiles.xml配置录像参数 板子上的地址/system/etc/media_profiles.xml
系统地址:device/softwinner/wing-k70/configs/media_profiles.xml (一般不用修改)
5) 参数设置完毕,剩下的需要修改sys_config.fex (需要修改)
Linux kernel 给android的配置,使用哪个摄像头。
Z:\A20-T2\lichee\tools\pack\chips\sun7i\configs\android\wing-n71j\sys_config.fex
【配置如下】

;--------------------------------------------------------------------------------
;csi gpio configuration
;csi_if: 0:hv_8bit 1:hv_16bit 2:hv_24bit 3:bt656 1ch 4:bt656 2ch 5:bt656 4ch
;csi_mode: 0:sample one csi to one buffer 1:sample two csi to one buffer
;csi_dev_qty: The quantity of devices linked to csi interface
;csi_vflip: flip in vertical direction 0:disable 1:enable
;csi_hflip: flip in horizontal direction 0:disable 1:enable
;csi_stby_mode: 0:not shut down power at standby 1:shut down power at standby
;csi_iovdd: camera module io power , pmu power supply
;csi_avdd:  camera module analog power , pmu power supply
;csi_dvdd:  camera module core power , pmu power supply
;pmu_ldo3:  fill "axp20_pll"
;pmu_ldo4:  fill "axp20_hdmi"
;fill "" when not using any pmu power supply
;csi_flash_pol: the active polority of the flash light IO 0:low active 1:high active
;--------------------------------------------------------------------------------
[camera_list_para]
camera_list_para_used   = 1
ov7670                  = 0
nt99141                 = 1  //选择某个摄像头
gc0308                  = 0
gt2005                  = 0
hi704                   = 0
sp0838                  = 0
mt9m112                 = 0
mt9m113                 = 0
gc2035                  = 0
ov2655                  = 0
hi253                   = 0
gc0307                  = 0
mt9d112                 = 0
ov5640                  = 0
gc2015                  = 0
ov2643                  = 0
gc0329                  = 0
gc0309                  = 0
tvp5150                 = 0
s5k4ec                  = 0
ov5650_mv9335           = 0
siv121d                 = 0

;--------------------------------------------------------------------------------
;csi gpio configuration
;csi_if: 0:hv_8bit 1:hv_16bit 2:hv_24bit 3:bt656 1ch 4:bt656 2ch 5:bt656 4ch
;csi_mode: 0:sample one csi to one buffer 1:sample two csi to one buffer
;csi_dev_qty: The quantity of devices linked to csi interface
;csi_vflip: flip in vertical direction 0:disable 1:enable
;csi_hflip: flip in horizontal direction 0:disable 1:enable
;csi_stby_mode: 0:not shut down power at standby 1:shut down power at standby
;csi_iovdd: camera module io power , pmu power supply
;csi_avdd:  camera module analog power , pmu power supply
;csi_dvdd:  camera module core power , pmu power supply
;pmu_ldo3:  fill "axp20_pll"
;pmu_ldo4:  fill "axp20_hdmi"
;fill "" when not using any pmu power supply
;csi_flash_pol: the active polority of the flash light IO 0:low active 1:high active
;--------------------------------------------------------------------------------

[csi0_para]      // CSI0 接口使用摄像头的配置
csi_used            = 1
csi_dev_qty         = 2  //数量2个
csi_stby_mode       = 0
csi_mname           = "nt99141"
csi_twi_id          = 1
csi_twi_addr        = 0x54  // I2C地址
csi_if              = 0
csi_vflip           = 0
csi_hflip           = 0
csi_iovdd           = "axp20_hdmi"
csi_avdd            = ""
csi_dvdd            = ""
csi_vol_iovdd       = 3300
csi_vol_dvdd        = 
csi_vol_avdd        = 
csi_flash_pol       = 0

csi_mname_b         =   // 第二个摄像头的配置,若不存在,放空
csi_twi_id_b        = 
csi_twi_addr_b      = 
csi_if_b            = 
csi_vflip_b         = 
csi_hflip_b         = 
csi_iovdd_b         = 
csi_avdd_b          = 
csi_dvdd_b          = 
csi_vol_iovdd_b     =
csi_vol_avdd_b      = 
csi_vol_dvdd_b      = 
csi_flash_pol_b     = 
// 以下为摄像头的硬件GPIO口配置,需要HW提供
csi_pck             = port:PE00<3><default><default><default>
csi_ck              = port:PE01<3><default><default><default>
csi_hsync           = port:PE02<3><default><default><default>
csi_vsync           = port:PE03<3><default><default><default>
csi_d0              = port:PE04<3><default><default><default>
csi_d1              = port:PE05<3><default><default><default>
csi_d2              = port:PE06<3><default><default><default>
csi_d3              = port:PE07<3><default><default><default>
csi_d4              = port:PE08<3><default><default><default>
csi_d5              = port:PE09<3><default><default><default>
csi_d6              = port:PE10<3><default><default><default>
csi_d7              = port:PE11<3><default><default><default>
csi_reset           = port:PH14<1><default><default><0>
csi_power_en        = port:PH16<1><default><default><0>
csi_stby            = port:PH19<1><default><default><0>
csi_flash           =
csi_af_en           =
csi_reset_b         = port:PH13<1><default><default><0>
csi_power_en_b      = port:PH16<1><default><default><0>
csi_stby_b          = port:PH18<1><default><default><0>
csi_flash_b         =
csi_af_en_b         =

[csi1_para]   // CSI1 接口使用摄像头的配置
csi_used            = 0
csi_dev_qty         = 1
csi_stby_mode       = 0
csi_mname           = "gc0308"
csi_if              = 0
csi_iovdd           = "axp20_pll"
csi_avdd            = ""
csi_dvdd            = ""
csi_vol_iovdd       = 2800
csi_vol_dvdd        = 
csi_vol_avdd        = 
csi_vflip           = 0
csi_hflip           = 0
csi_flash_pol       = 0
csi_facing          = 1

csi_twi_id          = 1
csi_twi_addr        = 0x42
csi_pck             = port:PG00<3><default><default><default>
csi_ck              = port:PG01<3><default><default><default>
csi_hsync           = port:PG02<3><default><default><default>
csi_vsync           = port:PG03<3><default><default><default>
csi_d0              = port:PG04<3><default><default><default>
csi_d1              = port:PG05<3><default><default><default>
csi_d2              = port:PG06<3><default><default><default>
csi_d3              = port:PG07<3><default><default><default>
csi_d4              = port:PG08<3><default><default><default>
csi_d5              = port:PG09<3><default><default><default>
csi_d6              = port:PG10<3><default><default><default>
csi_d7              = port:PG11<3><default><default><default>
csi_reset           = port:PH13<1><default><default><0>
csi_power_en        = port:PH16<1><default><default><0>
csi_stby            = port:PH19<1><default><default><0>

6) 增加驱动 (需要修改)以上分几个步骤说明
Z:\A20-T2\lichee\linux-3.4\drivers\media\video\sunxi_csi\device
init.sun7i.rc文件中增加的驱动如下图所示,与摄像头相关的驱动有3个
camera.ko sun7i_csi0.ko 和nt99141,ko,分别对应下面目录中的驱动
A20平台增加camera_第2张图片
lichee\linux-3.4\drivers\media\video\sunxi_csi
的目录结构如下:
A20平台增加camera_第3张图片
camera_detector:对摄像头的检测
csi0 csi1:
COMS Sensor Interface:CSI接口通常从COMS Sensor,Video Encoder和其它视频输出设备收集数据。Camera Serial Interface,相机串行接口,MIPI接口之一。
device:摄像头设备驱动
Kconfig:config文件,用于选择配置摄像头

第一步:修改camera_detector中camera_list.c
增加添加的摄像头,例如:

#define __NT99141__
static void camera_pwr_on_nt99141(__u32 list_index, __camera_info_t *camera_info)
{    
        camera_gpio_set_status(camera_info->stby_pin, 1);
        camera_gpio_set_status(camera_info->reset_pin, 1);
        //power supply
        camera_gpio_write(camera_info->stby_pin, camera_list[list_index].CSI_STBY_ON);
        camera_gpio_write(camera_info->reset_pin, camera_list[list_index].CSI_RST_ON);
        mdelay(1);
        clk_enable(camera_info->module_clk);
        mdelay(10);
        camera_gpio_write(camera_info->pwr_pin, camera_list[list_index].CSI_PWR_ON);
        mdelay(10);
        if(camera_info->dvdd) 
        {
        regulator_enable(camera_info->dvdd);
        mdelay(10);
        }
        if(camera_info->avdd)
        {
        regulator_enable(camera_info->avdd);
        mdelay(10);

        }
        if(camera_info->iovdd) 
        {
        regulator_enable(camera_info->iovdd);
        mdelay(10);
        }
        //standby off io
        camera_gpio_write(camera_info->stby_pin, camera_list[list_index].CSI_STBY_OFF);
        mdelay(10);
        camera_gpio_write(camera_info->reset_pin, camera_list[list_index].CSI_RST_OFF);
        mdelay(10);
        camera_gpio_write(camera_info->reset_pin, camera_list[list_index].CSI_RST_ON);
        mdelay(10);
        camera_gpio_write(camera_info->reset_pin, camera_list[list_index].CSI_RST_OFF);
        mdelay(10);    
}
static void camera_pwr_off_nt99141(__u32 list_index, __camera_info_t *camera_info)
{    
    camera_gpio_write(camera_info->stby_pin, camera_list[list_index].CSI_STBY_ON);
    mdelay(10);

    //reset on io
    camera_gpio_write(camera_info->reset_pin, camera_list[list_index].CSI_RST_ON);
    mdelay(10);
    //inactive mclk after power off
    //power supply off
    if(camera_info->iovdd) {
        regulator_disable(camera_info->iovdd);
    }
    if(camera_info->avdd) {
        regulator_disable(camera_info->avdd);
    }
    if(camera_info->dvdd) {
        regulator_disable(camera_info->dvdd);
    }
    camera_gpio_write(camera_info->pwr_pin, camera_list[list_index].CSI_PWR_OFF);
    mdelay(10);
    //standby of io
   clk_disable(camera_info->module_clk);
    //set the io to hi-z
    camera_gpio_set_status(camera_info->reset_pin, 0);//set the gpio to input
   // camera_gpio_set_status(camera_info->stby_pin, 0);//set the gpio to input
}

static __s32 camera_detect_nt99141(__u32 list_index, struct i2c_adapter *i2c_adap)
{

    int ret;
    struct regval_list regs;
    __u32 i2c_addr  = camera_list[list_index].i2c_addr;
    __u32 addr_step = camera_list[list_index].REG_ADDR_STEP;
    __u32 data_step = camera_list[list_index].REG_DATA_STEP;

    list_print("try to detect nt99141 ...addr_step = %d data_step = %d\n", addr_step, data_step);
    return 0;
    regs.reg_num[0] = 0x30;
    regs.reg_num[1] = 0x21;
    ret = camera_i2c_read(i2c_adap, regs.reg_num, regs.value, i2c_addr, addr_step, data_step);
    if (ret < 0) {
        list_print("gaoliang no read \n");
        return ret;
    }
        list_print("gaoliang read value = 0x%d \n", regs.value[0]);
    if (regs.value[0] != 0x56) {
        return -ENODEV;
    }

    list_print("detect nt99141 success!!\n");

    return 0;
}
__camera_list_t camera_list[MAX_CAMERA_LIST_ITEM]中增加nt99141
    CAMERA_LIST_ITEM_INIT(nt99141,       2, 1, 0x54, 1, 0, 0, 1, 1, 0),

第二步:修改CSI驱动,目前有两路CSI,具体使用哪路在配置文件中设置
\lichee\tools\pack\chips\sun7i\configs\android\wing-n71j\sys_config.fex
一般驱动不做修改
第三步:在device文件夹中增加你所添加的驱动。例如添加nt99141
先修改Makefile增加你所添加的驱动
obj-$(CONFIG_CSI_NT99141) += nt99141.o
再增加驱动原始文件
第四步:修改Kconfig

config CSI_NT99141
    tristate "OmniVision NT99141 5M sensor support"
    default m
    depends on I2C && VIDEO_V4L2
    select  CSI_DEV_SEL
    ---help---
      This is a Video4Linux2 sensor-level driver for the OmniVision
      NT99141 5M camera.

剩下就是测试,调试驱动文件了。

你可能感兴趣的:(全志A20平台)