Esempio n. 1
0
int	lm3530_set_brightness_control(struct lm3530_private_data* pdata, int val)
{
	if ((val < 0) || (val > 255))
		return	-EINVAL;

	/*                                                                                    */
#if defined(CONFIG_LG_FW_MAX17043_FUEL_GAUGE_I2C) || defined(CONFIG_LG_FW_MAX17048_FUEL_GAUGE_I2C)
	if (get_bat_present() == 0 &&
	    get_charging_ic_status() == POWER_SUPPLY_TYPE_FACTORY)
		return -1;
#endif
	return	lm3530_write_byte(pdata, LM3530_REG_BRT, val);
}
static int twl4030_ac_bci_battery_get_property(struct power_supply *psy,
					enum power_supply_property psp,
					union power_supply_propval *val)
{

	max8922_status chr_ic_status = CHARGING_IC_DEACTIVE;
	chr_ic_status = get_charging_ic_status();
	TYPE_MUIC_MODE muic_mode = MUIC_NONE;


	switch (psp) {
		case POWER_SUPPLY_PROP_ONLINE:
/* LGE_CHANGE_S [[email protected]] 2010-03-19 */
#if defined(CONFIG_HUB_MUIC)
			muic_mode = get_muic_mode();
			if ( muic_mode == MUIC_LG_TA || muic_mode == MUIC_NA_TA || muic_mode == MUIC_HCHH || muic_mode == MUIC_INVALID_CHG )
				val->intval = 1;
			else
				val->intval = 0;
			break;
// [email protected] 20120502 MUIC re-work start
#elif defined(CONFIG_MUIC)
			muic_mode = muic_get_mode();
			if ( muic_mode == MUIC_LG_TA || muic_mode == MUIC_NA_TA || muic_mode == MUIC_TA_1A || muic_mode == MUIC_INVALID_CHG && chr_ic_status != CHARGING_IC_DEACTIVE)
				val->intval = 1;
			else
				val->intval = 0;
			break;
// [email protected] 20120502 MUIC re-work end	
#endif
/* LGE_CHANGE_E [[email protected]] 2010-03-19 */
		default:
			return -EINVAL;
	}

	return 0;
}
static int twl4030_bci_battery_get_property(struct power_supply *psy,
					    enum power_supply_property psp,
					    union power_supply_propval *val)
{
	struct twl4030_bci_device_info *di;
#if defined(CONFIG_HUB_MUIC)
#else
	int status = 0;
#endif	
	max8922_status chr_ic_status = CHARGING_IC_DEACTIVE;
	chr_ic_status = get_charging_ic_status();

    TYPE_MUIC_MODE muic_mode = MUIC_NONE;


	di = to_twl4030_bci_device_info(psy);
/*
	switch (psp) {
		case POWER_SUPPLY_PROP_STATUS:
			val->intval = di->charge_status;
			return 0;
		default:
			break;
	}
*/
	switch (psp) {
		case POWER_SUPPLY_PROP_STATUS:
			val->intval = di->charge_status;
#if 0 //ntyeongon.moon 2011-03-16  full-charge status comes from soc level [START]
			if(di->voltage_uV > 4190) {		// QM Requested for Dummy Battery Test (LGP970)
				val->intval = POWER_SUPPLY_STATUS_FULL;
			}
#endif //ntyeongon.moon 2011-03-16  full-charge status comes from soc level [END]
			break;
		case POWER_SUPPLY_PROP_VOLTAGE_NOW:
			val->intval = di->voltage_uV;
			break;
		case POWER_SUPPLY_PROP_CURRENT_NOW:
			val->intval = di->current_uA;
			break;
		case POWER_SUPPLY_PROP_TEMP:
			if(di->battery_present == 0)		// No Battery or Dummy Battery
				val->intval = 200;
			// S[, 20120725, [email protected], Enable charging by fake mode.
			else if (di->temp_control == UNLIMITED_TEMP_VAL) 
			{
				if (di->temp_C > UNLIMITED_TEMP_HIGH)
					val->intval = UNLIMITED_TEMP_HIGH;
				else if (di->temp_C < UNLIMITED_TEMP_LOW)
					val->intval = UNLIMITED_TEMP_LOW;
				else
					val->intval = di->temp_C;
			}
			// E], 20120725, [email protected], Enable charging by fake mode.
			else
				val->intval = di->temp_C;
			break;
		case POWER_SUPPLY_PROP_ONLINE:
#if defined(CONFIG_HUB_MUIC)  || defined(CONFIG_MUIC)

			val->intval = di->charge_rsoc;
//2011-03-23 [email protected] get muic INT_STAT  VBUS [START_LGE]
			 if(!is_muic_mvbus_on()) val->intval = 0;
//2011-03-23 [email protected] get muic INT_STAT  VBUSVBUS [END_LGE]
			break;
#else
			status = twl4030bci_status();
			if ((status & AC_STATEC) == AC_STATEC)
				val->intval = POWER_SUPPLY_TYPE_MAINS;
			else if (usb_charger_flag)
				val->intval = POWER_SUPPLY_TYPE_USB;
			else
				val->intval = 0;
			break;
#endif  // CONFIG_HUB_MUIC
		case POWER_SUPPLY_PROP_PRESENT:
			val->intval = di->battery_present;
#if defined(CONFIG_HUB_MUIC)
			muic_mode = get_muic_mode();
			if(muic_mode == MUIC_CP_USB  ||		// JIG
			   muic_mode == MUIC_CP_UART ||
			   muic_mode == MUIC_AP_UART) {
				val->intval = 1;
			} else if(muic_mode == MUIC_NONE) {	// Dummy Battery
				val->intval = 1;
			}
// [email protected] 20120502 MUIC re-work start
#elif defined(CONFIG_MUIC)
			muic_mode = muic_get_mode();
			if(muic_mode == MUIC_CP_USB  ||		// JIG
			   muic_mode == MUIC_CP_UART ||
			   muic_mode == MUIC_AP_UART && 
			   chr_ic_status != CHARGING_IC_DEACTIVE) {
				val->intval = 1;
			} else if(muic_mode == MUIC_NONE) {	// Dummy Battery
				val->intval = 1;
			}
#else
	#error
// [email protected] 20120502 MUIC re-work end
#endif
            break;

		case POWER_SUPPLY_PROP_CAPACITY:
			#if defined(CONFIG_HUB_MUIC)
				muic_mode = get_muic_mode();
			#elif defined(CONFIG_MUIC)
				muic_mode = muic_get_mode();
			#endif
			val->intval = di->battery_capacity;
			printk("[BATTER] cap:%d , muic:%d \n",val->intval, muic_mode);
			// for Lockscreen sync with status bar
#if 0  //ntyeongon.moon 2011-03-16  full-charge status comes from soc level [START]
			if(di->charge_rsoc == POWER_SUPPLY_TYPE_MAINS ||
			   di->charge_rsoc == POWER_SUPPLY_TYPE_USB) {	// When Charging Mode
				if(di->charge_status == POWER_SUPPLY_STATUS_FULL) {
					val->intval = 100;
				} else if(di->battery_present == 1 &&	// Battery Present and not Full
					  val->intval == 100) {		// but battery level is 100%
					val->intval = 99;		// view as 99% for lockscreen
				} else if(di->voltage_uV > 4190) {	// QM Requested for Dummy Battery Test (LGP970)
					val->intval = 100;
				}
			}
#endif //ntyeongon.moon 2011-03-16  full-charge status comes from soc level [END]

			break;
			/* FIXME : It depends on H/W specific */
		case POWER_SUPPLY_PROP_HEALTH:
			if(!di->battery_present)
				val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
			else if(di->voltage_uV > 5000)				// Over voltage
				val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
			else if(di->temp_C < TEMP_CRITICAL_LOWER)	// Cold
				val->intval = POWER_SUPPLY_HEALTH_COLD;
			else if(di->temp_C > TEMP_CRITICAL_UPPER)	// Hot
				val->intval = POWER_SUPPLY_HEALTH_OVERHEAT;
			else
				val->intval = POWER_SUPPLY_HEALTH_GOOD;
			break;
		case POWER_SUPPLY_PROP_TECHNOLOGY:
			val->intval = POWER_SUPPLY_TECHNOLOGY_LION;	// Fixed value : Li-ion
			break;

// S[, 20120725, [email protected], Enable charging by fake mode.
		case POWER_SUPPLY_PROP_TEMP_CONTROL:
//#ifdef CONFIG_MACH_LGE_CX2 // <-- not defined.
//			lge_dynamic_nvdata_read(LGE_NVDATA_DYNAMIC_CHARGING_TEMP_OFFSET, &temp_val, 1);
//
//			val->intval = (int)temp_val;
//#else
			val->intval = (int)di->temp_control;
//#endif
			break;
// E], 20120725, [email protected], Enable charging by fake mode.
		default:
			return -EINVAL;
	}
	return 0;
}
static int set_battery_charging(struct twl4030_bci_device_info *di)
{
	int trickle_chg_max, trickle_chg_min, trickle_chg_timer_start;
	max8922_status chr_ic_status = get_charging_ic_status();
	
	if(di->battery_present == 0 || 						// No Battery State
		di->charge_rsoc == POWER_SUPPLY_TYPE_BATTERY) {	// No Charging Source
		start_monitor = 0;
		set_end_of_charge(0);
		set_charging_timer(0);
		return 0;
	}
	
	/*
	 * Recharging algorithm
     *  - High Temperature : up to 4.0V
     *  - Normal : up to 4.2V
     */
    // Set maximum charging voltage
    if((di->temp_C < TEMP_CRITICAL_LOWER ||
	   di->temp_C > TEMP_CRITICAL_UPPER) && // Critical Temperature! Must stop charging
	   di->temp_control != UNLIMITED_TEMP_VAL){ // 20120725, [email protected], Enable charging by fake mode.
		start_monitor = 0;
		set_end_of_charge(0);
		set_charging_timer(0);
		if (di->battery_present == 1)
        	charging_ic_deactive();
        return 0;
    } else if(di->temp_C < TEMP_LIMIT_LOWER ||
              di->temp_C > TEMP_LIMIT_UPPER) {	// Charging Limit
		trickle_chg_max = 4000;
		trickle_chg_timer_start = 3950;
		trickle_chg_min = 3900;
	} else {									// Normal Charging
		trickle_chg_max = 4220;					// to unintentional charging stop
		trickle_chg_timer_start = 4197;
		trickle_chg_min = 4140;
		if((di->previous_temp_C < TEMP_LIMIT_LOWER ||
		   di->previous_temp_C > TEMP_LIMIT_UPPER) &&
		   di->temp_control != UNLIMITED_TEMP_VAL) { // 20120725, [email protected], Enable charging by fake mode.
			start_monitor = 0;
			set_end_of_charge(0);
			set_charging_timer(0);
		}
	}

	// Deactive charger for protect overcharge & monitoring
	if(chr_ic_status != CHARGING_IC_DEACTIVE) {
		if(/*di->voltage_uV >= trickle_chg_max ||*/ charging_timeout() || end_of_charge) {
			// Battery Full Charged Once. Entering Trickle Charging Mode
			if(!charging_timeout())		// Do not stop charging when timeout occured
				charging_ic_deactive();	// It's not actually charged full.
			set_charging_timer(0);
			set_end_of_charge(0);
			if(start_monitor == 0) {
				printk(KERN_DEBUG "[Battery] Trickle Charging Start!\n");
				start_monitor = 1;
			}
		} else if(di->voltage_uV >= trickle_chg_timer_start) {
			set_charging_timer(1);
		}
	} else if(di->voltage_uV < trickle_chg_min) {	// active charger for recharging
		switch(di->charge_rsoc) {
			case POWER_SUPPLY_TYPE_MAINS:
				charging_ic_set_ta_mode();
				break;
			case POWER_SUPPLY_TYPE_USB:
				charging_ic_set_usb_mode();
				break;
			case POWER_SUPPLY_TYPE_UPS:
				charging_ic_set_factory_mode();
				break;
			default:
				break;
		}
	}
	return 0;
}