2 * APM emulation for PMU-based machines
4 * Copyright 2001 Benjamin Herrenschmidt (benh@kernel.crashing.org)
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/apm-emulation.h>
22 #include <linux/adb.h>
23 #include <linux/pmu.h>
25 #define APM_CRITICAL 10
28 static void pmu_apm_get_power_status(struct apm_power_info
*info
)
38 unsigned long btype
= 0;
40 info
->battery_status
= APM_BATTERY_STATUS_UNKNOWN
;
41 info
->battery_flag
= APM_BATTERY_FLAG_UNKNOWN
;
42 info
->units
= APM_UNITS_MINS
;
44 if (pmu_power_flags
& PMU_PWR_AC_PRESENT
)
45 info
->ac_line_status
= APM_AC_ONLINE
;
47 info
->ac_line_status
= APM_AC_OFFLINE
;
49 for (i
=0; i
<pmu_battery_count
; i
++) {
50 if (pmu_batteries
[i
].flags
& PMU_BATT_PRESENT
) {
56 percentage
+= (pmu_batteries
[i
].charge
* 100) /
57 pmu_batteries
[i
].max_charge
;
58 charge
+= pmu_batteries
[i
].charge
;
59 amperage
+= pmu_batteries
[i
].amperage
;
61 btype
= (pmu_batteries
[i
].flags
& PMU_BATT_TYPE_MASK
);
63 if ((pmu_batteries
[i
].flags
& PMU_BATT_CHARGING
))
68 info
->ac_line_status
= APM_AC_ONLINE
;
72 if (btype
== PMU_BATT_TYPE_SMART
)
73 time_units
= (charge
* 59) / (amperage
* -1);
75 time_units
= (charge
* 16440) / (amperage
* -60);
77 percentage
/= real_count
;
79 info
->battery_status
= APM_BATTERY_STATUS_CHARGING
;
80 info
->battery_flag
= APM_BATTERY_FLAG_CHARGING
;
81 } else if (percentage
<= APM_CRITICAL
) {
82 info
->battery_status
= APM_BATTERY_STATUS_CRITICAL
;
83 info
->battery_flag
= APM_BATTERY_FLAG_CRITICAL
;
84 } else if (percentage
<= APM_LOW
) {
85 info
->battery_status
= APM_BATTERY_STATUS_LOW
;
86 info
->battery_flag
= APM_BATTERY_FLAG_LOW
;
88 info
->battery_status
= APM_BATTERY_STATUS_HIGH
;
89 info
->battery_flag
= APM_BATTERY_FLAG_HIGH
;
93 info
->battery_life
= percentage
;
94 info
->time
= time_units
;
97 static int __init
apm_emu_init(void)
99 apm_get_power_status
= pmu_apm_get_power_status
;
101 printk(KERN_INFO
"apm_emu: PMU APM Emulation initialized.\n");
106 static void __exit
apm_emu_exit(void)
108 if (apm_get_power_status
== pmu_apm_get_power_status
)
109 apm_get_power_status
= NULL
;
111 printk(KERN_INFO
"apm_emu: PMU APM Emulation removed.\n");
114 module_init(apm_emu_init
);
115 module_exit(apm_emu_exit
);
117 MODULE_AUTHOR("Benjamin Herrenschmidt");
118 MODULE_DESCRIPTION("APM emulation for PowerMac");
119 MODULE_LICENSE("GPL");