2 * (C) Copyright 2003-2008
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
11 * See file CREDITS for list of people who contributed to this
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #include <asm/processor.h>
37 static void sdram_start (int hi_addr
)
39 long hi_addr_bit
= hi_addr
? 0x01000000 : 0;
41 /* unlock mode register */
42 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000000 | hi_addr_bit
;
43 __asm__
volatile ("sync");
45 /* precharge all banks */
46 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000002 | hi_addr_bit
;
47 __asm__
volatile ("sync");
50 /* set mode register: extended mode */
51 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_EMODE
;
52 __asm__
volatile ("sync");
54 /* set mode register: reset DLL */
55 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_MODE
| 0x04000000;
56 __asm__
volatile ("sync");
59 /* precharge all banks */
60 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000002 | hi_addr_bit
;
61 __asm__
volatile ("sync");
64 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000004 | hi_addr_bit
;
65 __asm__
volatile ("sync");
67 /* set mode register */
68 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_MODE
;
69 __asm__
volatile ("sync");
71 /* normal operation */
72 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| hi_addr_bit
;
73 __asm__
volatile ("sync");
78 * ATTENTION: Although partially referenced initdram does NOT make real use
79 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
80 * is something else than 0x00000000.
83 long int initdram (int board_type
)
90 /* setup SDRAM chip selects */
91 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0x0000001c; /* 512MB at 0x0 */
92 *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
= 0x40000000; /* disabled */
93 __asm__
volatile ("sync");
95 /* setup config registers */
96 *(vu_long
*)MPC5XXX_SDRAM_CONFIG1
= SDRAM_CONFIG1
;
97 *(vu_long
*)MPC5XXX_SDRAM_CONFIG2
= SDRAM_CONFIG2
;
98 __asm__
volatile ("sync");
102 *(vu_long
*)MPC5XXX_CDM_PORCFG
= SDRAM_TAPDELAY
;
103 __asm__
volatile ("sync");
106 /* find RAM size using SDRAM CS0 only */
108 test1
= get_ram_size((long *)CFG_SDRAM_BASE
, 0x20000000);
110 test2
= get_ram_size((long *)CFG_SDRAM_BASE
, 0x20000000);
118 /* memory smaller than 1MB is impossible */
119 if (dramsize
< (1 << 20)) {
123 /* set SDRAM CS0 size according to the amount of RAM found */
125 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0x13 +
126 __builtin_ffs(dramsize
>> 20) - 1;
128 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0; /* disabled */
131 *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
= dramsize
; /* disabled */
132 #else /* CFG_RAMBOOT */
134 /* retrieve size of memory connected to SDRAM CS0 */
135 dramsize
= *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
& 0xFF;
136 if (dramsize
>= 0x13) {
137 dramsize
= (1 << (dramsize
- 0x13)) << 20;
142 /* retrieve size of memory connected to SDRAM CS1 */
143 dramsize2
= *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
& 0xFF;
144 if (dramsize2
>= 0x13) {
145 dramsize2
= (1 << (dramsize2
- 0x13)) << 20;
150 #endif /* CFG_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 /* return dramsize + dramsize2; */
174 int checkboard (void)
176 puts ("Board: HMI1001\n");
180 #ifdef CONFIG_PREBOOT
182 static uchar kbd_magic_prefix
[] = "key_magic";
183 static uchar kbd_command_prefix
[] = "key_cmd";
194 struct kbd_data_t
* get_keys (struct kbd_data_t
*kbd_data
)
196 kbd_data
->s1
= *((volatile uchar
*)(CFG_STATUS1_BASE
));
197 kbd_data
->s2
= *((volatile uchar
*)(CFG_STATUS2_BASE
));
202 static int compare_magic (const struct kbd_data_t
*kbd_data
, char *str
)
207 if (s1
>= '0' && s1
<= '9')
209 else if (s1
>= 'a' && s1
<= 'f')
211 else if (s1
>= 'A' && s1
<= 'F')
216 if (((S1_ROT
& kbd_data
->s1
) >> 4) != s1
)
219 s2
= (S2_Q
| S2_M
) & kbd_data
->s2
;
233 if (s2
== (S2_Q
| S2_M
))
245 static char *key_match (const struct kbd_data_t
*kbd_data
)
247 char magic
[sizeof (kbd_magic_prefix
) + 1];
249 char *kbd_magic_keys
;
252 * The following string defines the characters that can be appended
253 * to "key_magic" to form the names of environment variables that
254 * hold "magic" key codes, i. e. such key codes that can cause
255 * pre-boot actions. If the string is empty (""), then only
256 * "key_magic" is checked (old behaviour); the string "125" causes
257 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
259 if ((kbd_magic_keys
= getenv ("magic_keys")) == NULL
)
262 /* loop over all magic keys;
263 * use '\0' suffix in case of empty string
265 for (suffix
= kbd_magic_keys
; *suffix
||
266 suffix
== kbd_magic_keys
; ++suffix
) {
267 sprintf (magic
, "%s%c", kbd_magic_prefix
, *suffix
);
269 if (compare_magic(kbd_data
, getenv(magic
)) == 0) {
270 char cmd_name
[sizeof (kbd_command_prefix
) + 1];
273 sprintf (cmd_name
, "%s%c", kbd_command_prefix
, *suffix
);
274 cmd
= getenv (cmd_name
);
283 #endif /* CONFIG_PREBOOT */
285 int misc_init_r (void)
287 #ifdef CONFIG_PREBOOT
288 struct kbd_data_t kbd_data
;
290 char *str
= strdup (key_match (get_keys (&kbd_data
)));
291 /* Set or delete definition */
292 setenv ("preboot", str
);
294 #endif /* CONFIG_PREBOOT */
299 int board_early_init_r (void)
301 *(vu_long
*)MPC5XXX_BOOTCS_CFG
&= ~0x1; /* clear RO */
302 *(vu_long
*)MPC5XXX_BOOTCS_START
=
303 *(vu_long
*)MPC5XXX_CS0_START
= START_REG(CFG_FLASH_BASE
);
304 *(vu_long
*)MPC5XXX_BOOTCS_STOP
=
305 *(vu_long
*)MPC5XXX_CS0_STOP
= STOP_REG(CFG_FLASH_BASE
, CFG_FLASH_SIZE
);
309 static struct pci_controller hose
;
311 extern void pci_mpc5xxx_init(struct pci_controller
*);
313 void pci_init_board(void)
315 pci_mpc5xxx_init(&hose
);