xref: /openbmc/u-boot/arch/arm/mach-orion5x/lowlevel_init.S (revision 66a00be2878dc0f972a6e100e91af5942ef8f736)
183d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */
23e93b4e6SMasahiro Yamada/*
33e93b4e6SMasahiro Yamada * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
43e93b4e6SMasahiro Yamada *
53e93b4e6SMasahiro Yamada * (C) Copyright 2009
63e93b4e6SMasahiro Yamada * Marvell Semiconductor <www.marvell.com>
73e93b4e6SMasahiro Yamada * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
83e93b4e6SMasahiro Yamada */
93e93b4e6SMasahiro Yamada
103e93b4e6SMasahiro Yamada#include <config.h>
113e93b4e6SMasahiro Yamada#include "asm/arch/orion5x.h"
123e93b4e6SMasahiro Yamada
133e93b4e6SMasahiro Yamada/*
143e93b4e6SMasahiro Yamada * Configuration values for SDRAM access setup
153e93b4e6SMasahiro Yamada */
163e93b4e6SMasahiro Yamada
173e93b4e6SMasahiro Yamada#define SDRAM_CONFIG			0x3148400
183e93b4e6SMasahiro Yamada#define SDRAM_MODE			0x62
193e93b4e6SMasahiro Yamada#define SDRAM_CONTROL			0x4041000
203e93b4e6SMasahiro Yamada#define SDRAM_TIME_CTRL_LOW		0x11602220
213e93b4e6SMasahiro Yamada#define SDRAM_TIME_CTRL_HI		0x40c
223e93b4e6SMasahiro Yamada#define SDRAM_OPEN_PAGE_EN		0x0
233e93b4e6SMasahiro Yamada/* DDR 1 2x 32M NANYA NT5DS16M16CS-6K ==> 64MB */
243e93b4e6SMasahiro Yamada#define SDRAM_BANK0_SIZE		0x3ff0001
253e93b4e6SMasahiro Yamada#define SDRAM_ADDR_CTRL			0x10
263e93b4e6SMasahiro Yamada
273e93b4e6SMasahiro Yamada#define SDRAM_OP_NOP			0x05
283e93b4e6SMasahiro Yamada#define SDRAM_OP_SETMODE		0x03
293e93b4e6SMasahiro Yamada
303e93b4e6SMasahiro Yamada#define SDRAM_PAD_CTRL_WR_EN		0x80000000
313e93b4e6SMasahiro Yamada#define SDRAM_PAD_CTRL_TUNE_EN		0x00010000
323e93b4e6SMasahiro Yamada#define SDRAM_PAD_CTRL_DRVN_MASK	0x0000003f
333e93b4e6SMasahiro Yamada#define SDRAM_PAD_CTRL_DRVP_MASK	0x00000fc0
343e93b4e6SMasahiro Yamada
353e93b4e6SMasahiro Yamada/*
363e93b4e6SMasahiro Yamada * For Guideline MEM-3 - Drive Strength value
373e93b4e6SMasahiro Yamada */
383e93b4e6SMasahiro Yamada
393e93b4e6SMasahiro Yamada#define DDR1_PAD_STRENGTH_DEFAULT	0x00001000
403e93b4e6SMasahiro Yamada#define SDRAM_PAD_CTRL_DRV_STR_MASK	0x00003000
413e93b4e6SMasahiro Yamada
423e93b4e6SMasahiro Yamada/*
433e93b4e6SMasahiro Yamada * For Guideline MEM-4 - DQS Reference Delay Tuning
443e93b4e6SMasahiro Yamada */
453e93b4e6SMasahiro Yamada
463e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_MASK		0x000000f0
473e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_H_MASK		0x00000100
483e93b4e6SMasahiro Yamada
493e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_333_167		0x00000000
503e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_500_167		0x00000030
513e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_667_167		0x00000060
523e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_400_200_1	0x000001E0
533e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_400_200		0x00000010
543e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_600_200		0x00000050
553e93b4e6SMasahiro Yamada#define MSAR_ARMDDRCLCK_800_200		0x00000070
563e93b4e6SMasahiro Yamada
573e93b4e6SMasahiro Yamada#define FTDLL_DDR1_166MHZ		0x0047F001
583e93b4e6SMasahiro Yamada
593e93b4e6SMasahiro Yamada#define FTDLL_DDR1_200MHZ		0x0044D001
603e93b4e6SMasahiro Yamada
613e93b4e6SMasahiro Yamada/*
623e93b4e6SMasahiro Yamada * Low-level init happens right after start.S has switched to SVC32,
633e93b4e6SMasahiro Yamada * flushed and disabled caches and disabled MMU. We're still running
649608e7deSAlbert ARIBAUD * from the boot chip select, so the first thing SPL should do is to
659608e7deSAlbert ARIBAUD * set up the RAM to copy U-Boot into.
663e93b4e6SMasahiro Yamada */
673e93b4e6SMasahiro Yamada
683e93b4e6SMasahiro Yamada.globl lowlevel_init
693e93b4e6SMasahiro Yamada
703e93b4e6SMasahiro Yamadalowlevel_init:
713e93b4e6SMasahiro Yamada
729608e7deSAlbert ARIBAUD#ifdef CONFIG_SPL_BUILD
739608e7deSAlbert ARIBAUD
74*66a00be2SMans Rullgard	/* Use 'r2 as the base for internal register accesses */
75*66a00be2SMans Rullgard	ldr	r2, =ORION5X_REGS_PHY_BASE
763e93b4e6SMasahiro Yamada
773e93b4e6SMasahiro Yamada	/* move internal registers from the default 0xD0000000
783e93b4e6SMasahiro Yamada	 * to their intended location, defined by SoC */
793e93b4e6SMasahiro Yamada	ldr	r3, =0xD0000000
803e93b4e6SMasahiro Yamada	add	r3, r3, #0x20000
81*66a00be2SMans Rullgard	str	r2, [r3, #0x80]
823e93b4e6SMasahiro Yamada
833e93b4e6SMasahiro Yamada	/* Use R3 as the base for DRAM registers */
84*66a00be2SMans Rullgard	add	r3, r2, #0x01000
853e93b4e6SMasahiro Yamada
863e93b4e6SMasahiro Yamada	/*DDR SDRAM Initialization Control */
87*66a00be2SMans Rullgard	ldr	r0, =0x00000001
88*66a00be2SMans Rullgard	str	r0, [r3, #0x480]
893e93b4e6SMasahiro Yamada
903e93b4e6SMasahiro Yamada	/* Use R3 as the base for PCI registers */
91*66a00be2SMans Rullgard	add	r3, r2, #0x31000
923e93b4e6SMasahiro Yamada
933e93b4e6SMasahiro Yamada	/* Disable arbiter */
94*66a00be2SMans Rullgard	ldr	r0, =0x00000030
95*66a00be2SMans Rullgard	str	r0, [r3, #0xd00]
963e93b4e6SMasahiro Yamada
973e93b4e6SMasahiro Yamada	/* Use R3 as the base for DRAM registers */
98*66a00be2SMans Rullgard	add	r3, r2, #0x01000
993e93b4e6SMasahiro Yamada
1003e93b4e6SMasahiro Yamada	/* set all dram windows to 0 */
101*66a00be2SMans Rullgard	mov	r0, #0
102*66a00be2SMans Rullgard	str	r0, [r3, #0x504]
103*66a00be2SMans Rullgard	str	r0, [r3, #0x50C]
104*66a00be2SMans Rullgard	str	r0, [r3, #0x514]
105*66a00be2SMans Rullgard	str	r0, [r3, #0x51C]
1063e93b4e6SMasahiro Yamada
1073e93b4e6SMasahiro Yamada	/* 1) Configure SDRAM  */
108*66a00be2SMans Rullgard	ldr	r0, =SDRAM_CONFIG
109*66a00be2SMans Rullgard	str	r0, [r3, #0x400]
1103e93b4e6SMasahiro Yamada
1113e93b4e6SMasahiro Yamada	/* 2) Set SDRAM Control reg */
112*66a00be2SMans Rullgard	ldr	r0, =SDRAM_CONTROL
113*66a00be2SMans Rullgard	str	r0, [r3, #0x404]
1143e93b4e6SMasahiro Yamada
1153e93b4e6SMasahiro Yamada	/* 3) Write SDRAM address control register */
116*66a00be2SMans Rullgard	ldr	r0, =SDRAM_ADDR_CTRL
117*66a00be2SMans Rullgard	str	r0, [r3, #0x410]
1183e93b4e6SMasahiro Yamada
1193e93b4e6SMasahiro Yamada	/* 4) Write SDRAM bank 0 size register */
120*66a00be2SMans Rullgard	ldr	r0, =SDRAM_BANK0_SIZE
121*66a00be2SMans Rullgard	str	r0, [r3, #0x504]
1223e93b4e6SMasahiro Yamada	/* keep other banks disabled */
1233e93b4e6SMasahiro Yamada
1243e93b4e6SMasahiro Yamada	/* 5) Write SDRAM open pages control register */
125*66a00be2SMans Rullgard	ldr	r0, =SDRAM_OPEN_PAGE_EN
126*66a00be2SMans Rullgard	str	r0, [r3, #0x414]
1273e93b4e6SMasahiro Yamada
1283e93b4e6SMasahiro Yamada	/* 6) Write SDRAM timing Low register */
129*66a00be2SMans Rullgard	ldr	r0, =SDRAM_TIME_CTRL_LOW
130*66a00be2SMans Rullgard	str	r0, [r3, #0x408]
1313e93b4e6SMasahiro Yamada
1323e93b4e6SMasahiro Yamada	/* 7) Write SDRAM timing High register */
133*66a00be2SMans Rullgard	ldr	r0, =SDRAM_TIME_CTRL_HI
134*66a00be2SMans Rullgard	str	r0, [r3, #0x40C]
1353e93b4e6SMasahiro Yamada
1363e93b4e6SMasahiro Yamada	/* 8) Write SDRAM mode register */
1373e93b4e6SMasahiro Yamada	/* The CPU must not attempt to change the SDRAM Mode register setting */
1383e93b4e6SMasahiro Yamada	/* prior to DRAM controller completion of the DRAM initialization     */
1393e93b4e6SMasahiro Yamada	/* sequence. To guarantee this restriction, it is recommended that    */
1403e93b4e6SMasahiro Yamada	/* the CPU sets the SDRAM Operation register to NOP command, performs */
1413e93b4e6SMasahiro Yamada	/* read polling until the register is back in Normal operation value, */
1423e93b4e6SMasahiro Yamada	/* and then sets SDRAM Mode register to its new value.		      */
1433e93b4e6SMasahiro Yamada
1443e93b4e6SMasahiro Yamada	/* 8.1 write 'nop' to SDRAM operation */
145*66a00be2SMans Rullgard	ldr	r0, =SDRAM_OP_NOP
146*66a00be2SMans Rullgard	str	r0, [r3, #0x418]
1473e93b4e6SMasahiro Yamada
1483e93b4e6SMasahiro Yamada	/* 8.2 poll SDRAM operation until back in 'normal' mode.  */
1493e93b4e6SMasahiro Yamada1:
150*66a00be2SMans Rullgard	ldr	r0, [r3, #0x418]
151*66a00be2SMans Rullgard	cmp	r0, #0
1523e93b4e6SMasahiro Yamada	bne	1b
1533e93b4e6SMasahiro Yamada
1543e93b4e6SMasahiro Yamada	/* 8.3 Now its safe to write new value to SDRAM Mode register	      */
155*66a00be2SMans Rullgard	ldr	r0, =SDRAM_MODE
156*66a00be2SMans Rullgard	str	r0, [r3, #0x41C]
1573e93b4e6SMasahiro Yamada
1583e93b4e6SMasahiro Yamada	/* 8.4 Set new mode */
159*66a00be2SMans Rullgard	ldr	r0, =SDRAM_OP_SETMODE
160*66a00be2SMans Rullgard	str	r0, [r3, #0x418]
1613e93b4e6SMasahiro Yamada
1623e93b4e6SMasahiro Yamada	/* 8.5 poll SDRAM operation until back in 'normal' mode.  */
1633e93b4e6SMasahiro Yamada2:
164*66a00be2SMans Rullgard	ldr	r0, [r3, #0x418]
165*66a00be2SMans Rullgard	cmp	r0, #0
1663e93b4e6SMasahiro Yamada	bne	2b
1673e93b4e6SMasahiro Yamada
1683e93b4e6SMasahiro Yamada	/* DDR SDRAM Address/Control Pads Calibration */
169*66a00be2SMans Rullgard	ldr	r0, [r3, #0x4C0]
1703e93b4e6SMasahiro Yamada
1713e93b4e6SMasahiro Yamada	/* Set Bit [31] to make the register writable			*/
172*66a00be2SMans Rullgard	orr	r0, r0, #SDRAM_PAD_CTRL_WR_EN
173*66a00be2SMans Rullgard	str	r0, [r3, #0x4C0]
1743e93b4e6SMasahiro Yamada
175*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_WR_EN
176*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_TUNE_EN
177*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRVN_MASK
178*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRVP_MASK
1793e93b4e6SMasahiro Yamada
1803e93b4e6SMasahiro Yamada	/* Get the final N locked value of driving strength [22:17]	*/
181*66a00be2SMans Rullgard	mov	r1, r0
1823e93b4e6SMasahiro Yamada	mov	r1, r1, LSL #9
1833e93b4e6SMasahiro Yamada	mov	r1, r1, LSR #26	 /* r1[5:0]<DrvN>  = r3[22:17]<LockN>	*/
1843e93b4e6SMasahiro Yamada	orr	r1, r1, r1, LSL #6 /* r1[11:6]<DrvP> = r1[5:0]<DrvN>	*/
1853e93b4e6SMasahiro Yamada
1863e93b4e6SMasahiro Yamada	/* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6]	*/
187*66a00be2SMans Rullgard	orr	r0, r0, r1
188*66a00be2SMans Rullgard	str	r0, [r3, #0x4C0]
1893e93b4e6SMasahiro Yamada
1903e93b4e6SMasahiro Yamada	/* DDR SDRAM Data Pads Calibration				*/
191*66a00be2SMans Rullgard	ldr	r0, [r3, #0x4C4]
1923e93b4e6SMasahiro Yamada
1933e93b4e6SMasahiro Yamada	/* Set Bit [31] to make the register writable			*/
194*66a00be2SMans Rullgard	orr	r0, r0, #SDRAM_PAD_CTRL_WR_EN
195*66a00be2SMans Rullgard	str	r0, [r3, #0x4C4]
1963e93b4e6SMasahiro Yamada
197*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_WR_EN
198*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_TUNE_EN
199*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRVN_MASK
200*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRVP_MASK
2013e93b4e6SMasahiro Yamada
2023e93b4e6SMasahiro Yamada	/* Get the final N locked value of driving strength [22:17]	*/
203*66a00be2SMans Rullgard	mov	r1, r0
2043e93b4e6SMasahiro Yamada	mov	r1, r1, LSL #9
2053e93b4e6SMasahiro Yamada	mov	r1, r1, LSR #26
2063e93b4e6SMasahiro Yamada	orr	r1, r1, r1, LSL #6 /* r1[5:0] = r3[22:17]<LockN>	*/
2073e93b4e6SMasahiro Yamada
2083e93b4e6SMasahiro Yamada	/* Write to both <DrvN> bits [5:0] and <DrvP> bits [11:6]	*/
209*66a00be2SMans Rullgard	orr	r0, r0, r1
2103e93b4e6SMasahiro Yamada
211*66a00be2SMans Rullgard	str	r0, [r3, #0x4C4]
2123e93b4e6SMasahiro Yamada
2133e93b4e6SMasahiro Yamada	/* Implement Guideline (GL# MEM-3) Drive Strength Value		*/
2143e93b4e6SMasahiro Yamada	/* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0		*/
2153e93b4e6SMasahiro Yamada
2163e93b4e6SMasahiro Yamada	ldr	r1, =DDR1_PAD_STRENGTH_DEFAULT
2173e93b4e6SMasahiro Yamada
2183e93b4e6SMasahiro Yamada	/* Enable writes to DDR SDRAM Addr/Ctrl Pads Calibration register */
219*66a00be2SMans Rullgard	ldr	r0, [r3, #0x4C0]
220*66a00be2SMans Rullgard	orr	r0, r0, #SDRAM_PAD_CTRL_WR_EN
221*66a00be2SMans Rullgard	str	r0, [r3, #0x4C0]
2223e93b4e6SMasahiro Yamada
2233e93b4e6SMasahiro Yamada	/* Correct strength and disable writes again */
224*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_WR_EN
225*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRV_STR_MASK
226*66a00be2SMans Rullgard	orr	r0, r0, r1
227*66a00be2SMans Rullgard	str	r0, [r3, #0x4C0]
2283e93b4e6SMasahiro Yamada
2293e93b4e6SMasahiro Yamada	/* Enable writes to DDR SDRAM Data Pads Calibration register */
230*66a00be2SMans Rullgard	ldr	r0, [r3, #0x4C4]
231*66a00be2SMans Rullgard	orr	r0, r0, #SDRAM_PAD_CTRL_WR_EN
232*66a00be2SMans Rullgard	str	r0, [r3, #0x4C4]
2333e93b4e6SMasahiro Yamada
2343e93b4e6SMasahiro Yamada	/* Correct strength and disable writes again */
235*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_DRV_STR_MASK
236*66a00be2SMans Rullgard	bic	r0, r0, #SDRAM_PAD_CTRL_WR_EN
237*66a00be2SMans Rullgard	orr	r0, r0, r1
238*66a00be2SMans Rullgard	str	r0, [r3, #0x4C4]
2393e93b4e6SMasahiro Yamada
2403e93b4e6SMasahiro Yamada	/* Implement Guideline (GL# MEM-4) DQS Reference Delay Tuning	*/
2413e93b4e6SMasahiro Yamada	/* Relevant for: 88F5181-A1/B0/B1 and 88F5281-A0/B0		*/
2423e93b4e6SMasahiro Yamada
2433e93b4e6SMasahiro Yamada	/* Get the "sample on reset" register for the DDR frequancy	*/
2443e93b4e6SMasahiro Yamada	ldr	r3, =0x10000
245*66a00be2SMans Rullgard	ldr	r0, [r3, #0x010]
2463e93b4e6SMasahiro Yamada	ldr	r1, =MSAR_ARMDDRCLCK_MASK
247*66a00be2SMans Rullgard	and	r1, r0, r1
2483e93b4e6SMasahiro Yamada
249*66a00be2SMans Rullgard	ldr	r0, =FTDLL_DDR1_166MHZ
2503e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_333_167
2513e93b4e6SMasahiro Yamada	beq	3f
2523e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_500_167
2533e93b4e6SMasahiro Yamada	beq	3f
2543e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_667_167
2553e93b4e6SMasahiro Yamada	beq	3f
2563e93b4e6SMasahiro Yamada
257*66a00be2SMans Rullgard	ldr	r0, =FTDLL_DDR1_200MHZ
2583e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_400_200_1
2593e93b4e6SMasahiro Yamada	beq	3f
2603e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_400_200
2613e93b4e6SMasahiro Yamada	beq	3f
2623e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_600_200
2633e93b4e6SMasahiro Yamada	beq	3f
2643e93b4e6SMasahiro Yamada	cmp	r1, #MSAR_ARMDDRCLCK_800_200
2653e93b4e6SMasahiro Yamada	beq	3f
2663e93b4e6SMasahiro Yamada
267*66a00be2SMans Rullgard	ldr	r0, =0
2683e93b4e6SMasahiro Yamada
2693e93b4e6SMasahiro Yamada3:
2703e93b4e6SMasahiro Yamada	/* Use R3 as the base for DRAM registers */
271*66a00be2SMans Rullgard	add	r3, r2, #0x01000
2723e93b4e6SMasahiro Yamada
2733e93b4e6SMasahiro Yamada	ldr	r2, [r3, #0x484]
274*66a00be2SMans Rullgard	orr	r2, r2, r0
2753e93b4e6SMasahiro Yamada	str	r2, [r3, #0x484]
2763e93b4e6SMasahiro Yamada
2779608e7deSAlbert ARIBAUD	/* enable for 2 GB DDR; detection should find out real amount */
278*66a00be2SMans Rullgard	sub	r0, r0, r0
279*66a00be2SMans Rullgard	str	r0, [r3, #0x500]
280*66a00be2SMans Rullgard	ldr	r0, =0x7fff0001
281*66a00be2SMans Rullgard	str	r0, [r3, #0x504]
2829608e7deSAlbert ARIBAUD
2839608e7deSAlbert ARIBAUD#endif /* CONFIG_SPL_BUILD */
2849608e7deSAlbert ARIBAUD
285a187559eSBin Meng	/* Return to U-Boot via saved link register */
2863e93b4e6SMasahiro Yamada	mov	pc, lr
287