void vSetHDMISyncDelay(u8 bResIndex)
{
	MT8193_VIDEO_FUNC();
	vWriteHdmiDGIMsk(tg_ctrl00, prgs_out, syn_del | prgs_out);
	vWriteHdmiDGIMsk(tg_ctrl01, HVSYNC_DELAY[bResIndex],
			 rg_vsync_delay | rg_hsync_delay | rg_vsync_forward);
}
void vSetHDMITxPLL(u8 bResIndex, u8 bdeepmode)
{
	u8 u4Feq = 0;
	MT8193_PLL_FUNC();

	vWriteHdmiDGIMsk(dgi0_anaif_ctrl1, dgi1_pad_clk_en,
			 anaif_dig1_clk_sel | dgi1_pad_clk_en | clk_sel_tv_mode | data_in_tv_mode |
			 dgi1_clk_pad_sel_tv_mode | tv_mode_clk_en);

	if ((bResIndex == HDMI_VIDEO_720x480p_60Hz) || (bResIndex == HDMI_VIDEO_720x576p_50Hz))
		u4Feq = 0;	/* 27M */
	else if ((bResIndex == HDMI_VIDEO_1920x1080p_60Hz)
		 || (bResIndex == HDMI_VIDEO_1920x1080p_50Hz))
		u4Feq = 2;	/* 148M */
	else
		u4Feq = 1;	/* 74M */

	if (((bResIndex == HDMI_VIDEO_1920x1080p_60Hz) || (bResIndex == HDMI_VIDEO_1920x1080p_50Hz))
	    && (bdeepmode == HDMI_DEEP_COLOR_12_BIT))
		vVideoPLLInit_1080P_36BIT();
	else
		vVideoPLLInit();

	udelay(10);
	if (bdeepmode == HDMI_NO_DEEP_COLOR) {
		vWriteHdmiSYSMsk(HDMI_SYS_PLLCTRL2, (HDMI_PLL_SETTING[u4Feq][0]), 0xFF);
		vWriteHdmiSYS(HDMI_SYS_PLLCTRL3,
			      (HDMI_PLL_SETTING[u4Feq][1]) | (HDMI_PLL_SETTING[u4Feq][2] << 8) |
			      (HDMI_PLL_SETTING[u4Feq][3] << 16) | (HDMI_PLL_SETTING[u4Feq][4] <<
								    24));
	} else if (bdeepmode == HDMI_DEEP_COLOR_10_BIT) {
		vWriteHdmiSYSMsk(HDMI_SYS_PLLCTRL2, (HDMI_PLL_SETTING_X_1_25[u4Feq][0]), 0xFF);
		vWriteHdmiSYS(HDMI_SYS_PLLCTRL3,
			      (HDMI_PLL_SETTING_X_1_25[u4Feq][1]) |
			      (HDMI_PLL_SETTING_X_1_25[u4Feq][2] << 8) |
			      (HDMI_PLL_SETTING_X_1_25[u4Feq][3] << 16) |
			      (HDMI_PLL_SETTING_X_1_25[u4Feq][4] << 24));
	} else if (bdeepmode == HDMI_DEEP_COLOR_12_BIT) {
		vWriteHdmiSYSMsk(HDMI_SYS_PLLCTRL2, (HDMI_PLL_SETTING_X_1_5[u4Feq][0]), 0xFF);
		vWriteHdmiSYS(HDMI_SYS_PLLCTRL3,
			      (HDMI_PLL_SETTING_X_1_5[u4Feq][1]) | (HDMI_PLL_SETTING_X_1_5[u4Feq][2]
								    << 8) |
			      (HDMI_PLL_SETTING_X_1_5[u4Feq][3] << 16) |
			      (HDMI_PLL_SETTING_X_1_5[u4Feq][4] << 24));
	}
	vWriteHdmiSYSMsk(HDMI_SYS_PLLCTRL6, RG_CK148M_EN, RG_CK148M_EN);


}
void vSetHDMIDataEnable(u8 bResIndex)
{
	MT8193_VIDEO_FUNC();
	if (bResIndex < HDMI_VIDEO_RESOLUTION_NUM) {
		vWriteHdmiDGIMsk(tg_ctrl02, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][0], 0xffffffff);
		vWriteHdmiDGIMsk(tg_ctrl03, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][1], 0xffffffff);
		vWriteHdmiDGIMsk(tg_ctrl04, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][5] << 5,
				 0xffffffff);
		vWriteHdmiDGIMsk(tg_ctrl05, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][4], 0xffffffff);
		vWriteHdmiDGIMsk(tg_ctrl06, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][3], 0xffffffff);
		vWriteHdmiDGIMsk(tg_ctrl07, HVSYNC_TOTAL_WIDTH_ACTIVE[bResIndex][2], 0xffffffff);
	}

}
void vHDMIVideoOutput(u8 ui1Res, u8 ui1ColorSpace)
{
	MT8193_VIDEO_FUNC();

	vWriteHdmiDGIMsk(fifo_ctrl, sw_rst, sw_rst);
	vWriteHdmiDGIMsk(dgi1_clk_rst_ctrl,
			 dgi1_clk_out_enable | dgi1_clk_in_inv_enable | dgi1_clk_in_enable,
			 dgi1_clk_out_enable | dgi1_clk_in_inv_enable | dgi1_clk_in_enable);
	vWriteHdmiDGIMsk(data_out_ctrl, fall_use_fall, fall_use_fall | rise_use_fall);
	vWriteHdmiDGIMsk(fifo_ctrl, (0x40 << 0), rd_start);
	vWriteHdmiDGIMsk(fifo_ctrl, fifo_reset_on, fifo_reset_sel | fifo_reset_on);
	vWriteHdmiDGIMsk(dec_ctl, dgi1_on, dgi1_on);
	vWriteHdmiDGIMsk(ctrl_422_444, (CBCR_PRELOAD[ui1Res] << 8), rg_cbcr_preload);

	if (ui1ColorSpace == HDMI_YCBCR_444) {
		vWriteHdmiDGIMsk(ctrl_422_444, rpt_422_444, rpt_422_444 | bypass_422_444);
		vWriteHdmiDGIMsk(data_out_ctrl, (0x1 << 0) | (0x0 << 2) | (0x0 << 4),
				 y_out_delay | c1_out_delay | c2_out_delay);
		vWriteHdmiDGIMsk(dgi1_yuv2rgb_ctr, 0, rg_yuv709_rgb | rg_yuv2rgb_en);
	} else if (ui1ColorSpace == HDMI_YCBCR_422) {
		vWriteHdmiDGIMsk(ctrl_422_444, bypass_422_444, rpt_422_444 | bypass_422_444);
		vWriteHdmiDGIMsk(data_out_ctrl, (0x1 << 0) | (0x0 << 2) | (0x0 << 4),
				 y_out_delay | c1_out_delay | c2_out_delay);
		vWriteHdmiDGIMsk(dgi1_yuv2rgb_ctr, 0, rg_yuv709_rgb | rg_yuv2rgb_en);
	} else if (ui1ColorSpace == HDMI_RGB) {
		vWriteHdmiDGIMsk(ctrl_422_444, rpt_422_444, rpt_422_444 | bypass_422_444);
		vWriteHdmiDGIMsk(data_out_ctrl, (0x1 << 0) | (0x1 << 2) | (0x0 << 4),
				 y_out_delay | c1_out_delay | c2_out_delay);
		vWriteHdmiDGIMsk(dgi1_yuv2rgb_ctr, rg_yuv709_rgb | rg_yuv2rgb_en,
				 rg_yuv709_rgb | rg_yuv2rgb_en);
	} else {
		pr_debug("color space type error\n");
	}
}
void vHDMIVideoOutput(u8 ui1Res, u8 ui1ColorSpace)
{
   MT8193_VIDEO_FUNC();

   vWriteHdmiDGIMsk(fifo_ctrl, sw_rst, sw_rst);
   vWriteHdmiDGIMsk(dgi0_anaif_ctrl1, dgi1_pad_clk_en, anaif_dig1_clk_sel|dgi1_pad_clk_en|clk_sel_tv_mode|data_in_tv_mode|dgi1_clk_pad_sel_tv_mode|tv_mode_clk_en);
   vWriteHdmiDGIMsk(dgi1_clk_rst_ctrl, dgi1_clk_out_enable|dgi1_clk_in_inv_enable|dgi1_clk_in_enable, dgi1_clk_out_enable|dgi1_clk_in_inv_enable|dgi1_clk_in_enable);
   vWriteHdmiDGIMsk(data_out_ctrl, fall_use_fall, fall_use_fall|rise_use_fall);
   vWriteHdmiDGIMsk(fifo_ctrl, (0x40<<0), rd_start);
   vWriteHdmiDGIMsk(fifo_ctrl, fifo_reset_on, fifo_reset_sel|fifo_reset_on);
   vWriteHdmiDGIMsk(dec_ctl, dgi1_on, dgi1_on);
   vWriteHdmiDGIMsk(ctrl_422_444, (CBCR_PRELOAD[ui1Res]<<8), rg_cbcr_preload);
   
   if(ui1ColorSpace==HDMI_YCBCR_444)
   {
     vWriteHdmiDGIMsk(ctrl_422_444, rpt_422_444, rpt_422_444|bypass_422_444);
	 vWriteHdmiDGIMsk(data_out_ctrl, (0x1<<0)|(0x0<<2)|(0x0<<4), y_out_delay|c1_out_delay|c2_out_delay);
   }
   else if(ui1ColorSpace==HDMI_YCBCR_422)
   {
     vWriteHdmiDGIMsk(ctrl_422_444, bypass_422_444, rpt_422_444|bypass_422_444);
	 vWriteHdmiDGIMsk(data_out_ctrl, (0x1<<0)|(0x0<<2)|(0x0<<4), y_out_delay|c1_out_delay|c2_out_delay);
   }
   else
   {
     vWriteHdmiDGIMsk(ctrl_422_444, 0, rpt_422_444|bypass_422_444);
     vWriteHdmiDGIMsk(data_out_ctrl, (0x1<<0)|(0x0<<2)|(0x0<<4), y_out_delay|c1_out_delay|c2_out_delay);
   }
}
void vUnBlackHDMIOnly(void)
{
  MT8193_DRV_FUNC();
  vWriteHdmiDGIMsk(fifo_ctrl, 0, fifo_reset_sel|fifo_reset_on|sw_rst);
  *(unsigned int*)(0xf400f0b4) = 0x0;
}