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
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,
36 static void sdram_start (int hi_addr
)
38 long hi_addr_bit
= hi_addr
? 0x01000000 : 0;
40 /* unlock mode register */
41 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000000 | hi_addr_bit
;
42 __asm__
volatile ("sync");
44 /* precharge all banks */
45 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000002 | hi_addr_bit
;
46 __asm__
volatile ("sync");
49 /* set mode register: extended mode */
50 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_EMODE
;
51 __asm__
volatile ("sync");
53 /* set mode register: reset DLL */
54 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_MODE
| 0x04000000;
55 __asm__
volatile ("sync");
58 /* precharge all banks */
59 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000002 | hi_addr_bit
;
60 __asm__
volatile ("sync");
63 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| 0x80000004 | hi_addr_bit
;
64 __asm__
volatile ("sync");
66 /* set mode register */
67 *(vu_long
*)MPC5XXX_SDRAM_MODE
= SDRAM_MODE
;
68 __asm__
volatile ("sync");
70 /* normal operation */
71 *(vu_long
*)MPC5XXX_SDRAM_CTRL
= SDRAM_CONTROL
| hi_addr_bit
;
72 __asm__
volatile ("sync");
77 * ATTENTION: Although partially referenced initdram does NOT make real use
78 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
79 * is something else than 0x00000000.
82 long int initdram (int board_type
)
88 /* setup SDRAM chip selects */
89 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0x0000001c; /* 512MB at 0x0 */
90 *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
= 0x40000000; /* disabled */
91 __asm__
volatile ("sync");
93 /* setup config registers */
94 *(vu_long
*)MPC5XXX_SDRAM_CONFIG1
= SDRAM_CONFIG1
;
95 *(vu_long
*)MPC5XXX_SDRAM_CONFIG2
= SDRAM_CONFIG2
;
96 __asm__
volatile ("sync");
100 *(vu_long
*)MPC5XXX_CDM_PORCFG
= SDRAM_TAPDELAY
;
101 __asm__
volatile ("sync");
104 /* find RAM size using SDRAM CS0 only */
106 test1
= get_ram_size((ulong
*)CFG_SDRAM_BASE
, 0x20000000);
108 test2
= get_ram_size((ulong
*)CFG_SDRAM_BASE
, 0x20000000);
116 /* memory smaller than 1MB is impossible */
117 if (dramsize
< (1 << 20)) {
121 /* set SDRAM CS0 size according to the amount of RAM found */
123 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0x13 +
124 __builtin_ffs(dramsize
>> 20) - 1;
126 *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
= 0; /* disabled */
129 *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
= dramsize
; /* disabled */
130 #else /* CFG_RAMBOOT */
132 /* retrieve size of memory connected to SDRAM CS0 */
133 dramsize
= *(vu_long
*)MPC5XXX_SDRAM_CS0CFG
& 0xFF;
134 if (dramsize
>= 0x13) {
135 dramsize
= (1 << (dramsize
- 0x13)) << 20;
140 /* retrieve size of memory connected to SDRAM CS1 */
141 dramsize2
= *(vu_long
*)MPC5XXX_SDRAM_CS1CFG
& 0xFF;
142 if (dramsize2
>= 0x13) {
143 dramsize2
= (1 << (dramsize2
- 0x13)) << 20;
148 #endif /* CFG_RAMBOOT */
150 /* return dramsize + dramsize2; */
154 int checkboard (void)
156 puts ("Board: HMI1001\n");
160 #ifdef CONFIG_PREBOOT
162 static uchar kbd_magic_prefix
[] = "key_magic";
163 static uchar kbd_command_prefix
[] = "key_cmd";
174 struct kbd_data_t
* get_keys (struct kbd_data_t
*kbd_data
)
176 kbd_data
->s1
= *((volatile uchar
*)(CFG_STATUS1_BASE
));
177 kbd_data
->s2
= *((volatile uchar
*)(CFG_STATUS2_BASE
));
182 static int compare_magic (const struct kbd_data_t
*kbd_data
, uchar
*str
)
187 if (s1
>= '0' && s1
<= '9')
189 else if (s1
>= 'a' && s1
<= 'f')
191 else if (s1
>= 'A' && s1
<= 'F')
196 if (((S1_ROT
& kbd_data
->s1
) >> 4) != s1
)
199 s2
= (S2_Q
| S2_M
) & kbd_data
->s2
;
213 if (s2
== (S2_Q
| S2_M
))
225 static uchar
*key_match (const struct kbd_data_t
*kbd_data
)
227 uchar magic
[sizeof (kbd_magic_prefix
) + 1];
229 uchar
*kbd_magic_keys
;
232 * The following string defines the characters that can be appended
233 * to "key_magic" to form the names of environment variables that
234 * hold "magic" key codes, i. e. such key codes that can cause
235 * pre-boot actions. If the string is empty (""), then only
236 * "key_magic" is checked (old behaviour); the string "125" causes
237 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
239 if ((kbd_magic_keys
= getenv ("magic_keys")) == NULL
)
242 /* loop over all magic keys;
243 * use '\0' suffix in case of empty string
245 for (suffix
= kbd_magic_keys
; *suffix
||
246 suffix
== kbd_magic_keys
; ++suffix
) {
247 sprintf (magic
, "%s%c", kbd_magic_prefix
, *suffix
);
249 if (compare_magic(kbd_data
, getenv(magic
)) == 0) {
250 uchar cmd_name
[sizeof (kbd_command_prefix
) + 1];
253 sprintf (cmd_name
, "%s%c", kbd_command_prefix
, *suffix
);
254 cmd
= getenv (cmd_name
);
263 #endif /* CONFIG_PREBOOT */
265 int misc_init_r (void)
267 #ifdef CONFIG_PREBOOT
268 struct kbd_data_t kbd_data
;
270 uchar
*str
= strdup (key_match (get_keys (&kbd_data
)));
271 /* Set or delete definition */
272 setenv ("preboot", str
);
274 #endif /* CONFIG_PREBOOT */
279 int board_early_init_r (void)
281 *(vu_long
*)MPC5XXX_BOOTCS_CFG
&= ~0x1; /* clear RO */
282 *(vu_long
*)MPC5XXX_BOOTCS_START
=
283 *(vu_long
*)MPC5XXX_CS0_START
= START_REG(CFG_FLASH_BASE
);
284 *(vu_long
*)MPC5XXX_BOOTCS_STOP
=
285 *(vu_long
*)MPC5XXX_CS0_STOP
= STOP_REG(CFG_FLASH_BASE
, CFG_FLASH_SIZE
);
289 static struct pci_controller hose
;
291 extern void pci_mpc5xxx_init(struct pci_controller
*);
293 void pci_init_board(void)
295 pci_mpc5xxx_init(&hose
);