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