aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sh/boards
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2007-01-24 07:56:20 -0500
committerRalf Baechle <ralf@linux-mips.org>2007-02-09 12:08:58 -0500
commit0a9b0db19262dbb09f3a34195e68cafd5dc3fa10 (patch)
tree4fc4cd76617f8899494ae1f2b58aac4afe114490 /arch/sh/boards
parent2116245ee121af820225834e9695005ab07d1e84 (diff)
[APM] SH: Convert to use shared APM emulation.
Signed-off-by: Paul Mundt <lethal@linux-sh.org> Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/sh/boards')
-rw-r--r--arch/sh/boards/hp6xx/hp6xx_apm.c68
1 files changed, 24 insertions, 44 deletions
diff --git a/arch/sh/boards/hp6xx/hp6xx_apm.c b/arch/sh/boards/hp6xx/hp6xx_apm.c
index d146cdaa0b8b..d1c1460c8a06 100644
--- a/arch/sh/boards/hp6xx/hp6xx_apm.c
+++ b/arch/sh/boards/hp6xx/hp6xx_apm.c
@@ -7,12 +7,11 @@
7 * modify it under the terms of the GNU General Public License. 7 * modify it under the terms of the GNU General Public License.
8 */ 8 */
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/apm_bios.h>
11#include <linux/kernel.h> 10#include <linux/kernel.h>
12#include <linux/init.h> 11#include <linux/init.h>
13#include <linux/interrupt.h> 12#include <linux/interrupt.h>
14#include <asm/io.h> 13#include <linux/apm-emulation.h>
15#include <asm/apm.h> 14#include <linux/io.h>
16#include <asm/adc.h> 15#include <asm/adc.h>
17#include <asm/hp6xx.h> 16#include <asm/hp6xx.h>
18 17
@@ -27,60 +26,41 @@
27 26
28#define MODNAME "hp6x0_apm" 27#define MODNAME "hp6x0_apm"
29 28
30static int hp6x0_apm_get_info(char *buf, char **start, off_t fpos, int length) 29static void hp6x0_apm_get_power_status(struct apm_power_info *info)
31{ 30{
31 int battery, backup, charging, percentage;
32 u8 pgdr; 32 u8 pgdr;
33 char *p;
34 int battery_status;
35 int battery_flag;
36 int ac_line_status;
37 int time_units = APM_BATTERY_LIFE_UNKNOWN;
38 33
39 int battery = adc_single(ADC_CHANNEL_BATTERY); 34 battery = adc_single(ADC_CHANNEL_BATTERY);
40 int backup = adc_single(ADC_CHANNEL_BACKUP); 35 backup = adc_single(ADC_CHANNEL_BACKUP);
41 int charging = adc_single(ADC_CHANNEL_CHARGE); 36 charging = adc_single(ADC_CHANNEL_CHARGE);
42 int percentage;
43 37
44 percentage = 100 * (battery - HP680_BATTERY_MIN) / 38 percentage = 100 * (battery - HP680_BATTERY_MIN) /
45 (HP680_BATTERY_MAX - HP680_BATTERY_MIN); 39 (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
46 40
47 ac_line_status = (battery > HP680_BATTERY_AC_ON) ? 41 info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
48 APM_AC_ONLINE : APM_AC_OFFLINE; 42 APM_AC_ONLINE : APM_AC_OFFLINE;
49 43
50 p = buf;
51
52 pgdr = ctrl_inb(SH7709_PGDR); 44 pgdr = ctrl_inb(SH7709_PGDR);
53 if (pgdr & PGDR_MAIN_BATTERY_OUT) { 45 if (pgdr & PGDR_MAIN_BATTERY_OUT) {
54 battery_status = APM_BATTERY_STATUS_NOT_PRESENT; 46 info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
55 battery_flag = 0x80; 47 info->battery_flag = 0x80;
56 percentage = -1; 48 } else if (charging < 8) {
57 } else if (charging < 8 ) { 49 info->battery_status = APM_BATTERY_STATUS_CHARGING;
58 battery_status = APM_BATTERY_STATUS_CHARGING; 50 info->battery_flag = 0x08;
59 battery_flag = 0x08; 51 info->ac_line_status = 0xff;
60 ac_line_status = 0xff;
61 } else if (percentage <= APM_CRITICAL) { 52 } else if (percentage <= APM_CRITICAL) {
62 battery_status = APM_BATTERY_STATUS_CRITICAL; 53 info->battery_status = APM_BATTERY_STATUS_CRITICAL;
63 battery_flag = 0x04; 54 info->battery_flag = 0x04;
64 } else if (percentage <= APM_LOW) { 55 } else if (percentage <= APM_LOW) {
65 battery_status = APM_BATTERY_STATUS_LOW; 56 info->battery_status = APM_BATTERY_STATUS_LOW;
66 battery_flag = 0x02; 57 info->battery_flag = 0x02;
67 } else { 58 } else {
68 battery_status = APM_BATTERY_STATUS_HIGH; 59 info->battery_status = APM_BATTERY_STATUS_HIGH;
69 battery_flag = 0x01; 60 info->battery_flag = 0x01;
70 } 61 }
71 62
72 p += sprintf(p, "1.0 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n", 63 info->units = 0;
73 APM_32_BIT_SUPPORT,
74 ac_line_status,
75 battery_status,
76 battery_flag,
77 percentage,
78 time_units,
79 "min");
80 p += sprintf(p, "bat=%d backup=%d charge=%d\n",
81 battery, backup, charging);
82
83 return p - buf;
84} 64}
85 65
86static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev) 66static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)
@@ -96,14 +76,14 @@ static int __init hp6x0_apm_init(void)
96 int ret; 76 int ret;
97 77
98 ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt, 78 ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
99 IRQF_DISABLED, MODNAME, 0); 79 IRQF_DISABLED, MODNAME, NULL);
100 if (unlikely(ret < 0)) { 80 if (unlikely(ret < 0)) {
101 printk(KERN_ERR MODNAME ": IRQ %d request failed\n", 81 printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
102 HP680_BTN_IRQ); 82 HP680_BTN_IRQ);
103 return ret; 83 return ret;
104 } 84 }
105 85
106 apm_get_info = hp6x0_apm_get_info; 86 apm_get_power_status = hp6x0_apm_get_power_status;
107 87
108 return ret; 88 return ret;
109} 89}
@@ -111,7 +91,7 @@ static int __init hp6x0_apm_init(void)
111static void __exit hp6x0_apm_exit(void) 91static void __exit hp6x0_apm_exit(void)
112{ 92{
113 free_irq(HP680_BTN_IRQ, 0); 93 free_irq(HP680_BTN_IRQ, 0);
114 apm_get_info = 0; 94 apm_get_info = NULL;
115} 95}
116 96
117module_init(hp6x0_apm_init); 97module_init(hp6x0_apm_init);