1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/types.h>
28#include <linux/mm.h>
29#include <linux/console.h>
30#include <linux/init.h>
31#include <linux/delay.h>
32#include <linux/ioport.h>
33#include <linux/vt_kern.h>
34
35#include <asm/bootinfo.h>
36#include <asm/setup.h>
37#include <asm/atarihw.h>
38#include <asm/atariints.h>
39#include <asm/atari_stram.h>
40#include <asm/system.h>
41#include <asm/machdep.h>
42#include <asm/hwtest.h>
43#include <asm/io.h>
44
45u_long atari_mch_cookie;
46u_long atari_mch_type;
47struct atari_hw_present atari_hw_present;
48u_long atari_switches;
49int atari_dont_touch_floppy_select;
50int atari_rtc_year_offset;
51
52
53static void atari_reset(void);
54static void atari_get_model(char *model);
55static int atari_get_hardware_list(char *buffer);
56
57
58extern void atari_init_IRQ (void);
59extern void atari_mksound(unsigned int count, unsigned int ticks);
60#ifdef CONFIG_HEARTBEAT
61static void atari_heartbeat(int on);
62#endif
63
64
65extern void atari_sched_init(irq_handler_t);
66extern unsigned long atari_gettimeoffset (void);
67extern int atari_mste_hwclk (int, struct rtc_time *);
68extern int atari_tt_hwclk (int, struct rtc_time *);
69extern int atari_mste_set_clock_mmss (unsigned long);
70extern int atari_tt_set_clock_mmss (unsigned long);
71
72
73
74
75
76
77
78
79
80
81static int __init scc_test(volatile char *ctla)
82{
83 if (!hwreg_present(ctla))
84 return 0;
85 MFPDELAY();
86
87 *ctla = 2;
88 MFPDELAY();
89 *ctla = 0x40;
90 MFPDELAY();
91
92 *ctla = 2;
93 MFPDELAY();
94 if (*ctla != 0x40)
95 return 0;
96 MFPDELAY();
97
98 *ctla = 2;
99 MFPDELAY();
100 *ctla = 0x60;
101 MFPDELAY();
102
103 *ctla = 2;
104 MFPDELAY();
105 if (*ctla != 0x60)
106 return 0;
107
108 return 1;
109}
110
111
112
113
114
115
116int __init atari_parse_bootinfo(const struct bi_record *record)
117{
118 int unknown = 0;
119 const u_long *data = record->data;
120
121 switch (record->tag) {
122 case BI_ATARI_MCH_COOKIE:
123 atari_mch_cookie = *data;
124 break;
125 case BI_ATARI_MCH_TYPE:
126 atari_mch_type = *data;
127 break;
128 default:
129 unknown = 1;
130 break;
131 }
132 return unknown;
133}
134
135
136
137static int __init atari_switches_setup(char *str)
138{
139 char switches[strlen(str) + 1];
140 char *p;
141 int ovsc_shift;
142 char *args = switches;
143
144 if (!MACH_IS_ATARI)
145 return 0;
146
147
148 strcpy(switches, str);
149 atari_switches = 0;
150
151
152 while ((p = strsep(&args, ",")) != NULL) {
153 if (!*p)
154 continue;
155 ovsc_shift = 0;
156 if (strncmp(p, "ov_", 3) == 0) {
157 p += 3;
158 ovsc_shift = ATARI_SWITCH_OVSC_SHIFT;
159 }
160
161 if (strcmp(p, "ikbd") == 0) {
162
163 atari_switches |= ATARI_SWITCH_IKBD << ovsc_shift;
164 } else if (strcmp(p, "midi") == 0) {
165
166 atari_switches |= ATARI_SWITCH_MIDI << ovsc_shift;
167 } else if (strcmp(p, "snd6") == 0) {
168 atari_switches |= ATARI_SWITCH_SND6 << ovsc_shift;
169 } else if (strcmp(p, "snd7") == 0) {
170 atari_switches |= ATARI_SWITCH_SND7 << ovsc_shift;
171 }
172 }
173 return 0;
174}
175
176early_param("switches", atari_switches_setup);
177
178
179
180
181
182
183void __init config_atari(void)
184{
185 unsigned short tos_version;
186
187 memset(&atari_hw_present, 0, sizeof(atari_hw_present));
188
189
190 ioport_resource.end = 0xFFFFFFFF;
191
192 mach_sched_init = atari_sched_init;
193 mach_init_IRQ = atari_init_IRQ;
194 mach_get_model = atari_get_model;
195 mach_get_hardware_list = atari_get_hardware_list;
196 mach_gettimeoffset = atari_gettimeoffset;
197 mach_reset = atari_reset;
198 mach_max_dma_address = 0xffffff;
199#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
200 mach_beep = atari_mksound;
201#endif
202#ifdef CONFIG_HEARTBEAT
203 mach_heartbeat = atari_heartbeat;
204#endif
205
206
207 if (atari_switches & ATARI_SWITCH_IKBD)
208 acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID;
209 if (atari_switches & ATARI_SWITCH_MIDI)
210 acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
211 if (atari_switches & (ATARI_SWITCH_SND6|ATARI_SWITCH_SND7)) {
212 sound_ym.rd_data_reg_sel = 14;
213 sound_ym.wd_data = sound_ym.rd_data_reg_sel |
214 ((atari_switches&ATARI_SWITCH_SND6) ? 0x40 : 0) |
215 ((atari_switches&ATARI_SWITCH_SND7) ? 0x80 : 0);
216 }
217
218
219
220
221
222 printk("Atari hardware found: ");
223 if (MACH_IS_MEDUSA || MACH_IS_HADES) {
224
225
226 } else if (hwreg_present(f030_xreg)) {
227 ATARIHW_SET(VIDEL_SHIFTER);
228 printk("VIDEL ");
229
230
231
232
233
234 ATARIHW_SET(ST_SCSI);
235 printk("STDMA-SCSI ");
236 } else if (hwreg_present(tt_palette)) {
237 ATARIHW_SET(TT_SHIFTER);
238 printk("TT_SHIFTER ");
239 } else if (hwreg_present(&shifter.bas_hi)) {
240 if (hwreg_present(&shifter.bas_lo) &&
241 (shifter.bas_lo = 0x0aau, shifter.bas_lo == 0x0aau)) {
242 ATARIHW_SET(EXTD_SHIFTER);
243 printk("EXTD_SHIFTER ");
244 } else {
245 ATARIHW_SET(STND_SHIFTER);
246 printk("STND_SHIFTER ");
247 }
248 }
249 if (hwreg_present(&mfp.par_dt_reg)) {
250 ATARIHW_SET(ST_MFP);
251 printk("ST_MFP ");
252 }
253 if (hwreg_present(&tt_mfp.par_dt_reg)) {
254 ATARIHW_SET(TT_MFP);
255 printk("TT_MFP ");
256 }
257 if (hwreg_present(&tt_scsi_dma.dma_addr_hi)) {
258 ATARIHW_SET(SCSI_DMA);
259 printk("TT_SCSI_DMA ");
260 }
261 if (!MACH_IS_HADES && hwreg_present(&st_dma.dma_hi)) {
262 ATARIHW_SET(STND_DMA);
263 printk("STND_DMA ");
264 }
265
266
267
268
269 if (MACH_IS_MEDUSA ||
270 (hwreg_present(&st_dma.dma_vhi) &&
271 (st_dma.dma_vhi = 0x55) && (st_dma.dma_hi = 0xaa) &&
272 st_dma.dma_vhi == 0x55 && st_dma.dma_hi == 0xaa &&
273 (st_dma.dma_vhi = 0xaa) && (st_dma.dma_hi = 0x55) &&
274 st_dma.dma_vhi == 0xaa && st_dma.dma_hi == 0x55)) {
275 ATARIHW_SET(EXTD_DMA);
276 printk("EXTD_DMA ");
277 }
278 if (hwreg_present(&tt_scsi.scsi_data)) {
279 ATARIHW_SET(TT_SCSI);
280 printk("TT_SCSI ");
281 }
282 if (hwreg_present(&sound_ym.rd_data_reg_sel)) {
283 ATARIHW_SET(YM_2149);
284 printk("YM2149 ");
285 }
286 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
287 hwreg_present(&tt_dmasnd.ctrl)) {
288 ATARIHW_SET(PCM_8BIT);
289 printk("PCM ");
290 }
291 if (!MACH_IS_HADES && hwreg_present(&falcon_codec.unused5)) {
292 ATARIHW_SET(CODEC);
293 printk("CODEC ");
294 }
295 if (hwreg_present(&dsp56k_host_interface.icr)) {
296 ATARIHW_SET(DSP56K);
297 printk("DSP56K ");
298 }
299 if (hwreg_present(&tt_scc_dma.dma_ctrl) &&
300#if 0
301
302 (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) &&
303 (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0)
304#else
305 !MACH_IS_MEDUSA && !MACH_IS_HADES
306#endif
307 ) {
308 ATARIHW_SET(SCC_DMA);
309 printk("SCC_DMA ");
310 }
311 if (scc_test(&scc.cha_a_ctrl)) {
312 ATARIHW_SET(SCC);
313 printk("SCC ");
314 }
315 if (scc_test(&st_escc.cha_b_ctrl)) {
316 ATARIHW_SET(ST_ESCC);
317 printk("ST_ESCC ");
318 }
319 if (MACH_IS_HADES) {
320 ATARIHW_SET(VME);
321 printk("VME ");
322 } else if (hwreg_present(&tt_scu.sys_mask)) {
323 ATARIHW_SET(SCU);
324
325 ATARIHW_SET(VME);
326 printk("VME SCU ");
327 }
328 if (hwreg_present((void *)(0xffff9210))) {
329 ATARIHW_SET(ANALOG_JOY);
330 printk("ANALOG_JOY ");
331 }
332 if (!MACH_IS_HADES && hwreg_present(blitter.halftone)) {
333 ATARIHW_SET(BLITTER);
334 printk("BLITTER ");
335 }
336 if (hwreg_present((void *)0xfff00039)) {
337 ATARIHW_SET(IDE);
338 printk("IDE ");
339 }
340#if 1
341 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
342 hwreg_present(&tt_microwire.data) &&
343 hwreg_present(&tt_microwire.mask) &&
344 (tt_microwire.mask = 0x7ff,
345 udelay(1),
346 tt_microwire.data = MW_LM1992_PSG_HIGH | MW_LM1992_ADDR,
347 udelay(1),
348 tt_microwire.data != 0)) {
349 ATARIHW_SET(MICROWIRE);
350 while (tt_microwire.mask != 0x7ff)
351 ;
352 printk("MICROWIRE ");
353 }
354#endif
355 if (hwreg_present(&tt_rtc.regsel)) {
356 ATARIHW_SET(TT_CLK);
357 printk("TT_CLK ");
358 mach_hwclk = atari_tt_hwclk;
359 mach_set_clock_mmss = atari_tt_set_clock_mmss;
360 }
361 if (!MACH_IS_HADES && hwreg_present(&mste_rtc.sec_ones)) {
362 ATARIHW_SET(MSTE_CLK);
363 printk("MSTE_CLK ");
364 mach_hwclk = atari_mste_hwclk;
365 mach_set_clock_mmss = atari_mste_set_clock_mmss;
366 }
367 if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
368 hwreg_present(&dma_wd.fdc_speed) &&
369 hwreg_write(&dma_wd.fdc_speed, 0)) {
370 ATARIHW_SET(FDCSPEED);
371 printk("FDC_SPEED ");
372 }
373 if (!MACH_IS_HADES && !ATARIHW_PRESENT(ST_SCSI)) {
374 ATARIHW_SET(ACSI);
375 printk("ACSI ");
376 }
377 printk("\n");
378
379 if (CPU_IS_040_OR_060)
380
381
382
383
384 asm volatile ("\n"
385 " moveq #0,%%d0\n"
386 " .chip 68040\n"
387 " movec %%d0,%%itt0\n"
388 " movec %%d0,%%dtt0\n"
389 " .chip 68k"
390 :
391 :
392 : "d0");
393
394
395 atari_stram_init();
396
397
398
399
400
401
402
403
404
405
406
407
408 if (CPU_IS_020_OR_030) {
409 unsigned long tt1_val;
410 tt1_val = 0xfe008543;
411
412
413 asm volatile ("\n"
414 " .chip 68030\n"
415 " pmove %0@,%/tt1\n"
416 " .chip 68k"
417 : : "a" (&tt1_val));
418 } else {
419 asm volatile ("\n"
420 " .chip 68040\n"
421 " movec %0,%%itt1\n"
422 " movec %0,%%dtt1\n"
423 " .chip 68k"
424 :
425 : "d" (0xfe00a040));
426
427
428
429 }
430
431
432
433
434
435
436
437
438
439
440
441 tos_version = (MACH_IS_MEDUSA || MACH_IS_HADES) ?
442 0xfff : *(unsigned short *)0xff000002;
443 atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68;
444}
445
446#ifdef CONFIG_HEARTBEAT
447static void atari_heartbeat(int on)
448{
449 unsigned char tmp;
450 unsigned long flags;
451
452 if (atari_dont_touch_floppy_select)
453 return;
454
455 local_irq_save(flags);
456 sound_ym.rd_data_reg_sel = 14;
457 tmp = sound_ym.rd_data_reg_sel;
458 sound_ym.wd_data = on ? (tmp & ~0x02) : (tmp | 0x02);
459 local_irq_restore(flags);
460}
461#endif
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494static void atari_reset(void)
495{
496 long tc_val = 0;
497 long reset_addr;
498
499
500
501
502
503 reset_addr = MACH_IS_HADES ? 0x7fe00030 :
504 MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 :
505 *(unsigned long *) 0xff000004;
506
507
508 if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
509 acia.key_ctrl = ACIA_RESET;
510 if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
511 acia.mid_ctrl = ACIA_RESET;
512
513
514
515
516
517 local_irq_disable();
518 asm volatile ("movec %0,%%vbr"
519 : : "d" (0));
520
521 if (CPU_IS_040_OR_060) {
522 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
523 if (CPU_IS_060) {
524
525 asm volatile ("\n"
526 " .chip 68060\n"
527 " movec %0,%%pcr\n"
528 " .chip 68k"
529 : : "d" (0));
530 }
531
532 asm volatile ("\n"
533 " move.l %0,%%d0\n"
534 " and.l #0xff000000,%%d0\n"
535 " or.w #0xe020,%%d0\n"
536 " .chip 68040\n"
537 " movec %%d0,%%itt0\n"
538 " movec %%d0,%%dtt0\n"
539 " .chip 68k\n"
540 " jmp %0@"
541 : : "a" (jmp_addr040)
542 : "d0");
543 jmp_addr_label040:
544 asm volatile ("\n"
545 " moveq #0,%%d0\n"
546 " nop\n"
547 " .chip 68040\n"
548 " cinva %%bc\n"
549 " nop\n"
550 " pflusha\n"
551 " nop\n"
552 " movec %%d0,%%tc\n"
553 " nop\n"
554
555
556
557
558 " move.l #0xffc000,%%d0\n"
559 " movec %%d0,%%itt0\n"
560 " movec %%d0,%%itt1\n"
561 " or.w #0x40,%/d0\n"
562 " movec %%d0,%%dtt0\n"
563 " movec %%d0,%%dtt1\n"
564 " .chip 68k\n"
565 " jmp %0@"
566 :
567 : "a" (reset_addr)
568 : "d0");
569 } else
570 asm volatile ("\n"
571 " pmove %0@,%%tc\n"
572 " jmp %1@"
573 :
574 : "a" (&tc_val), "a" (reset_addr));
575}
576
577
578static void atari_get_model(char *model)
579{
580 strcpy(model, "Atari ");
581 switch (atari_mch_cookie >> 16) {
582 case ATARI_MCH_ST:
583 if (ATARIHW_PRESENT(MSTE_CLK))
584 strcat(model, "Mega ST");
585 else
586 strcat(model, "ST");
587 break;
588 case ATARI_MCH_STE:
589 if (MACH_IS_MSTE)
590 strcat(model, "Mega STE");
591 else
592 strcat(model, "STE");
593 break;
594 case ATARI_MCH_TT:
595 if (MACH_IS_MEDUSA)
596
597 strcat(model, "Medusa");
598 else if (MACH_IS_HADES)
599 strcat(model, "Hades");
600 else
601 strcat(model, "TT");
602 break;
603 case ATARI_MCH_FALCON:
604 strcat(model, "Falcon");
605 if (MACH_IS_AB40)
606 strcat(model, " (with Afterburner040)");
607 break;
608 default:
609 sprintf(model + strlen(model), "(unknown mach cookie 0x%lx)",
610 atari_mch_cookie);
611 break;
612 }
613}
614
615
616static int atari_get_hardware_list(char *buffer)
617{
618 int len = 0, i;
619
620 for (i = 0; i < m68k_num_memory; i++)
621 len += sprintf(buffer+len, "\t%3ld MB at 0x%08lx (%s)\n",
622 m68k_memory[i].size >> 20, m68k_memory[i].addr,
623 (m68k_memory[i].addr & 0xff000000 ?
624 "alternate RAM" : "ST-RAM"));
625
626#define ATARIHW_ANNOUNCE(name, str) \
627 if (ATARIHW_PRESENT(name)) \
628 len += sprintf(buffer + len, "\t%s\n", str)
629
630 len += sprintf(buffer + len, "Detected hardware:\n");
631 ATARIHW_ANNOUNCE(STND_SHIFTER, "ST Shifter");
632 ATARIHW_ANNOUNCE(EXTD_SHIFTER, "STe Shifter");
633 ATARIHW_ANNOUNCE(TT_SHIFTER, "TT Shifter");
634 ATARIHW_ANNOUNCE(VIDEL_SHIFTER, "Falcon Shifter");
635 ATARIHW_ANNOUNCE(YM_2149, "Programmable Sound Generator");
636 ATARIHW_ANNOUNCE(PCM_8BIT, "PCM 8 Bit Sound");
637 ATARIHW_ANNOUNCE(CODEC, "CODEC Sound");
638 ATARIHW_ANNOUNCE(TT_SCSI, "SCSI Controller NCR5380 (TT style)");
639 ATARIHW_ANNOUNCE(ST_SCSI, "SCSI Controller NCR5380 (Falcon style)");
640 ATARIHW_ANNOUNCE(ACSI, "ACSI Interface");
641 ATARIHW_ANNOUNCE(IDE, "IDE Interface");
642 ATARIHW_ANNOUNCE(FDCSPEED, "8/16 Mhz Switch for FDC");
643 ATARIHW_ANNOUNCE(ST_MFP, "Multi Function Peripheral MFP 68901");
644 ATARIHW_ANNOUNCE(TT_MFP, "Second Multi Function Peripheral MFP 68901");
645 ATARIHW_ANNOUNCE(SCC, "Serial Communications Controller SCC 8530");
646 ATARIHW_ANNOUNCE(ST_ESCC, "Extended Serial Communications Controller SCC 85230");
647 ATARIHW_ANNOUNCE(ANALOG_JOY, "Paddle Interface");
648 ATARIHW_ANNOUNCE(MICROWIRE, "MICROWIRE(tm) Interface");
649 ATARIHW_ANNOUNCE(STND_DMA, "DMA Controller (24 bit)");
650 ATARIHW_ANNOUNCE(EXTD_DMA, "DMA Controller (32 bit)");
651 ATARIHW_ANNOUNCE(SCSI_DMA, "DMA Controller for NCR5380");
652 ATARIHW_ANNOUNCE(SCC_DMA, "DMA Controller for SCC");
653 ATARIHW_ANNOUNCE(TT_CLK, "Clock Chip MC146818A");
654 ATARIHW_ANNOUNCE(MSTE_CLK, "Clock Chip RP5C15");
655 ATARIHW_ANNOUNCE(SCU, "System Control Unit");
656 ATARIHW_ANNOUNCE(BLITTER, "Blitter");
657 ATARIHW_ANNOUNCE(VME, "VME Bus");
658 ATARIHW_ANNOUNCE(DSP56K, "DSP56001 processor");
659
660 return len;
661}
662