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