/*============================================================================*/
static bool usb_connect(u32 tmo)
{
    ulong start_time = get_timer(0);
    bool result = FALSE;
    u32 i = 1;

    mt_usb_disconnect_internal();
    mt_usb_connect_internal();

#if CFG_USBIF_COMPLIANCE
    /* USB compliance test: 100mA charging current when USB is unconfigured. */
    platform_set_chrg_cur(70);
#endif

    print("%s Enumeration(Start)\n", MOD);

    do {
        /* kick wdt to avoid cpu reset during usb driver installation if not present */
        platform_wdt_all_kick();
        service_interrupts();

        if (usbdl_configured()) {
            #if CFG_USBIF_COMPLIANCE
            /* USB compliance test: 500mA charging current when USB is configured but
             * we set the charging current to 450mA since 500mA doesn't support in the
             * platform.
             */
            platform_set_chrg_cur(450);
            #endif
            result = TRUE;
            break;
        }
        
        if (tmo) {
            /* enable timeout mechanism */
            if (get_timer(start_time) > tmo)
                break;
            #if !CFG_FPGA_PLATFORM
            /* cable plugged-out and power key detection each 1 second */
            if (get_timer(start_time) > i * 1000) {
                if (!usb_accessory_in() && !mt_detect_powerkey())
                    pl_power_off();
                /* check bypass power key from the 2nd second */
                if (i > 1 && mt_detect_powerkey()) {
                    print("%s Enumeration(Skip): powerkey pressed\n", MOD);                
                    break;
                }
                i++;
            }
            #endif
        }
    } while(1);

    print("%s Enumeration(End): %s %dms \n", MOD, result == TRUE ? "OK" : "TMO",
        get_timer(start_time));
    
    return result;
}
/**************************************************************************
*  Reboot State
**************************************************************************/
void handle_reboot (void)
{
    // check if device Is ready to use
    g_boot_dev.dev_wait_ready ();
    DM_TIME_TOTAL_END;
#if DM_TIME_ANALYSIS
    dump_time_analysis ();
#endif
    mt_usb_disconnect_internal();
    do_reboot (0);
}
static void usb_disconnect(void)
{
    mt_usb_disconnect_internal();
}