GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / arch / sh / boards / mach-hp6xx / hp6xx_apm.c
blobb49535c0ddd9f528d90eacf6fdfc82209294e1f5
1 /*
2 * bios-less APM driver for hp680
4 * Copyright 2005 (c) Andriy Skulysh <askulysh@gmail.com>
5 * Copyright 2008 (c) Kristoffer Ericson <kristoffer.ericson@gmail.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License.
9 */
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/interrupt.h>
14 #include <linux/apm-emulation.h>
15 #include <linux/io.h>
16 #include <asm/adc.h>
17 #include <mach/hp6xx.h>
19 /* percentage values */
20 #define APM_CRITICAL 10
21 #define APM_LOW 30
23 /* resonably sane values */
24 #define HP680_BATTERY_MAX 898
25 #define HP680_BATTERY_MIN 486
26 #define HP680_BATTERY_AC_ON 1023
28 #define MODNAME "hp6x0_apm"
30 #define PGDR 0xa400012c
32 static void hp6x0_apm_get_power_status(struct apm_power_info *info)
34 int battery, backup, charging, percentage;
35 u8 pgdr;
37 battery = adc_single(ADC_CHANNEL_BATTERY);
38 backup = adc_single(ADC_CHANNEL_BACKUP);
39 charging = adc_single(ADC_CHANNEL_CHARGE);
41 percentage = 100 * (battery - HP680_BATTERY_MIN) /
42 (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
44 /* % of full battery */
45 info->battery_life = percentage;
47 /* We want our estimates in minutes */
48 info->units = 0;
50 /* Extremely(!!) rough estimate, we will replace this with a datalist later on */
51 info->time = (2 * battery);
53 info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
54 APM_AC_ONLINE : APM_AC_OFFLINE;
56 pgdr = __raw_readb(PGDR);
57 if (pgdr & PGDR_MAIN_BATTERY_OUT) {
58 info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
59 info->battery_flag = 0x80;
60 } else if (charging < 8) {
61 info->battery_status = APM_BATTERY_STATUS_CHARGING;
62 info->battery_flag = 0x08;
63 info->ac_line_status = 0x01;
64 } else if (percentage <= APM_CRITICAL) {
65 info->battery_status = APM_BATTERY_STATUS_CRITICAL;
66 info->battery_flag = 0x04;
67 } else if (percentage <= APM_LOW) {
68 info->battery_status = APM_BATTERY_STATUS_LOW;
69 info->battery_flag = 0x02;
70 } else {
71 info->battery_status = APM_BATTERY_STATUS_HIGH;
72 info->battery_flag = 0x01;
76 static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)
78 if (!APM_DISABLED)
79 apm_queue_event(APM_USER_SUSPEND);
81 return IRQ_HANDLED;
84 static int __init hp6x0_apm_init(void)
86 int ret;
88 ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
89 IRQF_DISABLED, MODNAME, NULL);
90 if (unlikely(ret < 0)) {
91 printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
92 HP680_BTN_IRQ);
93 return ret;
96 apm_get_power_status = hp6x0_apm_get_power_status;
98 return ret;
101 static void __exit hp6x0_apm_exit(void)
103 free_irq(HP680_BTN_IRQ, 0);
106 module_init(hp6x0_apm_init);
107 module_exit(hp6x0_apm_exit);
109 MODULE_AUTHOR("Adriy Skulysh");
110 MODULE_DESCRIPTION("hp6xx Advanced Power Management");
111 MODULE_LICENSE("GPL");