Ejemplo n.º 1
0
static int s3c_get_bat_level(struct power_supply *bat_ps)
{
	int fg_soc = -1;
	int fg_vcell = -1;

	if ((fg_soc = fg_read_soc()) < 0) {
		dev_err(dev, "%s: Can't read soc!!!\n", __func__);
		fg_soc = s3c_bat_info.bat_info.level;
	}
	
	if ((fg_vcell = fg_read_vcell()) < 0) {
		dev_err(dev, "%s: Can't read vcell!!!\n", __func__);
		fg_vcell = s3c_bat_info.bat_info.batt_vol;
	} else
		s3c_bat_info.bat_info.batt_vol = fg_vcell;

	if (is_over_abs_time()) {
		//phj:here we can reach the MAXIMUM of soc for a given battery
		if (fg_soc)
			s3c_bat_info.max_soc_value=fg_soc;
		fg_soc = 100;
		s3c_bat_info.bat_info.batt_is_full = 1;
		dev_info(dev, "%s: charging time is over\n", __func__);
		s3c_set_chg_en(DISABLE);
		goto __end__;
	}

//	fg_soc = (fg_soc*100)/s3c_bat_info.max_soc_value;
//	if (fg_soc > 100)	fg_soc = 100;
//	fg_soc = 140 * (1 - exp(-fg_soc / 70)) - 4;  /* implemented in fg_tab */
	fg_soc = fg_tab[fg_soc];

	check_recharging_bat(avg_fg_vcell(fg_vcell));

__end__:
	dev_dbg(dev, "%s: fg_vcell = %d, fg_soc = %d, is_full = %d\n",
			__func__, fg_vcell, fg_soc, 
			s3c_bat_info.bat_info.batt_is_full);
	return fg_soc;
}
Ejemplo n.º 2
0
static void max8903_work(struct work_struct *work)
{
	struct max8903_data* data;
	struct max8903_pdata *pdata;
	static int msg_update_cnt =0;
	static int old_soc = 0;
	int soc = fg_read_soc();
	int ta_in, usb_in;

	data = container_of(work, struct max8903_data, work.work);

	pdata = data->pdata;

	if(pdata) {
		ta_in = gpio_get_value(pdata->dok) ? 0 : 1;
		usb_in = gpio_get_value(pdata->uok) ? 0 : 1;
	} else {
		ta_in = data->ta_in;
		usb_in = data->usb_in;
	}

	if ( ta_in && usb_in ) {
		usb_is_connected = true;
		dc_is_connected = false;
	} else if ( ta_in ) {
		usb_is_connected = false;
		dc_is_connected = true;
	} else {
		usb_is_connected = false;
		dc_is_connected = false;
	}


#ifdef SUPPORT_USB_STATE
	if(!data->usb_in && !data->ta_in)
		power_supply_changed(&data->battery);
	else if(data->ta_in)
		power_supply_changed(&data->adapter);
	else if(data->usb_in)
		power_supply_changed(&data->usb);
#else
	if(old_soc != soc || (data->ta_in != ta_in) || (data->usb_in != usb_in)) {
#ifdef FEATURE_TOUCH_NOISE
		if(data->ta_in != ta_in) {
			atm1664_power_noise(ta_in); 	
		}
#endif

		data->ta_in = ta_in;
		data->usb_in = usb_in;

		g_update_need = true;
	}

	if(g_update_need) {
#ifdef BATTERY_DEBUG
		if ( g_debug_enable ) {
			printk("[*NOTIFY] old_soc=%d soc=%d \n", old_soc , soc);
		}
#endif
		g_update_need = false;
		old_soc = soc;
		if(data->ta_in && data->usb_in)
			power_supply_changed(&data->usb);
		else if(data->ta_in)
			power_supply_changed(&data->adapter);
		else
			power_supply_changed(&data->battery);
	}
#endif

	if ( msg_update_cnt > 58 ) {
		printk("[BATTERY] old_soc=%d soc=%d, vcell=%duV, dc=%s, usb=%s\n", old_soc, soc, fg_read_vcell(), data->ta_in ? "true" : "false", data->usb_in ? "true" : "false");
		msg_update_cnt = 0;
	} else {
		msg_update_cnt++;
	}

#ifdef BATTERY_DEBUG
	if ( g_debug_enable ) {
		printk("[BATTERY] old_soc=%d soc=%d, vcell=%duV, dc=%s, usb=%s\n", old_soc, soc, fg_read_vcell(), data->ta_in ? "true" : "false", data->usb_in ? "true" : "false");
	}
#endif

	schedule_delayed_work(&data->work, msecs_to_jiffies(WORK_DELAY));
}
Ejemplo n.º 3
0
static int battery_get_property(struct power_supply *battery,
		enum power_supply_property psp,
		union power_supply_propval *val)
{
	struct max8903_data *data = container_of(battery,
			struct max8903_data, battery);

	switch (psp) {
		case POWER_SUPPLY_PROP_ONLINE:
			val->intval = 1; //always
			dev_dbg(data->dev, "%s: ONLINE=%d\n", __func__, val->intval);
			break;
		case POWER_SUPPLY_PROP_STATUS:
			val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
			if (data->pdata->chg) {
#ifdef SUPPORT_USB_STATE
				if (gpio_get_value(data->pdata->chg) == 0) { // low is charging
					if(fg_read_soc() >= FULL_SOC || fg_read_vcell() >= FULL_VCELL) {
						val->intval = POWER_SUPPLY_STATUS_FULL;
						gpio_set_value(data->pdata->cen, 1); // off
					} else if(data->ta_in || data->usb_in) {
						val->intval = POWER_SUPPLY_STATUS_CHARGING;
					} else {
						val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
					}
				} else { // not charging
					if(fg_read_soc() < FULL_SOC || fg_read_vcell() < FULL_VCELL) {
						gpio_set_value(data->pdata->cen, 0); // on
					}

					if (data->usb_in || data->ta_in) 
						val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
					else
						val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
				}
#else
				if(gpio_get_value(data->pdata->chg) == 0) { // low is charging
					if((fg_read_soc() >= FULL_SOC || fg_read_vcell() >= FULL_VCELL)
						&& (data->ta_in && !data->usb_in)) {
						val->intval = POWER_SUPPLY_STATUS_FULL;
						gpio_set_value(data->pdata->cen, 1); // off
					} else if(data->ta_in) {
						if(data->usb_in) {
							val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
						} else {
							val->intval = POWER_SUPPLY_STATUS_CHARGING;
						}
					} else {
						val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
					}

				} else { // not charging
					if(fg_read_soc() < FULL_SOC && fg_read_vcell() < FULL_VCELL) {
						gpio_set_value(data->pdata->cen, 0); // on
					}

					val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
				}
#endif
			}
			break;
		case POWER_SUPPLY_PROP_HEALTH:
			val->intval = POWER_SUPPLY_HEALTH_GOOD;
			if (data->fault)
				val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
			break;
		case POWER_SUPPLY_PROP_VOLTAGE_NOW:
			val->intval = fg_read_vcell();
			break;
                        
                case POWER_SUPPLY_PROP_TEMP:      
                        val->intval = 5;
		        break;      
		case POWER_SUPPLY_PROP_CAPACITY:
			val->intval = fg_read_soc(); // mehmet_VE %1 battery hack
			if (val->intval >= FULL_SOC) {
				val->intval = 100;
                        }                             
                        if (val->intval >= EMPTY_VOLT) {
                                val->intval = val->intval + 1;
                        }
			break;
#ifdef BATTERY_DEBUG
			if (g_force_soc_use) {
				val->intval = g_force_soc_val;
			}
#endif
			break;
		case POWER_SUPPLY_PROP_TECHNOLOGY:
			val->intval = POWER_SUPPLY_TECHNOLOGY_LIPO;
			break;
		default:
			return -EINVAL;
	}
	return 0;
}