Skip to content

Commit 0a9b0db

Browse files
pmundtralfbaechle
authored andcommitted
[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>
1 parent 2116245 commit 0a9b0db

5 files changed

Lines changed: 28 additions & 632 deletions

File tree

‎arch/sh/Kconfig‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ config GENERIC_IOMAP
4848
config GENERIC_TIME
4949
def_bool n
5050

51+
config SYS_SUPPORTS_APM_EMULATION
52+
bool
53+
5154
config ARCH_MAY_HAVE_PC_FDC
5255
bool
5356

@@ -126,6 +129,7 @@ config SH_7751_SYSTEMH
126129

127130
config SH_HP6XX
128131
bool "HP6XX"
132+
select SYS_SUPPORTS_APM_EMULATION
129133
help
130134
Select HP6XX if configuring for a HP jornada HP6xx.
131135
More information (hardware only) at
@@ -694,9 +698,6 @@ depends on EXPERIMENTAL
694698

695699
source kernel/power/Kconfig
696700

697-
config APM
698-
bool "Advanced Power Management Emulation"
699-
depends on PM
700701
endmenu
701702

702703
source "net/Kconfig"

‎arch/sh/boards/hp6xx/hp6xx_apm.c‎

Lines changed: 24 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
* modify it under the terms of the GNU General Public License.
88
*/
99
#include <linux/module.h>
10-
#include <linux/apm_bios.h>
1110
#include <linux/kernel.h>
1211
#include <linux/init.h>
1312
#include <linux/interrupt.h>
14-
#include <asm/io.h>
15-
#include <asm/apm.h>
13+
#include <linux/apm-emulation.h>
14+
#include <linux/io.h>
1615
#include <asm/adc.h>
1716
#include <asm/hp6xx.h>
1817

@@ -27,60 +26,41 @@
2726

2827
#define MODNAME "hp6x0_apm"
2928

30-
static int hp6x0_apm_get_info(char *buf, char **start, off_t fpos, int length)
29+
static void hp6x0_apm_get_power_status(struct apm_power_info *info)
3130
{
31+
int battery, backup, charging, percentage;
3232
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;
3833

39-
int battery = adc_single(ADC_CHANNEL_BATTERY);
40-
int backup = adc_single(ADC_CHANNEL_BACKUP);
41-
int charging = adc_single(ADC_CHANNEL_CHARGE);
42-
int percentage;
34+
battery = adc_single(ADC_CHANNEL_BATTERY);
35+
backup = adc_single(ADC_CHANNEL_BACKUP);
36+
charging = adc_single(ADC_CHANNEL_CHARGE);
4337

4438
percentage = 100 * (battery - HP680_BATTERY_MIN) /
4539
(HP680_BATTERY_MAX - HP680_BATTERY_MIN);
4640

47-
ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
41+
info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
4842
APM_AC_ONLINE : APM_AC_OFFLINE;
4943

50-
p = buf;
51-
5244
pgdr = ctrl_inb(SH7709_PGDR);
5345
if (pgdr & PGDR_MAIN_BATTERY_OUT) {
54-
battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
55-
battery_flag = 0x80;
56-
percentage = -1;
57-
} else if (charging < 8 ) {
58-
battery_status = APM_BATTERY_STATUS_CHARGING;
59-
battery_flag = 0x08;
60-
ac_line_status = 0xff;
46+
info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
47+
info->battery_flag = 0x80;
48+
} else if (charging < 8) {
49+
info->battery_status = APM_BATTERY_STATUS_CHARGING;
50+
info->battery_flag = 0x08;
51+
info->ac_line_status = 0xff;
6152
} else if (percentage <= APM_CRITICAL) {
62-
battery_status = APM_BATTERY_STATUS_CRITICAL;
63-
battery_flag = 0x04;
53+
info->battery_status = APM_BATTERY_STATUS_CRITICAL;
54+
info->battery_flag = 0x04;
6455
} else if (percentage <= APM_LOW) {
65-
battery_status = APM_BATTERY_STATUS_LOW;
66-
battery_flag = 0x02;
56+
info->battery_status = APM_BATTERY_STATUS_LOW;
57+
info->battery_flag = 0x02;
6758
} else {
68-
battery_status = APM_BATTERY_STATUS_HIGH;
69-
battery_flag = 0x01;
59+
info->battery_status = APM_BATTERY_STATUS_HIGH;
60+
info->battery_flag = 0x01;
7061
}
7162

72-
p += sprintf(p, "1.0 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
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;
63+
info->units = 0;
8464
}
8565

8666
static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)
@@ -96,22 +76,22 @@ static int __init hp6x0_apm_init(void)
9676
int ret;
9777

9878
ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
99-
IRQF_DISABLED, MODNAME, 0);
79+
IRQF_DISABLED, MODNAME, NULL);
10080
if (unlikely(ret < 0)) {
10181
printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
10282
HP680_BTN_IRQ);
10383
return ret;
10484
}
10585

106-
apm_get_info = hp6x0_apm_get_info;
86+
apm_get_power_status = hp6x0_apm_get_power_status;
10787

10888
return ret;
10989
}
11090

11191
static void __exit hp6x0_apm_exit(void)
11292
{
11393
free_irq(HP680_BTN_IRQ, 0);
114-
apm_get_info = 0;
94+
apm_get_info = NULL;
11595
}
11696

11797
module_init(hp6x0_apm_init);

‎arch/sh/kernel/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ obj-$(CONFIG_SH_CPU_FREQ) += cpufreq.o
1919
obj-$(CONFIG_MODULES) += module.o
2020
obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
2121
obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o
22-
obj-$(CONFIG_APM) += apm.o
2322
obj-$(CONFIG_PM) += pm.o
2423
obj-$(CONFIG_STACKTRACE) += stacktrace.o

0 commit comments

Comments
 (0)