blob: 25609076921fc01970ba6319b414bec74168afac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Uwe Zeisbergerf30c2262006-10-03 23:01:26 +02002 * arch/arm/mach-shark/leds.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * by Alexander Schulz
4 *
5 * derived from:
6 * arch/arm/kernel/leds-footbridge.c
7 * Copyright (C) 1998-1999 Russell King
8 *
9 * DIGITAL Shark LED control routines.
10 *
11 * The leds use is as follows:
12 * - Green front - toggles state every 50 timer interrupts
13 * - Amber front - Unused, this is a dual color led (Amber/Green)
14 * - Amber back - On if system is not idle
15 *
16 * Changelog:
17 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/spinlock.h>
22#include <linux/ioport.h>
Russell Kingfced80c2008-09-06 12:10:45 +010023#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/leds.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#define LED_STATE_ENABLED 1
28#define LED_STATE_CLAIMED 2
Alexander Schulzeab184c2009-01-08 18:05:58 +010029
30#define SEQUOIA_LED_GREEN (1<<6)
31#define SEQUOIA_LED_AMBER (1<<5)
32#define SEQUOIA_LED_BACK (1<<7)
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static char led_state;
35static short hw_led_state;
36static short saved_state;
37
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050038static DEFINE_RAW_SPINLOCK(leds_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40short sequoia_read(int addr) {
41 outw(addr,0x24);
42 return inw(0x26);
43}
44
45void sequoia_write(short value,short addr) {
46 outw(addr,0x24);
47 outw(value,0x26);
48}
49
50static void sequoia_leds_event(led_event_t evt)
51{
52 unsigned long flags;
53
Thomas Gleixnerbd31b852009-07-03 08:44:46 -050054 raw_spin_lock_irqsave(&leds_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 hw_led_state = sequoia_read(0x09);
57
58 switch (evt) {
59 case led_start:
60 hw_led_state |= SEQUOIA_LED_GREEN;
61 hw_led_state |= SEQUOIA_LED_AMBER;
62#ifdef CONFIG_LEDS_CPU
63 hw_led_state |= SEQUOIA_LED_BACK;
64#else
65 hw_led_state &= ~SEQUOIA_LED_BACK;
66#endif
67 led_state |= LED_STATE_ENABLED;
68 break;
69
70 case led_stop:
71 hw_led_state &= ~SEQUOIA_LED_BACK;
72 hw_led_state |= SEQUOIA_LED_GREEN;
73 hw_led_state |= SEQUOIA_LED_AMBER;
74 led_state &= ~LED_STATE_ENABLED;
75 break;
76
77 case led_claim:
78 led_state |= LED_STATE_CLAIMED;
79 saved_state = hw_led_state;
80 hw_led_state &= ~SEQUOIA_LED_BACK;
81 hw_led_state |= SEQUOIA_LED_GREEN;
82 hw_led_state |= SEQUOIA_LED_AMBER;
83 break;
84
85 case led_release:
86 led_state &= ~LED_STATE_CLAIMED;
87 hw_led_state = saved_state;
88 break;
89
90#ifdef CONFIG_LEDS_TIMER
91 case led_timer:
92 if (!(led_state & LED_STATE_CLAIMED))
93 hw_led_state ^= SEQUOIA_LED_GREEN;
94 break;
95#endif
96
97#ifdef CONFIG_LEDS_CPU
98 case led_idle_start:
99 if (!(led_state & LED_STATE_CLAIMED))
100 hw_led_state &= ~SEQUOIA_LED_BACK;
101 break;
102
103 case led_idle_end:
104 if (!(led_state & LED_STATE_CLAIMED))
105 hw_led_state |= SEQUOIA_LED_BACK;
106 break;
107#endif
108
109 case led_green_on:
110 if (led_state & LED_STATE_CLAIMED)
111 hw_led_state &= ~SEQUOIA_LED_GREEN;
112 break;
113
114 case led_green_off:
115 if (led_state & LED_STATE_CLAIMED)
116 hw_led_state |= SEQUOIA_LED_GREEN;
117 break;
118
119 case led_amber_on:
120 if (led_state & LED_STATE_CLAIMED)
121 hw_led_state &= ~SEQUOIA_LED_AMBER;
122 break;
123
124 case led_amber_off:
125 if (led_state & LED_STATE_CLAIMED)
126 hw_led_state |= SEQUOIA_LED_AMBER;
127 break;
128
129 case led_red_on:
130 if (led_state & LED_STATE_CLAIMED)
131 hw_led_state |= SEQUOIA_LED_BACK;
132 break;
133
134 case led_red_off:
135 if (led_state & LED_STATE_CLAIMED)
136 hw_led_state &= ~SEQUOIA_LED_BACK;
137 break;
138
139 default:
140 break;
141 }
142
143 if (led_state & LED_STATE_ENABLED)
144 sequoia_write(hw_led_state,0x09);
145
Thomas Gleixnerbd31b852009-07-03 08:44:46 -0500146 raw_spin_unlock_irqrestore(&leds_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147}
148
149static int __init leds_init(void)
150{
151 extern void (*leds_event)(led_event_t);
152 short temp;
153
154 leds_event = sequoia_leds_event;
155
156 /* Make LEDs independent of power-state */
157 request_region(0x24,4,"sequoia");
158 temp = sequoia_read(0x09);
159 temp |= 1<<10;
160 sequoia_write(temp,0x09);
161 leds_event(led_start);
162 return 0;
163}
164
165__initcall(leds_init);