blob: 9625b71322275ea942da3bc1b3a6616e205bdc7a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/arch/m68k/amiga/config.c
3 *
4 * Copyright (C) 1993 Hamish Macdonald
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
10
11/*
12 * Miscellaneous Amiga stuff
13 */
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/mm.h>
Alexey Dobriyan813dcf72008-10-03 22:42:36 +040018#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/tty.h>
20#include <linux/console.h>
21#include <linux/rtc.h>
22#include <linux/init.h>
23#include <linux/vt_kern.h>
24#include <linux/delay.h>
25#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/zorro.h>
Adrian Bunk8b169fa2008-02-04 22:30:25 -080027#include <linux/module.h>
Geert Uytterhoeven39d2d992008-10-13 21:58:53 +020028#include <linux/keyboard.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30#include <asm/bootinfo.h>
Geert Uytterhoeven4c3c5222013-10-02 11:37:33 +020031#include <asm/bootinfo-amiga.h>
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020032#include <asm/byteorder.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include <asm/pgtable.h>
35#include <asm/amigahw.h>
36#include <asm/amigaints.h>
37#include <asm/irq.h>
38#include <asm/rtc.h>
39#include <asm/machdep.h>
40#include <asm/io.h>
41
Adrian Bunk0795dbc2008-07-17 21:16:23 +020042static unsigned long amiga_model;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044unsigned long amiga_eclock;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080045EXPORT_SYMBOL(amiga_eclock);
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047unsigned long amiga_colorclock;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080048EXPORT_SYMBOL(amiga_colorclock);
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050unsigned long amiga_chipset;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080051EXPORT_SYMBOL(amiga_chipset);
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053unsigned char amiga_vblank;
Adrian Bunk8468afc2008-07-17 21:16:21 +020054EXPORT_SYMBOL(amiga_vblank);
55
Adrian Bunk0795dbc2008-07-17 21:16:23 +020056static unsigned char amiga_psfreq;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080057
Linus Torvalds1da177e2005-04-16 15:20:36 -070058struct amiga_hw_present amiga_hw_present;
Adrian Bunk8b169fa2008-02-04 22:30:25 -080059EXPORT_SYMBOL(amiga_hw_present);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61static char s_a500[] __initdata = "A500";
62static char s_a500p[] __initdata = "A500+";
63static char s_a600[] __initdata = "A600";
64static char s_a1000[] __initdata = "A1000";
65static char s_a1200[] __initdata = "A1200";
66static char s_a2000[] __initdata = "A2000";
67static char s_a2500[] __initdata = "A2500";
68static char s_a3000[] __initdata = "A3000";
69static char s_a3000t[] __initdata = "A3000T";
70static char s_a3000p[] __initdata = "A3000+";
71static char s_a4000[] __initdata = "A4000";
72static char s_a4000t[] __initdata = "A4000T";
73static char s_cdtv[] __initdata = "CDTV";
74static char s_cd32[] __initdata = "CD32";
75static char s_draco[] __initdata = "Draco";
76static char *amiga_models[] __initdata = {
Roman Zippel6ff58012007-05-01 22:32:43 +020077 [AMI_500-AMI_500] = s_a500,
78 [AMI_500PLUS-AMI_500] = s_a500p,
79 [AMI_600-AMI_500] = s_a600,
80 [AMI_1000-AMI_500] = s_a1000,
81 [AMI_1200-AMI_500] = s_a1200,
82 [AMI_2000-AMI_500] = s_a2000,
83 [AMI_2500-AMI_500] = s_a2500,
84 [AMI_3000-AMI_500] = s_a3000,
85 [AMI_3000T-AMI_500] = s_a3000t,
86 [AMI_3000PLUS-AMI_500] = s_a3000p,
87 [AMI_4000-AMI_500] = s_a4000,
88 [AMI_4000T-AMI_500] = s_a4000t,
89 [AMI_CDTV-AMI_500] = s_cdtv,
90 [AMI_CD32-AMI_500] = s_cd32,
91 [AMI_DRACO-AMI_500] = s_draco,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94static char amiga_model_name[13] = "Amiga ";
95
David Howells40220c12006-10-09 12:19:47 +010096static void amiga_sched_init(irq_handler_t handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097static void amiga_get_model(char *model);
Alexey Dobriyan813dcf72008-10-03 22:42:36 +040098static void amiga_get_hardware_list(struct seq_file *m);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* amiga specific timer functions */
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700100static u32 amiga_gettimeoffset(void);
Roman Zippel6ff58012007-05-01 22:32:43 +0200101extern void amiga_mksound(unsigned int count, unsigned int ticks);
102static void amiga_reset(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103extern void amiga_init_sound(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static void amiga_mem_console_write(struct console *co, const char *b,
105 unsigned int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#ifdef CONFIG_HEARTBEAT
107static void amiga_heartbeat(int on);
108#endif
109
110static struct console amiga_console_driver = {
Roman Zippel6ff58012007-05-01 22:32:43 +0200111 .name = "debug",
112 .flags = CON_PRINTBUFFER,
113 .index = -1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114};
115
116
117 /*
118 * Motherboard Resources present in all Amiga models
119 */
120
121static struct {
Roman Zippel6ff58012007-05-01 22:32:43 +0200122 struct resource _ciab, _ciaa, _custom, _kickstart;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123} mb_resources = {
Roman Zippel6ff58012007-05-01 22:32:43 +0200124 ._ciab = {
125 .name = "CIA B", .start = 0x00bfd000, .end = 0x00bfdfff
126 },
127 ._ciaa = {
128 .name = "CIA A", .start = 0x00bfe000, .end = 0x00bfefff
129 },
130 ._custom = {
131 .name = "Custom I/O", .start = 0x00dff000, .end = 0x00dfffff
132 },
133 ._kickstart = {
134 .name = "Kickstart ROM", .start = 0x00f80000, .end = 0x00ffffff
135 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136};
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138static struct resource ram_resource[NUM_MEMINFO];
139
140
141 /*
142 * Parse an Amiga-specific record in the bootinfo
143 */
144
Geert Uytterhoevena4df02a2013-06-25 21:15:24 +0200145int __init amiga_parse_bootinfo(const struct bi_record *record)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Roman Zippel6ff58012007-05-01 22:32:43 +0200147 int unknown = 0;
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200148 const void *data = record->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200150 switch (be16_to_cpu(record->tag)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 case BI_AMIGA_MODEL:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200152 amiga_model = be32_to_cpup(data);
Roman Zippel6ff58012007-05-01 22:32:43 +0200153 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 case BI_AMIGA_ECLOCK:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200156 amiga_eclock = be32_to_cpup(data);
Roman Zippel6ff58012007-05-01 22:32:43 +0200157 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 case BI_AMIGA_CHIPSET:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200160 amiga_chipset = be32_to_cpup(data);
Roman Zippel6ff58012007-05-01 22:32:43 +0200161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 case BI_AMIGA_CHIP_SIZE:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200164 amiga_chip_size = be32_to_cpup(data);
Roman Zippel6ff58012007-05-01 22:32:43 +0200165 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 case BI_AMIGA_VBLANK:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200168 amiga_vblank = *(const __u8 *)data;
Roman Zippel6ff58012007-05-01 22:32:43 +0200169 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171 case BI_AMIGA_PSFREQ:
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200172 amiga_psfreq = *(const __u8 *)data;
Roman Zippel6ff58012007-05-01 22:32:43 +0200173 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 case BI_AMIGA_AUTOCON:
176#ifdef CONFIG_ZORRO
Roman Zippel6ff58012007-05-01 22:32:43 +0200177 if (zorro_num_autocon < ZORRO_NUM_AUTO) {
Geert Uytterhoevenabe48102013-10-04 11:41:24 +0200178 const struct ConfigDev *cd = data;
Geert Uytterhoevenc2937382013-06-29 10:40:20 +0200179 struct zorro_dev_init *dev = &zorro_autocon_init[zorro_num_autocon++];
Roman Zippel6ff58012007-05-01 22:32:43 +0200180 dev->rom = cd->cd_Rom;
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +0200181 dev->slotaddr = be16_to_cpu(cd->cd_SlotAddr);
182 dev->slotsize = be16_to_cpu(cd->cd_SlotSize);
183 dev->boardaddr = be32_to_cpu(cd->cd_BoardAddr);
184 dev->boardsize = be32_to_cpu(cd->cd_BoardSize);
Roman Zippel6ff58012007-05-01 22:32:43 +0200185 } else
186 printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#endif /* CONFIG_ZORRO */
Roman Zippel6ff58012007-05-01 22:32:43 +0200188 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 case BI_AMIGA_SERPER:
Roman Zippel6ff58012007-05-01 22:32:43 +0200191 /* serial port period: ignored here */
192 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 default:
Roman Zippel6ff58012007-05-01 22:32:43 +0200195 unknown = 1;
196 }
197 return unknown;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
200 /*
201 * Identify builtin hardware
202 */
203
204static void __init amiga_identify(void)
205{
Roman Zippel6ff58012007-05-01 22:32:43 +0200206 /* Fill in some default values, if necessary */
207 if (amiga_eclock == 0)
208 amiga_eclock = 709379;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Roman Zippel6ff58012007-05-01 22:32:43 +0200210 memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Roman Zippel6ff58012007-05-01 22:32:43 +0200212 printk("Amiga hardware found: ");
213 if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
214 printk("[%s] ", amiga_models[amiga_model-AMI_500]);
215 strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
216 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Roman Zippel6ff58012007-05-01 22:32:43 +0200218 switch (amiga_model) {
219 case AMI_UNKNOWN:
220 goto Generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Roman Zippel6ff58012007-05-01 22:32:43 +0200222 case AMI_600:
223 case AMI_1200:
224 AMIGAHW_SET(A1200_IDE);
225 AMIGAHW_SET(PCMCIA);
226 case AMI_500:
227 case AMI_500PLUS:
228 case AMI_1000:
229 case AMI_2000:
230 case AMI_2500:
231 AMIGAHW_SET(A2000_CLK); /* Is this correct for all models? */
232 goto Generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
Roman Zippel6ff58012007-05-01 22:32:43 +0200234 case AMI_3000:
235 case AMI_3000T:
236 AMIGAHW_SET(AMBER_FF);
237 AMIGAHW_SET(MAGIC_REKICK);
238 /* fall through */
239 case AMI_3000PLUS:
240 AMIGAHW_SET(A3000_SCSI);
241 AMIGAHW_SET(A3000_CLK);
242 AMIGAHW_SET(ZORRO3);
243 goto Generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Roman Zippel6ff58012007-05-01 22:32:43 +0200245 case AMI_4000T:
246 AMIGAHW_SET(A4000_SCSI);
247 /* fall through */
248 case AMI_4000:
249 AMIGAHW_SET(A4000_IDE);
250 AMIGAHW_SET(A3000_CLK);
251 AMIGAHW_SET(ZORRO3);
252 goto Generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Roman Zippel6ff58012007-05-01 22:32:43 +0200254 case AMI_CDTV:
255 case AMI_CD32:
256 AMIGAHW_SET(CD_ROM);
257 AMIGAHW_SET(A2000_CLK); /* Is this correct? */
258 goto Generic;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Roman Zippel6ff58012007-05-01 22:32:43 +0200260 Generic:
261 AMIGAHW_SET(AMI_VIDEO);
262 AMIGAHW_SET(AMI_BLITTER);
263 AMIGAHW_SET(AMI_AUDIO);
264 AMIGAHW_SET(AMI_FLOPPY);
265 AMIGAHW_SET(AMI_KEYBOARD);
266 AMIGAHW_SET(AMI_MOUSE);
267 AMIGAHW_SET(AMI_SERIAL);
268 AMIGAHW_SET(AMI_PARALLEL);
269 AMIGAHW_SET(CHIP_RAM);
270 AMIGAHW_SET(PAULA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Roman Zippel6ff58012007-05-01 22:32:43 +0200272 switch (amiga_chipset) {
273 case CS_OCS:
274 case CS_ECS:
275 case CS_AGA:
276 switch (amiga_custom.deniseid & 0xf) {
277 case 0x0c:
278 AMIGAHW_SET(DENISE_HR);
279 break;
280 case 0x08:
281 AMIGAHW_SET(LISA);
282 break;
283 }
284 break;
285 default:
286 AMIGAHW_SET(DENISE);
287 break;
288 }
289 switch ((amiga_custom.vposr>>8) & 0x7f) {
290 case 0x00:
291 AMIGAHW_SET(AGNUS_PAL);
292 break;
293 case 0x10:
294 AMIGAHW_SET(AGNUS_NTSC);
295 break;
296 case 0x20:
297 case 0x21:
298 AMIGAHW_SET(AGNUS_HR_PAL);
299 break;
300 case 0x30:
301 case 0x31:
302 AMIGAHW_SET(AGNUS_HR_NTSC);
303 break;
304 case 0x22:
305 case 0x23:
306 AMIGAHW_SET(ALICE_PAL);
307 break;
308 case 0x32:
309 case 0x33:
310 AMIGAHW_SET(ALICE_NTSC);
311 break;
312 }
313 AMIGAHW_SET(ZORRO);
314 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Roman Zippel6ff58012007-05-01 22:32:43 +0200316 case AMI_DRACO:
317 panic("No support for Draco yet");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Roman Zippel6ff58012007-05-01 22:32:43 +0200319 default:
320 panic("Unknown Amiga Model");
321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Roman Zippel6ff58012007-05-01 22:32:43 +0200323#define AMIGAHW_ANNOUNCE(name, str) \
324 if (AMIGAHW_PRESENT(name)) \
325 printk(str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Roman Zippel6ff58012007-05-01 22:32:43 +0200327 AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO ");
328 AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER ");
329 AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF ");
330 AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO ");
331 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY ");
332 AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI ");
333 AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI ");
334 AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE ");
335 AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE ");
336 AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM ");
337 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD ");
338 AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE ");
339 AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL ");
340 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL ");
341 AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK ");
342 AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK ");
343 AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM ");
344 AMIGAHW_ANNOUNCE(PAULA, "PAULA ");
345 AMIGAHW_ANNOUNCE(DENISE, "DENISE ");
346 AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR ");
347 AMIGAHW_ANNOUNCE(LISA, "LISA ");
348 AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL ");
349 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC ");
350 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL ");
351 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC ");
352 AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL ");
353 AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC ");
354 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK ");
355 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA ");
356 if (AMIGAHW_PRESENT(ZORRO))
357 printk("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : "");
358 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360#undef AMIGAHW_ANNOUNCE
361}
362
Geert Uytterhoeven50190ed2013-10-18 13:16:06 +0200363
364static unsigned long amiga_random_get_entropy(void)
365{
366 /* VPOSR/VHPOSR provide at least 17 bits of data changing at 1.79 MHz */
367 return *(unsigned long *)&amiga_custom.vposr;
368}
369
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /*
372 * Setup the Amiga configuration info
373 */
374
375void __init config_amiga(void)
376{
Roman Zippel6ff58012007-05-01 22:32:43 +0200377 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Roman Zippel6ff58012007-05-01 22:32:43 +0200379 amiga_identify();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Roman Zippel6ff58012007-05-01 22:32:43 +0200381 /* Yuk, we don't have PCI memory */
382 iomem_resource.name = "Memory";
383 for (i = 0; i < 4; i++)
384 request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Roman Zippel6ff58012007-05-01 22:32:43 +0200386 mach_sched_init = amiga_sched_init;
387 mach_init_IRQ = amiga_init_IRQ;
388 mach_get_model = amiga_get_model;
389 mach_get_hardware_list = amiga_get_hardware_list;
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700390 arch_gettimeoffset = amiga_gettimeoffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Roman Zippel6ff58012007-05-01 22:32:43 +0200392 /*
393 * default MAX_DMA=0xffffffff on all machines. If we don't do so, the SCSI
394 * code will not be able to allocate any mem for transfers, unless we are
395 * dealing with a Z2 mem only system. /Jes
396 */
397 mach_max_dma_address = 0xffffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Roman Zippel6ff58012007-05-01 22:32:43 +0200399 mach_reset = amiga_reset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
Roman Zippel6ff58012007-05-01 22:32:43 +0200401 mach_beep = amiga_mksound;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402#endif
403
404#ifdef CONFIG_HEARTBEAT
Roman Zippel6ff58012007-05-01 22:32:43 +0200405 mach_heartbeat = amiga_heartbeat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#endif
407
Geert Uytterhoeven50190ed2013-10-18 13:16:06 +0200408 mach_random_get_entropy = amiga_random_get_entropy;
409
Adrian Bunk0795dbc2008-07-17 21:16:23 +0200410 /* Fill in the clock value (based on the 700 kHz E-Clock) */
Roman Zippel6ff58012007-05-01 22:32:43 +0200411 amiga_colorclock = 5*amiga_eclock; /* 3.5 MHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Roman Zippel6ff58012007-05-01 22:32:43 +0200413 /* clear all DMA bits */
414 amiga_custom.dmacon = DMAF_ALL;
415 /* ensure that the DMA master bit is set */
416 amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Roman Zippel6ff58012007-05-01 22:32:43 +0200418 /* don't use Z2 RAM as system memory on Z3 capable machines */
419 if (AMIGAHW_PRESENT(ZORRO3)) {
420 int i, j;
421 u32 disabled_z2mem = 0;
422
423 for (i = 0; i < m68k_num_memory; i++) {
424 if (m68k_memory[i].addr < 16*1024*1024) {
425 if (i == 0) {
426 /* don't cut off the branch we're sitting on */
427 printk("Warning: kernel runs in Zorro II memory\n");
428 continue;
429 }
430 disabled_z2mem += m68k_memory[i].size;
431 m68k_num_memory--;
432 for (j = i; j < m68k_num_memory; j++)
433 m68k_memory[j] = m68k_memory[j+1];
434 i--;
435 }
436 }
437 if (disabled_z2mem)
438 printk("%dK of Zorro II memory will not be used as system memory\n",
439 disabled_z2mem>>10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Roman Zippel6ff58012007-05-01 22:32:43 +0200442 /* request all RAM */
443 for (i = 0; i < m68k_num_memory; i++) {
444 ram_resource[i].name =
445 (m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" :
446 (m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" :
447 "16-bit Slow RAM";
448 ram_resource[i].start = m68k_memory[i].addr;
449 ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1;
450 request_resource(&iomem_resource, &ram_resource[i]);
451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Roman Zippel6ff58012007-05-01 22:32:43 +0200453 /* initialize chipram allocator */
454 amiga_chip_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Roman Zippel6ff58012007-05-01 22:32:43 +0200456 /* our beloved beeper */
457 if (AMIGAHW_PRESENT(AMI_AUDIO))
458 amiga_init_sound();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Roman Zippel6ff58012007-05-01 22:32:43 +0200460 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
468static unsigned short jiffy_ticks;
469
David Howells40220c12006-10-09 12:19:47 +0100470static void __init amiga_sched_init(irq_handler_t timer_routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
472 static struct resource sched_res = {
Roman Zippel6ff58012007-05-01 22:32:43 +0200473 .name = "timer", .start = 0x00bfd400, .end = 0x00bfd5ff,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 };
Julia Lawall1a0caf42009-08-02 10:47:47 +0200475 jiffy_ticks = DIV_ROUND_CLOSEST(amiga_eclock, HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 if (request_resource(&mb_resources._ciab, &sched_res))
Roman Zippel6ff58012007-05-01 22:32:43 +0200478 printk("Cannot allocate ciab.ta{lo,hi}\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 ciab.cra &= 0xC0; /* turn off timer A, continuous mode, from Eclk */
480 ciab.talo = jiffy_ticks % 256;
481 ciab.tahi = jiffy_ticks / 256;
482
483 /* install interrupt service routine for CIAB Timer A
484 *
485 * Please don't change this to use ciaa, as it interferes with the
486 * SCSI code. We'll have to take a look at this later
487 */
Geert Uytterhoeven66acd252008-12-30 14:00:34 +0100488 if (request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, 0, "timer", NULL))
489 pr_err("Couldn't register timer interrupt\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 /* start timer */
491 ciab.cra |= 0x11;
492}
493
494#define TICK_SIZE 10000
495
496/* This is always executed with interrupts disabled. */
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700497static u32 amiga_gettimeoffset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 unsigned short hi, lo, hi2;
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700500 u32 ticks, offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
502 /* read CIA B timer A current value */
503 hi = ciab.tahi;
504 lo = ciab.talo;
505 hi2 = ciab.tahi;
506
507 if (hi != hi2) {
508 lo = ciab.talo;
509 hi = hi2;
510 }
511
512 ticks = hi << 8 | lo;
513
514 if (ticks > jiffy_ticks / 2)
515 /* check for pending interrupt */
516 if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
517 offset = 10000;
518
519 ticks = jiffy_ticks - ticks;
520 ticks = (10000 * ticks) / jiffy_ticks;
521
Stephen Warrenc8d5ba12012-11-08 11:34:55 -0700522 return (ticks + offset) * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523}
524
Joe Perchesff2d8b12012-01-12 17:17:21 -0800525static void amiga_reset(void) __noreturn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Roman Zippel6ff58012007-05-01 22:32:43 +0200527static void amiga_reset(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Roman Zippel6ff58012007-05-01 22:32:43 +0200529 unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
530 unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Roman Zippel6ff58012007-05-01 22:32:43 +0200532 local_irq_disable();
533 if (CPU_IS_040_OR_060)
534 /* Setup transparent translation registers for mapping
535 * of 16 MB kernel segment before disabling translation
536 */
537 asm volatile ("\n"
538 " move.l %0,%%d0\n"
539 " and.l #0xff000000,%%d0\n"
540 " or.w #0xe020,%%d0\n" /* map 16 MB, enable, cacheable */
541 " .chip 68040\n"
542 " movec %%d0,%%itt0\n"
543 " movec %%d0,%%dtt0\n"
544 " .chip 68k\n"
545 " jmp %0@\n"
546 : /* no outputs */
547 : "a" (jmp_addr040)
548 : "d0");
549 else
550 /* for 680[23]0, just disable translation and jump to the physical
551 * address of the label
552 */
553 asm volatile ("\n"
554 " pmove %%tc,%@\n"
555 " bclr #7,%@\n"
556 " pmove %@,%%tc\n"
557 " jmp %0@\n"
558 : /* no outputs */
559 : "a" (jmp_addr));
560jmp_addr_label040:
561 /* disable translation on '040 now */
562 asm volatile ("\n"
563 " moveq #0,%%d0\n"
564 " .chip 68040\n"
565 " movec %%d0,%%tc\n" /* disable MMU */
566 " .chip 68k\n"
567 : /* no outputs */
568 : /* no inputs */
569 : "d0");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Roman Zippel6ff58012007-05-01 22:32:43 +0200571 jmp_addr_label:
572 /* pickup reset address from AmigaOS ROM, reset devices and jump
573 * to reset address
574 */
575 asm volatile ("\n"
576 " move.w #0x2700,%sr\n"
577 " lea 0x01000000,%a0\n"
578 " sub.l %a0@(-0x14),%a0\n"
579 " move.l %a0@(4),%a0\n"
580 " subq.l #2,%a0\n"
581 " jra 1f\n"
582 /* align on a longword boundary */
583 " " __ALIGN_STR "\n"
584 "1:\n"
585 " reset\n"
586 " jmp %a0@");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Roman Zippel6ff58012007-05-01 22:32:43 +0200588 for (;;)
589 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592
593 /*
594 * Debugging
595 */
596
597#define SAVEKMSG_MAXMEM 128*1024
598
599#define SAVEKMSG_MAGIC1 0x53415645 /* 'SAVE' */
600#define SAVEKMSG_MAGIC2 0x4B4D5347 /* 'KMSG' */
601
602struct savekmsg {
Roman Zippel6ff58012007-05-01 22:32:43 +0200603 unsigned long magic1; /* SAVEKMSG_MAGIC1 */
604 unsigned long magic2; /* SAVEKMSG_MAGIC2 */
605 unsigned long magicptr; /* address of magic1 */
606 unsigned long size;
607 char data[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608};
609
610static struct savekmsg *savekmsg;
611
612static void amiga_mem_console_write(struct console *co, const char *s,
613 unsigned int count)
614{
Roman Zippel6ff58012007-05-01 22:32:43 +0200615 if (savekmsg->size + count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
616 memcpy(savekmsg->data + savekmsg->size, s, count);
617 savekmsg->size += count;
618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619}
620
Roman Zippeld6713b42007-05-01 22:32:45 +0200621static int __init amiga_savekmsg_setup(char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Geert Uytterhoeven8a09cec2013-12-01 11:14:51 +0100623 bool registered;
624
Roman Zippeld6713b42007-05-01 22:32:45 +0200625 if (!MACH_IS_AMIGA || strcmp(arg, "mem"))
Geert Uytterhoeven5df1abd2011-01-07 13:25:29 +0100626 return 0;
Roman Zippeld6713b42007-05-01 22:32:45 +0200627
Geert Uytterhoeven5df1abd2011-01-07 13:25:29 +0100628 if (amiga_chip_size < SAVEKMSG_MAXMEM) {
629 pr_err("Not enough chipram for debugging\n");
630 return -ENOMEM;
Roman Zippeld6713b42007-05-01 22:32:45 +0200631 }
632
Geert Uytterhoeven5df1abd2011-01-07 13:25:29 +0100633 /* Just steal the block, the chipram allocator isn't functional yet */
634 amiga_chip_size -= SAVEKMSG_MAXMEM;
Geert Uytterhoeven6112ea02011-01-09 11:03:43 +0100635 savekmsg = ZTWO_VADDR(CHIP_PHYSADDR + amiga_chip_size);
Roman Zippel6ff58012007-05-01 22:32:43 +0200636 savekmsg->magic1 = SAVEKMSG_MAGIC1;
637 savekmsg->magic2 = SAVEKMSG_MAGIC2;
638 savekmsg->magicptr = ZTWO_PADDR(savekmsg);
639 savekmsg->size = 0;
Roman Zippeld6713b42007-05-01 22:32:45 +0200640
Geert Uytterhoeven8a09cec2013-12-01 11:14:51 +0100641 registered = !!amiga_console_driver.write;
Roman Zippeld6713b42007-05-01 22:32:45 +0200642 amiga_console_driver.write = amiga_mem_console_write;
Geert Uytterhoeven8a09cec2013-12-01 11:14:51 +0100643 if (!registered)
644 register_console(&amiga_console_driver);
Roman Zippeld6713b42007-05-01 22:32:45 +0200645 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646}
647
Roman Zippeld6713b42007-05-01 22:32:45 +0200648early_param("debug", amiga_savekmsg_setup);
649
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650static void amiga_serial_putc(char c)
651{
Roman Zippel6ff58012007-05-01 22:32:43 +0200652 amiga_custom.serdat = (unsigned char)c | 0x100;
653 while (!(amiga_custom.serdatr & 0x2000))
654 ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
Adrian Bunk0795dbc2008-07-17 21:16:23 +0200657static void amiga_serial_console_write(struct console *co, const char *s,
658 unsigned int count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Roman Zippel6ff58012007-05-01 22:32:43 +0200660 while (count--) {
661 if (*s == '\n')
662 amiga_serial_putc('\r');
663 amiga_serial_putc(*s++);
664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
Adrian Bunk0795dbc2008-07-17 21:16:23 +0200667#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668void amiga_serial_puts(const char *s)
669{
Roman Zippel6ff58012007-05-01 22:32:43 +0200670 amiga_serial_console_write(NULL, s, strlen(s));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671}
672
673int amiga_serial_console_wait_key(struct console *co)
674{
Roman Zippel6ff58012007-05-01 22:32:43 +0200675 int ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676
Roman Zippel6ff58012007-05-01 22:32:43 +0200677 while (!(amiga_custom.intreqr & IF_RBF))
678 barrier();
679 ch = amiga_custom.serdatr & 0xff;
680 /* clear the interrupt, so that another character can be read */
681 amiga_custom.intreq = IF_RBF;
682 return ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683}
684
685void amiga_serial_gets(struct console *co, char *s, int len)
686{
Roman Zippel6ff58012007-05-01 22:32:43 +0200687 int ch, cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
Roman Zippel6ff58012007-05-01 22:32:43 +0200689 while (1) {
690 ch = amiga_serial_console_wait_key(co);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Roman Zippel6ff58012007-05-01 22:32:43 +0200692 /* Check for backspace. */
693 if (ch == 8 || ch == 127) {
694 if (cnt == 0) {
695 amiga_serial_putc('\007');
696 continue;
697 }
698 cnt--;
699 amiga_serial_puts("\010 \010");
700 continue;
701 }
702
703 /* Check for enter. */
704 if (ch == 10 || ch == 13)
705 break;
706
707 /* See if line is too long. */
708 if (cnt >= len + 1) {
709 amiga_serial_putc(7);
710 cnt--;
711 continue;
712 }
713
714 /* Store and echo character. */
715 s[cnt++] = ch;
716 amiga_serial_putc(ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 }
Roman Zippel6ff58012007-05-01 22:32:43 +0200718 /* Print enter. */
719 amiga_serial_puts("\r\n");
720 s[cnt] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
722#endif
723
Roman Zippeld6713b42007-05-01 22:32:45 +0200724static int __init amiga_debug_setup(char *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725{
Geert Uytterhoeven8a09cec2013-12-01 11:14:51 +0100726 bool registered;
727
728 if (!MACH_IS_AMIGA || strcmp(arg, "ser"))
729 return 0;
730
731 /* no initialization required (?) */
732 registered = !!amiga_console_driver.write;
733 amiga_console_driver.write = amiga_serial_console_write;
734 if (!registered)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 register_console(&amiga_console_driver);
Roman Zippeld6713b42007-05-01 22:32:45 +0200736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
Roman Zippeld6713b42007-05-01 22:32:45 +0200739early_param("debug", amiga_debug_setup);
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741#ifdef CONFIG_HEARTBEAT
742static void amiga_heartbeat(int on)
743{
Roman Zippel6ff58012007-05-01 22:32:43 +0200744 if (on)
745 ciaa.pra &= ~2;
746 else
747 ciaa.pra |= 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749#endif
750
751 /*
752 * Amiga specific parts of /proc
753 */
754
755static void amiga_get_model(char *model)
756{
Roman Zippel6ff58012007-05-01 22:32:43 +0200757 strcpy(model, amiga_model_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
760
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400761static void amiga_get_hardware_list(struct seq_file *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
Roman Zippel6ff58012007-05-01 22:32:43 +0200763 if (AMIGAHW_PRESENT(CHIP_RAM))
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400764 seq_printf(m, "Chip RAM:\t%ldK\n", amiga_chip_size>>10);
765 seq_printf(m, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n",
Roman Zippel6ff58012007-05-01 22:32:43 +0200766 amiga_psfreq, amiga_eclock);
767 if (AMIGAHW_PRESENT(AMI_VIDEO)) {
768 char *type;
769 switch (amiga_chipset) {
770 case CS_OCS:
771 type = "OCS";
772 break;
773 case CS_ECS:
774 type = "ECS";
775 break;
776 case CS_AGA:
777 type = "AGA";
778 break;
779 default:
780 type = "Old or Unknown";
781 break;
782 }
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400783 seq_printf(m, "Graphics:\t%s\n", type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
786#define AMIGAHW_ANNOUNCE(name, str) \
Roman Zippel6ff58012007-05-01 22:32:43 +0200787 if (AMIGAHW_PRESENT(name)) \
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400788 seq_printf (m, "\t%s\n", str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400790 seq_printf (m, "Detected hardware:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Roman Zippel6ff58012007-05-01 22:32:43 +0200792 AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video");
793 AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter");
794 AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer");
795 AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio");
796 AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller");
797 AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)");
798 AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)");
799 AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)");
800 AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)");
801 AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive");
802 AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard");
803 AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port");
804 AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port");
805 AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port");
806 AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)");
807 AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)");
808 AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM");
809 AMIGAHW_ANNOUNCE(PAULA, "Paula 8364");
810 AMIGAHW_ANNOUNCE(DENISE, "Denise 8362");
811 AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373");
812 AMIGAHW_ANNOUNCE(LISA, "Lisa 8375");
813 AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371");
814 AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370");
815 AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372");
816 AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372");
817 AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374");
818 AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374");
819 AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
820 AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821#ifdef CONFIG_ZORRO
Roman Zippel6ff58012007-05-01 22:32:43 +0200822 if (AMIGAHW_PRESENT(ZORRO))
Alexey Dobriyan813dcf72008-10-03 22:42:36 +0400823 seq_printf(m, "\tZorro II%s AutoConfig: %d Expansion "
Roman Zippel6ff58012007-05-01 22:32:43 +0200824 "Device%s\n",
825 AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
826 zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827#endif /* CONFIG_ZORRO */
828
829#undef AMIGAHW_ANNOUNCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830}
Geert Uytterhoeven39d2d992008-10-13 21:58:53 +0200831
832/*
833 * The Amiga keyboard driver needs key_maps, but we cannot export it in
834 * drivers/char/defkeymap.c, as it is autogenerated
835 */
836#ifdef CONFIG_HW_CONSOLE
837EXPORT_SYMBOL_GPL(key_maps);
838#endif