1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
|
/* $Id: reset.c,v 1.4 1998/07/10 01:14:50 ralf Exp $
*
* Reset a SGI.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*
* Copyright (C) 1997, 1998 by Ralf Baechle
*/
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/notifier.h>
#include <linux/timer.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/system.h>
#include <asm/reboot.h>
#include <asm/sgialib.h>
#include <asm/sgihpc.h>
#include <asm/sgint23.h>
/*
* Just powerdown if init hasn't done after POWERDOWN_TIMEOUT seconds.
* I'm not shure if this feature is a good idea, for now it's here just to
* make the power button make behave just like under IRIX.
*/
#define POWERDOWN_TIMEOUT 120
/*
* Blink frequency during reboot grace period and when paniced.
*/
#define POWERDOWN_FREQ (HZ / 4)
#define PANIC_FREQ (HZ / 8)
static unsigned char sgi_volume;
static struct timer_list power_timer, blink_timer, debounce_timer, volume_timer;
static int shuting_down, has_paniced;
static void sgi_machine_restart(char *command) __attribute__((noreturn));
static void sgi_machine_halt(void) __attribute__((noreturn));
static void sgi_machine_power_off(void) __attribute__((noreturn));
/* XXX How to pass the reboot command to the firmware??? */
static void sgi_machine_restart(char *command)
{
if (shuting_down)
sgi_machine_power_off();
prom_reboot();
}
static void sgi_machine_halt(void)
{
if (shuting_down)
sgi_machine_power_off();
prom_imode();
}
static void sgi_machine_power_off(void)
{
struct indy_clock *clock = (struct indy_clock *)INDY_CLOCK_REGS;
cli();
clock->cmd |= 0x08; /* Disable watchdog */
clock->whsec = 0;
clock->wsec = 0;
while(1) {
hpc3mregs->panel=0xfe;
/* Good bye cruel world ... */
/* If we're still running, we probably got sent an alarm
interrupt. Read the flag to clear it. */
clock->halarm;
}
}
static void power_timeout(unsigned long data)
{
sgi_machine_power_off();
}
static void blink_timeout(unsigned long data)
{
/* XXX fix this for fullhouse */
sgi_hpc_write1 ^= (HPC3_WRITE1_LC0OFF|HPC3_WRITE1_LC1OFF);
hpc3mregs->write1 = sgi_hpc_write1;
del_timer(&blink_timer);
blink_timer.expires = jiffies + data;
add_timer(&blink_timer);
}
static void debounce(unsigned long data)
{
del_timer(&debounce_timer);
if (ioc_icontrol->istat1 & 2) { /* Interrupt still being sent. */
debounce_timer.expires = jiffies + 5; /* 0.05s */
add_timer(&debounce_timer);
hpc3mregs->panel = 0xf3;
return;
}
if (has_paniced)
prom_reboot();
enable_irq(9);
}
static inline void power_button(void)
{
if (has_paniced)
return;
if (shuting_down || kill_proc(1, SIGINT, 1)) {
/* No init process or button pressed twice. */
sgi_machine_power_off();
}
shuting_down = 1;
blink_timer.data = POWERDOWN_FREQ;
blink_timeout(POWERDOWN_FREQ);
init_timer(&power_timer);
power_timer.function = power_timeout;
power_timer.expires = jiffies + POWERDOWN_TIMEOUT * HZ;
add_timer(&power_timer);
}
void inline sgi_volume_set(unsigned char volume)
{
sgi_volume = volume;
hpc3c0->pbus_extregs[2][0] = sgi_volume;
hpc3c0->pbus_extregs[2][1] = sgi_volume;
}
void inline sgi_volume_get(unsigned char *volume)
{
*volume = sgi_volume;
}
static inline void volume_up_button(unsigned long data)
{
del_timer(&volume_timer);
if (sgi_volume < 0xff)
sgi_volume++;
hpc3c0->pbus_extregs[2][0] = sgi_volume;
hpc3c0->pbus_extregs[2][1] = sgi_volume;
if (ioc_icontrol->istat1 & 2) {
volume_timer.expires = jiffies + 1;
add_timer(&volume_timer);
}
}
static inline void volume_down_button(unsigned long data)
{
del_timer(&volume_timer);
if (sgi_volume > 0)
sgi_volume--;
hpc3c0->pbus_extregs[2][0] = sgi_volume;
hpc3c0->pbus_extregs[2][1] = sgi_volume;
if (ioc_icontrol->istat1 & 2) {
volume_timer.expires = jiffies + 1;
add_timer(&volume_timer);
}
}
static void panel_int(int irq, void *dev_id, struct pt_regs *regs)
{
unsigned int buttons;
buttons = hpc3mregs->panel;
hpc3mregs->panel = 3; /* power_interrupt | power_supply_on */
if (ioc_icontrol->istat1 & 2) { /* Wait until interrupt goes away */
disable_irq(9);
init_timer(&debounce_timer);
debounce_timer.function = debounce;
debounce_timer.expires = jiffies + 5;
add_timer(&debounce_timer);
}
if (!(buttons & 2)) /* Power button was pressed */
power_button();
if (!(buttons & 0x40)) { /* Volume up button was pressed */
init_timer(&volume_timer);
volume_timer.function = volume_up_button;
volume_timer.expires = jiffies + 1;
add_timer(&volume_timer);
}
if (!(buttons & 0x10)) { /* Volume down button was pressed */
init_timer(&volume_timer);
volume_timer.function = volume_down_button;
volume_timer.expires = jiffies + 1;
add_timer(&volume_timer);
}
}
static int panic_event(struct notifier_block *this, unsigned long event,
void *ptr)
{
if (has_paniced)
return NOTIFY_DONE;
has_paniced = 1;
blink_timer.data = PANIC_FREQ;
blink_timeout(PANIC_FREQ);
return NOTIFY_DONE;
}
static struct notifier_block panic_block = {
panic_event,
NULL,
0
};
void indy_reboot_setup(void)
{
static int setup_done;
if (setup_done)
return;
setup_done = 1;
_machine_restart = sgi_machine_restart;
_machine_halt = sgi_machine_halt;
_machine_power_off = sgi_machine_power_off;
request_irq(9, panel_int, 0, "Front Panel", NULL);
init_timer(&blink_timer);
blink_timer.function = blink_timeout;
notifier_chain_register(&panic_notifier_list, &panic_block);
}
|