This patch adds the support for the IPAQ h1940 leds.
In order to create the amber led (used for the battery charging), the red and 
green leds are set to the same default trigger.
Also, due to hardware limitation, the blue led can only be set in blinking 
mode.


Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>

---
 arch/arm/mach-s3c2410/mach-h1940.c |    6 	6 +	0 -	0 !
 drivers/leds/Kconfig               |    6 	6 +	0 -	0 !
 drivers/leds/Makefile              |    1 	1 +	0 -	0 !
 drivers/leds/leds-h1940.c          |  169 	169 +	0 -	0 !
 4 files changed, 182 insertions(+)

Index: linux-2.6/drivers/leds/Kconfig
===================================================================
--- linux-2.6.orig/drivers/leds/Kconfig	2006-12-21 00:29:47.000000000 +0100
+++ linux-2.6/drivers/leds/Kconfig	2006-12-21 00:44:49.000000000 +0100
@@ -82,6 +82,12 @@ config LEDS_WRAP
 	help
 	  This option enables support for the PCEngines WRAP programmable LEDs.
 
+config LEDS_H1940
+	bool "LED Support for iPAQ H1940 device"
+	depends LEDS_CLASS && ARCH_H1940
+	help
+	  This option enables support for the LEDs on the h1940.
+
 comment "LED Triggers"
 
 config LEDS_TRIGGERS
Index: linux-2.6/drivers/leds/Makefile
===================================================================
--- linux-2.6.orig/drivers/leds/Makefile	2006-12-21 00:29:47.000000000 +0100
+++ linux-2.6/drivers/leds/Makefile	2006-12-21 00:42:50.000000000 +0100
@@ -14,6 +14,7 @@ obj-$(CONFIG_LEDS_S3C24XX)		+= leds-s3c2
 obj-$(CONFIG_LEDS_AMS_DELTA)		+= leds-ams-delta.o
 obj-$(CONFIG_LEDS_NET48XX)		+= leds-net48xx.o
 obj-$(CONFIG_LEDS_WRAP)			+= leds-wrap.o
+obj-$(CONFIG_LEDS_H1940)		+= leds-h1940.o
 
 # LED Triggers
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
Index: linux-2.6/arch/arm/mach-s3c2410/mach-h1940.c
===================================================================
--- linux-2.6.orig/arch/arm/mach-s3c2410/mach-h1940.c	2006-12-21 00:29:47.000000000 +0100
+++ linux-2.6/arch/arm/mach-s3c2410/mach-h1940.c	2006-12-21 00:44:17.000000000 +0100
@@ -295,6 +295,11 @@ static struct s3c_butt_mach_info h1940_b
 	.size = ARRAY_SIZE(h1940_butts),
 };
 
+static struct platform_device s3c_device_leds = {
+	.name             = "h1940-leds",
+	.id               = -1,
+};
+
 static struct platform_device *h1940_devices[] __initdata = {
 	&s3c_device_usb,
 	&s3c_device_lcd,
@@ -307,6 +312,7 @@ static struct platform_device *h1940_dev
 	&s3c_device_ts,
 	&s3c_device_buttons,
 	&s3c_device_nand,
+	&s3c_device_leds,
 };
 
 static struct s3c24xx_board h1940_board __initdata = {
Index: linux-2.6/drivers/leds/leds-h1940.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6/drivers/leds/leds-h1940.c	2006-12-21 00:42:50.000000000 +0100
@@ -0,0 +1,169 @@
+/*
+ * drivers/leds/h1940-leds.c
+ * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
+ *
+ * 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.
+ *
+ *	    H1940 leds driver
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/ctype.h>
+#include <linux/leds.h>
+#include <asm/arch/regs-gpio.h>
+#include <asm/arch/hardware.h>
+#include <asm/arch/h1940-latch.h>
+
+#define DRV_NAME              "h1940-leds"
+
+/*
+ * Gree led.
+ */
+void h1940_greenled_set(struct led_classdev *led_dev, enum led_brightness value)
+{
+	switch (value) {
+		case LED_HALF:
+			h1940_latch_control(0,H1940_LATCH_LED_FLASH);
+			s3c2410_gpio_setpin(S3C2410_GPA7,1);
+			break;
+		case LED_FULL:
+			h1940_latch_control(0,H1940_LATCH_LED_GREEN);
+			s3c2410_gpio_setpin(S3C2410_GPA7,1);
+			break;
+		default:
+		case LED_OFF:
+			h1940_latch_control(H1940_LATCH_LED_FLASH,0);
+			h1940_latch_control(H1940_LATCH_LED_GREEN,0);
+			s3c2410_gpio_setpin(S3C2410_GPA7,0);
+			break;
+	}
+}
+
+static struct led_classdev h1940_greenled = {
+	.name			= "h1940:green",
+	.brightness_set		= h1940_greenled_set,
+	.default_trigger	= "h1940-charger",
+};
+
+/*
+ * Red led.
+ */
+void h1940_redled_set(struct led_classdev *led_dev, enum led_brightness value)
+{
+	switch (value) {
+		case LED_HALF:
+			h1940_latch_control(0,H1940_LATCH_LED_FLASH);
+			s3c2410_gpio_setpin(S3C2410_GPA1,1);
+			break;
+		case LED_FULL:
+			h1940_latch_control(0,H1940_LATCH_LED_RED);
+			s3c2410_gpio_setpin(S3C2410_GPA1,1);
+			break;
+		default:
+		case LED_OFF:
+			h1940_latch_control(H1940_LATCH_LED_FLASH,0);
+			h1940_latch_control(H1940_LATCH_LED_RED,0);
+			s3c2410_gpio_setpin(S3C2410_GPA1,0);
+			break;
+	}
+}
+
+static struct led_classdev h1940_redled = {
+	.name			= "h1940:red",
+	.brightness_set		= h1940_redled_set,
+	.default_trigger	= "h1940-charger",
+};
+
+/*
+ * Blue led.
+ * NB: it's called blue led, but it can only be blue flashing led
+ */
+void h1940_blueled_set(struct led_classdev *led_dev, enum led_brightness value)
+{
+	if (value) {
+		/* flashing Blue */
+		h1940_latch_control(0,H1940_LATCH_LED_FLASH);
+		s3c2410_gpio_setpin(S3C2410_GPA3,1);
+	}
+	else {
+		h1940_latch_control(H1940_LATCH_LED_FLASH,0);
+		s3c2410_gpio_setpin(S3C2410_GPA3,0);
+	}
+
+}
+
+static struct led_classdev h1940_blueled = {
+	.name			= "h1940:blue",
+	.brightness_set		= h1940_blueled_set,
+	.default_trigger	= "h1940-bluetooth",
+};
+
+static int __init h1940leds_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = led_classdev_register(&pdev->dev, &h1940_greenled);
+
+	if (ret)
+		goto err_green;
+
+	ret = led_classdev_register(&pdev->dev, &h1940_redled);
+
+	if (ret)
+		goto err_red;
+
+	ret = led_classdev_register(&pdev->dev, &h1940_blueled);
+
+	if (ret)
+		goto err_blue;
+
+	return 0;
+
+err_blue:
+	led_classdev_unregister(&h1940_redled);
+err_red:
+	led_classdev_unregister(&h1940_greenled);
+err_green:
+	return ret;
+}
+
+static int h1940leds_remove(struct platform_device *pdev)
+{
+	led_classdev_unregister(&h1940_greenled);
+	led_classdev_unregister(&h1940_redled);
+	led_classdev_unregister(&h1940_blueled);
+	return 0;
+}
+
+
+static struct platform_driver h1940leds_driver = {
+	.driver		= {
+		.name	= DRV_NAME,
+	},
+	.probe		= h1940leds_probe,
+	.remove		= h1940leds_remove,
+};
+
+
+static int __init h1940leds_init(void)
+{
+	return platform_driver_register(&h1940leds_driver);
+}
+
+static void __exit h1940leds_exit(void)
+{
+	platform_driver_unregister(&h1940leds_driver);
+}
+
+module_init(h1940leds_init);
+module_exit(h1940leds_exit);
+
+MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>");
+MODULE_DESCRIPTION("LED driver for the iPAQ H1940");
+MODULE_LICENSE("GPL");
