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