[ARM] 3393/2: AT91RM9200 LED support
Andrew Victor [Sun, 2 Apr 2006 16:15:48 +0000 (17:15 +0100)]
Patch from Andrew Victor

This patch adds support for the LED(s) on the AT91RM9200-based boards.

(This version of the patch can be applied before Patch 3392/1)

Signed-off-by: Andrew Victor <andrew@sanpeople.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

arch/arm/mach-at91rm9200/Makefile
arch/arm/mach-at91rm9200/board-csb337.c
arch/arm/mach-at91rm9200/board-csb637.c
arch/arm/mach-at91rm9200/board-dk.c
arch/arm/mach-at91rm9200/board-ek.c
arch/arm/mach-at91rm9200/devices.c
arch/arm/mach-at91rm9200/leds.c [new file with mode: 0644]
include/asm-arm/arch-at91rm9200/board.h

index 75e6ee3..ef88c41 100644 (file)
@@ -16,11 +16,12 @@ obj-$(CONFIG_MACH_CSB637)   += board-csb637.o
 #obj-$(CONFIG_MACH_KB9200)     += board-kb9202.o
 
 # LEDs support
-#led-$(CONFIG_ARCH_AT91RM9200DK)       += leds.o
-#led-$(CONFIG_MACH_AT91RM9200EK)       += leds.o
-#led-$(CONFIG_MACH_CSB337)     += leds.o
-#led-$(CONFIG_MACH_CSB637)     += leds.o
+led-$(CONFIG_ARCH_AT91RM9200DK)        += leds.o
+led-$(CONFIG_MACH_AT91RM9200EK)        += leds.o
+led-$(CONFIG_MACH_CSB337)      += leds.o
+led-$(CONFIG_MACH_CSB637)      += leds.o
 #led-$(CONFIG_MACH_KB9200)     += leds.o
+#led-$(CONFIG_MACH_KAFA)       += leds.o
 obj-$(CONFIG_LEDS) += $(led-y)
 
 # VGA support
index 54022e5..f45104c 100644 (file)
@@ -67,6 +67,9 @@ static void __init csb337_map_io(void)
        /* Initialize clocks: 3.6864 MHz crystal */
        at91_clock_init(3686400);
 
+       /* Setup the LEDs */
+       at91_init_leds(AT91_PIN_PB2, AT91_PIN_PB2);
+
 #ifdef CONFIG_SERIAL_AT91
        at91_console_port = CSB337_SERIAL_CONSOLE;
        memcpy(at91_serial_map, serial, sizeof(serial));
index 8195f9d..f2c2d6e 100644 (file)
@@ -67,6 +67,9 @@ static void __init csb637_map_io(void)
        /* Initialize clocks: 3.6864 MHz crystal */
        at91_clock_init(3686400);
 
+       /* Setup the LEDs */
+       at91_init_leds(AT91_PIN_PB2, AT91_PIN_PB2);
+
 #ifdef CONFIG_SERIAL_AT91
        at91_console_port = CSB637_SERIAL_CONSOLE;
        memcpy(at91_serial_map, serial, sizeof(serial));
index 8a78336..fefbea8 100644 (file)
@@ -70,6 +70,9 @@ static void __init dk_map_io(void)
        /* Initialize clocks: 18.432 MHz crystal */
        at91_clock_init(18432000);
 
+       /* Setup the LEDs */
+       at91_init_leds(AT91_PIN_PB2, AT91_PIN_PB2);
+
 #ifdef CONFIG_SERIAL_AT91
        at91_console_port = DK_SERIAL_CONSOLE;
        memcpy(at91_serial_map, serial, sizeof(serial));
index fd0752e..1f8e450 100644 (file)
@@ -70,6 +70,9 @@ static void __init ek_map_io(void)
        /* Initialize clocks: 18.432 MHz crystal */
        at91_clock_init(18432000);
 
+       /* Setup the LEDs */
+       at91_init_leds(AT91_PIN_PB1, AT91_PIN_PB2);
+
 #ifdef CONFIG_SERIAL_AT91
        at91_console_port = EK_SERIAL_CONSOLE;
        memcpy(at91_serial_map, serial, sizeof(serial));
index 57eedd5..aa36760 100644 (file)
@@ -290,4 +290,23 @@ void __init at91_add_device_mmc(struct at91_mmc_data *data)
 void __init at91_add_device_mmc(struct at91_mmc_data *data) {}
 #endif
 
+/* --------------------------------------------------------------------
+ *  LEDs
+ * -------------------------------------------------------------------- */
+
+#if defined(CONFIG_LEDS)
+u8 at91_leds_cpu;
+u8 at91_leds_timer;
+
+void __init at91_init_leds(u8 cpu_led, u8 timer_led)
+{
+       at91_leds_cpu   = cpu_led;
+       at91_leds_timer = timer_led;
+}
+
+#else
+void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
+#endif
+
+
 /* -------------------------------------------------------------------- */
diff --git a/arch/arm/mach-at91rm9200/leds.c b/arch/arm/mach-at91rm9200/leds.c
new file mode 100644 (file)
index 0000000..28150e8
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ * LED driver for Atmel AT91-based boards.
+ *
+ *  Copyright (C) SAN People (Pty) Ltd
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+*/
+
+#include <linux/config.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+
+#include <asm/mach-types.h>
+#include <asm/leds.h>
+#include <asm/arch/board.h>
+#include <asm/arch/gpio.h>
+
+
+static inline void at91_led_on(unsigned int led)
+{
+       at91_set_gpio_value(led, 0);
+}
+
+static inline void at91_led_off(unsigned int led)
+{
+       at91_set_gpio_value(led, 1);
+}
+
+static inline void at91_led_toggle(unsigned int led)
+{
+       unsigned long is_off = at91_get_gpio_value(led);
+       if (is_off)
+               at91_led_on(led);
+       else
+               at91_led_off(led);
+}
+
+
+/*
+ * Handle LED events.
+ */
+static void at91_leds_event(led_event_t evt)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+
+       switch(evt) {
+       case led_start:         /* System startup */
+               at91_led_on(at91_leds_cpu);
+               break;
+
+       case led_stop:          /* System stop / suspend */
+               at91_led_off(at91_leds_cpu);
+               break;
+
+#ifdef CONFIG_LEDS_TIMER
+       case led_timer:         /* Every 50 timer ticks */
+               at91_led_toggle(at91_leds_timer);
+               break;
+#endif
+
+#ifdef CONFIG_LEDS_CPU
+       case led_idle_start:    /* Entering idle state */
+               at91_led_off(at91_leds_cpu);
+               break;
+
+       case led_idle_end:      /* Exit idle state */
+               at91_led_on(at91_leds_cpu);
+               break;
+#endif
+
+       default:
+               break;
+       }
+
+       local_irq_restore(flags);
+}
+
+
+static int __init leds_init(void)
+{
+       if (!at91_leds_timer || !at91_leds_cpu)
+               return -ENODEV;
+
+       /* Enable PIO to access the LEDs */
+       at91_set_gpio_output(at91_leds_timer, 1);
+       at91_set_gpio_output(at91_leds_cpu, 1);
+
+       leds_event = at91_leds_event;
+
+       leds_event(led_start);
+       return 0;
+}
+
+__initcall(leds_init);
index 2e7d113..834d0ab 100644 (file)
@@ -77,4 +77,9 @@ struct at91_usbh_data {
 };
 extern void __init at91_add_device_usbh(struct at91_usbh_data *data);
 
+ /* LEDs */
+extern u8 at91_leds_cpu;
+extern u8 at91_leds_timer;
+extern void __init at91_init_leds(u8 cpu_led, u8 timer_led);
+
 #endif