Import 2.3.9pre5
[davej-history.git] / arch / mips / sgi / kernel / reset.c
blobc2f773d1ed746c0afdb64333504e7ac52dd96bd1
1 /* $Id: reset.c,v 1.6 1999/04/10 12:21:30 ulfc 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/sgihpc.h>
21 #include <asm/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 del_timer(&blink_timer);
92 blink_timer.expires = jiffies + data;
93 add_timer(&blink_timer);
96 static void debounce(unsigned long data)
98 del_timer(&debounce_timer);
99 if (ioc_icontrol->istat1 & 2) { /* Interrupt still being sent. */
100 debounce_timer.expires = jiffies + 5; /* 0.05s */
101 add_timer(&debounce_timer);
103 hpc3mregs->panel = 0xf3;
105 return;
108 if (has_paniced)
109 prom_reboot();
111 enable_irq(9);
114 static inline void power_button(void)
116 if (has_paniced)
117 return;
119 if (shuting_down || kill_proc(1, SIGINT, 1)) {
120 /* No init process or button pressed twice. */
121 sgi_machine_power_off();
124 shuting_down = 1;
125 blink_timer.data = POWERDOWN_FREQ;
126 blink_timeout(POWERDOWN_FREQ);
128 init_timer(&power_timer);
129 power_timer.function = power_timeout;
130 power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
131 add_timer(&power_timer);
134 void inline sgi_volume_set(unsigned char volume)
136 sgi_volume = volume;
138 hpc3c0->pbus_extregs[2][0] = sgi_volume;
139 hpc3c0->pbus_extregs[2][1] = sgi_volume;
142 void inline sgi_volume_get(unsigned char *volume)
144 *volume = sgi_volume;
147 static inline void volume_up_button(unsigned long data)
149 del_timer(&volume_timer);
151 if (sgi_volume < 0xff)
152 sgi_volume++;
154 hpc3c0->pbus_extregs[2][0] = sgi_volume;
155 hpc3c0->pbus_extregs[2][1] = sgi_volume;
157 if (ioc_icontrol->istat1 & 2) {
158 volume_timer.expires = jiffies + 1;
159 add_timer(&volume_timer);
164 static inline void volume_down_button(unsigned long data)
166 del_timer(&volume_timer);
168 if (sgi_volume > 0)
169 sgi_volume--;
171 hpc3c0->pbus_extregs[2][0] = sgi_volume;
172 hpc3c0->pbus_extregs[2][1] = sgi_volume;
174 if (ioc_icontrol->istat1 & 2) {
175 volume_timer.expires = jiffies + 1;
176 add_timer(&volume_timer);
180 static void panel_int(int irq, void *dev_id, struct pt_regs *regs)
182 unsigned int buttons;
184 buttons = hpc3mregs->panel;
185 hpc3mregs->panel = 3; /* power_interrupt | power_supply_on */
187 if (ioc_icontrol->istat1 & 2) { /* Wait until interrupt goes away */
188 disable_irq(9);
189 init_timer(&debounce_timer);
190 debounce_timer.function = debounce;
191 debounce_timer.expires = jiffies + 5;
192 add_timer(&debounce_timer);
195 if (!(buttons & 2)) /* Power button was pressed */
196 power_button();
197 if (!(buttons & 0x40)) { /* Volume up button was pressed */
198 init_timer(&volume_timer);
199 volume_timer.function = volume_up_button;
200 volume_timer.expires = jiffies + 1;
201 add_timer(&volume_timer);
203 if (!(buttons & 0x10)) { /* Volume down button was pressed */
204 init_timer(&volume_timer);
205 volume_timer.function = volume_down_button;
206 volume_timer.expires = jiffies + 1;
207 add_timer(&volume_timer);
211 static int panic_event(struct notifier_block *this, unsigned long event,
212 void *ptr)
214 if (has_paniced)
215 return NOTIFY_DONE;
216 has_paniced = 1;
218 blink_timer.data = PANIC_FREQ;
219 blink_timeout(PANIC_FREQ);
221 return NOTIFY_DONE;
224 static struct notifier_block panic_block = {
225 panic_event,
226 NULL,
230 void indy_reboot_setup(void)
232 static int setup_done;
234 if (setup_done)
235 return;
236 setup_done = 1;
238 _machine_restart = sgi_machine_restart;
239 _machine_halt = sgi_machine_halt;
240 _machine_power_off = sgi_machine_power_off;
242 request_irq(9, panel_int, 0, "Front Panel", NULL);
243 init_timer(&blink_timer);
244 blink_timer.function = blink_timeout;
245 notifier_chain_register(&panic_notifier_list, &panic_block);