2 * (C) Copyright 2003-2006
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
8 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/processor.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 #ifndef CONFIG_SYS_RAMBOOT
19 static void sdram_start(int hi_addr)
21 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
23 /* unlock mode register */
24 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
25 __asm__ volatile ("sync");
27 /* precharge all banks */
28 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
29 __asm__ volatile ("sync");
32 /* set mode register: extended mode */
33 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
34 __asm__ volatile ("sync");
36 /* set mode register: reset DLL */
37 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
38 __asm__ volatile ("sync");
39 #endif /* SDRAM_DDR */
41 /* precharge all banks */
42 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
43 __asm__ volatile ("sync");
46 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
47 __asm__ volatile ("sync");
49 /* set mode register */
50 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
51 __asm__ volatile ("sync");
53 /* normal operation */
54 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
55 __asm__ volatile ("sync");
57 #endif /* !CONFIG_SYS_RAMBOOT */
66 #ifndef CONFIG_SYS_RAMBOOT
69 /* setup SDRAM chip selects */
70 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
71 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
72 __asm__ volatile ("sync");
74 /* setup config registers */
75 *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
76 *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
77 __asm__ volatile ("sync");
81 *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
82 __asm__ volatile ("sync");
83 #endif /* SDRAM_DDR */
85 /* find RAM size using SDRAM CS0 only */
87 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
89 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
96 /* memory smaller than 1MB is impossible */
97 if (dramsize < (1 << 20))
100 /* set SDRAM CS0 size according to the amount of RAM found */
102 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
104 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
106 /* let SDRAM CS1 start right after CS0 */
107 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
109 /* find RAM size using SDRAM CS1 only */
112 test2 = test1 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
115 test2 = get_ram_size((long *) (CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
123 /* memory smaller than 1MB is impossible */
124 if (dramsize2 < (1 << 20))
127 /* set SDRAM CS1 size according to the amount of RAM found */
129 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize
130 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
132 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
134 #else /* CONFIG_SYS_RAMBOOT */
136 /* retrieve size of memory connected to SDRAM CS0 */
137 dramsize = *(vu_long *) MPC5XXX_SDRAM_CS0CFG & 0xFF;
138 if (dramsize >= 0x13)
139 dramsize = (1 << (dramsize - 0x13)) << 20;
143 /* retrieve size of memory connected to SDRAM CS1 */
144 dramsize2 = *(vu_long *) MPC5XXX_SDRAM_CS1CFG & 0xFF;
145 if (dramsize2 >= 0x13)
146 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
150 #endif /* CONFIG_SYS_RAMBOOT */
153 * On MPC5200B we need to set the special configuration delay in the
154 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
155 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
157 * "The SDelay should be written to a value of 0x00000004. It is
158 * required to account for changes caused by normal wafer processing
163 if ((SVR_MJREV(svr) >= 2) &&
164 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
166 *(vu_long *) MPC5XXX_SDRAM_SDELAY = 0x04;
167 __asm__ volatile ("sync");
170 gd->ram_size = dramsize + dramsize2;
176 int checkboard (void)
178 puts("Board: MarelV38B\n");
182 int board_early_init_f(void)
184 #ifdef CONFIG_HW_WATCHDOG
186 * Enable and configure the direction (output) of PSC3_9 - watchdog
187 * reset input. Refer to 7.3.2.2.[1,3,4] of the MPC5200B User's
190 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
191 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
192 #endif /* CONFIG_HW_WATCHDOG */
196 int board_early_init_r(void)
199 * Now, when we are in RAM, enable flash write access for the
200 * detection process. Note that CS_BOOT cannot be cleared when
201 * executing in flash.
203 *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
206 * Enable GPIO_WKUP_7 to "read the status of the actual power
207 * situation". Default direction is input, so no need to set it
210 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WKUP_7;
214 extern void board_get_enetaddr(uchar *enetaddr);
215 int misc_init_r(void)
219 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
220 board_get_enetaddr(enetaddr);
221 eth_setenv_enetaddr("ethaddr", enetaddr);
227 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
228 void init_ide_reset(void)
230 debug("init_ide_reset\n");
232 /* Configure PSC1_4 as GPIO output for ATA reset */
233 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
234 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
236 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
240 void ide_set_reset(int idereset)
242 debug("ide_reset(%d)\n", idereset);
245 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
246 /* Make a delay. MPC5200 spec says 25 usec min */
249 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
254 #ifdef CONFIG_HW_WATCHDOG
255 void hw_watchdog_reset(void)
258 * MarelV38B has a TPS3705 watchdog. Spec says that to kick the dog
259 * we need a positive or negative transition on WDI i.e., our PSC3_9.
261 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O ^= GPIO_PSC3_9;
263 #endif /* CONFIG_HW_WATCHDOG */