xref: /linux/arch/m68k/amiga/config.c (revision 3381df0954199458fa3993db72fb427f0ed1e43b)
1 /*
2  *  linux/arch/m68k/amiga/config.c
3  *
4  *  Copyright (C) 1993 Hamish Macdonald
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file COPYING in the main directory of this archive
8  * for more details.
9  */
10 
11 /*
12  * Miscellaneous Amiga stuff
13  */
14 
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/mm.h>
18 #include <linux/seq_file.h>
19 #include <linux/tty.h>
20 #include <linux/clocksource.h>
21 #include <linux/console.h>
22 #include <linux/rtc.h>
23 #include <linux/init.h>
24 #include <linux/vt_kern.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/zorro.h>
28 #include <linux/module.h>
29 #include <linux/keyboard.h>
30 
31 #include <asm/bootinfo.h>
32 #include <asm/bootinfo-amiga.h>
33 #include <asm/byteorder.h>
34 #include <asm/setup.h>
35 #include <asm/pgtable.h>
36 #include <asm/amigahw.h>
37 #include <asm/amigaints.h>
38 #include <asm/irq.h>
39 #include <asm/machdep.h>
40 #include <asm/io.h>
41 
42 static unsigned long amiga_model;
43 
44 unsigned long amiga_eclock;
45 EXPORT_SYMBOL(amiga_eclock);
46 
47 unsigned long amiga_colorclock;
48 EXPORT_SYMBOL(amiga_colorclock);
49 
50 unsigned long amiga_chipset;
51 EXPORT_SYMBOL(amiga_chipset);
52 
53 unsigned char amiga_vblank;
54 EXPORT_SYMBOL(amiga_vblank);
55 
56 static unsigned char amiga_psfreq;
57 
58 struct amiga_hw_present amiga_hw_present;
59 EXPORT_SYMBOL(amiga_hw_present);
60 
61 static char s_a500[] __initdata = "A500";
62 static char s_a500p[] __initdata = "A500+";
63 static char s_a600[] __initdata = "A600";
64 static char s_a1000[] __initdata = "A1000";
65 static char s_a1200[] __initdata = "A1200";
66 static char s_a2000[] __initdata = "A2000";
67 static char s_a2500[] __initdata = "A2500";
68 static char s_a3000[] __initdata = "A3000";
69 static char s_a3000t[] __initdata = "A3000T";
70 static char s_a3000p[] __initdata = "A3000+";
71 static char s_a4000[] __initdata = "A4000";
72 static char s_a4000t[] __initdata = "A4000T";
73 static char s_cdtv[] __initdata = "CDTV";
74 static char s_cd32[] __initdata = "CD32";
75 static char s_draco[] __initdata = "Draco";
76 static char *amiga_models[] __initdata = {
77 	[AMI_500-AMI_500]	= s_a500,
78 	[AMI_500PLUS-AMI_500]	= s_a500p,
79 	[AMI_600-AMI_500]	= s_a600,
80 	[AMI_1000-AMI_500]	= s_a1000,
81 	[AMI_1200-AMI_500]	= s_a1200,
82 	[AMI_2000-AMI_500]	= s_a2000,
83 	[AMI_2500-AMI_500]	= s_a2500,
84 	[AMI_3000-AMI_500]	= s_a3000,
85 	[AMI_3000T-AMI_500]	= s_a3000t,
86 	[AMI_3000PLUS-AMI_500]	= s_a3000p,
87 	[AMI_4000-AMI_500]	= s_a4000,
88 	[AMI_4000T-AMI_500]	= s_a4000t,
89 	[AMI_CDTV-AMI_500]	= s_cdtv,
90 	[AMI_CD32-AMI_500]	= s_cd32,
91 	[AMI_DRACO-AMI_500]	= s_draco,
92 };
93 
94 static char amiga_model_name[13] = "Amiga ";
95 
96 static void amiga_sched_init(irq_handler_t handler);
97 static void amiga_get_model(char *model);
98 static void amiga_get_hardware_list(struct seq_file *m);
99 extern void amiga_mksound(unsigned int count, unsigned int ticks);
100 static void amiga_reset(void);
101 extern void amiga_init_sound(void);
102 static void amiga_mem_console_write(struct console *co, const char *b,
103 				    unsigned int count);
104 #ifdef CONFIG_HEARTBEAT
105 static void amiga_heartbeat(int on);
106 #endif
107 
108 static struct console amiga_console_driver = {
109 	.name	= "debug",
110 	.flags	= CON_PRINTBUFFER,
111 	.index	= -1,
112 };
113 
114 
115     /*
116      *  Motherboard Resources present in all Amiga models
117      */
118 
119 static struct {
120 	struct resource _ciab, _ciaa, _custom, _kickstart;
121 } mb_resources = {
122 	._ciab = {
123 		.name = "CIA B", .start = 0x00bfd000, .end = 0x00bfdfff
124 	},
125 	._ciaa = {
126 		.name = "CIA A", .start = 0x00bfe000, .end = 0x00bfefff
127 	},
128 	._custom = {
129 		.name = "Custom I/O", .start = 0x00dff000, .end = 0x00dfffff
130 	},
131 	._kickstart = {
132 		.name = "Kickstart ROM", .start = 0x00f80000, .end = 0x00ffffff
133 	}
134 };
135 
136 static struct resource ram_resource[NUM_MEMINFO];
137 
138 
139     /*
140      *  Parse an Amiga-specific record in the bootinfo
141      */
142 
143 int __init amiga_parse_bootinfo(const struct bi_record *record)
144 {
145 	int unknown = 0;
146 	const void *data = record->data;
147 
148 	switch (be16_to_cpu(record->tag)) {
149 	case BI_AMIGA_MODEL:
150 		amiga_model = be32_to_cpup(data);
151 		break;
152 
153 	case BI_AMIGA_ECLOCK:
154 		amiga_eclock = be32_to_cpup(data);
155 		break;
156 
157 	case BI_AMIGA_CHIPSET:
158 		amiga_chipset = be32_to_cpup(data);
159 		break;
160 
161 	case BI_AMIGA_CHIP_SIZE:
162 		amiga_chip_size = be32_to_cpup(data);
163 		break;
164 
165 	case BI_AMIGA_VBLANK:
166 		amiga_vblank = *(const __u8 *)data;
167 		break;
168 
169 	case BI_AMIGA_PSFREQ:
170 		amiga_psfreq = *(const __u8 *)data;
171 		break;
172 
173 	case BI_AMIGA_AUTOCON:
174 #ifdef CONFIG_ZORRO
175 		if (zorro_num_autocon < ZORRO_NUM_AUTO) {
176 			const struct ConfigDev *cd = data;
177 			struct zorro_dev_init *dev = &zorro_autocon_init[zorro_num_autocon++];
178 			dev->rom = cd->cd_Rom;
179 			dev->slotaddr = be16_to_cpu(cd->cd_SlotAddr);
180 			dev->slotsize = be16_to_cpu(cd->cd_SlotSize);
181 			dev->boardaddr = be32_to_cpu(cd->cd_BoardAddr);
182 			dev->boardsize = be32_to_cpu(cd->cd_BoardSize);
183 		} else
184 			pr_warn("amiga_parse_bootinfo: too many AutoConfig devices\n");
185 #endif /* CONFIG_ZORRO */
186 		break;
187 
188 	case BI_AMIGA_SERPER:
189 		/* serial port period: ignored here */
190 		break;
191 
192 	default:
193 		unknown = 1;
194 	}
195 	return unknown;
196 }
197 
198     /*
199      *  Identify builtin hardware
200      */
201 
202 static void __init amiga_identify(void)
203 {
204 	/* Fill in some default values, if necessary */
205 	if (amiga_eclock == 0)
206 		amiga_eclock = 709379;
207 
208 	memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));
209 
210 	pr_info("Amiga hardware found: ");
211 	if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
212 		pr_cont("[%s] ", amiga_models[amiga_model-AMI_500]);
213 		strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
214 	}
215 
216 	switch (amiga_model) {
217 	case AMI_UNKNOWN:
218 		goto Generic;
219 
220 	case AMI_600:
221 	case AMI_1200:
222 		AMIGAHW_SET(A1200_IDE);
223 		AMIGAHW_SET(PCMCIA);
224 		fallthrough;
225 	case AMI_500:
226 	case AMI_500PLUS:
227 	case AMI_1000:
228 	case AMI_2000:
229 	case AMI_2500:
230 		AMIGAHW_SET(A2000_CLK);	/* Is this correct for all models? */
231 		goto Generic;
232 
233 	case AMI_3000:
234 	case AMI_3000T:
235 		AMIGAHW_SET(AMBER_FF);
236 		AMIGAHW_SET(MAGIC_REKICK);
237 		fallthrough;
238 	case AMI_3000PLUS:
239 		AMIGAHW_SET(A3000_SCSI);
240 		AMIGAHW_SET(A3000_CLK);
241 		AMIGAHW_SET(ZORRO3);
242 		goto Generic;
243 
244 	case AMI_4000T:
245 		AMIGAHW_SET(A4000_SCSI);
246 		fallthrough;
247 	case AMI_4000:
248 		AMIGAHW_SET(A4000_IDE);
249 		AMIGAHW_SET(A3000_CLK);
250 		AMIGAHW_SET(ZORRO3);
251 		goto Generic;
252 
253 	case AMI_CDTV:
254 	case AMI_CD32:
255 		AMIGAHW_SET(CD_ROM);
256 		AMIGAHW_SET(A2000_CLK);             /* Is this correct? */
257 		goto Generic;
258 
259 	Generic:
260 		AMIGAHW_SET(AMI_VIDEO);
261 		AMIGAHW_SET(AMI_BLITTER);
262 		AMIGAHW_SET(AMI_AUDIO);
263 		AMIGAHW_SET(AMI_FLOPPY);
264 		AMIGAHW_SET(AMI_KEYBOARD);
265 		AMIGAHW_SET(AMI_MOUSE);
266 		AMIGAHW_SET(AMI_SERIAL);
267 		AMIGAHW_SET(AMI_PARALLEL);
268 		AMIGAHW_SET(CHIP_RAM);
269 		AMIGAHW_SET(PAULA);
270 
271 		switch (amiga_chipset) {
272 		case CS_OCS:
273 		case CS_ECS:
274 		case CS_AGA:
275 			switch (amiga_custom.deniseid & 0xf) {
276 			case 0x0c:
277 				AMIGAHW_SET(DENISE_HR);
278 				break;
279 			case 0x08:
280 				AMIGAHW_SET(LISA);
281 				break;
282 			}
283 			break;
284 		default:
285 			AMIGAHW_SET(DENISE);
286 			break;
287 		}
288 		switch ((amiga_custom.vposr>>8) & 0x7f) {
289 		case 0x00:
290 			AMIGAHW_SET(AGNUS_PAL);
291 			break;
292 		case 0x10:
293 			AMIGAHW_SET(AGNUS_NTSC);
294 			break;
295 		case 0x20:
296 		case 0x21:
297 			AMIGAHW_SET(AGNUS_HR_PAL);
298 			break;
299 		case 0x30:
300 		case 0x31:
301 			AMIGAHW_SET(AGNUS_HR_NTSC);
302 			break;
303 		case 0x22:
304 		case 0x23:
305 			AMIGAHW_SET(ALICE_PAL);
306 			break;
307 		case 0x32:
308 		case 0x33:
309 			AMIGAHW_SET(ALICE_NTSC);
310 			break;
311 		}
312 		AMIGAHW_SET(ZORRO);
313 		break;
314 
315 	case AMI_DRACO:
316 		panic("No support for Draco yet");
317 
318 	default:
319 		panic("Unknown Amiga Model");
320 	}
321 
322 #define AMIGAHW_ANNOUNCE(name, str)		\
323 	if (AMIGAHW_PRESENT(name))		\
324 		pr_cont(str)
325 
326 	AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO ");
327 	AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER ");
328 	AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF ");
329 	AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO ");
330 	AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY ");
331 	AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI ");
332 	AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI ");
333 	AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE ");
334 	AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE ");
335 	AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM ");
336 	AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD ");
337 	AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE ");
338 	AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL ");
339 	AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL ");
340 	AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK ");
341 	AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK ");
342 	AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM ");
343 	AMIGAHW_ANNOUNCE(PAULA, "PAULA ");
344 	AMIGAHW_ANNOUNCE(DENISE, "DENISE ");
345 	AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR ");
346 	AMIGAHW_ANNOUNCE(LISA, "LISA ");
347 	AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL ");
348 	AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC ");
349 	AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL ");
350 	AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC ");
351 	AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL ");
352 	AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC ");
353 	AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK ");
354 	AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA ");
355 	if (AMIGAHW_PRESENT(ZORRO))
356 		pr_cont("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : "");
357 	pr_cont("\n");
358 
359 #undef AMIGAHW_ANNOUNCE
360 }
361 
362 
363 static unsigned long amiga_random_get_entropy(void)
364 {
365 	/* VPOSR/VHPOSR provide at least 17 bits of data changing at 1.79 MHz */
366 	return *(unsigned long *)&amiga_custom.vposr;
367 }
368 
369 
370     /*
371      *  Setup the Amiga configuration info
372      */
373 
374 void __init config_amiga(void)
375 {
376 	int i;
377 
378 	amiga_identify();
379 
380 	/* Yuk, we don't have PCI memory */
381 	iomem_resource.name = "Memory";
382 	for (i = 0; i < 4; i++)
383 		request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);
384 
385 	mach_sched_init      = amiga_sched_init;
386 	mach_init_IRQ        = amiga_init_IRQ;
387 	mach_get_model       = amiga_get_model;
388 	mach_get_hardware_list = amiga_get_hardware_list;
389 
390 	/*
391 	 * default MAX_DMA=0xffffffff on all machines. If we don't do so, the SCSI
392 	 * code will not be able to allocate any mem for transfers, unless we are
393 	 * dealing with a Z2 mem only system.                  /Jes
394 	 */
395 	mach_max_dma_address = 0xffffffff;
396 
397 	mach_reset           = amiga_reset;
398 #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
399 	mach_beep            = amiga_mksound;
400 #endif
401 
402 #ifdef CONFIG_HEARTBEAT
403 	mach_heartbeat = amiga_heartbeat;
404 #endif
405 
406 	mach_random_get_entropy = amiga_random_get_entropy;
407 
408 	/* Fill in the clock value (based on the 700 kHz E-Clock) */
409 	amiga_colorclock = 5*amiga_eclock;	/* 3.5 MHz */
410 
411 	/* clear all DMA bits */
412 	amiga_custom.dmacon = DMAF_ALL;
413 	/* ensure that the DMA master bit is set */
414 	amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
415 
416 	/* don't use Z2 RAM as system memory on Z3 capable machines */
417 	if (AMIGAHW_PRESENT(ZORRO3)) {
418 		int i, j;
419 		u32 disabled_z2mem = 0;
420 
421 		for (i = 0; i < m68k_num_memory; i++) {
422 			if (m68k_memory[i].addr < 16*1024*1024) {
423 				if (i == 0) {
424 					/* don't cut off the branch we're sitting on */
425 					pr_warn("Warning: kernel runs in Zorro II memory\n");
426 					continue;
427 				}
428 				disabled_z2mem += m68k_memory[i].size;
429 				m68k_num_memory--;
430 				for (j = i; j < m68k_num_memory; j++)
431 					m68k_memory[j] = m68k_memory[j+1];
432 				i--;
433 			}
434 		}
435 		if (disabled_z2mem)
436 			pr_info("%dK of Zorro II memory will not be used as system memory\n",
437 				disabled_z2mem>>10);
438 	}
439 
440 	/* request all RAM */
441 	for (i = 0; i < m68k_num_memory; i++) {
442 		ram_resource[i].name =
443 			(m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" :
444 			(m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" :
445 			"16-bit Slow RAM";
446 		ram_resource[i].start = m68k_memory[i].addr;
447 		ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1;
448 		request_resource(&iomem_resource, &ram_resource[i]);
449 	}
450 
451 	/* initialize chipram allocator */
452 	amiga_chip_init();
453 
454 	/* our beloved beeper */
455 	if (AMIGAHW_PRESENT(AMI_AUDIO))
456 		amiga_init_sound();
457 
458 	/*
459 	 * if it is an A3000, set the magic bit that forces
460 	 * a hard rekick
461 	 */
462 	if (AMIGAHW_PRESENT(MAGIC_REKICK))
463 		*(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
464 }
465 
466 static u64 amiga_read_clk(struct clocksource *cs);
467 
468 static struct clocksource amiga_clk = {
469 	.name   = "ciab",
470 	.rating = 250,
471 	.read   = amiga_read_clk,
472 	.mask   = CLOCKSOURCE_MASK(32),
473 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
474 };
475 
476 static unsigned short jiffy_ticks;
477 static u32 clk_total, clk_offset;
478 
479 static irqreturn_t ciab_timer_handler(int irq, void *dev_id)
480 {
481 	irq_handler_t timer_routine = dev_id;
482 
483 	clk_total += jiffy_ticks;
484 	clk_offset = 0;
485 	timer_routine(0, NULL);
486 
487 	return IRQ_HANDLED;
488 }
489 
490 static void __init amiga_sched_init(irq_handler_t timer_routine)
491 {
492 	static struct resource sched_res = {
493 		.name = "timer", .start = 0x00bfd400, .end = 0x00bfd5ff,
494 	};
495 	jiffy_ticks = DIV_ROUND_CLOSEST(amiga_eclock, HZ);
496 
497 	if (request_resource(&mb_resources._ciab, &sched_res))
498 		pr_warn("Cannot allocate ciab.ta{lo,hi}\n");
499 	ciab.cra &= 0xC0;   /* turn off timer A, continuous mode, from Eclk */
500 	ciab.talo = jiffy_ticks % 256;
501 	ciab.tahi = jiffy_ticks / 256;
502 
503 	/* install interrupt service routine for CIAB Timer A
504 	 *
505 	 * Please don't change this to use ciaa, as it interferes with the
506 	 * SCSI code. We'll have to take a look at this later
507 	 */
508 	if (request_irq(IRQ_AMIGA_CIAB_TA, ciab_timer_handler, IRQF_TIMER,
509 			"timer", timer_routine))
510 		pr_err("Couldn't register timer interrupt\n");
511 	/* start timer */
512 	ciab.cra |= 0x11;
513 
514 	clocksource_register_hz(&amiga_clk, amiga_eclock);
515 }
516 
517 static u64 amiga_read_clk(struct clocksource *cs)
518 {
519 	unsigned short hi, lo, hi2;
520 	unsigned long flags;
521 	u32 ticks;
522 
523 	local_irq_save(flags);
524 
525 	/* read CIA B timer A current value */
526 	hi  = ciab.tahi;
527 	lo  = ciab.talo;
528 	hi2 = ciab.tahi;
529 
530 	if (hi != hi2) {
531 		lo = ciab.talo;
532 		hi = hi2;
533 	}
534 
535 	ticks = hi << 8 | lo;
536 
537 	if (ticks > jiffy_ticks / 2)
538 		/* check for pending interrupt */
539 		if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
540 			clk_offset = jiffy_ticks;
541 
542 	ticks = jiffy_ticks - ticks;
543 	ticks += clk_offset + clk_total;
544 
545 	local_irq_restore(flags);
546 
547 	return ticks;
548 }
549 
550 static void amiga_reset(void)  __noreturn;
551 
552 static void amiga_reset(void)
553 {
554 	unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
555 	unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label);
556 
557 	local_irq_disable();
558 	if (CPU_IS_040_OR_060)
559 		/* Setup transparent translation registers for mapping
560 		 * of 16 MB kernel segment before disabling translation
561 		 */
562 		asm volatile ("\n"
563 			"	move.l	%0,%%d0\n"
564 			"	and.l	#0xff000000,%%d0\n"
565 			"	or.w	#0xe020,%%d0\n"   /* map 16 MB, enable, cacheable */
566 			"	.chip	68040\n"
567 			"	movec	%%d0,%%itt0\n"
568 			"	movec	%%d0,%%dtt0\n"
569 			"	.chip	68k\n"
570 			"	jmp	%0@\n"
571 			: /* no outputs */
572 			: "a" (jmp_addr040)
573 			: "d0");
574 	else
575 		/* for 680[23]0, just disable translation and jump to the physical
576 		 * address of the label
577 		 */
578 		asm volatile ("\n"
579 			"	pmove	%%tc,%@\n"
580 			"	bclr	#7,%@\n"
581 			"	pmove	%@,%%tc\n"
582 			"	jmp	%0@\n"
583 			: /* no outputs */
584 			: "a" (jmp_addr));
585 jmp_addr_label040:
586 	/* disable translation on '040 now */
587 	asm volatile ("\n"
588 		"	moveq	#0,%%d0\n"
589 		"	.chip	68040\n"
590 		"	movec	%%d0,%%tc\n"	/* disable MMU */
591 		"	.chip	68k\n"
592 		: /* no outputs */
593 		: /* no inputs */
594 		: "d0");
595 
596 	jmp_addr_label:
597 	/* pickup reset address from AmigaOS ROM, reset devices and jump
598 	 * to reset address
599 	 */
600 	asm volatile ("\n"
601 		"	move.w	#0x2700,%sr\n"
602 		"	lea	0x01000000,%a0\n"
603 		"	sub.l	%a0@(-0x14),%a0\n"
604 		"	move.l	%a0@(4),%a0\n"
605 		"	subq.l	#2,%a0\n"
606 		"	jra	1f\n"
607 		/* align on a longword boundary */
608 		"	" __ALIGN_STR "\n"
609 		"1:\n"
610 		"	reset\n"
611 		"	jmp   %a0@");
612 
613 	for (;;)
614 		;
615 }
616 
617 
618     /*
619      *  Debugging
620      */
621 
622 #define SAVEKMSG_MAXMEM		128*1024
623 
624 #define SAVEKMSG_MAGIC1		0x53415645	/* 'SAVE' */
625 #define SAVEKMSG_MAGIC2		0x4B4D5347	/* 'KMSG' */
626 
627 struct savekmsg {
628 	unsigned long magic1;		/* SAVEKMSG_MAGIC1 */
629 	unsigned long magic2;		/* SAVEKMSG_MAGIC2 */
630 	unsigned long magicptr;		/* address of magic1 */
631 	unsigned long size;
632 	char data[];
633 };
634 
635 static struct savekmsg *savekmsg;
636 
637 static void amiga_mem_console_write(struct console *co, const char *s,
638 				    unsigned int count)
639 {
640 	if (savekmsg->size + count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
641 		memcpy(savekmsg->data + savekmsg->size, s, count);
642 		savekmsg->size += count;
643 	}
644 }
645 
646 static int __init amiga_savekmsg_setup(char *arg)
647 {
648 	bool registered;
649 
650 	if (!MACH_IS_AMIGA || strcmp(arg, "mem"))
651 		return 0;
652 
653 	if (amiga_chip_size < SAVEKMSG_MAXMEM) {
654 		pr_err("Not enough chipram for debugging\n");
655 		return -ENOMEM;
656 	}
657 
658 	/* Just steal the block, the chipram allocator isn't functional yet */
659 	amiga_chip_size -= SAVEKMSG_MAXMEM;
660 	savekmsg = ZTWO_VADDR(CHIP_PHYSADDR + amiga_chip_size);
661 	savekmsg->magic1 = SAVEKMSG_MAGIC1;
662 	savekmsg->magic2 = SAVEKMSG_MAGIC2;
663 	savekmsg->magicptr = ZTWO_PADDR(savekmsg);
664 	savekmsg->size = 0;
665 
666 	registered = !!amiga_console_driver.write;
667 	amiga_console_driver.write = amiga_mem_console_write;
668 	if (!registered)
669 		register_console(&amiga_console_driver);
670 	return 0;
671 }
672 
673 early_param("debug", amiga_savekmsg_setup);
674 
675 static void amiga_serial_putc(char c)
676 {
677 	amiga_custom.serdat = (unsigned char)c | 0x100;
678 	while (!(amiga_custom.serdatr & 0x2000))
679 		;
680 }
681 
682 static void amiga_serial_console_write(struct console *co, const char *s,
683 				       unsigned int count)
684 {
685 	while (count--) {
686 		if (*s == '\n')
687 			amiga_serial_putc('\r');
688 		amiga_serial_putc(*s++);
689 	}
690 }
691 
692 #if 0
693 void amiga_serial_puts(const char *s)
694 {
695 	amiga_serial_console_write(NULL, s, strlen(s));
696 }
697 
698 int amiga_serial_console_wait_key(struct console *co)
699 {
700 	int ch;
701 
702 	while (!(amiga_custom.intreqr & IF_RBF))
703 		barrier();
704 	ch = amiga_custom.serdatr & 0xff;
705 	/* clear the interrupt, so that another character can be read */
706 	amiga_custom.intreq = IF_RBF;
707 	return ch;
708 }
709 
710 void amiga_serial_gets(struct console *co, char *s, int len)
711 {
712 	int ch, cnt = 0;
713 
714 	while (1) {
715 		ch = amiga_serial_console_wait_key(co);
716 
717 		/* Check for backspace. */
718 		if (ch == 8 || ch == 127) {
719 			if (cnt == 0) {
720 				amiga_serial_putc('\007');
721 				continue;
722 			}
723 			cnt--;
724 			amiga_serial_puts("\010 \010");
725 			continue;
726 		}
727 
728 		/* Check for enter. */
729 		if (ch == 10 || ch == 13)
730 			break;
731 
732 		/* See if line is too long. */
733 		if (cnt >= len + 1) {
734 			amiga_serial_putc(7);
735 			cnt--;
736 			continue;
737 		}
738 
739 		/* Store and echo character. */
740 		s[cnt++] = ch;
741 		amiga_serial_putc(ch);
742 	}
743 	/* Print enter. */
744 	amiga_serial_puts("\r\n");
745 	s[cnt] = 0;
746 }
747 #endif
748 
749 static int __init amiga_debug_setup(char *arg)
750 {
751 	bool registered;
752 
753 	if (!MACH_IS_AMIGA || strcmp(arg, "ser"))
754 		return 0;
755 
756 	/* no initialization required (?) */
757 	registered = !!amiga_console_driver.write;
758 	amiga_console_driver.write = amiga_serial_console_write;
759 	if (!registered)
760 		register_console(&amiga_console_driver);
761 	return 0;
762 }
763 
764 early_param("debug", amiga_debug_setup);
765 
766 #ifdef CONFIG_HEARTBEAT
767 static void amiga_heartbeat(int on)
768 {
769 	if (on)
770 		ciaa.pra &= ~2;
771 	else
772 		ciaa.pra |= 2;
773 }
774 #endif
775 
776     /*
777      *  Amiga specific parts of /proc
778      */
779 
780 static void amiga_get_model(char *model)
781 {
782 	strcpy(model, amiga_model_name);
783 }
784 
785 
786 static void amiga_get_hardware_list(struct seq_file *m)
787 {
788 	if (AMIGAHW_PRESENT(CHIP_RAM))
789 		seq_printf(m, "Chip RAM:\t%ldK\n", amiga_chip_size>>10);
790 	seq_printf(m, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n",
791 			amiga_psfreq, amiga_eclock);
792 	if (AMIGAHW_PRESENT(AMI_VIDEO)) {
793 		char *type;
794 		switch (amiga_chipset) {
795 		case CS_OCS:
796 			type = "OCS";
797 			break;
798 		case CS_ECS:
799 			type = "ECS";
800 			break;
801 		case CS_AGA:
802 			type = "AGA";
803 			break;
804 		default:
805 			type = "Old or Unknown";
806 			break;
807 		}
808 		seq_printf(m, "Graphics:\t%s\n", type);
809 	}
810 
811 #define AMIGAHW_ANNOUNCE(name, str)			\
812 	if (AMIGAHW_PRESENT(name))			\
813 		seq_printf (m, "\t%s\n", str)
814 
815 	seq_puts(m, "Detected hardware:\n");
816 	AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video");
817 	AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter");
818 	AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer");
819 	AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio");
820 	AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller");
821 	AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)");
822 	AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)");
823 	AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)");
824 	AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)");
825 	AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive");
826 	AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard");
827 	AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port");
828 	AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port");
829 	AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port");
830 	AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)");
831 	AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)");
832 	AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM");
833 	AMIGAHW_ANNOUNCE(PAULA, "Paula 8364");
834 	AMIGAHW_ANNOUNCE(DENISE, "Denise 8362");
835 	AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373");
836 	AMIGAHW_ANNOUNCE(LISA, "Lisa 8375");
837 	AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371");
838 	AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370");
839 	AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372");
840 	AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372");
841 	AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374");
842 	AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374");
843 	AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
844 	AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
845 #ifdef CONFIG_ZORRO
846 	if (AMIGAHW_PRESENT(ZORRO))
847 		seq_printf(m, "\tZorro II%s AutoConfig: %d Expansion "
848 				"Device%s\n",
849 				AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
850 				zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
851 #endif /* CONFIG_ZORRO */
852 
853 #undef AMIGAHW_ANNOUNCE
854 }
855 
856 /*
857  * The Amiga keyboard driver needs key_maps, but we cannot export it in
858  * drivers/char/defkeymap.c, as it is autogenerated
859  */
860 #ifdef CONFIG_HW_CONSOLE
861 EXPORT_SYMBOL_GPL(key_maps);
862 #endif
863