/**************************************************************************
 *               F U N C T I O N    D E C L A R A T I O N S               *
 **************************************************************************/
static int32_t
tpo_td070wgcb2_init(
    void
)
{
    int32_t real_freq = 0;

    printk("[%s:%d]\n", __FUNCTION__, __LINE__);

    g_pin_func_handle = gp_board_pin_func_request(GP_PIN_DISP0_LCD, GP_BOARD_WAIT_FOREVER);
    if (g_pin_func_handle < 0) {
        printk("[%s:%d] Error!\n", __FUNCTION__, __LINE__);
        return -1;
    }

    /* initial panel parameter */
    gpHalDispSetDevType(HAL_DISP_DEV_LCD);

    // config lcd clock 33 MHz
    // set lcd source : SPLL
    gpHalClkLcdSetSrc(HAL_LCD_CLK_SPLL);
    // Set lcd clock rate, must enable before lcd clk on
    gp_clk_set_rate("clk_lcd", gPanelInfo.workFreq, &real_freq, NULL);	// must enable before lcd clk on
    printk("[%s][%d] LCD CLOCK=%d Hz\n",__FUNCTION__, __LINE__, real_freq);

    gpHalDispSetClkType(gPanelInfo.clkType);

    // enable lcd clock
#ifdef CONFIG_PM
    gp_enable_clock((int*)"READLTIME_ABT", 1);
#endif
    gpHalLcdClkEnable(1);

    gpHalDispSetRes(gPanelInfo.width, gPanelInfo.height);
    gpHalDispSetLcdVsync(gPanelInfo.vsync);
    gpHalDispSetLcdHsync(gPanelInfo.hsync);
    gpHalDispSetPanelFormat(gPanelInfo.format, gPanelInfo.type, gPanelInfo.dataSeqEven, gPanelInfo.dataSeqOdd);
    gpHalDispSetClkPolarity(gPanelInfo.clkPolatiry);

    gpHalDispSetPriDmaType(gPanelInfo.dmaType);
    gpHalDispSetOsdDmaType(0, gPanelInfo.dmaType);
    gpHalDispSetOsdDmaType(1, gPanelInfo.dmaType);

    return 0;
}
static int32_t
auo_a043fl01_resume_init(
	void
)
{
	int32_t real_freq = 0;
	
	/* initial panel parameter */
	gpHalDispSetDevType(HAL_DISP_DEV_LCD);

	// set lcd source : XTAL(27MHZ)
	gpHalClkLcdSetSrc(HAL_LCD_CLK_XTAL);
	// Set lcd clock rate to 9 MHz, must enable before lcd clk on
	gp_clk_set_rate("clk_lcd", gPanelInfo.workFreq, &real_freq, NULL);
	printk("[%s][%d] LCD CLOCK=%d Hz\n",__FUNCTION__, __LINE__, real_freq);

	gpHalDispSetClkType(gPanelInfo.clkType);

	// enable lcd clock
#ifdef CONFIG_PM
	gp_enable_clock((int*)"READLTIME_ABT", 1);
#endif
	gpHalLcdClkEnable(1);

	gpHalDispSetRes(gPanelInfo.width, gPanelInfo.height);
	gpHalDispSetLcdVsync(gPanelInfo.vsync);
	gpHalDispSetLcdHsync(gPanelInfo.hsync);
	gpHalDispSetPanelFormat(gPanelInfo.format, gPanelInfo.type, gPanelInfo.dataSeqEven, gPanelInfo.dataSeqOdd);
	gpHalDispSetClkPolarity(gPanelInfo.clkPolatiry);

	gpHalDispSetPriDmaType(gPanelInfo.dmaType);
	gpHalDispSetOsdDmaType(0, gPanelInfo.dmaType);
	gpHalDispSetOsdDmaType(1, gPanelInfo.dmaType);

	return 0;
}
static int32_t
lcd_resume(
	void
)
{
	int32_t real_freq = 0;
	gp_board_panel_t *lcd_power;
	int handle;
	gpio_content_t ctx;

	printk("[%s:%d]\n", __FUNCTION__, __LINE__);

	lcd_power = gp_board_get_config("panel", gp_board_panel_t);

	gpHalDispSetDevType(HAL_DISP_DEV_LCD);

	// set lcd source : XTAL(27MHZ)
	gpHalClkLcdSetSrc(HAL_LCD_CLK_XTAL);
	// Set lcd clock rate, must enable before lcd clk on
	gp_clk_set_rate("clk_lcd", gPanelInfo.workFreq, &real_freq, NULL);	

	gpHalDispSetClkType(gPanelInfo.clkType);

#ifdef CONFIG_PM
	gp_enable_clock((int*)"READLTIME_ABT", 1);
#endif
	gpHalLcdClkEnable(1);		

	gpHalDispSetRes(gPanelInfo.width, gPanelInfo.height);
	gpHalDispSetLcdVsync(gPanelInfo.vsync);
	gpHalDispSetLcdHsync(gPanelInfo.hsync);
	gpHalDispSetPanelFormat(gPanelInfo.format, gPanelInfo.type, gPanelInfo.dataSeqEven, gPanelInfo.dataSeqOdd);
	gpHalDispSetClkPolarity(gPanelInfo.clkPolatiry);

	lcd_power->set_panelpowerOn0(1);		/* Power on VCC, VGL, AVDD, VGH */

	ctx.pin_index = MK_GPIO_INDEX( PCLK_channel, PCLK_func, PCLK_gid, PCLK_pin );
	handle = gp_gpio_request( ctx.pin_index, NULL );
	gp_gpio_set_function( handle, PCLK_func );	
	gp_gpio_release( handle );

	ctx.pin_index = MK_GPIO_INDEX( B_DATA_channel, B_DATA_func, B_DATA_gid, B_DATA_pin );
	handle = gp_gpio_request( ctx.pin_index, NULL );
	gp_gpio_set_function( handle, B_DATA_func );	
	gp_gpio_release( handle );

	ctx.pin_index = MK_GPIO_INDEX( G_DATA_channel, G_DATA_func, G_DATA_gid, G_DATA_pin );
	handle = gp_gpio_request( ctx.pin_index, NULL );
	gp_gpio_set_function( handle, G_DATA_func );	
	gp_gpio_release( handle );
	
	ctx.pin_index = MK_GPIO_INDEX( R_DATA_channel, R_DATA_func, R_DATA_gid, R_DATA_pin );
	handle = gp_gpio_request( ctx.pin_index, NULL );
	gp_gpio_set_function( handle, R_DATA_func );	
	gp_gpio_release( handle );

	lcd_power->set_panelpowerOn1(1);		/* Set LCD RESET to high */

	/* Set dither */
	disp_set_dither_type(gPanelInfo.ditherType);
	disp_set_dither_param(gPanelInfo.pDitherParam);
	disp_set_dither_enable(1);

	/* Set color matrix */
	disp_set_color_matrix(gPanelInfo.pColorMatrix);

	/* Set gamma table */
	disp_set_gamma_enable(0);
	disp_set_gamma_table(SP_DISP_GAMMA_R, (uint8_t*) gPanelInfo.pGammaTable[SP_DISP_GAMMA_R]);
	disp_set_gamma_table(SP_DISP_GAMMA_G, (uint8_t*) gPanelInfo.pGammaTable[SP_DISP_GAMMA_G]);
	disp_set_gamma_table(SP_DISP_GAMMA_B, (uint8_t*) gPanelInfo.pGammaTable[SP_DISP_GAMMA_B]);
	disp_set_gamma_enable(1);

	gpHalDispSetPriDmaType(gPanelInfo.dmaType);
	gpHalDispSetOsdDmaType(0, gPanelInfo.dmaType);
	gpHalDispSetOsdDmaType(1, gPanelInfo.dmaType);

	return 0;
}