Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / arch / mips / sgi / kernel / reset.c
blob53cd9b1e47e9d4fc158ab6d2d088cbd3edac1a76
1 /* $Id: reset.c,v 1.7 1999/08/11 20:26:51 andrewb Exp $
3 * Reset a SGI.
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
7 * for more details.
9 * Copyright (C) 1997, 1998 by Ralf Baechle
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/notifier.h>
14 #include <linux/timer.h>
15 #include <asm/io.h>
16 #include <asm/irq.h>
17 #include <asm/system.h>
18 #include <asm/reboot.h>
19 #include <asm/sgialib.h>
20 #include <asm/sgi/sgihpc.h>
21 #include <asm/sgi/sgint23.h>
24 * Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds.
25 * I'm not shure if this feature is a good idea, for now it's here just to
26 * make the power button make behave just like under IRIX.
28 #define POWERDOWN_TIMEOUT 120
31 * Blink frequency during reboot grace period and when paniced.
33 #define POWERDOWN_FREQ (HZ / 4)
34 #define PANIC_FREQ (HZ / 8)
36 static unsigned char sgi_volume;
38 static struct timer_list power_timer, blink_timer, debounce_timer, volume_timer;
39 static int shuting_down, has_paniced;
41 static void sgi_machine_restart(char *command) __attribute__((noreturn));
42 static void sgi_machine_halt(void) __attribute__((noreturn));
43 static void sgi_machine_power_off(void) __attribute__((noreturn));
45 /* XXX How to pass the reboot command to the firmware??? */
46 static void sgi_machine_restart(char *command)
48 if (shuting_down)
49 sgi_machine_power_off();
50 prom_reboot();
53 static void sgi_machine_halt(void)
55 if (shuting_down)
56 sgi_machine_power_off();
57 prom_imode();
60 static void sgi_machine_power_off(void)
62 struct indy_clock *clock = (struct indy_clock *)INDY_CLOCK_REGS;
64 cli();
66 clock->cmd |= 0x08; /* Disable watchdog */
67 clock->whsec = 0;
68 clock->wsec = 0;
70 while(1) {
71 hpc3mregs->panel=0xfe;
72 /* Good bye cruel world ... */
74 /* If we're still running, we probably got sent an alarm
75 interrupt. Read the flag to clear it. */
76 clock->halarm;
80 static void power_timeout(unsigned long data)
82 sgi_machine_power_off();
85 static void blink_timeout(unsigned long data)
87 /* XXX fix this for fullhouse */
88 sgi_hpc_write1 ^= (HPC3_WRITE1_LC0OFF|HPC3_WRITE1_LC1OFF);
89 hpc3mregs->write1 = sgi_hpc_write1;
91 mod_timer(&blink_timer, jiffies+data);
94 static void debounce(unsigned long data)
96 del_timer(&debounce_timer);
97 if (ioc_icontrol->istat1 & 2) { /* Interrupt still being sent. */
98 debounce_timer.expires = jiffies + 5; /* 0.05s */
99 add_timer(&debounce_timer);
101 hpc3mregs->panel = 0xf3;
103 return;
106 if (has_paniced)
107 prom_reboot();
109 enable_irq(SGI_PANEL_IRQ);
112 static inline void power_button(void)
114 if (has_paniced)
115 return;
117 if (shuting_down || kill_proc(1, SIGINT, 1)) {
118 /* No init process or button pressed twice. */
119 sgi_machine_power_off();
122 shuting_down = 1;
123 blink_timer.data = POWERDOWN_FREQ;
124 blink_timeout(POWERDOWN_FREQ);
126 init_timer(&power_timer);
127 power_timer.function = power_timeout;
128 power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
129 add_timer(&power_timer);
132 void inline sgi_volume_set(unsigned char volume)
134 sgi_volume = volume;
136 hpc3c0->pbus_extregs[2][0] = sgi_volume;
137 hpc3c0->pbus_extregs[2][1] = sgi_volume;
140 void inline sgi_volume_get(unsigned char *volume)
142 *volume = sgi_volume;
145 static inline void volume_up_button(unsigned long data)
147 del_timer(&volume_timer);
149 if (sgi_volume < 0xff)
150 sgi_volume++;
152 hpc3c0->pbus_extregs[2][0] = sgi_volume;
153 hpc3c0->pbus_extregs[2][1] = sgi_volume;
155 if (ioc_icontrol->istat1 & 2) {
156 volume_timer.expires = jiffies + 1;
157 add_timer(&volume_timer);
162 static inline void volume_down_button(unsigned long data)
164 del_timer(&volume_timer);
166 if (sgi_volume > 0)
167 sgi_volume--;
169 hpc3c0->pbus_extregs[2][0] = sgi_volume;
170 hpc3c0->pbus_extregs[2][1] = sgi_volume;
172 if (ioc_icontrol->istat1 & 2) {
173 volume_timer.expires = jiffies + 1;
174 add_timer(&volume_timer);
178 static void panel_int(int irq, void *dev_id, struct pt_regs *regs)
180 unsigned int buttons;
182 buttons = hpc3mregs->panel;
183 hpc3mregs->panel = 3; /* power_interrupt | power_supply_on */
185 if (ioc_icontrol->istat1 & 2) { /* Wait until interrupt goes away */
186 disable_irq(SGI_PANEL_IRQ);
187 init_timer(&debounce_timer);
188 debounce_timer.function = debounce;
189 debounce_timer.expires = jiffies + 5;
190 add_timer(&debounce_timer);
193 if (!(buttons & 2)) /* Power button was pressed */
194 power_button();
195 if (!(buttons & 0x40)) { /* Volume up button was pressed */
196 init_timer(&volume_timer);
197 volume_timer.function = volume_up_button;
198 volume_timer.expires = jiffies + 1;
199 add_timer(&volume_timer);
201 if (!(buttons & 0x10)) { /* Volume down button was pressed */
202 init_timer(&volume_timer);
203 volume_timer.function = volume_down_button;
204 volume_timer.expires = jiffies + 1;
205 add_timer(&volume_timer);
209 static int panic_event(struct notifier_block *this, unsigned long event,
210 void *ptr)
212 if (has_paniced)
213 return NOTIFY_DONE;
214 has_paniced = 1;
216 blink_timer.data = PANIC_FREQ;
217 blink_timeout(PANIC_FREQ);
219 return NOTIFY_DONE;
222 static struct notifier_block panic_block = {
223 panic_event,
224 NULL,
228 void indy_reboot_setup(void)
230 static int setup_done;
232 if (setup_done)
233 return;
234 setup_done = 1;
236 _machine_restart = sgi_machine_restart;
237 _machine_halt = sgi_machine_halt;
238 _machine_power_off = sgi_machine_power_off;
240 request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL);
241 init_timer(&blink_timer);
242 blink_timer.function = blink_timeout;
243 notifier_chain_register(&panic_notifier_list, &panic_block);