20e1fe77299f93f009d10af53ac2ee9f943ea814
[openwrt/svn-archive/archive.git] / target / linux / at91 / patches-2.6.25 / 002-led-driver.patch
1 --- a/arch/arm/mach-at91/at91rm9200_devices.c
2 +++ b/arch/arm/mach-at91/at91rm9200_devices.c
3 @@ -717,6 +717,26 @@
4 static void __init at91_add_device_watchdog(void) {}
5 #endif
6
7 +/* --------------------------------------------------------------------
8 + * LEDs
9 + * -------------------------------------------------------------------- */
10 +
11 +#if defined(CONFIG_LEDS)
12 +u8 at91_leds_cpu;
13 +u8 at91_leds_timer;
14 +
15 +void __init at91_init_leds(u8 cpu_led, u8 timer_led)
16 +{
17 + /* Enable GPIO to access the LEDs */
18 + at91_set_gpio_output(cpu_led, 1);
19 + at91_set_gpio_output(timer_led, 1);
20 +
21 + at91_leds_cpu = cpu_led;
22 + at91_leds_timer = timer_led;
23 +}
24 +#else
25 +void __init at91_init_leds(u8 cpu_led, u8 timer_led) {}
26 +#endif
27
28 /* --------------------------------------------------------------------
29 * SSC -- Synchronous Serial Controller
30 --- a/arch/arm/mach-at91/Makefile
31 +++ b/arch/arm/mach-at91/Makefile
32 @@ -60,7 +60,12 @@
33 obj-$(CONFIG_MACH_AT91EB01) += board-eb01.o
34
35 # Drivers
36 -obj-y += leds.o
37 +ifeq ($(CONFIG_MACH_VLINK),y)
38 +led-$(CONFIG_MACH_VLINK) += vlink_leds.o
39 +else
40 +led-y += leds.o
41 +endif
42 +obj-y += $(led-y)
43 obj-$(CONFIG_FB_S1D13XXX) += ics1523.o
44
45 # Power Management
46 --- /dev/null
47 +++ b/arch/arm/mach-at91/vlink_leds.c
48 @@ -0,0 +1,105 @@
49 +/*
50 + * LED driver for Atmel AT91-based boards.
51 + *
52 + * Copyright (C) SAN People (Pty) Ltd
53 + * Modified for FDL VersaLink Copyright (C) Guthrie Consulting
54 + *
55 + * This program is free software; you can redistribute it and/or
56 + * modify it under the terms of the GNU General Public License
57 + * as published by the Free Software Foundation; either version
58 + * 2 of the License, or (at your option) any later version.
59 +*/
60 +
61 +#include <linux/kernel.h>
62 +#include <linux/module.h>
63 +#include <linux/init.h>
64 +
65 +#include <asm/mach-types.h>
66 +#include <asm/leds.h>
67 +#include <asm/arch/board.h>
68 +#include <asm/arch/gpio.h>
69 +
70 +
71 +static inline void at91_led_on(unsigned int led)
72 +{
73 + at91_set_gpio_value(led, 0);
74 +}
75 +
76 +static inline void at91_led_off(unsigned int led)
77 +{
78 + at91_set_gpio_value(led, 1);
79 +}
80 +
81 +static inline void at91_led_toggle(unsigned int led)
82 +{
83 + unsigned long is_off = at91_get_gpio_value(led);
84 + if (is_off) {
85 + at91_led_on(led);
86 + at91_led_off(at91_leds_cpu);
87 + }
88 + else {
89 + at91_led_on(at91_leds_cpu);
90 + at91_led_off(led);
91 + }
92 +}
93 +
94 +
95 +/*
96 + * Handle LED events.
97 + */
98 +
99 +/*
100 + * VersaLink has a single bi-coloured LED which changes colour when the
101 + * polarity is reversed
102 + */
103 +static void at91_leds_event(led_event_t evt)
104 +{
105 + unsigned long flags;
106 +
107 + local_irq_save(flags);
108 +
109 + switch(evt) {
110 + case led_start: /* System startup */
111 + at91_led_toggle(at91_leds_timer);
112 + break;
113 +
114 + case led_stop: /* System stop / suspend */
115 + at91_led_toggle(at91_leds_timer);
116 + break;
117 +
118 +#ifdef CONFIG_LEDS_TIMER
119 + case led_timer: /* Every 50 timer ticks */
120 + at91_led_toggle(at91_leds_timer);
121 + break;
122 +#endif
123 +
124 +#ifdef CONFIG_LEDS_CPU
125 + case led_idle_start: /* Entering idle state */
126 + at91_led_toggle(at91_leds_timer);
127 + break;
128 +
129 + case led_idle_end: /* Exit idle state */
130 + at91_led_toggle(at91_leds_timer);
131 + break;
132 +#endif
133 +
134 + default:
135 + break;
136 + }
137 +
138 + local_irq_restore(flags);
139 +}
140 +
141 +
142 +static int __init leds_init(void)
143 +{
144 + if (!at91_leds_timer || !at91_leds_cpu)
145 + return -ENODEV;
146 +
147 + leds_event = at91_leds_event;
148 +
149 + leds_event(led_start);
150 + return 0;
151 +}
152 +
153 +__initcall(leds_init);
154 --- a/include/asm-arm/arch-at91/board.h
155 +++ b/include/asm-arm/arch-at91/board.h
156 @@ -162,6 +162,11 @@
157 /* ISI */
158 extern void __init at91_add_device_isi(void);
159
160 + /* LEDs */
161 +extern u8 at91_leds_cpu;
162 +extern u8 at91_leds_timer;
163 +extern void __init at91_init_leds(u8 cpu_led, u8 timer_led);
164 +
165 /* Touchscreen Controller */
166 extern void __init at91_add_device_tsadcc(void);
167