Skip to contentSkip to conversation

AC Power handling broken for desktops

PATCH New Olaf Hering 3 participants 10 messages Aug 24, 2005 – Oct 10, 2005 Linux for power macintosh

lore
Share & tools
lore
#0 lore raw

My G4/450 runs without AC Power, according to /proc/pmu/info:

PMU driver version : 2
PMU firmware version : 0c
AC Power : 0
Battery count : 0

It should report 1. Where is the best place to get the PMU_PWR_AC_PRESENT into ac_line_status?

#1 lore raw
Quoted 9 lines · Olaf Hering

My G4/450 runs without AC Power, according to /proc/pmu/info:

PMU driver version : 2
PMU firmware version : 0c
AC Power : 0
Battery count : 0

It should report 1. Where is the best place to get the PMU_PWR_AC_PRESENT into ac_line_status?

Do we get the bit set from the PMU ? If not, maybe we should hard code that value on non-laptops

Ben.

#2 lore raw
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Olaf Hering

My G4/450 runs without AC Power, according to /proc/pmu/info:

PMU driver version : 2
PMU firmware version : 0c
AC Power : 0
Battery count : 0

Quoted 5 lines
Quoted 2 lines

It should report 1. Where is the best place to get the PMU_PWR_AC_PRESENT into ac_line_status?

Do we get the bit set from the PMU ? If not, maybe we should hard code that value on non-laptops

Appearently not, how do I check it?

#3 lore raw
Quoted 10 lines · Olaf Hering
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · Olaf Hering

My G4/450 runs without AC Power, according to /proc/pmu/info:

PMU driver version : 2
PMU firmware version : 0c
AC Power : 0
Battery count : 0

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

It should report 1. Where is the best place to get the PMU_PWR_AC_PRESENT into ac_line_status?

Do we get the bit set from the PMU ? If not, maybe we should hard code that value on non-laptops

Appearently not, how do I check it?

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Ben

#4 lore raw
Quoted 2 lines · Benjamin Herrenschmidt

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Maybe just check for !PowerBook and force PMU_PWR_AC_PRESENT in this case.

#5 lore raw
Quoted 6 lines · Olaf Hering
Quoted 2 lines · Benjamin Herrenschmidt

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Maybe just check for !PowerBook and force PMU_PWR_AC_PRESENT in this case.

Yah, you can check that with pmac_feature, there is a "mobile" flag.

Ben

#9 lore raw
In reply to Olaf Hering
Quoted 4 lines
Quoted 2 lines

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Maybe just check for !PowerBook and force PMU_PWR_AC_PRESENT in this case.

Or just if battery count is 0, assume AC power ;-)

Segher

#6 lore raw
In reply to Benjamin Herrenschmidt
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 6 lines · Olaf Hering
Quoted 2 lines · Benjamin Herrenschmidt

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Maybe just check for !PowerBook and force PMU_PWR_AC_PRESENT in this case.

Yah, you can check that with pmac_feature, there is a "mobile" flag.

Its not obvious how to get to that flag. Is this patch acceptable? No batteries present should mean AC Power == 1.

 drivers/macintosh/apm_emu.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/macintosh/apm_emu.c +6 -2
Index: linux-2.6.13-rc7-ac-power/drivers/macintosh/apm_emu.c
===================================================================
@@ -430,8 +430,8 @@ static int apm_emu_get_info(char *buf, c
 	      -1: Unknown
 	   8) min = minutes; sec = seconds */
 
-	unsigned short  ac_line_status = 0xff;
-	unsigned short  battery_status = 0xff;
+	unsigned short  ac_line_status;
+	unsigned short  battery_status = 0;
 	unsigned short  battery_flag   = 0xff;
 	int		percentage     = -1;
 	int             time_units     = -1;
@@ -446,6 +446,7 @@ static int apm_emu_get_info(char *buf, c
 	ac_line_status = ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0);
 	for (i=0; i<pmu_battery_count; i++) {
 		if (pmu_batteries[i].flags & PMU_BATT_PRESENT) {
+			battery_status++;
 			if (percentage < 0)
 				percentage = 0;
 			if (charge < 0)
@@ -461,6 +462,9 @@ static int apm_emu_get_info(char *buf, c
 				charging++;
 		}
 	}
+	if (0 == battery_status)
+		ac_line_status = 1;
+	battery_status = 0xff;
 	if (real_count) {
 		if (amperage < 0) {
 			if (btype == PMU_BATT_TYPE_SMART)
#7 lore raw
Quoted 10 lines · Olaf Hering
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 6 lines · Olaf Hering
Quoted 2 lines · Benjamin Herrenschmidt

Not sure :) I don't fully know how to decode those power things in the device-tree... There are bits in darwin tho.

Maybe just check for !PowerBook and force PMU_PWR_AC_PRESENT in this case.

Quoted 7 lines
Quoted 1 line

Yah, you can check that with pmac_feature, there is a "mobile" flag.

Its not obvious how to get to that flag. Is this patch acceptable? No batteries present should mean AC Power == 1.

 drivers/macintosh/apm_emu.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Looks good to me.

Ben

#8 lore raw

PATCH 1/1 AC Power handling broken for desktops

Currently, AC Power is 0 on a desktop G4.
No batteries present should mean AC Power == 1.

 drivers/macintosh/apm_emu.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
drivers/macintosh/apm_emu.c +6 -2
Index: linux-2.6.13-rc7-ac-power/drivers/macintosh/apm_emu.c
===================================================================
@@ -430,8 +430,8 @@ static int apm_emu_get_info(char *buf, c
 	      -1: Unknown
 	   8) min = minutes; sec = seconds */
 
-	unsigned short  ac_line_status = 0xff;
-	unsigned short  battery_status = 0xff;
+	unsigned short  ac_line_status;
+	unsigned short  battery_status = 0;
 	unsigned short  battery_flag   = 0xff;
 	int		percentage     = -1;
 	int             time_units     = -1;
@@ -446,6 +446,7 @@ static int apm_emu_get_info(char *buf, c
 	ac_line_status = ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0);
 	for (i=0; i<pmu_battery_count; i++) {
 		if (pmu_batteries[i].flags & PMU_BATT_PRESENT) {
+			battery_status++;
 			if (percentage < 0)
 				percentage = 0;
 			if (charge < 0)
@@ -461,6 +462,9 @@ static int apm_emu_get_info(char *buf, c
 				charging++;
 		}
 	}
+	if (0 == battery_status)
+		ac_line_status = 1;
+	battery_status = 0xff;
 	if (real_count) {
 		if (amperage < 0) {
 			if (btype == PMU_BATT_TYPE_SMART)
Signature · 2 lines
short story of a lazy sysadmin:
 alias appserv=wotan