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
6 * Copyright (C) 1997, 1998, 2001, 2003 by Ralf Baechle
8 #include <linux/init.h>
9 #include <linux/ds1286.h>
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/notifier.h>
15 #include <linux/timer.h>
19 #include <asm/system.h>
20 #include <asm/reboot.h>
21 #include <asm/sgialib.h>
22 #include <asm/sgi/ioc.h>
23 #include <asm/sgi/hpc3.h>
24 #include <asm/sgi/mc.h>
25 #include <asm/sgi/ip22.h>
28 * Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds.
29 * I'm not sure if this feature is a good idea, for now it's here just to
30 * make the power button make behave just like under IRIX.
32 #define POWERDOWN_TIMEOUT 120
35 * Blink frequency during reboot grace period and when paniced.
37 #define POWERDOWN_FREQ (HZ / 4)
38 #define PANIC_FREQ (HZ / 8)
40 static struct timer_list power_timer
, blink_timer
, debounce_timer
, volume_timer
;
42 #define MACHINE_PANICED 1
43 #define MACHINE_SHUTTING_DOWN 2
44 static int machine_state
= 0;
46 static void sgi_machine_restart(char *command
) __attribute__((noreturn
));
47 static void sgi_machine_halt(void) __attribute__((noreturn
));
48 static void sgi_machine_power_off(void) __attribute__((noreturn
));
50 static void sgi_machine_restart(char *command
)
52 if (machine_state
& MACHINE_SHUTTING_DOWN
)
53 sgi_machine_power_off();
54 sgimc
->cpuctrl0
|= SGIMC_CCTRL0_SYSINIT
;
58 static void sgi_machine_halt(void)
60 if (machine_state
& MACHINE_SHUTTING_DOWN
)
61 sgi_machine_power_off();
62 ArcEnterInteractiveMode();
65 static void sgi_machine_power_off(void)
71 /* Disable watchdog */
72 tmp
= hpc3c0
->rtcregs
[RTC_CMD
] & 0xff;
73 hpc3c0
->rtcregs
[RTC_CMD
] = tmp
| RTC_WAM
;
74 hpc3c0
->rtcregs
[RTC_WSEC
] = 0;
75 hpc3c0
->rtcregs
[RTC_WHSEC
] = 0;
78 sgioc
->panel
= ~SGIOC_PANEL_POWERON
;
79 /* Good bye cruel world ... */
81 /* If we're still running, we probably got sent an alarm
82 interrupt. Read the flag to clear it. */
83 tmp
= hpc3c0
->rtcregs
[RTC_HOURS_ALARM
];
87 static void power_timeout(unsigned long data
)
89 sgi_machine_power_off();
92 static void blink_timeout(unsigned long data
)
94 /* XXX fix this for fullhouse */
95 sgi_ioc_reset
^= (SGIOC_RESET_LC0OFF
|SGIOC_RESET_LC1OFF
);
96 sgioc
->reset
= sgi_ioc_reset
;
98 mod_timer(&blink_timer
, jiffies
+data
);
101 static void debounce(unsigned long data
)
103 del_timer(&debounce_timer
);
104 if (sgint
->istat1
& SGINT_ISTAT1_PWR
) {
105 /* Interrupt still being sent. */
106 debounce_timer
.expires
= jiffies
+ 5; /* 0.05s */
107 add_timer(&debounce_timer
);
109 sgioc
->panel
= SGIOC_PANEL_POWERON
| SGIOC_PANEL_POWERINTR
|
110 SGIOC_PANEL_VOLDNINTR
| SGIOC_PANEL_VOLDNHOLD
|
111 SGIOC_PANEL_VOLUPINTR
| SGIOC_PANEL_VOLUPHOLD
;
116 if (machine_state
& MACHINE_PANICED
)
117 sgimc
->cpuctrl0
|= SGIMC_CCTRL0_SYSINIT
;
119 enable_irq(SGI_PANEL_IRQ
);
122 static inline void power_button(void)
124 if (machine_state
& MACHINE_PANICED
)
127 if ((machine_state
& MACHINE_SHUTTING_DOWN
) || kill_proc(1,SIGINT
,1)) {
128 /* No init process or button pressed twice. */
129 sgi_machine_power_off();
132 machine_state
|= MACHINE_SHUTTING_DOWN
;
133 blink_timer
.data
= POWERDOWN_FREQ
;
134 blink_timeout(POWERDOWN_FREQ
);
136 init_timer(&power_timer
);
137 power_timer
.function
= power_timeout
;
138 power_timer
.expires
= jiffies
+ POWERDOWN_TIMEOUT
* HZ
;
139 add_timer(&power_timer
);
142 void (*indy_volume_button
)(int) = NULL
;
144 EXPORT_SYMBOL(indy_volume_button
);
146 static inline void volume_up_button(unsigned long data
)
148 del_timer(&volume_timer
);
150 if (indy_volume_button
)
151 indy_volume_button(1);
153 if (sgint
->istat1
& SGINT_ISTAT1_PWR
) {
154 volume_timer
.expires
= jiffies
+ 1;
155 add_timer(&volume_timer
);
159 static inline void volume_down_button(unsigned long data
)
161 del_timer(&volume_timer
);
163 if (indy_volume_button
)
164 indy_volume_button(-1);
166 if (sgint
->istat1
& SGINT_ISTAT1_PWR
) {
167 volume_timer
.expires
= jiffies
+ 1;
168 add_timer(&volume_timer
);
172 static irqreturn_t
panel_int(int irq
, void *dev_id
, struct pt_regs
*regs
)
174 unsigned int buttons
;
176 buttons
= sgioc
->panel
;
177 sgioc
->panel
= SGIOC_PANEL_POWERON
| SGIOC_PANEL_POWERINTR
;
179 if (sgint
->istat1
& SGINT_ISTAT1_PWR
) {
180 /* Wait until interrupt goes away */
181 disable_irq(SGI_PANEL_IRQ
);
182 init_timer(&debounce_timer
);
183 debounce_timer
.function
= debounce
;
184 debounce_timer
.expires
= jiffies
+ 5;
185 add_timer(&debounce_timer
);
188 /* Power button was pressed
189 * ioc.ps page 22: "The Panel Register is called Power Control by Full
190 * House. Only lowest 2 bits are used. Guiness uses upper four bits
191 * for volume control". This is not true, all bits are pulled high
193 if (ip22_is_fullhouse() || !(buttons
& SGIOC_PANEL_POWERINTR
)) {
197 /* TODO: mute/unmute */
198 /* Volume up button was pressed */
199 if (!(buttons
& SGIOC_PANEL_VOLUPINTR
)) {
200 init_timer(&volume_timer
);
201 volume_timer
.function
= volume_up_button
;
202 volume_timer
.expires
= jiffies
+ 1;
203 add_timer(&volume_timer
);
205 /* Volume down button was pressed */
206 if (!(buttons
& SGIOC_PANEL_VOLDNINTR
)) {
207 init_timer(&volume_timer
);
208 volume_timer
.function
= volume_down_button
;
209 volume_timer
.expires
= jiffies
+ 1;
210 add_timer(&volume_timer
);
216 static int panic_event(struct notifier_block
*this, unsigned long event
,
219 if (machine_state
& MACHINE_PANICED
)
221 machine_state
|= MACHINE_PANICED
;
223 blink_timer
.data
= PANIC_FREQ
;
224 blink_timeout(PANIC_FREQ
);
229 static struct notifier_block panic_block
= {
230 .notifier_call
= panic_event
,
233 static int __init
reboot_setup(void)
235 _machine_restart
= sgi_machine_restart
;
236 _machine_halt
= sgi_machine_halt
;
237 _machine_power_off
= sgi_machine_power_off
;
239 request_irq(SGI_PANEL_IRQ
, panel_int
, 0, "Front Panel", NULL
);
240 init_timer(&blink_timer
);
241 blink_timer
.function
= blink_timeout
;
242 notifier_chain_register(&panic_notifier_list
, &panic_block
);
247 subsys_initcall(reboot_setup
);