---
 arch/arm/mach-s3c2410/Makefile     |    2 	1 +	1 -	0 !
 arch/arm/mach-s3c2410/h1940-batt.c |  162 	162 +	0 -	0 !
 arch/arm/mach-s3c2410/mach-h1940.c |    6 	6 +	0 -	0 !
 3 files changed, 169 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/arm/mach-s3c2410/Makefile
===================================================================
--- linux-2.6.orig/arch/arm/mach-s3c2410/Makefile	2006-12-10 23:50:15.000000000 +0100
+++ linux-2.6/arch/arm/mach-s3c2410/Makefile	2006-12-11 00:38:09.000000000 +0100
@@ -77,7 +77,7 @@ obj-$(CONFIG_MACH_AML_M5900)	+= mach-aml
 obj-$(CONFIG_MACH_ANUBIS)	+= mach-anubis.o
 obj-$(CONFIG_MACH_OSIRIS)	+= mach-osiris.o
 obj-$(CONFIG_ARCH_BAST)		+= mach-bast.o usb-simtec.o
-obj-$(CONFIG_ARCH_H1940)	+= mach-h1940.o h1940-bluetooth.o
+obj-$(CONFIG_ARCH_H1940)	+= mach-h1940.o h1940-bluetooth.o h1940-batt.o
 obj-$(CONFIG_MACH_N30)		+= mach-n30.o
 obj-$(CONFIG_ARCH_SMDK2410)	+= mach-smdk2410.o
 obj-$(CONFIG_MACH_SMDK2413)	+= mach-smdk2413.o
Index: linux-2.6/arch/arm/mach-s3c2410/h1940-batt.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/arch/arm/mach-s3c2410/h1940-batt.c	2006-12-11 00:38:45.000000000 +0100
@@ -0,0 +1,162 @@
+/*
+ * arch/arm/mach-s3c2410/h1940-batt.c
+ *	Copyright (c) Arnaud Patard
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License.  See the file COPYING in the main directory of this archive for
+ * more details.
+ *
+ *	    iPAQ H1940 battery controler driver
+ *
+ * ChangeLog
+ *   2006-03-22: RTP
+ *   	* First version
+ *
+ */
+
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/leds.h>
+#include <asm/io.h>
+#include <asm/irq.h>
+#include <asm/apm.h>
+
+#include <asm/arch/regs-gpio.h>
+
+#ifdef CONFIG_LEDS_H1940
+DEFINE_LED_TRIGGER(charger_led_trigger);
+#endif
+
+static irqreturn_t h1940batt_cable(int irq, void *dev_id)
+{
+	/* the GPF2 value is in inverse logic. 1 is for "not there"
+	 **/
+	int is_plugged = !s3c2410_gpio_getpin(S3C2410_GPF2);
+
+	printk(KERN_INFO "Power cable %s\n",\
+			is_plugged ? "plugged" : "unplugged" );
+
+	if (is_plugged) {
+		/* configure GPF3 to get an interrupt when battery charged */
+		s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_EINT3);
+#ifdef CONFIG_LEDS_H1940
+		/* amber led blinking */
+                led_trigger_event(charger_led_trigger, LED_HALF);
+#endif
+	}
+	else {
+#ifdef CONFIG_LEDS_H1940
+                led_trigger_event(charger_led_trigger, LED_OFF);
+#endif
+	}
+
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t h1940batt_charger(int irq, void *dev_id)
+{
+	int in_progress = s3c2410_gpio_getpin(S3C2410_GPF3);
+
+	if (in_progress) {
+		/* in theory we may get there...
+		 * but tests tends to say that we never get there
+		 **/
+		printk(KERN_INFO "charge in progress\n");
+	}
+	else {
+		printk(KERN_INFO "charged\n");
+#ifdef CONFIG_LEDS_H1940
+                led_trigger_event(charger_led_trigger, LED_FULL);
+#endif
+		/*
+		 * workaround :
+		 * setting here to INP to prevent a loop charged/charge in progress
+		 * when there's no battery
+		 **/
+		s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_INP);
+	}
+
+	return IRQ_HANDLED;
+}
+
+extern void (*apm_get_power_status)(struct apm_power_info *);
+
+static void h1940_apm_get_power_status(struct apm_power_info *info)
+{
+	int is_plugged = !s3c2410_gpio_getpin(S3C2410_GPF2);
+	int in_progress = s3c2410_gpio_getpin(S3C2410_GPF3);
+
+	if (is_plugged)
+		info->ac_line_status = APM_AC_ONLINE;
+	else
+		info->ac_line_status = APM_AC_OFFLINE;
+
+	if (in_progress) {
+		info->battery_status = APM_BATTERY_STATUS_CHARGING;
+		info->battery_flag = (1 << info->battery_status);
+	}
+	else {
+		info->battery_status = APM_BATTERY_STATUS_UNKNOWN;
+		info->battery_flag = APM_BATTERY_FLAG_UNKNOWN;
+	}
+}
+
+
+static int __init h1940batt_probe(struct platform_device *pdev)
+{
+	s3c2410_gpio_cfgpin(S3C2410_GPF2, S3C2410_GPF2_EINT2);
+	request_irq (IRQ_EINT2, h1940batt_cable,\
+				SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,\
+				pdev->name, NULL);
+
+	s3c2410_gpio_cfgpin(S3C2410_GPF3, S3C2410_GPF3_INP);
+	request_irq (IRQ_EINT3, h1940batt_charger,\
+				SA_INTERRUPT | SA_TRIGGER_RISING | SA_TRIGGER_FALLING,\
+				pdev->name, NULL);
+
+#ifdef CONFIG_LEDS_H1940
+        led_trigger_register_simple("h1940-charger", &charger_led_trigger);
+#endif
+	apm_get_power_status = h1940_apm_get_power_status;
+
+	printk(KERN_INFO "h1940-batt successfully loaded\n");
+
+	return 0;
+}
+
+static int h1940batt_remove(struct platform_device *pdev)
+{
+#ifdef CONFIG_LEDS_H1940
+        led_trigger_unregister_simple(charger_led_trigger);
+#endif
+	disable_irq(S3C2410_GPF2);
+	disable_irq(S3C2410_GPF3);
+
+	return 0;
+}
+
+static struct platform_driver h1940batt_driver = {
+	.driver		= {
+		.name	= "h1940-batt",
+	},
+	.probe		= h1940batt_probe,
+	.remove		= h1940batt_remove,
+};
+
+
+static int __init h1940batt_init(void)
+{
+	return platform_driver_register(&h1940batt_driver);
+}
+
+static void __exit h1940batt_exit(void)
+{
+	platform_driver_unregister(&h1940batt_driver);
+}
+
+module_init(h1940batt_init);
+module_exit(h1940batt_exit);
+
+MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
+MODULE_DESCRIPTION("iPAQ H1940 battery controler driver");
+MODULE_LICENSE("GPL");
Index: linux-2.6/arch/arm/mach-s3c2410/mach-h1940.c
===================================================================
--- linux-2.6.orig/arch/arm/mach-s3c2410/mach-h1940.c	2006-12-10 23:50:15.000000000 +0100
+++ linux-2.6/arch/arm/mach-s3c2410/mach-h1940.c	2006-12-11 00:38:09.000000000 +0100
@@ -287,6 +287,11 @@ static struct platform_device s3c_device
 	.id               = -1,
 };
 
+static struct platform_device s3c_device_batt = {
+	.name             = "h1940-batt",
+	.id               = -1,
+};
+
 static struct platform_device *h1940_devices[] __initdata = {
 	&s3c_device_usb,
 	&s3c_device_lcd,
@@ -301,6 +306,7 @@ static struct platform_device *h1940_dev
 	&s3c_device_nand,
 	&s3c_device_leds,
 	&s3c_device_bluetooth,
+	&s3c_device_batt,
 };
 
 static struct s3c24xx_board h1940_board __initdata = {
