www.pudn.com > nvp6114.zip > video.c, change:2014-09-29,size:50427b


#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/miscdevice.h>
#include <linux/proc_fs.h>

#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/system.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/string.h>
#include <linux/list.h>
#include <asm/delay.h>
#include <linux/timer.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/poll.h>
#include <asm/bitops.h>
#include <asm/uaccess.h>
#include <asm/irq.h>
#include <linux/moduleparam.h>
#include <linux/ioport.h>
#include <linux/interrupt.h>

#include "gpio_i2c.h"
#include "nvp6114.h"

/*for 144MHz data,72M clock sampling*/
//#define SAMPLING_CLK_72M

#ifdef ONLY_720H
#define VDEC_108M
#endif

#ifndef VDEC_108M
#define VDEC_144M
#endif
#define NTSC   0
#define PAL    1
#define SET_ALL_CH          0xff

/*nvp6114 色彩推荐配置*/
#define CON_CENTER_VAL_NTSC 0x88
#define CON_CENTER_VAL_PAL  0x88

#define BRI_CENTER_VAL_NTSC 0xFE
#define BRI_CENTER_VAL_PAL  0x00

#define HUE_CENTER_VAL_NTSC 0x01
#define HUE_CENTER_VAL_PAL  0x00

#define SAT_CENTER_VAL_NTSC 0x80
#define SAT_CENTER_VAL_PAL  0x80


unsigned int vdec_contrast_tbl[2]    = {CON_CENTER_VAL_PAL, CON_CENTER_VAL_NTSC};
unsigned int vdec_hue_tbl[2]         = {HUE_CENTER_VAL_PAL, HUE_CENTER_VAL_NTSC};
unsigned int vdec_saturation_tbl[2]  = {SAT_CENTER_VAL_PAL, SAT_CENTER_VAL_NTSC};
unsigned int vdec_brightness_tbl[2]  = {BRI_CENTER_VAL_PAL, BRI_CENTER_VAL_NTSC};
unsigned char vdec_motion_sens_tbl[8]= {0xe0,0xc8,0xa0,0x98,0x78,0x68,0x50,0x48};
extern unsigned int vdec_cnt;
extern int chip_id[4];
extern unsigned int vdec_mode;
extern void audio_init(unsigned char dec, unsigned char ch_num, unsigned char samplerate, unsigned char bits);
/***************************************************************************************/
/************************************ 720P@30fps ***************************************/
/***************************************************************************************/

////////////////////////////////////////////////////////////////////////////////////////////////
/*
                                         NVP6114_AHD_30P_(140621_ver.0.1)          
*/
////////////////////////////////////////////////////////////////////////////////////////////////
unsigned char NVP6114_B0_30P_Buf[] = {
      // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x00,0x00,0x20,0x03,0x00,0x00,0xaf,0x00,0x60,0x60,0x60,0x60,0x08,0x08,0x08,0x08,
/*0x10*/ 0x88,0x88,0x88,0x88,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0x04,0x04,0x04,0x04,
/*0x20*/ 0x00,0x00,0x00,0x00,0x2f,0x92,0x0b,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x30*/ 0x17,0x17,0x17,0x17,0x2f,0x92,0x0b,0x43,0x0a,0x0a,0x0a,0x0a,0x84,0x84,0x84,0x84,
/*0x40*/ 0xFD,0xFD,0xFD,0xFD,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x04,0x04,0x04,0x04,
/*0x50*/ 0x04,0x04,0x04,0x04,0xf1,0x10,0x10,0x00,0xa0,0xa0,0xa0,0xa0,0x9e,0x9e,0x9e,0x9e,
/*0x60*/ 0x00,0x00,0x00,0x00,0x8d,0x8d,0x8d,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x70*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0x00,0x00,0x00,0x00,
/*0x80*/ 0x00,0x00,0x02,0x80,0x04,0x04,0x08,0x04,0x0c,0x00,0x08,0x0e,0x80,0x20,0x0a,0x08,
/*0x90*/ 0x30,0x42,0x80,0x0a,0x7a,0x88,0x6c,0x5e,0x18,0x1f,0x8e,0x94,0xc7,0xa3,0xa0,0x0a,
/*0xa0*/ 0x00,0x00,0x02,0x80,0x04,0x04,0x08,0x04,0x0c,0x00,0x08,0x0e,0x80,0x20,0x0a,0x08,
/*0xb0*/ 0x30,0x42,0x80,0x0a,0x7a,0x88,0x6c,0x5e,0x18,0x1f,0x8e,0x94,0xc7,0xa3,0xa0,0x0a,
/*0xc0*/ 0x01,0x01,0x01,0x01,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
/*0xd0*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xf0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


unsigned char NVP6114_B1_30P_Buf[] = {
      // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x1b,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*0x10*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*0x20*/ 0x88,0x88,0x03,0x19,0x18,0x16,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*0x30*/ 0xaa,0x82,0x00,0x00,0x00,0x8C,0xA0,0x00,0x18,0x01,0x80,0x30,0x00,0x00,0x80,0x00,
/*0x40*/ 0x0f,0x0f,0x0f,0x0f,0x11,0xBB,0x81,0x55,0x60,0x00,0x03,0x10,0x00,0x00,0x00,0x00,
/*0x50*/ 0xDD,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x60*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x70*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x80*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x90*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xa0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xb0*/ 0xff,0xff,0xff,0xff,0x40,0x30,0x40,0x30,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x32,0x32,0x10,0x10,0x10,0x32,0x54,0x76,0x22,0x88,0x03,0x00,0x66,0x66,0x70,0x70,
/*0xd0*/ 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x0f,0xff,0x00,0x02,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x0f,0x0f,0x0f,0xff,
/*0xf0*/ 0xff,0xaa,0x66,0x00,0x83,0x70,0x00,0x1a,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0x01
};


unsigned char NVP6114_B2_30P_Buf[] = {
   // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,
/*0x10*/ 0x00,0x00,0x00,0x00,0xc0,0x00,0x55,0x55,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x20*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x30*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x40*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x50*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x60*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x70*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x80*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x90*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xa0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xb0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xc0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xd0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xf0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x74,0x00,0x74,0x00,0xff,0xff,0xff,0x02
};      

unsigned char NVP6114_B3_30P_Buf[] = {
      // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0xe0,0x0f,0x0c,0x1f,0x00,0x24,0x60,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*0x10*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0xff,0x88,
/*0x20*/ 0x84,0x20,0x23,0x00,0x2a,0xdd,0xf0,0x57,0x90,0x70,0x52,0x78,0x04,0x68,0x00,0x07,
/*0x30*/ 0xe0,0x43,0xa2,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*0x40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*0x50*/ 0x04,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x30,
/*0x60*/ 0x53,0x53,0x20,0x00,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*0x70*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x0f,0x8f,0x0f,0x0f,0x0f,0x8f,0x0f,0x0f,0x00,0x00,
/*0x80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x90*/ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xb0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5C,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0x20,
/*0xd0*/ 0x40,0x50,0x0e,0x00,0x80,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xc0,0x00,0x00,0x00,
/*0xe0*/ 0xa0,0x00,0x01,0x01,0x02,0xa0,0x02,0x05,0x04,0x0b,0xa0,0x06,0x17,0x08,0x30,0x00,
/*0xf0*/ 0x09,0xa0,0xf8,0x00,0x00,0x00,0x00,0x00,0x01,0x05,0x87,0x0b,0x8e,0x11,0x64,0x03
};

 
 unsigned char NVP6114_B4_30P_Buf[] = {
      // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x02,0x04,0x06,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x28,0x30,0x38,0x40,0x48,0x50,
/*0x10*/ 0x58,0x60,0x68,0x70,0x78,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*0x20*/ 0x01,0x03,0x05,0x07,0x0b,0x0f,0x13,0x17,0x1b,0x1f,0x27,0x2f,0x37,0x3f,0x47,0x4f,
/*0x30*/ 0x57,0x5f,0x67,0x6f,0x77,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*0x40*/ 0x00,0x0f,0x06,0x00,0xf5,0x28,0x5c,0x51,0xf5,0x28,0x5c,0x51,0x00,0x00,0x00,0x00,
/*0x50*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
/*0x60*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x70*/ 0xff,0x77,0x77,0x00,0x00,0x00,0x00,0x00,0x16,0x16,0x16,0x16,0x00,0x00,0x00,0x00,
/*0x80*/ 0x37,0x37,0x1b,0x05,0x00,0x07,0x00,0x09,0x00,0x00,0x08,0x06,0x00,0x46,0x00,0x00,
/*0x90*/ 0xaa,0x1c,0x18,0xff,0xaa,0x3c,0xff,0xff,0xaa,0x1b,0x00,0x00,0xaa,0x3b,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,
/*0xb0*/ 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x32,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x37,0x37,0x1b,0x05,0x00,0x07,0x00,0x09,0x00,0x00,0x08,0x06,0x00,0x46,0x00,0x00,
/*0xd0*/ 0xaa,0x1c,0x18,0xff,0xaa,0x3c,0xff,0xff,0xaa,0x1b,0x00,0x00,0xaa,0x3b,0x00,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,
/*0xf0*/ 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x32,0x00,0x00,0x00,0x00,0x00,0x04
};    


 unsigned char NVP6114_B5_30P_Buf[] = {
	 //	 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0xe0,0x0f,0x0c,0x1f,0x00,0x24,0x60,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*0x10*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0xff,0x88,
/*0x20*/ 0x84,0x20,0x23,0x00,0x2a,0xdd,0xf0,0x57,0x90,0x70,0x52,0x78,0x00,0x68,0x00,0x07,
/*0x30*/ 0xe0,0x43,0xa2,0x00,0x00,0x15,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*0x40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*0x50*/ 0x04,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x00,0x30,
/*0x60*/ 0x53,0x53,0x20,0x00,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*0x70*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x0f,0x8f,0x0f,0x0f,0x0f,0x8f,0x0f,0x0f,0x00,0x00,
/*0x80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x90*/ 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xb0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x10,0x30,0x0c,0x50,0x10,0x34,0x70,0x5C,0x20,0x20,0x30,0x40,0x20,0x20,0x14,0x20,
/*0xd0*/ 0x40,0x50,0x0e,0x00,0x80,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xc0,0x00,0x00,0x00,
/*0xe0*/ 0xa0,0x00,0x01,0x01,0x02,0xa0,0x02,0x05,0x04,0x0b,0xa0,0x06,0x17,0x08,0x30,0x00,
/*0xf0*/ 0x09,0xa0,0xf8,0x00,0x00,0x00,0x00,0x00,0x01,0x05,0x87,0x0b,0x8e,0x11,0x64,0x05 
 };		
 
 
////////////////////////////////////////////////////////////////////////////////////////////////
/*
                                          NVP6114_AHD_25P        
*/
////////////////////////////////////////////////////////////////////////////////////////////////

unsigned char NVP6114_B0_25P_Buf[] = {
	    // 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x00,0x00,0x20,0x03,0x00,0x00,0xaf,0x00,0x60,0x60,0x60,0x60,0x08,0x08,0x08,0x08,
/*0x10*/ 0x88,0x88,0x88,0x88,0x90,0x90,0x90,0x90,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x02,
/*0x20*/ 0x00,0x00,0x00,0x00,0x2f,0x92,0x0b,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x30*/ 0x17,0x17,0x17,0x17,0x2f,0x92,0x0b,0x43,0x0a,0x0a,0x0a,0x0a,0x84,0x84,0x84,0x84,
/*0x40*/ 0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x04,0x04,0x04,0x04,
/*0x50*/ 0x04,0x04,0x04,0x04,0x01,0x10,0x10,0x00,0x64,0x64,0x64,0x64,0x9e,0x9e,0x9e,0x9e,
/*0x60*/ 0x00,0x00,0x00,0x00,0x8d,0x8d,0x8d,0x8d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x70*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x88,0x88,0x11,0x11,0x00,0x00,0x00,0x00,
/*0x80*/ 0x00,0x00,0x02,0x80,0x04,0x04,0x08,0x04,0x0c,0x00,0x08,0x0e,0x80,0x20,0x0a,0x08,
/*0x90*/ 0x30,0x42,0x80,0x0a,0x7a,0x88,0x6c,0x5e,0x18,0x1f,0x8e,0x94,0xc7,0xa3,0xa0,0x0a,
/*0xa0*/ 0x00,0x00,0x02,0x80,0x04,0x04,0x08,0x04,0x0c,0x00,0x08,0x0e,0x80,0x20,0x0a,0x08,
/*0xb0*/ 0x30,0x42,0x80,0x0a,0x7a,0x88,0x6c,0x5e,0x18,0x1f,0x8e,0x94,0xc7,0xa3,0xa0,0x0a,
/*0xc0*/ 0x01,0x01,0x01,0x01,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,
/*0xd0*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xf0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};

unsigned char NVP6114_B1_25P_Buf[] = {
	//	0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x02,0x0f,0x0f,0x0f,0x0f,0x0f,0x1b,0x80,0x03,0x00,0x10,0x32,0x54,0x76,0x00,0x98,
/*0x10*/ 0xba,0xdc,0xfe,0x00,0x00,0x00,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,0x88,
/*0x20*/ 0x88,0x88,0x03,0x19,0x18,0x16,0x00,0x00,0x00,0x88,0xff,0x40,0xaa,0xaa,0xaa,0xaa,
/*0x30*/ 0xaa,0x82,0x00,0x00,0x00,0x8C,0xA0,0x00,0x18,0x01,0x80,0x30,0x00,0x00,0x80,0x00,
/*0x40*/ 0x0f,0x0f,0x0f,0x0f,0x11,0xBB,0x81,0x55,0x60,0x00,0x03,0x10,0x00,0x00,0x00,0x00,
/*0x50*/ 0xDD,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x60*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x70*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x80*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x90*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xa0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xb0*/ 0xff,0xff,0xff,0xff,0x40,0x30,0x40,0x30,0x40,0x30,0x40,0x30,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x32,0x32,0x10,0x10,0x10,0x32,0x54,0x76,0x22,0x88,0x03,0x00,0x66,0x66,0x70,0x70,
/*0xd0*/ 0x00,0x00,0x00,0xff,0x00,0x00,0x00,0x00,0x0e,0x01,0x00,0x01,0x00,0x00,0x00,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x01,0x0f,0x01,0xff,
/*0xf0*/ 0xab,0x00,0x77,0x0e,0x83,0x70,0xff,0x1a,0x00,0x0e,0x00,0x0e,0xff,0xff,0xff,0x01
};

unsigned char NVP6114_B2_25P_Buf[] = {
//	0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,0x03,0x60,
/*0x10*/ 0x00,0x00,0x00,0x00,0xc0,0x00,0x55,0x55,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x20*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x30*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x40*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x50*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x60*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x70*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x80*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0x90*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xa0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xb0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xc0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xd0*/ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xf0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3c,0x00,0x3c,0x00,0xff,0xff,0xff,0x02
};

unsigned char NVP6114_B3_25P_Buf[] = {
    //	 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0xe0,0x0f,0x0c,0x1f,0x00,0x24,0x60,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*0x10*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*0x20*/ 0x84,0x20,0x23,0x00,0x2a,0xdd,0xf0,0x57,0x90,0x70,0x52,0x78,0x00,0x68,0x00,0x07,
/*0x30*/ 0xe0,0x43,0xa2,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*0x40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*0x50*/ 0x04,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x30,
/*0x60*/ 0x53,0x53,0x20,0x00,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*0x70*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x0f,0x8f,0x0f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x90*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xb0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0x20,
/*0xd0*/ 0x40,0x50,0x0e,0x00,0x80,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xc0,0x00,0x00,0x00,
/*0xe0*/ 0xa0,0x00,0x01,0x01,0x02,0xa0,0x02,0x05,0x04,0x0b,0xa0,0x06,0x17,0x08,0x30,0x00,
/*0xf0*/ 0x09,0xa0,0xf8,0x00,0x00,0x00,0x00,0x00,0x01,0x05,0x87,0x0b,0x8e,0x11,0x64,0x03
};

unsigned char NVP6114_B4_25P_Buf[] = {
	    //	0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0x02,0x04,0x06,0x08,0x0c,0x10,0x14,0x18,0x1c,0x20,0x28,0x30,0x38,0x40,0x48,0x50,
/*0x10*/ 0x58,0x60,0x68,0x70,0x78,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*0x20*/ 0x01,0x03,0x05,0x07,0x0b,0x0f,0x13,0x17,0x1b,0x1f,0x27,0x2f,0x37,0x3f,0x47,0x4f,
/*0x30*/ 0x57,0x5f,0x67,0x6f,0x77,0x7f,0x87,0x8f,0x97,0x9f,0xaf,0xbf,0xcf,0xdf,0xef,0xff,
/*0x40*/ 0x00,0x0f,0x06,0x00,0x88,0x88,0x88,0x51,0x88,0x88,0x88,0x51,0x00,0x00,0x00,0x00,
/*0x50*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
/*0x60*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x11,0x11,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x70*/ 0xff,0xaa,0xaa,0x00,0x00,0x00,0x00,0x00,0x16,0x16,0x16,0x16,0x00,0x00,0x00,0x00,
/*0x80*/ 0x37,0x37,0x1b,0x05,0x00,0x07,0x00,0x09,0x00,0x00,0x08,0x06,0x00,0x46,0x00,0x00,
/*0x90*/ 0xaa,0x1c,0x18,0xff,0xaa,0x3c,0xff,0xff,0xaa,0x1b,0x00,0x00,0xaa,0x3b,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,
/*0xb0*/ 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x32,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x37,0x37,0x1b,0x05,0x00,0x07,0x00,0x09,0x00,0x00,0x08,0x06,0x00,0x46,0x00,0x00,
/*0xd0*/ 0xaa,0x1c,0x18,0xff,0xaa,0x3c,0xff,0xff,0xaa,0x1b,0x00,0x00,0xaa,0x3b,0x00,0x00,
/*0xe0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01,
/*0xf0*/ 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x32,0x00,0x00,0x00,0x00,0x00,0x04
};


unsigned char NVP6114_B5_25P_Buf[] = {
	 //	 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
/*0x00*/ 0xe0,0x0f,0x0c,0x1f,0x00,0x24,0x60,0x80,0x50,0x38,0x0f,0x00,0x04,0x10,0x30,0x00,
/*0x10*/ 0x06,0x06,0x00,0x80,0x37,0x80,0x49,0x37,0xef,0xdf,0xdf,0x08,0x50,0x0c,0x00,0x88,
/*0x20*/ 0x84,0x20,0x23,0x00,0x2a,0xdd,0xf0,0x57,0x90,0x70,0x52,0x78,0x00,0x68,0x00,0x07,
/*0x30*/ 0xe0,0x43,0xa2,0x00,0x00,0x17,0x25,0x00,0x00,0x02,0x02,0x00,0x00,0x00,0x00,0x00,
/*0x40*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x44,0xaa,0x00,0x00,0x00,0x00,0x00,
/*0x50*/ 0x04,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00,0x30,
/*0x60*/ 0x53,0x53,0x20,0x00,0x22,0x22,0x22,0x22,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
/*0x70*/ 0xc0,0x01,0x06,0x06,0x11,0x00,0x0f,0x8f,0x0f,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x80*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0x90*/ 0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x48,0x84,0x00,0x80,0x00,0x00,0x00,0x00,
/*0xa0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xb0*/ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/*0xc0*/ 0x10,0x10,0x0e,0x70,0x10,0x34,0x70,0x5c,0x40,0x20,0x30,0x40,0x10,0x08,0x04,0x20,
/*0xd0*/ 0x40,0x50,0x0e,0x00,0x80,0x80,0x00,0x00,0x39,0xb2,0x05,0x00,0xc0,0x00,0x00,0x00,
/*0xe0*/ 0xa0,0x00,0x01,0x01,0x02,0xa0,0x02,0x05,0x04,0x0b,0xa0,0x06,0x17,0x08,0x30,0x00,
/*0xf0*/ 0x09,0xa0,0xf8,0x00,0x00,0x00,0x00,0x00,0x01,0x05,0x87,0x0b,0x8e,0x11,0x64,0x05
 };


void vdec_ntsc_common_init(void);
void vdec_pal_common_init(void);
void nvp6114_720p_30fps(void);
void nvp6114_720p_25fps(void);
void vdec_write_table(unsigned char chip_addr, unsigned char addr, unsigned char *tbl_ptr, unsigned char tbl_cnt);


extern unsigned int vdec_mode;
extern unsigned int vdec_slave_addr[2];
void NCdecoder_AfeReset(void)
{
	gpio_i2c_write(vdec_slave_addr[0], 0xFF, 0x00);
	gpio_i2c_write(vdec_slave_addr[1], 0xFF, 0x00);
	gpio_i2c_write(vdec_slave_addr[0], 0x02, gpio_i2c_read(vdec_slave_addr[0], 0x02)|0x0F);
	gpio_i2c_write(vdec_slave_addr[1], 0x02, gpio_i2c_read(vdec_slave_addr[1], 0x02)|0x0F);
	gpio_i2c_write(vdec_slave_addr[0], 0x02, gpio_i2c_read(vdec_slave_addr[0], 0x02)&0xF0);
	gpio_i2c_write(vdec_slave_addr[1], 0x02, gpio_i2c_read(vdec_slave_addr[1], 0x02)&0xF0);
	printk("AFE reset done\n");
}
EXPORT_SYMBOL(NCdecoder_AfeReset);

void wpd_control(unsigned char ison)
{
	int i = 0;

	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x03);
		gpio_i2c_write(vdec_slave_addr[i], 0x70, 0xb8);
		gpio_i2c_write(vdec_slave_addr[i], 0x71, 0x01);
		gpio_i2c_write(vdec_slave_addr[i], 0x72, 0x06);
		gpio_i2c_write(vdec_slave_addr[i], 0x73, 0x11);
		gpio_i2c_write(vdec_slave_addr[i], 0x74, (ison==1)?0x91:0x11);
		gpio_i2c_write(vdec_slave_addr[i], 0x77, 0x03);
		gpio_i2c_write(vdec_slave_addr[i], 0x78, 0x03);
		gpio_i2c_write(vdec_slave_addr[i], 0x79, 0x22);
	}	
	printk("wpd_control %s\n", ison?"ON":"OFF");
}
EXPORT_SYMBOL(wpd_control);

void set_4ch_videosequence(void)
{
	gpio_i2c_write(vdec_slave_addr[0], 0xFF, 0x01);
	gpio_i2c_write(vdec_slave_addr[0], 0xC0, 0x10);  //change video sequence here.
	gpio_i2c_write(vdec_slave_addr[0], 0xC1, 0x32);
	gpio_i2c_write(vdec_slave_addr[0], 0xCA, 0x01);  //only enable video port1
}
void vdec_system_init_new(void)
{
    int i = 0;                               
	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01); 
		gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x40); 
		gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x02);		
		
		gpio_i2c_write(vdec_slave_addr[i], 0x4A, 0x03); 
		gpio_i2c_write(vdec_slave_addr[i], 0x4B, 0x10); 		
		
		gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x61);
		gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x00);
		msleep(100); 
		gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x60); 
		gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x00);
		gpio_i2c_write(vdec_slave_addr[i], 0x3e, 0x80);	 
		gpio_i2c_write(vdec_slave_addr[i], 0x38, 0x18);
		gpio_i2c_write(vdec_slave_addr[i], 0x38, 0x08);   
		msleep(100); 
	}

}

void software_reset(void)
{
	  int i = 0;                               
	for(i=0;i<vdec_cnt;i++)
	{
	    gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01); 
	    gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x40); 
	    gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x02);
	    gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x61);
	    gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x00);
	    msleep(100); 
	    gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x60); 
	    gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x00);
	    msleep(100); 
	}
	printk("\n\r nvp6114 software reset!!!");
}           

void vdec_ntsc_common_init(void)
{
	int i = 0;

	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B0_30P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B1_30P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x02);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B2_30P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x03);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B3_30P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x04);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B4_30P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x05);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B5_30P_Buf,254);	
	}
}

void vdec_pal_common_init(void)
{
	int i = 0;

	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B0_25P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B1_25P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x02);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B2_25P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x03);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B3_25P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x04);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B4_25P_Buf,254);
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x05);
        vdec_write_table(vdec_slave_addr[i],0x00,NVP6114_B5_25P_Buf,254);
	}
}
void mpp2clk_72M(void)
{
	int i=0;
	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
		gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x03);  //mpp1&mpp2 port clock func enables
		gpio_i2c_write(vdec_slave_addr[i], 0xB4, 0x56);  //clock&delay setting
		gpio_i2c_write(vdec_slave_addr[i], 0xB5, 0x56);
	}
}
extern unsigned int outmode;
/*视频输入制式检测函数*/
void video_fmt_det(vdec_input_videofmt *pvideofmt)
{
	int reg_ec[4], reg_ed[4], i, reg_ee[4], reg_ef[4], reg_f0[4];
	for(i=0;i<vdec_cnt;i++)
	{
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
		reg_ec[i] = gpio_i2c_read(vdec_slave_addr[i], 0xEC);
		reg_ed[i] = gpio_i2c_read(vdec_slave_addr[i], 0xED);
		reg_ee[i] = gpio_i2c_read(vdec_slave_addr[i], 0xEE);
		reg_ef[i] = gpio_i2c_read(vdec_slave_addr[i], 0xEF);
		reg_f0[i] = gpio_i2c_read(vdec_slave_addr[i], 0xF0);
		//printk("%x %x %x %x %x\n", reg_ec[i], reg_ed[i],reg_ee[i],reg_ef[i],reg_f0[i]);
	}
	for(i=0;i<(4*vdec_cnt);i++) 
	{
		if(outmode == NVP6114_OUT_ALL_960H)   
		{
			if(((reg_ef[i/4]>>(i%4*2) &0x03)==0x02) && (reg_ec[i/4]>>i &0x01)==0x01)
			{
				pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_SD_PAL;
				printk("ch[%d] video input fmt[SD PAL]\n", i);
			}
			else if(((reg_ef[i/4]>>(i%4*2) &0x03)==0x03) && (reg_ec[i/4]>>i &0x01)==0x01)
			{
				pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_SD_NTSC;
				printk("ch[%d] video input fmt[SD NTSC]\n", i);
			}
			else
			{
				if(0 == ((reg_ee[i/4]>>(i%4+4)) & 0x01))
				{
					if(((reg_ed[i/4]>>(i%4+4)) & 0x01) &&((reg_f0[i/4]>>(i%4*2) &0x03)==0x03))
					{
						pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_AHD_30FPS;
						printk("ch[%d] video input fmt[AHD 30P]\n", i);
					}
				}
				else 
				{
					if(0 == ((reg_ed[i/4]>>(i%4+4)) & 0x01) &&((reg_f0[i/4]>>(i%4*2)&0x03)==0x03))
					{
						pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_AHD_25FPS;
						printk("ch[%d] video input fmt[AHD 25P]\n", i);
					}	
				}
			}
		}
		else
		{
			if((reg_ec[i/4]>>(i%4+4)) & 0x01)
			{
				pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_SD_NTSC;
				printk("ch[%d] video input fmt[SD]\n", i); 
			}
			else
			{
				if(0 == ((reg_ee[i/4]>>(i%4+4)) & 0x01))
				{
					if(((reg_ed[i/4]>>(i%4+4)) & 0x01) &&((reg_f0[i/4]>>(i%4*2) &0x03)==0x03))
					{
						pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_AHD_30FPS;
						printk("ch[%d] video input fmt[AHD 30P]\n", i);
					}
				}
				else 
				{
					if(0 == ((reg_ed[i/4]>>(i%4+4)) & 0x01) &&((reg_f0[i/4]>>(i%4*2)&0x03)==0x03))
					{
						pvideofmt->getvideofmt[i] = NVP6114_INPUT_VIDEOFMT_AHD_25FPS;
						printk("ch[%d] video input fmt[AHD 25P]\n", i);
					}	
				}
			}
		}
	}	
}
/***********FUNC:nvp6114_960H_setting***************/
//vformat:0->NTSC  1->PAL
//channel_mode: 
//0x00 --> ALL channel 720P mode
//0x03 --> 1/2 channel 960H + 3/4 channel 720P mode
//0x0c --> 1/2 channel 720P + 3/4 channel 960H mode
//0x0F --> ALL channel 960H mode
void nvp6114_960H_setting(unsigned char vformat, unsigned char channel_mode)
{
	int i;
	unsigned char ch12_960H=0;
	unsigned char ch34_960H=0;
	if(channel_mode&0x03)
		ch12_960H = 1;
	if(channel_mode&0x0C)
		ch34_960H = 1;
	for(i=0;i<vdec_cnt;i++)
	{
		if(ch12_960H==ch34_960H)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x04);  //bank4
			gpio_i2c_write(vdec_slave_addr[i], 0x5F, 0x00);
		}
		else
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x04);  //bank4
			gpio_i2c_write(vdec_slave_addr[i], 0x5F, 0x01);  //each bank setting
		}	
		
		/************bank 0 diff setting *************/
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);  //bank0
		gpio_i2c_write(vdec_slave_addr[i], 0x54, vformat==PAL?0x01:0xf1);
		if(1==ch12_960H)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x08, vformat==PAL?0xDD:0xA0);
			gpio_i2c_write(vdec_slave_addr[i], 0x09, vformat==PAL?0xDD:0xA0);
			gpio_i2c_write(vdec_slave_addr[i], 0x14, 0x90);
			gpio_i2c_write(vdec_slave_addr[i], 0x15, 0x90);
			gpio_i2c_write(vdec_slave_addr[i], 0x18, 0x88);		
			gpio_i2c_write(vdec_slave_addr[i], 0x1A, 0x22);
			gpio_i2c_write(vdec_slave_addr[i], 0x1C, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x1D, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x40, vformat==PAL?0x00:0x01);
			gpio_i2c_write(vdec_slave_addr[i], 0x41, vformat==PAL?0x00:0x01);
			gpio_i2c_write(vdec_slave_addr[i], 0x48, vformat==PAL?0x00:0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x49, vformat==PAL?0x00:0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x58, vformat==PAL?0x40:0x33);
			gpio_i2c_write(vdec_slave_addr[i], 0x59, vformat==PAL?0x40:0x33);
			gpio_i2c_write(vdec_slave_addr[i], 0x5C, 0x1E);
			gpio_i2c_write(vdec_slave_addr[i], 0x5D, 0x1E);
			gpio_i2c_write(vdec_slave_addr[i], 0x64, vformat==PAL?0x0D:0x08);
			gpio_i2c_write(vdec_slave_addr[i], 0x65, vformat==PAL?0x0D:0x08);
		}
		else if(0==ch12_960H)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x08, 0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x09, 0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x14, 0x9f);
			gpio_i2c_write(vdec_slave_addr[i], 0x15, 0x9f);
			gpio_i2c_write(vdec_slave_addr[i], 0x18, 0x00);		
			gpio_i2c_write(vdec_slave_addr[i], 0x1A, 0x33);  
			gpio_i2c_write(vdec_slave_addr[i], 0x1C, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x1D, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x40, vformat==PAL?0x00:0xFD);
			gpio_i2c_write(vdec_slave_addr[i], 0x41, vformat==PAL?0x00:0xFD);
			gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0x58, vformat==PAL?0x64:0xa0);
			gpio_i2c_write(vdec_slave_addr[i], 0x59, vformat==PAL?0x64:0xa0);
			gpio_i2c_write(vdec_slave_addr[i], 0x5C, 0x9E);
			gpio_i2c_write(vdec_slave_addr[i], 0x5D, 0x9E);
			gpio_i2c_write(vdec_slave_addr[i], 0x64, 0x8d);
			gpio_i2c_write(vdec_slave_addr[i], 0x65, 0x8d);
		}
		
		if(1==ch34_960H)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x0A, vformat==PAL?0xDD:0xA0);
			gpio_i2c_write(vdec_slave_addr[i], 0x0B, vformat==PAL?0xDD:0xA0);
			gpio_i2c_write(vdec_slave_addr[i], 0x16, 0x90);
			gpio_i2c_write(vdec_slave_addr[i], 0x17, 0x90);
			gpio_i2c_write(vdec_slave_addr[i], 0x19, 0x88);
			gpio_i2c_write(vdec_slave_addr[i], 0x1B, 0x22);
			gpio_i2c_write(vdec_slave_addr[i], 0x1E, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x1F, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x42, vformat==PAL?0x00:0x01);
			gpio_i2c_write(vdec_slave_addr[i], 0x43, vformat==PAL?0x00:0x01);
			gpio_i2c_write(vdec_slave_addr[i], 0x4A, vformat==PAL?0x00:0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x4B, vformat==PAL?0x00:0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x5A, vformat==PAL?0x40:0x33);
			gpio_i2c_write(vdec_slave_addr[i], 0x5B, vformat==PAL?0x40:0x33);
			gpio_i2c_write(vdec_slave_addr[i], 0x5E, 0x1E);
			gpio_i2c_write(vdec_slave_addr[i], 0x5F, 0x1E);
			gpio_i2c_write(vdec_slave_addr[i], 0x66, vformat==PAL?0x0D:0x08);
			gpio_i2c_write(vdec_slave_addr[i], 0x67, vformat==PAL?0x0D:0x08);
		}
		else{
			gpio_i2c_write(vdec_slave_addr[i], 0x0A, 0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x0B, 0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x16, 0x9f);
			gpio_i2c_write(vdec_slave_addr[i], 0x17, 0x9f);
			gpio_i2c_write(vdec_slave_addr[i], 0x19, 0x00);		
			gpio_i2c_write(vdec_slave_addr[i], 0x1B, 0x33); 
			gpio_i2c_write(vdec_slave_addr[i], 0x1E, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x1F, vformat==PAL?0x02:0x04);
			gpio_i2c_write(vdec_slave_addr[i], 0x42, vformat==PAL?0x00:0xFD);
			gpio_i2c_write(vdec_slave_addr[i], 0x43, vformat==PAL?0x00:0xFD);
			gpio_i2c_write(vdec_slave_addr[i], 0x4A, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0x4B, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0x5A, vformat==PAL?0x64:0xa0);
			gpio_i2c_write(vdec_slave_addr[i], 0x5B, vformat==PAL?0x64:0xa0);
			gpio_i2c_write(vdec_slave_addr[i], 0x5E, 0x9E);
			gpio_i2c_write(vdec_slave_addr[i], 0x5F, 0x9E);
			gpio_i2c_write(vdec_slave_addr[i], 0x66, 0x8d);
			gpio_i2c_write(vdec_slave_addr[i], 0x67, 0x8d);
		}
		
		/************bank 2 diff setting *************/
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x02);  		
		gpio_i2c_write(vdec_slave_addr[i], 0x12, (ch34_960H?0x03:0x00)<<2|(ch12_960H?0x03:0x00));
		gpio_i2c_write(vdec_slave_addr[i], 0x16, (ch12_960H?0x00:0x55));
		gpio_i2c_write(vdec_slave_addr[i], 0x17, (ch34_960H?0x00:0x55));
				
		/************bank 4 diff setting *************/
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x04);   			
		gpio_i2c_write(vdec_slave_addr[i], 0x5C, (ch34_960H?0x00:0x0F)<<4|(ch12_960H?0x00:0x0F));
		gpio_i2c_write(vdec_slave_addr[i], 0x41, (ch34_960H?0x00:0x03)<<2|(ch12_960H?0x00:0x03));
		gpio_i2c_write(vdec_slave_addr[i], 0x40, 0x00);
		if(ch12_960H==1)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x64, 0x11);
			gpio_i2c_write(vdec_slave_addr[i], 0x68, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x71, 0x55);
		}
		else{
			gpio_i2c_write(vdec_slave_addr[i], 0x64, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x68, 0x11);
			gpio_i2c_write(vdec_slave_addr[i], 0x71, vformat==PAL?0xAA:0x77);
		}
		if(ch34_960H==1)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x65, 0x11);
			gpio_i2c_write(vdec_slave_addr[i], 0x69, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x72, 0x55);	
		}
		else {
			gpio_i2c_write(vdec_slave_addr[i], 0x65, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x69, 0x11);
			gpio_i2c_write(vdec_slave_addr[i], 0x72, vformat==PAL?0xAA:0x77);				
		}
		if(1==ch12_960H && 1==ch34_960H)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0x40, 0x60);
			//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);
		}
		else if(0==ch12_960H && 0==ch34_960H)
		{
			if(vformat == NTSC)
			{
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0xf5);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x28);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x5c);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0xf5);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x28);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x5c);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);
			}
			else
			{
	
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);			
			}
			
		}
		else if(1==ch12_960H)
		{
			if(vformat == NTSC)
			{
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0xf5);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x28);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x5c);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);
			}
			else
			{
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);			
			}
		}
		else if(1==ch34_960H)
		{
			if(vformat == NTSC)
			{
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0xf5);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x28);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x5c);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);		
			}
			else
			{
				//============== FSC_EXT_VAL ===================//
				gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x45, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x46, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x47, 0x51);
				gpio_i2c_write(vdec_slave_addr[i], 0x48, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x49, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4a, 0x88);
				gpio_i2c_write(vdec_slave_addr[i], 0x4b, 0x51);			
			}
		}
		/************bank 3 diff setting *************/
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x03);  		
		gpio_i2c_write(vdec_slave_addr[i], 0x53, (ch34_960H?0x03:0x00)<<2|(ch12_960H?0x03:0x00));		
		gpio_i2c_write(vdec_slave_addr[i], 0x2C, vformat==PAL?0x00:0x04);	
		if(0==ch12_960H && 0==ch34_960H)
		{
			//================== Bank3 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x03);
			//========= Mode Enable for Ch 1~2 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x70);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, vformat==PAL?0x70:0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x20);
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x24);			
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x08);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x04);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0x39);
			//================ Bank 5 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x05);
			//========= Mode Enable for Ch 3~4 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x70);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, vformat==PAL?0x70:0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x20);			
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x24);
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x08);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x04);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);	
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0x39);
		}
		else if(1==ch12_960H)
		{
			//================== Bank3 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x03);
			//========= Mode Enable for Ch 1~2 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x1F);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x21);
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x20);
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x20);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x84);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0xb9);
			//================ Bank 5 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x05);
			//========= Mode Enable for Ch 3~4 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x70);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, vformat==PAL?0x70:0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x20);			
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x24);
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x08);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x04);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x30);	
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0x39);
		}
		else if(1==ch34_960H)
		{
			//================== Bank3 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x03);
			//========= Mode Enable for Ch 1~2 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x70);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, vformat==PAL?0x70:0x60);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x20);
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x24);
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x08);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x04);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x30);
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0x39);
			//================ Bank 5 =====================//
			gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x05);
			//========= Mode Enable for Ch 3~4 =============//
			gpio_i2c_write(vdec_slave_addr[i], 0x29, 0x1F);
			gpio_i2c_write(vdec_slave_addr[i], 0x5c, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0x62, 0x21);
			gpio_i2c_write(vdec_slave_addr[i], 0x05, 0x20);
			gpio_i2c_write(vdec_slave_addr[i], 0x1b, 0x20);	
			gpio_i2c_write(vdec_slave_addr[i], 0x50, 0x84);			
			gpio_i2c_write(vdec_slave_addr[i], 0x5f, 0x00);	
			gpio_i2c_write(vdec_slave_addr[i], 0xD4, 0x00);
			gpio_i2c_write(vdec_slave_addr[i], 0xD5, 0x80);
			gpio_i2c_write(vdec_slave_addr[i], 0xD8, 0xB9);
		}	
		gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x03);
		gpio_i2c_write(vdec_slave_addr[i], 0x35, vformat==PAL?0x17:0x15);
		gpio_i2c_write(vdec_slave_addr[i], 0xC1, vformat==PAL?0x10:0x30);
		gpio_i2c_write(vdec_slave_addr[i], 0xC2, vformat==PAL?0x0E:0x0C);
		gpio_i2c_write(vdec_slave_addr[i], 0xC3, vformat==PAL?0x70:0x50);
		gpio_i2c_write(vdec_slave_addr[i], 0xC8, vformat==PAL?0x40:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCC, vformat==PAL?0x10:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCD, vformat==PAL?0x08:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCE, vformat==PAL?0x04:0x14);
		gpio_i2c_write(vdec_slave_addr[i], 0xff, 0x05);
		gpio_i2c_write(vdec_slave_addr[i], 0x35, vformat==PAL?0x17:0x15);
		gpio_i2c_write(vdec_slave_addr[i], 0xC1, vformat==PAL?0x10:0x30);
		gpio_i2c_write(vdec_slave_addr[i], 0xC2, vformat==PAL?0x0E:0x0C);
		gpio_i2c_write(vdec_slave_addr[i], 0xC3, vformat==PAL?0x70:0x50);
		gpio_i2c_write(vdec_slave_addr[i], 0xC8, vformat==PAL?0x40:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCC, vformat==PAL?0x10:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCD, vformat==PAL?0x08:0x20);
		gpio_i2c_write(vdec_slave_addr[i], 0xCE, vformat==PAL?0x04:0x14);
		
		/************bank 1 diff setting *************/
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);  
		gpio_i2c_write(vdec_slave_addr[i], 0x44, 0x11);
		gpio_i2c_write(vdec_slave_addr[i], 0x45, (ch34_960H?0x01:0x0B)<<4|(ch12_960H?0x01:0x0B));
		gpio_i2c_write(vdec_slave_addr[i], 0x47, (ch34_960H?0x00:0x05)<<4|(ch12_960H?0x00:0x05));
		gpio_i2c_write(vdec_slave_addr[i], 0x50, (ch34_960H?0x07:0x0D)<<4|(ch12_960H?0x07:0x0D));
		gpio_i2c_write(vdec_slave_addr[i], 0xD3, (ch34_960H?0x00:0x03)<<2|(ch12_960H?0x00:0x03));
				
		if(ch12_960H==0 && ch34_960H==0)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x66);			
			gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x66);
		}
		else if(ch12_960H==1 && ch34_960H==1)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x46);			
			gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x46);
		}
		else if(ch12_960H==1)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x66);
			gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x46);			
		}
		else if(ch34_960H==1)
		{

			gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x66);
			gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x46);
		}
	}
	printk("ch1/2 mode[%s],ch3/4 mode[%s]\n", ch12_960H?"960H":"720P", ch34_960H?"960H":"720P");
}


void nvp6114_720p_30fps(void)
{
	printk("common_init\n");
	vdec_ntsc_common_init();

	#ifdef SAMPLING_CLK_72M
	for(i=0;i<vdec_cnt;i++)
	{		
		//bank1 
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
		gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x43);
		gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x43);
	}
	mpp2clk_72M();
	printk("\n\rUsing 72M clk SETTING!!!\n");
	#endif
	vdec_system_init_new();
	software_reset();
	printk("\n\rNVP6114 720P@30fps MODE SETTING!!!\n");
}

void nvp6114_720p_25fps( void )
{
	vdec_pal_common_init();	

	#ifdef SAMPLING_CLK_72M
	for(i=0;i<vdec_cnt;i++)
	{		
		//bank1 
		gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x01);
		gpio_i2c_write(vdec_slave_addr[i], 0xCC, 0x43);
		gpio_i2c_write(vdec_slave_addr[i], 0xCD, 0x43);
	}
	mpp2clk_72M();
	printk("\n\rUsing 72M clk SETTING!!!\n");
	#endif

	vdec_system_init_new();
	software_reset();
	printk("\n\rNVP6114 720P@25fps MODE SETTING!!!\n");
}

void vdec_video_set_contrast(unsigned int ch, unsigned int value, unsigned int v_format)
{
    int num;
	int i = 0;

	if(ch != 0xff)
    {
		gpio_i2c_write(vdec_slave_addr[ch/4], 0xFF, 0x00);
		if(value >= 100)
		{
			gpio_i2c_write(vdec_slave_addr[ch/4], (0x10+(ch%4)),(vdec_contrast_tbl[v_format]+value-100));
		}
  	  	else
		{
			gpio_i2c_write(vdec_slave_addr[ch/4], (0x10+(ch%4)),(vdec_contrast_tbl[v_format]+(0xff-(98-value))));
		}
	}
	else
	{
		for(i=0;i<vdec_cnt;i++)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);
			for(num=0; num<4; num++)
			{
				if(value >= 100)
					gpio_i2c_write(vdec_slave_addr[i], (0x10+(num%4)), (vdec_contrast_tbl[v_format]+value-100));
              	else
					gpio_i2c_write(vdec_slave_addr[i], (0x10+(num%4)), (vdec_contrast_tbl[v_format]+(0xff-(98-value))));
			}
		}
	}
}

void vdec_video_set_brightness(unsigned int ch, unsigned int value, unsigned int v_format)
{
    int num;
	int i=0;
	
	if(ch != SET_ALL_CH)
    {
		{
			gpio_i2c_write(vdec_slave_addr[ch/4], 0xFF, 0x00);
			if(value >= 100)
			{
				gpio_i2c_write(vdec_slave_addr[ch/4], (0x0c+(ch%4)),(vdec_brightness_tbl[v_format]+value-100));
			}
       	   	else
			{
				gpio_i2c_write(vdec_slave_addr[ch/4], (0x0c+(ch%4)),(vdec_brightness_tbl[v_format]+(0xff-(98-value))));
			}
		}
		
	}
	else
	{
		for(i=0;i<vdec_cnt;i++)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);	
			for(num=0; num<4; num++)
			{
				if(value >= 100)
				{
					gpio_i2c_write(vdec_slave_addr[i], (0x0c+(num%4)), (vdec_brightness_tbl[v_format]+value-100));
				}
              	else
				{
					gpio_i2c_write(vdec_slave_addr[i], (0x0c+(num%4)), (vdec_brightness_tbl[v_format]+(0xff-(98-value))));
				}
			}
		}
	}
}

void vdec_video_set_saturation(unsigned int ch, unsigned int value, unsigned int v_format)
{
    int num;
	int i = 0;
	

	if(ch != SET_ALL_CH)
    {
		//if(ch<8)
		{
			gpio_i2c_write(vdec_slave_addr[ch/4], 0xFF, 0x00);
			gpio_i2c_write(vdec_slave_addr[ch/4], (0x3c+(ch%4)),(vdec_saturation_tbl[v_format]+value-100));
		}
		
	}
	else
	{
		for(i=0;i<vdec_cnt;i++)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);
			for(num=0; num<4; num++)
			{
				gpio_i2c_write(vdec_slave_addr[i], (0x3c+(num%4)), (vdec_saturation_tbl[v_format]+value-100));
			}
		}
	}
}

void vdec_video_set_hue(unsigned int ch, unsigned int value, unsigned int v_format)
{
    int num;
	int i = 0;
	

	if(ch != SET_ALL_CH)
    {
		//if(ch<8)
		{
			gpio_i2c_write(vdec_slave_addr[ch/4], 0xFF, 0x00);
			gpio_i2c_write(vdec_slave_addr[ch/4], (0x40+(ch%4)), (vdec_hue_tbl[v_format]+value-100));
		}
		
	}
	else
	{
		for(i=0;i<vdec_cnt;i++)
		{
			gpio_i2c_write(vdec_slave_addr[i], 0xFF, 0x00);
			for(num=0; num<4; num++)
			{
				gpio_i2c_write(vdec_slave_addr[i], (0x40+(num%4)), (vdec_hue_tbl[v_format]+value-100));
			}
		}
	}
}

void vdec_write_table(unsigned char chip_addr, unsigned char addr, unsigned char *tbl_ptr, unsigned char tbl_cnt)
{
	unsigned char i = 0;
	
	for(i = 0; i < tbl_cnt; i ++)
	{
		gpio_i2c_write(chip_addr, (addr + i), *(tbl_ptr + i));
	}
}