// zhoulidong  add for lcm detect (start)
static unsigned int rgk_lcm_compare_id(void)
{
    int data[4] = {0,0,0,0};
    int res = 0;
    int rawdata = 0;
    int lcm_vol = 0;

#ifdef AUXADC_LCM_VOLTAGE_CHANNEL
    res = IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL,data,&rawdata);
    if(res < 0)

    {
    #ifdef BUILD_LK
    printf("[adc_uboot]: get data error\n");
    #endif
    return 0;

    }
#endif
    lcm_vol = data[0]*1000+data[1]*10;


    #ifdef BUILD_LK
    printf("@@@@@@@[adc_uboot]: lcm_vol= %d , file : %s, line : %d\n",lcm_vol, __FILE__, __LINE__);
    #endif

    if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE &&lcm_compare_id())
    {
    return 1;
    }

    return 0;

}
static void lcm_init(void)
{

lcm_compare_id();

#if defined(BUILD_LK)
	upmu_set_rg_vgp2_vosel(5);
	upmu_set_rg_vgp2_en(1);

	upmu_set_rg_vgp3_vosel(3);
	upmu_set_rg_vgp3_en(1);	
#else
	hwPowerOn(MT6323_POWER_LDO_VGP2, VOL_2800, "Lance_LCM");
 	hwPowerOn(MT6323_POWER_LDO_VGP3, VOL_1800, "Lance_LCM");
#endif
	MDELAY(50);

#ifdef BUILD_LK
	printf("MYCAT ILI9608 lk lcm_init\n");
#else
      printk("MYCAT ILI9608  kernel lcm_init\n");
#endif
    SET_RESET_PIN(1);
    MDELAY(1);
    SET_RESET_PIN(0);
    MDELAY(20);
    SET_RESET_PIN(1);
    MDELAY(120);
		push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
    //init_lcm_registers();
}
static void lcm_resume(void)
{
	//if(lcm_suspended==0) return;
	//lcm_suspended = 0;
		lcm_compare_id();
	lcm_init();
	
//	push_table(lcm_sleep_out_setting, sizeof(lcm_sleep_out_setting) / sizeof(struct LCM_setting_table), 1);
}
static void lcm_init(void)
{
#ifdef BUILD_LK
    lcm_compare_id();
#endif

    SET_RESET_PIN(1);
    SET_RESET_PIN(0);
    MDELAY(25);
    SET_RESET_PIN(1);
    MDELAY(50);

    init_lcm_registers();
}
static void lcm_init(void)
{
#ifdef BUILD_LK
		pmic_config_interface(0x0532,5,0x7,5);//add by libo for VGP2 POWER ON
		pmic_config_interface(0x050C,1,0x1,15);
#else
		hwPowerOn(MT6323_POWER_LDO_VGP2,VOL_2800,"LCM");
#endif
lcm_compare_id();
		MDELAY(100);
    SET_RESET_PIN(0);
    MDELAY(100);
    SET_RESET_PIN(1);
    MDELAY(120);
    init_lcm_registers();
    

}
static void lcm_suspend(void)
{
		unsigned int data_array[33];
		data_array[0] = 0x00280500; 	   //exit sleep mode 
		dsi_set_cmdq(&data_array, 1, 1); 
		MDELAY(200); 
		
		data_array[0] = 0x00100500; 	   //exit sleep mode 
		dsi_set_cmdq(&data_array, 1, 1); 
		MDELAY(100);		
	lcm_compare_id();
SET_RESET_PIN(1);
MDELAY(5);	
SET_RESET_PIN(0);	
MDELAY(20);	
SET_RESET_PIN(1);
MDELAY(150);	

//	push_table(lcm_sleep_in_setting, sizeof(lcm_sleep_in_setting) / sizeof(struct LCM_setting_table), 1);

}
static void lcm_init(void)
{
	unsigned int data_array[16];

    	lcm_compare_id();

//<2013/06/03-25639-stevenchen, [Pelican][drv] Add second source TCL LCM.
	lcm_id = mt_get_gpio_in(GPIO_LCM_ID_PIN);

	#ifdef BUILD_LK
       	printf("LCM_ID = %d \n", lcm_id);
	#endif
//>2013/06/03-25639-stevenchen	

//<2013/04/12-23801-stevenchen, [Pelican][drv] Implement esd recovery function.
//<<EricHsieh,2013/6/18,Bootup time tuning
	SET_RESET_PIN(1);
	SET_RESET_PIN(0);
	MDELAY(1);//1
	
	SET_RESET_PIN(1);
	MDELAY(10);    //20
//>>EricHsieh,2013/6/18,Bootup time tuning
//>2013/04/12-23801-stevenchen

#if 0
	init_lcm_registers();
#else
    //<2013/06/03-25639-stevenchen, [Pelican][drv] Add second source TCL LCM.
    if( lcm_id == 1 )
    {
	push_table(lcm_tcl_initialization_setting, sizeof(lcm_tcl_initialization_setting) / sizeof(struct LCM_setting_table), 1);
    }
    else
    {
	push_table(lcm_initialization_setting, sizeof(lcm_initialization_setting) / sizeof(struct LCM_setting_table), 1);
    }
    //>2013/06/03-25639-stevenchen
#endif
}
// zhoulidong  add for lcm detect (start)
static int rgk_lcm_compare_id(void)
{
	int data[4] = {0,0,0,0};
	int res = 0;
	int rawdata = 0;
	int lcm_vol = 0;


#ifdef AUXADC_LCM_VOLTAGE_CHANNEL
	res = IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL,data,&rawdata);
	if(res < 0)
	{ 
	#ifdef BUILD_LK
		printf("[adc_uboot]: get data error\n");
	#endif
		return 0;
	}
#endif

	lcm_vol = data[0]*1000+data[1]*10;

#ifdef BUILD_LK
	printf("sym j5010  [adc_uboot]: lcm_vol= %d\n",lcm_vol);
#else
	printk("sym j5010 [adc_uboot]: lcm_vol= %d\n",lcm_vol);
#endif
	if( lcm_compare_id())
	      ;
	else
		return 0;
	
	if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE) 
	{
		return 1;
	}
	else
		return 0;
}
static void lcm_init(void)
{
    unsigned int data_array[16];
    unsigned int id = 0;
    SET_RESET_PIN(1);
    SET_RESET_PIN(0);
    MDELAY(30);
    SET_RESET_PIN(1);
    MDELAY(120);

    id = lcm_compare_id();

#ifdef BUILD_LK
    printf("ILI9806C lk %s id=%d\n", __func__,id);
#else
    printk("ILI9806C kernel %s id=%d\n", __func__,id);
#endif

    if(0 == id)
        push_table(lcm_initialization_setting_TN, sizeof(lcm_initialization_setting_TN) / sizeof(struct LCM_setting_table), 1);
    else
        push_table(lcm_initialization_setting_IPS, sizeof(lcm_initialization_setting_IPS) / sizeof(struct LCM_setting_table), 1);
}
// zhoulidong  add for lcm detect (start)
static unsigned int rgk_lcm_compare_id(void)
{
    int data[4] = {0,0,0,0};
    int res = 0;
    int rawdata = 0;
    int lcm_vol = 0;

#ifdef AUXADC_LCM_VOLTAGE_CHANNEL
    res = IMM_GetOneChannelValue(AUXADC_LCM_VOLTAGE_CHANNEL,data,&rawdata);
    if(res < 0)
    {
    #ifdef BUILD_LK
    printf("[adc_uboot]: get data error\n");
    #endif
    return 0;

    }
#endif
    lcm_vol = data[0]*1000+data[1]*10;


    #ifdef BUILD_LK
    printf("[adc_uboot]: lcm_vol= %d\n",lcm_vol);
    #endif
#if 0
    if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE &&lcm_compare_id())
#else
    if (lcm_vol>=MIN_VOLTAGE &&lcm_vol <= MAX_VOLTAGE)  // remove compare_id func for mt6582 temply by xiaoanxiang 2013-09-05
#endif
    {
    return 1;
    }

    return 0;

}