Merge branch 'master' of /home/trondmy/kernel/linux-2.6/
[linux-2.6] / arch / arm / mach-pxa / leds-trizeps4.c
1 /*
2  * linux/arch/arm/mach-pxa/leds-trizeps4.c
3  *
4  *  Author:     Jürgen Schindele
5  *  Created:    20 02, 2006
6  *  Copyright:  Jürgen Schindele
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include <linux/config.h>
14 #include <linux/init.h>
15
16 #include <asm/hardware.h>
17 #include <asm/system.h>
18 #include <asm/types.h>
19 #include <asm/leds.h>
20
21 #include <asm/arch/pxa-regs.h>
22 #include <asm/arch/trizeps4.h>
23
24 #include "leds.h"
25
26 #define LED_STATE_ENABLED       1
27 #define LED_STATE_CLAIMED       2
28
29 #define SYS_BUSY                0x01
30 #define HEARTBEAT               0x02
31 #define BLINK                   0x04
32
33 static unsigned int led_state;
34 static unsigned int hw_led_state;
35
36 void trizeps4_leds_event(led_event_t evt)
37 {
38         unsigned long flags;
39
40         local_irq_save(flags);
41
42         switch (evt) {
43         case led_start:
44                 hw_led_state = 0;
45                 pxa_gpio_mode( GPIO_SYS_BUSY_LED  | GPIO_OUT);          /* LED1 */
46                 pxa_gpio_mode( GPIO_HEARTBEAT_LED | GPIO_OUT);          /* LED2 */
47                 led_state = LED_STATE_ENABLED;
48                 break;
49
50         case led_stop:
51                 led_state &= ~LED_STATE_ENABLED;
52                 break;
53
54         case led_claim:
55                 led_state |= LED_STATE_CLAIMED;
56                 hw_led_state = 0;
57                 break;
58
59         case led_release:
60                 led_state &= ~LED_STATE_CLAIMED;
61                 hw_led_state = 0;
62                 break;
63
64 #ifdef CONFIG_LEDS_TIMER
65         case led_timer:
66                 hw_led_state ^= HEARTBEAT;
67                 break;
68 #endif
69
70 #ifdef CONFIG_LEDS_CPU
71         case led_idle_start:
72                 hw_led_state &= ~SYS_BUSY;
73                 break;
74
75         case led_idle_end:
76                 hw_led_state |= SYS_BUSY;
77                 break;
78 #endif
79
80         case led_halted:
81                 break;
82
83         case led_green_on:
84                 hw_led_state |= BLINK;
85                 break;
86
87         case led_green_off:
88                 hw_led_state &= ~BLINK;
89                 break;
90
91         case led_amber_on:
92                 break;
93
94         case led_amber_off:
95                 break;
96
97         case led_red_on:
98                 break;
99
100         case led_red_off:
101                 break;
102
103         default:
104                 break;
105         }
106
107         if  (led_state & LED_STATE_ENABLED) {
108                 switch (hw_led_state) {
109                         case 0:
110                                 GPSR(GPIO_SYS_BUSY_LED)  |= GPIO_bit(GPIO_SYS_BUSY_LED);
111                                 GPSR(GPIO_HEARTBEAT_LED) |= GPIO_bit(GPIO_HEARTBEAT_LED);
112                                 break;
113                         case 1:
114                                 GPCR(GPIO_SYS_BUSY_LED)  |= GPIO_bit(GPIO_SYS_BUSY_LED);
115                                 GPSR(GPIO_HEARTBEAT_LED) |= GPIO_bit(GPIO_HEARTBEAT_LED);
116                                 break;
117                         case 2:
118                                 GPSR(GPIO_SYS_BUSY_LED)  |= GPIO_bit(GPIO_SYS_BUSY_LED);
119                                 GPCR(GPIO_HEARTBEAT_LED) |= GPIO_bit(GPIO_HEARTBEAT_LED);
120                                 break;
121                         case 3:
122                                 GPCR(GPIO_SYS_BUSY_LED)  |= GPIO_bit(GPIO_SYS_BUSY_LED);
123                                 GPCR(GPIO_HEARTBEAT_LED) |= GPIO_bit(GPIO_HEARTBEAT_LED);
124                                 break;
125                 }
126         }
127         else {
128                 /* turn all off */
129                 GPSR(GPIO_SYS_BUSY_LED)  |= GPIO_bit(GPIO_SYS_BUSY_LED);
130                 GPSR(GPIO_HEARTBEAT_LED) |= GPIO_bit(GPIO_HEARTBEAT_LED);
131         }
132
133         local_irq_restore(flags);
134 }