1 /*
2  *  linux/arch/m68k/atari/config.c
3  *
4  *  Copyright (C) 1994 Bjoern Brauel
5  *
6  *  5/2/94 Roman Hodek:
7  *    Added setting of time_adj to get a better clock.
8  *
9  *  5/14/94 Roman Hodek:
10  *    gettod() for TT
11  *
12  *  5/15/94 Roman Hodek:
13  *    hard_reset_now() for Atari (and others?)
14  *
15  *  94/12/30 Andreas Schwab:
16  *    atari_sched_init fixed to get precise clock.
17  *
18  * This file is subject to the terms and conditions of the GNU General Public
19  * License.  See the file COPYING in the main directory of this archive
20  * for more details.
21  */
22 
23 /*
24  * Miscellaneous atari stuff
25  */
26 
27 #include <linux/types.h>
28 #include <linux/mm.h>
29 #include <linux/seq_file.h>
30 #include <linux/console.h>
31 #include <linux/init.h>
32 #include <linux/delay.h>
33 #include <linux/ioport.h>
34 #include <linux/platform_device.h>
35 #include <linux/usb/isp116x.h>
36 #include <linux/vt_kern.h>
37 #include <linux/module.h>
38 
39 #include <asm/bootinfo.h>
40 #include <asm/bootinfo-atari.h>
41 #include <asm/byteorder.h>
42 #include <asm/setup.h>
43 #include <asm/atarihw.h>
44 #include <asm/atariints.h>
45 #include <asm/atari_stram.h>
46 #include <asm/machdep.h>
47 #include <asm/hwtest.h>
48 #include <asm/io.h>
49 
50 u_long atari_mch_cookie;
51 EXPORT_SYMBOL(atari_mch_cookie);
52 
53 u_long atari_mch_type;
54 EXPORT_SYMBOL(atari_mch_type);
55 
56 struct atari_hw_present atari_hw_present;
57 EXPORT_SYMBOL(atari_hw_present);
58 
59 u_long atari_switches;
60 EXPORT_SYMBOL(atari_switches);
61 
62 int atari_dont_touch_floppy_select;
63 EXPORT_SYMBOL(atari_dont_touch_floppy_select);
64 
65 int atari_rtc_year_offset;
66 
67 /* local function prototypes */
68 static void atari_reset(void);
69 static void atari_get_model(char *model);
70 static void atari_get_hardware_list(struct seq_file *m);
71 
72 /* atari specific irq functions */
73 extern void atari_init_IRQ (void);
74 extern void atari_mksound(unsigned int count, unsigned int ticks);
75 #ifdef CONFIG_HEARTBEAT
76 static void atari_heartbeat(int on);
77 #endif
78 
79 /* atari specific timer functions (in time.c) */
80 extern void atari_sched_init(void);
81 extern int atari_mste_hwclk (int, struct rtc_time *);
82 extern int atari_tt_hwclk (int, struct rtc_time *);
83 
84 /* ++roman: This is a more elaborate test for an SCC chip, since the plain
85  * Medusa board generates DTACK at the SCC's standard addresses, but a SCC
86  * board in the Medusa is possible. Also, the addresses where the ST_ESCC
87  * resides generate DTACK without the chip, too.
88  * The method is to write values into the interrupt vector register, that
89  * should be readable without trouble (from channel A!).
90  */
91 
scc_test(volatile char * ctla)92 static int __init scc_test(volatile char *ctla)
93 {
94 	if (!hwreg_present(ctla))
95 		return 0;
96 	MFPDELAY();
97 
98 	*ctla = 2;
99 	MFPDELAY();
100 	*ctla = 0x40;
101 	MFPDELAY();
102 
103 	*ctla = 2;
104 	MFPDELAY();
105 	if (*ctla != 0x40)
106 		return 0;
107 	MFPDELAY();
108 
109 	*ctla = 2;
110 	MFPDELAY();
111 	*ctla = 0x60;
112 	MFPDELAY();
113 
114 	*ctla = 2;
115 	MFPDELAY();
116 	if (*ctla != 0x60)
117 		return 0;
118 
119 	return 1;
120 }
121 
122 
123     /*
124      *  Parse an Atari-specific record in the bootinfo
125      */
126 
atari_parse_bootinfo(const struct bi_record * record)127 int __init atari_parse_bootinfo(const struct bi_record *record)
128 {
129 	int unknown = 0;
130 	const void *data = record->data;
131 
132 	switch (be16_to_cpu(record->tag)) {
133 	case BI_ATARI_MCH_COOKIE:
134 		atari_mch_cookie = be32_to_cpup(data);
135 		break;
136 	case BI_ATARI_MCH_TYPE:
137 		atari_mch_type = be32_to_cpup(data);
138 		break;
139 	default:
140 		unknown = 1;
141 		break;
142 	}
143 	return unknown;
144 }
145 
146 
147 /* Parse the Atari-specific switches= option. */
atari_switches_setup(char * str)148 static int __init atari_switches_setup(char *str)
149 {
150 	char switches[COMMAND_LINE_SIZE];
151 	char *p;
152 	int ovsc_shift;
153 	char *args = switches;
154 
155 	if (!MACH_IS_ATARI)
156 		return 0;
157 
158 	/* copy string to local array, strsep works destructively... */
159 	strcpy(switches, str);
160 	atari_switches = 0;
161 
162 	/* parse the options */
163 	while ((p = strsep(&args, ",")) != NULL) {
164 		if (!*p)
165 			continue;
166 		ovsc_shift = 0;
167 		if (strncmp(p, "ov_", 3) == 0) {
168 			p += 3;
169 			ovsc_shift = ATARI_SWITCH_OVSC_SHIFT;
170 		}
171 
172 		if (strcmp(p, "ikbd") == 0) {
173 			/* RTS line of IKBD ACIA */
174 			atari_switches |= ATARI_SWITCH_IKBD << ovsc_shift;
175 		} else if (strcmp(p, "midi") == 0) {
176 			/* RTS line of MIDI ACIA */
177 			atari_switches |= ATARI_SWITCH_MIDI << ovsc_shift;
178 		} else if (strcmp(p, "snd6") == 0) {
179 			atari_switches |= ATARI_SWITCH_SND6 << ovsc_shift;
180 		} else if (strcmp(p, "snd7") == 0) {
181 			atari_switches |= ATARI_SWITCH_SND7 << ovsc_shift;
182 		}
183 	}
184 	return 0;
185 }
186 
187 early_param("switches", atari_switches_setup);
188 
189 
190     /*
191      *  Setup the Atari configuration info
192      */
193 
config_atari(void)194 void __init config_atari(void)
195 {
196 	unsigned short tos_version;
197 
198 	memset(&atari_hw_present, 0, sizeof(atari_hw_present));
199 
200 	/* Change size of I/O space from 64KB to 4GB. */
201 	ioport_resource.end  = 0xFFFFFFFF;
202 
203 	mach_sched_init      = atari_sched_init;
204 	mach_init_IRQ        = atari_init_IRQ;
205 	mach_get_model	 = atari_get_model;
206 	mach_get_hardware_list = atari_get_hardware_list;
207 	mach_reset           = atari_reset;
208 #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
209 	mach_beep          = atari_mksound;
210 #endif
211 #ifdef CONFIG_HEARTBEAT
212 	mach_heartbeat = atari_heartbeat;
213 #endif
214 
215 	/* Set switches as requested by the user */
216 	if (atari_switches & ATARI_SWITCH_IKBD)
217 		acia.key_ctrl = ACIA_DIV64 | ACIA_D8N1S | ACIA_RHTID;
218 	if (atari_switches & ATARI_SWITCH_MIDI)
219 		acia.mid_ctrl = ACIA_DIV16 | ACIA_D8N1S | ACIA_RHTID;
220 	if (atari_switches & (ATARI_SWITCH_SND6|ATARI_SWITCH_SND7)) {
221 		sound_ym.rd_data_reg_sel = 14;
222 		sound_ym.wd_data = sound_ym.rd_data_reg_sel |
223 				   ((atari_switches&ATARI_SWITCH_SND6) ? 0x40 : 0) |
224 				   ((atari_switches&ATARI_SWITCH_SND7) ? 0x80 : 0);
225 	}
226 
227 	/* ++bjoern:
228 	 * Determine hardware present
229 	 */
230 
231 	pr_info("Atari hardware found:");
232 	if (MACH_IS_MEDUSA) {
233 		/* There's no Atari video hardware on the Medusa, but all the
234 		 * addresses below generate a DTACK so no bus error occurs! */
235 	} else if (hwreg_present(f030_xreg)) {
236 		ATARIHW_SET(VIDEL_SHIFTER);
237 		pr_cont(" VIDEL");
238 		/* This is a temporary hack: If there is Falcon video
239 		 * hardware, we assume that the ST-DMA serves SCSI instead of
240 		 * ACSI. In the future, there should be a better method for
241 		 * this...
242 		 */
243 		ATARIHW_SET(ST_SCSI);
244 		pr_cont(" STDMA-SCSI");
245 	} else if (hwreg_present(tt_palette)) {
246 		ATARIHW_SET(TT_SHIFTER);
247 		pr_cont(" TT_SHIFTER");
248 	} else if (hwreg_present(&shifter_st.bas_hi)) {
249 		if (hwreg_present(&shifter_st.bas_lo) &&
250 		    (shifter_st.bas_lo = 0x0aau, shifter_st.bas_lo == 0x0aau)) {
251 			ATARIHW_SET(EXTD_SHIFTER);
252 			pr_cont(" EXTD_SHIFTER");
253 		} else {
254 			ATARIHW_SET(STND_SHIFTER);
255 			pr_cont(" STND_SHIFTER");
256 		}
257 	}
258 	if (hwreg_present(&st_mfp.par_dt_reg)) {
259 		ATARIHW_SET(ST_MFP);
260 		pr_cont(" ST_MFP");
261 	}
262 	if (hwreg_present(&tt_mfp.par_dt_reg)) {
263 		ATARIHW_SET(TT_MFP);
264 		pr_cont(" TT_MFP");
265 	}
266 	if (hwreg_present(&tt_scsi_dma.dma_addr_hi)) {
267 		ATARIHW_SET(SCSI_DMA);
268 		pr_cont(" TT_SCSI_DMA");
269 	}
270 	/*
271 	 * The ST-DMA address registers aren't readable
272 	 * on all Medusas, so the test below may fail
273 	 */
274 	if (MACH_IS_MEDUSA ||
275 	    (hwreg_present(&st_dma.dma_vhi) &&
276 	     (st_dma.dma_vhi = 0x55) && (st_dma.dma_hi = 0xaa) &&
277 	     st_dma.dma_vhi == 0x55 && st_dma.dma_hi == 0xaa &&
278 	     (st_dma.dma_vhi = 0xaa) && (st_dma.dma_hi = 0x55) &&
279 	     st_dma.dma_vhi == 0xaa && st_dma.dma_hi == 0x55)) {
280 		ATARIHW_SET(EXTD_DMA);
281 		pr_cont(" EXTD_DMA");
282 	}
283 	if (hwreg_present(&tt_scsi.scsi_data)) {
284 		ATARIHW_SET(TT_SCSI);
285 		pr_cont(" TT_SCSI");
286 	}
287 	if (hwreg_present(&sound_ym.rd_data_reg_sel)) {
288 		ATARIHW_SET(YM_2149);
289 		pr_cont(" YM2149");
290 	}
291 	if (!MACH_IS_MEDUSA && hwreg_present(&tt_dmasnd.ctrl)) {
292 		ATARIHW_SET(PCM_8BIT);
293 		pr_cont(" PCM");
294 	}
295 	if (hwreg_present(&falcon_codec.unused5)) {
296 		ATARIHW_SET(CODEC);
297 		pr_cont(" CODEC");
298 	}
299 	if (hwreg_present(&dsp56k_host_interface.icr)) {
300 		ATARIHW_SET(DSP56K);
301 		pr_cont(" DSP56K");
302 	}
303 	if (hwreg_present(&tt_scc_dma.dma_ctrl) &&
304 #if 0
305 	    /* This test sucks! Who knows some better? */
306 	    (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) &&
307 	    (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0)
308 #else
309 	    !MACH_IS_MEDUSA
310 #endif
311 	    ) {
312 		ATARIHW_SET(SCC_DMA);
313 		pr_cont(" SCC_DMA");
314 	}
315 	if (scc_test(&atari_scc.cha_a_ctrl)) {
316 		ATARIHW_SET(SCC);
317 		pr_cont(" SCC");
318 	}
319 	if (scc_test(&st_escc.cha_b_ctrl)) {
320 		ATARIHW_SET(ST_ESCC);
321 		pr_cont(" ST_ESCC");
322 	}
323 	if (hwreg_present(&tt_scu.sys_mask)) {
324 		ATARIHW_SET(SCU);
325 		/* Assume a VME bus if there's a SCU */
326 		ATARIHW_SET(VME);
327 		pr_cont(" VME SCU");
328 	}
329 	if (hwreg_present((void *)(0xffff9210))) {
330 		ATARIHW_SET(ANALOG_JOY);
331 		pr_cont(" ANALOG_JOY");
332 	}
333 	if (hwreg_present(blitter.halftone)) {
334 		ATARIHW_SET(BLITTER);
335 		pr_cont(" BLITTER");
336 	}
337 	if (hwreg_present((void *)0xfff00039)) {
338 		ATARIHW_SET(IDE);
339 		pr_cont(" IDE");
340 	}
341 #if 1 /* This maybe wrong */
342 	if (!MACH_IS_MEDUSA && 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 		pr_cont(" MICROWIRE");
353 	}
354 #endif
355 	if (hwreg_present(&tt_rtc.regsel)) {
356 		ATARIHW_SET(TT_CLK);
357 		pr_cont(" TT_CLK");
358 		mach_hwclk = atari_tt_hwclk;
359 	}
360 	if (hwreg_present(&mste_rtc.sec_ones)) {
361 		ATARIHW_SET(MSTE_CLK);
362 		pr_cont(" MSTE_CLK");
363 		mach_hwclk = atari_mste_hwclk;
364 	}
365 	if (!MACH_IS_MEDUSA && hwreg_present(&dma_wd.fdc_speed) &&
366 	    hwreg_write(&dma_wd.fdc_speed, 0)) {
367 		ATARIHW_SET(FDCSPEED);
368 		pr_cont(" FDC_SPEED");
369 	}
370 	if (!ATARIHW_PRESENT(ST_SCSI)) {
371 		ATARIHW_SET(ACSI);
372 		pr_cont(" ACSI");
373 	}
374 	pr_cont("\n");
375 
376 	if (CPU_IS_040_OR_060)
377 		/* Now it seems to be safe to turn of the tt0 transparent
378 		 * translation (the one that must not be turned off in
379 		 * head.S...)
380 		 */
381 		asm volatile ("\n"
382 			"	moveq	#0,%%d0\n"
383 			"	.chip	68040\n"
384 			"	movec	%%d0,%%itt0\n"
385 			"	movec	%%d0,%%dtt0\n"
386 			"	.chip	68k"
387 			: /* no outputs */
388 			: /* no inputs */
389 			: "d0");
390 
391 	/* allocator for memory that must reside in st-ram */
392 	atari_stram_init();
393 
394 	/* Set up a mapping for the VMEbus address region:
395 	 *
396 	 * VME is either at phys. 0xfexxxxxx (TT) or 0xa00000..0xdfffff
397 	 * (MegaSTE) In both cases, the whole 16 MB chunk is mapped at
398 	 * 0xfe000000 virt., because this can be done with a single
399 	 * transparent translation. On the 68040, lots of often unused
400 	 * page tables would be needed otherwise. On a MegaSTE or similar,
401 	 * the highest byte is stripped off by hardware due to the 24 bit
402 	 * design of the bus.
403 	 */
404 
405 	if (CPU_IS_020_OR_030) {
406 		unsigned long tt1_val;
407 		tt1_val = 0xfe008543;	/* Translate 0xfexxxxxx, enable, cache
408 					 * inhibit, read and write, FDC mask = 3,
409 					 * FDC val = 4 -> Supervisor only */
410 		asm volatile ("\n"
411 			"	.chip	68030\n"
412 			"	pmove	%0,%/tt1\n"
413 			"	.chip	68k"
414 			: : "m" (tt1_val));
415 	} else {
416 	        asm volatile ("\n"
417 			"	.chip	68040\n"
418 			"	movec	%0,%%itt1\n"
419 			"	movec	%0,%%dtt1\n"
420 			"	.chip	68k"
421 			:
422 			: "d" (0xfe00a040));	/* Translate 0xfexxxxxx, enable,
423 						 * supervisor only, non-cacheable/
424 						 * serialized, writable */
425 
426 	}
427 
428 	/* Fetch tos version at Physical 2 */
429 	/*
430 	 * We my not be able to access this address if the kernel is
431 	 * loaded to st ram, since the first page is unmapped.  On the
432 	 * Medusa this is always the case and there is nothing we can do
433 	 * about this, so we just assume the smaller offset.  For the TT
434 	 * we use the fact that in head.S we have set up a mapping
435 	 * 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible
436 	 * in the last 16MB of the address space.
437 	 */
438 	tos_version = (MACH_IS_MEDUSA) ?
439 			0xfff : *(unsigned short *)0xff000002;
440 	atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68;
441 }
442 
443 #ifdef CONFIG_HEARTBEAT
atari_heartbeat(int on)444 static void atari_heartbeat(int on)
445 {
446 	unsigned char tmp;
447 	unsigned long flags;
448 
449 	if (atari_dont_touch_floppy_select)
450 		return;
451 
452 	local_irq_save(flags);
453 	sound_ym.rd_data_reg_sel = 14;	/* Select PSG Port A */
454 	tmp = sound_ym.rd_data_reg_sel;
455 	sound_ym.wd_data = on ? (tmp & ~0x02) : (tmp | 0x02);
456 	local_irq_restore(flags);
457 }
458 #endif
459 
460 /* ++roman:
461  *
462  * This function does a reset on machines that lack the ability to
463  * assert the processor's _RESET signal somehow via hardware. It is
464  * based on the fact that you can find the initial SP and PC values
465  * after a reset at physical addresses 0 and 4. This works pretty well
466  * for Atari machines, since the lowest 8 bytes of physical memory are
467  * really ROM (mapped by hardware). For other 680x0 machines: don't
468  * know if it works...
469  *
470  * To get the values at addresses 0 and 4, the MMU better is turned
471  * off first. After that, we have to jump into physical address space
472  * (the PC before the pmove statement points to the virtual address of
473  * the code). Getting that physical address is not hard, but the code
474  * becomes a bit complex since I've tried to ensure that the jump
475  * statement after the pmove is in the cache already (otherwise the
476  * processor can't fetch it!). For that, the code first jumps to the
477  * jump statement with the (virtual) address of the pmove section in
478  * an address register . The jump statement is surely in the cache
479  * now. After that, that physical address of the reset code is loaded
480  * into the same address register, pmove is done and the same jump
481  * statements goes to the reset code. Since there are not many
482  * statements between the two jumps, I hope it stays in the cache.
483  *
484  * The C code makes heavy use of the GCC features that you can get the
485  * address of a C label. No hope to compile this with another compiler
486  * than GCC!
487  */
488 
489 /* ++andreas: no need for complicated code, just depend on prefetch */
490 
atari_reset(void)491 static void atari_reset(void)
492 {
493 	long tc_val = 0;
494 	long reset_addr;
495 
496 	/*
497 	 * On the Medusa, phys. 0x4 may contain garbage because it's no
498 	 * ROM.  See above for explanation why we cannot use PTOV(4).
499 	 */
500 	reset_addr = MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 :
501 		     *(unsigned long *) 0xff000004;
502 
503 	/* reset ACIA for switch off OverScan, if it's active */
504 	if (atari_switches & ATARI_SWITCH_OVSC_IKBD)
505 		acia.key_ctrl = ACIA_RESET;
506 	if (atari_switches & ATARI_SWITCH_OVSC_MIDI)
507 		acia.mid_ctrl = ACIA_RESET;
508 
509 	/* processor independent: turn off interrupts and reset the VBR;
510 	 * the caches must be left enabled, else prefetching the final jump
511 	 * instruction doesn't work.
512 	 */
513 	local_irq_disable();
514 	asm volatile ("movec	%0,%%vbr"
515 			: : "d" (0));
516 
517 	if (CPU_IS_040_OR_060) {
518 		unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
519 		if (CPU_IS_060) {
520 			/* 68060: clear PCR to turn off superscalar operation */
521 			asm volatile ("\n"
522 				"	.chip 68060\n"
523 				"	movec %0,%%pcr\n"
524 				"	.chip 68k"
525 				: : "d" (0));
526 		}
527 
528 		asm volatile ("\n"
529 			"	move.l	%0,%%d0\n"
530 			"	and.l	#0xff000000,%%d0\n"
531 			"	or.w	#0xe020,%%d0\n"   /* map 16 MB, enable, cacheable */
532 			"	.chip	68040\n"
533 			"	movec	%%d0,%%itt0\n"
534 			"	movec	%%d0,%%dtt0\n"
535 			"	.chip	68k\n"
536 			"	jmp	%0@"
537 			: : "a" (jmp_addr040)
538 			: "d0");
539 	jmp_addr_label040:
540 		asm volatile ("\n"
541 			"	moveq	#0,%%d0\n"
542 			"	nop\n"
543 			"	.chip	68040\n"
544 			"	cinva	%%bc\n"
545 			"	nop\n"
546 			"	pflusha\n"
547 			"	nop\n"
548 			"	movec	%%d0,%%tc\n"
549 			"	nop\n"
550 			/* the following setup of transparent translations is needed on the
551 			 * Afterburner040 to successfully reboot. Other machines shouldn't
552 			 * care about a different tt regs setup, they also didn't care in
553 			 * the past that the regs weren't turned off. */
554 			"	move.l	#0xffc000,%%d0\n" /* whole insn space cacheable */
555 			"	movec	%%d0,%%itt0\n"
556 			"	movec	%%d0,%%itt1\n"
557 			"	or.w	#0x40,%/d0\n" /* whole data space non-cacheable/ser. */
558 			"	movec	%%d0,%%dtt0\n"
559 			"	movec	%%d0,%%dtt1\n"
560 			"	.chip	68k\n"
561 			"	jmp	%0@"
562 			: /* no outputs */
563 			: "a" (reset_addr)
564 			: "d0");
565 	} else
566 		asm volatile ("\n"
567 			"	pmove	%0,%%tc\n"
568 			"	jmp	%1@"
569 			: /* no outputs */
570 			: "m" (tc_val), "a" (reset_addr));
571 }
572 
573 
atari_get_model(char * model)574 static void atari_get_model(char *model)
575 {
576 	strcpy(model, "Atari ");
577 	switch (atari_mch_cookie >> 16) {
578 	case ATARI_MCH_ST:
579 		if (ATARIHW_PRESENT(MSTE_CLK))
580 			strcat(model, "Mega ST");
581 		else
582 			strcat(model, "ST");
583 		break;
584 	case ATARI_MCH_STE:
585 		if (MACH_IS_MSTE)
586 			strcat(model, "Mega STE");
587 		else
588 			strcat(model, "STE");
589 		break;
590 	case ATARI_MCH_TT:
591 		if (MACH_IS_MEDUSA)
592 			/* Medusa has TT _MCH cookie */
593 			strcat(model, "Medusa");
594 		else
595 			strcat(model, "TT");
596 		break;
597 	case ATARI_MCH_FALCON:
598 		strcat(model, "Falcon");
599 		if (MACH_IS_AB40)
600 			strcat(model, " (with Afterburner040)");
601 		break;
602 	default:
603 		sprintf(model + strlen(model), "(unknown mach cookie 0x%lx)",
604 			atari_mch_cookie);
605 		break;
606 	}
607 }
608 
609 
atari_get_hardware_list(struct seq_file * m)610 static void atari_get_hardware_list(struct seq_file *m)
611 {
612 	int i;
613 
614 	for (i = 0; i < m68k_num_memory; i++)
615 		seq_printf(m, "\t%3ld MB at 0x%08lx (%s)\n",
616 				m68k_memory[i].size >> 20, m68k_memory[i].addr,
617 				(m68k_memory[i].addr & 0xff000000 ?
618 				 "alternate RAM" : "ST-RAM"));
619 
620 #define ATARIHW_ANNOUNCE(name, str)			\
621 	if (ATARIHW_PRESENT(name))			\
622 		seq_printf(m, "\t%s\n", str)
623 
624 	seq_puts(m, "Detected hardware:\n");
625 	ATARIHW_ANNOUNCE(STND_SHIFTER, "ST Shifter");
626 	ATARIHW_ANNOUNCE(EXTD_SHIFTER, "STe Shifter");
627 	ATARIHW_ANNOUNCE(TT_SHIFTER, "TT Shifter");
628 	ATARIHW_ANNOUNCE(VIDEL_SHIFTER, "Falcon Shifter");
629 	ATARIHW_ANNOUNCE(YM_2149, "Programmable Sound Generator");
630 	ATARIHW_ANNOUNCE(PCM_8BIT, "PCM 8 Bit Sound");
631 	ATARIHW_ANNOUNCE(CODEC, "CODEC Sound");
632 	ATARIHW_ANNOUNCE(TT_SCSI, "SCSI Controller NCR5380 (TT style)");
633 	ATARIHW_ANNOUNCE(ST_SCSI, "SCSI Controller NCR5380 (Falcon style)");
634 	ATARIHW_ANNOUNCE(ACSI, "ACSI Interface");
635 	ATARIHW_ANNOUNCE(IDE, "IDE Interface");
636 	ATARIHW_ANNOUNCE(FDCSPEED, "8/16 Mhz Switch for FDC");
637 	ATARIHW_ANNOUNCE(ST_MFP, "Multi Function Peripheral MFP 68901");
638 	ATARIHW_ANNOUNCE(TT_MFP, "Second Multi Function Peripheral MFP 68901");
639 	ATARIHW_ANNOUNCE(SCC, "Serial Communications Controller SCC 8530");
640 	ATARIHW_ANNOUNCE(ST_ESCC, "Extended Serial Communications Controller SCC 85230");
641 	ATARIHW_ANNOUNCE(ANALOG_JOY, "Paddle Interface");
642 	ATARIHW_ANNOUNCE(MICROWIRE, "MICROWIRE(tm) Interface");
643 	ATARIHW_ANNOUNCE(STND_DMA, "DMA Controller (24 bit)");
644 	ATARIHW_ANNOUNCE(EXTD_DMA, "DMA Controller (32 bit)");
645 	ATARIHW_ANNOUNCE(SCSI_DMA, "DMA Controller for NCR5380");
646 	ATARIHW_ANNOUNCE(SCC_DMA, "DMA Controller for SCC");
647 	ATARIHW_ANNOUNCE(TT_CLK, "Clock Chip MC146818A");
648 	ATARIHW_ANNOUNCE(MSTE_CLK, "Clock Chip RP5C15");
649 	ATARIHW_ANNOUNCE(SCU, "System Control Unit");
650 	ATARIHW_ANNOUNCE(BLITTER, "Blitter");
651 	ATARIHW_ANNOUNCE(VME, "VME Bus");
652 	ATARIHW_ANNOUNCE(DSP56K, "DSP56001 processor");
653 }
654 
655 /*
656  * MSch: initial platform device support for Atari,
657  * required for EtherNAT/EtherNEC/NetUSBee drivers
658  */
659 
660 #if defined(CONFIG_ATARI_ETHERNAT) || defined(CONFIG_ATARI_ETHERNEC)
isp1160_delay(struct device * dev,int delay)661 static void isp1160_delay(struct device *dev, int delay)
662 {
663 	ndelay(delay);
664 }
665 #endif
666 
667 #ifdef CONFIG_ATARI_ETHERNAT
668 /*
669  * EtherNAT: SMC91C111 Ethernet chipset, handled by smc91x driver
670  */
671 
672 #define ATARI_ETHERNAT_IRQ		140
673 
674 static struct resource smc91x_resources[] = {
675 	[0] = {
676 		.name	= "smc91x-regs",
677 		.start	= ATARI_ETHERNAT_PHYS_ADDR,
678 		.end	= ATARI_ETHERNAT_PHYS_ADDR + 0xfffff,
679 		.flags	= IORESOURCE_MEM,
680 	},
681 	[1] = {
682 		.name	= "smc91x-irq",
683 		.start	= ATARI_ETHERNAT_IRQ,
684 		.end	= ATARI_ETHERNAT_IRQ,
685 		.flags	= IORESOURCE_IRQ,
686 	},
687 };
688 
689 static struct platform_device smc91x_device = {
690 	.name		= "smc91x",
691 	.id		= -1,
692 	.num_resources	= ARRAY_SIZE(smc91x_resources),
693 	.resource	= smc91x_resources,
694 };
695 
696 /*
697  * ISP 1160 - using the isp116x-hcd module
698  */
699 
700 #define ATARI_USB_PHYS_ADDR	0x80000012
701 #define ATARI_USB_IRQ		139
702 
703 static struct resource isp1160_resources[] = {
704 	[0] = {
705 		.name	= "isp1160-data",
706 		.start	= ATARI_USB_PHYS_ADDR,
707 		.end	= ATARI_USB_PHYS_ADDR + 0x1,
708 		.flags	= IORESOURCE_MEM,
709 	},
710 	[1] = {
711 		.name	= "isp1160-regs",
712 		.start	= ATARI_USB_PHYS_ADDR + 0x4,
713 		.end	= ATARI_USB_PHYS_ADDR + 0x5,
714 		.flags	= IORESOURCE_MEM,
715 	},
716 	[2] = {
717 		.name	= "isp1160-irq",
718 		.start	= ATARI_USB_IRQ,
719 		.end	= ATARI_USB_IRQ,
720 		.flags	= IORESOURCE_IRQ,
721 	},
722 };
723 
724 /* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
725 static struct isp116x_platform_data isp1160_platform_data = {
726 	/* Enable internal resistors on downstream ports */
727 	.sel15Kres		= 1,
728 	/* On-chip overcurrent protection */
729 	.oc_enable		= 1,
730 	/* INT output polarity */
731 	.int_act_high		= 1,
732 	/* INT edge or level triggered */
733 	.int_edge_triggered	= 0,
734 
735 	/* WAKEUP pin connected - NOT SUPPORTED  */
736 	/* .remote_wakeup_connected = 0, */
737 	/* Wakeup by devices on usb bus enabled */
738 	.remote_wakeup_enable	= 0,
739 	.delay			= isp1160_delay,
740 };
741 
742 static struct platform_device isp1160_device = {
743 	.name		= "isp116x-hcd",
744 	.id		= 0,
745 	.num_resources	= ARRAY_SIZE(isp1160_resources),
746 	.resource	= isp1160_resources,
747 	.dev			= {
748 		.platform_data	= &isp1160_platform_data,
749 	},
750 };
751 
752 static struct platform_device *atari_ethernat_devices[] __initdata = {
753 	&smc91x_device,
754 	&isp1160_device
755 };
756 #endif /* CONFIG_ATARI_ETHERNAT */
757 
758 #ifdef CONFIG_ATARI_ETHERNEC
759 /*
760  * EtherNEC: RTL8019 (NE2000 compatible) Ethernet chipset,
761  * handled by ne.c driver
762  */
763 
764 #define ATARI_ETHERNEC_PHYS_ADDR	0xfffa0000
765 #define ATARI_ETHERNEC_BASE		0x300
766 #define ATARI_ETHERNEC_IRQ		IRQ_MFP_TIMER1
767 
768 static struct resource rtl8019_resources[] = {
769 	[0] = {
770 		.name	= "rtl8019-regs",
771 		.start	= ATARI_ETHERNEC_BASE,
772 		.end	= ATARI_ETHERNEC_BASE + 0x20 - 1,
773 		.flags	= IORESOURCE_IO,
774 	},
775 	[1] = {
776 		.name	= "rtl8019-irq",
777 		.start	= ATARI_ETHERNEC_IRQ,
778 		.end	= ATARI_ETHERNEC_IRQ,
779 		.flags	= IORESOURCE_IRQ,
780 	},
781 };
782 
783 static struct platform_device rtl8019_device = {
784 	.name		= "ne",
785 	.id		= -1,
786 	.num_resources	= ARRAY_SIZE(rtl8019_resources),
787 	.resource	= rtl8019_resources,
788 };
789 
790 /*
791  * NetUSBee: ISP1160 USB host adapter via ROM-port adapter
792  */
793 
794 #define ATARI_NETUSBEE_PHYS_ADDR	0xfffa8000
795 #define ATARI_NETUSBEE_BASE		0x340
796 #define ATARI_NETUSBEE_IRQ		IRQ_MFP_TIMER2
797 
798 static struct resource netusbee_resources[] = {
799 	[0] = {
800 		.name	= "isp1160-data",
801 		.start	= ATARI_NETUSBEE_BASE,
802 		.end	= ATARI_NETUSBEE_BASE + 0x1,
803 		.flags	= IORESOURCE_MEM,
804 	},
805 	[1] = {
806 		.name	= "isp1160-regs",
807 		.start	= ATARI_NETUSBEE_BASE + 0x20,
808 		.end	= ATARI_NETUSBEE_BASE + 0x21,
809 		.flags	= IORESOURCE_MEM,
810 	},
811 	[2] = {
812 		.name	= "isp1160-irq",
813 		.start	= ATARI_NETUSBEE_IRQ,
814 		.end	= ATARI_NETUSBEE_IRQ,
815 		.flags	= IORESOURCE_IRQ,
816 	},
817 };
818 
819 /* (DataBusWidth16|AnalogOCEnable|DREQOutputPolarity|DownstreamPort15KRSel ) */
820 static struct isp116x_platform_data netusbee_platform_data = {
821 	/* Enable internal resistors on downstream ports */
822 	.sel15Kres		= 1,
823 	/* On-chip overcurrent protection */
824 	.oc_enable		= 1,
825 	/* INT output polarity */
826 	.int_act_high		= 1,
827 	/* INT edge or level triggered */
828 	.int_edge_triggered	= 0,
829 
830 	/* WAKEUP pin connected - NOT SUPPORTED  */
831 	/* .remote_wakeup_connected = 0, */
832 	/* Wakeup by devices on usb bus enabled */
833 	.remote_wakeup_enable	= 0,
834 	.delay			= isp1160_delay,
835 };
836 
837 static struct platform_device netusbee_device = {
838 	.name		= "isp116x-hcd",
839 	.id		= 1,
840 	.num_resources	= ARRAY_SIZE(netusbee_resources),
841 	.resource	= netusbee_resources,
842 	.dev			= {
843 		.platform_data	= &netusbee_platform_data,
844 	},
845 };
846 
847 static struct platform_device *atari_netusbee_devices[] __initdata = {
848 	&rtl8019_device,
849 	&netusbee_device
850 };
851 #endif /* CONFIG_ATARI_ETHERNEC */
852 
853 #if IS_ENABLED(CONFIG_ATARI_SCSI)
854 static const struct resource atari_scsi_st_rsrc[] __initconst = {
855 	{
856 		.flags = IORESOURCE_IRQ,
857 		.start = IRQ_MFP_FSCSI,
858 		.end   = IRQ_MFP_FSCSI,
859 	},
860 };
861 
862 static const struct resource atari_scsi_tt_rsrc[] __initconst = {
863 	{
864 		.flags = IORESOURCE_IRQ,
865 		.start = IRQ_TT_MFP_SCSI,
866 		.end   = IRQ_TT_MFP_SCSI,
867 	},
868 };
869 #endif
870 
871 /*
872  * Falcon IDE interface
873  */
874 
875 #define FALCON_IDE_BASE	0xfff00000
876 
877 static const struct resource atari_falconide_rsrc[] __initconst = {
878 	{
879 		.flags = IORESOURCE_MEM,
880 		.start = FALCON_IDE_BASE,
881 		.end   = FALCON_IDE_BASE + 0x39,
882 	},
883 	{
884 		.flags = IORESOURCE_IRQ,
885 		.start = IRQ_MFP_FSCSI,
886 		.end   = IRQ_MFP_FSCSI,
887 	},
888 };
889 
atari_platform_init(void)890 int __init atari_platform_init(void)
891 {
892 	struct platform_device *pdev;
893 	int rv = 0;
894 
895 	if (!MACH_IS_ATARI)
896 		return -ENODEV;
897 
898 #ifdef CONFIG_ATARI_ETHERNAT
899 	{
900 		unsigned char *enatc_virt;
901 		enatc_virt = (unsigned char *)ioremap((ATARI_ETHERNAT_PHYS_ADDR+0x23), 0xf);
902 		if (hwreg_present(enatc_virt)) {
903 			rv = platform_add_devices(atari_ethernat_devices,
904 						ARRAY_SIZE(atari_ethernat_devices));
905 		}
906 		iounmap(enatc_virt);
907 	}
908 #endif
909 
910 #ifdef CONFIG_ATARI_ETHERNEC
911 	{
912 		int error;
913 		unsigned char *enec_virt;
914 		enec_virt = (unsigned char *)ioremap((ATARI_ETHERNEC_PHYS_ADDR), 0xf);
915 		if (hwreg_present(enec_virt)) {
916 			error = platform_add_devices(atari_netusbee_devices,
917 						ARRAY_SIZE(atari_netusbee_devices));
918 			if (error && !rv)
919 				rv = error;
920 		}
921 		iounmap(enec_virt);
922 	}
923 #endif
924 
925 #if IS_ENABLED(CONFIG_ATARI_SCSI)
926 	if (ATARIHW_PRESENT(ST_SCSI))
927 		platform_device_register_simple("atari_scsi", -1,
928 			atari_scsi_st_rsrc, ARRAY_SIZE(atari_scsi_st_rsrc));
929 	else if (ATARIHW_PRESENT(TT_SCSI))
930 		platform_device_register_simple("atari_scsi", -1,
931 			atari_scsi_tt_rsrc, ARRAY_SIZE(atari_scsi_tt_rsrc));
932 #endif
933 
934 	if (ATARIHW_PRESENT(IDE)) {
935 		pdev = platform_device_register_simple("atari-falcon-ide", -1,
936 			atari_falconide_rsrc, ARRAY_SIZE(atari_falconide_rsrc));
937 		if (IS_ERR(pdev))
938 			rv = PTR_ERR(pdev);
939 	}
940 
941 	return rv;
942 }
943 
944 arch_initcall(atari_platform_init);
945