Example #1
0
static void zeus_poweroff(void)
{
	/* int n_usbic_state; */

	printk("\nZEUS BOARD GOING TO SHUTDOWN!!!\n");

#if defined(CONFIG_USB_ANDROID)
	android_usb_set_connected(0);
#endif
        tl2796_lcd_poweroff();
	/* get_real_usbic_state(); */
	//gpio_direction_output(GPIO_MSM_RST,0);
	//gpio_direction_output(GPIO_FONE_ACTIVE, 0);
	// if (GPIO_TA_CONNECTED_N is LOW)
//#if (CONFIG_ARCHER_REV < ARCHER_REV13)
//	if ( get_real_usbic_state() )
         if ( sec_switch_get_cable_status() != CABLE_TYPE_NONE ) //me add
//#else
//	if ( !gpio_get_value( OMAP_GPIO_TA_NCONNECTED ) || gpio_get_value( OMAP_GPIO_IF_CON_SENSE ) )
//#endif
	{
		printk("Warmreset by TA or USB or Jtag\n\n");

		preempt_disable();
		local_irq_disable();
		local_fiq_disable();

#ifdef CONFIG_ARCHER_KOR_DEBUG
		omap_writel(0x54455352, OMAP343X_CTRL_BASE + 0x9C4); // set to normal reset
#endif
#if 1

		/* using watchdog reset */
		omap_watchdog_reset();
		/* machine_restart("ta_inserted"); */
#else
		/* using core_dpll_warmreset with global reset */
		//omap3_configure_core_dpll_warmreset();
		machine_restart("ta_inserted");
#endif

		while(1);
	}
	else
	{
		printk("Power Off !\n\n");
		while(1)
		{
			gpio_direction_output(GPIO_PS_HOLD, 0);

			if (0 /*is_powerbutton_pressed*/)
				printk("Power button is pressed\n\n");
			else
				twl4030_poweroff();
		}
	}

	return;
}
Example #2
0
void off_mode_charging( void )
{
	int bootup_reason = BOOTUP_UNKNOWN;
#if CONFIG_MAX17043_GAUGE
	union power_supply_propval BatteryVol = {0,};
	union power_supply_propval BatteryCap = {0,};
	int model_count = 0;
#elif CONFIG_TWL4030_MADC_VBAT
	int BatteryCap = 0, BatteryVol = 0;
#endif

#ifdef CONFIG_DISCHARGING_EXPERIMENTATION
	int quick_once = 1;
#endif

#if CONFIG_MAX17043_GAUGE
	select_bus(1, 100);	
	off_mode_charging_info.write_model_false = max17043_write_custom_model();
	mdelay(500);
	//#ifndef CONFIG_DISCHARGING_EXPERIMENTATION
	//if(!off_mode_charging_info.write_model_false)
	//{
		//max17043_quick_start();
		//mdelay(1000);	
	//}
	//#endif
#elif CONFIG_TWL4030_MADC_VBAT
	twl4030_vadc_onoff(1);
	twl4030_madc_init();
#endif

	bootup_reason = off_mode_charging_info.bootup_reason;
	
	while (1)
	{
#if CONFIG_MAX17043_GAUGE
		// select I2C2
		select_bus(1, 100);	
		ds278x_battery_get_property(POWER_SUPPLY_PROP_VOLTAGE_NOW, &BatteryVol);
		ds278x_battery_get_property(POWER_SUPPLY_PROP_CAPACITY, &BatteryCap);
		if (off_mode_charging_info.write_model_false)
		{
			model_count++;
			if ((model_count%2) == 0)
			{
				off_mode_charging_info.write_model_false = off_mode_custom_model_retry();
			}
		}
#elif CONFIG_TWL4030_MADC_VBAT
		BatteryVol = twl4030_get_battery_voltage();
		printf("**** Off Mode Charging(from MADC) *****\n");
		printf("****      VOLTAGE: %d   ********\n", BatteryVol);
		printf("****  End Of Off Mode Charging  ****\n");
#endif
		//mdelay(1000);
		// select I2C1
		select_bus(0, 100);		

		off_mode_charging_info.cable_exist = dc_ok_detect();
		#ifdef CONFIG_DISCHARGING_EXPERIMENTATION
		off_mode_charging_info.cable_exist = 0;
		#endif

		if ((twl4030_bootup_reason_get() & BOOTUP_POWER_KEY) || (bootup_reason & BOOTUP_POWER_KEY))
		{

//&*&*&*HC1_20110503, Adjust long press time (ref. bsp spec v0.6)
//&*&*&*HC1_20110428, enable pwr key long press function 
#if CONFIG_PWRKEY_LONGPRESS
			if ((bootup_reason != BOOTUP_POWER_KEY) && (!pwrkey_press_check(PWRKEY_PRESS_TIME_CHARGING, bootup_reason)))
			{
				bootup_reason = BOOTUP_UNKNOWN;
				continue;		
			}
#endif // CONFIG_PWRKEY_LONGPRESS			
//&*&*&*HC2_20110428, enable pwr key long press function 
//&*&*&*HC2_20110503, Adjust long press time (ref. bsp spec v0.6)

#if (defined(CONFIG_TWL4030_MADC_VBAT) || defined(CONFIG_MAX17043_GAUGE))
			//&*&*&*AL1_20110528, different voltage between cable exist and not.
			
#if CONFIG_MAX17043_GAUGE
			if((BatteryVol.intval < POWER_ON_VOLTAGE_NO_CABLE) && (off_mode_charging_info.cable_exist == 1))
			{
				bootup_reason = BOOTUP_UNKNOWN;
				#if CONFIG_KEY_LIGHT_NOTIFICATION
				key_light_flash(3);
				#endif // CONFIG_KEY_LIGHT_NOTIFICATION
				printf("Battery voltage < 3.5V with no cable, can't boot up !!!\n");
			}	
			else if((off_mode_charging_info.CableInType == CABLE_AC) && (off_mode_charging_info.cable_exist == 0))
			{
				if(BatteryVol.intval < POWER_ON_VOLTAGE_WITH_AC_CABLE)
				{
					bootup_reason = BOOTUP_UNKNOWN;
					#if CONFIG_KEY_LIGHT_NOTIFICATION
					key_light_flash(3);
					#endif // CONFIG_KEY_LIGHT_NOTIFICATION
					printf("Battery voltage < 3.3V with AC cable, can't boot up !!!\n");
				}
				else
					break;
			}
			else if((off_mode_charging_info.CableInType == CABLE_USB) && (off_mode_charging_info.cable_exist == 0))
			{
				if(BatteryVol.intval < POWER_ON_VOLTAGE_WITH_USB_CABLE)
				{
					bootup_reason = BOOTUP_UNKNOWN;
					#if CONFIG_KEY_LIGHT_NOTIFICATION
					key_light_flash(3);
					#endif // CONFIG_KEY_LIGHT_NOTIFICATION
					printf("Battery voltage < 3.5V with USB cable, can't boot up !!!\n");
				}
				else
					break;
			}
			//&*&*&*AL2_20110528, different voltage between cable exist and not.
#elif CONFIG_TWL4030_MADC_VBAT
			if(BatteryVol < POWER_ON_VOLTAGE)
			{
				bootup_reason = BOOTUP_UNKNOWN;
				printf("Battery voltage < 3.6V with no cable, can't boot up !!!\n");
			}	
#endif
			else
			{
				#if CONFIG_KEY_LIGHT_NOTIFICATION
				 // power on, keep key light on
				key_light_flash(0);
				#endif // CONFIG_KEY_LIGHT_NOTIFICATION
				break;
			}	
#else
			printf("No battery voltage checking implementation! !!\n");
			break;
#endif
//&*&*&*HC2_20110103, enable the battery check
//&*&*&*HC2_20101230, disable the battery check
		}
		if(off_mode_charging_info.cable_exist == 1)
		{
			printf("Not a vaild long press !!! Please press and hold pwr key more than 1 sec.\n");
			twl4030_poweroff();
			break;
		}
		else
		{

			if (off_mode_charging_info.CableInType == CABLE_UNKNOW)
			{
				off_mode_charging_info.CableInType = twl4030_get_cable_type();
				if(off_mode_charging_info.CableInType == USB_EVENT_VBUS)
				{
					off_mode_charging_info.CableInType = CABLE_USB;
					printf("\n **** USB Cable: Start 500mA**** \n");
				}
				else
				{
					off_mode_charging_info.CableInType = CABLE_AC;
					printf("\n **** AC Cable: Start 1500mA**** \n");
				}
				
				#if CONFIG_CHARGING_REDUCE_SYS_LOAD
				pre_charging_configure();			
				change_cpu_freq(0);
				change_mem_freq(0);		
				off_mode_charging_info.enter_reduce_frequencce = 1;
				#endif //CHARGING_REDUCE_SYS_LOAD
			}
			if(off_mode_charging_info.CableInType == CABLE_AC)
				charging_mode(CHARGING_START_1000MA);
			else
				charging_mode(CHARGING_START_500MA);
		}

		#ifdef CONFIG_MAX17043_DEBUG_MESSAGE_FORMAT
		select_bus(1, 100);
		max1704x_register_dump();
		mdelay(5000);
		#endif

		mdelay(1000);

		// control charging LED
		off_mode_charging_info.is_charging_complete = chg_status_detect();
		charging_led_notification(off_mode_charging_info.is_charging_complete, BatteryCap.intval);
		off_mode_charging_info.charging_fault = chg_fault_detect();

		/* wait for redeuce frequence to get accurate capacity */
		#ifdef CONFIG_DISCHARGING_EXPERIMENTATION
		if(!off_mode_charging_info.write_model_false && quick_once)
		{
			select_bus(1, 100);
			max17043_quick_start();
			mdelay(1000);	
			quick_once = 0;
		}
		//if(BatteryCap.intval == 2)
		//{
			//select_bus(0, 100);
			//twl4030_poweroff();
			//break;
		//}
		#endif

		if(off_mode_charging_info.charging_fault == 0)
		{
			printf("\n **** charging_fault:%d, charging time out, re-toggle CEN pin.***** \n", off_mode_charging_info.charging_fault);
			charging_mode(CHARGING_STOP);
		}
		
		printf("\n");
	}	
}
Example #3
0
int off_mode_start( void )
{
	printf(" +++ off_mode_start +++\n");
	int bootup_reason;

	off_mode_charging_info.battery_info = g_BatteryID;
	printf(" #### Battery ID: %d ####\n", off_mode_charging_info.battery_info);
	off_mode_charging_info.bootup_reason = twl4030_bootup_reason_get();
	bootup_reason = off_mode_charging_info.bootup_reason;
	
	if (bootup_reason == BOOTUP_8S_OFF)
	{
		printf("[pwr key 8s]:  ");
		bootup_reason = BOOTUP_POWER_KEY;
	}
	else if (bootup_reason == BOOTUP_8S_OFF_CABLE)
	{
		printf("[pwr key 8s + cable]:  ");
		bootup_reason = BOOTUP_CABLE_IN;		
	}
//&*&*&*HC1_20110727, Add rtc bootup check 		
	else if (bootup_reason == BOOTUP_8S_OFF_RTC)
	{
		printf("[pwr key 8s + rtc]:  ");
		bootup_reason = BOOTUP_RTC;		
	}
//&*&*&*HC2_20110727, Add rtc bootup check 	
	
	// select I2C0
	select_bus(0, 100);

	if (bootup_reason & BOOTUP_POWER_KEY)
	{
		printf("power key detect...\n");		
		
//&*&*&*HC1_20110503, Adjust long press time (ref. bsp spec v0.6)		
//&*&*&*HC1_20110428, enable pwr key long press function 
#if CONFIG_PWRKEY_LONGPRESS
		if (pwrkey_press_check(PWRKEY_PRESS_TIME_STARTUP, bootup_reason))
			bootup_reason = BOOTUP_POWER_KEY;
		else
			bootup_reason = BOOTUP_UNKNOWN;
#endif // #if CONFIG_PWRKEY_LONGPRESS		
//&*&*&*HC2_20110428, enable pwr key long press function 
//&*&*&*HC2_20110503, Adjust long press time (ref. bsp spec v0.6)
		off_mode_charging_info.bootup_reason  = bootup_reason;
		off_mode_charging();
	}
	else if (bootup_reason &  BOOTUP_CABLE_IN)
	{
		printf("cable detect...\n");
		off_mode_charging_info.bootup_reason  = bootup_reason;
		off_mode_charging();
	}
	else if (bootup_reason & BOOTUP_BATTERY_DETECT)
	{
		printf("battery detect...\n");
		#ifdef CONFIG_DISCHARGING_EXPERIMENTATION
		off_mode_charging();
		#else
		twl4030_poweroff();
		#endif
	}
//&*&*&*HC1_20110727, Add rtc bootup check 		
	else if (bootup_reason & BOOTUP_RTC)
	{
		printf("rtc alarm...\n");
		twl4030_alarm_it_enable(0);
		twl4030_poweroff();
	}
//&*&*&*HC2_20110727, Add rtc bootup check 			
	else
	{
//&*&*&*HC1_20110221, let reboot pass the check 	
		printf("reboot ...\n");		
//&*&*&*HC2_20110221, let reboot pass the check 			
	}

#if CONFIG_CHARGING_REDUCE_SYS_LOAD
	//if (bootup_reason &  BOOTUP_CABLE_IN)
	if(off_mode_charging_info.enter_reduce_frequencce)
	{
		change_mem_freq(1);
		change_cpu_freq(1);
		post_charging_configure();
	}
	printf("end of uBoot boot_reason :%d...\n", bootup_reason);	
#endif //CHARGING_REDUCE_SYS_LOAD	
	return 0;

}
Example #4
0
static void board_poweroff(void)
{
	/* int n_usbic_state; */
#if ( defined( CONFIG_MACH_SAMSUNG_P1WIFI ) )
	u8 hwsts = 0;
	u8 vbus_val = 0;

	twl_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &hwsts, 0x0F /*REG_STS_HW_CONDITIONS*/);

	if(hwsts & 0x80)  // STS_VBUS		0x80
		vbus_val = 1;
	else
		vbus_val = 0;
#endif

	printk("\nPower off routine - Board Shutdown!! \n");

/*
#if defined(CONFIG_USB_ANDROID)
	android_usb_set_connected(0);
#endif
*/

	/* get_real_usbic_state(); */
	//gpio_direction_output(GPIO_MSM_RST,0);
	//gpio_direction_output(GPIO_FONE_ACTIVE, 0);
	// if (GPIO_TA_CONNECTED_N is LOW)
#if ( defined( CONFIG_MACH_SAMSUNG_LATONA ) ) // jypark72, to avoid build error
	if ( !gpio_get_value( OMAP_GPIO_TA_NCONNECTED ) || gpio_get_value( OMAP_GPIO_JIG_ON18 ) )
#elif ( defined( CONFIG_MACH_SAMSUNG_P1WIFI ) )
	if (vbus_val || gpio_get_value( OMAP_GPIO_JIG_ON18 ) )
#endif
	{
		printk("Warmreset by TA or USB or Jtag - check 2 pins : JIG_ON18, TA_nConnected \n\n");

		preempt_disable();
		local_irq_disable();
		local_fiq_disable();

#ifdef CONFIG_SAMSUNG_KERNEL_DEBUG
		omap_writel(0x54455352, OMAP343X_CTRL_BASE + 0x9C4); // set to normal reset
#endif

#if 1
		/* using watchdog reset */
		omap_watchdog_reset();
		//machine_restart("ta_inserted");
#else
		/* using core_dpll_warmreset with global reset */
		//omap3_configure_core_dpll_warmreset();
		machine_restart("ta_inserted");
#endif

		while(1);
	}
	else
	{
		while(1)
		{
			if (gpio_get_value(OMAP_GPIO_KEY_PWRON)) {
				printk("Power button is pressed\n\n");
			}
			else {
				printk("Power Off !\n\n");
				gpio_set_value( OMAP_GPIO_PS_HOLD_PU, 0 ); 
				twl4030_poweroff();
				//for(;;);
			}
		}
	}
	return;
}