| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * File:         arch/blackfin/mach-bf527/head.S | 
 | 3 |  * Based on:     arch/blackfin/mach-bf533/head.S | 
 | 4 |  * Author:       Jeff Dionne <jeff@uclinux.org> COPYRIGHT 1998 D. Jeff Dionne | 
 | 5 |  * | 
 | 6 |  * Created:      1998 | 
 | 7 |  * Description:  Startup code for Blackfin BF537 | 
 | 8 |  * | 
 | 9 |  * Modified: | 
 | 10 |  *               Copyright 2004-2007 Analog Devices Inc. | 
 | 11 |  * | 
 | 12 |  * Bugs:         Enter bugs at http://blackfin.uclinux.org/ | 
 | 13 |  * | 
 | 14 |  * This program is free software; you can redistribute it and/or modify | 
 | 15 |  * it under the terms of the GNU General Public License as published by | 
 | 16 |  * the Free Software Foundation; either version 2 of the License, or | 
 | 17 |  * (at your option) any later version. | 
 | 18 |  * | 
 | 19 |  * This program is distributed in the hope that it will be useful, | 
 | 20 |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 21 |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
 | 22 |  * GNU General Public License for more details. | 
 | 23 |  * | 
 | 24 |  * You should have received a copy of the GNU General Public License | 
 | 25 |  * along with this program; if not, see the file COPYING, or write | 
 | 26 |  * to the Free Software Foundation, Inc., | 
 | 27 |  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
 | 28 |  */ | 
 | 29 |  | 
 | 30 | #include <linux/linkage.h> | 
 | 31 | #include <linux/init.h> | 
 | 32 | #include <asm/blackfin.h> | 
 | 33 | #include <asm/trace.h> | 
 | 34 |  | 
| Michael Hennerich | 68e2fc7 | 2008-07-14 16:51:57 +0800 | [diff] [blame] | 35 | #ifdef CONFIG_BFIN_KERNEL_CLOCK | 
| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 36 | #include <asm/mach-common/clocks.h> | 
 | 37 | #include <asm/mach/mem_init.h> | 
 | 38 | #endif | 
 | 39 |  | 
| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 40 | .extern ___bss_stop | 
 | 41 | .extern ___bss_start | 
 | 42 | .extern _bf53x_relocate_l1_mem | 
 | 43 |  | 
 | 44 | #define INITIAL_STACK	0xFFB01000 | 
 | 45 |  | 
 | 46 | __INIT | 
 | 47 |  | 
 | 48 | ENTRY(__start) | 
 | 49 | 	/* R0: argument of command line string, passed from uboot, save it */ | 
 | 50 | 	R7 = R0; | 
 | 51 | 	/* Enable Cycle Counter and Nesting Of Interrupts */ | 
 | 52 | #ifdef CONFIG_BFIN_SCRATCH_REG_CYCLES | 
 | 53 | 	R0 = SYSCFG_SNEN; | 
 | 54 | #else | 
 | 55 | 	R0 = SYSCFG_SNEN | SYSCFG_CCEN; | 
 | 56 | #endif | 
 | 57 | 	SYSCFG = R0; | 
 | 58 | 	R0 = 0; | 
 | 59 |  | 
 | 60 | 	/* Clear Out All the data and pointer Registers */ | 
 | 61 | 	R1 = R0; | 
 | 62 | 	R2 = R0; | 
 | 63 | 	R3 = R0; | 
 | 64 | 	R4 = R0; | 
 | 65 | 	R5 = R0; | 
 | 66 | 	R6 = R0; | 
 | 67 |  | 
 | 68 | 	P0 = R0; | 
 | 69 | 	P1 = R0; | 
 | 70 | 	P2 = R0; | 
 | 71 | 	P3 = R0; | 
 | 72 | 	P4 = R0; | 
 | 73 | 	P5 = R0; | 
 | 74 |  | 
 | 75 | 	LC0 = r0; | 
 | 76 | 	LC1 = r0; | 
 | 77 | 	L0 = r0; | 
 | 78 | 	L1 = r0; | 
 | 79 | 	L2 = r0; | 
 | 80 | 	L3 = r0; | 
 | 81 |  | 
 | 82 | 	/* Clear Out All the DAG Registers */ | 
 | 83 | 	B0 = r0; | 
 | 84 | 	B1 = r0; | 
 | 85 | 	B2 = r0; | 
 | 86 | 	B3 = r0; | 
 | 87 |  | 
 | 88 | 	I0 = r0; | 
 | 89 | 	I1 = r0; | 
 | 90 | 	I2 = r0; | 
 | 91 | 	I3 = r0; | 
 | 92 |  | 
 | 93 | 	M0 = r0; | 
 | 94 | 	M1 = r0; | 
 | 95 | 	M2 = r0; | 
 | 96 | 	M3 = r0; | 
 | 97 |  | 
 | 98 | 	trace_buffer_init(p0,r0); | 
 | 99 | 	P0 = R1; | 
 | 100 | 	R0 = R1; | 
 | 101 |  | 
 | 102 | 	/* Turn off the icache */ | 
 | 103 | 	p0.l = LO(IMEM_CONTROL); | 
 | 104 | 	p0.h = HI(IMEM_CONTROL); | 
 | 105 | 	R1 = [p0]; | 
 | 106 | 	R0 = ~ENICPLB; | 
 | 107 | 	R0 = R0 & R1; | 
 | 108 |  | 
 | 109 | 	/* Anomaly 05000125 */ | 
 | 110 | #if ANOMALY_05000125 | 
 | 111 | 	CLI R2; | 
 | 112 | 	SSYNC; | 
 | 113 | #endif | 
 | 114 | 	[p0] = R0; | 
 | 115 | 	SSYNC; | 
 | 116 | #if ANOMALY_05000125 | 
 | 117 | 	STI R2; | 
 | 118 | #endif | 
 | 119 |  | 
 | 120 | 	/* Turn off the dcache */ | 
 | 121 | 	p0.l = LO(DMEM_CONTROL); | 
 | 122 | 	p0.h = HI(DMEM_CONTROL); | 
 | 123 | 	R1 = [p0]; | 
 | 124 | 	R0 = ~ENDCPLB; | 
 | 125 | 	R0 = R0 & R1; | 
 | 126 |  | 
 | 127 | 	/* Anomaly 05000125 */ | 
 | 128 | #if ANOMALY_05000125 | 
 | 129 | 	CLI R2; | 
 | 130 | 	SSYNC; | 
 | 131 | #endif | 
 | 132 | 	[p0] = R0; | 
 | 133 | 	SSYNC; | 
 | 134 | #if ANOMALY_05000125 | 
 | 135 | 	STI R2; | 
 | 136 | #endif | 
 | 137 |  | 
 | 138 |  | 
 | 139 | #if defined(CONFIG_BF527) | 
 | 140 | 	p0.h = hi(EMAC_SYSTAT); | 
 | 141 | 	p0.l = lo(EMAC_SYSTAT); | 
 | 142 | 	R0.h = 0xFFFF; /* Clear EMAC Interrupt Status bits */ | 
 | 143 | 	R0.l = 0xFFFF; | 
 | 144 | 	[P0] = R0; | 
 | 145 | 	SSYNC; | 
 | 146 | #endif | 
 | 147 |  | 
 | 148 | 	/* Initialise UART - when booting from u-boot, the UART is not disabled | 
 | 149 | 	 * so if we dont initalize here, our serial console gets hosed */ | 
 | 150 | 	p0.h = hi(UART1_LCR); | 
 | 151 | 	p0.l = lo(UART1_LCR); | 
 | 152 | 	r0 = 0x0(Z); | 
 | 153 | 	w[p0] = r0.L;	/* To enable DLL writes */ | 
 | 154 | 	ssync; | 
 | 155 |  | 
 | 156 | 	p0.h = hi(UART1_DLL); | 
 | 157 | 	p0.l = lo(UART1_DLL); | 
 | 158 | 	r0 = 0x0(Z); | 
 | 159 | 	w[p0] = r0.L; | 
 | 160 | 	ssync; | 
 | 161 |  | 
 | 162 | 	p0.h = hi(UART1_DLH); | 
 | 163 | 	p0.l = lo(UART1_DLH); | 
 | 164 | 	r0 = 0x00(Z); | 
 | 165 | 	w[p0] = r0.L; | 
 | 166 | 	ssync; | 
 | 167 |  | 
 | 168 | 	p0.h = hi(UART1_GCTL); | 
 | 169 | 	p0.l = lo(UART1_GCTL); | 
 | 170 | 	r0 = 0x0(Z); | 
 | 171 | 	w[p0] = r0.L;	/* To enable UART clock */ | 
 | 172 | 	ssync; | 
 | 173 |  | 
 | 174 | 	/* Initialize stack pointer */ | 
 | 175 | 	sp.l = lo(INITIAL_STACK); | 
 | 176 | 	sp.h = hi(INITIAL_STACK); | 
 | 177 | 	fp = sp; | 
 | 178 | 	usp = sp; | 
 | 179 |  | 
 | 180 | #ifdef CONFIG_EARLY_PRINTK | 
 | 181 | 	SP += -12; | 
 | 182 | 	call _init_early_exception_vectors; | 
 | 183 | 	SP += 12; | 
 | 184 | #endif | 
 | 185 |  | 
 | 186 | 	/* Put The Code for PLL Programming and SDRAM Programming in L1 ISRAM */ | 
 | 187 | 	call _bf53x_relocate_l1_mem; | 
| Michael Hennerich | 68e2fc7 | 2008-07-14 16:51:57 +0800 | [diff] [blame] | 188 | #ifdef CONFIG_BFIN_KERNEL_CLOCK | 
| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 189 | 	call _start_dma_code; | 
 | 190 | #endif | 
 | 191 |  | 
 | 192 | 	/* Code for initializing Async memory banks */ | 
 | 193 |  | 
 | 194 | 	p2.h = hi(EBIU_AMBCTL1); | 
 | 195 | 	p2.l = lo(EBIU_AMBCTL1); | 
 | 196 | 	r0.h = hi(AMBCTL1VAL); | 
 | 197 | 	r0.l = lo(AMBCTL1VAL); | 
 | 198 | 	[p2] = r0; | 
 | 199 | 	ssync; | 
 | 200 |  | 
 | 201 | 	p2.h = hi(EBIU_AMBCTL0); | 
 | 202 | 	p2.l = lo(EBIU_AMBCTL0); | 
 | 203 | 	r0.h = hi(AMBCTL0VAL); | 
 | 204 | 	r0.l = lo(AMBCTL0VAL); | 
 | 205 | 	[p2] = r0; | 
 | 206 | 	ssync; | 
 | 207 |  | 
 | 208 | 	p2.h = hi(EBIU_AMGCTL); | 
 | 209 | 	p2.l = lo(EBIU_AMGCTL); | 
 | 210 | 	r0 = AMGCTLVAL; | 
 | 211 | 	w[p2] = r0; | 
 | 212 | 	ssync; | 
 | 213 |  | 
 | 214 | 	/* This section keeps the processor in supervisor mode | 
 | 215 | 	 * during kernel boot.  Switches to user mode at end of boot. | 
 | 216 | 	 * See page 3-9 of Hardware Reference manual for documentation. | 
 | 217 | 	 */ | 
 | 218 |  | 
 | 219 | 	/* EVT15 = _real_start */ | 
 | 220 |  | 
 | 221 | 	p0.l = lo(EVT15); | 
 | 222 | 	p0.h = hi(EVT15); | 
 | 223 | 	p1.l = _real_start; | 
 | 224 | 	p1.h = _real_start; | 
 | 225 | 	[p0] = p1; | 
 | 226 | 	csync; | 
 | 227 |  | 
 | 228 | 	p0.l = lo(IMASK); | 
 | 229 | 	p0.h = hi(IMASK); | 
 | 230 | 	p1.l = IMASK_IVG15; | 
 | 231 | 	p1.h = 0x0; | 
 | 232 | 	[p0] = p1; | 
 | 233 | 	csync; | 
 | 234 |  | 
 | 235 | 	raise 15; | 
 | 236 | 	p0.l = .LWAIT_HERE; | 
 | 237 | 	p0.h = .LWAIT_HERE; | 
 | 238 | 	reti = p0; | 
 | 239 | #if ANOMALY_05000281 | 
 | 240 | 	nop; nop; nop; | 
 | 241 | #endif | 
 | 242 | 	rti; | 
 | 243 |  | 
 | 244 | .LWAIT_HERE: | 
 | 245 | 	jump .LWAIT_HERE; | 
 | 246 | ENDPROC(__start) | 
 | 247 |  | 
 | 248 | ENTRY(_real_start) | 
 | 249 | 	[ -- sp ] = reti; | 
 | 250 | 	p0.l = lo(WDOG_CTL); | 
 | 251 | 	p0.h = hi(WDOG_CTL); | 
 | 252 | 	r0 = 0xAD6(z); | 
 | 253 | 	w[p0] = r0;	/* watchdog off for now */ | 
 | 254 | 	ssync; | 
 | 255 |  | 
 | 256 | 	/* Code update for BSS size == 0 | 
 | 257 | 	 * Zero out the bss region. | 
 | 258 | 	 */ | 
 | 259 |  | 
 | 260 | 	p1.l = ___bss_start; | 
 | 261 | 	p1.h = ___bss_start; | 
 | 262 | 	p2.l = ___bss_stop; | 
 | 263 | 	p2.h = ___bss_stop; | 
 | 264 | 	r0 = 0; | 
 | 265 | 	p2 -= p1; | 
 | 266 | 	lsetup (.L_clear_bss, .L_clear_bss) lc0 = p2; | 
 | 267 | .L_clear_bss: | 
 | 268 | 	B[p1++] = r0; | 
 | 269 |  | 
 | 270 | 	/* In case there is a NULL pointer reference | 
 | 271 | 	 * Zero out region before stext | 
 | 272 | 	 */ | 
 | 273 |  | 
 | 274 | 	p1.l = 0x0; | 
 | 275 | 	p1.h = 0x0; | 
 | 276 | 	r0.l = __stext; | 
 | 277 | 	r0.h = __stext; | 
 | 278 | 	r0 = r0 >> 1; | 
 | 279 | 	p2 = r0; | 
 | 280 | 	r0 = 0; | 
 | 281 | 	lsetup (.L_clear_zero, .L_clear_zero) lc0 = p2; | 
 | 282 | .L_clear_zero: | 
 | 283 | 	W[p1++] = r0; | 
 | 284 |  | 
 | 285 | 	/* pass the uboot arguments to the global value command line */ | 
 | 286 | 	R0 = R7; | 
 | 287 | 	call _cmdline_init; | 
 | 288 |  | 
 | 289 | 	p1.l = __rambase; | 
 | 290 | 	p1.h = __rambase; | 
 | 291 | 	r0.l = __sdata; | 
 | 292 | 	r0.h = __sdata; | 
 | 293 | 	[p1] = r0; | 
 | 294 |  | 
 | 295 | 	p1.l = __ramstart; | 
 | 296 | 	p1.h = __ramstart; | 
 | 297 | 	p3.l = ___bss_stop; | 
 | 298 | 	p3.h = ___bss_stop; | 
 | 299 |  | 
 | 300 | 	r1 = p3; | 
 | 301 | 	[p1] = r1; | 
 | 302 |  | 
 | 303 | 	/* | 
 | 304 | 	 * load the current thread pointer and stack | 
 | 305 | 	 */ | 
 | 306 | 	r1.l = _init_thread_union; | 
 | 307 | 	r1.h = _init_thread_union; | 
 | 308 |  | 
 | 309 | 	r2.l = 0x2000; | 
 | 310 | 	r2.h = 0x0000; | 
 | 311 | 	r1 = r1 + r2; | 
 | 312 | 	sp = r1; | 
 | 313 | 	usp = sp; | 
 | 314 | 	fp = sp; | 
 | 315 | 	jump.l _start_kernel; | 
 | 316 | ENDPROC(_real_start) | 
 | 317 |  | 
 | 318 | __FINIT | 
 | 319 |  | 
 | 320 | .section .l1.text | 
| Michael Hennerich | 68e2fc7 | 2008-07-14 16:51:57 +0800 | [diff] [blame] | 321 | #ifdef CONFIG_BFIN_KERNEL_CLOCK | 
| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 322 | ENTRY(_start_dma_code) | 
 | 323 |  | 
 | 324 | 	/* Enable PHY CLK buffer output */ | 
 | 325 | 	p0.h = hi(VR_CTL); | 
 | 326 | 	p0.l = lo(VR_CTL); | 
 | 327 | 	r0.l = w[p0]; | 
 | 328 | 	bitset(r0, 14); | 
 | 329 | 	w[p0] = r0.l; | 
 | 330 | 	ssync; | 
 | 331 |  | 
 | 332 | 	p0.h = hi(SIC_IWR0); | 
 | 333 | 	p0.l = lo(SIC_IWR0); | 
 | 334 | 	r0.l = 0x1; | 
 | 335 | 	r0.h = 0x0; | 
 | 336 | 	[p0] = r0; | 
 | 337 | 	SSYNC; | 
 | 338 |  | 
 | 339 | 	/* | 
 | 340 | 	 *  Set PLL_CTL | 
 | 341 | 	 *   - [14:09] = MSEL[5:0] : CLKIN / VCO multiplication factors | 
 | 342 | 	 *   - [8]     = BYPASS    : BYPASS the PLL, run CLKIN into CCLK/SCLK | 
 | 343 | 	 *   - [7]     = output delay (add 200ps of delay to mem signals) | 
 | 344 | 	 *   - [6]     = input delay (add 200ps of input delay to mem signals) | 
 | 345 | 	 *   - [5]     = PDWN      : 1=All Clocks off | 
 | 346 | 	 *   - [3]     = STOPCK    : 1=Core Clock off | 
 | 347 | 	 *   - [1]     = PLL_OFF   : 1=Disable Power to PLL | 
 | 348 | 	 *   - [0]     = DF        : 1=Pass CLKIN/2 to PLL / 0=Pass CLKIN to PLL | 
 | 349 | 	 *   all other bits set to zero | 
 | 350 | 	 */ | 
 | 351 |  | 
 | 352 | 	p0.h = hi(PLL_LOCKCNT); | 
 | 353 | 	p0.l = lo(PLL_LOCKCNT); | 
 | 354 | 	r0 = 0x300(Z); | 
 | 355 | 	w[p0] = r0.l; | 
 | 356 | 	ssync; | 
 | 357 |  | 
 | 358 | 	P2.H = hi(EBIU_SDGCTL); | 
 | 359 | 	P2.L = lo(EBIU_SDGCTL); | 
 | 360 | 	R0 = [P2]; | 
 | 361 | 	BITSET (R0, 24); | 
 | 362 | 	[P2] = R0; | 
 | 363 | 	SSYNC; | 
 | 364 |  | 
 | 365 | 	r0 = CONFIG_VCO_MULT & 63;       /* Load the VCO multiplier         */ | 
 | 366 | 	r0 = r0 << 9;                    /* Shift it over,                  */ | 
 | 367 | 	r1 = CLKIN_HALF;                 /* Do we need to divide CLKIN by 2?*/ | 
 | 368 | 	r0 = r1 | r0; | 
 | 369 | 	r1 = PLL_BYPASS;                 /* Bypass the PLL?                 */ | 
 | 370 | 	r1 = r1 << 8;                    /* Shift it over                   */ | 
 | 371 | 	r0 = r1 | r0;                    /* add them all together           */ | 
 | 372 |  | 
 | 373 | 	p0.h = hi(PLL_CTL); | 
 | 374 | 	p0.l = lo(PLL_CTL);              /* Load the address                */ | 
 | 375 | 	cli r2;                          /* Disable interrupts              */ | 
 | 376 | 	ssync; | 
 | 377 | 	w[p0] = r0.l;                    /* Set the value                   */ | 
 | 378 | 	idle;                            /* Wait for the PLL to stablize    */ | 
 | 379 | 	sti r2;                          /* Enable interrupts               */ | 
 | 380 |  | 
 | 381 | .Lcheck_again: | 
 | 382 | 	p0.h = hi(PLL_STAT); | 
 | 383 | 	p0.l = lo(PLL_STAT); | 
 | 384 | 	R0 = W[P0](Z); | 
 | 385 | 	CC = BITTST(R0,5); | 
 | 386 | 	if ! CC jump .Lcheck_again; | 
 | 387 |  | 
 | 388 | 	/* Configure SCLK & CCLK Dividers */ | 
 | 389 | 	r0 = (CONFIG_CCLK_ACT_DIV | CONFIG_SCLK_DIV); | 
 | 390 | 	p0.h = hi(PLL_DIV); | 
 | 391 | 	p0.l = lo(PLL_DIV); | 
 | 392 | 	w[p0] = r0.l; | 
 | 393 | 	ssync; | 
 | 394 |  | 
 | 395 | 	p0.l = lo(EBIU_SDRRC); | 
 | 396 | 	p0.h = hi(EBIU_SDRRC); | 
 | 397 | 	r0 = mem_SDRRC; | 
 | 398 | 	w[p0] = r0.l; | 
 | 399 | 	ssync; | 
 | 400 |  | 
| Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 401 | 	P2.H = hi(EBIU_SDGCTL); | 
 | 402 | 	P2.L = lo(EBIU_SDGCTL); | 
 | 403 | 	R0 = [P2]; | 
 | 404 | 	BITCLR (R0, 24); | 
 | 405 | 	p0.h = hi(EBIU_SDSTAT); | 
 | 406 | 	p0.l = lo(EBIU_SDSTAT); | 
 | 407 | 	r2.l = w[p0]; | 
 | 408 | 	cc = bittst(r2,3); | 
 | 409 | 	if !cc jump .Lskip; | 
 | 410 | 	NOP; | 
 | 411 | 	BITSET (R0, 23); | 
 | 412 | .Lskip: | 
 | 413 | 	[P2] = R0; | 
 | 414 | 	SSYNC; | 
 | 415 |  | 
 | 416 | 	R0.L = lo(mem_SDGCTL); | 
 | 417 | 	R0.H = hi(mem_SDGCTL); | 
 | 418 | 	R1 = [p2]; | 
 | 419 | 	R1 = R1 | R0; | 
 | 420 | 	[P2] = R1; | 
 | 421 | 	SSYNC; | 
 | 422 |  | 
 | 423 | 	p0.h = hi(SIC_IWR0); | 
 | 424 | 	p0.l = lo(SIC_IWR0); | 
 | 425 | 	r0.l = lo(IWR_ENABLE_ALL); | 
 | 426 | 	r0.h = hi(IWR_ENABLE_ALL); | 
 | 427 | 	[p0] = r0; | 
 | 428 | 	SSYNC; | 
 | 429 |  | 
 | 430 | 	RTS; | 
 | 431 | ENDPROC(_start_dma_code) | 
 | 432 | #endif /* CONFIG_BFIN_KERNEL_CLOCK */ |