xref: /openbmc/u-boot/arch/arm/mach-davinci/lowlevel_init.S (revision 83d290c56fab2d38cd1ab4c4cc7099559c1d5046)
1*83d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */
2601fbec7SMasahiro Yamada/*
3601fbec7SMasahiro Yamada * Low-level board setup code for TI DaVinci SoC based boards.
4601fbec7SMasahiro Yamada *
5601fbec7SMasahiro Yamada * Copyright (C) 2007 Sergey Kubushyn <ksi@koi8.net>
6601fbec7SMasahiro Yamada *
7601fbec7SMasahiro Yamada * Partially based on TI sources, original copyrights follow:
8601fbec7SMasahiro Yamada */
9601fbec7SMasahiro Yamada
10601fbec7SMasahiro Yamada/*
11601fbec7SMasahiro Yamada * Board specific setup info
12601fbec7SMasahiro Yamada *
13601fbec7SMasahiro Yamada * (C) Copyright 2003
14601fbec7SMasahiro Yamada * Texas Instruments, <www.ti.com>
15601fbec7SMasahiro Yamada * Kshitij Gupta <Kshitij@ti.com>
16601fbec7SMasahiro Yamada *
17601fbec7SMasahiro Yamada * Modified for OMAP 1610 H2 board by Nishant Kamat, Jan 2004
18601fbec7SMasahiro Yamada *
19601fbec7SMasahiro Yamada * Modified for OMAP 5912 OSK board by Rishi Bhattacharya, Apr 2004
20601fbec7SMasahiro Yamada *
21601fbec7SMasahiro Yamada * Modified for DV-EVM board by Rishi Bhattacharya, Apr 2005
22601fbec7SMasahiro Yamada *
23601fbec7SMasahiro Yamada * Modified for DV-EVM board by Swaminathan S, Nov 2005
24601fbec7SMasahiro Yamada */
25601fbec7SMasahiro Yamada
26601fbec7SMasahiro Yamada#include <config.h>
27601fbec7SMasahiro Yamada
28601fbec7SMasahiro Yamada#define MDSTAT_STATE	0x3f
29601fbec7SMasahiro Yamada
30601fbec7SMasahiro Yamada.globl	lowlevel_init
31601fbec7SMasahiro Yamadalowlevel_init:
32601fbec7SMasahiro Yamada#ifdef CONFIG_SOC_DM644X
33601fbec7SMasahiro Yamada
34601fbec7SMasahiro Yamada	/*-------------------------------------------------------*
35601fbec7SMasahiro Yamada	 * Mask all IRQs by setting all bits in the EINT default *
36601fbec7SMasahiro Yamada	 *-------------------------------------------------------*/
37601fbec7SMasahiro Yamada	mov	r1, $0
38601fbec7SMasahiro Yamada	ldr	r0, =EINT_ENABLE0
39601fbec7SMasahiro Yamada	str	r1, [r0]
40601fbec7SMasahiro Yamada	ldr	r0, =EINT_ENABLE1
41601fbec7SMasahiro Yamada	str	r1, [r0]
42601fbec7SMasahiro Yamada
43601fbec7SMasahiro Yamada	/*------------------------------------------------------*
44601fbec7SMasahiro Yamada	 * Put the GEM in reset					*
45601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
46601fbec7SMasahiro Yamada
47601fbec7SMasahiro Yamada	/* Put the GEM in reset */
48601fbec7SMasahiro Yamada	ldr	r8, PSC_GEM_FLAG_CLEAR
49601fbec7SMasahiro Yamada	ldr	r6, MDCTL_GEM
50601fbec7SMasahiro Yamada	ldr	r7, [r6]
51601fbec7SMasahiro Yamada	and	r7, r7, r8
52601fbec7SMasahiro Yamada	str	r7, [r6]
53601fbec7SMasahiro Yamada
54601fbec7SMasahiro Yamada	/* Enable the Power Domain Transition Command */
55601fbec7SMasahiro Yamada	ldr	r6, PTCMD
56601fbec7SMasahiro Yamada	ldr	r7, [r6]
57601fbec7SMasahiro Yamada	orr	r7, r7, $0x02
58601fbec7SMasahiro Yamada	str	r7, [r6]
59601fbec7SMasahiro Yamada
60601fbec7SMasahiro Yamada	/* Check for Transition Complete(PTSTAT) */
61601fbec7SMasahiro YamadacheckStatClkStopGem:
62601fbec7SMasahiro Yamada	ldr	r6, PTSTAT
63601fbec7SMasahiro Yamada	ldr	r7, [r6]
64601fbec7SMasahiro Yamada	ands	r7, r7, $0x02
65601fbec7SMasahiro Yamada	bne	checkStatClkStopGem
66601fbec7SMasahiro Yamada
67601fbec7SMasahiro Yamada	/* Check for GEM Reset Completion */
68601fbec7SMasahiro YamadacheckGemStatClkStop:
69601fbec7SMasahiro Yamada	ldr	r6, MDSTAT_GEM
70601fbec7SMasahiro Yamada	ldr	r7, [r6]
71601fbec7SMasahiro Yamada	ands	r7, r7, $0x100
72601fbec7SMasahiro Yamada	bne	checkGemStatClkStop
73601fbec7SMasahiro Yamada
74601fbec7SMasahiro Yamada	/* Do this for enabling a WDT initiated reset this is a workaround
75601fbec7SMasahiro Yamada	   for a chip bug.  Not required under normal situations */
76601fbec7SMasahiro Yamada	ldr	r6, P1394
77601fbec7SMasahiro Yamada	mov	r10, $0
78601fbec7SMasahiro Yamada	str	r10, [r6]
79601fbec7SMasahiro Yamada
80601fbec7SMasahiro Yamada	/*------------------------------------------------------*
81601fbec7SMasahiro Yamada	 * Enable L1 & L2 Memories in Fast mode                 *
82601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
83601fbec7SMasahiro Yamada	ldr	r6, DFT_ENABLE
84601fbec7SMasahiro Yamada	mov	r10, $0x01
85601fbec7SMasahiro Yamada	str	r10, [r6]
86601fbec7SMasahiro Yamada
87601fbec7SMasahiro Yamada	ldr	r6, MMARG_BRF0
88601fbec7SMasahiro Yamada	ldr	r10, MMARG_BRF0_VAL
89601fbec7SMasahiro Yamada	str	r10, [r6]
90601fbec7SMasahiro Yamada
91601fbec7SMasahiro Yamada	ldr	r6, DFT_ENABLE
92601fbec7SMasahiro Yamada	mov	r10, $0
93601fbec7SMasahiro Yamada	str	r10, [r6]
94601fbec7SMasahiro Yamada
95601fbec7SMasahiro Yamada	/*------------------------------------------------------*
96601fbec7SMasahiro Yamada	 * DDR2 PLL Initialization				*
97601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
98601fbec7SMasahiro Yamada
99601fbec7SMasahiro Yamada	/* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
100601fbec7SMasahiro Yamada	mov	r10, $0
101601fbec7SMasahiro Yamada	ldr	r6, PLL2_CTL
102601fbec7SMasahiro Yamada	ldr	r7, PLL_CLKSRC_MASK
103601fbec7SMasahiro Yamada	ldr	r8, [r6]
104601fbec7SMasahiro Yamada	and	r8, r8, r7
105601fbec7SMasahiro Yamada	mov	r9, r10, lsl $8
106601fbec7SMasahiro Yamada	orr	r8, r8, r9
107601fbec7SMasahiro Yamada	str	r8, [r6]
108601fbec7SMasahiro Yamada
109601fbec7SMasahiro Yamada	/* Select the PLLEN source */
110601fbec7SMasahiro Yamada	ldr	r7, PLL_ENSRC_MASK
111601fbec7SMasahiro Yamada	and	r8, r8, r7
112601fbec7SMasahiro Yamada	str	r8, [r6]
113601fbec7SMasahiro Yamada
114601fbec7SMasahiro Yamada	/* Bypass the PLL */
115601fbec7SMasahiro Yamada	ldr	r7, PLL_BYPASS_MASK
116601fbec7SMasahiro Yamada	and	r8, r8, r7
117601fbec7SMasahiro Yamada	str	r8, [r6]
118601fbec7SMasahiro Yamada
119601fbec7SMasahiro Yamada	/* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
120601fbec7SMasahiro Yamada	mov	r10, $0x20
121601fbec7SMasahiro YamadaWaitPPL2Loop:
122601fbec7SMasahiro Yamada	subs	r10, r10, $1
123601fbec7SMasahiro Yamada	bne	WaitPPL2Loop
124601fbec7SMasahiro Yamada
125601fbec7SMasahiro Yamada	/* Reset the PLL */
126601fbec7SMasahiro Yamada	ldr	r7, PLL_RESET_MASK
127601fbec7SMasahiro Yamada	and	r8, r8, r7
128601fbec7SMasahiro Yamada	str	r8, [r6]
129601fbec7SMasahiro Yamada
130601fbec7SMasahiro Yamada	/* Power up the PLL */
131601fbec7SMasahiro Yamada	ldr	r7, PLL_PWRUP_MASK
132601fbec7SMasahiro Yamada	and	r8, r8, r7
133601fbec7SMasahiro Yamada	str	r8, [r6]
134601fbec7SMasahiro Yamada
135601fbec7SMasahiro Yamada	/* Enable the PLL from Disable Mode */
136601fbec7SMasahiro Yamada	ldr	r7, PLL_DISABLE_ENABLE_MASK
137601fbec7SMasahiro Yamada	and	r8, r8, r7
138601fbec7SMasahiro Yamada	str	r8, [r6]
139601fbec7SMasahiro Yamada
140601fbec7SMasahiro Yamada	/* Program the PLL Multiplier */
141601fbec7SMasahiro Yamada	ldr	r6, PLL2_PLLM
142601fbec7SMasahiro Yamada	mov	r2, $0x17	/* 162 MHz */
143601fbec7SMasahiro Yamada	str	r2, [r6]
144601fbec7SMasahiro Yamada
145601fbec7SMasahiro Yamada	/* Program the PLL2 Divisor Value */
146601fbec7SMasahiro Yamada	ldr	r6, PLL2_DIV2
147601fbec7SMasahiro Yamada	mov	r3, $0x01
148601fbec7SMasahiro Yamada	str	r3, [r6]
149601fbec7SMasahiro Yamada
150601fbec7SMasahiro Yamada	/* Program the PLL2 Divisor Value */
151601fbec7SMasahiro Yamada	ldr	r6, PLL2_DIV1
152601fbec7SMasahiro Yamada	mov	r4, $0x0b	/* 54 MHz */
153601fbec7SMasahiro Yamada	str	r4, [r6]
154601fbec7SMasahiro Yamada
155601fbec7SMasahiro Yamada	/* PLL2 DIV2 MMR */
156601fbec7SMasahiro Yamada	ldr	r8, PLL2_DIV_MASK
157601fbec7SMasahiro Yamada	ldr	r6, PLL2_DIV2
158601fbec7SMasahiro Yamada	ldr	r9, [r6]
159601fbec7SMasahiro Yamada	and	r8, r8, r9
160601fbec7SMasahiro Yamada	mov	r9, $0x01
161601fbec7SMasahiro Yamada	mov	r9, r9, lsl $15
162601fbec7SMasahiro Yamada	orr	r8, r8, r9
163601fbec7SMasahiro Yamada	str	r8, [r6]
164601fbec7SMasahiro Yamada
165601fbec7SMasahiro Yamada	/* Program the GOSET bit to take new divider values */
166601fbec7SMasahiro Yamada	ldr	r6, PLL2_PLLCMD
167601fbec7SMasahiro Yamada	ldr	r7, [r6]
168601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
169601fbec7SMasahiro Yamada	str	r7, [r6]
170601fbec7SMasahiro Yamada
171601fbec7SMasahiro Yamada	/* Wait for Done */
172601fbec7SMasahiro Yamada	ldr	r6, PLL2_PLLSTAT
173601fbec7SMasahiro YamadadoneLoop_0:
174601fbec7SMasahiro Yamada	ldr	r7, [r6]
175601fbec7SMasahiro Yamada	ands	r7, r7, $0x01
176601fbec7SMasahiro Yamada	bne	doneLoop_0
177601fbec7SMasahiro Yamada
178601fbec7SMasahiro Yamada	/* PLL2 DIV1 MMR */
179601fbec7SMasahiro Yamada	ldr	r8, PLL2_DIV_MASK
180601fbec7SMasahiro Yamada	ldr	r6, PLL2_DIV1
181601fbec7SMasahiro Yamada	ldr	r9, [r6]
182601fbec7SMasahiro Yamada	and	r8, r8, r9
183601fbec7SMasahiro Yamada	mov	r9, $0x01
184601fbec7SMasahiro Yamada	mov	r9, r9, lsl $15
185601fbec7SMasahiro Yamada	orr	r8, r8, r9
186601fbec7SMasahiro Yamada	str	r8, [r6]
187601fbec7SMasahiro Yamada
188601fbec7SMasahiro Yamada	/* Program the GOSET bit to take new divider values */
189601fbec7SMasahiro Yamada	ldr	r6, PLL2_PLLCMD
190601fbec7SMasahiro Yamada	ldr	r7, [r6]
191601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
192601fbec7SMasahiro Yamada	str	r7, [r6]
193601fbec7SMasahiro Yamada
194601fbec7SMasahiro Yamada	/* Wait for Done */
195601fbec7SMasahiro Yamada	ldr	r6, PLL2_PLLSTAT
196601fbec7SMasahiro YamadadoneLoop:
197601fbec7SMasahiro Yamada	ldr	r7, [r6]
198601fbec7SMasahiro Yamada	ands	r7, r7, $0x01
199601fbec7SMasahiro Yamada	bne	doneLoop
200601fbec7SMasahiro Yamada
201601fbec7SMasahiro Yamada	/* Wait for PLL to Reset Properly */
202601fbec7SMasahiro Yamada	mov	r10, $0x218
203601fbec7SMasahiro YamadaResetPPL2Loop:
204601fbec7SMasahiro Yamada	subs	r10, r10, $1
205601fbec7SMasahiro Yamada	bne	ResetPPL2Loop
206601fbec7SMasahiro Yamada
207601fbec7SMasahiro Yamada	/* Bring PLL out of Reset */
208601fbec7SMasahiro Yamada	ldr	r6, PLL2_CTL
209601fbec7SMasahiro Yamada	ldr	r8, [r6]
210601fbec7SMasahiro Yamada	orr	r8, r8, $0x08
211601fbec7SMasahiro Yamada	str	r8, [r6]
212601fbec7SMasahiro Yamada
213601fbec7SMasahiro Yamada	/* Wait for PLL to Lock */
214601fbec7SMasahiro Yamada	ldr	r10, PLL_LOCK_COUNT
215601fbec7SMasahiro YamadaPLL2Lock:
216601fbec7SMasahiro Yamada	subs	r10, r10, $1
217601fbec7SMasahiro Yamada	bne	PLL2Lock
218601fbec7SMasahiro Yamada
219601fbec7SMasahiro Yamada	/* Enable the PLL */
220601fbec7SMasahiro Yamada	ldr	r6, PLL2_CTL
221601fbec7SMasahiro Yamada	ldr	r8, [r6]
222601fbec7SMasahiro Yamada	orr	r8, r8, $0x01
223601fbec7SMasahiro Yamada	str	r8, [r6]
224601fbec7SMasahiro Yamada
225601fbec7SMasahiro Yamada	/*------------------------------------------------------*
226601fbec7SMasahiro Yamada	 * Issue Soft Reset to DDR Module			*
227601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
228601fbec7SMasahiro Yamada
229601fbec7SMasahiro Yamada	/* Shut down the DDR2 LPSC Module */
230601fbec7SMasahiro Yamada	ldr	r8, PSC_FLAG_CLEAR
231601fbec7SMasahiro Yamada	ldr	r6, MDCTL_DDR2
232601fbec7SMasahiro Yamada	ldr	r7, [r6]
233601fbec7SMasahiro Yamada	and	r7, r7, r8
234601fbec7SMasahiro Yamada	orr	r7, r7, $0x03
235601fbec7SMasahiro Yamada	str	r7, [r6]
236601fbec7SMasahiro Yamada
237601fbec7SMasahiro Yamada	/* Enable the Power Domain Transition Command */
238601fbec7SMasahiro Yamada	ldr	r6, PTCMD
239601fbec7SMasahiro Yamada	ldr	r7, [r6]
240601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
241601fbec7SMasahiro Yamada	str	r7, [r6]
242601fbec7SMasahiro Yamada
243601fbec7SMasahiro Yamada	/* Check for Transition Complete(PTSTAT) */
244601fbec7SMasahiro YamadacheckStatClkStop:
245601fbec7SMasahiro Yamada	ldr	r6, PTSTAT
246601fbec7SMasahiro Yamada	ldr	r7, [r6]
247601fbec7SMasahiro Yamada	ands	r7, r7, $0x01
248601fbec7SMasahiro Yamada	bne	checkStatClkStop
249601fbec7SMasahiro Yamada
250601fbec7SMasahiro Yamada	/* Check for DDR2 Controller Enable Completion */
251601fbec7SMasahiro YamadacheckDDRStatClkStop:
252601fbec7SMasahiro Yamada	ldr	r6, MDSTAT_DDR2
253601fbec7SMasahiro Yamada	ldr	r7, [r6]
254601fbec7SMasahiro Yamada	and	r7, r7, $MDSTAT_STATE
255601fbec7SMasahiro Yamada	cmp	r7, $0x03
256601fbec7SMasahiro Yamada	bne	checkDDRStatClkStop
257601fbec7SMasahiro Yamada
258601fbec7SMasahiro Yamada	/*------------------------------------------------------*
259601fbec7SMasahiro Yamada	 * Program DDR2 MMRs for 162MHz Setting			*
260601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
261601fbec7SMasahiro Yamada
262601fbec7SMasahiro Yamada	/* Program PHY Control Register */
263601fbec7SMasahiro Yamada	ldr	r6, DDRCTL
264601fbec7SMasahiro Yamada	ldr	r7, DDRCTL_VAL
265601fbec7SMasahiro Yamada	str	r7, [r6]
266601fbec7SMasahiro Yamada
267601fbec7SMasahiro Yamada	/* Program SDRAM Bank Config Register */
268601fbec7SMasahiro Yamada	ldr	r6, SDCFG
269601fbec7SMasahiro Yamada	ldr	r7, SDCFG_VAL
270601fbec7SMasahiro Yamada	str	r7, [r6]
271601fbec7SMasahiro Yamada
272601fbec7SMasahiro Yamada	/* Program SDRAM TIM-0 Config Register */
273601fbec7SMasahiro Yamada	ldr	r6, SDTIM0
274601fbec7SMasahiro Yamada	ldr	r7, SDTIM0_VAL_162MHz
275601fbec7SMasahiro Yamada	str	r7, [r6]
276601fbec7SMasahiro Yamada
277601fbec7SMasahiro Yamada	/* Program SDRAM TIM-1 Config Register */
278601fbec7SMasahiro Yamada	ldr	r6, SDTIM1
279601fbec7SMasahiro Yamada	ldr	r7, SDTIM1_VAL_162MHz
280601fbec7SMasahiro Yamada	str	r7, [r6]
281601fbec7SMasahiro Yamada
282601fbec7SMasahiro Yamada	/* Program the SDRAM Bank Config Control Register */
283601fbec7SMasahiro Yamada	ldr	r10, MASK_VAL
284601fbec7SMasahiro Yamada	ldr	r8, SDCFG
285601fbec7SMasahiro Yamada	ldr	r9, SDCFG_VAL
286601fbec7SMasahiro Yamada	and	r9, r9, r10
287601fbec7SMasahiro Yamada	str	r9, [r8]
288601fbec7SMasahiro Yamada
289601fbec7SMasahiro Yamada	/* Program SDRAM SDREF Config Register */
290601fbec7SMasahiro Yamada	ldr	r6, SDREF
291601fbec7SMasahiro Yamada	ldr	r7, SDREF_VAL
292601fbec7SMasahiro Yamada	str	r7, [r6]
293601fbec7SMasahiro Yamada
294601fbec7SMasahiro Yamada	/*------------------------------------------------------*
295601fbec7SMasahiro Yamada	 * Issue Soft Reset to DDR Module			*
296601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
297601fbec7SMasahiro Yamada
298601fbec7SMasahiro Yamada	/* Issue a Dummy DDR2 read/write */
299601fbec7SMasahiro Yamada	ldr	r8, DDR2_START_ADDR
300601fbec7SMasahiro Yamada	ldr	r7, DUMMY_VAL
301601fbec7SMasahiro Yamada	str	r7, [r8]
302601fbec7SMasahiro Yamada	ldr	r7, [r8]
303601fbec7SMasahiro Yamada
304601fbec7SMasahiro Yamada	/* Shut down the DDR2 LPSC Module */
305601fbec7SMasahiro Yamada	ldr	r8, PSC_FLAG_CLEAR
306601fbec7SMasahiro Yamada	ldr	r6, MDCTL_DDR2
307601fbec7SMasahiro Yamada	ldr	r7, [r6]
308601fbec7SMasahiro Yamada	and	r7, r7, r8
309601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
310601fbec7SMasahiro Yamada	str	r7, [r6]
311601fbec7SMasahiro Yamada
312601fbec7SMasahiro Yamada	/* Enable the Power Domain Transition Command */
313601fbec7SMasahiro Yamada	ldr	r6, PTCMD
314601fbec7SMasahiro Yamada	ldr	r7, [r6]
315601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
316601fbec7SMasahiro Yamada	str	r7, [r6]
317601fbec7SMasahiro Yamada
318601fbec7SMasahiro Yamada	/* Check for Transition Complete(PTSTAT) */
319601fbec7SMasahiro YamadacheckStatClkStop2:
320601fbec7SMasahiro Yamada	ldr	r6, PTSTAT
321601fbec7SMasahiro Yamada	ldr	r7, [r6]
322601fbec7SMasahiro Yamada	ands	r7, r7, $0x01
323601fbec7SMasahiro Yamada	bne	checkStatClkStop2
324601fbec7SMasahiro Yamada
325601fbec7SMasahiro Yamada	/* Check for DDR2 Controller Enable Completion */
326601fbec7SMasahiro YamadacheckDDRStatClkStop2:
327601fbec7SMasahiro Yamada	ldr	r6, MDSTAT_DDR2
328601fbec7SMasahiro Yamada	ldr	r7, [r6]
329601fbec7SMasahiro Yamada	and	r7, r7, $MDSTAT_STATE
330601fbec7SMasahiro Yamada	cmp	r7, $0x01
331601fbec7SMasahiro Yamada	bne	checkDDRStatClkStop2
332601fbec7SMasahiro Yamada
333601fbec7SMasahiro Yamada	/*------------------------------------------------------*
334601fbec7SMasahiro Yamada	 * Turn DDR2 Controller Clocks On			*
335601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
336601fbec7SMasahiro Yamada
337601fbec7SMasahiro Yamada	/* Enable the DDR2 LPSC Module */
338601fbec7SMasahiro Yamada	ldr	r6, MDCTL_DDR2
339601fbec7SMasahiro Yamada	ldr	r7, [r6]
340601fbec7SMasahiro Yamada	orr	r7, r7, $0x03
341601fbec7SMasahiro Yamada	str	r7, [r6]
342601fbec7SMasahiro Yamada
343601fbec7SMasahiro Yamada	/* Enable the Power Domain Transition Command */
344601fbec7SMasahiro Yamada	ldr	r6, PTCMD
345601fbec7SMasahiro Yamada	ldr	r7, [r6]
346601fbec7SMasahiro Yamada	orr	r7, r7, $0x01
347601fbec7SMasahiro Yamada	str	r7, [r6]
348601fbec7SMasahiro Yamada
349601fbec7SMasahiro Yamada	/* Check for Transition Complete(PTSTAT) */
350601fbec7SMasahiro YamadacheckStatClkEn2:
351601fbec7SMasahiro Yamada	ldr	r6, PTSTAT
352601fbec7SMasahiro Yamada	ldr	r7, [r6]
353601fbec7SMasahiro Yamada	ands	r7, r7, $0x01
354601fbec7SMasahiro Yamada	bne	checkStatClkEn2
355601fbec7SMasahiro Yamada
356601fbec7SMasahiro Yamada	/* Check for DDR2 Controller Enable Completion */
357601fbec7SMasahiro YamadacheckDDRStatClkEn2:
358601fbec7SMasahiro Yamada	ldr	r6, MDSTAT_DDR2
359601fbec7SMasahiro Yamada	ldr	r7, [r6]
360601fbec7SMasahiro Yamada	and	r7, r7, $MDSTAT_STATE
361601fbec7SMasahiro Yamada	cmp	r7, $0x03
362601fbec7SMasahiro Yamada	bne	checkDDRStatClkEn2
363601fbec7SMasahiro Yamada
364601fbec7SMasahiro Yamada	/*  DDR Writes and Reads */
365601fbec7SMasahiro Yamada	ldr	r6, CFGTEST
366601fbec7SMasahiro Yamada	mov	r3, $0x01
367601fbec7SMasahiro Yamada	str	r3, [r6]
368601fbec7SMasahiro Yamada
369601fbec7SMasahiro Yamada	/*------------------------------------------------------*
370601fbec7SMasahiro Yamada	 * System PLL Initialization				*
371601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
372601fbec7SMasahiro Yamada
373601fbec7SMasahiro Yamada	/* Select the Clock Mode Depending on the Value written in the Boot Table by the run script */
374601fbec7SMasahiro Yamada	mov	r2, $0
375601fbec7SMasahiro Yamada	ldr	r6, PLL1_CTL
376601fbec7SMasahiro Yamada	ldr	r7, PLL_CLKSRC_MASK
377601fbec7SMasahiro Yamada	ldr	r8, [r6]
378601fbec7SMasahiro Yamada	and	r8, r8, r7
379601fbec7SMasahiro Yamada	mov	r9, r2, lsl $8
380601fbec7SMasahiro Yamada	orr	r8, r8, r9
381601fbec7SMasahiro Yamada	str	r8, [r6]
382601fbec7SMasahiro Yamada
383601fbec7SMasahiro Yamada	/* Select the PLLEN source */
384601fbec7SMasahiro Yamada	ldr	r7, PLL_ENSRC_MASK
385601fbec7SMasahiro Yamada	and	r8, r8, r7
386601fbec7SMasahiro Yamada	str	r8, [r6]
387601fbec7SMasahiro Yamada
388601fbec7SMasahiro Yamada	/* Bypass the PLL */
389601fbec7SMasahiro Yamada	ldr	r7, PLL_BYPASS_MASK
390601fbec7SMasahiro Yamada	and	r8, r8, r7
391601fbec7SMasahiro Yamada	str	r8, [r6]
392601fbec7SMasahiro Yamada
393601fbec7SMasahiro Yamada	/* Wait for few cycles to allow PLLEN Mux switch properly to bypass Clock */
394601fbec7SMasahiro Yamada	mov	r10, $0x20
395601fbec7SMasahiro Yamada
396601fbec7SMasahiro YamadaWaitLoop:
397601fbec7SMasahiro Yamada	subs	r10, r10, $1
398601fbec7SMasahiro Yamada	bne	WaitLoop
399601fbec7SMasahiro Yamada
400601fbec7SMasahiro Yamada	/* Reset the PLL */
401601fbec7SMasahiro Yamada	ldr	r7, PLL_RESET_MASK
402601fbec7SMasahiro Yamada	and	r8, r8, r7
403601fbec7SMasahiro Yamada	str	r8, [r6]
404601fbec7SMasahiro Yamada
405601fbec7SMasahiro Yamada	/* Disable the PLL */
406601fbec7SMasahiro Yamada	orr	r8, r8, $0x10
407601fbec7SMasahiro Yamada	str	r8, [r6]
408601fbec7SMasahiro Yamada
409601fbec7SMasahiro Yamada	/* Power up the PLL */
410601fbec7SMasahiro Yamada	ldr	r7, PLL_PWRUP_MASK
411601fbec7SMasahiro Yamada	and	r8, r8, r7
412601fbec7SMasahiro Yamada	str	r8, [r6]
413601fbec7SMasahiro Yamada
414601fbec7SMasahiro Yamada	/* Enable the PLL from Disable Mode */
415601fbec7SMasahiro Yamada	ldr	r7, PLL_DISABLE_ENABLE_MASK
416601fbec7SMasahiro Yamada	and	r8, r8, r7
417601fbec7SMasahiro Yamada	str	r8, [r6]
418601fbec7SMasahiro Yamada
419601fbec7SMasahiro Yamada	/* Program the PLL Multiplier */
420601fbec7SMasahiro Yamada	ldr	r6, PLL1_PLLM
421601fbec7SMasahiro Yamada	mov	r3, $0x15	/* For 594MHz */
422601fbec7SMasahiro Yamada	str	r3, [r6]
423601fbec7SMasahiro Yamada
424601fbec7SMasahiro Yamada	/* Wait for PLL to Reset Properly */
425601fbec7SMasahiro Yamada	mov	r10, $0xff
426601fbec7SMasahiro Yamada
427601fbec7SMasahiro YamadaResetLoop:
428601fbec7SMasahiro Yamada	subs	r10, r10, $1
429601fbec7SMasahiro Yamada	bne	ResetLoop
430601fbec7SMasahiro Yamada
431601fbec7SMasahiro Yamada	/* Bring PLL out of Reset */
432601fbec7SMasahiro Yamada	ldr	r6, PLL1_CTL
433601fbec7SMasahiro Yamada	orr	r8, r8, $0x08
434601fbec7SMasahiro Yamada	str	r8, [r6]
435601fbec7SMasahiro Yamada
436601fbec7SMasahiro Yamada	/* Wait for PLL to Lock */
437601fbec7SMasahiro Yamada	ldr	r10, PLL_LOCK_COUNT
438601fbec7SMasahiro Yamada
439601fbec7SMasahiro YamadaPLL1Lock:
440601fbec7SMasahiro Yamada	subs	r10, r10, $1
441601fbec7SMasahiro Yamada	bne	PLL1Lock
442601fbec7SMasahiro Yamada
443601fbec7SMasahiro Yamada	/* Enable the PLL */
444601fbec7SMasahiro Yamada	orr	r8, r8, $0x01
445601fbec7SMasahiro Yamada	str	r8, [r6]
446601fbec7SMasahiro Yamada
447601fbec7SMasahiro Yamada	nop
448601fbec7SMasahiro Yamada	nop
449601fbec7SMasahiro Yamada	nop
450601fbec7SMasahiro Yamada	nop
451601fbec7SMasahiro Yamada
452601fbec7SMasahiro Yamada	/*------------------------------------------------------*
453601fbec7SMasahiro Yamada	 * AEMIF configuration for NOR Flash (double check)     *
454601fbec7SMasahiro Yamada	 *------------------------------------------------------*/
455601fbec7SMasahiro Yamada	ldr	r0, _PINMUX0
456601fbec7SMasahiro Yamada	ldr	r1, _DEV_SETTING
457601fbec7SMasahiro Yamada	str	r1, [r0]
458601fbec7SMasahiro Yamada
459601fbec7SMasahiro Yamada	ldr	r0, WAITCFG
460601fbec7SMasahiro Yamada	ldr	r1, WAITCFG_VAL
461601fbec7SMasahiro Yamada	ldr	r2, [r0]
462601fbec7SMasahiro Yamada	orr	r2, r2, r1
463601fbec7SMasahiro Yamada	str	r2, [r0]
464601fbec7SMasahiro Yamada
465601fbec7SMasahiro Yamada	ldr	r0, ACFG3
466601fbec7SMasahiro Yamada	ldr	r1, ACFG3_VAL
467601fbec7SMasahiro Yamada	ldr	r2, [r0]
468601fbec7SMasahiro Yamada	and	r1, r2, r1
469601fbec7SMasahiro Yamada	str	r1, [r0]
470601fbec7SMasahiro Yamada
471601fbec7SMasahiro Yamada	ldr	r0, ACFG4
472601fbec7SMasahiro Yamada	ldr	r1, ACFG4_VAL
473601fbec7SMasahiro Yamada	ldr	r2, [r0]
474601fbec7SMasahiro Yamada	and	r1, r2, r1
475601fbec7SMasahiro Yamada	str	r1, [r0]
476601fbec7SMasahiro Yamada
477601fbec7SMasahiro Yamada	ldr	r0, ACFG5
478601fbec7SMasahiro Yamada	ldr	r1, ACFG5_VAL
479601fbec7SMasahiro Yamada	ldr	r2, [r0]
480601fbec7SMasahiro Yamada	and	r1, r2, r1
481601fbec7SMasahiro Yamada	str	r1, [r0]
482601fbec7SMasahiro Yamada
483601fbec7SMasahiro Yamada	/*--------------------------------------*
484601fbec7SMasahiro Yamada	 * VTP manual Calibration               *
485601fbec7SMasahiro Yamada	 *--------------------------------------*/
486601fbec7SMasahiro Yamada	ldr	r0, VTPIOCR
487601fbec7SMasahiro Yamada	ldr	r1, VTP_MMR0
488601fbec7SMasahiro Yamada	str	r1, [r0]
489601fbec7SMasahiro Yamada
490601fbec7SMasahiro Yamada	ldr	r0, VTPIOCR
491601fbec7SMasahiro Yamada	ldr	r1, VTP_MMR1
492601fbec7SMasahiro Yamada	str	r1, [r0]
493601fbec7SMasahiro Yamada
494601fbec7SMasahiro Yamada	/* Wait for 33 VTP CLK cycles.  VRP operates at 27 MHz */
495601fbec7SMasahiro Yamada	ldr	r10, VTP_LOCK_COUNT
496601fbec7SMasahiro YamadaVTPLock:
497601fbec7SMasahiro Yamada	subs	r10, r10, $1
498601fbec7SMasahiro Yamada	bne	VTPLock
499601fbec7SMasahiro Yamada
500601fbec7SMasahiro Yamada	ldr	r6, DFT_ENABLE
501601fbec7SMasahiro Yamada	mov	r10, $0x01
502601fbec7SMasahiro Yamada	str	r10, [r6]
503601fbec7SMasahiro Yamada
504601fbec7SMasahiro Yamada	ldr	r6, DDRVTPR
505601fbec7SMasahiro Yamada	ldr	r7, [r6]
506601fbec7SMasahiro Yamada	mov	r8, r7, LSL #32-10
507601fbec7SMasahiro Yamada	mov	r8, r8, LSR #32-10        /* grab low 10 bits  */
508601fbec7SMasahiro Yamada	ldr	r7, VTP_RECAL
509601fbec7SMasahiro Yamada	orr	r8, r7, r8
510601fbec7SMasahiro Yamada	ldr	r7, VTP_EN
511601fbec7SMasahiro Yamada	orr	r8, r7, r8
512601fbec7SMasahiro Yamada	str	r8, [r0]
513601fbec7SMasahiro Yamada
514601fbec7SMasahiro Yamada
515601fbec7SMasahiro Yamada	/* Wait for 33 VTP CLK cycles.  VRP operates at 27 MHz */
516601fbec7SMasahiro Yamada	ldr	r10, VTP_LOCK_COUNT
517601fbec7SMasahiro YamadaVTP1Lock:
518601fbec7SMasahiro Yamada	subs	r10, r10, $1
519601fbec7SMasahiro Yamada	bne	VTP1Lock
520601fbec7SMasahiro Yamada
521601fbec7SMasahiro Yamada	ldr	r1, [r0]
522601fbec7SMasahiro Yamada	ldr	r2, VTP_MASK
523601fbec7SMasahiro Yamada	and	r2, r1, r2
524601fbec7SMasahiro Yamada	str	r2, [r0]
525601fbec7SMasahiro Yamada
526601fbec7SMasahiro Yamada	ldr	r6, DFT_ENABLE
527601fbec7SMasahiro Yamada	mov	r10, $0
528601fbec7SMasahiro Yamada	str	r10, [r6]
529601fbec7SMasahiro Yamada
530601fbec7SMasahiro Yamada	/*
531601fbec7SMasahiro Yamada	 * Call board-specific lowlevel init.
532601fbec7SMasahiro Yamada	 * That MUST be present and THAT returns
533601fbec7SMasahiro Yamada	 * back to arch calling code with "mov pc, lr."
534601fbec7SMasahiro Yamada	 */
535601fbec7SMasahiro Yamada	b	dv_board_init
536601fbec7SMasahiro Yamada
537601fbec7SMasahiro Yamada.ltorg
538601fbec7SMasahiro Yamada
539601fbec7SMasahiro Yamada_PINMUX0:
540601fbec7SMasahiro Yamada	.word	0x01c40000		/* Device Configuration Registers */
541601fbec7SMasahiro Yamada_PINMUX1:
542601fbec7SMasahiro Yamada	.word	0x01c40004		/* Device Configuration Registers */
543601fbec7SMasahiro Yamada
544601fbec7SMasahiro Yamada_DEV_SETTING:
545601fbec7SMasahiro Yamada	.word	0x00000c1f
546601fbec7SMasahiro Yamada
547601fbec7SMasahiro YamadaWAITCFG:
548601fbec7SMasahiro Yamada	.word	0x01e00004
549601fbec7SMasahiro YamadaWAITCFG_VAL:
550601fbec7SMasahiro Yamada	.word	0
551601fbec7SMasahiro YamadaACFG3:
552601fbec7SMasahiro Yamada	.word	0x01e00014
553601fbec7SMasahiro YamadaACFG3_VAL:
554601fbec7SMasahiro Yamada	.word	0x3ffffffd
555601fbec7SMasahiro YamadaACFG4:
556601fbec7SMasahiro Yamada	.word	0x01e00018
557601fbec7SMasahiro YamadaACFG4_VAL:
558601fbec7SMasahiro Yamada	.word	0x3ffffffd
559601fbec7SMasahiro YamadaACFG5:
560601fbec7SMasahiro Yamada	.word	0x01e0001c
561601fbec7SMasahiro YamadaACFG5_VAL:
562601fbec7SMasahiro Yamada	.word	0x3ffffffd
563601fbec7SMasahiro Yamada
564601fbec7SMasahiro YamadaMDCTL_DDR2:
565601fbec7SMasahiro Yamada	.word	0x01c41a34
566601fbec7SMasahiro YamadaMDSTAT_DDR2:
567601fbec7SMasahiro Yamada	.word	0x01c41834
568601fbec7SMasahiro Yamada
569601fbec7SMasahiro YamadaPTCMD:
570601fbec7SMasahiro Yamada	.word	0x01c41120
571601fbec7SMasahiro YamadaPTSTAT:
572601fbec7SMasahiro Yamada	.word	0x01c41128
573601fbec7SMasahiro Yamada
574601fbec7SMasahiro YamadaEINT_ENABLE0:
575601fbec7SMasahiro Yamada	.word	0x01c48018
576601fbec7SMasahiro YamadaEINT_ENABLE1:
577601fbec7SMasahiro Yamada	.word	0x01c4801c
578601fbec7SMasahiro Yamada
579601fbec7SMasahiro YamadaPSC_FLAG_CLEAR:
580601fbec7SMasahiro Yamada	.word	0xffffffe0
581601fbec7SMasahiro YamadaPSC_GEM_FLAG_CLEAR:
582601fbec7SMasahiro Yamada	.word	0xfffffeff
583601fbec7SMasahiro Yamada
584601fbec7SMasahiro Yamada/* DDR2 MMR & CONFIGURATION VALUES, 162 MHZ clock */
585601fbec7SMasahiro YamadaDDRCTL:
586601fbec7SMasahiro Yamada	.word	0x200000e4
587601fbec7SMasahiro YamadaDDRCTL_VAL:
588601fbec7SMasahiro Yamada	.word	0x50006405
589601fbec7SMasahiro YamadaSDREF:
590601fbec7SMasahiro Yamada	.word	0x2000000c
591601fbec7SMasahiro YamadaSDREF_VAL:
592601fbec7SMasahiro Yamada	.word	0x000005c3
593601fbec7SMasahiro YamadaSDCFG:
594601fbec7SMasahiro Yamada	.word	0x20000008
595601fbec7SMasahiro YamadaSDCFG_VAL:
596601fbec7SMasahiro Yamada#ifdef	DDR_4BANKS
597601fbec7SMasahiro Yamada	.word	0x00178622
598601fbec7SMasahiro Yamada#elif defined DDR_8BANKS
599601fbec7SMasahiro Yamada	.word	0x00178632
600601fbec7SMasahiro Yamada#else
601601fbec7SMasahiro Yamada#error "Unknown DDR configuration!!!"
602601fbec7SMasahiro Yamada#endif
603601fbec7SMasahiro YamadaSDTIM0:
604601fbec7SMasahiro Yamada	.word	0x20000010
605601fbec7SMasahiro YamadaSDTIM0_VAL_162MHz:
606601fbec7SMasahiro Yamada	.word	0x28923211
607601fbec7SMasahiro YamadaSDTIM1:
608601fbec7SMasahiro Yamada	.word	0x20000014
609601fbec7SMasahiro YamadaSDTIM1_VAL_162MHz:
610601fbec7SMasahiro Yamada	.word	0x0016c722
611601fbec7SMasahiro YamadaVTPIOCR:
612601fbec7SMasahiro Yamada	.word	0x200000f0	/* VTP IO Control register */
613601fbec7SMasahiro YamadaDDRVTPR:
614601fbec7SMasahiro Yamada	.word	0x01c42030	/* DDR VPTR MMR */
615601fbec7SMasahiro YamadaVTP_MMR0:
616601fbec7SMasahiro Yamada	.word	0x201f
617601fbec7SMasahiro YamadaVTP_MMR1:
618601fbec7SMasahiro Yamada	.word	0xa01f
619601fbec7SMasahiro YamadaDFT_ENABLE:
620601fbec7SMasahiro Yamada	.word	0x01c4004c
621601fbec7SMasahiro YamadaVTP_LOCK_COUNT:
622601fbec7SMasahiro Yamada	.word	0x5b0
623601fbec7SMasahiro YamadaVTP_MASK:
624601fbec7SMasahiro Yamada	.word	0xffffdfff
625601fbec7SMasahiro YamadaVTP_RECAL:
626601fbec7SMasahiro Yamada	.word	0x08000
627601fbec7SMasahiro YamadaVTP_EN:
628601fbec7SMasahiro Yamada	.word	0x02000
629601fbec7SMasahiro YamadaCFGTEST:
630601fbec7SMasahiro Yamada	.word	0x80010000
631601fbec7SMasahiro YamadaMASK_VAL:
632601fbec7SMasahiro Yamada	.word	0x00000fff
633601fbec7SMasahiro Yamada
634601fbec7SMasahiro Yamada/* GEM Power Up & LPSC Control Register */
635601fbec7SMasahiro YamadaMDCTL_GEM:
636601fbec7SMasahiro Yamada	.word	0x01c41a9c
637601fbec7SMasahiro YamadaMDSTAT_GEM:
638601fbec7SMasahiro Yamada	.word	0x01c4189c
639601fbec7SMasahiro Yamada
640601fbec7SMasahiro Yamada/* For WDT reset chip bug */
641601fbec7SMasahiro YamadaP1394:
642601fbec7SMasahiro Yamada	.word	0x01c41a20
643601fbec7SMasahiro Yamada
644601fbec7SMasahiro YamadaPLL_CLKSRC_MASK:
645601fbec7SMasahiro Yamada	.word	0xfffffeff	/* Mask the Clock Mode bit */
646601fbec7SMasahiro YamadaPLL_ENSRC_MASK:
647601fbec7SMasahiro Yamada	.word	0xffffffdf	/* Select the PLLEN source */
648601fbec7SMasahiro YamadaPLL_BYPASS_MASK:
649601fbec7SMasahiro Yamada	.word	0xfffffffe	/* Put the PLL in BYPASS */
650601fbec7SMasahiro YamadaPLL_RESET_MASK:
651601fbec7SMasahiro Yamada	.word	0xfffffff7	/* Put the PLL in Reset Mode */
652601fbec7SMasahiro YamadaPLL_PWRUP_MASK:
653601fbec7SMasahiro Yamada	.word	0xfffffffd	/* PLL Power up Mask Bit  */
654601fbec7SMasahiro YamadaPLL_DISABLE_ENABLE_MASK:
655601fbec7SMasahiro Yamada	.word	0xffffffef	/* Enable the PLL from Disable */
656601fbec7SMasahiro YamadaPLL_LOCK_COUNT:
657601fbec7SMasahiro Yamada	.word	0x2000
658601fbec7SMasahiro Yamada
659601fbec7SMasahiro Yamada/* PLL1-SYSTEM PLL MMRs */
660601fbec7SMasahiro YamadaPLL1_CTL:
661601fbec7SMasahiro Yamada	.word	0x01c40900
662601fbec7SMasahiro YamadaPLL1_PLLM:
663601fbec7SMasahiro Yamada	.word	0x01c40910
664601fbec7SMasahiro Yamada
665601fbec7SMasahiro Yamada/* PLL2-SYSTEM PLL MMRs */
666601fbec7SMasahiro YamadaPLL2_CTL:
667601fbec7SMasahiro Yamada	.word	0x01c40d00
668601fbec7SMasahiro YamadaPLL2_PLLM:
669601fbec7SMasahiro Yamada	.word	0x01c40d10
670601fbec7SMasahiro YamadaPLL2_DIV1:
671601fbec7SMasahiro Yamada	.word	0x01c40d18
672601fbec7SMasahiro YamadaPLL2_DIV2:
673601fbec7SMasahiro Yamada	.word	0x01c40d1c
674601fbec7SMasahiro YamadaPLL2_PLLCMD:
675601fbec7SMasahiro Yamada	.word	0x01c40d38
676601fbec7SMasahiro YamadaPLL2_PLLSTAT:
677601fbec7SMasahiro Yamada	.word	0x01c40d3c
678601fbec7SMasahiro YamadaPLL2_DIV_MASK:
679601fbec7SMasahiro Yamada	.word	0xffff7fff
680601fbec7SMasahiro Yamada
681601fbec7SMasahiro YamadaMMARG_BRF0:
682601fbec7SMasahiro Yamada	.word	0x01c42010	/* BRF margin mode 0 (R/W)*/
683601fbec7SMasahiro YamadaMMARG_BRF0_VAL:
684601fbec7SMasahiro Yamada	.word	0x00444400
685601fbec7SMasahiro Yamada
686601fbec7SMasahiro YamadaDDR2_START_ADDR:
687601fbec7SMasahiro Yamada	.word	0x80000000
688601fbec7SMasahiro YamadaDUMMY_VAL:
689601fbec7SMasahiro Yamada	.word	0xa55aa55a
690601fbec7SMasahiro Yamada#else /* CONFIG_SOC_DM644X */
691601fbec7SMasahiro Yamada	mov pc, lr
692601fbec7SMasahiro Yamada#endif
693