]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * This file is subject to the terms and conditions of the GNU General Public | |
3 | * License. See the file "COPYING" in the main directory of this archive | |
4 | * for more details. | |
5 | * | |
71baa1a5 | 6 | * Copyright (C) 1997, 1998, 2001, 03, 05 by Ralf Baechle |
1da177e4 | 7 | */ |
71baa1a5 | 8 | #include <linux/linkage.h> |
1da177e4 LT |
9 | #include <linux/init.h> |
10 | #include <linux/ds1286.h> | |
11 | #include <linux/module.h> | |
12 | #include <linux/interrupt.h> | |
13 | #include <linux/kernel.h> | |
14 | #include <linux/sched.h> | |
15 | #include <linux/notifier.h> | |
16 | #include <linux/timer.h> | |
17 | ||
18 | #include <asm/io.h> | |
19 | #include <asm/irq.h> | |
20 | #include <asm/system.h> | |
21 | #include <asm/reboot.h> | |
22 | #include <asm/sgialib.h> | |
23 | #include <asm/sgi/ioc.h> | |
24 | #include <asm/sgi/hpc3.h> | |
25 | #include <asm/sgi/mc.h> | |
26 | #include <asm/sgi/ip22.h> | |
27 | ||
28 | /* | |
29 | * Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds. | |
30 | * I'm not sure if this feature is a good idea, for now it's here just to | |
31 | * make the power button make behave just like under IRIX. | |
32 | */ | |
33 | #define POWERDOWN_TIMEOUT 120 | |
34 | ||
35 | /* | |
36 | * Blink frequency during reboot grace period and when paniced. | |
37 | */ | |
38 | #define POWERDOWN_FREQ (HZ / 4) | |
39 | #define PANIC_FREQ (HZ / 8) | |
40 | ||
41 | static struct timer_list power_timer, blink_timer, debounce_timer, volume_timer; | |
42 | ||
43 | #define MACHINE_PANICED 1 | |
44 | #define MACHINE_SHUTTING_DOWN 2 | |
1da177e4 | 45 | |
71baa1a5 | 46 | static int machine_state; |
1da177e4 | 47 | |
71baa1a5 | 48 | static void ATTRIB_NORET sgi_machine_power_off(void) |
1da177e4 LT |
49 | { |
50 | unsigned int tmp; | |
51 | ||
52 | local_irq_disable(); | |
53 | ||
54 | /* Disable watchdog */ | |
55 | tmp = hpc3c0->rtcregs[RTC_CMD] & 0xff; | |
56 | hpc3c0->rtcregs[RTC_CMD] = tmp | RTC_WAM; | |
57 | hpc3c0->rtcregs[RTC_WSEC] = 0; | |
58 | hpc3c0->rtcregs[RTC_WHSEC] = 0; | |
59 | ||
60 | while (1) { | |
61 | sgioc->panel = ~SGIOC_PANEL_POWERON; | |
62 | /* Good bye cruel world ... */ | |
63 | ||
64 | /* If we're still running, we probably got sent an alarm | |
65 | interrupt. Read the flag to clear it. */ | |
66 | tmp = hpc3c0->rtcregs[RTC_HOURS_ALARM]; | |
67 | } | |
68 | } | |
69 | ||
71baa1a5 RB |
70 | static void ATTRIB_NORET sgi_machine_restart(char *command) |
71 | { | |
72 | if (machine_state & MACHINE_SHUTTING_DOWN) | |
73 | sgi_machine_power_off(); | |
74 | sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT; | |
75 | while (1); | |
76 | } | |
77 | ||
78 | static void ATTRIB_NORET sgi_machine_halt(void) | |
79 | { | |
80 | if (machine_state & MACHINE_SHUTTING_DOWN) | |
81 | sgi_machine_power_off(); | |
82 | ArcEnterInteractiveMode(); | |
83 | } | |
84 | ||
1da177e4 LT |
85 | static void power_timeout(unsigned long data) |
86 | { | |
87 | sgi_machine_power_off(); | |
88 | } | |
89 | ||
90 | static void blink_timeout(unsigned long data) | |
91 | { | |
92 | /* XXX fix this for fullhouse */ | |
93 | sgi_ioc_reset ^= (SGIOC_RESET_LC0OFF|SGIOC_RESET_LC1OFF); | |
94 | sgioc->reset = sgi_ioc_reset; | |
95 | ||
71baa1a5 | 96 | mod_timer(&blink_timer, jiffies + data); |
1da177e4 LT |
97 | } |
98 | ||
99 | static void debounce(unsigned long data) | |
100 | { | |
101 | del_timer(&debounce_timer); | |
102 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
103 | /* Interrupt still being sent. */ | |
71baa1a5 | 104 | debounce_timer.expires = jiffies + (HZ / 20); /* 0.05s */ |
1da177e4 LT |
105 | add_timer(&debounce_timer); |
106 | ||
107 | sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR | | |
108 | SGIOC_PANEL_VOLDNINTR | SGIOC_PANEL_VOLDNHOLD | | |
109 | SGIOC_PANEL_VOLUPINTR | SGIOC_PANEL_VOLUPHOLD; | |
110 | ||
111 | return; | |
112 | } | |
113 | ||
114 | if (machine_state & MACHINE_PANICED) | |
115 | sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT; | |
116 | ||
117 | enable_irq(SGI_PANEL_IRQ); | |
118 | } | |
119 | ||
120 | static inline void power_button(void) | |
121 | { | |
122 | if (machine_state & MACHINE_PANICED) | |
123 | return; | |
124 | ||
125 | if ((machine_state & MACHINE_SHUTTING_DOWN) || kill_proc(1,SIGINT,1)) { | |
126 | /* No init process or button pressed twice. */ | |
127 | sgi_machine_power_off(); | |
128 | } | |
129 | ||
130 | machine_state |= MACHINE_SHUTTING_DOWN; | |
131 | blink_timer.data = POWERDOWN_FREQ; | |
132 | blink_timeout(POWERDOWN_FREQ); | |
133 | ||
134 | init_timer(&power_timer); | |
135 | power_timer.function = power_timeout; | |
136 | power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ; | |
137 | add_timer(&power_timer); | |
138 | } | |
139 | ||
140 | void (*indy_volume_button)(int) = NULL; | |
141 | ||
142 | EXPORT_SYMBOL(indy_volume_button); | |
143 | ||
144 | static inline void volume_up_button(unsigned long data) | |
145 | { | |
146 | del_timer(&volume_timer); | |
147 | ||
148 | if (indy_volume_button) | |
149 | indy_volume_button(1); | |
150 | ||
151 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
71baa1a5 | 152 | volume_timer.expires = jiffies + (HZ / 100); |
1da177e4 LT |
153 | add_timer(&volume_timer); |
154 | } | |
155 | } | |
156 | ||
157 | static inline void volume_down_button(unsigned long data) | |
158 | { | |
159 | del_timer(&volume_timer); | |
160 | ||
161 | if (indy_volume_button) | |
162 | indy_volume_button(-1); | |
163 | ||
164 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
71baa1a5 | 165 | volume_timer.expires = jiffies + (HZ / 100); |
1da177e4 LT |
166 | add_timer(&volume_timer); |
167 | } | |
168 | } | |
169 | ||
170 | static irqreturn_t panel_int(int irq, void *dev_id, struct pt_regs *regs) | |
171 | { | |
172 | unsigned int buttons; | |
173 | ||
174 | buttons = sgioc->panel; | |
175 | sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR; | |
176 | ||
177 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
178 | /* Wait until interrupt goes away */ | |
179 | disable_irq(SGI_PANEL_IRQ); | |
180 | init_timer(&debounce_timer); | |
181 | debounce_timer.function = debounce; | |
182 | debounce_timer.expires = jiffies + 5; | |
183 | add_timer(&debounce_timer); | |
184 | } | |
185 | ||
42a3b4f2 | 186 | /* Power button was pressed |
1da177e4 LT |
187 | * ioc.ps page 22: "The Panel Register is called Power Control by Full |
188 | * House. Only lowest 2 bits are used. Guiness uses upper four bits | |
189 | * for volume control". This is not true, all bits are pulled high | |
190 | * on fullhouse */ | |
191 | if (ip22_is_fullhouse() || !(buttons & SGIOC_PANEL_POWERINTR)) { | |
192 | power_button(); | |
193 | return IRQ_HANDLED; | |
194 | } | |
195 | /* TODO: mute/unmute */ | |
196 | /* Volume up button was pressed */ | |
197 | if (!(buttons & SGIOC_PANEL_VOLUPINTR)) { | |
198 | init_timer(&volume_timer); | |
199 | volume_timer.function = volume_up_button; | |
71baa1a5 | 200 | volume_timer.expires = jiffies + (HZ / 100); |
1da177e4 LT |
201 | add_timer(&volume_timer); |
202 | } | |
203 | /* Volume down button was pressed */ | |
204 | if (!(buttons & SGIOC_PANEL_VOLDNINTR)) { | |
205 | init_timer(&volume_timer); | |
206 | volume_timer.function = volume_down_button; | |
71baa1a5 | 207 | volume_timer.expires = jiffies + (HZ / 100); |
1da177e4 LT |
208 | add_timer(&volume_timer); |
209 | } | |
210 | ||
211 | return IRQ_HANDLED; | |
212 | } | |
213 | ||
214 | static int panic_event(struct notifier_block *this, unsigned long event, | |
215 | void *ptr) | |
216 | { | |
217 | if (machine_state & MACHINE_PANICED) | |
218 | return NOTIFY_DONE; | |
219 | machine_state |= MACHINE_PANICED; | |
220 | ||
221 | blink_timer.data = PANIC_FREQ; | |
222 | blink_timeout(PANIC_FREQ); | |
223 | ||
224 | return NOTIFY_DONE; | |
225 | } | |
226 | ||
227 | static struct notifier_block panic_block = { | |
228 | .notifier_call = panic_event, | |
229 | }; | |
230 | ||
231 | static int __init reboot_setup(void) | |
232 | { | |
233 | _machine_restart = sgi_machine_restart; | |
234 | _machine_halt = sgi_machine_halt; | |
235 | _machine_power_off = sgi_machine_power_off; | |
236 | ||
237 | request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL); | |
238 | init_timer(&blink_timer); | |
239 | blink_timer.function = blink_timeout; | |
240 | notifier_chain_register(&panic_notifier_list, &panic_block); | |
241 | ||
242 | return 0; | |
243 | } | |
244 | ||
245 | subsys_initcall(reboot_setup); |