[ARM] 3393/2: AT91RM9200 LED support
authorAndrew Victor <andrew@sanpeople.com>
Sun, 2 Apr 2006 16:15:48 +0000 (17:15 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
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 75e6ee318dedc2d735a195445cde96179fdc232a..ef88c4128edc33ade67f23836c2124d96662a57a 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 54022e58d50dc263d15b29aa51f181f72b48e821..f45104ceea8fc5b20dc63fe5534c70777e7fea1b 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 8195f9d919ea56691aa62a1b2b339cddfbb730c1..f2c2d6e79bc6ee87bc83c9a8040cce21ec05a992 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 8a783368366ed16ccbe15eb0dfcd341d7c3c05a5..fefbea882aab33f0ceb996d6b7cafd17a9c305cc 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 fd0752eba897ea771c5b11279ae1a560a44f4fde..1f8e450060be217a063570ca89bb33df0b8782eb 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 57eedd5beaf6412c1b152843babf7536ee4c8486..aa36760efbc33bfc646fc3ad6867a09e05ed503d 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 2e7d1139a799827d4942e0c187b56ef6c1388232..834d0ab991aed2b0804cd5734601106fd69e4831 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