2 * (C) Copyright 2003-2006
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <asm/processor.h>
32 static void sdram_start(int hi_addr)
34 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
36 /* unlock mode register */
37 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
38 __asm__ volatile ("sync");
40 /* precharge all banks */
41 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
42 __asm__ volatile ("sync");
45 /* set mode register: extended mode */
46 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
47 __asm__ volatile ("sync");
49 /* set mode register: reset DLL */
50 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
51 __asm__ volatile ("sync");
52 #endif /* SDRAM_DDR */
54 /* precharge all banks */
55 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
56 __asm__ volatile ("sync");
59 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
60 __asm__ volatile ("sync");
62 /* set mode register */
63 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
64 __asm__ volatile ("sync");
66 /* normal operation */
67 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
68 __asm__ volatile ("sync");
70 #endif /* !CFG_RAMBOOT */
73 long int initdram(int board_type)
82 /* setup SDRAM chip selects */
83 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
84 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
85 __asm__ volatile ("sync");
87 /* setup config registers */
88 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
89 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
90 __asm__ volatile ("sync");
94 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
95 __asm__ volatile ("sync");
96 #endif /* SDRAM_DDR */
98 /* find RAM size using SDRAM CS0 only */
100 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
102 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
109 /* memory smaller than 1MB is impossible */
110 if (dramsize < (1 << 20))
113 /* set SDRAM CS0 size according to the amount of RAM found */
115 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
117 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
119 /* let SDRAM CS1 start right after CS0 */
120 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
122 /* find RAM size using SDRAM CS1 only */
125 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
128 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
136 /* memory smaller than 1MB is impossible */
137 if (dramsize2 < (1 << 20))
140 /* set SDRAM CS1 size according to the amount of RAM found */
142 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
143 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
145 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
147 #else /* CFG_RAMBOOT */
149 /* retrieve size of memory connected to SDRAM CS0 */
150 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
151 if (dramsize >= 0x13)
152 dramsize = (1 << (dramsize - 0x13)) << 20;
156 /* retrieve size of memory connected to SDRAM CS1 */
157 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
158 if (dramsize2 >= 0x13)
159 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
163 #endif /* CFG_RAMBOOT */
166 * On MPC5200B we need to set the special configuration delay in the
167 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
168 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
170 * "The SDelay should be written to a value of 0x00000004. It is
171 * required to account for changes caused by normal wafer processing
176 if ((SVR_MJREV(svr) >= 2) &&
177 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
179 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
180 __asm__ volatile ("sync");
183 return dramsize + dramsize2;
187 int checkboard (void)
189 puts("Board: MarelV38B\n");
194 int board_early_init_r(void)
197 * Now, when we are in RAM, enable flash write access for detection process.
198 * Note that CS_BOOT cannot be cleared when executing in flash.
200 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
205 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
207 #define GPIO_PSC1_4 0x01000000UL
209 void init_ide_reset(void)
211 debug("init_ide_reset\n");
213 /* Configure PSC1_4 as GPIO output for ATA reset */
214 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
215 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
217 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
221 void ide_set_reset(int idereset)
223 debug("ide_reset(%d)\n", idereset);
226 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
227 /* Make a delay. MPC5200 spec says 25 usec min */
230 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
232 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
237 /* TIMER7 as GPIO output low */
238 *(vu_long *) (MPC5XXX_GPT + 0x70) |= 0x24;
242 void led_d4_off(void)
244 /* TIMER7 as GPIO output high */
245 *(vu_long *) (MPC5XXX_GPT + 0x70) |= 0x34;
249 void hw_watchdog_reset(void)
251 /* TODO fill this in */