hh.org updates
[hh.org.git] / arch / arm / mach-pxa / h3900 / h3900_battery.c
blobba08e971186230531f2924ae93d1fa1d52fbefdb
1 /*
2 * Battery driver for iPAQ h3900
4 * Copyright 2005 Phil Blundell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/tty.h>
15 #include <linux/sched.h>
16 #include <linux/delay.h>
17 #include <linux/pm.h>
18 #include <linux/err.h>
19 #include <linux/interrupt.h>
20 #include <linux/platform_device.h>
22 #include <asm/mach-types.h>
23 #include <asm/hardware.h>
24 #include <asm/apm.h>
25 #include <asm/arch/pxa-regs.h>
27 #include <asm/mach/arch.h>
28 #include <asm/arch/h3900-asic.h>
29 #include <asm/arch/h3900-gpio.h>
31 #include <linux/soc/asic3_base.h>
33 static int ac_in;
35 static int
36 h3900_ac_power (void)
38 return (GPLR0 & GPIO_H3900_AC_IN_N) ? 0 : 1;
41 static void
42 h3900_apm_get_power_status (struct apm_power_info *info)
44 info->ac_line_status = ac_in ? APM_AC_ONLINE : APM_AC_OFFLINE;
47 static irqreturn_t
48 h3900_ac_in_isr (int irq, void *dev_id, struct pt_regs *regs)
50 ac_in = h3900_ac_power ();
52 return IRQ_HANDLED;
55 static int
56 h3900_battery_init (void)
58 int result;
60 asic3_set_gpio_out_b(&h3900_asic3.dev,
61 GPIO3_CH_TIMER, GPIO3_CH_TIMER);
63 result = request_irq (IRQ_GPIO (GPIO_NR_H3900_AC_IN_N), h3900_ac_in_isr,
64 SA_INTERRUPT | SA_SAMPLE_RANDOM, "AC presence", NULL);
65 if (result) {
66 printk (KERN_CRIT "%s: unable to grab AC in IRQ\n", __FUNCTION__);
67 return result;
70 apm_get_power_status = h3900_apm_get_power_status;
72 return 0;
75 static void
76 h3900_battery_exit (void)
78 free_irq (IRQ_GPIO (GPIO_NR_H3900_AC_IN_N), NULL);
79 apm_get_power_status = NULL;
82 module_init (h3900_battery_init)
83 module_exit (h3900_battery_exit)