Ejemplo n.º 1
0
int off_mode_custom_model_retry(void)
{
	union power_supply_propval BatteryVol = {0,};
	int ret = 0;

	printf("\n S off_mode_custom_model_retry\n");

	charging_mode(CHARGING_STOP);
	mdelay(2000);
	ds278x_battery_get_property(POWER_SUPPLY_PROP_VOLTAGE_NOW, &BatteryVol);

	if (BatteryVol.intval != 1)
	{
		ret = max17043_write_custom_model();
		mdelay(500);	
		max17043_quick_start();
		mdelay(1000);
	}
	else
		ret = 1;

	printf("\n E off_mode_custom_model_retry, ret=%d\n", ret);

	return ret;	
}
Ejemplo n.º 2
0
void charging(i_charger *ic)
{

    ic->voltage = adc_V();
    ic->current = adc_A();
	
	charging_mode(ic);

	void (*f)(i_charger*);
	f= _fun[ic->i_stage];
	f(ic);
}
Ejemplo n.º 3
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");
	}	
}