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>
18 #if defined(CONFIG_LITE5200B)
19 #include "mt46v32m16.h"
21 # if defined(CONFIG_MPC5200_DDR)
22 # include "mt46v16m16-75.h"
24 #include "mt48lc16m16a2-75.h"
28 #ifdef CONFIG_LITE5200B_PM
29 /* u-boot part of low-power mode implementation */
30 #define SAVED_ADDR (*(void **)0x00000000)
33 void lite5200b_wakeup(void)
35 unsigned char wakeup_pin;
36 void (*linux_wakeup)(void);
38 /* check PSC2_4, if it's down "QT" is signaling we have a wakeup
39 * from low power mode */
40 *(vu_char *)MPC5XXX_WU_GPIO_ENABLE = PSC2_4;
41 __asm__ volatile ("sync");
43 wakeup_pin = *(vu_char *)MPC5XXX_WU_GPIO_DATA_I;
44 if (wakeup_pin & PSC2_4)
47 /* acknowledge to "QT"
48 * by holding pin at 1 for 10 uS */
49 *(vu_char *)MPC5XXX_WU_GPIO_DIR = PSC2_4;
50 __asm__ volatile ("sync");
51 *(vu_char *)MPC5XXX_WU_GPIO_DATA_O = PSC2_4;
52 __asm__ volatile ("sync");
55 /* put ram out of self-refresh */
56 *(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x80000000; /* mode_en */
57 __asm__ volatile ("sync");
58 *(vu_long *)MPC5XXX_SDRAM_CTRL |= 0x50000000; /* cke ref_en */
59 __asm__ volatile ("sync");
60 *(vu_long *)MPC5XXX_SDRAM_CTRL &= ~0x80000000; /* !mode_en */
61 __asm__ volatile ("sync");
62 udelay(10); /* wait a bit */
64 /* jump back to linux kernel code */
65 linux_wakeup = SAVED_ADDR;
66 printf("\n\nLooks like we just woke, transferring control to 0x%08lx\n",
67 (unsigned long)linux_wakeup);
71 #define lite5200b_wakeup()
74 #ifndef CONFIG_SYS_RAMBOOT
75 static void sdram_start (int hi_addr)
77 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
79 /* unlock mode register */
80 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
81 __asm__ volatile ("sync");
83 /* precharge all banks */
84 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
85 __asm__ volatile ("sync");
88 /* set mode register: extended mode */
89 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
90 __asm__ volatile ("sync");
92 /* set mode register: reset DLL */
93 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
94 __asm__ volatile ("sync");
97 /* precharge all banks */
98 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
99 __asm__ volatile ("sync");
102 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
103 __asm__ volatile ("sync");
105 /* set mode register */
106 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
107 __asm__ volatile ("sync");
109 /* normal operation */
110 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
111 __asm__ volatile ("sync");
116 * ATTENTION: Although partially referenced initdram does NOT make real use
117 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
118 * is something else than 0x00000000.
121 phys_size_t initdram (int board_type)
127 #ifndef CONFIG_SYS_RAMBOOT
130 /* setup SDRAM chip selects */
131 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
132 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
133 __asm__ volatile ("sync");
135 /* setup config registers */
136 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
137 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
138 __asm__ volatile ("sync");
142 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
143 __asm__ volatile ("sync");
146 /* find RAM size using SDRAM CS0 only */
148 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
150 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
158 /* memory smaller than 1MB is impossible */
159 if (dramsize < (1 << 20)) {
163 /* set SDRAM CS0 size according to the amount of RAM found */
165 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
167 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
170 /* let SDRAM CS1 start right after CS0 */
171 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
173 /* find RAM size using SDRAM CS1 only */
176 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
179 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
188 /* memory smaller than 1MB is impossible */
189 if (dramsize2 < (1 << 20)) {
193 /* set SDRAM CS1 size according to the amount of RAM found */
195 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
196 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
198 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
201 #else /* CONFIG_SYS_RAMBOOT */
203 /* retrieve size of memory connected to SDRAM CS0 */
204 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
205 if (dramsize >= 0x13) {
206 dramsize = (1 << (dramsize - 0x13)) << 20;
211 /* retrieve size of memory connected to SDRAM CS1 */
212 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
213 if (dramsize2 >= 0x13) {
214 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
219 #endif /* CONFIG_SYS_RAMBOOT */
222 * On MPC5200B we need to set the special configuration delay in the
223 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
224 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
226 * "The SDelay should be written to a value of 0x00000004. It is
227 * required to account for changes caused by normal wafer processing
232 if ((SVR_MJREV(svr) >= 2) &&
233 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
235 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
236 __asm__ volatile ("sync");
241 return dramsize + dramsize2;
244 int checkboard (void)
246 #if defined (CONFIG_LITE5200B)
247 puts ("Board: Freescale Lite5200B\n");
249 puts ("Board: Motorola MPC5200 (IceCube)\n");
254 void flash_preinit(void)
257 * Now, when we are in RAM, enable flash write
258 * access for detection process.
259 * Note that CS_BOOT cannot be cleared when
260 * executing in flash.
262 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
265 void flash_afterinit(ulong size)
267 if (size == 0x800000) { /* adjust mapping */
268 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
269 START_REG(CONFIG_SYS_BOOTCS_START | size);
270 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
271 STOP_REG(CONFIG_SYS_BOOTCS_START | size, size);
276 static struct pci_controller hose;
278 extern void pci_mpc5xxx_init(struct pci_controller *);
280 void pci_init_board(void)
282 pci_mpc5xxx_init(&hose);
286 #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
288 void init_ide_reset (void)
290 debug ("init_ide_reset\n");
292 /* Configure PSC1_4 as GPIO output for ATA reset */
293 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
294 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
296 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
299 void ide_set_reset (int idereset)
301 debug ("ide_reset(%d)\n", idereset);
304 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
305 /* Make a delay. MPC5200 spec says 25 usec min */
308 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
313 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
315 ft_board_setup(void *blob, bd_t *bd)
317 ft_cpu_setup(blob, bd);
321 int board_eth_init(bd_t *bis)
323 cpu_eth_init(bis); /* Built in FEC comes first */
324 return pci_eth_init(bis);