blob: 60e2da1c92c07a79f47c387fe75059b7f1d61657 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#define m68k_debug_device debug_device
2
3/*
4 * arch/ppc/amiga/config.c
5 *
6 * Copyright (C) 1993 Hamish Macdonald
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file COPYING in the main directory of this archive
10 * for more details.
11 */
12
13/*
14 * Miscellaneous Amiga stuff
15 */
16
17#include <linux/config.h>
18#include <linux/types.h>
19#include <linux/kernel.h>
20#include <linux/mm.h>
21#include <linux/kd.h>
22#include <linux/tty.h>
23#include <linux/console.h>
24#include <linux/init.h>
25#ifdef CONFIG_ZORRO
26#include <linux/zorro.h>
27#endif
28
29#include <asm/bootinfo.h>
30#include <asm/setup.h>
31#include <asm/system.h>
32#include <asm/pgtable.h>
33#include <asm/amigahw.h>
34#include <asm/amigaints.h>
35#include <asm/irq.h>
36#include <asm/machdep.h>
37#include <asm/io.h>
38
39unsigned long powerup_PCI_present;
40unsigned long powerup_BPPCPLUS_present;
41unsigned long amiga_model;
42unsigned long amiga_eclock;
43unsigned long amiga_masterclock;
44unsigned long amiga_colorclock;
45unsigned long amiga_chipset;
46unsigned char amiga_vblank;
47unsigned char amiga_psfreq;
48struct amiga_hw_present amiga_hw_present;
49
50static char s_a500[] __initdata = "A500";
51static char s_a500p[] __initdata = "A500+";
52static char s_a600[] __initdata = "A600";
53static char s_a1000[] __initdata = "A1000";
54static char s_a1200[] __initdata = "A1200";
55static char s_a2000[] __initdata = "A2000";
56static char s_a2500[] __initdata = "A2500";
57static char s_a3000[] __initdata = "A3000";
58static char s_a3000t[] __initdata = "A3000T";
59static char s_a3000p[] __initdata = "A3000+";
60static char s_a4000[] __initdata = "A4000";
61static char s_a4000t[] __initdata = "A4000T";
62static char s_cdtv[] __initdata = "CDTV";
63static char s_cd32[] __initdata = "CD32";
64static char s_draco[] __initdata = "Draco";
65static char *amiga_models[] __initdata = {
66 s_a500, s_a500p, s_a600, s_a1000, s_a1200, s_a2000, s_a2500, s_a3000,
67 s_a3000t, s_a3000p, s_a4000, s_a4000t, s_cdtv, s_cd32, s_draco,
68};
69
70static char amiga_model_name[13] = "Amiga ";
71
72extern char m68k_debug_device[];
73
74static void amiga_sched_init(irqreturn_t (*handler)(int, void *, struct pt_regs *));
75/* amiga specific irq functions */
76extern void amiga_init_IRQ (void);
77extern void (*amiga_default_handler[]) (int, void *, struct pt_regs *);
78extern int amiga_request_irq (unsigned int irq,
79 void (*handler)(int, void *, struct pt_regs *),
80 unsigned long flags, const char *devname,
81 void *dev_id);
82extern void amiga_free_irq (unsigned int irq, void *dev_id);
83extern void amiga_enable_irq (unsigned int);
84extern void amiga_disable_irq (unsigned int);
85static void amiga_get_model(char *model);
86static int amiga_get_hardware_list(char *buffer);
87/* amiga specific timer functions */
88static unsigned long amiga_gettimeoffset (void);
89static void a3000_gettod (int *, int *, int *, int *, int *, int *);
90static void a2000_gettod (int *, int *, int *, int *, int *, int *);
91static int amiga_hwclk (int, struct hwclk_time *);
92static int amiga_set_clock_mmss (unsigned long);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093static void amiga_reset (void);
94extern void amiga_init_sound(void);
95static void amiga_savekmsg_init(void);
96static void amiga_mem_console_write(struct console *co, const char *b,
97 unsigned int count);
98void amiga_serial_console_write(struct console *co, const char *s,
99 unsigned int count);
100static void amiga_debug_init(void);
101#ifdef CONFIG_HEARTBEAT
102static void amiga_heartbeat(int on);
103#endif
104
105static struct console amiga_console_driver = {
106 .name = "debug",
107 .flags = CON_PRINTBUFFER,
108 .index = -1,
109};
110
111
112 /*
113 * Motherboard Resources present in all Amiga models
114 */
115
116static struct {
117 struct resource _ciab, _ciaa, _custom, _kickstart;
118} mb_resources = {
119// { "Ranger Memory", 0x00c00000, 0x00c7ffff },
120 ._ciab = { "CIA B", 0x00bfd000, 0x00bfdfff },
121 ._ciaa = { "CIA A", 0x00bfe000, 0x00bfefff },
122 ._custom = { "Custom I/O", 0x00dff000, 0x00dfffff },
123 ._kickstart = { "Kickstart ROM", 0x00f80000, 0x00ffffff }
124};
125
126static struct resource rtc_resource = {
127 NULL, 0x00dc0000, 0x00dcffff
128};
129
130static struct resource ram_resource[NUM_MEMINFO];
131
132
133 /*
134 * Parse an Amiga-specific record in the bootinfo
135 */
136
137int amiga_parse_bootinfo(const struct bi_record *record)
138{
139 int unknown = 0;
140 const unsigned long *data = record->data;
141
142 switch (record->tag) {
143 case BI_AMIGA_MODEL:
144 {
145 unsigned long d = *data;
146
147 powerup_PCI_present = d & 0x100;
148 amiga_model = d & 0xff;
149 }
150 break;
151
152 case BI_AMIGA_ECLOCK:
153 amiga_eclock = *data;
154 break;
155
156 case BI_AMIGA_CHIPSET:
157 amiga_chipset = *data;
158 break;
159
160 case BI_AMIGA_CHIP_SIZE:
161 amiga_chip_size = *(const int *)data;
162 break;
163
164 case BI_AMIGA_VBLANK:
165 amiga_vblank = *(const unsigned char *)data;
166 break;
167
168 case BI_AMIGA_PSFREQ:
169 amiga_psfreq = *(const unsigned char *)data;
170 break;
171
172 case BI_AMIGA_AUTOCON:
173#ifdef CONFIG_ZORRO
174 if (zorro_num_autocon < ZORRO_NUM_AUTO) {
175 const struct ConfigDev *cd = (struct ConfigDev *)data;
176 struct zorro_dev *dev = &zorro_autocon[zorro_num_autocon++];
177 dev->rom = cd->cd_Rom;
178 dev->slotaddr = cd->cd_SlotAddr;
179 dev->slotsize = cd->cd_SlotSize;
180 dev->resource.start = (unsigned long)cd->cd_BoardAddr;
181 dev->resource.end = dev->resource.start+cd->cd_BoardSize-1;
182 } else
183 printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
184#endif /* CONFIG_ZORRO */
185 break;
186
187 case BI_AMIGA_SERPER:
188 /* serial port period: ignored here */
189 break;
190
191 case BI_AMIGA_PUP_BRIDGE:
192 powerup_PCI_present = *(const unsigned short *)data;
193 break;
194
195 case BI_AMIGA_BPPC_SCSI:
196 powerup_BPPCPLUS_present = *(const unsigned short *)data;
197 break;
198
199 default:
200 unknown = 1;
201 }
202 return(unknown);
203}
204
205 /*
206 * Identify builtin hardware
207 */
208
209static void __init amiga_identify(void)
210{
211 /* Fill in some default values, if necessary */
212 if (amiga_eclock == 0)
213 amiga_eclock = 709379;
214
215 memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));
216
217 printk("Amiga hardware found: ");
218 if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
219 printk("[%s] ", amiga_models[amiga_model-AMI_500]);
220 strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
221 }
222
223 switch(amiga_model) {
224 case AMI_UNKNOWN:
225 goto Generic;
226
227 case AMI_600:
228 case AMI_1200:
229 AMIGAHW_SET(A1200_IDE);
230 AMIGAHW_SET(PCMCIA);
231 case AMI_500:
232 case AMI_500PLUS:
233 case AMI_1000:
234 case AMI_2000:
235 case AMI_2500:
236 AMIGAHW_SET(A2000_CLK); /* Is this correct for all models? */
237 goto Generic;
238
239 case AMI_3000:
240 case AMI_3000T:
241 AMIGAHW_SET(AMBER_FF);
242 AMIGAHW_SET(MAGIC_REKICK);
243 /* fall through */
244 case AMI_3000PLUS:
245 AMIGAHW_SET(A3000_SCSI);
246 AMIGAHW_SET(A3000_CLK);
247 AMIGAHW_SET(ZORRO3);
248 goto Generic;
249
250 case AMI_4000T:
251 AMIGAHW_SET(A4000_SCSI);
252 /* fall through */
253 case AMI_4000:
254 AMIGAHW_SET(A4000_IDE);
255 AMIGAHW_SET(A3000_CLK);
256 AMIGAHW_SET(ZORRO3);
257 goto Generic;
258
259 case AMI_CDTV:
260 case AMI_CD32:
261 AMIGAHW_SET(CD_ROM);
262 AMIGAHW_SET(A2000_CLK); /* Is this correct? */
263 goto Generic;
264
265 Generic:
266 AMIGAHW_SET(AMI_VIDEO);
267 AMIGAHW_SET(AMI_BLITTER);
268 AMIGAHW_SET(AMI_AUDIO);
269 AMIGAHW_SET(AMI_FLOPPY);
270 AMIGAHW_SET(AMI_KEYBOARD);
271 AMIGAHW_SET(AMI_MOUSE);
272 AMIGAHW_SET(AMI_SERIAL);
273 AMIGAHW_SET(AMI_PARALLEL);
274 AMIGAHW_SET(CHIP_RAM);
275 AMIGAHW_SET(PAULA);
276
277 switch(amiga_chipset) {
278 case CS_OCS:
279 case CS_ECS:
280 case CS_AGA:
Al Virob4290a22006-01-12 01:06:12 -0800281 switch (amiga_custom.deniseid & 0xf) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 case 0x0c:
283 AMIGAHW_SET(DENISE_HR);
284 break;
285 case 0x08:
286 AMIGAHW_SET(LISA);
287 break;
288 }
289 break;
290 default:
291 AMIGAHW_SET(DENISE);
292 break;
293 }
Al Virob4290a22006-01-12 01:06:12 -0800294 switch ((amiga_custom.vposr>>8) & 0x7f) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 case 0x00:
296 AMIGAHW_SET(AGNUS_PAL);
297 break;
298 case 0x10:
299 AMIGAHW_SET(AGNUS_NTSC);
300 break;
301 case 0x20:
302 case 0x21:
303 AMIGAHW_SET(AGNUS_HR_PAL);
304 break;
305 case 0x30:
306 case 0x31:
307 AMIGAHW_SET(AGNUS_HR_NTSC);
308 break;
309 case 0x22:
310 case 0x23:
311 AMIGAHW_SET(ALICE_PAL);
312 break;
313 case 0x32:
314 case 0x33:
315 AMIGAHW_SET(ALICE_NTSC);
316 break;
317 }
318 AMIGAHW_SET(ZORRO);
319 break;
320
321 case AMI_DRACO:
322 panic("No support for Draco yet");
323
324 default:
325 panic("Unknown Amiga Model");
326 }
327
328#define AMIGAHW_ANNOUNCE(name, str) \
329 if (AMIGAHW_PRESENT(name)) \
330 printk(str)
331
332 AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO ");
333 AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER ");
334 AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF ");
335 AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO ");
336 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY ");
337 AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI ");
338 AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI ");
339 AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE ");
340 AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE ");
341 AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM ");
342 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD ");
343 AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE ");
344 AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL ");
345 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL ");
346 AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK ");
347 AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK ");
348 AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM ");
349 AMIGAHW_ANNOUNCE(PAULA, "PAULA ");
350 AMIGAHW_ANNOUNCE(DENISE, "DENISE ");
351 AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR ");
352 AMIGAHW_ANNOUNCE(LISA, "LISA ");
353 AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL ");
354 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC ");
355 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL ");
356 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC ");
357 AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL ");
358 AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC ");
359 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK ");
360 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA ");
361 if (AMIGAHW_PRESENT(ZORRO))
362 printk("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : "");
363 printk("\n");
364
365#undef AMIGAHW_ANNOUNCE
366}
367
368 /*
369 * Setup the Amiga configuration info
370 */
371
372void __init config_amiga(void)
373{
374 int i;
375
376 amiga_debug_init();
377 amiga_identify();
378
379 /* Some APUS boxes may have PCI memory, but ... */
380 iomem_resource.name = "Memory";
381 for (i = 0; i < 4; i++)
382 request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);
383
384 mach_sched_init = amiga_sched_init;
385 mach_init_IRQ = amiga_init_IRQ;
386#ifndef CONFIG_APUS
387 mach_default_handler = &amiga_default_handler;
388 mach_request_irq = amiga_request_irq;
389 mach_free_irq = amiga_free_irq;
390 enable_irq = amiga_enable_irq;
391 disable_irq = amiga_disable_irq;
392#endif
393 mach_get_model = amiga_get_model;
394 mach_get_hardware_list = amiga_get_hardware_list;
395 mach_gettimeoffset = amiga_gettimeoffset;
396 if (AMIGAHW_PRESENT(A3000_CLK)){
397 mach_gettod = a3000_gettod;
398 rtc_resource.name = "A3000 RTC";
399 request_resource(&iomem_resource, &rtc_resource);
400 }
401 else{ /* if (AMIGAHW_PRESENT(A2000_CLK)) */
402 mach_gettod = a2000_gettod;
403 rtc_resource.name = "A2000 RTC";
404 request_resource(&iomem_resource, &rtc_resource);
405 }
406
407 mach_max_dma_address = 0xffffffff; /*
408 * default MAX_DMA=0xffffffff
409 * on all machines. If we don't
410 * do so, the SCSI code will not
411 * be able to allocate any mem
412 * for transfers, unless we are
413 * dealing with a Z2 mem only
414 * system. /Jes
415 */
416
417 mach_hwclk = amiga_hwclk;
418 mach_set_clock_mmss = amiga_set_clock_mmss;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 mach_reset = amiga_reset;
420#ifdef CONFIG_HEARTBEAT
421 mach_heartbeat = amiga_heartbeat;
422#endif
423
424 /* Fill in the clock values (based on the 700 kHz E-Clock) */
425 amiga_masterclock = 40*amiga_eclock; /* 28 MHz */
426 amiga_colorclock = 5*amiga_eclock; /* 3.5 MHz */
427
428 /* clear all DMA bits */
Al Virob4290a22006-01-12 01:06:12 -0800429 amiga_custom.dmacon = DMAF_ALL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 /* ensure that the DMA master bit is set */
Al Virob4290a22006-01-12 01:06:12 -0800431 amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* request all RAM */
434 for (i = 0; i < m68k_num_memory; i++) {
435 ram_resource[i].name =
436 (m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" :
437 (m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" :
438 "16-bit Slow RAM";
439 ram_resource[i].start = m68k_memory[i].addr;
440 ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1;
441 request_resource(&iomem_resource, &ram_resource[i]);
442 }
443
444 /* initialize chipram allocator */
445 amiga_chip_init ();
446
447 /* debugging using chipram */
448 if (!strcmp( m68k_debug_device, "mem" )){
449 if (!AMIGAHW_PRESENT(CHIP_RAM))
450 printk("Warning: no chipram present for debugging\n");
451 else {
452 amiga_savekmsg_init();
453 amiga_console_driver.write = amiga_mem_console_write;
454 register_console(&amiga_console_driver);
455 }
456 }
457
458 /* our beloved beeper */
459 if (AMIGAHW_PRESENT(AMI_AUDIO))
460 amiga_init_sound();
461
462 /*
463 * if it is an A3000, set the magic bit that forces
464 * a hard rekick
465 */
466 if (AMIGAHW_PRESENT(MAGIC_REKICK))
467 *(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
468}
469
470static unsigned short jiffy_ticks;
471
472static void __init amiga_sched_init(irqreturn_t (*timer_routine)(int, void *,
473 struct pt_regs *))
474{
475 static struct resource sched_res = {
476 "timer", 0x00bfd400, 0x00bfd5ff,
477 };
478 jiffy_ticks = (amiga_eclock+HZ/2)/HZ;
479
480 if (request_resource(&mb_resources._ciab, &sched_res))
481 printk("Cannot allocate ciab.ta{lo,hi}\n");
482 ciab.cra &= 0xC0; /* turn off timer A, continuous mode, from Eclk */
483 ciab.talo = jiffy_ticks % 256;
484 ciab.tahi = jiffy_ticks / 256;
485
486 /* install interrupt service routine for CIAB Timer A
487 *
488 * Please don't change this to use ciaa, as it interferes with the
489 * SCSI code. We'll have to take a look at this later
490 */
491 request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, 0, "timer", NULL);
492 /* start timer */
493 ciab.cra |= 0x11;
494}
495
496#define TICK_SIZE 10000
497
498extern unsigned char cia_get_irq_mask(unsigned int irq);
499
500/* This is always executed with interrupts disabled. */
501static unsigned long amiga_gettimeoffset (void)
502{
503 unsigned short hi, lo, hi2;
504 unsigned long ticks, offset = 0;
505
506 /* read CIA B timer A current value */
507 hi = ciab.tahi;
508 lo = ciab.talo;
509 hi2 = ciab.tahi;
510
511 if (hi != hi2) {
512 lo = ciab.talo;
513 hi = hi2;
514 }
515
516 ticks = hi << 8 | lo;
517
518 if (ticks > jiffy_ticks / 2)
519 /* check for pending interrupt */
520 if (cia_get_irq_mask(IRQ_AMIGA_CIAB) & CIA_ICR_TA)
521 offset = 10000;
522
523 ticks = jiffy_ticks - ticks;
524 ticks = (10000 * ticks) / jiffy_ticks;
525
526 return ticks + offset;
527}
528
529static void a3000_gettod (int *yearp, int *monp, int *dayp,
530 int *hourp, int *minp, int *secp)
531{
532 volatile struct tod3000 *tod = TOD_3000;
533
534 tod->cntrl1 = TOD3000_CNTRL1_HOLD;
535
536 *secp = tod->second1 * 10 + tod->second2;
537 *minp = tod->minute1 * 10 + tod->minute2;
538 *hourp = tod->hour1 * 10 + tod->hour2;
539 *dayp = tod->day1 * 10 + tod->day2;
540 *monp = tod->month1 * 10 + tod->month2;
541 *yearp = tod->year1 * 10 + tod->year2;
542
543 tod->cntrl1 = TOD3000_CNTRL1_FREE;
544}
545
546static void a2000_gettod (int *yearp, int *monp, int *dayp,
547 int *hourp, int *minp, int *secp)
548{
549 volatile struct tod2000 *tod = TOD_2000;
550
551 tod->cntrl1 = TOD2000_CNTRL1_HOLD;
552
553 while (tod->cntrl1 & TOD2000_CNTRL1_BUSY)
554 ;
555
556 *secp = tod->second1 * 10 + tod->second2;
557 *minp = tod->minute1 * 10 + tod->minute2;
558 *hourp = (tod->hour1 & 3) * 10 + tod->hour2;
559 *dayp = tod->day1 * 10 + tod->day2;
560 *monp = tod->month1 * 10 + tod->month2;
561 *yearp = tod->year1 * 10 + tod->year2;
562
563 if (!(tod->cntrl3 & TOD2000_CNTRL3_24HMODE)){
564 if (!(tod->hour1 & TOD2000_HOUR1_PM) && *hourp == 12)
565 *hourp = 0;
566 else if ((tod->hour1 & TOD2000_HOUR1_PM) && *hourp != 12)
567 *hourp += 12;
568 }
569
570 tod->cntrl1 &= ~TOD2000_CNTRL1_HOLD;
571}
572
573static int amiga_hwclk(int op, struct hwclk_time *t)
574{
575 if (AMIGAHW_PRESENT(A3000_CLK)) {
576 volatile struct tod3000 *tod = TOD_3000;
577
578 tod->cntrl1 = TOD3000_CNTRL1_HOLD;
579
580 if (!op) { /* read */
581 t->sec = tod->second1 * 10 + tod->second2;
582 t->min = tod->minute1 * 10 + tod->minute2;
583 t->hour = tod->hour1 * 10 + tod->hour2;
584 t->day = tod->day1 * 10 + tod->day2;
585 t->wday = tod->weekday;
586 t->mon = tod->month1 * 10 + tod->month2 - 1;
587 t->year = tod->year1 * 10 + tod->year2;
588 if (t->year <= 69)
589 t->year += 100;
590 } else {
591 tod->second1 = t->sec / 10;
592 tod->second2 = t->sec % 10;
593 tod->minute1 = t->min / 10;
594 tod->minute2 = t->min % 10;
595 tod->hour1 = t->hour / 10;
596 tod->hour2 = t->hour % 10;
597 tod->day1 = t->day / 10;
598 tod->day2 = t->day % 10;
599 if (t->wday != -1)
600 tod->weekday = t->wday;
601 tod->month1 = (t->mon + 1) / 10;
602 tod->month2 = (t->mon + 1) % 10;
603 if (t->year >= 100)
604 t->year -= 100;
605 tod->year1 = t->year / 10;
606 tod->year2 = t->year % 10;
607 }
608
609 tod->cntrl1 = TOD3000_CNTRL1_FREE;
610 } else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
611 volatile struct tod2000 *tod = TOD_2000;
612
613 tod->cntrl1 = TOD2000_CNTRL1_HOLD;
614
615 while (tod->cntrl1 & TOD2000_CNTRL1_BUSY)
616 ;
617
618 if (!op) { /* read */
619 t->sec = tod->second1 * 10 + tod->second2;
620 t->min = tod->minute1 * 10 + tod->minute2;
621 t->hour = (tod->hour1 & 3) * 10 + tod->hour2;
622 t->day = tod->day1 * 10 + tod->day2;
623 t->wday = tod->weekday;
624 t->mon = tod->month1 * 10 + tod->month2 - 1;
625 t->year = tod->year1 * 10 + tod->year2;
626 if (t->year <= 69)
627 t->year += 100;
628
629 if (!(tod->cntrl3 & TOD2000_CNTRL3_24HMODE)){
630 if (!(tod->hour1 & TOD2000_HOUR1_PM) && t->hour == 12)
631 t->hour = 0;
632 else if ((tod->hour1 & TOD2000_HOUR1_PM) && t->hour != 12)
633 t->hour += 12;
634 }
635 } else {
636 tod->second1 = t->sec / 10;
637 tod->second2 = t->sec % 10;
638 tod->minute1 = t->min / 10;
639 tod->minute2 = t->min % 10;
640 if (tod->cntrl3 & TOD2000_CNTRL3_24HMODE)
641 tod->hour1 = t->hour / 10;
642 else if (t->hour >= 12)
643 tod->hour1 = TOD2000_HOUR1_PM +
644 (t->hour - 12) / 10;
645 else
646 tod->hour1 = t->hour / 10;
647 tod->hour2 = t->hour % 10;
648 tod->day1 = t->day / 10;
649 tod->day2 = t->day % 10;
650 if (t->wday != -1)
651 tod->weekday = t->wday;
652 tod->month1 = (t->mon + 1) / 10;
653 tod->month2 = (t->mon + 1) % 10;
654 if (t->year >= 100)
655 t->year -= 100;
656 tod->year1 = t->year / 10;
657 tod->year2 = t->year % 10;
658 }
659
660 tod->cntrl1 &= ~TOD2000_CNTRL1_HOLD;
661 }
662
663 return 0;
664}
665
666static int amiga_set_clock_mmss (unsigned long nowtime)
667{
668 short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;
669
670 if (AMIGAHW_PRESENT(A3000_CLK)) {
671 volatile struct tod3000 *tod = TOD_3000;
672
673 tod->cntrl1 = TOD3000_CNTRL1_HOLD;
674
675 tod->second1 = real_seconds / 10;
676 tod->second2 = real_seconds % 10;
677 tod->minute1 = real_minutes / 10;
678 tod->minute2 = real_minutes % 10;
679
680 tod->cntrl1 = TOD3000_CNTRL1_FREE;
681 } else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
682 volatile struct tod2000 *tod = TOD_2000;
683
684 tod->cntrl1 = TOD2000_CNTRL1_HOLD;
685
686 while (tod->cntrl1 & TOD2000_CNTRL1_BUSY)
687 ;
688
689 tod->second1 = real_seconds / 10;
690 tod->second2 = real_seconds % 10;
691 tod->minute1 = real_minutes / 10;
692 tod->minute2 = real_minutes % 10;
693
694 tod->cntrl1 &= ~TOD2000_CNTRL1_HOLD;
695 }
696
697 return 0;
698}
699
700static NORET_TYPE void amiga_reset( void )
701 ATTRIB_NORET;
702
703static void amiga_reset (void)
704{
705 for (;;);
706}
707
708
709 /*
710 * Debugging
711 */
712
713#define SAVEKMSG_MAXMEM 128*1024
714
715#define SAVEKMSG_MAGIC1 0x53415645 /* 'SAVE' */
716#define SAVEKMSG_MAGIC2 0x4B4D5347 /* 'KMSG' */
717
718struct savekmsg {
719 unsigned long magic1; /* SAVEKMSG_MAGIC1 */
720 unsigned long magic2; /* SAVEKMSG_MAGIC2 */
721 unsigned long magicptr; /* address of magic1 */
722 unsigned long size;
723 char data[0];
724};
725
726static struct savekmsg *savekmsg = NULL;
727
728static void amiga_mem_console_write(struct console *co, const char *s,
729 unsigned int count)
730{
731 if (savekmsg->size+count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
732 memcpy(savekmsg->data+savekmsg->size, s, count);
733 savekmsg->size += count;
734 }
735}
736
737static void amiga_savekmsg_init(void)
738{
739 static struct resource debug_res = { "Debug" };
740
741 savekmsg = amiga_chip_alloc_res(SAVEKMSG_MAXMEM, &debug_res);
742 savekmsg->magic1 = SAVEKMSG_MAGIC1;
743 savekmsg->magic2 = SAVEKMSG_MAGIC2;
744 savekmsg->magicptr = virt_to_phys(savekmsg);
745 savekmsg->size = 0;
746}
747
748static void amiga_serial_putc(char c)
749{
Al Virob4290a22006-01-12 01:06:12 -0800750 amiga_custom.serdat = (unsigned char)c | 0x100;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 mb();
Al Virob4290a22006-01-12 01:06:12 -0800752 while (!(amiga_custom.serdatr & 0x2000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 ;
754}
755
756void amiga_serial_console_write(struct console *co, const char *s,
757 unsigned int count)
758{
759#if 0 /* def CONFIG_KGDB */
760 /* FIXME:APUS GDB doesn't seem to like O-packages before it is
761 properly connected with the target. */
762 __gdb_output_string (s, count);
763#else
764 while (count--) {
765 if (*s == '\n')
766 amiga_serial_putc('\r');
767 amiga_serial_putc(*s++);
768 }
769#endif
770}
771
772#ifdef CONFIG_SERIAL_CONSOLE
773void amiga_serial_puts(const char *s)
774{
775 amiga_serial_console_write(NULL, s, strlen(s));
776}
777
778int amiga_serial_console_wait_key(struct console *co)
779{
780 int ch;
781
Al Virob4290a22006-01-12 01:06:12 -0800782 while (!(amiga_custom.intreqr & IF_RBF))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 barrier();
Al Virob4290a22006-01-12 01:06:12 -0800784 ch = amiga_custom.serdatr & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 /* clear the interrupt, so that another character can be read */
Al Virob4290a22006-01-12 01:06:12 -0800786 amiga_custom.intreq = IF_RBF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return ch;
788}
789
790void amiga_serial_gets(struct console *co, char *s, int len)
791{
792 int ch, cnt = 0;
793
794 while (1) {
795 ch = amiga_serial_console_wait_key(co);
796
797 /* Check for backspace. */
798 if (ch == 8 || ch == 127) {
799 if (cnt == 0) {
800 amiga_serial_putc('\007');
801 continue;
802 }
803 cnt--;
804 amiga_serial_puts("\010 \010");
805 continue;
806 }
807
808 /* Check for enter. */
809 if (ch == 10 || ch == 13)
810 break;
811
812 /* See if line is too long. */
813 if (cnt >= len + 1) {
814 amiga_serial_putc(7);
815 cnt--;
816 continue;
817 }
818
819 /* Store and echo character. */
820 s[cnt++] = ch;
821 amiga_serial_putc(ch);
822 }
823 /* Print enter. */
824 amiga_serial_puts("\r\n");
825 s[cnt] = 0;
826}
827#endif
828
829static void __init amiga_debug_init(void)
830{
831 if (!strcmp( m68k_debug_device, "ser" )) {
832 /* no initialization required (?) */
833 amiga_console_driver.write = amiga_serial_console_write;
834 register_console(&amiga_console_driver);
835 }
836}
837
838#ifdef CONFIG_HEARTBEAT
839static void amiga_heartbeat(int on)
840{
841 if (on)
842 ciaa.pra &= ~2;
843 else
844 ciaa.pra |= 2;
845}
846#endif
847
848 /*
849 * Amiga specific parts of /proc
850 */
851
852static void amiga_get_model(char *model)
853{
854 strcpy(model, amiga_model_name);
855}
856
857
858static int amiga_get_hardware_list(char *buffer)
859{
860 int len = 0;
861
862 if (AMIGAHW_PRESENT(CHIP_RAM))
863 len += sprintf(buffer+len, "Chip RAM:\t%ldK\n", amiga_chip_size>>10);
864 len += sprintf(buffer+len, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n",
865 amiga_psfreq, amiga_eclock);
866 if (AMIGAHW_PRESENT(AMI_VIDEO)) {
867 char *type;
868 switch(amiga_chipset) {
869 case CS_OCS:
870 type = "OCS";
871 break;
872 case CS_ECS:
873 type = "ECS";
874 break;
875 case CS_AGA:
876 type = "AGA";
877 break;
878 default:
879 type = "Old or Unknown";
880 break;
881 }
882 len += sprintf(buffer+len, "Graphics:\t%s\n", type);
883 }
884
885#define AMIGAHW_ANNOUNCE(name, str) \
886 if (AMIGAHW_PRESENT(name)) \
887 len += sprintf (buffer+len, "\t%s\n", str)
888
889 len += sprintf (buffer + len, "Detected hardware:\n");
890
891 AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video");
892 AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter");
893 AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer");
894 AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio");
895 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller");
896 AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)");
897 AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)");
898 AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)");
899 AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)");
900 AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive");
901 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard");
902 AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port");
903 AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port");
904 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port");
905 AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)");
906 AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)");
907 AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM");
908 AMIGAHW_ANNOUNCE(PAULA, "Paula 8364");
909 AMIGAHW_ANNOUNCE(DENISE, "Denise 8362");
910 AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373");
911 AMIGAHW_ANNOUNCE(LISA, "Lisa 8375");
912 AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371");
913 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370");
914 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372");
915 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372");
916 AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374");
917 AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374");
918 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
919 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
920 if (AMIGAHW_PRESENT(ZORRO))
921 len += sprintf(buffer+len, "\tZorro II%s AutoConfig: %d Expansion "
922 "Device%s\n",
923 AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
924 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
925
926#undef AMIGAHW_ANNOUNCE
927
928 return(len);
929}
930
931#ifdef CONFIG_APUS
932int get_hardware_list(char *buffer)
933{
934 extern int get_cpuinfo(char *buffer);
935 int len = 0;
936 char model[80];
937 u_long mem;
938 int i;
939
940 if (mach_get_model)
941 mach_get_model(model);
942 else
943 strcpy(model, "Unknown PowerPC");
944
945 len += sprintf(buffer+len, "Model:\t\t%s\n", model);
946 len += get_cpuinfo(buffer+len);
947 for (mem = 0, i = 0; i < m68k_realnum_memory; i++)
948 mem += m68k_memory[i].size;
949 len += sprintf(buffer+len, "System Memory:\t%ldK\n", mem>>10);
950
951 if (mach_get_hardware_list)
952 len += mach_get_hardware_list(buffer+len);
953
954 return(len);
955}
956#endif