blob: a3377299162e44683ab241f4a4698d10fa5b97b9 [file] [log] [blame]
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +02001/*
2 * (C) Copyright 2003-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +02009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
Heiko Schocher76756e42009-03-26 07:33:59 +010013#include <net.h>
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020014#include <asm/processor.h>
15
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010016
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020017#ifndef CONFIG_SYS_RAMBOOT
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020018static void sdram_start(int hi_addr)
19{
20 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
21
22 /* unlock mode register */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010023 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020024 __asm__ volatile ("sync");
25
26 /* precharge all banks */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010027 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020028 __asm__ volatile ("sync");
29
30#if SDRAM_DDR
31 /* set mode register: extended mode */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010032 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020033 __asm__ volatile ("sync");
34
35 /* set mode register: reset DLL */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010036 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020037 __asm__ volatile ("sync");
38#endif /* SDRAM_DDR */
39
40 /* precharge all banks */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010041 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020042 __asm__ volatile ("sync");
43
44 /* auto refresh */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010045 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020046 __asm__ volatile ("sync");
47
48 /* set mode register */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010049 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020050 __asm__ volatile ("sync");
51
52 /* normal operation */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010053 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020054 __asm__ volatile ("sync");
55}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056#endif /* !CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020057
58
Becky Bruce9973e3c2008-06-09 16:03:40 -050059phys_size_t initdram(int board_type)
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020060{
61 ulong dramsize = 0;
62 ulong dramsize2 = 0;
63 uint svr, pvr;
64
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020065#ifndef CONFIG_SYS_RAMBOOT
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020066 ulong test1, test2;
67
68 /* setup SDRAM chip selects */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010069 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
70 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020071 __asm__ volatile ("sync");
72
73 /* setup config registers */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010074 *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
75 *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020076 __asm__ volatile ("sync");
77
78#if SDRAM_DDR
79 /* set tap delay */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +010080 *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020081 __asm__ volatile ("sync");
82#endif /* SDRAM_DDR */
83
84 /* find RAM size using SDRAM CS0 only */
85 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020086 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020087 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020088 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +020089 if (test1 > test2) {
90 sdram_start(0);
91 dramsize = test1;
92 } else
93 dramsize = test2;
94
95 /* memory smaller than 1MB is impossible */
96 if (dramsize < (1 << 20))
97 dramsize = 0;
98
99 /* set SDRAM CS0 size according to the amount of RAM found */
100 if (dramsize > 0)
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100101 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200102 else
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100103 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200104
105 /* let SDRAM CS1 start right after CS0 */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100106 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200107
108 /* find RAM size using SDRAM CS1 only */
109 if (!dramsize)
110 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200111 test2 = test1 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200112 if (!dramsize) {
113 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114 test2 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200115 }
116 if (test1 > test2) {
117 sdram_start(0);
118 dramsize2 = test1;
119 } else
120 dramsize2 = test2;
121
122 /* memory smaller than 1MB is impossible */
123 if (dramsize2 < (1 << 20))
124 dramsize2 = 0;
125
126 /* set SDRAM CS1 size according to the amount of RAM found */
127 if (dramsize2 > 0)
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100128 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200129 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
130 else
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100131 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200132
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200133#else /* CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200134
135 /* retrieve size of memory connected to SDRAM CS0 */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100136 dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200137 if (dramsize >= 0x13)
138 dramsize = (1 << (dramsize - 0x13)) << 20;
139 else
140 dramsize = 0;
141
142 /* retrieve size of memory connected to SDRAM CS1 */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100143 dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200144 if (dramsize2 >= 0x13)
145 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
146 else
147 dramsize2 = 0;
148
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149#endif /* CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200150
151 /*
152 * On MPC5200B we need to set the special configuration delay in the
153 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
154 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
155 *
156 * "The SDelay should be written to a value of 0x00000004. It is
157 * required to account for changes caused by normal wafer processing
158 * parameters."
159 */
160 svr = get_svr();
161 pvr = get_pvr();
162 if ((SVR_MJREV(svr) >= 2) &&
163 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
164
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100165 *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200166 __asm__ volatile ("sync");
167 }
168
169 return dramsize + dramsize2;
170}
171
172
173int checkboard (void)
174{
175 puts("Board: MarelV38B\n");
176 return 0;
177}
178
Bartlomiej Siekacce4acb2006-12-28 19:08:21 +0100179int board_early_init_f(void)
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200180{
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100181#ifdef CONFIG_HW_WATCHDOG
182 /*
183 * Enable and configure the direction (output) of PSC3_9 - watchdog
184 * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's
185 * Manual.
186 */
187 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
188 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
189#endif /* CONFIG_HW_WATCHDOG */
Bartlomiej Siekacce4acb2006-12-28 19:08:21 +0100190 return 0;
191}
192
193int board_early_init_r(void)
194{
195 /*
196 * Now, when we are in RAM, enable flash write access for the
197 * detection process. Note that CS_BOOT cannot be cleared when
198 * executing in flash.
199 */
200 *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100201
202 /*
203 * Enable GPIO_WKUP_7 to "read the status of the actual power
204 * situation". Default direction is input, so no need to set it
205 * explicitly.
206 */
207 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200208 return 0;
209}
210
Mike Frysingerd8d21e62009-02-16 18:03:14 -0500211extern void board_get_enetaddr(uchar *enetaddr);
212int misc_init_r(void)
213{
214 uchar enetaddr[6];
215
216 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
217 board_get_enetaddr(enetaddr);
Heiko Schocher76756e42009-03-26 07:33:59 +0100218 eth_setenv_enetaddr("ethaddr", enetaddr);
Mike Frysingerd8d21e62009-02-16 18:03:14 -0500219 }
220
221 return 0;
222}
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200223
Jon Loeligerd39b5742007-07-10 10:48:22 -0500224#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200225void init_ide_reset(void)
226{
227 debug("init_ide_reset\n");
228
229 /* Configure PSC1_4 as GPIO output for ATA reset */
230 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100231 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200232 /* Deassert reset */
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100233 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200234}
235
236
237void ide_set_reset(int idereset)
238{
239 debug("ide_reset(%d)\n", idereset);
240
241 if (idereset) {
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100242 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200243 /* Make a delay. MPC5200 spec says 25 usec min */
244 udelay(500000);
245 } else
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100246 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200247}
Jon Loeligerd39b5742007-07-10 10:48:22 -0500248#endif
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200249
250
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100251#ifdef CONFIG_HW_WATCHDOG
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200252void hw_watchdog_reset(void)
253{
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100254 /*
255 * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog
256 * we need a positive or negative transition on WDI i.e., our PSC3_9.
257 */
258 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9;
Bartlomiej Sieka4707fb52006-10-13 21:09:09 +0200259}
Bartlomiej Sieka25721b52006-11-01 02:04:38 +0100260#endif /* CONFIG_HW_WATCHDOG */