1*95e1ffb1Schristos/*	$NetBSD: s3c2410_vector.S,v 1.2 2005/12/11 12:17:09 christos Exp $	*/
279290227Smycroft
379290227Smycroft/*
479290227Smycroft * Copyright (c) 2003 By Noon Software, Inc.  All rights reserved.
579290227Smycroft *
679290227Smycroft * Redistribution and use in source and binary forms, with or without
779290227Smycroft * modification, are permitted provided that the following conditions
879290227Smycroft * are met:
979290227Smycroft * 1. Redistributions of source code must retain the above copyright
1079290227Smycroft *    notice, this list of conditions and the following disclaimer.
1179290227Smycroft * 2. Redistributions in binary form must reproduce the above copyright
1279290227Smycroft *    notice, this list of conditions and the following disclaimer in the
1379290227Smycroft *    documentation and/or other materials provided with the distribution.
1479290227Smycroft * 3. The names of the authors may not be used to endorse or promote products
1579290227Smycroft *    derived from this software without specific prior written permission.
1679290227Smycroft *
1779290227Smycroft * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
1879290227Smycroft * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1979290227Smycroft * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2079290227Smycroft * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2179290227Smycroft * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2279290227Smycroft * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2379290227Smycroft * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2479290227Smycroft * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2579290227Smycroft * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2679290227Smycroft * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2779290227Smycroft */
2879290227Smycroft
2979290227Smycroft/*
3079290227Smycroft * Vector and initialize for S3C2410 based systems.
3179290227Smycroft */
3279290227Smycroft
3379290227Smycroft#include <machine/asm.h>
3479290227Smycroft#include <arm/armreg.h>
3579290227Smycroft#include <arm/s3c2xx0/s3c2410reg.h>
3679290227Smycroft
3779290227Smycroft
3879290227Smycroft#define TEMP_STACK_SIZE	(4*1024)
3979290227Smycroft
4079290227Smycroft	.code 32
4179290227Smycroft	.section ".vectors"
4279290227Smycroft
4379290227Smycroftreset_vector:
4479290227Smycroft	b	__reset_entry
4579290227Smycroftundef:
4679290227Smycroft	b	.
4779290227Smycroftswi:
4879290227Smycroft	b	.
4979290227Smycroftabrtp:
5079290227Smycroft	b	.
5179290227Smycroftabrtd:
5279290227Smycroft	b	.
5379290227Smycroftresv:
5479290227Smycroft	b	.
5579290227Smycroftirq:
5679290227Smycroft	b	.
5779290227Smycroftfiq:
5879290227Smycroft	b	.
5979290227Smycroft
6079290227Smycroft/*
6179290227Smycroft * Normally this code lives on ROM and runs immediately after reset, but
6279290227Smycroft * it may run on RAM and/or be called after system has been initialized.
6379290227Smycroft */
6479290227Smycroft__reset_entry:
6579290227Smycroft	mrs	r0, cpsr
6679290227Smycroft	/* SVC mode, Disable interrupts */
6779290227Smycroft	bic	r0, r0, #PSR_MODE
6879290227Smycroft	orr	r0, r0, #(I32_bit|F32_bit|PSR_SVC32_MODE)
6979290227Smycroft	msr	cpsr, r0
7079290227Smycroft
7179290227Smycroft	/* Disable MMU, Disable cache */
7279290227Smycroft	mrc	p15, 0, r10, c1, c0, 0
7379290227Smycroft	ldr	r0, =(CPU_CONTROL_MMU_ENABLE|CPU_CONTROL_DC_ENABLE|CPU_CONTROL_IC_ENABLE)
7479290227Smycroft	bic	r10, r10, r0
7579290227Smycroft	mcr	p15, 0, r10, c1, c0, 0
7679290227Smycroft	nop
7779290227Smycroft	nop
7879290227Smycroft	nop
7979290227Smycroft
8079290227Smycroft	/* invalidate I-cache */
8179290227Smycroft	mcr	p15, 0, r2, c7, c5, 0
8279290227Smycroft	nop
8379290227Smycroft	nop
8479290227Smycroft	nop
8579290227Smycroft
8679290227Smycroft	/* Enable I-cache */
8779290227Smycroft	orr	r10, r10, #CPU_CONTROL_IC_ENABLE
8879290227Smycroft	mcr	p15, 0, r10, c1, c0, 0
8979290227Smycroft	nop
9079290227Smycroft	nop
9179290227Smycroft	nop
9279290227Smycroft
9379290227Smycroft	/* Stop WDT */
9479290227Smycroft	ldr	r0, Lwdt_wtcon_addr
9579290227Smycroft	mov	r1, #WTCON_WDTSTOP
9679290227Smycroft	str	r1, [r0]
9779290227Smycroft
9879290227Smycroft	/* Disable all interrupts */
9979290227Smycroft	ldr	r0, Lintctl_intmsk_addr
10079290227Smycroft	mov	r1, #0x0
10179290227Smycroft	str	r1, [r0]
10279290227Smycroft
10379290227Smycroft	ldr	r9, =S3C2410_GPIO_BASE
10479290227Smycroft	/* LEDs on SMDK2410 */
10579290227Smycroft	mov	r1, #0x5500
10679290227Smycroft	str	r1, [r9, #GPIO_PFCON]
10779290227Smycroft	mov	r1, #0xe0
10879290227Smycroft	str	r1, [r9, #GPIO_PFDAT]
10979290227Smycroft
11079290227Smycroft	mov	r0, pc
11179290227Smycroft	cmp	r0, #S3C2410_SDRAM_START
11279290227Smycroft	bhs	running_on_ram
11379290227Smycroft
11479290227Smycroft	ldr	r8, =S3C2410_CLKMAN_BASE
11579290227Smycroft	ldr	r1, [r8,#CLKMAN_CLKDIVN]
11679290227Smycroft	orr	r1, r1, #CLKDIVN_HDIVN|CLKDIVN_PDIVN
11779290227Smycroft	str	r1, [r8,#CLKMAN_CLKDIVN]
11879290227Smycroft
11979290227Smycroft	ldr	r1, Lclkman_locktime_data
12079290227Smycroft	str	r1, [r8,#CLKMAN_LOCKTIME]
12179290227Smycroft
12279290227Smycroft	/* Initialize PLL */
12379290227Smycroft	ldr	r1, Lclkman_mpllcon_data
12479290227Smycroft	str	r1, [r8,#CLKMAN_MPLLCON]
12579290227Smycroft	ldr	r1, Lclkman_upllcon_data
12679290227Smycroft	str	r1, [r8,#CLKMAN_UPLLCON]
12779290227Smycroft
12879290227Smycroft	ldr	r9, =S3C2410_GPIO_BASE
12979290227Smycroft	mov	r1, #0xd0
13079290227Smycroft	str	r1, [r9, #GPIO_PFDAT]
13179290227Smycroft
13279290227Smycroft#ifdef RAM_INIT_HOOK
13379290227Smycroft	bl	RAM_INIT_HOOK
13479290227Smycroft#endif
13579290227Smycroft
13679290227Smycroftrunning_on_ram:
13779290227Smycroft	/* Change Bus mode to Sync */
13879290227Smycroft	mrc	p15, 0, r0, c1, c0, 0
13979290227Smycroft	bic	r0, r0, #(1<<31)		/* unset iA bit */
14079290227Smycroft	orr	r0, r0, #(1<<30)		/* set nF bit */
14179290227Smycroft	mcr	p15, 0, r0, c1, c0, 0
14279290227Smycroft	nop
14379290227Smycroft	nop
14479290227Smycroft	nop
14579290227Smycroft
14679290227Smycroft	ldr	r9, =S3C2410_GPIO_BASE
14779290227Smycroft	mov	r1, #0xb0
14879290227Smycroft	str	r1, [r9, #GPIO_PFDAT]
14979290227Smycroft
15079290227Smycroft	/* set temporary stack */
15179290227Smycroft	adr	sp, reset_vector
15279290227Smycroft	/* do we have a room below? */
15379290227Smycroft	ldr	r1, =(S3C2410_SDRAM_START+TEMP_STACK_SIZE)
15479290227Smycroft	cmp	sp, r1
15579290227Smycroft	/* otherwise use top area of RAM */
15679290227Smycroft	ldrlo	sp, =(S3C2410_SDRAM_START+SDRAM_SIZE)
15779290227Smycroft
15879290227Smycroft#ifdef IO_INIT_HOOK
15979290227Smycroft	bl	IO_INIT_HOOK
16079290227Smycroft#endif
16179290227Smycroft
16279290227Smycroft	ldr	r9, =S3C2410_GPIO_BASE
16379290227Smycroft	mov	r1, #0x70
16479290227Smycroft	str	r1, [r9, #GPIO_PFDAT]
16579290227Smycroft
16679290227Smycroft	b	start
16779290227Smycroft
16879290227SmycroftLwdt_wtcon_addr:
16979290227Smycroft	.word	(S3C2410_WDT_BASE + WDT_WTCON)
17079290227Smycroft
17179290227SmycroftLintctl_intmsk_addr:
17279290227Smycroft	.word	(S3C2410_INTCTL_BASE + INTCTL_INTMSK)
17379290227Smycroft
17479290227Smycroft	.ltorg
17579290227Smycroft
17679290227SmycroftLclkman_locktime_data:
17779290227Smycroft	.word	(0xffffff)
17879290227Smycroft
17979290227SmycroftLclkman_mpllcon_data:
18079290227Smycroft#if XTAL_CLK == 12000000 && FCLK == 180000000
18179290227Smycroft	.word	0x00052011	/* M=82, P=1, S=1 */
18279290227Smycroft#else
18379290227Smycroft#error	illegal XTAL_CLK/FCLK combination
18479290227Smycroft#endif
18579290227SmycroftLclkman_upllcon_data:
18679290227Smycroft	.word	0x00078023	/* M=120, P=2, S=3 */
187