/*****************************************
 * Routine: board_init
 * Description: Early hardware init.
 *****************************************/
int board_init (void)
{
    /*Warning: DO NOT use "printf" before serial initialize*/
#ifdef CFG_UBOOT_PROFILING
    unsigned int time_disp_init;
    unsigned int time_led_init;
    unsigned int time_pmic6329_init;
    unsigned int time_gpio_init;
    unsigned int time_wdt_init;
    unsigned int time_serial_init;
#endif

    mtk_serial_init();

    mtk_wdt_init(); // Modify mtk_wdt.h can select dummy function.
    mt6577_pinmux_init();
    gd->bd->bi_arch_number = MACH_TYPE_MT6577;	/* board id for linux */
    gd->bd->bi_boot_params = CFG_BOOTARGS_ADDR; /* address of boot parameters */


    gd->fb_base = memory_size() - mt65xx_disp_get_vram_size();

#ifdef CFG_UBOOT_PROFILING
    time_led_init = get_timer(0);
#endif
    leds_init();
    isink0_init(); //turn on isink0, HW connection must be floating or pull low
#ifdef CFG_UBOOT_PROFILING
    printf("[PROFILE] ------- led init takes %d ms -------- \n", get_timer(time_led_init));
#endif

#ifdef CFG_LCD
#ifdef CFG_UBOOT_PROFILING
    time_disp_init = get_timer(0);
#endif
    mt65xx_disp_init((void*)gd->fb_base);
    UBOOT_TRACER;
#ifdef CFG_UBOOT_PROFILING
    printf("[PROFILE] ------- disp init takes %d ms -------- \n", get_timer(time_disp_init));
#endif
#endif



#ifdef CFG_UBOOT_PROFILING
    time_pmic6329_init = get_timer(0);
#endif

    pmic6329_init();

#ifdef CFG_UBOOT_PROFILING
    printf("[PROFILE] ------- pmic6329_init takes %d ms -------- \n", get_timer(time_pmic6329_init));
#endif

    printf("[CHIP]: %x-%x\n", get_chip_eco_ver(), get_chip_ver());
    return 0;
}
void platform_early_init(void)
{
#ifdef LK_PROFILING
    unsigned int time_led_init;
    unsigned int time_pmic6329_init;
    unsigned int time_i2c_init;
    unsigned int time_disp_init;
    unsigned int time_platform_early_init;
    time_platform_early_init = get_timer(0);
#endif
    /* initialize the uart */
    uart_init_early();

    /* initialize the frame buffet information */
    g_fb_size = mt_disp_get_vram_size();
    g_fb_base = memory_size() - g_fb_size;
    dprintf(INFO, "FB base = 0x%x, FB size = %d\n", g_fb_base, g_fb_size);

    platform_init_interrupts();
    platform_early_init_timer();
    mt_gpio_set_default();
#ifdef LK_PROFILING
    time_i2c_init = get_timer(0);
#endif
//    i2c_v1_init();
#ifdef LK_PROFILING
    printf("[PROFILE] ------- i2c init takes %d ms -------- \n", get_timer(time_i2c_init));
#endif

    mtk_wdt_init();
#ifdef LK_PROFILING
    time_led_init = get_timer(0);
#endif
    leds_init();
#ifdef LK_PROFILING
      printf("[PROFILE] ------- led init takes %d ms -------- \n", get_timer(time_led_init));
#endif

    isink0_init();              //turn on PMIC6329 isink0
#ifdef LK_PROFILING
    time_disp_init = get_timer(0);
#endif
    mt_disp_init((void *)g_fb_base);
#ifdef LK_PROFILING
    printf("[PROFILE] ------- disp init takes %d ms -------- \n", get_timer(time_disp_init));
#endif

#ifdef CONFIG_CFB_CONSOLE
    drv_video_init();
#endif

#ifdef LK_PROFILING
    time_pmic6329_init = get_timer(0);
#endif
    pmic6329_init();

	//<2013/01/03-samhuang, improve KPI-0092 to add VIB before show logo.
	lk_vibr_enable();
	//>2013/01/03-samhuang

#ifdef LK_PROFILING
    printf("[PROFILE] ------- pmic6329_init takes %d ms -------- \n", get_timer(time_pmic6329_init));
    printf("[PROFILE] ------- platform_early_init takes %d ms -------- \n", get_timer(time_platform_early_init));
#endif
}