Commit 5493f1f4 authored by Paul Mackerras's avatar Paul Mackerras Committed by Linus Torvalds

[PATCH] update apm emulation for mac

This updates the battery charge calculations for powerbooks.  This is
Ben Herrenschmidt's work.
parent ce121b29
...@@ -436,40 +436,40 @@ static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length) ...@@ -436,40 +436,40 @@ static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length)
int percentage = -1; int percentage = -1;
int time_units = -1; int time_units = -1;
int real_count = 0; int real_count = 0;
int charge = -1;
int current = 0;
int i; int i;
char * p = buf; char * p = buf;
char charging = 0; char charging = 0;
long charge = -1;
long current = 0;
unsigned long btype = 0;
ac_line_status = ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0); ac_line_status = ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0);
for (i=0; i<pmu_battery_count; i++) { for (i=0; i<pmu_battery_count; i++) {
if (percentage < 0)
percentage = 0;
if (charge < 0)
charge = 0;
if (pmu_batteries[i].flags & PMU_BATT_PRESENT) { if (pmu_batteries[i].flags & PMU_BATT_PRESENT) {
if (percentage < 0)
percentage = 0;
if (charge < 0)
charge = 0;
percentage += (pmu_batteries[i].charge * 100) / percentage += (pmu_batteries[i].charge * 100) /
pmu_batteries[i].max_charge; pmu_batteries[i].max_charge;
/* hrm... should we provide the remaining charge charge += pmu_batteries[i].charge;
* time when AC is plugged ? If yes, just remove current += pmu_batteries[i].current;
* that test --BenH if (btype == 0)
*/ btype = (pmu_batteries[i].flags & PMU_BATT_TYPE_MASK);
if (!ac_line_status) {
charge += pmu_batteries[i].charge;
current += pmu_batteries[i].current;
}
real_count++; real_count++;
if ((pmu_batteries[i].flags & PMU_BATT_CHARGING)) if ((pmu_batteries[i].flags & PMU_BATT_CHARGING))
charging++; charging++;
} }
} }
if (real_count) { if (real_count) {
time_units = (charge * 59) / (current * -1); if (current < 0) {
if(!charging) if (btype == PMU_BATT_TYPE_SMART)
battery_flag &= ~0x08; time_units = (charge * 59) / (current * -1);
else
time_units = (charge * 16440) / (current * -60);
}
percentage /= real_count; percentage /= real_count;
if (battery_flag & 0x08) { if (charging > 0) {
battery_status = 0x03; battery_status = 0x03;
battery_flag = 0x08; battery_flag = 0x08;
} else if (percentage <= APM_CRITICAL) { } else if (percentage <= APM_CRITICAL) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment