blob: fec03c59ff94f382a9026bf699a95b00bd7804e0 [file] [log] [blame]
Andrew Victorcc2832a2006-04-02 17:15:48 +01001/*
2 * LED driver for Atmel AT91-based boards.
3 *
4 * Copyright (C) SAN People (Pty) Ltd
5 *
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.
10*/
11
Andrew Victorcc2832a2006-04-02 17:15:48 +010012#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15
Russell Kinga09e64f2008-08-05 16:14:15 +010016#include <mach/board.h>
17#include <mach/gpio.h>
Andrew Victorcc2832a2006-04-02 17:15:48 +010018
19
Andrew Victora04ff1a2008-01-23 09:27:06 +010020/* ------------------------------------------------------------------------- */
21
22#if defined(CONFIG_NEW_LEDS)
23
24#include <linux/platform_device.h>
25
26/*
27 * New cross-platform LED support.
28 */
29
30static struct gpio_led_platform_data led_data;
31
32static struct platform_device at91_leds = {
33 .name = "leds-gpio",
34 .id = -1,
35 .dev.platform_data = &led_data,
36};
37
38void __init at91_gpio_leds(struct gpio_led *leds, int nr)
39{
40 int i;
41
42 if (!nr)
43 return;
44
45 for (i = 0; i < nr; i++)
46 at91_set_gpio_output(leds[i].gpio, leds[i].active_low);
47
48 led_data.leds = leds;
49 led_data.num_leds = nr;
50 platform_device_register(&at91_leds);
51}
52
53#else
54void __init at91_gpio_leds(struct gpio_led *leds, int nr) {}
55#endif
56
57
58/* ------------------------------------------------------------------------- */
59
60#if defined(CONFIG_LEDS)
61
62#include <asm/leds.h>
63
64/*
65 * Old ARM-specific LED framework; not fully functional when generic time is
66 * in use.
67 */
68
69static u8 at91_leds_cpu;
70static u8 at91_leds_timer;
71
Andrew Victorcc2832a2006-04-02 17:15:48 +010072static inline void at91_led_on(unsigned int led)
73{
74 at91_set_gpio_value(led, 0);
75}
76
77static inline void at91_led_off(unsigned int led)
78{
79 at91_set_gpio_value(led, 1);
80}
81
82static inline void at91_led_toggle(unsigned int led)
83{
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);
89}
90
91
92/*
93 * Handle LED events.
94 */
95static void at91_leds_event(led_event_t evt)
96{
97 unsigned long flags;
98
99 local_irq_save(flags);
100
101 switch(evt) {
102 case led_start: /* System startup */
103 at91_led_on(at91_leds_cpu);
104 break;
105
106 case led_stop: /* System stop / suspend */
107 at91_led_off(at91_leds_cpu);
108 break;
109
110#ifdef CONFIG_LEDS_TIMER
111 case led_timer: /* Every 50 timer ticks */
112 at91_led_toggle(at91_leds_timer);
113 break;
114#endif
115
116#ifdef CONFIG_LEDS_CPU
117 case led_idle_start: /* Entering idle state */
118 at91_led_off(at91_leds_cpu);
119 break;
120
121 case led_idle_end: /* Exit idle state */
122 at91_led_on(at91_leds_cpu);
123 break;
124#endif
125
126 default:
127 break;
128 }
129
130 local_irq_restore(flags);
131}
132
133
134static int __init leds_init(void)
135{
136 if (!at91_leds_timer || !at91_leds_cpu)
137 return -ENODEV;
138
Andrew Victorcc2832a2006-04-02 17:15:48 +0100139 leds_event = at91_leds_event;
140
141 leds_event(led_start);
142 return 0;
143}
144
145__initcall(leds_init);
Andrew Victora04ff1a2008-01-23 09:27:06 +0100146
147
148void __init at91_init_leds(u8 cpu_led, u8 timer_led)
149{
150 /* Enable GPIO to access the LEDs */
151 at91_set_gpio_output(cpu_led, 1);
152 at91_set_gpio_output(timer_led, 1);
153
154 at91_leds_cpu = cpu_led;
155 at91_leds_timer = timer_led;
156}
157
158#else
159void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
160#endif