blob: 978ff8db00f854baa3d1d6e473fa51b725ccd877 [file] [log] [blame]
Bartlomiej Sieka2dfa3d22006-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 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <mpc5xxx.h>
Heiko Schocher50219e62009-03-26 07:33:59 +010029#include <net.h>
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020030#include <asm/processor.h>
31
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010032
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033#ifndef CONFIG_SYS_RAMBOOT
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020034static void sdram_start(int hi_addr)
35{
36 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
37
38 /* unlock mode register */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010039 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020040 __asm__ volatile ("sync");
41
42 /* precharge all banks */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010043 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020044 __asm__ volatile ("sync");
45
46#if SDRAM_DDR
47 /* set mode register: extended mode */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010048 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020049 __asm__ volatile ("sync");
50
51 /* set mode register: reset DLL */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010052 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020053 __asm__ volatile ("sync");
54#endif /* SDRAM_DDR */
55
56 /* precharge all banks */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010057 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020058 __asm__ volatile ("sync");
59
60 /* auto refresh */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010061 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020062 __asm__ volatile ("sync");
63
64 /* set mode register */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010065 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020066 __asm__ volatile ("sync");
67
68 /* normal operation */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010069 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020070 __asm__ volatile ("sync");
71}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072#endif /* !CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020073
74
Becky Brucebd99ae72008-06-09 16:03:40 -050075phys_size_t initdram(int board_type)
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020076{
77 ulong dramsize = 0;
78 ulong dramsize2 = 0;
79 uint svr, pvr;
80
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081#ifndef CONFIG_SYS_RAMBOOT
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020082 ulong test1, test2;
83
84 /* setup SDRAM chip selects */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010085 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
86 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020087 __asm__ volatile ("sync");
88
89 /* setup config registers */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010090 *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
91 *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020092 __asm__ volatile ("sync");
93
94#if SDRAM_DDR
95 /* set tap delay */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +010096 *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +020097 __asm__ volatile ("sync");
98#endif /* SDRAM_DDR */
99
100 /* find RAM size using SDRAM CS0 only */
101 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200102 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200103 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200105 if (test1 > test2) {
106 sdram_start(0);
107 dramsize = test1;
108 } else
109 dramsize = test2;
110
111 /* memory smaller than 1MB is impossible */
112 if (dramsize < (1 << 20))
113 dramsize = 0;
114
115 /* set SDRAM CS0 size according to the amount of RAM found */
116 if (dramsize > 0)
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100117 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200118 else
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100119 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200120
121 /* let SDRAM CS1 start right after CS0 */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100122 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200123
124 /* find RAM size using SDRAM CS1 only */
125 if (!dramsize)
126 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127 test2 = test1 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200128 if (!dramsize) {
129 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130 test2 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200131 }
132 if (test1 > test2) {
133 sdram_start(0);
134 dramsize2 = test1;
135 } else
136 dramsize2 = test2;
137
138 /* memory smaller than 1MB is impossible */
139 if (dramsize2 < (1 << 20))
140 dramsize2 = 0;
141
142 /* set SDRAM CS1 size according to the amount of RAM found */
143 if (dramsize2 > 0)
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100144 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200145 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
146 else
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100147 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200148
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149#else /* CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200150
151 /* retrieve size of memory connected to SDRAM CS0 */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100152 dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200153 if (dramsize >= 0x13)
154 dramsize = (1 << (dramsize - 0x13)) << 20;
155 else
156 dramsize = 0;
157
158 /* retrieve size of memory connected to SDRAM CS1 */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100159 dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200160 if (dramsize2 >= 0x13)
161 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
162 else
163 dramsize2 = 0;
164
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200165#endif /* CONFIG_SYS_RAMBOOT */
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200166
167 /*
168 * On MPC5200B we need to set the special configuration delay in the
169 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
170 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
171 *
172 * "The SDelay should be written to a value of 0x00000004. It is
173 * required to account for changes caused by normal wafer processing
174 * parameters."
175 */
176 svr = get_svr();
177 pvr = get_pvr();
178 if ((SVR_MJREV(svr) >= 2) &&
179 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
180
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100181 *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200182 __asm__ volatile ("sync");
183 }
184
185 return dramsize + dramsize2;
186}
187
188
189int checkboard (void)
190{
191 puts("Board: MarelV38B\n");
192 return 0;
193}
194
Bartlomiej Sieka37e66642006-12-28 19:08:21 +0100195int board_early_init_f(void)
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200196{
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100197#ifdef CONFIG_HW_WATCHDOG
198 /*
199 * Enable and configure the direction (output) of PSC3_9 - watchdog
200 * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's
201 * Manual.
202 */
203 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
204 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
205#endif /* CONFIG_HW_WATCHDOG */
Bartlomiej Sieka37e66642006-12-28 19:08:21 +0100206 return 0;
207}
208
209int board_early_init_r(void)
210{
211 /*
212 * Now, when we are in RAM, enable flash write access for the
213 * detection process. Note that CS_BOOT cannot be cleared when
214 * executing in flash.
215 */
216 *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100217
218 /*
219 * Enable GPIO_WKUP_7 to "read the status of the actual power
220 * situation". Default direction is input, so no need to set it
221 * explicitly.
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200222 */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100223 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200224 return 0;
225}
226
Mike Frysinger13e9bb92009-02-16 18:03:14 -0500227extern void board_get_enetaddr(uchar *enetaddr);
228int misc_init_r(void)
229{
230 uchar enetaddr[6];
231
232 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
233 board_get_enetaddr(enetaddr);
Heiko Schocher50219e62009-03-26 07:33:59 +0100234 eth_setenv_enetaddr("ethaddr", enetaddr);
Mike Frysinger13e9bb92009-02-16 18:03:14 -0500235 }
236
237 return 0;
238}
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200239
Jon Loeliger761ea742007-07-10 10:48:22 -0500240#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200241void init_ide_reset(void)
242{
243 debug("init_ide_reset\n");
244
245 /* Configure PSC1_4 as GPIO output for ATA reset */
246 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100247 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200248 /* Deassert reset */
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100249 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200250}
251
252
253void ide_set_reset(int idereset)
254{
255 debug("ide_reset(%d)\n", idereset);
256
257 if (idereset) {
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100258 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200259 /* Make a delay. MPC5200 spec says 25 usec min */
260 udelay(500000);
261 } else
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100262 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200263}
Jon Loeliger761ea742007-07-10 10:48:22 -0500264#endif
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200265
266
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100267#ifdef CONFIG_HW_WATCHDOG
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200268void hw_watchdog_reset(void)
269{
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100270 /*
271 * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog
272 * we need a positive or negative transition on WDI i.e., our PSC3_9.
273 */
274 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9;
Bartlomiej Sieka2dfa3d22006-10-13 21:09:09 +0200275}
Bartlomiej Sieka252eede2006-11-01 02:04:38 +0100276#endif /* CONFIG_HW_WATCHDOG */