11.6Smatt/*	$NetBSD: smdk2410_start.S,v 1.6 2011/01/31 06:28:05 matt Exp $ */
21.1Sbsh
31.1Sbsh/*
41.1Sbsh * Copyright (c) 2002, 2003 Fujitsu Component Limited
51.1Sbsh * Copyright (c) 2002, 2003 Genetec Corporation
61.1Sbsh * All rights reserved.
71.1Sbsh *
81.1Sbsh * Redistribution and use in source and binary forms, with or without
91.1Sbsh * modification, are permitted provided that the following conditions
101.1Sbsh * are met:
111.1Sbsh * 1. Redistributions of source code must retain the above copyright
121.1Sbsh *    notice, this list of conditions and the following disclaimer.
131.1Sbsh * 2. Redistributions in binary form must reproduce the above copyright
141.1Sbsh *    notice, this list of conditions and the following disclaimer in the
151.1Sbsh *    documentation and/or other materials provided with the distribution.
161.1Sbsh * 3. Neither the name of The Fujitsu Component Limited nor the name of
171.1Sbsh *    Genetec corporation may not be used to endorse or promote products
181.1Sbsh *    derived from this software without specific prior written permission.
191.1Sbsh *
201.1Sbsh * THIS SOFTWARE IS PROVIDED BY FUJITSU COMPONENT LIMITED AND GENETEC
211.1Sbsh * CORPORATION ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
221.1Sbsh * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
231.1Sbsh * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
241.1Sbsh * DISCLAIMED.  IN NO EVENT SHALL FUJITSU COMPONENT LIMITED OR GENETEC
251.1Sbsh * CORPORATION BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
261.1Sbsh * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
271.1Sbsh * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
281.1Sbsh * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
291.1Sbsh * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
301.1Sbsh * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
311.1Sbsh * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Sbsh * SUCH DAMAGE.
331.1Sbsh */
341.1Sbsh
351.6Smatt#include "opt_smdk2xx0.h"		/* SMDK2XX0_CLOCK_CONFIG */
361.6Smatt
371.1Sbsh#include <machine/asm.h>
381.1Sbsh#include <arm/armreg.h>
391.6Smatt#include "assym.h"
401.1Sbsh
411.1Sbsh#include <arm/s3c2xx0/s3c2410reg.h>	/* for S3C2410_SDRAM_START */
421.6Smatt
431.6SmattRCSID("$NetBSD: smdk2410_start.S,v 1.6 2011/01/31 06:28:05 matt Exp $")
441.1Sbsh
451.1Sbsh/*
461.1Sbsh * Kernel start routine for Samsung SMDK2410.
471.1Sbsh * This code is excuted at the very first after the kernel is loaded
481.1Sbsh * by boot program.
491.1Sbsh */
501.1Sbsh	.text
511.1Sbsh
521.1Sbsh#ifndef	SDRAM_START
531.1Sbsh#define	SDRAM_START	S3C2410_SDRAM_START
541.1Sbsh#endif
551.1Sbsh#define KERNEL_TEXT_ADDR	(SDRAM_START+0x00200000)
561.1Sbsh
571.1Sbsh	.global	_C_LABEL(smdk2410_start)
581.1Sbsh_C_LABEL(smdk2410_start):
591.2Sbsh	/* Disable interrupt */
601.2Sbsh	mrs	r0, cpsr
611.2Sbsh	orr	r0, r0, #I32_bit
621.2Sbsh	msr	cpsr, r0
631.2Sbsh
641.4Sbsh#ifdef SMDK2XX0_CLOCK_CONFIG
651.4Sbsh	adr	r4, clock_config_data
661.4Sbsh
671.4Sbsh	mov	r2, #S3C2410_CLKMAN_BASE
681.4Sbsh	ldr	r1, [r2, #CLKMAN_CLKSLOW]
691.4Sbsh	orr	r0, r1, #CLKSLOW_SLOW
701.4Sbsh	str	r0, [r2, #CLKMAN_CLKSLOW]
711.4Sbsh	nop
721.4Sbsh	nop
731.4Sbsh
741.4Sbsh	ldmia	r4, {r0,r3}
751.4Sbsh	str	r0, [r2, #CLKMAN_CLKDIVN]
761.4Sbsh
771.4Sbsh	str	r3, [r2, #CLKMAN_MPLLCON]
781.4Sbsh	nop
791.4Sbsh	nop
801.4Sbsh
811.4Sbsh	str	r1, [r2, #CLKMAN_CLKSLOW]
821.4Sbsh#endif
831.4Sbsh
841.1Sbsh	/* Are we running on right place ? */
851.1Sbsh	adr r0, _C_LABEL(smdk2410_start)
861.1Sbsh	ldr	r2, =KERNEL_TEXT_ADDR
871.1Sbsh	cmp	r0, r2
881.1Sbsh	beq	smdk2410_start_ram
891.1Sbsh
901.1Sbsh	/*
911.1Sbsh	 * move me to RAM
921.1Sbsh	 */
931.1Sbsh	ldr r1, Lcopy_size
941.1Sbsh	adr r0, _C_LABEL(smdk2410_start)
951.1Sbsh	add r1, r1, #3
961.1Sbsh	mov r1, r1, LSR #2
971.1Sbsh	mov r4, r2
981.1Sbsh
991.1Sbsh	cmp r0, r2
1001.1Sbsh	bhs 5f
1011.1Sbsh
1021.1Sbsh	/* src < dest. copy from top */
1031.1Sbsh	add r0,r0,r1,LSL #2
1041.1Sbsh	add r2,r2,r1,LSL #2
1051.1Sbsh
1061.1Sbsh3:	ldr r3,[r0,#-4]!
1071.1Sbsh	str r3,[r2,#-4]!
1081.1Sbsh	subs r1,r1,#1
1091.1Sbsh	bhi 3b
1101.1Sbsh	b 7f
1111.1Sbsh
1121.1Sbsh	/* src >= dest. copy from bottom */
1131.1Sbsh5:	ldr r3,[r0],#4
1141.1Sbsh	str r3,[r2],#4
1151.1Sbsh	subs r1,r1,#1
1161.1Sbsh	bhi 5b
1171.1Sbsh
1181.1Sbsh7:
1191.1Sbsh	/* Jump to RAM */
1201.1Sbsh	ldr r0, Lstart_off
1211.1Sbsh	add pc, r4, r0
1221.1Sbsh
1231.1SbshLcopy_size:	.word _edata-_C_LABEL(smdk2410_start)
1241.1SbshLstart_off:	.word smdk2410_start_ram-_C_LABEL(smdk2410_start)
1251.1Sbsh
1261.1Sbshsmdk2410_start_ram:
1271.1Sbsh	/*
1281.3Sbsh	 *  Kernel is loaded in SDRAM (0x30200000..), and is expected to run
1291.1Sbsh	 *  in VA 0xc0200000..
1301.1Sbsh	 */
1311.1Sbsh
1321.1Sbsh	/* Disable MMU for a while */
1331.1Sbsh	mrc	p15, 0, r2, c1, c0, 0
1341.1Sbsh	bic	r2, r2, #CPU_CONTROL_MMU_ENABLE
1351.1Sbsh	mcr	p15, 0, r2, c1, c0, 0
1361.1Sbsh
1371.1Sbsh	nop
1381.1Sbsh	nop
1391.1Sbsh	nop
1401.1Sbsh
1411.1Sbsh	mov	r0,#SDRAM_START      /* pagetable */
1421.1Sbsh	adr	r4, mmu_init_table
1431.1Sbsh	b	2f
1441.1Sbsh1:
1451.1Sbsh	str	r3, [r0, r2]
1461.1Sbsh	add	r2, r2, #4
1471.1Sbsh	add	r3, r3, #(L1_S_SIZE)
1481.1Sbsh	adds	r1, r1, #-1
1491.1Sbsh	bhi	1b
1501.1Sbsh2:
1511.1Sbsh	ldmia	r4!, {r1,r2,r3}   /* # of sections, PA|attr, VA */
1521.1Sbsh	cmp	r1, #0
1531.1Sbsh	bne	1b
1541.1Sbsh
1551.1Sbsh	mcr	p15, 0, r0, c2, c0, 0	/* Set TTB */
1561.1Sbsh	mcr	p15, 0, r0, c8, c7, 0	/* Flush TLB */
1571.1Sbsh
1581.1Sbsh	/* Set the Domain Access register.  Very important! */
1591.1Sbsh	mov	r0, #((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT)
1601.1Sbsh	mcr	p15, 0, r0, c3, c0, 0
1611.1Sbsh
1621.1Sbsh	/* Enable MMU */
1631.1Sbsh	mrc	p15, 0, r0, c1, c0, 0
1641.1Sbsh	orr	r0, r0, #CPU_CONTROL_MMU_ENABLE
1651.1Sbsh	mcr	p15, 0, r0, c1, c0, 0
1661.1Sbsh
1671.1Sbsh	nop
1681.1Sbsh	nop
1691.1Sbsh	nop
1701.1Sbsh
1711.1Sbsh	/* Jump to kernel code in TRUE VA */
1721.1Sbsh	adr	r0, Lstart
1731.1Sbsh	ldr	pc, [r0]
1741.1Sbsh
1751.1SbshLstart:
1761.1Sbsh	.word	start
1771.4Sbsh
1781.4Sbsh	.macro clock_data  hdivn, pdivn, mdiv, pdiv, sdiv
1791.4Sbsh	.word	(\hdivn)<<1 | \pdivn
1801.4Sbsh	.word	(\mdiv)<<PLLCON_MDIV_SHIFT | (\pdiv)<<PLLCON_PDIV_SHIFT | (\sdiv)<<PLLCON_SDIV_SHIFT
1811.4Sbsh	.endm
1821.4Sbsh#ifdef	SMDK2XX0_CLOCK_CONFIG
1831.4Sbshclock_config_data:
1841.4Sbsh	clock_data SMDK2XX0_CLOCK_CONFIG
1851.4Sbsh#endif
1861.1Sbsh
1871.1Sbsh#define MMU_INIT(va,pa,n_sec,attr) \
1881.1Sbsh	.word	n_sec					    ; \
1891.1Sbsh	.word	4*((va)>>L1_S_SHIFT)			    ; \
1901.1Sbsh	.word	(pa)|(attr)				    ;
1911.1Sbsh
1921.1Sbshmmu_init_table:
1931.1Sbsh	/* fill all table VA==PA */
1941.6Smatt	MMU_INIT(0x00000000, 0x00000000, 1<<(32-L1_S_SHIFT), L1_TYPE_S|L1_S_AP_KRW)
1951.1Sbsh	/* map SDRAM VA==PA, WT cacheable */
1961.6Smatt	MMU_INIT(SDRAM_START, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
1971.1Sbsh	/* map VA 0xc0000000..0xc3ffffff to PA 0x30000000..0x33ffffff */
1981.6Smatt	MMU_INIT(0xc0000000, SDRAM_START, 64, L1_TYPE_S|L1_S_C|L1_S_AP_KRW)
1991.1Sbsh
2001.1Sbsh	.word 0	/* end of table */
2011.1Sbsh
202