config.c 24.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *  linux/arch/m68k/amiga/config.c
 *
 *  Copyright (C) 1993 Hamish Macdonald
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file COPYING in the main directory of this archive
 * for more details.
 */

/*
 * Miscellaneous Amiga stuff
 */

#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/mm.h>
18
#include <linux/seq_file.h>
L
Linus Torvalds 已提交
19 20 21 22 23 24 25 26
#include <linux/tty.h>
#include <linux/console.h>
#include <linux/rtc.h>
#include <linux/init.h>
#include <linux/vt_kern.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/zorro.h>
27
#include <linux/module.h>
28
#include <linux/keyboard.h>
L
Linus Torvalds 已提交
29 30 31 32 33 34 35 36 37 38 39 40

#include <asm/bootinfo.h>
#include <asm/setup.h>
#include <asm/system.h>
#include <asm/pgtable.h>
#include <asm/amigahw.h>
#include <asm/amigaints.h>
#include <asm/irq.h>
#include <asm/rtc.h>
#include <asm/machdep.h>
#include <asm/io.h>

A
Adrian Bunk 已提交
41
static unsigned long amiga_model;
42

L
Linus Torvalds 已提交
43
unsigned long amiga_eclock;
44 45
EXPORT_SYMBOL(amiga_eclock);

L
Linus Torvalds 已提交
46
unsigned long amiga_colorclock;
47 48
EXPORT_SYMBOL(amiga_colorclock);

L
Linus Torvalds 已提交
49
unsigned long amiga_chipset;
50 51
EXPORT_SYMBOL(amiga_chipset);

L
Linus Torvalds 已提交
52
unsigned char amiga_vblank;
A
Adrian Bunk 已提交
53 54
EXPORT_SYMBOL(amiga_vblank);

A
Adrian Bunk 已提交
55
static unsigned char amiga_psfreq;
56

L
Linus Torvalds 已提交
57
struct amiga_hw_present amiga_hw_present;
58
EXPORT_SYMBOL(amiga_hw_present);
L
Linus Torvalds 已提交
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

static char s_a500[] __initdata = "A500";
static char s_a500p[] __initdata = "A500+";
static char s_a600[] __initdata = "A600";
static char s_a1000[] __initdata = "A1000";
static char s_a1200[] __initdata = "A1200";
static char s_a2000[] __initdata = "A2000";
static char s_a2500[] __initdata = "A2500";
static char s_a3000[] __initdata = "A3000";
static char s_a3000t[] __initdata = "A3000T";
static char s_a3000p[] __initdata = "A3000+";
static char s_a4000[] __initdata = "A4000";
static char s_a4000t[] __initdata = "A4000T";
static char s_cdtv[] __initdata = "CDTV";
static char s_cd32[] __initdata = "CD32";
static char s_draco[] __initdata = "Draco";
static char *amiga_models[] __initdata = {
R
Roman Zippel 已提交
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
	[AMI_500-AMI_500]	= s_a500,
	[AMI_500PLUS-AMI_500]	= s_a500p,
	[AMI_600-AMI_500]	= s_a600,
	[AMI_1000-AMI_500]	= s_a1000,
	[AMI_1200-AMI_500]	= s_a1200,
	[AMI_2000-AMI_500]	= s_a2000,
	[AMI_2500-AMI_500]	= s_a2500,
	[AMI_3000-AMI_500]	= s_a3000,
	[AMI_3000T-AMI_500]	= s_a3000t,
	[AMI_3000PLUS-AMI_500]	= s_a3000p,
	[AMI_4000-AMI_500]	= s_a4000,
	[AMI_4000T-AMI_500]	= s_a4000t,
	[AMI_CDTV-AMI_500]	= s_cdtv,
	[AMI_CD32-AMI_500]	= s_cd32,
	[AMI_DRACO-AMI_500]	= s_draco,
L
Linus Torvalds 已提交
91 92 93 94
};

static char amiga_model_name[13] = "Amiga ";

95
static void amiga_sched_init(irq_handler_t handler);
L
Linus Torvalds 已提交
96
static void amiga_get_model(char *model);
97
static void amiga_get_hardware_list(struct seq_file *m);
L
Linus Torvalds 已提交
98
/* amiga specific timer functions */
R
Roman Zippel 已提交
99 100 101 102 103 104 105
static unsigned long amiga_gettimeoffset(void);
static int a3000_hwclk(int, struct rtc_time *);
static int a2000_hwclk(int, struct rtc_time *);
static int amiga_set_clock_mmss(unsigned long);
static unsigned int amiga_get_ss(void);
extern void amiga_mksound(unsigned int count, unsigned int ticks);
static void amiga_reset(void);
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113
extern void amiga_init_sound(void);
static void amiga_mem_console_write(struct console *co, const char *b,
				    unsigned int count);
#ifdef CONFIG_HEARTBEAT
static void amiga_heartbeat(int on);
#endif

static struct console amiga_console_driver = {
R
Roman Zippel 已提交
114 115 116
	.name	= "debug",
	.flags	= CON_PRINTBUFFER,
	.index	= -1,
L
Linus Torvalds 已提交
117 118 119 120 121 122 123 124
};


    /*
     *  Motherboard Resources present in all Amiga models
     */

static struct {
R
Roman Zippel 已提交
125
	struct resource _ciab, _ciaa, _custom, _kickstart;
L
Linus Torvalds 已提交
126
} mb_resources = {
R
Roman Zippel 已提交
127 128 129 130 131 132 133 134 135 136 137 138
	._ciab = {
		.name = "CIA B", .start = 0x00bfd000, .end = 0x00bfdfff
	},
	._ciaa = {
		.name = "CIA A", .start = 0x00bfe000, .end = 0x00bfefff
	},
	._custom = {
		.name = "Custom I/O", .start = 0x00dff000, .end = 0x00dfffff
	},
	._kickstart = {
		.name = "Kickstart ROM", .start = 0x00f80000, .end = 0x00ffffff
	}
L
Linus Torvalds 已提交
139 140 141
};

static struct resource rtc_resource = {
R
Roman Zippel 已提交
142
	.start = 0x00dc0000, .end = 0x00dcffff
L
Linus Torvalds 已提交
143 144 145 146 147 148 149 150 151 152 153
};

static struct resource ram_resource[NUM_MEMINFO];


    /*
     *  Parse an Amiga-specific record in the bootinfo
     */

int amiga_parse_bootinfo(const struct bi_record *record)
{
R
Roman Zippel 已提交
154 155
	int unknown = 0;
	const unsigned long *data = record->data;
L
Linus Torvalds 已提交
156

R
Roman Zippel 已提交
157
	switch (record->tag) {
L
Linus Torvalds 已提交
158
	case BI_AMIGA_MODEL:
R
Roman Zippel 已提交
159 160
		amiga_model = *data;
		break;
L
Linus Torvalds 已提交
161 162

	case BI_AMIGA_ECLOCK:
R
Roman Zippel 已提交
163 164
		amiga_eclock = *data;
		break;
L
Linus Torvalds 已提交
165 166

	case BI_AMIGA_CHIPSET:
R
Roman Zippel 已提交
167 168
		amiga_chipset = *data;
		break;
L
Linus Torvalds 已提交
169 170

	case BI_AMIGA_CHIP_SIZE:
R
Roman Zippel 已提交
171 172
		amiga_chip_size = *(const int *)data;
		break;
L
Linus Torvalds 已提交
173 174

	case BI_AMIGA_VBLANK:
R
Roman Zippel 已提交
175 176
		amiga_vblank = *(const unsigned char *)data;
		break;
L
Linus Torvalds 已提交
177 178

	case BI_AMIGA_PSFREQ:
R
Roman Zippel 已提交
179 180
		amiga_psfreq = *(const unsigned char *)data;
		break;
L
Linus Torvalds 已提交
181 182 183

	case BI_AMIGA_AUTOCON:
#ifdef CONFIG_ZORRO
R
Roman Zippel 已提交
184 185 186 187 188 189 190 191 192 193
		if (zorro_num_autocon < ZORRO_NUM_AUTO) {
			const struct ConfigDev *cd = (struct ConfigDev *)data;
			struct zorro_dev *dev = &zorro_autocon[zorro_num_autocon++];
			dev->rom = cd->cd_Rom;
			dev->slotaddr = cd->cd_SlotAddr;
			dev->slotsize = cd->cd_SlotSize;
			dev->resource.start = (unsigned long)cd->cd_BoardAddr;
			dev->resource.end = dev->resource.start + cd->cd_BoardSize - 1;
		} else
			printk("amiga_parse_bootinfo: too many AutoConfig devices\n");
L
Linus Torvalds 已提交
194
#endif /* CONFIG_ZORRO */
R
Roman Zippel 已提交
195
		break;
L
Linus Torvalds 已提交
196 197

	case BI_AMIGA_SERPER:
R
Roman Zippel 已提交
198 199
		/* serial port period: ignored here */
		break;
L
Linus Torvalds 已提交
200 201

	default:
R
Roman Zippel 已提交
202 203 204
		unknown = 1;
	}
	return unknown;
L
Linus Torvalds 已提交
205 206 207 208 209 210 211 212
}

    /*
     *  Identify builtin hardware
     */

static void __init amiga_identify(void)
{
R
Roman Zippel 已提交
213 214 215
	/* Fill in some default values, if necessary */
	if (amiga_eclock == 0)
		amiga_eclock = 709379;
L
Linus Torvalds 已提交
216

R
Roman Zippel 已提交
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
	memset(&amiga_hw_present, 0, sizeof(amiga_hw_present));

	printk("Amiga hardware found: ");
	if (amiga_model >= AMI_500 && amiga_model <= AMI_DRACO) {
		printk("[%s] ", amiga_models[amiga_model-AMI_500]);
		strcat(amiga_model_name, amiga_models[amiga_model-AMI_500]);
	}

	switch (amiga_model) {
	case AMI_UNKNOWN:
		goto Generic;

	case AMI_600:
	case AMI_1200:
		AMIGAHW_SET(A1200_IDE);
		AMIGAHW_SET(PCMCIA);
	case AMI_500:
	case AMI_500PLUS:
	case AMI_1000:
	case AMI_2000:
	case AMI_2500:
		AMIGAHW_SET(A2000_CLK);	/* Is this correct for all models? */
		goto Generic;

	case AMI_3000:
	case AMI_3000T:
		AMIGAHW_SET(AMBER_FF);
		AMIGAHW_SET(MAGIC_REKICK);
		/* fall through */
	case AMI_3000PLUS:
		AMIGAHW_SET(A3000_SCSI);
		AMIGAHW_SET(A3000_CLK);
		AMIGAHW_SET(ZORRO3);
		goto Generic;

	case AMI_4000T:
		AMIGAHW_SET(A4000_SCSI);
		/* fall through */
	case AMI_4000:
		AMIGAHW_SET(A4000_IDE);
		AMIGAHW_SET(A3000_CLK);
		AMIGAHW_SET(ZORRO3);
		goto Generic;

	case AMI_CDTV:
	case AMI_CD32:
		AMIGAHW_SET(CD_ROM);
		AMIGAHW_SET(A2000_CLK);             /* Is this correct? */
		goto Generic;

	Generic:
		AMIGAHW_SET(AMI_VIDEO);
		AMIGAHW_SET(AMI_BLITTER);
		AMIGAHW_SET(AMI_AUDIO);
		AMIGAHW_SET(AMI_FLOPPY);
		AMIGAHW_SET(AMI_KEYBOARD);
		AMIGAHW_SET(AMI_MOUSE);
		AMIGAHW_SET(AMI_SERIAL);
		AMIGAHW_SET(AMI_PARALLEL);
		AMIGAHW_SET(CHIP_RAM);
		AMIGAHW_SET(PAULA);

		switch (amiga_chipset) {
		case CS_OCS:
		case CS_ECS:
		case CS_AGA:
			switch (amiga_custom.deniseid & 0xf) {
			case 0x0c:
				AMIGAHW_SET(DENISE_HR);
				break;
			case 0x08:
				AMIGAHW_SET(LISA);
				break;
			}
			break;
		default:
			AMIGAHW_SET(DENISE);
			break;
		}
		switch ((amiga_custom.vposr>>8) & 0x7f) {
		case 0x00:
			AMIGAHW_SET(AGNUS_PAL);
			break;
		case 0x10:
			AMIGAHW_SET(AGNUS_NTSC);
			break;
		case 0x20:
		case 0x21:
			AMIGAHW_SET(AGNUS_HR_PAL);
			break;
		case 0x30:
		case 0x31:
			AMIGAHW_SET(AGNUS_HR_NTSC);
			break;
		case 0x22:
		case 0x23:
			AMIGAHW_SET(ALICE_PAL);
			break;
		case 0x32:
		case 0x33:
			AMIGAHW_SET(ALICE_NTSC);
			break;
		}
		AMIGAHW_SET(ZORRO);
		break;

	case AMI_DRACO:
		panic("No support for Draco yet");

	default:
		panic("Unknown Amiga Model");
	}

#define AMIGAHW_ANNOUNCE(name, str)		\
	if (AMIGAHW_PRESENT(name))		\
		printk(str)

	AMIGAHW_ANNOUNCE(AMI_VIDEO, "VIDEO ");
	AMIGAHW_ANNOUNCE(AMI_BLITTER, "BLITTER ");
	AMIGAHW_ANNOUNCE(AMBER_FF, "AMBER_FF ");
	AMIGAHW_ANNOUNCE(AMI_AUDIO, "AUDIO ");
	AMIGAHW_ANNOUNCE(AMI_FLOPPY, "FLOPPY ");
	AMIGAHW_ANNOUNCE(A3000_SCSI, "A3000_SCSI ");
	AMIGAHW_ANNOUNCE(A4000_SCSI, "A4000_SCSI ");
	AMIGAHW_ANNOUNCE(A1200_IDE, "A1200_IDE ");
	AMIGAHW_ANNOUNCE(A4000_IDE, "A4000_IDE ");
	AMIGAHW_ANNOUNCE(CD_ROM, "CD_ROM ");
	AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "KEYBOARD ");
	AMIGAHW_ANNOUNCE(AMI_MOUSE, "MOUSE ");
	AMIGAHW_ANNOUNCE(AMI_SERIAL, "SERIAL ");
	AMIGAHW_ANNOUNCE(AMI_PARALLEL, "PARALLEL ");
	AMIGAHW_ANNOUNCE(A2000_CLK, "A2000_CLK ");
	AMIGAHW_ANNOUNCE(A3000_CLK, "A3000_CLK ");
	AMIGAHW_ANNOUNCE(CHIP_RAM, "CHIP_RAM ");
	AMIGAHW_ANNOUNCE(PAULA, "PAULA ");
	AMIGAHW_ANNOUNCE(DENISE, "DENISE ");
	AMIGAHW_ANNOUNCE(DENISE_HR, "DENISE_HR ");
	AMIGAHW_ANNOUNCE(LISA, "LISA ");
	AMIGAHW_ANNOUNCE(AGNUS_PAL, "AGNUS_PAL ");
	AMIGAHW_ANNOUNCE(AGNUS_NTSC, "AGNUS_NTSC ");
	AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "AGNUS_HR_PAL ");
	AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "AGNUS_HR_NTSC ");
	AMIGAHW_ANNOUNCE(ALICE_PAL, "ALICE_PAL ");
	AMIGAHW_ANNOUNCE(ALICE_NTSC, "ALICE_NTSC ");
	AMIGAHW_ANNOUNCE(MAGIC_REKICK, "MAGIC_REKICK ");
	AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA ");
	if (AMIGAHW_PRESENT(ZORRO))
		printk("ZORRO%s ", AMIGAHW_PRESENT(ZORRO3) ? "3" : "");
	printk("\n");
L
Linus Torvalds 已提交
366 367 368 369 370 371 372 373 374 375

#undef AMIGAHW_ANNOUNCE
}

    /*
     *  Setup the Amiga configuration info
     */

void __init config_amiga(void)
{
R
Roman Zippel 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
	int i;

	amiga_identify();

	/* Yuk, we don't have PCI memory */
	iomem_resource.name = "Memory";
	for (i = 0; i < 4; i++)
		request_resource(&iomem_resource, &((struct resource *)&mb_resources)[i]);

	mach_sched_init      = amiga_sched_init;
	mach_init_IRQ        = amiga_init_IRQ;
	mach_get_model       = amiga_get_model;
	mach_get_hardware_list = amiga_get_hardware_list;
	mach_gettimeoffset   = amiga_gettimeoffset;
	if (AMIGAHW_PRESENT(A3000_CLK)) {
		mach_hwclk         = a3000_hwclk;
		rtc_resource.name = "A3000 RTC";
		request_resource(&iomem_resource, &rtc_resource);
	} else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
		mach_hwclk         = a2000_hwclk;
		rtc_resource.name = "A2000 RTC";
		request_resource(&iomem_resource, &rtc_resource);
	}

	/*
	 * default MAX_DMA=0xffffffff on all machines. If we don't do so, the SCSI
	 * code will not be able to allocate any mem for transfers, unless we are
	 * dealing with a Z2 mem only system.                  /Jes
	 */
	mach_max_dma_address = 0xffffffff;

	mach_set_clock_mmss  = amiga_set_clock_mmss;
	mach_get_ss          = amiga_get_ss;
	mach_reset           = amiga_reset;
L
Linus Torvalds 已提交
410
#if defined(CONFIG_INPUT_M68K_BEEP) || defined(CONFIG_INPUT_M68K_BEEP_MODULE)
R
Roman Zippel 已提交
411
	mach_beep            = amiga_mksound;
L
Linus Torvalds 已提交
412 413 414
#endif

#ifdef CONFIG_HEARTBEAT
R
Roman Zippel 已提交
415
	mach_heartbeat = amiga_heartbeat;
L
Linus Torvalds 已提交
416 417
#endif

A
Adrian Bunk 已提交
418
	/* Fill in the clock value (based on the 700 kHz E-Clock) */
R
Roman Zippel 已提交
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473
	amiga_colorclock = 5*amiga_eclock;	/* 3.5 MHz */

	/* clear all DMA bits */
	amiga_custom.dmacon = DMAF_ALL;
	/* ensure that the DMA master bit is set */
	amiga_custom.dmacon = DMAF_SETCLR | DMAF_MASTER;

	/* don't use Z2 RAM as system memory on Z3 capable machines */
	if (AMIGAHW_PRESENT(ZORRO3)) {
		int i, j;
		u32 disabled_z2mem = 0;

		for (i = 0; i < m68k_num_memory; i++) {
			if (m68k_memory[i].addr < 16*1024*1024) {
				if (i == 0) {
					/* don't cut off the branch we're sitting on */
					printk("Warning: kernel runs in Zorro II memory\n");
					continue;
				}
				disabled_z2mem += m68k_memory[i].size;
				m68k_num_memory--;
				for (j = i; j < m68k_num_memory; j++)
					m68k_memory[j] = m68k_memory[j+1];
				i--;
			}
		}
		if (disabled_z2mem)
		printk("%dK of Zorro II memory will not be used as system memory\n",
		disabled_z2mem>>10);
	}

	/* request all RAM */
	for (i = 0; i < m68k_num_memory; i++) {
		ram_resource[i].name =
			(m68k_memory[i].addr >= 0x01000000) ? "32-bit Fast RAM" :
			(m68k_memory[i].addr < 0x00c00000) ? "16-bit Fast RAM" :
			"16-bit Slow RAM";
		ram_resource[i].start = m68k_memory[i].addr;
		ram_resource[i].end = m68k_memory[i].addr+m68k_memory[i].size-1;
		request_resource(&iomem_resource, &ram_resource[i]);
	}

	/* initialize chipram allocator */
	amiga_chip_init();

	/* our beloved beeper */
	if (AMIGAHW_PRESENT(AMI_AUDIO))
		amiga_init_sound();

	/*
	 * if it is an A3000, set the magic bit that forces
	 * a hard rekick
	 */
	if (AMIGAHW_PRESENT(MAGIC_REKICK))
		*(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
L
Linus Torvalds 已提交
474 475 476 477
}

static unsigned short jiffy_ticks;

478
static void __init amiga_sched_init(irq_handler_t timer_routine)
L
Linus Torvalds 已提交
479 480
{
	static struct resource sched_res = {
R
Roman Zippel 已提交
481
		.name = "timer", .start = 0x00bfd400, .end = 0x00bfd5ff,
L
Linus Torvalds 已提交
482 483 484 485
	};
	jiffy_ticks = (amiga_eclock+HZ/2)/HZ;

	if (request_resource(&mb_resources._ciab, &sched_res))
R
Roman Zippel 已提交
486
		printk("Cannot allocate ciab.ta{lo,hi}\n");
L
Linus Torvalds 已提交
487 488 489 490 491 492 493 494 495
	ciab.cra &= 0xC0;   /* turn off timer A, continuous mode, from Eclk */
	ciab.talo = jiffy_ticks % 256;
	ciab.tahi = jiffy_ticks / 256;

	/* install interrupt service routine for CIAB Timer A
	 *
	 * Please don't change this to use ciaa, as it interferes with the
	 * SCSI code. We'll have to take a look at this later
	 */
496 497
	if (request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, 0, "timer", NULL))
		pr_err("Couldn't register timer interrupt\n");
L
Linus Torvalds 已提交
498 499 500 501 502 503 504
	/* start timer */
	ciab.cra |= 0x11;
}

#define TICK_SIZE 10000

/* This is always executed with interrupts disabled.  */
R
Roman Zippel 已提交
505
static unsigned long amiga_gettimeoffset(void)
L
Linus Torvalds 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
{
	unsigned short hi, lo, hi2;
	unsigned long ticks, offset = 0;

	/* read CIA B timer A current value */
	hi  = ciab.tahi;
	lo  = ciab.talo;
	hi2 = ciab.tahi;

	if (hi != hi2) {
		lo = ciab.talo;
		hi = hi2;
	}

	ticks = hi << 8 | lo;

	if (ticks > jiffy_ticks / 2)
		/* check for pending interrupt */
		if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
			offset = 10000;

	ticks = jiffy_ticks - ticks;
	ticks = (10000 * ticks) / jiffy_ticks;

	return ticks + offset;
}

static int a3000_hwclk(int op, struct rtc_time *t)
{
	tod_3000.cntrl1 = TOD3000_CNTRL1_HOLD;

	if (!op) { /* read */
		t->tm_sec  = tod_3000.second1 * 10 + tod_3000.second2;
		t->tm_min  = tod_3000.minute1 * 10 + tod_3000.minute2;
		t->tm_hour = tod_3000.hour1   * 10 + tod_3000.hour2;
		t->tm_mday = tod_3000.day1    * 10 + tod_3000.day2;
		t->tm_wday = tod_3000.weekday;
		t->tm_mon  = tod_3000.month1  * 10 + tod_3000.month2 - 1;
		t->tm_year = tod_3000.year1   * 10 + tod_3000.year2;
		if (t->tm_year <= 69)
			t->tm_year += 100;
	} else {
		tod_3000.second1 = t->tm_sec / 10;
		tod_3000.second2 = t->tm_sec % 10;
		tod_3000.minute1 = t->tm_min / 10;
		tod_3000.minute2 = t->tm_min % 10;
		tod_3000.hour1   = t->tm_hour / 10;
		tod_3000.hour2   = t->tm_hour % 10;
		tod_3000.day1    = t->tm_mday / 10;
		tod_3000.day2    = t->tm_mday % 10;
		if (t->tm_wday != -1)
			tod_3000.weekday = t->tm_wday;
		tod_3000.month1  = (t->tm_mon + 1) / 10;
		tod_3000.month2  = (t->tm_mon + 1) % 10;
		if (t->tm_year >= 100)
			t->tm_year -= 100;
		tod_3000.year1   = t->tm_year / 10;
		tod_3000.year2   = t->tm_year % 10;
	}

	tod_3000.cntrl1 = TOD3000_CNTRL1_FREE;

	return 0;
}

static int a2000_hwclk(int op, struct rtc_time *t)
{
	int cnt = 5;

	tod_2000.cntrl1 = TOD2000_CNTRL1_HOLD;

R
Roel Kluin 已提交
577
	while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt) {
R
Roman Zippel 已提交
578 579 580
		tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;
		udelay(70);
		tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
R
Roel Kluin 已提交
581
		--cnt;
L
Linus Torvalds 已提交
582 583 584
	}

	if (!cnt)
R
Roman Zippel 已提交
585 586
		printk(KERN_INFO "hwclk: timed out waiting for RTC (0x%x)\n",
			tod_2000.cntrl1);
L
Linus Torvalds 已提交
587 588 589 590 591 592 593 594 595 596 597 598

	if (!op) { /* read */
		t->tm_sec  = tod_2000.second1     * 10 + tod_2000.second2;
		t->tm_min  = tod_2000.minute1     * 10 + tod_2000.minute2;
		t->tm_hour = (tod_2000.hour1 & 3) * 10 + tod_2000.hour2;
		t->tm_mday = tod_2000.day1        * 10 + tod_2000.day2;
		t->tm_wday = tod_2000.weekday;
		t->tm_mon  = tod_2000.month1      * 10 + tod_2000.month2 - 1;
		t->tm_year = tod_2000.year1       * 10 + tod_2000.year2;
		if (t->tm_year <= 69)
			t->tm_year += 100;

R
Roman Zippel 已提交
599
		if (!(tod_2000.cntrl3 & TOD2000_CNTRL3_24HMODE)) {
L
Linus Torvalds 已提交
600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
			if (!(tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour == 12)
				t->tm_hour = 0;
			else if ((tod_2000.hour1 & TOD2000_HOUR1_PM) && t->tm_hour != 12)
				t->tm_hour += 12;
		}
	} else {
		tod_2000.second1 = t->tm_sec / 10;
		tod_2000.second2 = t->tm_sec % 10;
		tod_2000.minute1 = t->tm_min / 10;
		tod_2000.minute2 = t->tm_min % 10;
		if (tod_2000.cntrl3 & TOD2000_CNTRL3_24HMODE)
			tod_2000.hour1 = t->tm_hour / 10;
		else if (t->tm_hour >= 12)
			tod_2000.hour1 = TOD2000_HOUR1_PM +
				(t->tm_hour - 12) / 10;
		else
			tod_2000.hour1 = t->tm_hour / 10;
		tod_2000.hour2   = t->tm_hour % 10;
		tod_2000.day1    = t->tm_mday / 10;
		tod_2000.day2    = t->tm_mday % 10;
		if (t->tm_wday != -1)
			tod_2000.weekday = t->tm_wday;
		tod_2000.month1  = (t->tm_mon + 1) / 10;
		tod_2000.month2  = (t->tm_mon + 1) % 10;
		if (t->tm_year >= 100)
			t->tm_year -= 100;
		tod_2000.year1   = t->tm_year / 10;
		tod_2000.year2   = t->tm_year % 10;
	}

	tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;

	return 0;
}

R
Roman Zippel 已提交
635
static int amiga_set_clock_mmss(unsigned long nowtime)
L
Linus Torvalds 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652
{
	short real_seconds = nowtime % 60, real_minutes = (nowtime / 60) % 60;

	if (AMIGAHW_PRESENT(A3000_CLK)) {
		tod_3000.cntrl1 = TOD3000_CNTRL1_HOLD;

		tod_3000.second1 = real_seconds / 10;
		tod_3000.second2 = real_seconds % 10;
		tod_3000.minute1 = real_minutes / 10;
		tod_3000.minute2 = real_minutes % 10;

		tod_3000.cntrl1 = TOD3000_CNTRL1_FREE;
	} else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
		int cnt = 5;

		tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;

R
Roel Kluin 已提交
653
		while ((tod_2000.cntrl1 & TOD2000_CNTRL1_BUSY) && cnt) {
L
Linus Torvalds 已提交
654 655 656
			tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;
			udelay(70);
			tod_2000.cntrl1 |= TOD2000_CNTRL1_HOLD;
R
Roel Kluin 已提交
657
			--cnt;
L
Linus Torvalds 已提交
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673
		}

		if (!cnt)
			printk(KERN_INFO "set_clock_mmss: timed out waiting for RTC (0x%x)\n", tod_2000.cntrl1);

		tod_2000.second1 = real_seconds / 10;
		tod_2000.second2 = real_seconds % 10;
		tod_2000.minute1 = real_minutes / 10;
		tod_2000.minute2 = real_minutes % 10;

		tod_2000.cntrl1 &= ~TOD2000_CNTRL1_HOLD;
	}

	return 0;
}

R
Roman Zippel 已提交
674
static unsigned int amiga_get_ss(void)
L
Linus Torvalds 已提交
675 676 677 678 679 680 681 682 683 684 685 686 687
{
	unsigned int s;

	if (AMIGAHW_PRESENT(A3000_CLK)) {
		tod_3000.cntrl1 = TOD3000_CNTRL1_HOLD;
		s = tod_3000.second1 * 10 + tod_3000.second2;
		tod_3000.cntrl1 = TOD3000_CNTRL1_FREE;
	} else /* if (AMIGAHW_PRESENT(A2000_CLK)) */ {
		s = tod_2000.second1 * 10 + tod_2000.second2;
	}
	return s;
}

R
Roman Zippel 已提交
688
static NORET_TYPE void amiga_reset(void)
L
Linus Torvalds 已提交
689 690
    ATTRIB_NORET;

R
Roman Zippel 已提交
691
static void amiga_reset(void)
L
Linus Torvalds 已提交
692
{
R
Roman Zippel 已提交
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
	unsigned long jmp_addr040 = virt_to_phys(&&jmp_addr_label040);
	unsigned long jmp_addr = virt_to_phys(&&jmp_addr_label);

	local_irq_disable();
	if (CPU_IS_040_OR_060)
		/* Setup transparent translation registers for mapping
		 * of 16 MB kernel segment before disabling translation
		 */
		asm volatile ("\n"
			"	move.l	%0,%%d0\n"
			"	and.l	#0xff000000,%%d0\n"
			"	or.w	#0xe020,%%d0\n"   /* map 16 MB, enable, cacheable */
			"	.chip	68040\n"
			"	movec	%%d0,%%itt0\n"
			"	movec	%%d0,%%dtt0\n"
			"	.chip	68k\n"
			"	jmp	%0@\n"
			: /* no outputs */
			: "a" (jmp_addr040)
			: "d0");
	else
		/* for 680[23]0, just disable translation and jump to the physical
		 * address of the label
		 */
		asm volatile ("\n"
			"	pmove	%%tc,%@\n"
			"	bclr	#7,%@\n"
			"	pmove	%@,%%tc\n"
			"	jmp	%0@\n"
			: /* no outputs */
			: "a" (jmp_addr));
jmp_addr_label040:
	/* disable translation on '040 now */
	asm volatile ("\n"
		"	moveq	#0,%%d0\n"
		"	.chip	68040\n"
		"	movec	%%d0,%%tc\n"	/* disable MMU */
		"	.chip	68k\n"
		: /* no outputs */
		: /* no inputs */
		: "d0");

	jmp_addr_label:
	/* pickup reset address from AmigaOS ROM, reset devices and jump
	 * to reset address
	 */
	asm volatile ("\n"
		"	move.w	#0x2700,%sr\n"
		"	lea	0x01000000,%a0\n"
		"	sub.l	%a0@(-0x14),%a0\n"
		"	move.l	%a0@(4),%a0\n"
		"	subq.l	#2,%a0\n"
		"	jra	1f\n"
		/* align on a longword boundary */
		"	" __ALIGN_STR "\n"
		"1:\n"
		"	reset\n"
		"	jmp   %a0@");

	for (;;)
		;
L
Linus Torvalds 已提交
754 755 756 757 758 759 760 761 762 763 764 765 766
}


    /*
     *  Debugging
     */

#define SAVEKMSG_MAXMEM		128*1024

#define SAVEKMSG_MAGIC1		0x53415645	/* 'SAVE' */
#define SAVEKMSG_MAGIC2		0x4B4D5347	/* 'KMSG' */

struct savekmsg {
R
Roman Zippel 已提交
767 768 769 770 771
	unsigned long magic1;		/* SAVEKMSG_MAGIC1 */
	unsigned long magic2;		/* SAVEKMSG_MAGIC2 */
	unsigned long magicptr;		/* address of magic1 */
	unsigned long size;
	char data[0];
L
Linus Torvalds 已提交
772 773 774 775 776 777 778
};

static struct savekmsg *savekmsg;

static void amiga_mem_console_write(struct console *co, const char *s,
				    unsigned int count)
{
R
Roman Zippel 已提交
779 780 781 782
	if (savekmsg->size + count <= SAVEKMSG_MAXMEM-sizeof(struct savekmsg)) {
		memcpy(savekmsg->data + savekmsg->size, s, count);
		savekmsg->size += count;
	}
L
Linus Torvalds 已提交
783 784
}

R
Roman Zippel 已提交
785
static int __init amiga_savekmsg_setup(char *arg)
L
Linus Torvalds 已提交
786
{
R
Roman Zippel 已提交
787
	static struct resource debug_res = { .name = "Debug" };
L
Linus Torvalds 已提交
788

R
Roman Zippel 已提交
789 790 791 792 793 794 795 796
	if (!MACH_IS_AMIGA || strcmp(arg, "mem"))
		goto done;

	if (!AMIGAHW_PRESENT(CHIP_RAM)) {
		printk("Warning: no chipram present for debugging\n");
		goto done;
	}

R
Roman Zippel 已提交
797 798 799 800 801
	savekmsg = amiga_chip_alloc_res(SAVEKMSG_MAXMEM, &debug_res);
	savekmsg->magic1 = SAVEKMSG_MAGIC1;
	savekmsg->magic2 = SAVEKMSG_MAGIC2;
	savekmsg->magicptr = ZTWO_PADDR(savekmsg);
	savekmsg->size = 0;
R
Roman Zippel 已提交
802 803 804 805 806 807

	amiga_console_driver.write = amiga_mem_console_write;
	register_console(&amiga_console_driver);

done:
	return 0;
L
Linus Torvalds 已提交
808 809
}

R
Roman Zippel 已提交
810 811
early_param("debug", amiga_savekmsg_setup);

L
Linus Torvalds 已提交
812 813
static void amiga_serial_putc(char c)
{
R
Roman Zippel 已提交
814 815 816
	amiga_custom.serdat = (unsigned char)c | 0x100;
	while (!(amiga_custom.serdatr & 0x2000))
		;
L
Linus Torvalds 已提交
817 818
}

A
Adrian Bunk 已提交
819 820
static void amiga_serial_console_write(struct console *co, const char *s,
				       unsigned int count)
L
Linus Torvalds 已提交
821
{
R
Roman Zippel 已提交
822 823 824 825 826
	while (count--) {
		if (*s == '\n')
			amiga_serial_putc('\r');
		amiga_serial_putc(*s++);
	}
L
Linus Torvalds 已提交
827 828
}

A
Adrian Bunk 已提交
829
#if 0
L
Linus Torvalds 已提交
830 831
void amiga_serial_puts(const char *s)
{
R
Roman Zippel 已提交
832
	amiga_serial_console_write(NULL, s, strlen(s));
L
Linus Torvalds 已提交
833 834 835 836
}

int amiga_serial_console_wait_key(struct console *co)
{
R
Roman Zippel 已提交
837 838 839 840 841 842 843 844
	int ch;

	while (!(amiga_custom.intreqr & IF_RBF))
		barrier();
	ch = amiga_custom.serdatr & 0xff;
	/* clear the interrupt, so that another character can be read */
	amiga_custom.intreq = IF_RBF;
	return ch;
L
Linus Torvalds 已提交
845 846 847 848
}

void amiga_serial_gets(struct console *co, char *s, int len)
{
R
Roman Zippel 已提交
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
	int ch, cnt = 0;

	while (1) {
		ch = amiga_serial_console_wait_key(co);

		/* Check for backspace. */
		if (ch == 8 || ch == 127) {
			if (cnt == 0) {
				amiga_serial_putc('\007');
				continue;
			}
			cnt--;
			amiga_serial_puts("\010 \010");
			continue;
		}
L
Linus Torvalds 已提交
864

R
Roman Zippel 已提交
865 866 867
		/* Check for enter. */
		if (ch == 10 || ch == 13)
			break;
L
Linus Torvalds 已提交
868

R
Roman Zippel 已提交
869 870 871 872 873 874
		/* See if line is too long. */
		if (cnt >= len + 1) {
			amiga_serial_putc(7);
			cnt--;
			continue;
		}
L
Linus Torvalds 已提交
875

R
Roman Zippel 已提交
876 877 878 879 880 881 882
		/* Store and echo character. */
		s[cnt++] = ch;
		amiga_serial_putc(ch);
	}
	/* Print enter. */
	amiga_serial_puts("\r\n");
	s[cnt] = 0;
L
Linus Torvalds 已提交
883 884 885
}
#endif

R
Roman Zippel 已提交
886
static int __init amiga_debug_setup(char *arg)
L
Linus Torvalds 已提交
887
{
R
Roman Zippel 已提交
888
	if (MACH_IS_AMIGA && !strcmp(arg, "ser")) {
L
Linus Torvalds 已提交
889 890 891 892
		/* no initialization required (?) */
		amiga_console_driver.write = amiga_serial_console_write;
		register_console(&amiga_console_driver);
	}
R
Roman Zippel 已提交
893
	return 0;
L
Linus Torvalds 已提交
894 895
}

R
Roman Zippel 已提交
896 897
early_param("debug", amiga_debug_setup);

L
Linus Torvalds 已提交
898 899 900
#ifdef CONFIG_HEARTBEAT
static void amiga_heartbeat(int on)
{
R
Roman Zippel 已提交
901 902 903 904
	if (on)
		ciaa.pra &= ~2;
	else
		ciaa.pra |= 2;
L
Linus Torvalds 已提交
905 906 907 908 909 910 911 912 913
}
#endif

    /*
     *  Amiga specific parts of /proc
     */

static void amiga_get_model(char *model)
{
R
Roman Zippel 已提交
914
	strcpy(model, amiga_model_name);
L
Linus Torvalds 已提交
915 916 917
}


918
static void amiga_get_hardware_list(struct seq_file *m)
L
Linus Torvalds 已提交
919
{
R
Roman Zippel 已提交
920
	if (AMIGAHW_PRESENT(CHIP_RAM))
921 922
		seq_printf(m, "Chip RAM:\t%ldK\n", amiga_chip_size>>10);
	seq_printf(m, "PS Freq:\t%dHz\nEClock Freq:\t%ldHz\n",
R
Roman Zippel 已提交
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
			amiga_psfreq, amiga_eclock);
	if (AMIGAHW_PRESENT(AMI_VIDEO)) {
		char *type;
		switch (amiga_chipset) {
		case CS_OCS:
			type = "OCS";
			break;
		case CS_ECS:
			type = "ECS";
			break;
		case CS_AGA:
			type = "AGA";
			break;
		default:
			type = "Old or Unknown";
			break;
		}
940
		seq_printf(m, "Graphics:\t%s\n", type);
L
Linus Torvalds 已提交
941 942 943
	}

#define AMIGAHW_ANNOUNCE(name, str)			\
R
Roman Zippel 已提交
944
	if (AMIGAHW_PRESENT(name))			\
945
		seq_printf (m, "\t%s\n", str)
R
Roman Zippel 已提交
946

947
	seq_printf (m, "Detected hardware:\n");
R
Roman Zippel 已提交
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977

	AMIGAHW_ANNOUNCE(AMI_VIDEO, "Amiga Video");
	AMIGAHW_ANNOUNCE(AMI_BLITTER, "Blitter");
	AMIGAHW_ANNOUNCE(AMBER_FF, "Amber Flicker Fixer");
	AMIGAHW_ANNOUNCE(AMI_AUDIO, "Amiga Audio");
	AMIGAHW_ANNOUNCE(AMI_FLOPPY, "Floppy Controller");
	AMIGAHW_ANNOUNCE(A3000_SCSI, "SCSI Controller WD33C93 (A3000 style)");
	AMIGAHW_ANNOUNCE(A4000_SCSI, "SCSI Controller NCR53C710 (A4000T style)");
	AMIGAHW_ANNOUNCE(A1200_IDE, "IDE Interface (A1200 style)");
	AMIGAHW_ANNOUNCE(A4000_IDE, "IDE Interface (A4000 style)");
	AMIGAHW_ANNOUNCE(CD_ROM, "Internal CD ROM drive");
	AMIGAHW_ANNOUNCE(AMI_KEYBOARD, "Keyboard");
	AMIGAHW_ANNOUNCE(AMI_MOUSE, "Mouse Port");
	AMIGAHW_ANNOUNCE(AMI_SERIAL, "Serial Port");
	AMIGAHW_ANNOUNCE(AMI_PARALLEL, "Parallel Port");
	AMIGAHW_ANNOUNCE(A2000_CLK, "Hardware Clock (A2000 style)");
	AMIGAHW_ANNOUNCE(A3000_CLK, "Hardware Clock (A3000 style)");
	AMIGAHW_ANNOUNCE(CHIP_RAM, "Chip RAM");
	AMIGAHW_ANNOUNCE(PAULA, "Paula 8364");
	AMIGAHW_ANNOUNCE(DENISE, "Denise 8362");
	AMIGAHW_ANNOUNCE(DENISE_HR, "Denise 8373");
	AMIGAHW_ANNOUNCE(LISA, "Lisa 8375");
	AMIGAHW_ANNOUNCE(AGNUS_PAL, "Normal/Fat PAL Agnus 8367/8371");
	AMIGAHW_ANNOUNCE(AGNUS_NTSC, "Normal/Fat NTSC Agnus 8361/8370");
	AMIGAHW_ANNOUNCE(AGNUS_HR_PAL, "Fat Hires PAL Agnus 8372");
	AMIGAHW_ANNOUNCE(AGNUS_HR_NTSC, "Fat Hires NTSC Agnus 8372");
	AMIGAHW_ANNOUNCE(ALICE_PAL, "PAL Alice 8374");
	AMIGAHW_ANNOUNCE(ALICE_NTSC, "NTSC Alice 8374");
	AMIGAHW_ANNOUNCE(MAGIC_REKICK, "Magic Hard Rekick");
	AMIGAHW_ANNOUNCE(PCMCIA, "PCMCIA Slot");
L
Linus Torvalds 已提交
978
#ifdef CONFIG_ZORRO
R
Roman Zippel 已提交
979
	if (AMIGAHW_PRESENT(ZORRO))
980
		seq_printf(m, "\tZorro II%s AutoConfig: %d Expansion "
R
Roman Zippel 已提交
981 982 983
				"Device%s\n",
				AMIGAHW_PRESENT(ZORRO3) ? "I" : "",
				zorro_num_autocon, zorro_num_autocon == 1 ? "" : "s");
L
Linus Torvalds 已提交
984 985 986 987
#endif /* CONFIG_ZORRO */

#undef AMIGAHW_ANNOUNCE
}
988 989 990 991 992 993 994 995

/*
 * The Amiga keyboard driver needs key_maps, but we cannot export it in
 * drivers/char/defkeymap.c, as it is autogenerated
 */
#ifdef CONFIG_HW_CONSOLE
EXPORT_SYMBOL_GPL(key_maps);
#endif