/*============================================================================*/
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;
}
Example #2
0
int usb_cable_in(void)
{
#if !CFG_FPGA_PLATFORM
    int exist = 0;
    CHARGER_TYPE ret;

    if ((g_boot_reason == BR_USB) || usb_accessory_in()) {
        ret = mt_charger_type_detection();
        if (ret == PMIC_STANDARD_HOST || ret == PMIC_CHARGING_HOST) {
            print("\n%s USB cable in\n", MOD);
            mt_usb_phy_poweron();
            mt_usb_phy_savecurrent();

            /* enable pmic hw charger detection */
            #if CFG_BATTERY_DETECT
            if (hw_check_battery())
                pl_hw_ulc_det();
            #endif

            exist = 1;
        } else if (ret == PMIC_NONSTANDARD_CHARGER || ret == PMIC_STANDARD_CHARGER) {
            #if CFG_USBIF_COMPLIANCE
            platform_set_chrg_cur(450);
            #endif
        }
    }
    return exist;
#else
    mt_usb_phy_poweron();
    mt_usb_phy_savecurrent();
    return 1;
#endif
}
/*============================================================================*/
bool usb_handshake(struct bldr_command_handler *handler)
{
    uint32 enum_tmo = CFG_USB_ENUM_TIMEOUT_EN ? USB_ENUM_TIMEOUT : 0;
    uint32 handshake_tmo = CFG_USB_HANDSHAKE_TIMEOUT_EN ? USB_SYNC_TIME : 0;
    bool result = FALSE;
    bool force_download = FALSE;

    platform_vusb_on();

    force_download = platform_com_wait_forever_check();

    if (TRUE == force_download) {
        enum_tmo = 0;
        handshake_tmo = 0;
    } else if (!usb_cable_in()) {
        return FALSE;
    }
    
    print("%s USB enum timeout (%s), handshake timeout(%s)\n", MOD, 
        enum_tmo ? "Yes" : "No", 
        handshake_tmo ? "Yes" : "No");
    
    usbdl_init();
    udelay(1000);
    usb_disconnect();

    if (usb_connect(enum_tmo) == FALSE) {
        print("%s USB enum timeout!\n", MOD);
        goto end;
    }

    udelay(1000);
    if (FALSE == usb_handshake_handler(handler, handshake_tmo)) {    
        goto end;
    }

    result = TRUE;

    if (FALSE == usb_port_down(USB_PORT_DOWN_TIME)) {
        print("%s USB port down timeout!\n", MOD);
    }

end:
    usb_service_offline();

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

    return result;
}
Example #4
0
int usb_accessory_in(void)
{
#if !CFG_FPGA_PLATFORM
    int exist = 0;

    if (PMIC_CHRDET_EXIST == pmic_IsUsbCableIn()) {
        exist = 1;
        #if !CFG_USBIF_COMPLIANCE
        /* enable charging current as early as possible to avoid can't enter 
         * following battery charging flow when low battery
         */
        platform_set_chrg_cur(450);
        #endif
    }
    return exist;
#else
    return 1;
#endif
}