This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

The camera MT9D131 can not communicate with the board DM365.

Other Parts Discussed in Thread: PCA9543A, THS7303, TVP7002

      I am the beginner of programmation of DM365, now I have a problem that my boss demande me to write a driver of camera MT9D131, now I can successfully register this camera and can read and write the registers in the camera. I have finish my first version of driver with only the fonction ".init  .set_fmt   .try_fmt   .s_stream", but when I use the demo function to test the driver, the demo "encode" reply to me that "No camera was connected", I do not know what is the problem.

      My question is:

             1.Because I have fused the camera by myself, so I am not sure this is correct, the connection is like this:

                 MT9D131                                   DM365(interface of image)

                  DOUT0...3          ->                         DDC-DATA12...15

                  DOUT4...7          ->                         DDC-DATA0...3

                  I2C...DATA         ->                          I2C...DATA

                  I2C...CLK        ->                             I2C...CLK

                  V_Valide            ->                          CCD-VSYNC

                  H_Valide            ->                         CCD_HSYNC

                  RESET               ->                          CCD_DDSRST

                  PCLK                  ->                          PCLK

                   EXTCLK            ->                          SP14_SD1_GPIO_MD2_CONN(Clock1)

 

              2.Have you any reference about the programmation of DM365, the code of demo is too complicated for me to understande

              3. My code of certaine fonction is like this, thank you very much.

                   static int mt9d131_init(struct v4l2_subdev *sd, u32 val)
{
    int ret;
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    ret=pll_disable(client);
    if(ret<0)
        return -EIO;
    //Perform MCU reset
    ret=change_page(client,1);
    if(ret<0)
        return -EIO;
    ret=reg_write(client,MT9D131_MCU_BOOTMODE,0x0501);
    if(ret<0)
        return -EIO;
    //Enable Reset
    ret=change_page(client,1);
    if(ret<0)
        return -EIO;
    ret=reg_write(client,MT9D131_RESET_LOGICIEL,0x0021);
    if(ret<0)
        return -EIO;
    //Disable Reset,ignore the pin Standby
    ret=reg_write(client,MT9D131_RESET_LOGICIEL,0x00A0);
    if(ret<0)
        return -EIO;
    msleep(20);
    //Enable PLL
    return pll_enable(client,18,8,2)>0?0:-EIO;
}

static int mt9d131_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    int ret;
    //Change mode to capture
    if(change_mode(client,1)<0)
        return -EIO;
    //Enable the output
    if (enable) {
        if (driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,2,1) < 0)
            return -EIO;
    } else {
    //Disable the output
        if (driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,1,1) < 0)
            return -EIO;
    }
    return 0;
}

static int mt9d131_set_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)
{
    int i,ret;
    int flag=0;
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    struct v4l2_pix_format *pix = &f->fmt.pix;
    for(i=0;i<mt9d131_num_formats;i++)
    {
        if(pix->pixelformat==mt9d131_formats[i].pixelformat)
        {   
            //bypass the JPEG
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x30,1);
            switch(mt9d131_formats[i].index){
            case 0://When output of the format match the YUV
                ret=driver_clear(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x21,1);
                break;
            case 1://When output of the format match the RGB
                ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x20,1);
                break;
            case 2://When output of the format match the JPEG
                ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x10,1);//Allow the JPEG in context B
                ret=driver_write(client,MT9D131_ID_JPEG,MT9D131_JPEG_FORMAT,0,1);
            }
            printk("Use %s.\n",mt9d131_formats[i].description);
            flag=1;
            if(ret<0)
            {
                printk("Out put register error\n");
                return ret;
            }
            break;
        }
    }
    if(flag==0)
        return -EIO;
    if(pix->width<=MT9D131_MAX_WIDTHB&&pix->height<=MT9D131_MAX_HEIGHTB)//Change the size of window
    {
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_WIDTHB,pix->width,0);
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_HEIGHTB,pix->height,0);
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X0B,0,0);
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X1B,pix->width,0);
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y0B,0,0);
        ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y1B,pix->width,0);
        if(ret<0)
        {
            printk("Out put register error\n");
            return ret;
        }
    }
    else
        return -EIO;
    ret=change_mode(client,1);
    ret=driver_write(client,MT9D131_ID_SEQ ,MT9D131_SEQ_CMD,5,1);//Refresh the register
    ret=driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,2,1);//Begin to start capture
    return ret<0?ret:0;
}


static int mt9d131_try_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)
{
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    struct v4l2_pix_format *pix = &f->fmt.pix;
    int ret,i;
    int flag=0;
    for(i=0;i<mt9d131_num_formats;i++)
    {
        if(pix->pixelformat==mt9d131_formats[i].pixelformat)
        {
            flag=1;
            break;
        }
    }
    if(!flag)
        pix->pixelformat=mt9d131_formats[0].pixelformat;
    if(pix->width>MT9D131_MAX_WIDTHB)
        pix->width=MT9D131_MAX_WIDTHB;
    if(pix->width>MT9D131_MAX_HEIGHTB)
        pix->width=MT9D131_MAX_HEIGHTB;
    pix->width &= ~0x01; /* has to be even */
    pix->height &= ~0x01; /* has to be even */
    return 0;
}

 

  • Mingming Chen,

     

    Mingming Chen said:
    2.Have you any reference about the programmation of DM365, the code of demo is too complicated for me to understande

    which demo you are referring to?

  • The demo of DVSDK3.xxxxxxxxxx

  • I assume that you are referring to kernel source code which comes with DVSDK. In that case, referring sensor drivers(for mt9p031/mt9t031) in it is the easiest way to develop driver for your sensor. Also, you can check if driver is already there for your sensor in open source.

  • But, my probleme is that I have only the MT9D131,and is anyone knows how the interface VPFE work, for example, now my connection is

    DOUT[0...7](camera) <===========>CCD_DATA[12....15,0....3]<==================>YIN[0.....7](DM365)

    Is this right?

  • Mingming Chen,

    Please refer to dm36x VPFE user guide section 2 to understand how to interface ISIF with sensor.

  • My probleme now is that my connection is D_Out[0....7] to Yin[0....7], the user guide say that whether use Yin or Cin for the 8 bit YCbCr input is depend on YCSWP, but I do not know this value is 1 or 0. I have already change the code in board-dm365-evm.c like this:

    {
            .module_name = "mt9d131",
            .is_camera = 1,
            .grp_id = VPFE_SUBDEV_MT9D131,
            .num_inputs = ARRAY_SIZE(mt9t031_inputs),
            .inputs = mt9td131_inputs,
            .ccdc_if_params = {
                .if_type = VPFE_YCBCR_SYNC_8,
                .hdpol = VPFE_PINPOL_POSITIVE,
                .vdpol = VPFE_PINPOL_POSITIVE,
            },
            .board_info = {
                I2C_BOARD_INFO("mt9d131", 0xBA>>1),
                /* this is for PCLK rising edge */
                .platform_data = (void *)1,
            },
        }

    but I still do not know whether I should connect to Yin or Cin

    Furthuermore now I can already use the I2C to communicate with the registers but when I lance the demo encode the result is

    Failed to detect video standard, video input connected?

    In the Capture.c of demo encoder, I can see this phrase:

    if(Capture_detectVideoStd(NULL,&videoStd,&cAttrs)<0)

    {

             ERR("Failed to detect video standard,video input connected?\n");

     My question is

    1. By default, we use Yin or Cin for 8 bits input?

    2. My bootargs for using the camera is ' ................video=davincifb:vid0=OFF:vid1=OFF:osd0=720x576x16,2025K dm365_imp.oper_mode=0 vpfe_capture.interface=1 vpfe_capture.bufsize=4147200 davinci_enc_mngr.ch0_mode=1080-30I'  Is this right? Or there is any reference for me.

    3. How the function Capture_detectVideoStd works,

    Thank you very much

     

  • In the board file, do you see support for any sensor like mt9p031/mt9t031? You can use that code as a reference in that case.

  • I have already write a driver of MT9D131, but the probleme is when I lance the demo DMAI_DEBUG=2 , Capture says "can not open /dev/video0", but my camera have already registered as a sub_device of vpfe,

    v4l2_sub device MT9D131 registered!

    So now I can not fix my probleme

     

  • Can you please provide all the debug/print messages starting from linux kernel booting till application spits out error?

  • You can also read the code of my driver if you want

    Starting kernel ...                                                            
                                                                                   
    Uncompressing Linux.............................................................
    Linux version 2.6.32-rc2-davinci1 (administrateur@ubuntu) (gcc version 4.3.3 (S0
    CPU: ARM926EJ-S [41069265] revision 5 (ARMv5TEJ), cr=00053177                  
    CPU: VIVT data cache, VIVT instruction cache                                   
    Machine: DaVinci DM365 EVM                                                     
    Memory policy: ECC disabled, Data cache writeback                              
    DaVinci dm365_rev1.2 variant 0x8                                               
    Clocks: enable vpss_dac at 243000000 Hz                                        
    Clocks: enable arm_clk at 297000000 Hz                                         
    Built 1 zonelists in Zone order, mobility grouping off.  Total pages: 15240    
    Kernel command line: mem=60M console=ttyS0,115200n8 root=/dev/nfs rw nfsroot=190
    PID hash table entries: 256 (order: -2, 1024 bytes)                            
    Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)                  
    Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)                   
    Memory: 60MB = 60MB total                                                      
    Memory: 56276KB available (3968K code, 387K data, 144K init, 0K highmem)       
    SLUB: Genslabs=11, HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1        
    Hierarchical RCU implementation.                                               
    NR_IRQS:245                                                                    
    Clocks: enable timer0 at 24000000 Hz                                           
    Console: colour dummy device 80x30                                             
    Calibrating delay loop... 147.86 BogoMIPS (lpj=739328)                         
    Mount-cache hash table entries: 512                                            
    CPU: Testing write buffer coherency: ok                                        
    Clocks: enable gpio at 121500000 Hz                                            
    DaVinci: 8 gpio irqs                                                           
    NET: Registered protocol family 16                                             
    Clocks: enable uart0 at 24000000 Hz                                            
    Clocks: enable uart1 at 121500000 Hz                                           
    davinci_serial_init:97: failed to get UART2 clock                              
    Clocks: enable clkout1 at 24000000 Hz                                          
    CLOCK : Clkout1 is ON                                                          
    Clocks: enable aemif at 121500000 Hz                                           
    Reset to high                                                                  
    EVM: HD imager video input                                                     
    bio: create slab <bio-0> at 0                                                  
    DM365 IPIPE initialized in Continuous mode                                     
    SCSI subsystem initialized                                                     
    usbcore: registered new interface driver usbfs                                 
    usbcore: registered new interface driver hub                                   
    usbcore: registered new device driver usb                                      
    Clocks: enable i2c at 24000000 Hz                                              
    pca9543a_probe                                                                 
    vpss vpss: dm365_vpss vpss probed                                              
    vpss vpss: dm365_vpss vpss probe success                                       
    dm365_afew_hw_init                                                             
    ch0 default output "COMPOSITE", mode "NTSC"                                    
    VPBE Encoder Initialized                                                       
    cfg80211: Using static regulatory domain info                                  
    cfg80211: Regulatory domain: US                                                
            (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)      
            (2402000 KHz - 2472000 KHz @ 40000 KHz), (600 mBi, 2700 mBm)           
            (5170000 KHz - 5190000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)           
            (5190000 KHz - 5210000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)           
            (5210000 KHz - 5230000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)           
            (5230000 KHz - 5330000 KHz @ 40000 KHz), (600 mBi, 2300 mBm)           
            (5735000 KHz - 5835000 KHz @ 40000 KHz), (600 mBi, 3000 mBm)           
    cfg80211: Calling CRDA for country: US                                         
    LogicPD encoder initialized                                                    
    Switching to clocksource timer0_1                                              
    musb_hdrc: version 6.0, cppi-dma, host, debug=0                                
    Clocks: enable usb at 24000000 Hz                                              
    musb_hdrc: USB Host mode controller at fec64000 using DMA, IRQ 12              
    musb_hdrc musb_hdrc: MUSB HDRC host driver                                     
    musb_hdrc musb_hdrc: new USB bus registered, assigned bus number 1             
    usb usb1: configuration #1 chosen from 1 choice                                
    hub 1-0:1.0: USB hub found                                                     
    hub 1-0:1.0: 1 port detected                                                   
    NET: Registered protocol family 2                                              
    IP route cache hash table entries: 1024 (order: 0, 4096 bytes)                 
    TCP established hash table entries: 2048 (order: 2, 16384 bytes)               
    TCP bind hash table entries: 2048 (order: 1, 8192 bytes)                       
    TCP: Hash tables configured (established 2048 bind 2048)                       
    TCP reno registered                                                            
    NET: Registered protocol family 1                                              
    RPC: Registered udp transport module.                                          
    RPC: Registered tcp transport module.                                          
    RPC: Registered tcp NFSv4.1 backchannel transport module.                      
    JFFS2 version 2.2. (NAND) �© 2001-2006 Red Hat, Inc.                           
    msgmni has been set to 110                                                     
    alg: No test for stdrng (krng)                                                 
    io scheduler noop registered                                                   
    io scheduler anticipatory registered (default)                                 
    davincifb davincifb.0: dm_osd0_fb: 0x0x16@0,0 with framebuffer size 2025KB     
    davincifb davincifb.0: dm_vid0_fb: 0x0x16@0,0 with framebuffer size 1020KB     
    davincifb davincifb.0: dm_osd1_fb: 720x480x4@0,0 with framebuffer size 675KB   
    davincifb davincifb.0: dm_vid1_fb: 0x0x16@0,0 with framebuffer size 1020KB     
    DM365 IPIPEIF probed                                                           
    imp serializer initialized                                                     
    davinci_previewer initialized                                                  
    davinci_resizer initialized                                                    
    Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled                       
    serial8250.0: ttyS0 at MMIO 0x1c20000 (irq = 40) is a 16550A                   
    console [ttyS0] enabled                                                        
    brd: module loaded                                                             
    at24 1-0050: 32768 byte 24c256 EEPROM (writable)                               
    Read MAC addr from EEPROM: 00:0e:99:02:cd:cc                                   
    Clocks: enable spi0 at 121500000 Hz                                            
    spi_davinci spi_davinci.0: DaVinci SPI driver in EDMA mode                     
    Using RX channel = 17 , TX channel = 16 and event queue = 3                    
    at25 spi0.0: 8 KByte at25640 eeprom, pagesize 32                               
    spi_davinci spi_davinci.0: Controller at 0xfec66000                            
    console [netcon0] enabled                                                      
    netconsole: network logging started                                            
    Initializing USB Mass Storage driver...                                        
    usbcore: registered new interface driver usb-storage                           
    USB Mass Storage support registered.                                           
    usbcore: registered new interface driver usbtest                               
    input: DM365 EVM Controls as /devices/platform/i2c_davinci.1/i2c-1/1-0025/input0
    i2c /dev entries driver                                                        
    Linux video capture interface: v2.00                                           
    ths7303 1-002c: chip found @ 0x58 (DaVinci I2C adapter)                        
    Enabling mt9d131 sensor                                                        
    vpfe_init                                                                      
    Clocks: enable vpss_master at 243000000 Hz                                     
    vpfe-capture: vpss clock vpss_master enabled                                   
    vpfe-capture vpfe-capture: v4l2 device registered                              
    vpfe-capture vpfe-capture: video device registered                             
    Reset to high                                                                  
    msg.addr = 115                                                                 
    dm365evm_enable_pca9543a, status = -121                                        
    EVM: switch to HD imager video input                                           
    mt9d131 1-005d: Detected a MT9D131 chip ID 1519                                
    mt9d131 1-005d: mt9d131 1-005d decoder driver registered !!                    
    vpfe-capture vpfe-capture: v4l2 sub device mt9d131 registered                  
    vpfe_register_ccdc_device: DM365 ISIF                                          
    DM365 ISIF is registered with vpfe.                                            
    af major#: 252, minor# 0                                                       
    AF Driver initialized                                                          
    aew major#: 251, minor# 0                                                      
    AEW Driver initialized                                                         
    Trying to register davinci display video device.                               
    layer=c26ff200,layer->video_dev=c26ff370                                       
    Trying to register davinci display video device.                               
    layer=c25a9e00,layer->video_dev=c25a9f70                                       
    davinci_init:DaVinci V4L2 Display Driver V1.0 loaded                           
    Clocks: enable timer2 at 24000000 Hz                                           
    watchdog watchdog: heartbeat 60 sec                                            
    Clocks: enable mmcsd0 at 121500000 Hz                                          
    davinci_mmc davinci_mmc.0: Using DMA, 4-bit mode                               
    usbcore: registered new interface driver usbhid                                
    usbhid: v2.6:USB HID core driver                                               
    Advanced Linux Sound Architecture Driver Version 1.0.21.                       
    No device for DAI tlv320aic3x                                                  
    Clocks: enable asp0 at 121500000 Hz                                            
    No device for DAI davinci-i2s                                                  
    asoc: tlv320aic3x <-> davinci-i2s mapping ok                                   
    ALSA device list:                                                              
      #0: DaVinci EVM (tlv320aic3x)                                                
    TCP cubic registered                                                           
    NET: Registered protocol family 17                                             
    lib80211: common routines for IEEE802.11 drivers                               
    Clocks: enable emac at 121500000 Hz                                            
    emac-mii: probed                                                               
    eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=1:01, id=221613)     
    IP-Config: Guessing netmask 255.255.255.0                                      
    IP-Config: Complete:                                                           
         device=eth0, addr=192.168.2.199, mask=255.255.255.0, gw=255.255.255.255,  
         host=192.168.2.199, domain=, nis-domain=(none),                           
         bootserver=255.255.255.255, rootserver=192.168.2.30, rootpath=            
    Looking up port of RPC 100003/2 on 192.168.2.30                                
    PHY: 1:01 - Link is Up - 100/Full                                              
    Looking up port of RPC 100005/1 on 192.168.2.30                                
    VFS: Mounted root (nfs filesystem) on device 0:14.                             
    Freeing init memory: 144K                                                      
    INIT: version 2.86 booting                                                     
    Starting the hotplug events dispatcher: udevd.                                 
    Synthesizing the initial hotplug events...done.                                
    Waiting for /dev to be fully populated...done.                                 
    Activating swap...done.                                                        
    Remounting root filesystem...done.                                             
    Calculating module dependencies                                                
    WARNING: Couldn't open directory /lib/modules/2.6.32-rc2-davinci1: No such filey
    FATAL: Could not open /lib/modules/2.6.32-rc2-davinci1/modules.dep.temp for wriy
    Loading modules:                                                               
    Checking all file systems: fsck                                                
    fsck 1.40 (29-Jun-2007)                                                        
    Mounting local filesystems: mount nothing was mounted                          
    umount.nfs: /dev/root: not found or not mounted                                
    Setting up networking ....                                                     
    /etc/network/options is deprecated.                                            
    Setting up IP spoofing protection: rp_filter done.                             
    Disabling IPv4 packet forwarding: done.                                        
    Disabling TCP/IP Explicit Congestion Notification: done.                       
    Starting network interfaces: done.                                             
    Starting hotplug subsystem:                                                    
       pci                                                                         
       pci      [success]                                                          
       usb                                                                         
       usb      [success]                                                          
       isapnp                                                                      
       isapnp   [success]                                                          
       ide                                                                         
       ide      [success]                                                          
       input                                                                       
       input    [success]                                                          
       scsi                                                                        
       scsi     [success]                                                          
    done.                                                                          
    Starting portmap daemon....                                                    
    Cleaning: /tmp /var/lock /var/run done.                                        
    Setting pseudo-terminal access permissions...done.                             
    Updating /etc/motd...done.                                                     
    INIT: Entering runlevel: 3                                                     
    Starting system log daemon: syslogd klogd.                                     
    Starting NFS common utilities: statd.                                          
    Starting internet superserver: inetd.                                          
    Starting OpenBSD Secure Shell server: sshd@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @                    
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
    Permissions 0755 for '/etc/ssh/ssh_host_key' are too open.                     
    It is recommended that your private key files are NOT accessible by others.    
    This private key will be ignored.                                              
    bad permissions: ignore key: /etc/ssh/ssh_host_key                             
    Could not load host key: /etc/ssh/ssh_host_key                                 
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @                    
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
    Permissions 0755 for '/etc/ssh/ssh_host_rsa_key' are too open.                 
    It is recommended that your private key files are NOT accessible by others.    
    This private key will be ignored.                                              
    bad permissions: ignore key: /etc/ssh/ssh_host_rsa_key                         
    Could not load host key: /etc/ssh/ssh_host_rsa_key                             
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
    @         WARNING: UNPROTECTED PRIVATE KEY FILE!          @                    
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                    
    Permissions 0755 for '/etc/ssh/ssh_host_dsa_key' are too open.                 
    It is recommended that your private key files are NOT accessible by others.    
    This private key will be ignored.                                              
    bad permissions: ignore key: /etc/ssh/ssh_host_dsa_key                         
    Could not load host key: /etc/ssh/ssh_host_dsa_key                             
    Disabling protocol version 1. Could not load host key                          
    Disabling protocol version 2. Could not load host key                          
    sshd: no hostkeys available -- exiting.                                        
     failed (1: ).                                                                 
                                                                                   
    MontaVista(R) Linux(R) Professional Edition 5.0.0 (0801921)                    
                                                                                   
    192.168.2.199 login: root                                                      
    Last login: Thu Jan  1 00:00:42 1970 on console                                
    Linux 192.168.2.199 2.6.32-rc2-davinci1 #147 PREEMPT Wed Aug 18 15:02:52 CEST 2x
                                                                                   
    Welcome to MontaVista(R) Linux(R) Professional Edition 5.0.0 (0801921).        
                                                                                   
    root@192.168.2.199:~# cd /opt                                                  
    root@192.168.2.199:/opt# ./loadmodules_hd.sh                                   
    CMEMK module: built on Jun  7 2011 at 17:06:03                                 
      Reference Linux version 2.6.32                                               
      File /home/chemi/dvsdk/dvsdk_3_10_00_19/linuxutils_2_25_04_10/packages/ti/sdoc
    allocated heap buffer 0xc5000000 of size 0x8d5000                              
    cmemk initialized                                                              
    IRQK module: built on Jun  7 2011 at 17:06:07                                  
      Reference Linux version 2.6.32                                               
      File /home/chemi/dvsdk/dvsdk_3_10_00_19/linuxutils_2_25_04_10/packages/ti/sdoc
    Clocks: enable mjcp at 243000000 Hz                                            
    irqk initialized                                                               
    EDMAK module: built on Jun  7 2011 at 17:06:06                                 
      Reference Linux version 2.6.32                                               
      File /home/chemi/dvsdk/dvsdk_3_10_00_19/linuxutils_2_25_04_10/packages/ti/sdoc
    root@192.168.2.199:/opt# DMAI_DEBUG=2 ./encode -v 2.m4v                        
    ./encode: /usr/lib/libpng12.so.0: no version information available (required by)
    Encode demo started.                                                           
    @0x0006cc1a:[T:0x4001f970] ti.sdo.dmai - [Dmai] Dmai log level set to '2'. Note.
    @0x000b8850:[T:0x4001f970] ti.sdo.dmai - [Display] Found width=720 height=480, 4
    @0x000b89ef:[T:0x4001f970] ti.sdo.dmai - [Display] Setting width=720 height=4800
    @0x000b8afe:[T:0x4001f970] ti.sdo.dmai - [Display] New width=720, height=480, y4
    @0x000b8c42:[T:0x4001f970] ti.sdo.dmai - [BufTab] Allocating BufTab for 1 buffes
    @0x000b8e6d:[T:0x4001f970] ti.sdo.dmai - [Buffer] Set user pointer 0x403ca000 ()
    @0x000b93b4:[T:0x4001f970] ti.sdo.dmai - [Display] Display buffer 0 mapped to 00
    @0x000c1733:[T:0x40bf6490] ti.sdo.dmai - [Capture] Composite input not found (I)
    Error: Failed to detect video standard, video input connected?                 
    @0x000c1f29:[T:0x413f6490] ti.sdo.dmai - [Venc1] Creating encoder mpeg4enc for 4
    @0x000c5b04:[T:0x413f6490] ti.sdo.dmai - [Venc1] Failed to open video encode al)
    Error: Failed to create video encoder: mpeg4enc                                
    @0x000e26e4:[T:0x41bf6490] ti.sdo.dmai - [BufTab] Allocating BufTab for 9 buffes
    @0x000e2901:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e2ae5:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e2cf1:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e2ec1:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e30b6:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e332a:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e3509:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e3711:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e38ec:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000e4218:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e4337:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e4417:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e44e2:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e45aa:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e46a2:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e4773:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e4838:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000e48ff:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    root@192.168.2.199:/opt# DMAI_DEBUG=2 ./encode -v 2.m4v                        
    ./encode: /usr/lib/libpng12.so.0: no version information available (required by)
    Encode demo started.                                                           
    @0x0001c32b:[T:0x4001f970] ti.sdo.dmai - [Dmai] Dmai log level set to '2'. Note.
    @0x0006a2eb:[T:0x4001f970] ti.sdo.dmai - [Display] Found width=720 height=480, 4
    @0x0006a483:[T:0x4001f970] ti.sdo.dmai - [Display] Setting width=720 height=4800
    @0x0006a599:[T:0x4001f970] ti.sdo.dmai - [Display] New width=720, height=480, y4
    @0x0006a6e1:[T:0x4001f970] ti.sdo.dmai - [BufTab] Allocating BufTab for 1 buffes
    @0x0006a90a:[T:0x4001f970] ti.sdo.dmai - [Buffer] Set user pointer 0x403ca000 ()
    @0x0006ae51:[T:0x4001f970] ti.sdo.dmai - [Display] Display buffer 0 mapped to 00
    @0x000734ab:[T:0x40bf6490] ti.sdo.dmai - [Capture] Composite input not found (I)
    Error: Failed to detect video standard, video input connected?                 
    @0x00073cc2:[T:0x413f6490] ti.sdo.dmai - [Venc1] Creating encoder mpeg4enc for 4
    @0x00077b8f:[T:0x413f6490] ti.sdo.dmai - [Venc1] Failed to open video encode al)
    Error: Failed to create video encoder: mpeg4enc                                
    @0x000b5215:[T:0x41bf6490] ti.sdo.dmai - [BufTab] Allocating BufTab for 9 buffes
    @0x000b545d:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b5643:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b5818:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b59eb:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b5bbb:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b5d90:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b5f62:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b6133:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b6306:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000b6b9e:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b6cbf:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b6d97:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b6e66:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b6f2a:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b6fe9:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b70af:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b7171:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000b7302:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    root@192.168.2.199:/opt# rm encode                                             
    root@192.168.2.199:/opt# DMAI_DEBUG=2 ./encode -v 2.m4v                        
    ./encode: /usr/lib/libpng12.so.0: no version information available (required by)
    Encode demo started.                                                           
    @0x0006743f:[T:0x4001f970] ti.sdo.dmai - [Dmai] Dmai log level set to '2'. Note.
    @0x000b969e:[T:0x4001f970] ti.sdo.dmai - [Display] Found width=720 height=480, 4
    @0x000b983c:[T:0x4001f970] ti.sdo.dmai - [Display] Setting width=720 height=4800
    @0x000bb972:[T:0x4001f970] ti.sdo.dmai - [Display] New width=720, height=480, y4
    @0x000bbaee:[T:0x4001f970] ti.sdo.dmai - [BufTab] Allocating BufTab for 1 buffes
    @0x000bbd29:[T:0x4001f970] ti.sdo.dmai - [Buffer] Set user pointer 0x403ca000 ()
    @0x000bc7b3:[T:0x4001f970] ti.sdo.dmai - [Display] Display buffer 0 mapped to 00
    @0x000c2495:[T:0x40bf6490] ti.sdo.dmai - [Capture] Cannot open /dev/video0 (No )
    Error: Failed to detect video standard, video input connected?                 
    @0x000c2c83:[T:0x413f6490] ti.sdo.dmai - [Venc1] Creating encoder mpeg4enc for 4
    @0x000c691b:[T:0x413f6490] ti.sdo.dmai - [Venc1] Failed to open video encode al)
    Error: Failed to create video encoder: mpeg4enc                                
    @0x000d9d70:[T:0x41bf6490] ti.sdo.dmai - [BufTab] Allocating BufTab for 9 buffes
    @0x000d9fd0:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000da1b8:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000da38a:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000da593:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000da76a:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000da942:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000dab57:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000dad3b:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000daf45:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Alloc Buffer of size 0 at 0x4)
    @0x000db816:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000db938:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dba4c:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dbb20:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dbcb0:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dbda9:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dbe7d:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dbf71:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    @0x000dc043:[T:0x41bf6490] ti.sdo.dmai - [Buffer] Free Buffer of size 0 at 0x41)
    root@192.168.2.199:/opt#

    You can also read the code of my driver if you want

    #include <linux/videodev2.h>
    #include <linux/slab.h>
    #include <linux/i2c.h>
    #include <linux/log2.h>
    #include <linux/delay.h>
    #include <media/v4l2-device.h>
    #include <media/v4l2-common.h>
    #include <media/v4l2-chip-ident.h>

    #define MT9D131_PAGE_REGISTRE       0xF0
    #define MT9D131_CHIP_VERSION        0x00
    #define MT9D131_ROW_START            0x01
    #define MT9D131_COLUMN_START        0x02
    #define MT9D131_ROW_WIDTH            0x03
    #define MT9D131_COL_WIDTH            0x04
    #define MT9D131_HORIZONTAL_BLANKINGB 0x05
    #define MT9D131_VERTICAL_BLANKINGB  0x06
    #define MT9D131_HORIZONTAL_BLANKINGA 0x07
    #define MT9D131_VERTICAL_BLANKINGA  0x08
    #define MT9D131_SHUTTER_WIDTH       0x09
    #define MT9D131_ROW_SPEED           0x0A
    #define MT9D131_SHUTTER_DELAY       0x0C
    #define MT9D131_RESET_LOGICIEL      0x0D
    #define MT9D131_CLOCK_CONTROL       0x65
    #define MT9D131_MCU_BOOTMODE        0xC1
    #define MT9D131_PLL_CONTROL1        0x66
    #define MT9D131_PLL_CONTROL2        0x67
    #define MT9D131_VARIABLE_ADDRESS    0xC6
    #define MT9D131_VARIABLE_DATA       0xC8
    #define MT9D131_ID_SEQ              0x01
    #define MT9D131_ID_MODE             0x07
    #define MT9D131_OUT_FORMATA         125
    #define MT9D131_OUT_FORMATB         126
    #define MT9D131_SEQ_CAPTUREMODE     32
    #define MT9D131_SEQ_CMD             3
    #define MT9D131_MODE_CONFIG         11
    #define MT9D131_ID_JPEG             0x09
    #define MT9D131_JPEG_FORMAT         6
    #define MT9D131_OUTPUT_WIDTHB       7
    #define MT9D131_OUTPUT_HEIGHTB      9
    #define MT9D131_CROP_X0B            53
    #define MT9D131_CROP_X1B            55    
    #define MT9D131_CROP_Y0B            57
    #define MT9D131_CROP_Y1B            59   
    #define MT9D131_BUS_PARAM    (SOCAM_PCLK_SAMPLE_RISING |    \
        SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH |    \
        SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH |    \
        SOCAM_MASTER | SOCAM_DATAWIDTH_10)
    #define MT9D131_MAX_WIDTHA          800
    #define MT9D131_MAX_HEIGHTA          600
    #define MT9D131_MAX_WIDTHB          1600
    #define MT9D131_MAX_HEIGHTB          1200
    static int debug;
    module_param(debug, bool, 0644);
    MODULE_PARM_DESC(debug, "Debug level (0-1)");

    static const struct v4l2_fmtdesc mt9d131_formats[] = {
        {
            .index = 0,
            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
            .description = "YUV Format",
            .pixelformat = V4L2_PIX_FMT_UYVY,
        },
        {
            .index = 1,
            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
            .description = "RGB Format",
            .pixelformat = V4L2_PIX_FMT_RGB565X,
        },
        {
            .index=2,
            .type = V4L2_BUF_TYPE_VIDEO_CAPTURE,
            .description = "JPEG Format",
            .pixelformat = V4L2_PIX_FMT_JPEG,
        }
    };

    static const unsigned int mt9d131_num_formats = ARRAY_SIZE(mt9d131_formats);

    static const struct v4l2_queryctrl mt9d131_controls[] = {
        {
            .id        = V4L2_CID_VFLIP,
            .type        = V4L2_CTRL_TYPE_BOOLEAN,
            .name        = "Flip Vertically",
            .minimum    = 0,
            .maximum    = 1,
            .step        = 1,
            .default_value    = 0,
        }, {
            .id        = V4L2_CID_HFLIP,
            .type        = V4L2_CTRL_TYPE_BOOLEAN,
            .name        = "Flip Horizontally",
            .minimum    = 0,
            .maximum    = 1,
            .step        = 1,
            .default_value    = 0,
        }, {
            .id        = V4L2_CID_GAIN,
            .type        = V4L2_CTRL_TYPE_INTEGER,
            .name        = "Gain",
            .minimum    = 0,
            .maximum    = 127,
            .step        = 1,
            .default_value    = 64,
            .flags        = V4L2_CTRL_FLAG_SLIDER,
        }, {
            .id        = V4L2_CID_EXPOSURE,
            .type        = V4L2_CTRL_TYPE_INTEGER,
            .name        = "Exposure",
            .minimum    = 1,
            .maximum    = 255,
            .step        = 1,
            .default_value    = 255,
            .flags        = V4L2_CTRL_FLAG_SLIDER,
        }, {
            .id        = V4L2_CID_EXPOSURE_AUTO,
            .type        = V4L2_CTRL_TYPE_BOOLEAN,
            .name        = "Automatic Exposure",
            .minimum    = 0,
            .maximum    = 1,
            .step        = 1,
            .default_value    = 1,
        }
    };

    static const unsigned int mt9d131_num_controls = ARRAY_SIZE(mt9d131_controls);

    struct mt9d131 {
        struct v4l2_subdev sd;
        int model;    /* V4L2_IDENT_MT9D131* codes from v4l2-chip-ident.h */
    };

    static inline struct mt9d131 *to_mt9d131(struct v4l2_subdev *sd)
    {
        return container_of(sd, struct mt9d131, sd);
    }

    //The fonction to read the content in certaine register
    static int reg_read(struct i2c_client *client, const u8 reg)
    {
        s32 data;
        data = i2c_smbus_read_word_data(client, reg);
        return data < 0 ? data : swab16(data);
    }

    //The fonction to write the content into certaine register
    static int reg_write(struct i2c_client *client, const u8 reg,
                 const u16 data)
    {
        return i2c_smbus_write_word_data(client, reg, swab16(data));
    }

    //Turn certaine bits of the reg to 1
    static int reg_set(struct i2c_client *client, const u8 reg,
               const u16 data)
    {
        int ret;
        ret = reg_read(client, reg);
        if (ret < 0)
        {
            dev_dbg(&client->dev, "Can not set register: %x\n",reg);
            return ret;
        }
        return reg_write(client, reg, ret | data);
    }

    //Turn certaines bits of the reg to 0
    static int reg_clear(struct i2c_client *client, const u8 reg,
                 const u16 data)
    {
        int ret;
        ret = reg_read(client, reg);
        if (ret < 0)
            return ret;
        return reg_write(client, reg, ret & ~data);
    }

    //Change the page of register
    static int change_page(struct i2c_client *client,const u16 data)
    {
        int ret;
        u8 reg= MT9D131_PAGE_REGISTRE;
        ret = reg_read(client, reg);
        if (ret < 0)
        {
            dev_dbg(&client->dev, "Can not read register: %x\n",reg);
            return ret;
        }
        else
            return reg_write(client,reg,data);
    }

    static int set_shutter(struct i2c_client *client, const u32 data)
    {
        int ret;
        ret=change_page(client,0);
        if(ret<0)
            return -ret;
        ret = reg_write(client, MT9D131_SHUTTER_WIDTH, data >> 16);
        return ret;
    }

    static int set_shutter_delay(struct i2c_client *client, const u16 data)
    {
        int ret;
        ret=change_page(client,0);
        if(ret<=0)
            return ret;
        ret = reg_write(client, MT9D131_SHUTTER_DELAY, data);
        return ret;
    }

    static int get_shutter(struct i2c_client *client,u32 *data)
    {
        int ret;
        ret=reg_read(client,MT9D131_SHUTTER_WIDTH);
        *data=ret;
        return ret;
    }

    //This fonction change the variables of drivers
    static int driver_write(struct i2c_client *client,const u8 id,const u8 offset,const u16 val,const int bits_access)
    {
        u16 addr;
        u16 ret;
        addr=(((u16)id)<<8)|offset;
        if(bits_access)
            addr|=0xA000;
        else
            addr|=0x2000;
        ret=change_page(client,1);
        if(ret<0)
            return ret;
        ret=reg_write(client,MT9D131_VARIABLE_ADDRESS ,addr);
        if(ret<0)
            return ret;
        if(bits_access)
            ret=reg_write(client,MT9D131_VARIABLE_DATA,(u8)val);
        else
            ret=reg_write(client,MT9D131_VARIABLE_DATA,val);
        if(ret<0)
            dev_dbg(&client->dev, "Access to driver id=%d,offset=0x%x failes",id,offset );
        return ret;
    }

    //This fonction change the variables of drivers
    static int driver_read(struct i2c_client* client,const u8 id,const u8 offset,const int bits_access)
    {
        u16 addr;
        u16 data;
        u16 ret;
        addr=(((u16)id)<<8)|offset;
        if(bits_access)
            addr|=0xA000;
        else
            addr|=0x2000;
        ret=change_page(client,1);
        if(ret<0)
            return ret;
        ret=reg_write(client,MT9D131_VARIABLE_ADDRESS ,addr);
        if(ret<0)
            return ret;
        data=reg_read(client,MT9D131_VARIABLE_DATA);
        if(data<0)
            return data;
        if(bits_access)
            return data&0x00ff;
        else
            return data;
    }
    //Set the bits of certaine driver to 1
    static int driver_set(struct i2c_client* client,const u8 id,const u8 offset,const u8 mask,const int bits_access)
    {
        s16 data=driver_read(client,id,offset,bits_access);
        if(data<0)
        {
            dev_dbg(&client->dev, "Access to driver id=%d,offset=0x%x failes",id,offset );
            return data;
        }
        return driver_write(client,id,offset,data|mask,bits_access);
    }

    //Set the bits of certain driver to 0
    static int driver_clear(struct i2c_client* client,const u8 id,const u8 offset,const u8 mask,const int bits_access)
    {
        s16 data=driver_read(client,id,offset,bits_access);
        if(data<0)
        {
            dev_dbg(&client->dev, "Access to driver id=%d,offset=0x%x failes",id,offset );
            return data;
        }
        return driver_write(client,id,offset,data&~mask,bits_access);
    }

    //Disable the pll
    static int pll_disable(struct i2c_client *client)
    {
        int ret;
        ret=change_page(client,0);
        if(ret<0)
            return ret;
        //Bypasse the PLL
        ret=reg_set(client,MT9D131_CLOCK_CONTROL,0xC000);
        return ret;
    }

    //Enable the pll,and set the frequence by M,N,P fin=25MHZ
    static int pll_enable(struct i2c_client *client,int M,int N,int P)
    {
        int ret;
        u16 data=0;
        ret=change_page(client,0);
        if(ret<0)
            return ret;
        ret=reg_set(client,MT9D131_CLOCK_CONTROL,0xC000);
        if(ret<0)
            return ret;
        if(M<16||N>64||P>128)
            return -EIO;
        data=data|(M<<8)|N;
        ret=reg_write(client,MT9D131_PLL_CONTROL1,data);
        if(ret<0)
            return ret;
        ret=reg_clear(client,MT9D131_PLL_CONTROL2,0x0f);
        ret=reg_set(client,MT9D131_PLL_CONTROL2,P);
        if(ret<0)
            return ret;
        ret=reg_clear(client,MT9D131_CLOCK_CONTROL,0x4000);
        if(ret<0)
            return ret;
        msleep(1);
        printk("PLL enabled" );
        ret=reg_clear(client,MT9D131_CLOCK_CONTROL,0x8000);
        return ret;
    }

    //Change the mode of the camera ,mode=0 for preview,mode=1 for capture and start capture image
    static int change_mode(struct i2c_client *client,int mode)
    {
        int ret;
        if(mode)
            ret=driver_set(client,MT9D131_ID_SEQ,MT9D131_SEQ_CAPTUREMODE,0x0002,1);
        else
            ret=driver_clear(client,MT9D131_ID_SEQ,MT9D131_SEQ_CAPTUREMODE,0x0002,1);
        if(ret<0)
            dev_dbg(&client->dev, "Failed to change mode" );
        return ret;
    }

    static int mt9d131_init(struct v4l2_subdev *sd, u32 val)
    {
        int ret;
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        ret=pll_disable(client);
        if(ret<0)
            return -EIO;
        //Perform MCU reset
        ret=change_page(client,1);
        if(ret<0)
            return -EIO;
        ret=reg_write(client,MT9D131_MCU_BOOTMODE,0x0501);
        if(ret<0)
            return -EIO;
        //Enable Reset
        ret=change_page(client,1);
        if(ret<0)
            return -EIO;
        ret=reg_write(client,MT9D131_RESET_LOGICIEL,0x0021);
        if(ret<0)
            return -EIO;
        //Disable Reset,ignore the pin Standby
        ret=reg_write(client,MT9D131_RESET_LOGICIEL,0x00A0);
        if(ret<0)
            return -EIO;
        msleep(20);
        //Enable PLL
        return pll_enable(client,18,8,2)>0?0:-EIO;
    }

    static int mt9d131_s_stream(struct v4l2_subdev *sd, int enable)
    {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        int ret;
        //Change mode to capture
        if(change_mode(client,1)<0)
            return -EIO;
        //Enable the output
        if (enable) {
            if (driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,2,1) < 0)
                return -EIO;
        } else {
        //Disable the output
            if (driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,1,1) < 0)
                return -EIO;
        }
        return 0;
    }

    static int mt9d131_set_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)
    {
        int i,ret;
        int flag=0;
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct v4l2_pix_format *pix = &f->fmt.pix;
        for(i=0;i<mt9d131_num_formats;i++)
        {
            if(pix->pixelformat==mt9d131_formats[i].pixelformat)
            {   
                //bypass the JPEG
                ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x30,1);
                switch(mt9d131_formats[i].index){
                case 0://When output of the format match the YUV
                    ret=driver_clear(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x21,1);
                    break;
                case 1://When output of the format match the RGB
                    ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x20,1);
                    break;
                case 2://When output of the format match the JPEG
                    ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x10,1);//Allow the JPEG in context B
                    ret=driver_write(client,MT9D131_ID_JPEG,MT9D131_JPEG_FORMAT,0,1);
                }
                printk("Use %s.\n",mt9d131_formats[i].description);
                flag=1;
                if(ret<0)
                {
                    printk("Out put register error\n");
                    return ret;
                }
                break;
            }
        }
        if(flag==0)
            return -EIO;
        if(pix->width<=MT9D131_MAX_WIDTHB&&pix->height<=MT9D131_MAX_HEIGHTB)//Change the size of window
        {
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_WIDTHB,pix->width,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_HEIGHTB,pix->height,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X0B,0,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X1B,pix->width,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y0B,0,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y1B,pix->width,0);
            if(ret<0)
            {
                printk("Out put register error\n");
                return ret;
            }
        }
        else
            return -EIO;
        ret=change_mode(client,1);
        ret=driver_write(client,MT9D131_ID_SEQ ,MT9D131_SEQ_CMD,5,1);//Refresh the register
        ret=driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,2,1);//Begin to start capture
        return ret<0?ret:0;
    }


    static int mt9d131_try_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)
    {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct v4l2_pix_format *pix = &f->fmt.pix;
        int ret,i;
        int flag=0;
        for(i=0;i<mt9d131_num_formats;i++)
        {
            if(pix->pixelformat==mt9d131_formats[i].pixelformat)
            {
                flag=1;
                break;
            }
        }
        if(!flag)
            pix->pixelformat=mt9d131_formats[0].pixelformat;
        if(pix->width>MT9D131_MAX_WIDTHB)
            pix->width=MT9D131_MAX_WIDTHB;
        if(pix->width>MT9D131_MAX_HEIGHTB)
            pix->width=MT9D131_MAX_HEIGHTB;
        pix->width &= ~0x01; /* has to be even */
        pix->height &= ~0x01; /* has to be even */
        return 0;
    }
                   
    //Get identification of this camera
    static int mt9d131_get_chip_id(struct v4l2_subdev *sd,
                       struct v4l2_dbg_chip_ident *id)
    {
        struct mt9d131 *mt9d131 = to_mt9d131(sd);
        struct i2c_client *client = v4l2_get_subdevdata(sd);;

        if (id->match.type != V4L2_CHIP_MATCH_I2C_ADDR)
            return -EINVAL;

        if (id->match.addr != client->addr)
            return -ENODEV;

        id->ident    = mt9d131->model;
        id->revision    = 0;

        return 0;
    }

    //Register the camera,copy from mt9t031.c
    #ifdef CONFIG_VIDEO_ADV_DEBUG
    static int mt9d131_get_register(struct v4l2_subdev *sd,
                    struct v4l2_dbg_register *reg)
    {
        struct i2c_client *client = v4l2_get_subdevdata(sd);;
        struct mt9d131 *mt9d131 = to_mt9d131(sd);

        if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
            return -EINVAL;

        if (reg->match.addr != client->addr)
            return -ENODEV;

        reg->val = reg_read(client, reg->reg);

        if (reg->val > 0xffff)
            return -EIO;

        return 0;
    }

    static int mt9d131_set_register(struct v4l2_subdev *sd,
                    struct v4l2_dbg_register *reg)
    {
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct mt9d131 *mt9d131 = to_mt9d131(sd);

        if (reg->match.type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
            return -EINVAL;

        if (reg->match.addr != client->addr)
            return -ENODEV;

        if (reg_write(client, reg->reg, reg->val) < 0)
            return -EIO;

        return 0;
    }
    #endif

    static const struct v4l2_subdev_core_ops mt9d131_core_ops = {
        .g_chip_ident = mt9d131_get_chip_id,
        .init = mt9d131_init,
    #ifdef CONFIG_VIDEO_ADV_DEBUG
        .get_register = mt9d131_get_register,
        .set_register = mt9d131_set_register,
    #endif
    };

    static const struct v4l2_subdev_video_ops mt9d131_video_ops = {
        .s_fmt = mt9d131_set_fmt,
        .try_fmt = mt9d131_try_fmt,
        .s_stream = mt9d131_s_stream,
    };

    static const struct v4l2_subdev_ops mt9d131_ops = {
        .core = &mt9d131_core_ops,
        .video = &mt9d131_video_ops,
    };
    /* Interface active, can use i2c. If it fails, it can indeed mean, that
     * this wasn't our capture interface, so, we wait for the right one */
    static int mt9d131_detect(struct i2c_client *client, int *model)
    {
        s32 data;
        int ret;
        /* Read out the chip version register */
        ret=change_page(client,0);
        data = reg_read(client, MT9D131_CHIP_VERSION);
        switch (data) {
        case 0x1519:
            *model = V4L2_IDENT_MT9D131;
            break;
        default:
            dev_err(&client->dev,
                "No MT9D131 chip detected, register read %x\n", data);
            return -ENODEV;
        }

        dev_info(&client->dev, "Detected a MT9D131 chip ID %x\n", data);
        return 0;
    }

    static int mt9d131_probe(struct i2c_client *client,
                 const struct i2c_device_id *did)
    {
        struct mt9d131 *mt9d131;
        struct v4l2_subdev *sd;
        int pclk_pol;
        int ret;

        if (!i2c_check_functionality(client->adapter,
                         I2C_FUNC_SMBUS_WORD_DATA)) {
            dev_warn(&client->dev,
                 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
            return -EIO;
        }

        if (!client->dev.platform_data) {
            dev_err(&client->dev, "No platform data!!\n");
            return -ENODEV;
        }

        pclk_pol = (int)client->dev.platform_data;

        mt9d131 = kzalloc(sizeof(struct mt9d131), GFP_KERNEL);
        if (!mt9d131)
            return -ENOMEM;
        ret = mt9d131_detect(client, &mt9d131->model);
       
        if (ret)
            goto clean;
        /* Register with V4L2 layer as slave device */
        sd = &mt9d131->sd;
        v4l2_i2c_subdev_init(sd, client, &mt9d131_ops);
        ret=change_page(client,0);
        if (!pclk_pol)
            reg_clear(v4l2_get_subdevdata(sd),
                  MT9D131_ROW_SPEED, 0x0100);
        else
            reg_set(v4l2_get_subdevdata(sd),
                MT9D131_ROW_SPEED, 0x0100);
       
        v4l2_info(sd, "%s decoder driver registered !!\n", sd->name);
        return 0;

    clean:
        kfree(mt9d131);
        return ret;
    }

    static int mt9d131_remove(struct i2c_client *client)
    {
        struct v4l2_subdev *sd = i2c_get_clientdata(client);
        struct mt9d131 *mt9d131 = to_mt9d131(sd);

        v4l2_device_unregister_subdev(sd);

        kfree(mt9d131);
        return 0;
    }


    static const struct i2c_device_id mt9d131_id[] = {
        { "mt9d131", 0 },
        { }
    };
    MODULE_DEVICE_TABLE(i2c, mt9d131_id);

    static struct i2c_driver mt9d131_i2c_driver = {
        .driver = {
            .name = "mt9d131",
        },
        .probe        = mt9d131_probe,
        .remove        = mt9d131_remove,
        .id_table    = mt9d131_id,
    };

    static int __init mt9d131_mod_init(void)
    {
        printk("Enabling mt9d131 sensor\n");
        return i2c_add_driver(&mt9d131_i2c_driver);
    }

    static void __exit mt9d131_mod_exit(void)
    {
        i2c_del_driver(&mt9d131_i2c_driver);
    }

    module_init(mt9d131_mod_init);
    module_exit(mt9d131_mod_exit);

    MODULE_DESCRIPTION("Micron MT9D131 Camera driver");
    MODULE_AUTHOR("Thibault BEYOU");
    MODULE_LICENSE("GPL v2");

     

  • Hey,

    device/sub-device registrations seem to be fine. But, the application is trying to set COMPOSITE input. Since it is camera you are trying to capture from , you should provide right arguments so that it can capture from it [ if it has such a opt ion ].

  • Sorry, please look at the line in black, the first time I lance the application, I use the application, I change the code like this itocl(/dev/video2,............), but when I try to open the /dev/video0, it can not be opened, that is my problem

  • My question is, is anybody knows when the board DM365 is booted, which module created this node /dev/video0, thank you very much.

  • Mingming Chen,

    please use following commands after system boots up.

    ls /dev/v*

    This will display all the video nodes which are present. Result might be like,

    /dev/video

    /dev/video1

    /dev/video2

    If the video nodes are present, there should not be problem with opening them.

    -----------------------------------------------------------------------------------------------------

    In the debug messages I am seeing following error message.

    @0x000c1733:[T:0x40bf6490] ti.sdo.dmai - [Capture] Composite input not found (I)

    This means application is looking for COMPOSITE input. This needs to be addressed as well. It should look for CAMERA input. You might need to check for application's options.


  • ./encode: /usr/lib/libpng12.so.0: no version information available (required by)
    Encode demo started.                                                           
    @0x00093aff:[T:0x4001f970] ti.sdo.dmai - [Dmai] Dmai log level set to '2'. Note.
    @0x000e1161:[T:0x4001f970] ti.sdo.dmai - [Display] Found width=720 height=480, 4
    @0x000e1300:[T:0x4001f970] ti.sdo.dmai - [Display] Setting width=720 height=4800
    @0x000e140a:[T:0x4001f970] ti.sdo.dmai - [Display] New width=720, height=480, y4
    @0x000e154b:[T:0x4001f970] ti.sdo.dmai - [BufTab] Allocating BufTab for 1 buffes
    @0x000e1773:[T:0x4001f970] ti.sdo.dmai - [Buffer] Set user pointer 0x403ca000 ()
    @0x000e1cba:[T:0x4001f970] ti.sdo.dmai - [Display] Display buffer 0 mapped to 00
    @0x000ea5dc:[T:0x40bf6490] ti.sdo.dmai - [Capture] Cannot open /dev/video0 (No )
    Error: Failed to detect video standard, video input connected?  

     

    root@192.168.2.199:/opt# ls /dev/video*                                        
    /dev/video0  /dev/video2  /dev/video3      

     

    I modify the file v4l2_dev, when the system is booted, the information is like that

    vpfe-capture: vpss clock vpss_master enabled                                   
    vpfe-capture vpfe-capture: v4l2 device registered                              
    TTTTTTTTTTTTTTTTTTTTTTTTTTTTvideo0                                             
    vpfe-capture vpfe-capture: video device registered                             
    Reset to high                                                                  
    msg.addr = 115                                                                 
    dm365evm_enable_pca9543a, status = -121                                        
    EVM: switch to HD imager video input                                           
    mt9d131 1-005d: Detected a MT9D131 chip ID 1519                                
    mt9d131 1-005d: mt9d131 1-005d decoder driver registered !!                    
    vpfe-capture vpfe-capture: v4l2 sub device mt9d131 registered                  
    vpfe_register_ccdc_device: DM365 ISIF                                          
    DM365 ISIF is registered with vpfe.                                            
    af major#: 252, minor# 0                                                       
    AF Driver initialized                                                          
    aew major#: 251, minor# 0                                                      
    AEW Driver initialized                                                         
    Trying to register davinci display video device.                               
    layer=c2173000,layer->video_dev=c2173170                                       
    TTTTTTTTTTTTTTTTTTTTTTTTTTTTvideo2                                             
    Trying to register davinci display video device.                               
    layer=c2173200,layer->video_dev=c2173370                                       
    TTTTTTTTTTTTTTTTTTTTTTTTTTTTvideo3                           

     

    I think that video2..3 is the output device, now I am getting mad of this probleme

     

     

  • One more way to approaching this problem is by checking whether application is built properly corresponding to kernel you built. [Note: Also, you can use simple capture applications to test your driver changes.]

  • My problem now is like this, when I try to open the node /dev/video0, the system excecute the function S_format automaticlly, like that

    ret=open("/dev/video0“, 0_RDWR,0);

    int mt9d131.c

    int mt9d131_s_fmt()

    {

               printk("Now set_fmt is running \n");

               ............

    }

     

    when I lance my programme, the result is like that

    ./test

    Now set_fmt is running.

    Can not open video0 because of fd=-1

    I do not know whether there is my configuration of Kernel of linux, if anyone also has DM365_EVM, can you try to run my test programme and response to me the result, thank you very much

    But when I add this command ret=ioctl(fd,VIDIOC_S_FMT,&fmt)

    The function mt9d131_s_fmt() was not excecuted,ret=-1

    Even if I change the sub_device to Tv7002, I can not excecute VIDIOC_S_FMT now

    I do not know whether there is my configuration of Kernel of linux, if anyone also has DM365_EVM, can you try to run my test programme and response to me the result, thank you very much


    Dmai_Test.rar
  • Mingming Chen,

    When you open the device, device tries to setup sensor or decoder internally to default state. Thats why, you are seeing set format call of sensor being called. Looks like set format called in sensor sub-device driver is failing[You need to check that]. Hence opening v4l2 device is ending with failure. Once opening the device fails, any calls which use file descriptor of the device will fail.

  • Thank you very much for your response, but how can the v4l2 driver know the default state of my driver.

    For exemple:

                        The fonction of my S_fmt is like this:

    static int mt9d131_set_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)
    {
        struct mt9d131 *mt9d11 = to_mt9d131(sd);
        int i,ret;
        int flag=0;
        printk("Begin to setformat mt9d131");
        struct i2c_client *client = v4l2_get_subdevdata(sd);
        struct v4l2_pix_format *pix = &f->fmt.pix;
        if (f==NULL)
            return  -EINVAL;
        for(i=0;i<mt9d131_num_formats;i++)
        {
            if(pix->pixelformat==mt9d131_formats[i].pixelformat)
            {   
                //bypass the JPEG
                ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x30,1);
                switch(mt9d131_formats[i].index){
                case 0://When output of the format match the YUV
                    ret=driver_clear(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x21,1);
                    break;
                case 1://When output of the format match the RGB
                    ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUT_FORMATB,0x20,1);
                    break;
                case 2://When output of the format match the JPEG
                    ret=driver_write(client,MT9D131_ID_MODE,MT9D131_MODE_CONFIG,0x10,1);//Allow the JPEG in context B
                    ret=driver_write(client,MT9D131_ID_JPEG,MT9D131_JPEG_FORMAT,0,1);
                }
                printk("Use %s.\n",mt9d131_formats[i].description);
                flag=1;
                if(ret<0)
                {
                    printk("Out put register error\n");
                    return -EINVAL;
                }
                break;
            }
        }
        if(flag==0)
        {

            printk("No format matched\n");
            return 1;
        }
        if(pix->width<=MT9D131_MAX_WIDTHB&&pix->height<=MT9D131_MAX_HEIGHTB)//Change the size of window
        {
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_WIDTHB,pix->width,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_OUTPUT_HEIGHTB,pix->height,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X0B,0,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_X1B,pix->width,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y0B,0,0);
            ret=driver_write(client,MT9D131_ID_MODE,MT9D131_CROP_Y1B,pix->width,0);
            if(ret<0)
            {
                printk("Out put register error\n");
                return ret;
            }
        }
        else
            return -EIO;
        ret=change_mode(client,1);
        ret=driver_write(client,MT9D131_ID_SEQ ,MT9D131_SEQ_CMD,5,1);//Refresh the register
        ret=driver_write(client,MT9D131_ID_SEQ,MT9D131_SEQ_CMD,2,1);//Begin to start capture
        return ret<0?ret:0;
    }

    My problem is :1 where the parametre struct v4l2_format *f come from by open("/dev/video,mode,0)?

                            2 when I do nothing in the function S_FMT like that

    static int mt9d131_set_fmt(struct v4l2_subdev *sd,struct v4l2_format *f)

    {

              printk("Begin to setformat mt9d131");

              return 0;

    }

    Now the set_format is executed without any problem, after the v4l2 executed the TRY_FORMAT without any problem. Now the fonction open is executed well and return the value fd=3.

    But when I try to execute the S_FMT with ret=itocl(fd,VIDIOC_S_FMT,&fmt), I think the S_FMT is not executed because I do not view the phrase "Begin to setformat mt9d131" with ret=-1

    Now even I use the decoder TVP7002, I can open the video0 with no problem but I can not execute S_FMT of this camera, I do not know why.

     

     

  • Mingming Chen,

    The design of VPFE capture driver takes into consideration design of sensor driver also. Since you added new sensor driver, you need to change VPFE capture driver also appropriately.

  • How can I change the VPFE capture driver, where can I find the fichier.c? Or is there any reference of the how to modify the driver, thank you very much.

  • Hi! Mingming,

    How did you solve this problem? I just meet the same problem!