lowlevel_init.S 8.65 KB
Newer Older
1 2 3 4 5
/* Memory sub-system initialization code */

#include <config.h>
#include <asm/regdef.h>
#include <asm/au1x00.h>
wdenk's avatar
wdenk committed
6 7 8 9 10
#include <asm/mipsregs.h>

#define AU1500_SYS_ADDR		0xB1900000
#define sys_endian		0x0038
#define CP0_Config0		$16
11 12
#define CPU_SCALE		((CONFIG_SYS_MHZ) / 12) /* CPU clock is a multiple of 12 MHz */
#define MEM_1MS			((CONFIG_SYS_MHZ) * 1000)
wdenk's avatar
wdenk committed
13 14 15 16

	.text
	.set noreorder
	.set mips32
17

wdenk's avatar
wdenk committed
18 19
	.globl	lowlevel_init
lowlevel_init:
wdenk's avatar
wdenk committed
20 21 22 23 24 25
	/*
	 * Step 1) Establish CPU endian mode.
	 * Db1500-specific:
	 * Switch S1.1 Off(bit7 reads 1) is Little Endian
	 * Switch S1.1 On (bit7 reads 0) is Big Endian
	 */
26 27 28 29 30 31 32 33 34 35 36 37 38
#ifdef CONFIG_DBAU1550
	li	t0, MEM_STCFG2
	li	t1, 0x00000040
	sw	t1, 0(t0)

	li	t0, MEM_STTIME2
	li	t1, 0x22080a20
	sw	t1, 0(t0)

	li	t0, MEM_STADDR2
	li	t1, 0x10c03f00
	sw	t1, 0(t0)
#else
wdenk's avatar
wdenk committed
39 40 41 42 43 44 45 46 47 48 49
	li	t0, MEM_STCFG1
	li	t1, 0x00000080
	sw	t1, 0(t0)

	li	t0, MEM_STTIME1
	li	t1, 0x22080a20
	sw	t1, 0(t0)

	li	t0, MEM_STADDR1
	li	t1, 0x10c03f00
	sw	t1, 0(t0)
50
#endif
wdenk's avatar
wdenk committed
51

52 53
	li	t0, DB1XX0_BCSR_ADDR
	lw	t1,8(t0)
wdenk's avatar
wdenk committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
	andi	t1,t1,0x80
	beq	zero,t1,big_endian
	nop
little_endian:

	/* Change Au1 core to little endian */
	li	t0, AU1500_SYS_ADDR
	li	t1, 1
	sw	t1, sys_endian(t0)
	mfc0	t2, CP0_CONFIG
	mtc0	t2, CP0_CONFIG
	nop
	nop

	/* Big Endian is default so nothing to do but fall through */

big_endian:

	/*
	 * Step 2) Establish Status Register
	 * (set BEV, clear ERL, clear EXL, clear IE)
	 */
	li	t1, 0x00400000
	mtc0	t1, CP0_STATUS

	/*
	 * Step 3) Establish CP0 Config0
	 * (set OD, set K0=3)
	 */
	li	t1, 0x00080003
	mtc0	t1, CP0_CONFIG

	/*
	 * Step 4) Disable Watchpoint facilities
	 */
	li t1, 0x00000000
	mtc0	t1, CP0_WATCHLO
	mtc0	t1, CP0_IWATCHLO
	/*
	 * Step 5) Disable the performance counters
	 */
	mtc0	zero, CP0_PERFORMANCE
	nop

	/*
	 * Step 6) Establish EJTAG Debug register
	 */
	mtc0	zero, CP0_DEBUG
	nop

	/*
	 * Step 7) Establish Cause
	 * (set IV bit)
	 */
	li	t1, 0x00800000
	mtc0	t1, CP0_CAUSE

	/* Establish Wired (and Random) */
	mtc0	zero, CP0_WIRED
	nop

115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
#ifdef CONFIG_DBAU1550
	/* No workaround if running from ram */
	lui	t0, 0xffc0
	lui	t3, 0xbfc0
	and	t1, ra, t0
	bne	t1, t3, noCacheJump
	nop

	/*** From AMD YAMON ***/
	/*
	 * Step 8) Initialize the caches
	 */
	li		t0, (16*1024)
	li		t1, 32
	li		t2, 0x80000000
	addu	t3, t0, t2
cacheloop:
	cache	0, 0(t2)
	cache	1, 0(t2)
	addu	t2, t1
	bne		t2, t3, cacheloop
	nop

	/* Save return address */
	move		t3, ra

	/* Run from cacheable space now */
	bal		cachehere
	nop
cachehere:
	li		t1, ~0x20000000 /* convert to KSEG0 */
	and		t0, ra, t1
	addi	t0, 5*4			/* 5 insns beyond cachehere */
	jr		t0
	nop

	/* Restore return address */
	move		ra, t3

	/*
	 * Step 9) Initialize the TLB
	 */
	li		t0, 0			# index value
	li		t1, 0x00000000		# entryhi value
	li		t2, 32			# 32 entries

tlbloop:
	/* Probe TLB for matching EntryHi */
	mtc0	t1, CP0_ENTRYHI
	tlbp
	nop

	/* Examine Index[P], 1=no matching entry */
	mfc0	t3, CP0_INDEX
	li	t4, 0x80000000
	and	t3, t4, t3
	addiu	t1, t1, 1		# increment t1 (asid)
	beq	zero, t3, tlbloop
	nop

	/* Initialize the TLB entry */
	mtc0	t0, CP0_INDEX
	mtc0	zero, CP0_ENTRYLO0
	mtc0	zero, CP0_ENTRYLO1
	mtc0	zero, CP0_PAGEMASK
	tlbwi

	/* Do it again */
	addiu	t0, t0, 1
	bne	t0, t2, tlbloop
	nop

Heiko Schocher's avatar
Heiko Schocher committed
187 188
#endif /* CONFIG_DBAU1550 */

189 190
	/* First setup pll:s to make serial work ok */
	/* We have a 12 MHz crystal */
wdenk's avatar
wdenk committed
191
	li	t0, SYS_CPUPLL
192
	li	t1, CPU_SCALE  /* CPU clock */
wdenk's avatar
wdenk committed
193
	sw	t1, 0(t0)
194 195
	sync
	nop
wdenk's avatar
wdenk committed
196
	nop
197

wdenk's avatar
wdenk committed
198 199 200 201 202
	/* wait 1mS for clocks to settle */
	li	t1, MEM_1MS
1:	add	t1, -1
	bne	t1, zero, 1b
	nop
203
	/* Setup AUX PLL */
wdenk's avatar
wdenk committed
204 205 206
	li	t0, SYS_AUXPLL
	li	t1, 0x20 /* 96 MHz */
	sw	t1, 0(t0) /* aux pll */
207
	sync
208

Heiko Schocher's avatar
Heiko Schocher committed
209
#ifdef CONFIG_DBAU1550
wdenk's avatar
wdenk committed
210
	/*  Static memory controller */
211 212 213 214
	/* RCE0 - can not change while fetching, do so from icache */
	move		t2, ra /* Store return address */
	bal		getAddr
	nop
215

216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
getAddr:
	move		t1, ra
	move		ra, t2 /* Move return addess back */

	cache	0x14,0(t1)
	cache	0x14,32(t1)
	/*** /From YAMON ***/

noCacheJump:
#endif /* CONFIG_DBAU1550 */

#ifdef CONFIG_DBAU1550
	li	t0, MEM_STTIME0
	li	t1, 0x040181D7
	sw	t1, 0(t0)

	/* RCE0 AMD MirrorBit Flash (?) */
wdenk's avatar
wdenk committed
233
	li	t0, MEM_STCFG0
234
	li	t1, 0x00000003
wdenk's avatar
wdenk committed
235
	sw	t1, 0(t0)
236

237 238 239 240
	li	t0, MEM_STADDR0
	li	t1, 0x11803E00
	sw	t1, 0(t0)
#else /* CONFIG_DBAU1550 */
wdenk's avatar
wdenk committed
241
	li	t0, MEM_STTIME0
Heiko Schocher's avatar
Heiko Schocher committed
242
	li	t1, 0x040181D7
243 244 245 246 247
	sw	t1, 0(t0)

	/* RCE0 AMD 29LV640M MirrorBit Flash */
	li	t0, MEM_STCFG0
	li	t1, 0x00000013
wdenk's avatar
wdenk committed
248
	sw	t1, 0(t0)
249

wdenk's avatar
wdenk committed
250 251 252
	li	t0, MEM_STADDR0
	li	t1, 0x11E03F80
	sw	t1, 0(t0)
253
#endif /* CONFIG_DBAU1550 */
254

wdenk's avatar
wdenk committed
255 256 257 258
	/* RCE1 CPLD Board Logic */
	li	t0, MEM_STCFG1
	li	t1, 0x00000080
	sw	t1, 0(t0)
259

wdenk's avatar
wdenk committed
260 261 262
	li	t0, MEM_STTIME1
	li	t1, 0x22080a20
	sw	t1, 0(t0)
263

wdenk's avatar
wdenk committed
264 265 266 267
	li	t0, MEM_STADDR1
	li	t1, 0x10c03f00
	sw	t1, 0(t0)

268
#ifdef CONFIG_DBAU1550
wdenk's avatar
wdenk committed
269
	/* RCE2 CPLD Board Logic */
270 271 272 273 274 275 276 277 278 279 280 281
	li	t0, MEM_STCFG2
	li	t1, 0x00000040
	sw	t1, 0(t0)

	li	t0, MEM_STTIME2
	li	t1, 0x22080a20
	sw	t1, 0(t0)

	li	t0, MEM_STADDR2
	li	t1, 0x10c03f00
	sw	t1, 0(t0)
#else
wdenk's avatar
wdenk committed
282 283 284 285 286 287 288 289 290 291 292
	li	t0, MEM_STCFG2
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, MEM_STTIME2
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, MEM_STADDR2
	li	t1, 0x00000000
	sw	t1, 0(t0)
293
#endif
wdenk's avatar
wdenk committed
294 295 296 297 298 299 300 301 302 303 304 305 306

	/* RCE3 PCMCIA 250ns */
	li	t0, MEM_STCFG3
	li	t1, 0x00000002
	sw	t1, 0(t0)

	li	t0, MEM_STTIME3
	li	t1, 0x280E3E07
	sw	t1, 0(t0)

	li	t0, MEM_STADDR3
	li	t1, 0x10000000
	sw	t1, 0(t0)
307 308 309

	sync

wdenk's avatar
wdenk committed
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
	/* Set peripherals to a known state */
	li	t0, IC0_CFG0CLR
	li	t1, 0xFFFFFFFF
	sw	t1, 0(t0)

	li	t0, IC0_CFG0CLR
	sw	t1, 0(t0)

	li	t0, IC0_CFG1CLR
	sw	t1, 0(t0)

	li	t0, IC0_CFG2CLR
	sw	t1, 0(t0)

	li	t0, IC0_SRCSET
	sw	t1, 0(t0)

	li	t0, IC0_ASSIGNSET
	sw	t1, 0(t0)

	li	t0, IC0_WAKECLR
	sw	t1, 0(t0)

	li	t0, IC0_RISINGCLR
	sw	t1, 0(t0)

	li	t0, IC0_FALLINGCLR
	sw	t1, 0(t0)

	li	t0, IC0_TESTBIT
	li	t1, 0x00000000
	sw	t1, 0(t0)
342 343
	sync

wdenk's avatar
wdenk committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	li	t0, IC1_CFG0CLR
	li	t1, 0xFFFFFFFF
	sw	t1, 0(t0)

	li	t0, IC1_CFG0CLR
	sw	t1, 0(t0)

	li	t0, IC1_CFG1CLR
	sw	t1, 0(t0)

	li	t0, IC1_CFG2CLR
	sw	t1, 0(t0)

	li	t0, IC1_SRCSET
	sw	t1, 0(t0)

	li	t0, IC1_ASSIGNSET
	sw	t1, 0(t0)

	li	t0, IC1_WAKECLR
	sw	t1, 0(t0)

	li	t0, IC1_RISINGCLR
	sw	t1, 0(t0)

	li	t0, IC1_FALLINGCLR
	sw	t1, 0(t0)

	li	t0, IC1_TESTBIT
	li	t1, 0x00000000
	sw	t1, 0(t0)
375 376
	sync

wdenk's avatar
wdenk committed
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
	li	t0, SYS_FREQCTRL0
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, SYS_FREQCTRL1
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, SYS_CLKSRC
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, SYS_PININPUTEN
	li	t1, 0x00000000
	sw	t1, 0(t0)
392 393
	sync

wdenk's avatar
wdenk committed
394 395 396
	li	t0, 0xB1100100
	li	t1, 0x00000000
	sw	t1, 0(t0)
397

wdenk's avatar
wdenk committed
398 399 400
	li	t0, 0xB1400100
	li	t1, 0x00000000
	sw	t1, 0(t0)
401 402


wdenk's avatar
wdenk committed
403 404 405
	li	t0, SYS_WAKEMSK
	li	t1, 0x00000000
	sw	t1, 0(t0)
406

wdenk's avatar
wdenk committed
407 408 409
	li	t0, SYS_WAKESRC
	li	t1, 0x00000000
	sw	t1, 0(t0)
410

wdenk's avatar
wdenk committed
411 412 413 414 415
	/* wait 1mS before setup */
	li	t1, MEM_1MS
1:	add	t1, -1
	bne	t1, zero, 1b
	nop
416

417 418 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 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
#ifdef CONFIG_DBAU1550
/* SDCS 0,1,2 DDR SDRAM */
	li	t0, MEM_SDMODE0
	li	t1, 0x04276221
	sw	t1, 0(t0)

	li	t0, MEM_SDMODE1
	li	t1, 0x04276221
	sw	t1, 0(t0)

	li	t0, MEM_SDMODE2
	li	t1, 0x04276221
	sw	t1, 0(t0)

	li	t0, MEM_SDADDR0
	li	t1, 0xe21003f0
	sw	t1, 0(t0)

	li	t0, MEM_SDADDR1
	li	t1, 0xe21043f0
	sw	t1, 0(t0)

	li	t0, MEM_SDADDR2
	li	t1, 0xe21083f0
	sw	t1, 0(t0)

	sync

	li	t0, MEM_SDCONFIGA
	li	t1, 0x9030060a /* Program refresh - disabled */
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDCONFIGB
	li	t1, 0x00028000
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDPRECMD /* Precharge all */
	li	t1, 0
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD0
	li	t1, 0x40000000
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD1
	li	t1, 0x40000000
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD2
	li	t1, 0x40000000
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD0
	li	t1, 0x00000063
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD1
	li	t1, 0x00000063
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD2
	li	t1, 0x00000063
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDPRECMD /* Precharge all */
	sw	zero, 0(t0)
	sync

	/* Issue 2 autoref */
	li	t0, MEM_SDAUTOREF
	sw	zero, 0(t0)
	sync

	li	t0, MEM_SDAUTOREF
	sw	zero, 0(t0)
	sync

	/* Enable refresh */
	li	t0, MEM_SDCONFIGA
	li	t1, 0x9830060a /* Program refresh - enabled */
	sw	t1, 0(t0)
	sync

#else /* CONFIG_DBAU1550 */
wdenk's avatar
wdenk committed
510 511 512 513
/* SDCS 0,1 SDRAM */
	li	t0, MEM_SDMODE0
	li	t1, 0x005522AA
	sw	t1, 0(t0)
514

wdenk's avatar
wdenk committed
515 516 517
	li	t0, MEM_SDMODE1
	li	t1, 0x005522AA
	sw	t1, 0(t0)
518

wdenk's avatar
wdenk committed
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
	li	t0, MEM_SDMODE2
	li	t1, 0x00000000
	sw	t1, 0(t0)

	li	t0, MEM_SDADDR0
	li	t1, 0x001003F8
	sw	t1, 0(t0)


	li	t0, MEM_SDADDR1
	li	t1, 0x001023F8
	sw	t1, 0(t0)

	li	t0, MEM_SDADDR2
	li	t1, 0x00000000
	sw	t1, 0(t0)

	sync

	li	t0, MEM_SDREFCFG
	li	t1, 0x64000C24 /* Disable */
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDPRECMD
	sw	zero, 0(t0)
	sync

	li	t0, MEM_SDAUTOREF
	sw	zero, 0(t0)
	sync
	sw	zero, 0(t0)
	sync

	li	t0, MEM_SDREFCFG
	li	t1, 0x66000C24 /* Enable */
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD0
	li	t1, 0x00000033
	sw	t1, 0(t0)
	sync

	li	t0, MEM_SDWRMD1
	li	t1, 0x00000033
	sw	t1, 0(t0)
	sync

568
#endif /* CONFIG_DBAU1550 */
wdenk's avatar
wdenk committed
569 570 571 572 573
	/* wait 1mS after setup */
	li	t1, MEM_1MS
1:	add	t1, -1
	bne	t1, zero, 1b
	nop
574

wdenk's avatar
wdenk committed
575 576 577
	li	t0, SYS_PINFUNC
	li	t1, 0x00008080
	sw	t1, 0(t0)
578

wdenk's avatar
wdenk committed
579 580 581
	li	t0, SYS_TRIOUTCLR
	li	t1, 0x00001FFF
	sw	t1, 0(t0)
582

wdenk's avatar
wdenk committed
583 584 585
	li	t0, SYS_OUTPUTCLR
	li	t1, 0x00008000
	sw	t1, 0(t0)
586 587
	sync

588
	jr	ra
589
	nop