Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / sh / boards / hp6xx / hp6xx_apm.c
blobeec4bed31d84a4f5fe063514c5acbb2626a692bb
1 /*
2 * bios-less APM driver for hp680
4 * Copyright 2005 (c) Andriy Skulysh <askulysh@gmail.com>
5 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
6 =======
7 * Copyright 2008 (c) Kristoffer Ericson <kristoffer.ericson@gmail.com>
8 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License.
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/interrupt.h>
17 #include <linux/apm-emulation.h>
18 #include <linux/io.h>
19 #include <asm/adc.h>
20 #include <asm/hp6xx.h>
22 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
23 #define SH7709_PGDR 0xa400012c
25 =======
26 /* percentage values */
27 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
28 #define APM_CRITICAL 10
29 #define APM_LOW 30
31 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
32 =======
33 /* resonably sane values */
34 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
35 #define HP680_BATTERY_MAX 898
36 #define HP680_BATTERY_MIN 486
37 #define HP680_BATTERY_AC_ON 1023
39 #define MODNAME "hp6x0_apm"
41 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
42 =======
43 #define PGDR 0xa400012c
45 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
46 static void hp6x0_apm_get_power_status(struct apm_power_info *info)
48 int battery, backup, charging, percentage;
49 u8 pgdr;
51 battery = adc_single(ADC_CHANNEL_BATTERY);
52 backup = adc_single(ADC_CHANNEL_BACKUP);
53 charging = adc_single(ADC_CHANNEL_CHARGE);
55 percentage = 100 * (battery - HP680_BATTERY_MIN) /
56 (HP680_BATTERY_MAX - HP680_BATTERY_MIN);
58 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
59 =======
60 /* % of full battery */
61 info->battery_life = percentage;
63 /* We want our estimates in minutes */
64 info->units = 0;
66 /* Extremely(!!) rough estimate, we will replace this with a datalist later on */
67 info->time = (2 * battery);
69 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
70 info->ac_line_status = (battery > HP680_BATTERY_AC_ON) ?
71 APM_AC_ONLINE : APM_AC_OFFLINE;
73 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
74 pgdr = ctrl_inb(SH7709_PGDR);
75 =======
76 pgdr = ctrl_inb(PGDR);
77 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
78 if (pgdr & PGDR_MAIN_BATTERY_OUT) {
79 info->battery_status = APM_BATTERY_STATUS_NOT_PRESENT;
80 info->battery_flag = 0x80;
81 } else if (charging < 8) {
82 info->battery_status = APM_BATTERY_STATUS_CHARGING;
83 info->battery_flag = 0x08;
84 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
85 info->ac_line_status = 0xff;
86 =======
87 info->ac_line_status = 0x01;
88 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
89 } else if (percentage <= APM_CRITICAL) {
90 info->battery_status = APM_BATTERY_STATUS_CRITICAL;
91 info->battery_flag = 0x04;
92 } else if (percentage <= APM_LOW) {
93 info->battery_status = APM_BATTERY_STATUS_LOW;
94 info->battery_flag = 0x02;
95 } else {
96 info->battery_status = APM_BATTERY_STATUS_HIGH;
97 info->battery_flag = 0x01;
99 <<<<<<< HEAD:arch/sh/boards/hp6xx/hp6xx_apm.c
101 info->units = 0;
102 =======
103 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sh/boards/hp6xx/hp6xx_apm.c
106 static irqreturn_t hp6x0_apm_interrupt(int irq, void *dev)
108 if (!APM_DISABLED)
109 apm_queue_event(APM_USER_SUSPEND);
111 return IRQ_HANDLED;
114 static int __init hp6x0_apm_init(void)
116 int ret;
118 ret = request_irq(HP680_BTN_IRQ, hp6x0_apm_interrupt,
119 IRQF_DISABLED, MODNAME, NULL);
120 if (unlikely(ret < 0)) {
121 printk(KERN_ERR MODNAME ": IRQ %d request failed\n",
122 HP680_BTN_IRQ);
123 return ret;
126 apm_get_power_status = hp6x0_apm_get_power_status;
128 return ret;
131 static void __exit hp6x0_apm_exit(void)
133 free_irq(HP680_BTN_IRQ, 0);
136 module_init(hp6x0_apm_init);
137 module_exit(hp6x0_apm_exit);
139 MODULE_AUTHOR("Adriy Skulysh");
140 MODULE_DESCRIPTION("hp6xx Advanced Power Management");
141 MODULE_LICENSE("GPL");