コード例 #1
0
ファイル: cmd_fastboot.c プロジェクト: al177/kf_u-boot
int do_fastboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	int ret = 1;
	unsigned long val;
	/* Initialize the board specific support */
	if (0 == fastboot_init(&interface))
	{
		printf ("Fastboot entered...\n");
		run_command("setgreenled 50", 0);
		fastboot_countdown = CFG_FASTBOOT_COUNTDOWN;
		/* If we got this far, we are a success */
		ret = 0;
		val = getbootmode();
		/* On disconnect or error, polling returns non zero */
		/* Always delay for fastboot unless we're in bootmode 4002 
		 * or using the "factory" cable */
		if((0x4002 != val) && !(__raw_readl(0x48055138) & 0x00100000)){
			while (fastboot_countdown)
			{
	            if (!fastboot_confirmed) {
                   fastboot_countdown--;
                }
				if (fastboot_poll())
					break;
				/* if we're holding down the button to get into
				 * recovery, don't wait for the fastboot timeout so we don't
				 * accidentally power off.  short circuit 49999/50000 times
				 * through to keep from overwhelming the twl6030 */

				if (!(fastboot_countdown % 50000) &&
						(0 == twl6030_get_power_button_status())) {
					fastboot_wait_power_button_abort = 1;
					break;
				}
			}
		}else{
			while (1)
			{
				if (fastboot_poll())
					break;
			}
		}
	}

	/* Reset the board specific support */
	fastboot_shutdown();
	/* If we're in 4003, go on to OMAP boot over USB */
	if(0x4003 == val){
        printf ("setting boot sequence first to USB.\nreboot...\n");
        set_SWBootingCfg();		
	}
	return ret;
}
コード例 #2
0
ファイル: smb347.c プロジェクト: fat-tire/u-boot-otter2
/*
It is a 0.5 sec loop.
work_index	second	function
0		0	voltage,capacity
1		0.5	power_button
2		1	vbus
3		1.5	power_button
4		2	temperature
5		2.5	power_button
6		3	vbus
7		3.5	power_button
8		4	current
9		4.5	power_button
*/
static int low_bat_charge()
{
	u16 v = 0, cap = 0;
	s16 t = 0, c = 0;
    int result=0;
    int voltage=0;
    int current=0;
    int temperature=0;
    int vbus=0;
    int ms=0;
    int sec=0;
    int value=0;
    int capacity=0;
    int show_low_bat=0;
    int show_low_bat_ptw=0;
    int power_button=0;
    int work_index=0;
    while(result==0){
        work_index=sec%10;
        //printf("sec=%d work_index=%d\n",sec,work_index);
        switch(work_index){
            case 0:
		bq27541_voltage(&v);
		voltage = v;
		bq27541_capacity(&cap);
		capacity = cap;
                if((voltage >= LOW_BATTERY_VOLTAGE_LIMIT) && (capacity >= LOW_BATTERY_CAPACITY_LIMIT)){
                    result=1;
                    break;
                }
                if( show_low_bat==1){ 
                    show_low_bat=2;
                    turn_off_lcd();
                 
                }
                if((voltage > LOW_LCD_VOLTAGE_LIMIT) && (show_low_bat==0)){
                   show_low_bat=1;
                   initialize_lcd(OTTER_LCD_DISPLAY_LOW_BATT_SCREEN);
                }
                printf("Battery voltage=%d capacity=%d \n",voltage,capacity);
                break;
            case 4:
		bq27541_temperature(&t);
		temperature = t;
                //printf("Battery temperature=%d\n",temperature);
                if( (temperature>TEMPERATURE_HOT_LIMIT) || (temperature<TEMPERATURE_COLD_LIMIT)){
                     printf("shutdown due to temperature protect %d\n",temperature);
                     twl6030_shutdown();
                }
                break;
            case 8:
		bq27541_current(&c);
		current = c;
                printf("Battery current=%d\n",current);
        	/*
	 	 * Shutdown if there is drain current, and we've displayed the LCD
	 	 * and shut it down after 10 seconds
	 	 */
                if(current<0 && (show_low_bat<1 || show_low_bat>15)){
                    printf("shutdown due to there is discharge %d mA\n",current);
                    twl6030_shutdown();
                }
                smb347_i2c_read_u8(&value,SUMMIT_SMB347_INTSTAT_REG_D);
                if((PC_TIMEOUT_STATUS & value) || (COMPLETE_CHARGE_TIMEOUT_STATUS & value)){
					printf("shutdown due to the charge time out\n");
					twl6030_shutdown();
                }
                break;
            case 2:
            case 6:
                vbus=twl6030_get_vbus_status();
                //printf("vbus=%d\n",vbus);
                if(vbus==0){
                    printf("shutdown due to there is no VBUS\n");
                    twl6030_shutdown();
                }
                break;
            default :
                power_button=twl6030_get_power_button_status(); 
                if( (power_button ==0 )&& (voltage > LOW_LCD_VOLTAGE_LIMIT) && (show_low_bat==2)&& (show_low_bat_ptw==0)){
                    show_low_bat_ptw=1;
                    initialize_lcd(OTTER_LCD_DISPLAY_LOW_BATT_CHARGING_SCREEN);
                }
                if((power_button ==1)&& (show_low_bat_ptw==1)){
                    show_low_bat_ptw=0;
                    turn_off_lcd();           
                }
                break;
        }
        //delay 0.5s
        sec++;
        mdelay(200);
    }
    //check vbus again
    vbus=twl6030_get_vbus_status();
    if((vbus==0)){
        run_command("setgreenled ff", 0);
        run_command("setamberled 0", 0);
    }
    return result;
}