]>
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 | * | |
fcdb27ad | 6 | * Copyright (C) 1997, 1998, 2001, 03, 05, 06 by Ralf Baechle |
1da177e4 | 7 | */ |
71baa1a5 | 8 | #include <linux/linkage.h> |
1da177e4 | 9 | #include <linux/init.h> |
d4a5f6d7 | 10 | #include <linux/rtc/ds1286.h> |
1da177e4 LT |
11 | #include <linux/interrupt.h> |
12 | #include <linux/kernel.h> | |
3f07c014 | 13 | #include <linux/sched/signal.h> |
1da177e4 | 14 | #include <linux/notifier.h> |
fcdb27ad | 15 | #include <linux/pm.h> |
1da177e4 LT |
16 | #include <linux/timer.h> |
17 | ||
18 | #include <asm/io.h> | |
19 | #include <asm/irq.h> | |
1da177e4 LT |
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> | |
26 | ||
27 | /* | |
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. | |
31 | */ | |
32 | #define POWERDOWN_TIMEOUT 120 | |
33 | ||
34 | /* | |
f18190bd | 35 | * Blink frequency during reboot grace period and when panicked. |
1da177e4 LT |
36 | */ |
37 | #define POWERDOWN_FREQ (HZ / 4) | |
38 | #define PANIC_FREQ (HZ / 8) | |
39 | ||
b03d7b18 | 40 | static struct timer_list power_timer, blink_timer, debounce_timer; |
1da177e4 LT |
41 | |
42 | #define MACHINE_PANICED 1 | |
43 | #define MACHINE_SHUTTING_DOWN 2 | |
1da177e4 | 44 | |
71baa1a5 | 45 | static int machine_state; |
1da177e4 | 46 | |
b3f6df9f | 47 | static void __noreturn sgi_machine_power_off(void) |
1da177e4 LT |
48 | { |
49 | unsigned int tmp; | |
50 | ||
51 | local_irq_disable(); | |
52 | ||
53 | /* Disable watchdog */ | |
54 | tmp = hpc3c0->rtcregs[RTC_CMD] & 0xff; | |
55 | hpc3c0->rtcregs[RTC_CMD] = tmp | RTC_WAM; | |
56 | hpc3c0->rtcregs[RTC_WSEC] = 0; | |
57 | hpc3c0->rtcregs[RTC_WHSEC] = 0; | |
58 | ||
59 | while (1) { | |
60 | sgioc->panel = ~SGIOC_PANEL_POWERON; | |
61 | /* Good bye cruel world ... */ | |
62 | ||
63 | /* If we're still running, we probably got sent an alarm | |
64 | interrupt. Read the flag to clear it. */ | |
65 | tmp = hpc3c0->rtcregs[RTC_HOURS_ALARM]; | |
66 | } | |
67 | } | |
68 | ||
b3f6df9f | 69 | static void __noreturn sgi_machine_restart(char *command) |
71baa1a5 RB |
70 | { |
71 | if (machine_state & MACHINE_SHUTTING_DOWN) | |
72 | sgi_machine_power_off(); | |
73 | sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT; | |
74 | while (1); | |
75 | } | |
76 | ||
b3f6df9f | 77 | static void __noreturn sgi_machine_halt(void) |
71baa1a5 RB |
78 | { |
79 | if (machine_state & MACHINE_SHUTTING_DOWN) | |
80 | sgi_machine_power_off(); | |
81 | ArcEnterInteractiveMode(); | |
82 | } | |
83 | ||
1da177e4 LT |
84 | static void power_timeout(unsigned long data) |
85 | { | |
86 | sgi_machine_power_off(); | |
87 | } | |
88 | ||
89 | static void blink_timeout(unsigned long data) | |
90 | { | |
91 | /* XXX fix this for fullhouse */ | |
92 | sgi_ioc_reset ^= (SGIOC_RESET_LC0OFF|SGIOC_RESET_LC1OFF); | |
93 | sgioc->reset = sgi_ioc_reset; | |
94 | ||
71baa1a5 | 95 | mod_timer(&blink_timer, jiffies + data); |
1da177e4 LT |
96 | } |
97 | ||
98 | static void debounce(unsigned long data) | |
99 | { | |
100 | del_timer(&debounce_timer); | |
101 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
102 | /* Interrupt still being sent. */ | |
70342287 | 103 | debounce_timer.expires = jiffies + (HZ / 20); /* 0.05s */ |
1da177e4 LT |
104 | add_timer(&debounce_timer); |
105 | ||
106 | sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR | | |
107 | SGIOC_PANEL_VOLDNINTR | SGIOC_PANEL_VOLDNHOLD | | |
108 | SGIOC_PANEL_VOLUPINTR | SGIOC_PANEL_VOLUPHOLD; | |
109 | ||
110 | return; | |
111 | } | |
112 | ||
113 | if (machine_state & MACHINE_PANICED) | |
114 | sgimc->cpuctrl0 |= SGIMC_CCTRL0_SYSINIT; | |
115 | ||
116 | enable_irq(SGI_PANEL_IRQ); | |
117 | } | |
118 | ||
119 | static inline void power_button(void) | |
120 | { | |
121 | if (machine_state & MACHINE_PANICED) | |
122 | return; | |
123 | ||
9ec52099 CLG |
124 | if ((machine_state & MACHINE_SHUTTING_DOWN) || |
125 | kill_cad_pid(SIGINT, 1)) { | |
1da177e4 LT |
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 | ||
7d12e780 | 140 | static irqreturn_t panel_int(int irq, void *dev_id) |
1da177e4 LT |
141 | { |
142 | unsigned int buttons; | |
143 | ||
144 | buttons = sgioc->panel; | |
145 | sgioc->panel = SGIOC_PANEL_POWERON | SGIOC_PANEL_POWERINTR; | |
146 | ||
147 | if (sgint->istat1 & SGINT_ISTAT1_PWR) { | |
148 | /* Wait until interrupt goes away */ | |
7e9e05ca | 149 | disable_irq_nosync(SGI_PANEL_IRQ); |
1da177e4 LT |
150 | init_timer(&debounce_timer); |
151 | debounce_timer.function = debounce; | |
152 | debounce_timer.expires = jiffies + 5; | |
153 | add_timer(&debounce_timer); | |
154 | } | |
155 | ||
42a3b4f2 | 156 | /* Power button was pressed |
1da177e4 LT |
157 | * ioc.ps page 22: "The Panel Register is called Power Control by Full |
158 | * House. Only lowest 2 bits are used. Guiness uses upper four bits | |
159 | * for volume control". This is not true, all bits are pulled high | |
160 | * on fullhouse */ | |
b03d7b18 | 161 | if (!(buttons & SGIOC_PANEL_POWERINTR)) |
1da177e4 | 162 | power_button(); |
1da177e4 LT |
163 | |
164 | return IRQ_HANDLED; | |
165 | } | |
166 | ||
167 | static int panic_event(struct notifier_block *this, unsigned long event, | |
70342287 | 168 | void *ptr) |
1da177e4 LT |
169 | { |
170 | if (machine_state & MACHINE_PANICED) | |
171 | return NOTIFY_DONE; | |
172 | machine_state |= MACHINE_PANICED; | |
173 | ||
174 | blink_timer.data = PANIC_FREQ; | |
175 | blink_timeout(PANIC_FREQ); | |
176 | ||
177 | return NOTIFY_DONE; | |
178 | } | |
179 | ||
180 | static struct notifier_block panic_block = { | |
181 | .notifier_call = panic_event, | |
182 | }; | |
183 | ||
184 | static int __init reboot_setup(void) | |
185 | { | |
754d0f23 RB |
186 | int res; |
187 | ||
1da177e4 LT |
188 | _machine_restart = sgi_machine_restart; |
189 | _machine_halt = sgi_machine_halt; | |
fcdb27ad | 190 | pm_power_off = sgi_machine_power_off; |
1da177e4 | 191 | |
754d0f23 RB |
192 | res = request_irq(SGI_PANEL_IRQ, panel_int, 0, "Front Panel", NULL); |
193 | if (res) { | |
194 | printk(KERN_ERR "Allocation of front panel IRQ failed\n"); | |
195 | return res; | |
196 | } | |
197 | ||
1da177e4 LT |
198 | init_timer(&blink_timer); |
199 | blink_timer.function = blink_timeout; | |
e041c683 | 200 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); |
1da177e4 LT |
201 | |
202 | return 0; | |
203 | } | |
204 | ||
205 | subsys_initcall(reboot_setup); |