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