]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[ARM] 4981/1: [KS8695] Simple LED driver
authorAndrew Victor <linux@maxim.org.za>
Tue, 15 Apr 2008 20:13:33 +0000 (21:13 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 17 Apr 2008 14:58:25 +0000 (15:58 +0100)
Simple gpio-connected LED driver for KS8695 platforms.
(Based on old AT91 LED driver)

Signed-off-by: Andrew Victor <linux@maxim.org.za>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mach-ks8695/Makefile
arch/arm/mach-ks8695/devices.c
arch/arm/mach-ks8695/leds.c [new file with mode: 0644]
include/asm-arm/arch-ks8695/devices.h

index 730a3af12c985f53467c6281209f864dc9e5cd74..ade42b73afbb2cea2c6c5722be88a2904af65e78 100644 (file)
@@ -11,5 +11,8 @@ obj-                          :=
 # PCI support is optional
 obj-$(CONFIG_PCI)              += pci.o
 
+# LEDs
+obj-$(CONFIG_LEDS)             += leds.o
+
 # Board-specific support
 obj-$(CONFIG_MACH_KS8695)      += board-micrel.o
index 386593f8ac65b8476bba078a666a55cb3f951be0..3db2ec61d06f5f5206bfa46e935712bfc1abf382 100644 (file)
@@ -176,6 +176,27 @@ static void __init ks8695_add_device_watchdog(void) {}
 #endif
 
 
+/* --------------------------------------------------------------------
+ *  LEDs
+ * -------------------------------------------------------------------- */
+
+#if defined(CONFIG_LEDS)
+short ks8695_leds_cpu = -1;
+short ks8695_leds_timer = -1;
+
+void __init ks8695_init_leds(u8 cpu_led, u8 timer_led)
+{
+       /* Enable GPIO to access the LEDs */
+       gpio_direction_output(cpu_led, 1);
+       gpio_direction_output(timer_led, 1);
+
+       ks8695_leds_cpu   = cpu_led;
+       ks8695_leds_timer = timer_led;
+}
+#else
+void __init ks8695_init_leds(u8 cpu_led, u8 timer_led) {}
+#endif
+
 /* -------------------------------------------------------------------- */
 
 /*
diff --git a/arch/arm/mach-ks8695/leds.c b/arch/arm/mach-ks8695/leds.c
new file mode 100644 (file)
index 0000000..d61762a
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * LED driver for KS8695-based boards.
+ *
+ * Copyright (C) Andrew Victor
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+
+#include <asm/mach-types.h>
+#include <asm/leds.h>
+#include <asm/arch/devices.h>
+#include <asm/arch/gpio.h>
+
+
+static inline void ks8695_led_on(unsigned int led)
+{
+       gpio_set_value(led, 0);
+}
+
+static inline void ks8695_led_off(unsigned int led)
+{
+       gpio_set_value(led, 1);
+}
+
+static inline void ks8695_led_toggle(unsigned int led)
+{
+       unsigned long is_off = gpio_get_value(led);
+       if (is_off)
+               ks8695_led_on(led);
+       else
+               ks8695_led_off(led);
+}
+
+
+/*
+ * Handle LED events.
+ */
+static void ks8695_leds_event(led_event_t evt)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+
+       switch(evt) {
+       case led_start:         /* System startup */
+               ks8695_led_on(ks8695_leds_cpu);
+               break;
+
+       case led_stop:          /* System stop / suspend */
+               ks8695_led_off(ks8695_leds_cpu);
+               break;
+
+#ifdef CONFIG_LEDS_TIMER
+       case led_timer:         /* Every 50 timer ticks */
+               ks8695_led_toggle(ks8695_leds_timer);
+               break;
+#endif
+
+#ifdef CONFIG_LEDS_CPU
+       case led_idle_start:    /* Entering idle state */
+               ks8695_led_off(ks8695_leds_cpu);
+               break;
+
+       case led_idle_end:      /* Exit idle state */
+               ks8695_led_on(ks8695_leds_cpu);
+               break;
+#endif
+
+       default:
+               break;
+       }
+
+       local_irq_restore(flags);
+}
+
+
+static int __init leds_init(void)
+{
+       if ((ks8695_leds_timer == -1) || (ks8695_leds_cpu == -1))
+               return -ENODEV;
+
+       leds_event = ks8695_leds_event;
+
+       leds_event(led_start);
+       return 0;
+}
+
+__initcall(leds_init);
index b0364dce463fd82f3ef1055e392e51a4da029d50..7ad2c656e162bf436fc729242ee6b8915122a8a0 100644 (file)
@@ -18,6 +18,11 @@ extern void __init ks8695_add_device_wan(void);
 extern void __init ks8695_add_device_lan(void);
 extern void __init ks8695_add_device_hpna(void);
 
+ /* LEDs */
+extern short ks8695_leds_cpu;
+extern short ks8695_leds_timer;
+extern void __init ks8695_init_leds(u8 cpu_led, u8 timer_led);
+
  /* PCI */
 #define KS8695_MODE_PCI                0
 #define KS8695_MODE_MINIPCI    1