1 /* $Id: reset.c,v 1.7 1999/08/11 20:26:51 andrewb Exp $
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
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>
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
)
49 sgi_machine_power_off();
53 static void sgi_machine_halt(void)
56 sgi_machine_power_off();
60 static void sgi_machine_power_off(void)
62 struct indy_clock
*clock
= (struct indy_clock
*)INDY_CLOCK_REGS
;
66 clock
->cmd
|= 0x08; /* Disable watchdog */
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. */
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;
109 enable_irq(SGI_PANEL_IRQ
);
112 static inline void power_button(void)
117 if (shuting_down
|| kill_proc(1, SIGINT
, 1)) {
118 /* No init process or button pressed twice. */
119 sgi_machine_power_off();
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
)
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)
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
);
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 */
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
,
216 blink_timer
.data
= PANIC_FREQ
;
217 blink_timeout(PANIC_FREQ
);
222 static struct notifier_block panic_block
= {
228 void indy_reboot_setup(void)
230 static int setup_done
;
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
);