Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 72058
b: refs/heads/master
c: 2a721df
h: refs/heads/master
v: v3
  • Loading branch information
Anton Vorontsov committed Oct 4, 2007
1 parent 034a10a commit a513daf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 26 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d385376f0d75fdbeed8041ed6baf5cb4a1578ffb
refs/heads/master: 2a721dfc8c677588fc98d818dfad3354081c6ddb
78 changes: 53 additions & 25 deletions trunk/drivers/power/apm_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,41 +87,63 @@ static void find_main_battery(void)
}
}

static int calculate_time(int status)
static int calculate_time(int status, int using_charge)
{
union power_supply_propval charge_full, charge_empty;
union power_supply_propval charge, I;
union power_supply_propval full;
union power_supply_propval empty;
union power_supply_propval cur;
union power_supply_propval I;
enum power_supply_property full_prop;
enum power_supply_property full_design_prop;
enum power_supply_property empty_prop;
enum power_supply_property empty_design_prop;
enum power_supply_property cur_avg_prop;
enum power_supply_property cur_now_prop;

if (MPSY_PROP(CHARGE_FULL, &charge_full)) {
/* if battery can't report this property, use design value */
if (MPSY_PROP(CHARGE_FULL_DESIGN, &charge_full))
if (MPSY_PROP(CURRENT_AVG, &I)) {
/* if battery can't report average value, use momentary */
if (MPSY_PROP(CURRENT_NOW, &I))
return -1;
}

if (MPSY_PROP(CHARGE_EMPTY, &charge_empty)) {
/* if battery can't report this property, use design value */
if (MPSY_PROP(CHARGE_EMPTY_DESIGN, &charge_empty))
charge_empty.intval = 0;
if (using_charge) {
full_prop = POWER_SUPPLY_PROP_CHARGE_FULL;
full_design_prop = POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN;
empty_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
cur_avg_prop = POWER_SUPPLY_PROP_CHARGE_AVG;
cur_now_prop = POWER_SUPPLY_PROP_CHARGE_NOW;
} else {
full_prop = POWER_SUPPLY_PROP_ENERGY_FULL;
full_design_prop = POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN;
empty_prop = POWER_SUPPLY_PROP_ENERGY_EMPTY;
empty_design_prop = POWER_SUPPLY_PROP_CHARGE_EMPTY;
cur_avg_prop = POWER_SUPPLY_PROP_ENERGY_AVG;
cur_now_prop = POWER_SUPPLY_PROP_ENERGY_NOW;
}

if (MPSY_PROP(CHARGE_AVG, &charge)) {
/* if battery can't report average value, use momentary */
if (MPSY_PROP(CHARGE_NOW, &charge))
if (_MPSY_PROP(full_prop, &full)) {
/* if battery can't report this property, use design value */
if (_MPSY_PROP(full_design_prop, &full))
return -1;
}

if (MPSY_PROP(CURRENT_AVG, &I)) {
if (_MPSY_PROP(empty_prop, &empty)) {
/* if battery can't report this property, use design value */
if (_MPSY_PROP(empty_design_prop, &empty))
empty.intval = 0;
}

if (_MPSY_PROP(cur_avg_prop, &cur)) {
/* if battery can't report average value, use momentary */
if (MPSY_PROP(CURRENT_NOW, &I))
if (_MPSY_PROP(cur_now_prop, &cur))
return -1;
}

if (status == POWER_SUPPLY_STATUS_CHARGING)
return ((charge.intval - charge_full.intval) * 60L) /
I.intval;
return ((cur.intval - full.intval) * 60L) / I.intval;
else
return -((charge.intval - charge_empty.intval) * 60L) /
I.intval;
return -((cur.intval - empty.intval) * 60L) / I.intval;
}

static int calculate_capacity(int using_charge)
Expand Down Expand Up @@ -238,16 +260,22 @@ static void apm_battery_apm_get_power_status(struct apm_power_info *info)

if (status.intval == POWER_SUPPLY_STATUS_CHARGING) {
if (!MPSY_PROP(TIME_TO_FULL_AVG, &time_to_full) ||
!MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full))
!MPSY_PROP(TIME_TO_FULL_NOW, &time_to_full)) {
info->time = time_to_full.intval / 60;
else
info->time = calculate_time(status.intval);
} else {
info->time = calculate_time(status.intval, 0);
if (info->time == -1)
info->time = calculate_time(status.intval, 1);
}
} else {
if (!MPSY_PROP(TIME_TO_EMPTY_AVG, &time_to_empty) ||
!MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty))
!MPSY_PROP(TIME_TO_EMPTY_NOW, &time_to_empty)) {
info->time = time_to_empty.intval / 60;
else
info->time = calculate_time(status.intval);
} else {
info->time = calculate_time(status.intval, 0);
if (info->time == -1)
info->time = calculate_time(status.intval, 1);
}
}

up(&power_supply_class->sem);
Expand Down

0 comments on commit a513daf

Please sign in to comment.