/*
* before call this ftn. set the status data!!
*/
bool _s5p_tv_if_set_disp(void)
{
	s5p_tv_status *st = &s5ptv_status;

	s5p_tv_disp_mode disp_mode = st->tvout_param.disp_mode;
	s5p_tv_o_mode out_mode = st->tvout_param.out_mode;
	
	TVOUTIFPRINTK("(%d, %d)\n\r",disp_mode,out_mode);

	switch (disp_mode) {

	case TVOUT_NTSC_M:

	case TVOUT_NTSC_443:
		st->sdout_video_scale_cfg.component_level=S5P_TV_SD_LEVEL_0IRE;
		st->sdout_video_scale_cfg.component_ratio=SDOUT_VTOS_RATIO_7_3;
		st->sdout_video_scale_cfg.composite_level=S5P_TV_SD_LEVEL_75IRE;
		st->sdout_video_scale_cfg.composite_ratio=SDOUT_VTOS_RATIO_10_4;
		break;

	case TVOUT_PAL_BDGHI:

	case TVOUT_PAL_M:

	case TVOUT_PAL_N:

	case TVOUT_PAL_NC:

	case TVOUT_PAL_60:
		st->sdout_video_scale_cfg.component_level=S5P_TV_SD_LEVEL_0IRE;
		st->sdout_video_scale_cfg.component_ratio=SDOUT_VTOS_RATIO_7_3;
		st->sdout_video_scale_cfg.composite_level=S5P_TV_SD_LEVEL_0IRE;
		st->sdout_video_scale_cfg.composite_ratio=SDOUT_VTOS_RATIO_7_3;
		break;

	case TVOUT_480P_60_16_9:

	case TVOUT_480P_60_4_3:

	case TVOUT_576P_50_16_9:

	case TVOUT_576P_50_4_3:

	case TVOUT_720P_50:

	case TVOUT_720P_60:

#ifdef CONFIG_CPU_S5PV210

	case TVOUT_1080I_50:

	case TVOUT_1080I_60:

	case TVOUT_1080P_50:

	case TVOUT_1080P_60:

	case TVOUT_1080P_30:		

	case TVOUT_480P_59:		

	case TVOUT_720P_59:		

	case TVOUT_1080I_59:

	case TVOUT_1080P_59:		
#endif		
		if (!_s5p_tv_if_init_avi_frame(&st->tvout_param)) {
			st->tvout_param_available = false;
			return false;
		}

		break;

	default:
		TVOUTIFPRINTK("invalid disp_mode parameter(%d)\n\r",disp_mode);
		st->tvout_param_available = false;
		return false;
		break;
	}

	switch (out_mode) {

	case TVOUT_OUTPUT_COMPOSITE:
		st->sdout_order = S5P_TV_SD_O_ORDER_COMPOSITE_Y_C_CVBS;
		st->sdout_dac_on[2] = false;
		st->sdout_dac_on[1] = false;
		st->sdout_dac_on[0] = true;
		break;

	case TVOUT_OUTPUT_SVIDEO:
		st->sdout_order = S5P_TV_SD_O_ORDER_COMPOSITE_C_Y_CVBS;
		st->sdout_dac_on[2] = true;
		st->sdout_dac_on[1] = true;
		st->sdout_dac_on[0] = false;
		break;

	case TVOUT_OUTPUT_COMPONENT_YPBPR_INERLACED:

	case TVOUT_OUTPUT_COMPONENT_YPBPR_PROGRESSIVE:

	case TVOUT_OUTPUT_COMPONENT_RGB_PROGRESSIVE:
		st->sdout_order = S5P_TV_SD_O_ORDER_COMPONENT_RBG_PRPBY;
		st->sdout_dac_on[2] = true;
		st->sdout_dac_on[1] = true;
		st->sdout_dac_on[0] = true;
		break;

	case TVOUT_OUTPUT_HDMI_RGB:
	case TVOUT_OUTPUT_HDMI:
	case TVOUT_OUTPUT_DVI:
		st->hdmi_video_blue_screen.cb_b = 0;//128;
		st->hdmi_video_blue_screen.y_g  = 0;
		st->hdmi_video_blue_screen.cr_r = 0;//128;
		break;

	default:
		TVOUTIFPRINTK("invalid out_mode parameter(%d)\n\r",out_mode);
		st->tvout_param_available = false;
		return false;
		break;
	}
#if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_PM_PWR_GATING )
    if((st->hpd_status) && st->suspend_status == false)
    {
#endif
	_s5p_tv_if_start();
#if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_PM_PWR_GATING )
    }
    // If the cable is not inserted or system is on suspend mode 
    // Just set variable, _s5p_tv_if_start() function will be called in resume or handle_cable function according to this variable
    else
        st->tvout_output_enable = true;
#endif
	
	return true;
}
bool _s5p_tv_if_init_hd_video_reg(void)
{
	enum s5p_tv_hdmi_err herr = 0;
	enum s5p_tv_hdmi_csc_type cscType;
	struct s5p_tv_status *st = &s5ptv_status;

	u8 cb_b = st->hdmi_video_blue_screen.cb_b;
	u8 y_g = st->hdmi_video_blue_screen.y_g;
	u8 cr_r = st->hdmi_video_blue_screen.cr_r;

	u8 y_min = st->hdmi_color_range.y_min;
	u8 y_max = st->hdmi_color_range.y_max;
	u8 c_min = st->hdmi_color_range.c_min;
	u8 c_max = st->hdmi_color_range.c_max;

	enum s5p_tv_disp_mode disp_mode = st->tvout_param.disp_mode;
	enum s5p_tv_o_mode out_mode = st->tvout_param.out_mode;

	enum s5p_hdmi_transmit *a_trans_type =
		&st->hdmi_av_info_frame.trans_type;
	u8 *a_check_sum = &st->hdmi_av_info_frame.check_sum;
	u8 *a_data = st->hdmi_av_info_frame.data;

	enum s5p_hdmi_transmit m_trans_type =
		st->hdmi_mpg_info_frame.trans_type;
	u8 m_check_sum = st->hdmi_mpg_info_frame.check_sum;
	u8 *m_data = st->hdmi_mpg_info_frame.data;

	enum s5p_hdmi_transmit s_trans_type =
		st->hdmi_spd_info_frame.trans_type;
	u8 *spd_header = st->hdmi_spd_info_frame.spd_header;
	u8 *spd_data = st->hdmi_spd_info_frame.spd_data;

	if (!_s5p_tv_if_init_avi_frame(&st->tvout_param)) {
		st->tvout_param_available = false;
		return false;
	}

	herr = __s5p_hdmi_video_init_display_mode(disp_mode, out_mode, a_data);

	if (herr != HDMI_NO_ERROR)
		return false;

	st->hdmi_av_info_frame.check_sum = _s5p_tv_if_video_avi_checksum();

	if (!st->hdcp_en)
		__s5p_hdmi_video_init_bluescreen(
				st->hdmi_video_blue_screen.enable,
				cb_b, y_g, cr_r);

	__s5p_hdmi_video_init_color_range(y_min, y_max, c_min, c_max);

	switch (out_mode) {

	case TVOUT_OUTPUT_HDMI_RGB:
	case TVOUT_OUTPUT_HDMI:
		cscType = HDMI_BYPASS;
		break;

	case TVOUT_OUTPUT_DVI:
		cscType = HDMI_CSC_YUV601_TO_RGB_LR;
		s_trans_type = HDMI_DO_NOT_TANS;
		break;

	default:
		TVOUTIFPRINTK("invalid out_mode parameter(%d)\n\r",
				out_mode);
		return false;
		break;
	}

	herr = __s5p_hdmi_video_init_csc(cscType);

	if (herr != HDMI_NO_ERROR)
		return false;


	herr =  __s5p_hdmi_video_init_avi_infoframe(*a_trans_type,
					*a_check_sum, a_data);

	if (herr != HDMI_NO_ERROR)
		return false;


	herr = __s5p_hdmi_video_init_mpg_infoframe(m_trans_type,
					m_check_sum, m_data);

	if (herr != HDMI_NO_ERROR)
		return false;


	herr = __s5p_hdmi_init_spd_infoframe(s_trans_type,
					spd_header, spd_data);

	if (herr != HDMI_NO_ERROR)
		return false;

	return true;
}