OMAP3: GPIO: Enable debounce clock only when debounce is enabled v3.
[linux-ginger.git] / arch / arm / mach-at91 / leds.c
blobfec03c59ff94f382a9026bf699a95b00bd7804e0
1 /*
2 * LED driver for Atmel AT91-based boards.
4 * Copyright (C) SAN People (Pty) Ltd
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
16 #include <mach/board.h>
17 #include <mach/gpio.h>
20 /* ------------------------------------------------------------------------- */
22 #if defined(CONFIG_NEW_LEDS)
24 #include <linux/platform_device.h>
27 * New cross-platform LED support.
30 static struct gpio_led_platform_data led_data;
32 static struct platform_device at91_leds = {
33 .name = "leds-gpio",
34 .id = -1,
35 .dev.platform_data = &led_data,
38 void __init at91_gpio_leds(struct gpio_led *leds, int nr)
40 int i;
42 if (!nr)
43 return;
45 for (i = 0; i < nr; i++)
46 at91_set_gpio_output(leds[i].gpio, leds[i].active_low);
48 led_data.leds = leds;
49 led_data.num_leds = nr;
50 platform_device_register(&at91_leds);
53 #else
54 void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
55 #endif
58 /* ------------------------------------------------------------------------- */
60 #if defined(CONFIG_LEDS)
62 #include <asm/leds.h>
65 * Old ARM-specific LED framework; not fully functional when generic time is
66 * in use.
69 static u8 at91_leds_cpu;
70 static u8 at91_leds_timer;
72 static inline void at91_led_on(unsigned int led)
74 at91_set_gpio_value(led, 0);
77 static inline void at91_led_off(unsigned int led)
79 at91_set_gpio_value(led, 1);
82 static inline void at91_led_toggle(unsigned int led)
84 unsigned long is_off = at91_get_gpio_value(led);
85 if (is_off)
86 at91_led_on(led);
87 else
88 at91_led_off(led);
93 * Handle LED events.
95 static void at91_leds_event(led_event_t evt)
97 unsigned long flags;
99 local_irq_save(flags);
101 switch(evt) {
102 case led_start: /* System startup */
103 at91_led_on(at91_leds_cpu);
104 break;
106 case led_stop: /* System stop / suspend */
107 at91_led_off(at91_leds_cpu);
108 break;
110 #ifdef CONFIG_LEDS_TIMER
111 case led_timer: /* Every 50 timer ticks */
112 at91_led_toggle(at91_leds_timer);
113 break;
114 #endif
116 #ifdef CONFIG_LEDS_CPU
117 case led_idle_start: /* Entering idle state */
118 at91_led_off(at91_leds_cpu);
119 break;
121 case led_idle_end: /* Exit idle state */
122 at91_led_on(at91_leds_cpu);
123 break;
124 #endif
126 default:
127 break;
130 local_irq_restore(flags);
134 static int __init leds_init(void)
136 if (!at91_leds_timer || !at91_leds_cpu)
137 return -ENODEV;
139 leds_event = at91_leds_event;
141 leds_event(led_start);
142 return 0;
145 __initcall(leds_init);
148 void __init at91_init_leds(u8 cpu_led, u8 timer_led)
150 /* Enable GPIO to access the LEDs */
151 at91_set_gpio_output(cpu_led, 1);
152 at91_set_gpio_output(timer_led, 1);
154 at91_leds_cpu = cpu_led;
155 at91_leds_timer = timer_led;
158 #else
159 void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
160 #endif