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