]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/hmi1001/hmi1001.c
Restructure POST directory to support of other CPUs, boards, etc.
[people/ms/u-boot.git] / board / hmi1001 / hmi1001.c
CommitLineData
a87589da
WD
1/*
2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
8 * (C) Copyright 2004
9 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
10 *
11 * See file CREDITS for list of people who contributed to this
12 * project.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307 USA
28 */
29
30#include <common.h>
31#include <mpc5xxx.h>
32#include <pci.h>
6d51e505 33#include <malloc.h>
a87589da
WD
34
35#ifndef CFG_RAMBOOT
36static void sdram_start (int hi_addr)
37{
38 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
39
40 /* unlock mode register */
41 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
42 __asm__ volatile ("sync");
43
44 /* precharge all banks */
45 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
46 __asm__ volatile ("sync");
47
48#if SDRAM_DDR
49 /* set mode register: extended mode */
50 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
51 __asm__ volatile ("sync");
52
53 /* set mode register: reset DLL */
54 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
55 __asm__ volatile ("sync");
56#endif
57
58 /* precharge all banks */
59 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
60 __asm__ volatile ("sync");
61
62 /* auto refresh */
63 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
64 __asm__ volatile ("sync");
65
66 /* set mode register */
67 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
68 __asm__ volatile ("sync");
69
70 /* normal operation */
71 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
72 __asm__ volatile ("sync");
73}
74#endif
75
76/*
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.
80 */
81
82long int initdram (int board_type)
83{
84 ulong dramsize = 0;
85#ifndef CFG_RAMBOOT
86 ulong test1, test2;
87
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");
92
93 /* setup config registers */
94 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
95 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
96 __asm__ volatile ("sync");
97
98#if SDRAM_DDR
99 /* set tap delay */
100 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
101 __asm__ volatile ("sync");
102#endif
103
104 /* find RAM size using SDRAM CS0 only */
105 sdram_start(0);
106 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
107 sdram_start(1);
108 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
109 if (test1 > test2) {
110 sdram_start(0);
111 dramsize = test1;
112 } else {
113 dramsize = test2;
114 }
115
116 /* memory smaller than 1MB is impossible */
117 if (dramsize < (1 << 20)) {
118 dramsize = 0;
119 }
120
121 /* set SDRAM CS0 size according to the amount of RAM found */
122 if (dramsize > 0) {
123 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
124 __builtin_ffs(dramsize >> 20) - 1;
125 } else {
126 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
127 }
128
129 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
130#else /* CFG_RAMBOOT */
131
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;
136 } else {
137 dramsize = 0;
138 }
139
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;
144 } else {
145 dramsize2 = 0;
146 }
147
148#endif /* CFG_RAMBOOT */
149
150/* return dramsize + dramsize2; */
151 return dramsize;
152}
153
154int checkboard (void)
155{
156 puts ("Board: HMI1001\n");
157 return 0;
158}
159
9f96ae44
WD
160#ifdef CONFIG_PREBOOT
161
162static uchar kbd_magic_prefix[] = "key_magic";
163static uchar kbd_command_prefix[] = "key_cmd";
164
165#define S1_ROT 0xf0
166#define S2_Q 0x40
167#define S2_M 0x20
168
169struct kbd_data_t {
170 char s1;
171 char s2;
172};
173
174struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
175{
176 kbd_data->s1 = *((volatile uchar*)(CFG_STATUS1_BASE));
177 kbd_data->s2 = *((volatile uchar*)(CFG_STATUS2_BASE));
178
179 return kbd_data;
180}
181
6d51e505 182static int compare_magic (const struct kbd_data_t *kbd_data, uchar *str)
9f96ae44
WD
183{
184 char s1 = str[0];
185 char s2;
186
187 if (s1 >= '0' && s1 <= '9')
188 s1 -= '0';
189 else if (s1 >= 'a' && s1 <= 'f')
190 s1 = s1 - 'a' + 10;
191 else if (s1 >= 'A' && s1 <= 'F')
192 s1 = s1 - 'A' + 10;
193 else
194 return -1;
195
196 if (((S1_ROT & kbd_data->s1) >> 4) != s1)
197 return -1;
198
199 s2 = (S2_Q | S2_M) & kbd_data->s2;
200
201 switch (str[1]) {
202 case 'q':
203 case 'Q':
204 if (s2 == S2_Q)
205 return -1;
206 break;
207 case 'm':
208 case 'M':
209 if (s2 == S2_M)
210 return -1;
211 break;
212 case '\0':
213 if (s2 == (S2_Q | S2_M))
214 return 0;
215 default:
216 return -1;
217 }
218
219 if (str[2])
220 return -1;
221
222 return 0;
223}
224
225static uchar *key_match (const struct kbd_data_t *kbd_data)
226{
227 uchar magic[sizeof (kbd_magic_prefix) + 1];
228 uchar *suffix;
229 uchar *kbd_magic_keys;
230
231 /*
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.
238 */
239 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
240 kbd_magic_keys = "";
241
242 /* loop over all magic keys;
243 * use '\0' suffix in case of empty string
244 */
245 for (suffix = kbd_magic_keys; *suffix ||
246 suffix == kbd_magic_keys; ++suffix) {
247 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
248
249 if (compare_magic(kbd_data, getenv(magic)) == 0) {
250 uchar cmd_name[sizeof (kbd_command_prefix) + 1];
251 char *cmd;
252
253 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
254 cmd = getenv (cmd_name);
255
256 return (cmd);
257 }
258 }
259
260 return (NULL);
261}
262
263#endif /* CONFIG_PREBOOT */
264
9f96ae44
WD
265int misc_init_r (void)
266{
267#ifdef CONFIG_PREBOOT
268 struct kbd_data_t kbd_data;
269 /* Decode keys */
270 uchar *str = strdup (key_match (get_keys (&kbd_data)));
271 /* Set or delete definition */
272 setenv ("preboot", str);
273 free (str);
274#endif /* CONFIG_PREBOOT */
275
a87589da
WD
276 return 0;
277}
278
279int board_early_init_r (void)
280{
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);
286 return 0;
287}
98128f38
WD
288#ifdef CONFIG_PCI
289static struct pci_controller hose;
290
291extern void pci_mpc5xxx_init(struct pci_controller *);
292
293void pci_init_board(void)
294{
295 pci_mpc5xxx_init(&hose);
296}
297#endif