2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
9 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
12 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
14 * See file CREDITS for list of people who contributed to this
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of
20 * the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 #include <asm/processor.h>
40 #ifndef CONFIG_SYS_RAMBOOT
41 static void sdram_start (int hi_addr)
43 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
45 /* unlock mode register */
46 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
47 (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
48 __asm__ volatile ("sync");
50 /* precharge all banks */
51 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
52 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
53 __asm__ volatile ("sync");
56 /* set mode register: extended mode */
57 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_EMODE));
58 __asm__ volatile ("sync");
60 /* set mode register: reset DLL */
61 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE,
62 (SDRAM_MODE | 0x04000000));
63 __asm__ volatile ("sync");
66 /* precharge all banks */
67 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
68 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
69 __asm__ volatile ("sync");
72 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
73 (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
74 __asm__ volatile ("sync");
76 /* set mode register */
77 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_MODE));
78 __asm__ volatile ("sync");
80 /* normal operation */
81 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
82 (SDRAM_CONTROL | hi_addr_bit));
83 __asm__ volatile ("sync");
88 * ATTENTION: Although partially referenced initdram does NOT make real use
89 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
90 * is something else than 0x00000000.
93 phys_size_t initdram (int board_type)
99 #ifndef CONFIG_SYS_RAMBOOT
102 /* setup SDRAM chip selects */
103 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0x0000001c); /* 512MB at 0x0 */
104 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);/* disabled */
105 __asm__ volatile ("sync");
107 /* setup config registers */
108 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
109 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
110 __asm__ volatile ("sync");
114 out_be32 ((unsigned __iomem *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
115 __asm__ volatile ("sync");
118 /* find RAM size using SDRAM CS0 only */
120 test1 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
122 test2 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
130 /* memory smaller than 1MB is impossible */
131 if (dramsize < (1 << 20)) {
135 /* set SDRAM CS0 size according to the amount of RAM found */
137 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG,
138 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
140 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
143 /* let SDRAM CS1 start right after CS0 */
144 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, (dramsize + 0x0000001c));/*512MB*/
146 /* find RAM size using SDRAM CS1 only */
149 test2 = test1 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
152 test2 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
161 /* memory smaller than 1MB is impossible */
162 if (dramsize2 < (1 << 20)) {
166 /* set SDRAM CS1 size according to the amount of RAM found */
168 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG,
169 (dramsize | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
171 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
174 #else /* CONFIG_SYS_RAMBOOT */
176 /* retrieve size of memory connected to SDRAM CS0 */
177 dramsize = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
178 if (dramsize >= 0x13) {
179 dramsize = (1 << (dramsize - 0x13)) << 20;
184 /* retrieve size of memory connected to SDRAM CS1 */
185 dramsize2 = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
186 if (dramsize2 >= 0x13) {
187 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
192 #endif /* CONFIG_SYS_RAMBOOT */
195 * On MPC5200B we need to set the special configuration delay in the
196 * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
197 * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
199 * "The SDelay should be written to a value of 0x00000004. It is
200 * required to account for changes caused by normal wafer processing
205 if ((SVR_MJREV(svr) >= 2) &&
206 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
208 out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_SDELAY, 0x04);
209 __asm__ volatile ("sync");
212 return dramsize + dramsize2;
215 int checkboard (void)
217 puts ("Board: MUC.MC-52 HW WDT ");
218 #if defined(CONFIG_HW_WATCHDOG)
226 #ifdef CONFIG_PREBOOT
228 static uchar kbd_magic_prefix[] = "key_magic";
229 static uchar kbd_command_prefix[] = "key_cmd";
240 struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
242 kbd_data->s1 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS1_BASE);
243 kbd_data->s2 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS2_BASE);
248 static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
253 if (s1 >= '0' && s1 <= '9')
255 else if (s1 >= 'a' && s1 <= 'f')
257 else if (s1 >= 'A' && s1 <= 'F')
262 if (((S1_ROT & kbd_data->s1) >> 4) != s1)
265 s2 = (S2_Q | S2_M) & kbd_data->s2;
279 if (s2 == (S2_Q | S2_M))
291 static char *key_match (const struct kbd_data_t *kbd_data)
293 char magic[sizeof (kbd_magic_prefix) + 1];
295 char *kbd_magic_keys;
298 * The following string defines the characters that can be appended
299 * to "key_magic" to form the names of environment variables that
300 * hold "magic" key codes, i. e. such key codes that can cause
301 * pre-boot actions. If the string is empty (""), then only
302 * "key_magic" is checked (old behaviour); the string "125" causes
303 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
305 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
308 /* loop over all magic keys;
309 * use '\0' suffix in case of empty string
311 for (suffix = kbd_magic_keys; *suffix ||
312 suffix == kbd_magic_keys; ++suffix) {
313 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
315 if (compare_magic(kbd_data, getenv(magic)) == 0) {
316 char cmd_name[sizeof (kbd_command_prefix) + 1];
319 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
320 cmd = getenv (cmd_name);
329 #endif /* CONFIG_PREBOOT */
331 int misc_init_r (void)
333 #ifdef CONFIG_PREBOOT
334 struct kbd_data_t kbd_data;
336 char *str = strdup (key_match (get_keys (&kbd_data)));
337 /* Set or delete definition */
338 setenv ("preboot", str);
340 #endif /* CONFIG_PREBOOT */
342 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), ' ');
343 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), ' ');
344 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), ' ');
345 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), ' ');
346 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), ' ');
347 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), ' ');
348 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), ' ');
349 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), ' ');
354 int board_early_init_r (void)
356 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG, in_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG) & ~0x1);
357 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_FLASH_BASE));
358 out_be32 ((unsigned __iomem *)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_FLASH_BASE));
359 out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_STOP,
360 STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
361 out_be32 ((unsigned __iomem *)MPC5XXX_CS0_STOP,
362 STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
366 int last_stage_init (void)
368 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), 'M');
369 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), 'U');
370 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), 'C');
371 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), '.');
372 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), 'M');
373 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), 'C');
374 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), '5');
375 out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), '2');
380 #if defined(CONFIG_HW_WATCHDOG)
381 #define GPT_OUT_0 0x00000027
382 #define GPT_OUT_1 0x00000037
383 void hw_watchdog_reset (void)
385 /* Trigger HW Watchdog with TIMER_0 */
386 out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_1);
387 out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_0);
392 static struct pci_controller hose;
394 extern void pci_mpc5xxx_init (struct pci_controller *);
396 void pci_init_board (void)
398 pci_mpc5xxx_init (&hose);
402 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
403 void ft_board_setup(void *blob, bd_t *bd)
405 ft_cpu_setup(blob, bd);
407 #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */