to make u-boot work for fat32 filesystem
[jz_uboot.git] / board / hmi1001 / hmi1001.c
blob237e8631657d51f9c320f5e3db23d23a55482831
1 /*
2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
8 * (C) Copyright 2004
9 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
11 * See file CREDITS for list of people who contributed to this
12 * project.
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,
27 * MA 02111-1307 USA
30 #include <common.h>
31 #include <mpc5xxx.h>
32 #include <pci.h>
33 #include <malloc.h>
35 #ifndef CFG_RAMBOOT
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");
48 #if SDRAM_DDR
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");
56 #endif
58 /* precharge all banks */
59 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
60 __asm__ volatile ("sync");
62 /* auto refresh */
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");
74 #endif
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)
84 ulong dramsize = 0;
85 #ifndef CFG_RAMBOOT
86 ulong test1, test2;
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");
98 #if SDRAM_DDR
99 /* set tap delay */
100 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
101 __asm__ volatile ("sync");
102 #endif
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;
116 /* memory smaller than 1MB is impossible */
117 if (dramsize < (1 << 20)) {
118 dramsize = 0;
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 */
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;
136 } else {
137 dramsize = 0;
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;
148 #endif /* CFG_RAMBOOT */
150 /* return dramsize + dramsize2; */
151 return dramsize;
154 int checkboard (void)
156 puts ("Board: HMI1001\n");
157 return 0;
160 #ifdef CONFIG_PREBOOT
162 static uchar kbd_magic_prefix[] = "key_magic";
163 static uchar kbd_command_prefix[] = "key_cmd";
165 #define S1_ROT 0xf0
166 #define S2_Q 0x40
167 #define S2_M 0x20
169 struct kbd_data_t {
170 char s1;
171 char s2;
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));
179 return kbd_data;
182 static int compare_magic (const struct kbd_data_t *kbd_data, uchar *str)
184 char s1 = str[0];
185 char s2;
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;
196 if (((S1_ROT & kbd_data->s1) >> 4) != s1)
197 return -1;
199 s2 = (S2_Q | S2_M) & kbd_data->s2;
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;
219 if (str[2])
220 return -1;
222 return 0;
225 static uchar *key_match (const struct kbd_data_t *kbd_data)
227 uchar magic[sizeof (kbd_magic_prefix) + 1];
228 uchar *suffix;
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)
240 kbd_magic_keys = "";
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];
251 char *cmd;
253 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
254 cmd = getenv (cmd_name);
256 return (cmd);
260 return (NULL);
263 #endif /* CONFIG_PREBOOT */
265 int misc_init_r (void)
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 */
276 return 0;
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);
286 return 0;
288 #ifdef CONFIG_PCI
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);
297 #endif