コード例 #1
0
static void
#endif
sample_battery_timer_func(unsigned long data)
{
#ifdef WIN32
	UNREFERENCED_PARAMETER(data);
#endif

	switch (sample_battery_status) {
	case POWER_SUPPLY_STATUS_FULL:
		if (!power_supply_am_i_supplied(&sample_battery_psy)) {
			printk
			    ("External power removed --> started discharging\n");
			sample_battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
		}
		mod_timer(&sample_battery_timer,
			  jiffies + msecs_to_jiffies(interval));
		break;
	case POWER_SUPPLY_STATUS_CHARGING:
		if (!power_supply_am_i_supplied(&sample_battery_psy)) {
			printk
			    ("External power removed --> started discharging\n");
			sample_battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
		} else if (sample_battery_capacity < 100) {
			printk("Sample battery charging (%d%%)\n",
			       sample_battery_capacity);
			sample_battery_capacity++;
		} else {
			printk("Sample battery full\n");
			sample_battery_status = POWER_SUPPLY_STATUS_FULL;
		}
		power_supply_changed(&sample_battery_psy);
		mod_timer(&sample_battery_timer,
			  jiffies + msecs_to_jiffies(interval));
		break;
	case POWER_SUPPLY_STATUS_DISCHARGING:
		if (sample_battery_capacity > 0) {
			printk("Sample battery discharging (%d%%)\n",
			       sample_battery_capacity);
			sample_battery_capacity--;
		} else {
			printk("Sample battery empty\n");
			sample_battery_status =
			    POWER_SUPPLY_STATUS_NOT_CHARGING;
		}
		power_supply_changed(&sample_battery_psy);
		mod_timer(&sample_battery_timer,
			  jiffies + msecs_to_jiffies(interval));
		break;
	default:
		break;
	}
}
コード例 #2
0
ファイル: bq27x00_battery.c プロジェクト: raghavendraba/linux
static int bq27x00_battery_status(struct bq27x00_device_info *di,
				  union power_supply_propval *val)
{
	int status;

	if (bq27xxx_is_chip_version_higher(di)) {
		if (di->cache.flags & BQ27500_FLAG_FC)
			status = POWER_SUPPLY_STATUS_FULL;
		else if (di->cache.flags & BQ27500_FLAG_DSC)
			status = POWER_SUPPLY_STATUS_DISCHARGING;
		else
			status = POWER_SUPPLY_STATUS_CHARGING;
	} else {
		if (di->cache.flags & BQ27000_FLAG_FC)
			status = POWER_SUPPLY_STATUS_FULL;
		else if (di->cache.flags & BQ27000_FLAG_CHGS)
			status = POWER_SUPPLY_STATUS_CHARGING;
		else if (power_supply_am_i_supplied(di->bat))
			status = POWER_SUPPLY_STATUS_NOT_CHARGING;
		else
			status = POWER_SUPPLY_STATUS_DISCHARGING;
	}

	val->intval = status;

	return 0;
}
コード例 #3
0
ファイル: generic-adc-battery.c プロジェクト: 19Dan01/linux
static void gab_work(struct work_struct *work)
{
	struct gab *adc_bat;
	struct gab_platform_data *pdata;
	struct delayed_work *delayed_work;
	bool is_plugged;
	int status;

	delayed_work = container_of(work, struct delayed_work, work);
	adc_bat = container_of(delayed_work, struct gab, bat_work);
	pdata = adc_bat->pdata;
	status = adc_bat->status;

	is_plugged = power_supply_am_i_supplied(adc_bat->psy);
	adc_bat->cable_plugged = is_plugged;

	if (!is_plugged)
		adc_bat->status =  POWER_SUPPLY_STATUS_DISCHARGING;
	else if (gab_charge_finished(adc_bat))
		adc_bat->status = POWER_SUPPLY_STATUS_NOT_CHARGING;
	else
		adc_bat->status = POWER_SUPPLY_STATUS_CHARGING;

	if (status != adc_bat->status)
		power_supply_changed(adc_bat->psy);
}
コード例 #4
0
static void
twl4030_bci_battery_update_status(struct twl4030_bci_device_info *di)
{
	int old_charge_source = di->charge_rsoc;
	int old_charge_status = di->charge_status;
	int old_capacity = di->capacity;
	static int stable_count;

	twl4030_bci_battery_read_status(di);
	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;
	if (power_supply_am_i_supplied(&di->bat))
		di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
	else
		di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;

	/*
	 * Read the current usb_charger_flag
	 * compare this with the value from the last
	 * update cycle to determine if there was a
	 * change.
	 */
	di->charge_rsoc = usb_charger_flag;

	/*
	 * Battery voltage fluctuates, when we are on a threshold
	 * level, we do not want to keep informing user of the
	 * capacity fluctuations, or he the battery progress will
	 * keep moving.
	 */
	if (old_capacity != di->capacity) {
		stable_count = 0;
	} else {
		stable_count++;
	}
	/*
	 * Send uevent to user space to notify
	 * of some battery specific events.
	 * Ac plugged in, USB plugged in and Capacity
	 * level changed.
	 * called every 100 jiffies = 0.7 seconds
	 * 20 stable cycles means capacity did not change
	 * in the last 15 seconds.
	 */
	if ((old_charge_status != di->charge_status)
			|| (stable_count == 20)
			|| (old_charge_source !=  di->charge_rsoc)) {
		power_supply_changed(&di->bat);
	}
}
コード例 #5
0
static void sample_battery_ext_power_changed(struct power_supply *psy)
{
#ifdef WIN32
	UNREFERENCED_PARAMETER(psy);
#endif

	if (power_supply_am_i_supplied(psy)) {
		printk("External power inserted --> started charging\n");
		sample_battery_status = POWER_SUPPLY_STATUS_CHARGING;
	} else {
		printk("External power removed --> started discharging\n");
		sample_battery_status = POWER_SUPPLY_STATUS_DISCHARGING;
	}
	mod_timer(&sample_battery_timer, jiffies + msecs_to_jiffies(interval));
}
コード例 #6
0
static void tosa_bat_update(struct tosa_bat *bat)
{
	int old;
	struct power_supply *psy = &bat->psy;

	mutex_lock(&bat->work_lock);

	old = bat->status;

	if (bat->is_present && !bat->is_present(bat)) {
#ifdef CONFIG_DEBUG_PRINTK
		printk(KERN_NOTICE "%s not present\n", psy->name);
#else
		;
#endif
		bat->status = POWER_SUPPLY_STATUS_UNKNOWN;
		bat->full_chrg = -1;
	} else if (power_supply_am_i_supplied(psy)) {
		if (bat->status == POWER_SUPPLY_STATUS_DISCHARGING) {
			gpio_set_value(bat->gpio_charge_off, 0);
			mdelay(15);
		}

		if (gpio_get_value(bat->gpio_full)) {
			if (old == POWER_SUPPLY_STATUS_CHARGING ||
					bat->full_chrg == -1)
				bat->full_chrg = tosa_read_bat(bat);

			gpio_set_value(bat->gpio_charge_off, 1);
			bat->status = POWER_SUPPLY_STATUS_FULL;
		} else {
			gpio_set_value(bat->gpio_charge_off, 0);
			bat->status = POWER_SUPPLY_STATUS_CHARGING;
		}
	} else {
		gpio_set_value(bat->gpio_charge_off, 1);
		bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
	}

	if (old != bat->status)
		power_supply_changed(psy);

	mutex_unlock(&bat->work_lock);
}
コード例 #7
0
static void
twl6030_bci_battery_update_status(struct twl6030_bci_device_info *di)
{
	if (charger_source == 1) {
		/* reconfig params for ac charging & reset 32 second timer */
		twl_i2c_write_u8(TWL6030_MODULE_BQ, 0xC0, REG_STATUS_CONTROL);
		twl_i2c_write_u8(TWL6030_MODULE_BQ, 0xC8, REG_CONTROL_REGISTER);
		twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x7C,
						REG_CONTROL_BATTERY_VOLTAGE);
		twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x51,
						REG_BATTERY_TERMINATION);
		twl_i2c_write_u8(TWL6030_MODULE_BQ, 0x02,
						REG_SPECIAL_CHARGER_VOLTAGE);
	}
	twl6030_bci_battery_read_status(di);
	di->charge_status = POWER_SUPPLY_STATUS_UNKNOWN;

	if (power_supply_am_i_supplied(&di->bat))
		di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
	else
		di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
}
コード例 #8
0
static int picasso_battery_get_status(struct power_supply *psy,
union power_supply_propval *val) {
	s32 ret, capacity;
	int bat_present, ac_status;
	
	ret = picasso_battery_read_register(EC_BATT_DESIGN_CAPACITY);
	if (ret < 0) {
		return ret;
	}
	bat_present = !!ret;

	ret = picasso_battery_read_register(EC_BATT_CAPACITY);
	if (ret < 0) {
		return ret;
	}
	capacity = ret;
	ac_status = power_supply_am_i_supplied(psy);

	if (capacity < 100) {
		if (ac_status) {
			val->intval = POWER_SUPPLY_STATUS_CHARGING;
		} else {
			val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
		}
	} else {
		if (ac_status) {
			val->intval = POWER_SUPPLY_STATUS_FULL;
		} else {
			val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
		}
	}

	if (!bat_present) {
		val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
	}

	return 0;
}
コード例 #9
0
static void s3c_adc_bat_work(struct work_struct *work)
{
	struct s3c_adc_bat *bat = &main_bat;
	int is_charged;
	int is_plugged;
	static int was_plugged;

	is_plugged = power_supply_am_i_supplied(&bat->psy);
	bat->cable_plugged = is_plugged;
	if (is_plugged != was_plugged) {
		was_plugged = is_plugged;
		if (is_plugged) {
			if (bat->pdata->enable_charger)
				bat->pdata->enable_charger();
			bat->status = POWER_SUPPLY_STATUS_CHARGING;
		} else {
			if (bat->pdata->disable_charger)
				bat->pdata->disable_charger();
			bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
		}
	} else {
		if ((bat->pdata->gpio_charge_finished >= 0) && is_plugged) {
			is_charged = charge_finished(&main_bat);
			if (is_charged) {
				if (bat->pdata->disable_charger)
					bat->pdata->disable_charger();
				bat->status = POWER_SUPPLY_STATUS_FULL;
			} else {
				if (bat->pdata->enable_charger)
					bat->pdata->enable_charger();
				bat->status = POWER_SUPPLY_STATUS_CHARGING;
			}
		}
	}

	power_supply_changed(&bat->psy);
}
コード例 #10
0
static void set_battery_status(struct twl4030_bci_device_info *di)
{

// [email protected] 20120502 MUIC re-work start
#if defined(CONFIG_HUB_MUIC)
	TYPE_MUIC_MODE muic_mode = get_muic_mode();
#elif defined(CONFIG_MUIC)
	TYPE_MUIC_MODE muic_mode = muic_get_mode();
#endif
// [email protected] 20120502 MUIC re-work end

	// Set Power Resources
	switch (muic_mode) {
		case MUIC_AP_UART:
		case MUIC_CP_UART:
		case MUIC_CP_USB:
			di->charge_rsoc = POWER_SUPPLY_TYPE_UPS;
			wakeup_timer_seconds = 0;	// disable wakeup.
			break;
		case MUIC_NA_TA:
		case MUIC_LG_TA:
		case MUIC_TA_1A:
		case MUIC_INVALID_CHG:
			di->charge_rsoc = POWER_SUPPLY_TYPE_MAINS;
			wakeup_timer_seconds = 60;	// to wake up to monitor battery when charging mode
			break;
		case MUIC_AP_USB:
			di->charge_rsoc = POWER_SUPPLY_TYPE_USB;
			wakeup_timer_seconds = 0;	// disable wakeup. The phone will be wakeup because of wakelock
			break;
		default :
			di->charge_rsoc = POWER_SUPPLY_TYPE_BATTERY;
			wakeup_timer_seconds = 0;	// disable wakeup.
			if(di->battery_capacity <= 1)	// enable wakeup for monitoring power-off voltage
				wakeup_timer_seconds = 60;
		break;
	}
	
	// Set Charging Status
	if(di->charge_rsoc == POWER_SUPPLY_TYPE_UPS ||		// JIG
	   di->charge_rsoc == POWER_SUPPLY_TYPE_BATTERY) {	// Battery
		di->charge_status = POWER_SUPPLY_STATUS_DISCHARGING;
	} else {
		if(di->battery_present == 0) {			// Battery not present. Display as not charging
			di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;		
		} else if((di->temp_C < TEMP_CRITICAL_LOWER ||
			  di->temp_C > TEMP_CRITICAL_UPPER) &&
			  di->temp_control != UNLIMITED_TEMP_VAL) {	// 20120725, [email protected], Enable charging by fake mode.
			// Charging Stoped
			di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING;
		} else if((di->temp_C < TEMP_LIMIT_LOWER ||
			  di->temp_C > TEMP_LIMIT_UPPER) &&
			  di->temp_control != UNLIMITED_TEMP_VAL) {	// 20120725, [email protected], Enable charging by fake mode.
			// Charging Limited
			di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
		} else if(start_monitor||di->battery_capacity >= 100) {			// Charging FULL
			di->charge_status = POWER_SUPPLY_STATUS_FULL;
		} else {					// Normal Charging
			di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
		}
	}

	/*ntyeongon.moon 2011-04-01 CP USB Charging mode [START]*/
	if((di->charge_status==POWER_SUPPLY_STATUS_DISCHARGING)
		&& power_supply_am_i_supplied(&di->bat)    )
    {
		di->charge_status = POWER_SUPPLY_STATUS_CHARGING;
	}
	/*ntyeongon.moon 2011-04-01 CP USB Charging mode [END]*/

}