2 * bios-less APM driver for hp680
4 * Copyright 2005 (c) Andriy Skulysh <askulysh@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License.
9 #include <linux/module.h>
10 #include <linux/apm_bios.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
17 #include <asm/hp6xx/hp6xx.h>
19 #define SH7709_PGDR 0xa400012c
21 #define APM_CRITICAL 10
24 #define HP680_BATTERY_MAX 875
25 #define HP680_BATTERY_MIN 600
26 #define HP680_BATTERY_AC_ON 900
28 #define MODNAME "hp6x0_apm"
30 static int hp6x0_apm_get_info(char *buf, char **start, off_t fpos, int length)
37 int time_units = APM_BATTERY_LIFE_UNKNOWN;
39 int battery = adc_single(ADC_CHANNEL_BATTERY);
40 int backup = adc_single(ADC_CHANNEL_BACKUP);
41 int charging = adc_single(ADC_CHANNEL_CHARGE);
44 percentage = 100 * (battery - HP680_BATTERY_MIN) /
45 (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
47 ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
48 APM_AC_ONLINE : APM_AC_OFFLINE;
52 pgdr = ctrl_inb(SH7709_PGDR);
53 if (pgdr & PGDR_MAIN_BATTERY_OUT) {
54 battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
57 } else if (charging < 8 ) {
58 battery_status = APM_BATTERY_STATUS_CHARGING;
60 ac_line_status = 0xff;
61 } else if (percentage <= APM_CRITICAL) {
62 battery_status = APM_BATTERY_STATUS_CRITICAL;
64 } else if (percentage <= APM_LOW) {
65 battery_status = APM_BATTERY_STATUS_LOW;
68 battery_status = APM_BATTERY_STATUS_HIGH;
72 p += sprintf(p, "1.0 1.2 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
80 p += sprintf(p, "bat=%d backup=%d charge=%d\n",
81 battery, backup, charging);
86 static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev, struct pt_regs *regs)
89 apm_queue_event(APM_USER_SUSPEND);
94 static int __init hp6x0_apm_init(void)
98 ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
99 SA_INTERRUPT, MODNAME, 0);
100 if (unlikely(ret < 0)) {
101 printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
106 apm_get_info = hp6x0_apm_get_info;
111 static void __exit hp6x0_apm_exit(void)
113 free_irq(HP680_BTN_IRQ, 0);
117 module_init(hp6x0_apm_init);
118 module_exit(hp6x0_apm_exit);
120 MODULE_AUTHOR("Adriy Skulysh");
121 MODULE_DESCRIPTION("hp6xx Advanced Power Management");
122 MODULE_LICENSE("GPL");