]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Miscellaneous Mac68K-specific stuff | |
3 | */ | |
4 | ||
1da177e4 LT |
5 | #include <linux/types.h> |
6 | #include <linux/errno.h> | |
1da177e4 LT |
7 | #include <linux/kernel.h> |
8 | #include <linux/delay.h> | |
9 | #include <linux/sched.h> | |
1da177e4 LT |
10 | #include <linux/time.h> |
11 | #include <linux/rtc.h> | |
12 | #include <linux/mm.h> | |
13 | ||
14 | #include <linux/adb.h> | |
15 | #include <linux/cuda.h> | |
16 | #include <linux/pmu.h> | |
17 | ||
7c0f6ba6 | 18 | #include <linux/uaccess.h> |
1da177e4 | 19 | #include <asm/io.h> |
1da177e4 LT |
20 | #include <asm/segment.h> |
21 | #include <asm/setup.h> | |
22 | #include <asm/macintosh.h> | |
23 | #include <asm/mac_via.h> | |
24 | #include <asm/mac_oss.h> | |
25 | ||
1da177e4 LT |
26 | #include <asm/machdep.h> |
27 | ||
28 | /* Offset between Unix time (1970-based) and Mac time (1904-based) */ | |
29 | ||
30 | #define RTC_OFFSET 2082844800 | |
31 | ||
1da177e4 LT |
32 | static void (*rom_reset)(void); |
33 | ||
3272244c AV |
34 | #ifdef CONFIG_ADB_CUDA |
35 | static long cuda_read_time(void) | |
1da177e4 | 36 | { |
3272244c | 37 | struct adb_request req; |
1da177e4 LT |
38 | long time; |
39 | ||
3272244c AV |
40 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME) < 0) |
41 | return 0; | |
42 | while (!req.complete) | |
43 | cuda_poll(); | |
1da177e4 LT |
44 | |
45 | time = (req.reply[3] << 24) | (req.reply[4] << 16) | |
46 | | (req.reply[5] << 8) | req.reply[6]; | |
47 | return time - RTC_OFFSET; | |
48 | } | |
49 | ||
3272244c AV |
50 | static void cuda_write_time(long data) |
51 | { | |
52 | struct adb_request req; | |
53 | data += RTC_OFFSET; | |
54 | if (cuda_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, | |
55 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, | |
56 | (data >> 8) & 0xFF, data & 0xFF) < 0) | |
57 | return; | |
58 | while (!req.complete) | |
59 | cuda_poll(); | |
60 | } | |
1da177e4 | 61 | |
3272244c | 62 | static __u8 cuda_read_pram(int offset) |
1da177e4 | 63 | { |
3272244c AV |
64 | struct adb_request req; |
65 | if (cuda_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM, | |
66 | (offset >> 8) & 0xFF, offset & 0xFF) < 0) | |
67 | return 0; | |
68 | while (!req.complete) | |
69 | cuda_poll(); | |
70 | return req.reply[3]; | |
71 | } | |
1da177e4 | 72 | |
3272244c AV |
73 | static void cuda_write_pram(int offset, __u8 data) |
74 | { | |
75 | struct adb_request req; | |
76 | if (cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, | |
77 | (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) | |
78 | return; | |
79 | while (!req.complete) | |
80 | cuda_poll(); | |
81 | } | |
82 | #else | |
83 | #define cuda_read_time() 0 | |
84 | #define cuda_write_time(n) | |
85 | #define cuda_read_pram NULL | |
86 | #define cuda_write_pram NULL | |
87 | #endif | |
88 | ||
d643e2d2 | 89 | #ifdef CONFIG_ADB_PMU68K |
3272244c AV |
90 | static long pmu_read_time(void) |
91 | { | |
92 | struct adb_request req; | |
93 | long time; | |
94 | ||
95 | if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0) | |
96 | return 0; | |
97 | while (!req.complete) | |
98 | pmu_poll(); | |
1da177e4 | 99 | |
d643e2d2 FT |
100 | time = (req.reply[1] << 24) | (req.reply[2] << 16) |
101 | | (req.reply[3] << 8) | req.reply[4]; | |
3272244c AV |
102 | return time - RTC_OFFSET; |
103 | } | |
104 | ||
105 | static void pmu_write_time(long data) | |
106 | { | |
107 | struct adb_request req; | |
108 | data += RTC_OFFSET; | |
109 | if (pmu_request(&req, NULL, 5, PMU_SET_RTC, | |
1da177e4 | 110 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, |
3272244c AV |
111 | (data >> 8) & 0xFF, data & 0xFF) < 0) |
112 | return; | |
113 | while (!req.complete) | |
114 | pmu_poll(); | |
1da177e4 LT |
115 | } |
116 | ||
3272244c AV |
117 | static __u8 pmu_read_pram(int offset) |
118 | { | |
119 | struct adb_request req; | |
120 | if (pmu_request(&req, NULL, 3, PMU_READ_NVRAM, | |
121 | (offset >> 8) & 0xFF, offset & 0xFF) < 0) | |
122 | return 0; | |
123 | while (!req.complete) | |
124 | pmu_poll(); | |
125 | return req.reply[3]; | |
126 | } | |
1da177e4 | 127 | |
3272244c | 128 | static void pmu_write_pram(int offset, __u8 data) |
1da177e4 | 129 | { |
3272244c AV |
130 | struct adb_request req; |
131 | if (pmu_request(&req, NULL, 4, PMU_WRITE_NVRAM, | |
132 | (offset >> 8) & 0xFF, offset & 0xFF, data) < 0) | |
133 | return; | |
134 | while (!req.complete) | |
135 | pmu_poll(); | |
136 | } | |
137 | #else | |
138 | #define pmu_read_time() 0 | |
139 | #define pmu_write_time(n) | |
140 | #define pmu_read_pram NULL | |
141 | #define pmu_write_pram NULL | |
142 | #endif | |
1da177e4 | 143 | |
40f7f9c1 | 144 | #if 0 /* def CONFIG_ADB_MACIISI */ |
3272244c AV |
145 | extern int maciisi_request(struct adb_request *req, |
146 | void (*done)(struct adb_request *), int nbytes, ...); | |
147 | ||
148 | static long maciisi_read_time(void) | |
149 | { | |
150 | struct adb_request req; | |
151 | long time; | |
152 | ||
153 | if (maciisi_request(&req, NULL, 2, CUDA_PACKET, CUDA_GET_TIME)) | |
154 | return 0; | |
155 | ||
156 | time = (req.reply[3] << 24) | (req.reply[4] << 16) | |
157 | | (req.reply[5] << 8) | req.reply[6]; | |
158 | return time - RTC_OFFSET; | |
1da177e4 LT |
159 | } |
160 | ||
3272244c AV |
161 | static void maciisi_write_time(long data) |
162 | { | |
163 | struct adb_request req; | |
164 | data += RTC_OFFSET; | |
165 | maciisi_request(&req, NULL, 6, CUDA_PACKET, CUDA_SET_TIME, | |
166 | (data >> 24) & 0xFF, (data >> 16) & 0xFF, | |
167 | (data >> 8) & 0xFF, data & 0xFF); | |
168 | } | |
1da177e4 | 169 | |
3272244c | 170 | static __u8 maciisi_read_pram(int offset) |
1da177e4 | 171 | { |
3272244c AV |
172 | struct adb_request req; |
173 | if (maciisi_request(&req, NULL, 4, CUDA_PACKET, CUDA_GET_PRAM, | |
174 | (offset >> 8) & 0xFF, offset & 0xFF)) | |
175 | return 0; | |
176 | return req.reply[3]; | |
177 | } | |
1da177e4 | 178 | |
3272244c AV |
179 | static void maciisi_write_pram(int offset, __u8 data) |
180 | { | |
181 | struct adb_request req; | |
182 | maciisi_request(&req, NULL, 5, CUDA_PACKET, CUDA_SET_PRAM, | |
183 | (offset >> 8) & 0xFF, offset & 0xFF, data); | |
1da177e4 | 184 | } |
3272244c AV |
185 | #else |
186 | #define maciisi_read_time() 0 | |
187 | #define maciisi_write_time(n) | |
188 | #define maciisi_read_pram NULL | |
189 | #define maciisi_write_pram NULL | |
190 | #endif | |
1da177e4 LT |
191 | |
192 | /* | |
193 | * VIA PRAM/RTC access routines | |
194 | * | |
195 | * Must be called with interrupts disabled and | |
196 | * the RTC should be enabled. | |
197 | */ | |
198 | ||
199 | static __u8 via_pram_readbyte(void) | |
200 | { | |
201 | int i,reg; | |
202 | __u8 data; | |
203 | ||
204 | reg = via1[vBufB] & ~VIA1B_vRTCClk; | |
205 | ||
206 | /* Set the RTC data line to be an input. */ | |
207 | ||
208 | via1[vDirB] &= ~VIA1B_vRTCData; | |
209 | ||
210 | /* The bits of the byte come out in MSB order */ | |
211 | ||
212 | data = 0; | |
213 | for (i = 0 ; i < 8 ; i++) { | |
214 | via1[vBufB] = reg; | |
215 | via1[vBufB] = reg | VIA1B_vRTCClk; | |
216 | data = (data << 1) | (via1[vBufB] & VIA1B_vRTCData); | |
217 | } | |
218 | ||
219 | /* Return RTC data line to output state */ | |
220 | ||
221 | via1[vDirB] |= VIA1B_vRTCData; | |
222 | ||
223 | return data; | |
224 | } | |
225 | ||
226 | static void via_pram_writebyte(__u8 data) | |
227 | { | |
228 | int i,reg,bit; | |
229 | ||
230 | reg = via1[vBufB] & ~(VIA1B_vRTCClk | VIA1B_vRTCData); | |
231 | ||
232 | /* The bits of the byte go in in MSB order */ | |
233 | ||
234 | for (i = 0 ; i < 8 ; i++) { | |
235 | bit = data & 0x80? 1 : 0; | |
236 | data <<= 1; | |
237 | via1[vBufB] = reg | bit; | |
238 | via1[vBufB] = reg | bit | VIA1B_vRTCClk; | |
239 | } | |
240 | } | |
241 | ||
242 | /* | |
243 | * Execute a VIA PRAM/RTC command. For read commands | |
244 | * data should point to a one-byte buffer for the | |
245 | * resulting data. For write commands it should point | |
246 | * to the data byte to for the command. | |
247 | * | |
248 | * This function disables all interrupts while running. | |
249 | */ | |
250 | ||
251 | static void via_pram_command(int command, __u8 *data) | |
252 | { | |
253 | unsigned long flags; | |
254 | int is_read; | |
255 | ||
256 | local_irq_save(flags); | |
257 | ||
258 | /* Enable the RTC and make sure the strobe line is high */ | |
259 | ||
260 | via1[vBufB] = (via1[vBufB] | VIA1B_vRTCClk) & ~VIA1B_vRTCEnb; | |
261 | ||
262 | if (command & 0xFF00) { /* extended (two-byte) command */ | |
263 | via_pram_writebyte((command & 0xFF00) >> 8); | |
264 | via_pram_writebyte(command & 0xFF); | |
265 | is_read = command & 0x8000; | |
266 | } else { /* one-byte command */ | |
267 | via_pram_writebyte(command); | |
268 | is_read = command & 0x80; | |
269 | } | |
270 | if (is_read) { | |
271 | *data = via_pram_readbyte(); | |
272 | } else { | |
273 | via_pram_writebyte(*data); | |
274 | } | |
275 | ||
276 | /* All done, disable the RTC */ | |
277 | ||
278 | via1[vBufB] |= VIA1B_vRTCEnb; | |
279 | ||
280 | local_irq_restore(flags); | |
281 | } | |
282 | ||
283 | static __u8 via_read_pram(int offset) | |
284 | { | |
285 | return 0; | |
286 | } | |
287 | ||
288 | static void via_write_pram(int offset, __u8 data) | |
289 | { | |
290 | } | |
291 | ||
292 | /* | |
293 | * Return the current time in seconds since January 1, 1904. | |
294 | * | |
295 | * This only works on machines with the VIA-based PRAM/RTC, which | |
296 | * is basically any machine with Mac II-style ADB. | |
297 | */ | |
298 | ||
299 | static long via_read_time(void) | |
300 | { | |
301 | union { | |
75a23850 FT |
302 | __u8 cdata[4]; |
303 | long idata; | |
1da177e4 | 304 | } result, last_result; |
75a23850 FT |
305 | int count = 1; |
306 | ||
307 | via_pram_command(0x81, &last_result.cdata[3]); | |
308 | via_pram_command(0x85, &last_result.cdata[2]); | |
309 | via_pram_command(0x89, &last_result.cdata[1]); | |
310 | via_pram_command(0x8D, &last_result.cdata[0]); | |
1da177e4 LT |
311 | |
312 | /* | |
313 | * The NetBSD guys say to loop until you get the same reading | |
314 | * twice in a row. | |
315 | */ | |
316 | ||
75a23850 | 317 | while (1) { |
1da177e4 LT |
318 | via_pram_command(0x81, &result.cdata[3]); |
319 | via_pram_command(0x85, &result.cdata[2]); | |
320 | via_pram_command(0x89, &result.cdata[1]); | |
321 | via_pram_command(0x8D, &result.cdata[0]); | |
1da177e4 | 322 | |
75a23850 FT |
323 | if (result.idata == last_result.idata) |
324 | return result.idata - RTC_OFFSET; | |
325 | ||
326 | if (++count > 10) | |
327 | break; | |
328 | ||
329 | last_result.idata = result.idata; | |
330 | } | |
331 | ||
332 | pr_err("via_read_time: failed to read a stable value; " | |
333 | "got 0x%08lx then 0x%08lx\n", | |
334 | last_result.idata, result.idata); | |
335 | ||
336 | return 0; | |
1da177e4 LT |
337 | } |
338 | ||
339 | /* | |
340 | * Set the current time to a number of seconds since January 1, 1904. | |
341 | * | |
342 | * This only works on machines with the VIA-based PRAM/RTC, which | |
343 | * is basically any machine with Mac II-style ADB. | |
344 | */ | |
345 | ||
346 | static void via_write_time(long time) | |
347 | { | |
348 | union { | |
349 | __u8 cdata[4]; | |
350 | long idata; | |
351 | } data; | |
352 | __u8 temp; | |
353 | ||
354 | /* Clear the write protect bit */ | |
355 | ||
356 | temp = 0x55; | |
357 | via_pram_command(0x35, &temp); | |
358 | ||
359 | data.idata = time + RTC_OFFSET; | |
360 | via_pram_command(0x01, &data.cdata[3]); | |
361 | via_pram_command(0x05, &data.cdata[2]); | |
362 | via_pram_command(0x09, &data.cdata[1]); | |
363 | via_pram_command(0x0D, &data.cdata[0]); | |
364 | ||
365 | /* Set the write protect bit */ | |
366 | ||
367 | temp = 0xD5; | |
368 | via_pram_command(0x35, &temp); | |
369 | } | |
370 | ||
371 | static void via_shutdown(void) | |
372 | { | |
373 | if (rbv_present) { | |
374 | via2[rBufB] &= ~0x04; | |
375 | } else { | |
376 | /* Direction of vDirB is output */ | |
377 | via2[vDirB] |= 0x04; | |
378 | /* Send a value of 0 on that line */ | |
379 | via2[vBufB] &= ~0x04; | |
380 | mdelay(1000); | |
381 | } | |
382 | } | |
383 | ||
384 | /* | |
385 | * FIXME: not sure how this is supposed to work exactly... | |
386 | */ | |
387 | ||
388 | static void oss_shutdown(void) | |
389 | { | |
390 | oss->rom_ctrl = OSS_POWEROFF; | |
391 | } | |
392 | ||
393 | #ifdef CONFIG_ADB_CUDA | |
394 | ||
395 | static void cuda_restart(void) | |
396 | { | |
3272244c AV |
397 | struct adb_request req; |
398 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_RESET_SYSTEM) < 0) | |
399 | return; | |
400 | while (!req.complete) | |
401 | cuda_poll(); | |
1da177e4 LT |
402 | } |
403 | ||
404 | static void cuda_shutdown(void) | |
405 | { | |
3272244c AV |
406 | struct adb_request req; |
407 | if (cuda_request(&req, NULL, 2, CUDA_PACKET, CUDA_POWERDOWN) < 0) | |
408 | return; | |
409 | while (!req.complete) | |
410 | cuda_poll(); | |
1da177e4 LT |
411 | } |
412 | ||
413 | #endif /* CONFIG_ADB_CUDA */ | |
414 | ||
3272244c | 415 | #ifdef CONFIG_ADB_PMU68K |
1da177e4 LT |
416 | |
417 | void pmu_restart(void) | |
418 | { | |
3272244c AV |
419 | struct adb_request req; |
420 | if (pmu_request(&req, NULL, | |
421 | 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) | |
422 | return; | |
423 | while (!req.complete) | |
424 | pmu_poll(); | |
425 | if (pmu_request(&req, NULL, 1, PMU_RESET) < 0) | |
426 | return; | |
427 | while (!req.complete) | |
428 | pmu_poll(); | |
1da177e4 LT |
429 | } |
430 | ||
431 | void pmu_shutdown(void) | |
432 | { | |
3272244c AV |
433 | struct adb_request req; |
434 | if (pmu_request(&req, NULL, | |
435 | 2, PMU_SET_INTR_MASK, PMU_INT_ADB|PMU_INT_TICK) < 0) | |
436 | return; | |
437 | while (!req.complete) | |
438 | pmu_poll(); | |
439 | if (pmu_request(&req, NULL, 5, PMU_SHUTDOWN, 'M', 'A', 'T', 'T') < 0) | |
440 | return; | |
441 | while (!req.complete) | |
442 | pmu_poll(); | |
1da177e4 LT |
443 | } |
444 | ||
3272244c | 445 | #endif |
1da177e4 LT |
446 | |
447 | /* | |
448 | *------------------------------------------------------------------- | |
449 | * Below this point are the generic routines; they'll dispatch to the | |
450 | * correct routine for the hardware on which we're running. | |
451 | *------------------------------------------------------------------- | |
452 | */ | |
453 | ||
454 | void mac_pram_read(int offset, __u8 *buffer, int len) | |
455 | { | |
3272244c | 456 | __u8 (*func)(int); |
1da177e4 LT |
457 | int i; |
458 | ||
3272244c AV |
459 | switch(macintosh_config->adb_type) { |
460 | case MAC_ADB_IISI: | |
461 | func = maciisi_read_pram; break; | |
462 | case MAC_ADB_PB1: | |
463 | case MAC_ADB_PB2: | |
464 | func = pmu_read_pram; break; | |
465 | case MAC_ADB_CUDA: | |
466 | func = cuda_read_pram; break; | |
467 | default: | |
1da177e4 LT |
468 | func = via_read_pram; |
469 | } | |
3272244c AV |
470 | if (!func) |
471 | return; | |
1da177e4 LT |
472 | for (i = 0 ; i < len ; i++) { |
473 | buffer[i] = (*func)(offset++); | |
474 | } | |
475 | } | |
476 | ||
477 | void mac_pram_write(int offset, __u8 *buffer, int len) | |
478 | { | |
3272244c | 479 | void (*func)(int, __u8); |
1da177e4 LT |
480 | int i; |
481 | ||
3272244c AV |
482 | switch(macintosh_config->adb_type) { |
483 | case MAC_ADB_IISI: | |
484 | func = maciisi_write_pram; break; | |
485 | case MAC_ADB_PB1: | |
486 | case MAC_ADB_PB2: | |
487 | func = pmu_write_pram; break; | |
488 | case MAC_ADB_CUDA: | |
489 | func = cuda_write_pram; break; | |
490 | default: | |
1da177e4 LT |
491 | func = via_write_pram; |
492 | } | |
3272244c AV |
493 | if (!func) |
494 | return; | |
1da177e4 LT |
495 | for (i = 0 ; i < len ; i++) { |
496 | (*func)(offset++, buffer[i]); | |
497 | } | |
498 | } | |
499 | ||
500 | void mac_poweroff(void) | |
501 | { | |
502 | /* | |
503 | * MAC_ADB_IISI may need to be moved up here if it doesn't actually | |
504 | * work using the ADB packet method. --David Kilzer | |
505 | */ | |
506 | ||
507 | if (oss_present) { | |
508 | oss_shutdown(); | |
509 | } else if (macintosh_config->adb_type == MAC_ADB_II) { | |
510 | via_shutdown(); | |
511 | #ifdef CONFIG_ADB_CUDA | |
512 | } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { | |
513 | cuda_shutdown(); | |
514 | #endif | |
3272244c | 515 | #ifdef CONFIG_ADB_PMU68K |
1da177e4 LT |
516 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
517 | || macintosh_config->adb_type == MAC_ADB_PB2) { | |
518 | pmu_shutdown(); | |
519 | #endif | |
520 | } | |
521 | local_irq_enable(); | |
522 | printk("It is now safe to turn off your Macintosh.\n"); | |
523 | while(1); | |
524 | } | |
525 | ||
526 | void mac_reset(void) | |
527 | { | |
528 | if (macintosh_config->adb_type == MAC_ADB_II) { | |
529 | unsigned long flags; | |
530 | ||
531 | /* need ROMBASE in booter */ | |
532 | /* indeed, plus need to MAP THE ROM !! */ | |
533 | ||
534 | if (mac_bi_data.rombase == 0) | |
535 | mac_bi_data.rombase = 0x40800000; | |
536 | ||
537 | /* works on some */ | |
538 | rom_reset = (void *) (mac_bi_data.rombase + 0xa); | |
539 | ||
540 | if (macintosh_config->ident == MAC_MODEL_SE30) { | |
541 | /* | |
542 | * MSch: Machines known to crash on ROM reset ... | |
543 | */ | |
544 | } else { | |
545 | local_irq_save(flags); | |
546 | ||
547 | rom_reset(); | |
548 | ||
549 | local_irq_restore(flags); | |
550 | } | |
551 | #ifdef CONFIG_ADB_CUDA | |
552 | } else if (macintosh_config->adb_type == MAC_ADB_CUDA) { | |
553 | cuda_restart(); | |
554 | #endif | |
3272244c | 555 | #ifdef CONFIG_ADB_PMU68K |
1da177e4 LT |
556 | } else if (macintosh_config->adb_type == MAC_ADB_PB1 |
557 | || macintosh_config->adb_type == MAC_ADB_PB2) { | |
558 | pmu_restart(); | |
559 | #endif | |
560 | } else if (CPU_IS_030) { | |
561 | ||
562 | /* 030-specific reset routine. The idea is general, but the | |
563 | * specific registers to reset are '030-specific. Until I | |
564 | * have a non-030 machine, I can't test anything else. | |
565 | * -- C. Scott Ananian <cananian@alumni.princeton.edu> | |
566 | */ | |
567 | ||
568 | unsigned long rombase = 0x40000000; | |
569 | ||
570 | /* make a 1-to-1 mapping, using the transparent tran. reg. */ | |
571 | unsigned long virt = (unsigned long) mac_reset; | |
572 | unsigned long phys = virt_to_phys(mac_reset); | |
77add9f3 | 573 | unsigned long addr = (phys&0xFF000000)|0x8777; |
1da177e4 LT |
574 | unsigned long offset = phys-virt; |
575 | local_irq_disable(); /* lets not screw this up, ok? */ | |
576 | __asm__ __volatile__(".chip 68030\n\t" | |
577 | "pmove %0,%/tt0\n\t" | |
578 | ".chip 68k" | |
77add9f3 | 579 | : : "m" (addr)); |
1da177e4 LT |
580 | /* Now jump to physical address so we can disable MMU */ |
581 | __asm__ __volatile__( | |
582 | ".chip 68030\n\t" | |
583 | "lea %/pc@(1f),%/a0\n\t" | |
584 | "addl %0,%/a0\n\t"/* fixup target address and stack ptr */ | |
585 | "addl %0,%/sp\n\t" | |
586 | "pflusha\n\t" | |
587 | "jmp %/a0@\n\t" /* jump into physical memory */ | |
588 | "0:.long 0\n\t" /* a constant zero. */ | |
589 | /* OK. Now reset everything and jump to reset vector. */ | |
590 | "1:\n\t" | |
591 | "lea %/pc@(0b),%/a0\n\t" | |
592 | "pmove %/a0@, %/tc\n\t" /* disable mmu */ | |
593 | "pmove %/a0@, %/tt0\n\t" /* disable tt0 */ | |
594 | "pmove %/a0@, %/tt1\n\t" /* disable tt1 */ | |
595 | "movel #0, %/a0\n\t" | |
596 | "movec %/a0, %/vbr\n\t" /* clear vector base register */ | |
597 | "movec %/a0, %/cacr\n\t" /* disable caches */ | |
598 | "movel #0x0808,%/a0\n\t" | |
599 | "movec %/a0, %/cacr\n\t" /* flush i&d caches */ | |
600 | "movew #0x2700,%/sr\n\t" /* set up status register */ | |
601 | "movel %1@(0x0),%/a0\n\t"/* load interrupt stack pointer */ | |
602 | "movec %/a0, %/isp\n\t" | |
603 | "movel %1@(0x4),%/a0\n\t" /* load reset vector */ | |
604 | "reset\n\t" /* reset external devices */ | |
605 | "jmp %/a0@\n\t" /* jump to the reset vector */ | |
606 | ".chip 68k" | |
607 | : : "r" (offset), "a" (rombase) : "a0"); | |
608 | } | |
609 | ||
610 | /* should never get here */ | |
611 | local_irq_enable(); | |
612 | printk ("Restart failed. Please restart manually.\n"); | |
613 | while(1); | |
614 | } | |
615 | ||
616 | /* | |
617 | * This function translates seconds since 1970 into a proper date. | |
618 | * | |
619 | * Algorithm cribbed from glibc2.1, __offtime(). | |
620 | */ | |
621 | #define SECS_PER_MINUTE (60) | |
622 | #define SECS_PER_HOUR (SECS_PER_MINUTE * 60) | |
623 | #define SECS_PER_DAY (SECS_PER_HOUR * 24) | |
624 | ||
625 | static void unmktime(unsigned long time, long offset, | |
626 | int *yearp, int *monp, int *dayp, | |
627 | int *hourp, int *minp, int *secp) | |
628 | { | |
629 | /* How many days come before each month (0-12). */ | |
630 | static const unsigned short int __mon_yday[2][13] = | |
631 | { | |
632 | /* Normal years. */ | |
633 | { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }, | |
634 | /* Leap years. */ | |
635 | { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } | |
636 | }; | |
637 | long int days, rem, y, wday, yday; | |
638 | const unsigned short int *ip; | |
639 | ||
640 | days = time / SECS_PER_DAY; | |
641 | rem = time % SECS_PER_DAY; | |
642 | rem += offset; | |
643 | while (rem < 0) { | |
644 | rem += SECS_PER_DAY; | |
645 | --days; | |
646 | } | |
647 | while (rem >= SECS_PER_DAY) { | |
648 | rem -= SECS_PER_DAY; | |
649 | ++days; | |
650 | } | |
651 | *hourp = rem / SECS_PER_HOUR; | |
652 | rem %= SECS_PER_HOUR; | |
653 | *minp = rem / SECS_PER_MINUTE; | |
654 | *secp = rem % SECS_PER_MINUTE; | |
655 | /* January 1, 1970 was a Thursday. */ | |
656 | wday = (4 + days) % 7; /* Day in the week. Not currently used */ | |
657 | if (wday < 0) wday += 7; | |
658 | y = 1970; | |
659 | ||
660 | #define DIV(a, b) ((a) / (b) - ((a) % (b) < 0)) | |
661 | #define LEAPS_THRU_END_OF(y) (DIV (y, 4) - DIV (y, 100) + DIV (y, 400)) | |
662 | #define __isleap(year) \ | |
663 | ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0)) | |
664 | ||
665 | while (days < 0 || days >= (__isleap (y) ? 366 : 365)) | |
666 | { | |
667 | /* Guess a corrected year, assuming 365 days per year. */ | |
668 | long int yg = y + days / 365 - (days % 365 < 0); | |
669 | ||
670 | /* Adjust DAYS and Y to match the guessed year. */ | |
671 | days -= ((yg - y) * 365 | |
672 | + LEAPS_THRU_END_OF (yg - 1) | |
673 | - LEAPS_THRU_END_OF (y - 1)); | |
674 | y = yg; | |
675 | } | |
676 | *yearp = y - 1900; | |
677 | yday = days; /* day in the year. Not currently used. */ | |
678 | ip = __mon_yday[__isleap(y)]; | |
679 | for (y = 11; days < (long int) ip[y]; --y) | |
680 | continue; | |
681 | days -= ip[y]; | |
682 | *monp = y; | |
683 | *dayp = days + 1; /* day in the month */ | |
684 | return; | |
685 | } | |
686 | ||
687 | /* | |
688 | * Read/write the hardware clock. | |
689 | */ | |
690 | ||
691 | int mac_hwclk(int op, struct rtc_time *t) | |
692 | { | |
693 | unsigned long now; | |
694 | ||
695 | if (!op) { /* read */ | |
3272244c AV |
696 | switch (macintosh_config->adb_type) { |
697 | case MAC_ADB_II: | |
698 | case MAC_ADB_IOP: | |
1da177e4 | 699 | now = via_read_time(); |
3272244c AV |
700 | break; |
701 | case MAC_ADB_IISI: | |
702 | now = maciisi_read_time(); | |
703 | break; | |
704 | case MAC_ADB_PB1: | |
705 | case MAC_ADB_PB2: | |
706 | now = pmu_read_time(); | |
707 | break; | |
708 | case MAC_ADB_CUDA: | |
709 | now = cuda_read_time(); | |
710 | break; | |
711 | default: | |
1da177e4 LT |
712 | now = 0; |
713 | } | |
714 | ||
715 | t->tm_wday = 0; | |
716 | unmktime(now, 0, | |
717 | &t->tm_year, &t->tm_mon, &t->tm_mday, | |
718 | &t->tm_hour, &t->tm_min, &t->tm_sec); | |
40f7f9c1 | 719 | #if 0 |
1da177e4 | 720 | printk("mac_hwclk: read %04d-%02d-%-2d %02d:%02d:%02d\n", |
40f7f9c1 FT |
721 | t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
722 | t->tm_hour, t->tm_min, t->tm_sec); | |
723 | #endif | |
1da177e4 | 724 | } else { /* write */ |
40f7f9c1 | 725 | #if 0 |
1da177e4 | 726 | printk("mac_hwclk: tried to write %04d-%02d-%-2d %02d:%02d:%02d\n", |
40f7f9c1 FT |
727 | t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
728 | t->tm_hour, t->tm_min, t->tm_sec); | |
729 | #endif | |
1da177e4 | 730 | |
1da177e4 LT |
731 | now = mktime(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, |
732 | t->tm_hour, t->tm_min, t->tm_sec); | |
733 | ||
3272244c AV |
734 | switch (macintosh_config->adb_type) { |
735 | case MAC_ADB_II: | |
736 | case MAC_ADB_IOP: | |
1da177e4 | 737 | via_write_time(now); |
3272244c AV |
738 | break; |
739 | case MAC_ADB_CUDA: | |
740 | cuda_write_time(now); | |
741 | break; | |
742 | case MAC_ADB_PB1: | |
743 | case MAC_ADB_PB2: | |
744 | pmu_write_time(now); | |
745 | break; | |
746 | case MAC_ADB_IISI: | |
747 | maciisi_write_time(now); | |
1da177e4 | 748 | } |
1da177e4 LT |
749 | } |
750 | return 0; | |
751 | } | |
752 | ||
753 | /* | |
754 | * Set minutes/seconds in the hardware clock | |
755 | */ | |
756 | ||
757 | int mac_set_clock_mmss (unsigned long nowtime) | |
758 | { | |
759 | struct rtc_time now; | |
760 | ||
761 | mac_hwclk(0, &now); | |
762 | now.tm_sec = nowtime % 60; | |
763 | now.tm_min = (nowtime / 60) % 60; | |
764 | mac_hwclk(1, &now); | |
765 | ||
766 | return 0; | |
767 | } |