blob: acc0e06862df63e1cc12678d7b7b56fe7b65ab2d [file] [log] [blame]
Wolfgang Denk07ad17c2006-02-22 00:43:16 +01001/*
2 * (C) Copyright 2003-2006
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 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28#include <mpc5xxx.h>
29#include <pci.h>
30
31//###CHD: es gibt eigentlich kein DDR bei uns -> weg damit!; dto. PCI!
32#if defined(CONFIG_MPC5200_DDR)
33#include "mt46v16m16-75.h"
34#else
35//#include "mt48lc16m16a2-75.h"
36#include "mt48lc8m32b2-6-7.h"
37#endif
38
Stefan Roese254a3d02006-02-28 15:33:28 +010039extern flash_info_t flash_info[]; /* FLASH chips info */
40
Stefan Roese896391f2006-03-01 17:00:49 +010041ulong flash_get_size (ulong base, int banknum);
42
Wolfgang Denk07ad17c2006-02-22 00:43:16 +010043//###CHD: wenn RAMBOOT gehen wuerde, ....
44#ifndef CFG_RAMBOOT
45static void sdram_start (int hi_addr)
46{
47 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
48
49 /* unlock mode register */
50 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
51 __asm__ volatile ("sync");
52
53 /* precharge all banks */
54 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
55 __asm__ volatile ("sync");
56
57#if SDRAM_DDR
58 /* set mode register: extended mode */
59 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
60 __asm__ volatile ("sync");
61
62 /* set mode register: reset DLL */
63 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
64 __asm__ volatile ("sync");
65#endif
66
67 /* precharge all banks */
68 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
69 __asm__ volatile ("sync");
70
71 /* auto refresh */
72 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
73 __asm__ volatile ("sync");
74
75 /* set mode register */
76 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
77 __asm__ volatile ("sync");
78
79 /* normal operation */
80 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
81 __asm__ volatile ("sync");
82}
83#endif
84
85/*
86 * ATTENTION: Although partially referenced initdram does NOT make real use
87 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
88 * is something else than 0x00000000.
89 */
90
91#if defined(CONFIG_MPC5200)
92long int initdram (int board_type)
93{
94 ulong dramsize = 0;
95 ulong dramsize2 = 0;
96#ifndef CFG_RAMBOOT
97 ulong test1, test2;
98
99 /* setup SDRAM chip selects */
100 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
101 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
102 __asm__ volatile ("sync");
103
104 /* setup config registers */
105 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
106 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
107 __asm__ volatile ("sync");
108
109#if SDRAM_DDR
110 /* set tap delay */
111 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
112 __asm__ volatile ("sync");
113#endif
114
115 /* find RAM size using SDRAM CS0 only */
116 sdram_start(0);
117 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
118 sdram_start(1);
119 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
120 if (test1 > test2) {
121 sdram_start(0);
122 dramsize = test1;
123 } else {
124 dramsize = test2;
125 }
126
127 /* memory smaller than 1MB is impossible */
128 if (dramsize < (1 << 20)) {
129 dramsize = 0;
130 }
131
132 /* set SDRAM CS0 size according to the amount of RAM found */
133 if (dramsize > 0) {
134 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
135 } else {
136 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
137 }
138
139 /* let SDRAM CS1 start right after CS0 */
140 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
141
142 /* find RAM size using SDRAM CS1 only */
143 if (!dramsize)
144 sdram_start(0);
145 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
146 if (!dramsize) {
147 sdram_start(1);
148 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
149 }
150 if (test1 > test2) {
151 sdram_start(0);
152 dramsize2 = test1;
153 } else {
154 dramsize2 = test2;
155 }
156
157 /* memory smaller than 1MB is impossible */
158 if (dramsize2 < (1 << 20)) {
159 dramsize2 = 0;
160 }
161
162 /* set SDRAM CS1 size according to the amount of RAM found */
163 if (dramsize2 > 0) {
164 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
165 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
166 } else {
167 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
168 }
169
170#else /* CFG_RAMBOOT */
171
172 /* retrieve size of memory connected to SDRAM CS0 */
173 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
174 if (dramsize >= 0x13) {
175 dramsize = (1 << (dramsize - 0x13)) << 20;
176 } else {
177 dramsize = 0;
178 }
179
180 /* retrieve size of memory connected to SDRAM CS1 */
181 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
182 if (dramsize2 >= 0x13) {
183 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
184 } else {
185 dramsize2 = 0;
186 }
187
188#endif /* CFG_RAMBOOT */
189
190 return dramsize + dramsize2;
191}
192
193//###CHD: sowas gibt es bei usn nicht!
194#elif defined(CONFIG_MGT5100)
195
196long int initdram (int board_type)
197{
198 ulong dramsize = 0;
199#ifndef CFG_RAMBOOT
200 ulong test1, test2;
201
202 /* setup and enable SDRAM chip selects */
203 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
204 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
205 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
206 __asm__ volatile ("sync");
207
208 /* setup config registers */
209 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
210 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
211
212 /* address select register */
213 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
214 __asm__ volatile ("sync");
215
216 /* find RAM size */
217 sdram_start(0);
218 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
219 sdram_start(1);
220 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
221 if (test1 > test2) {
222 sdram_start(0);
223 dramsize = test1;
224 } else {
225 dramsize = test2;
226 }
227
228 /* set SDRAM end address according to size */
229 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
230
231#else /* CFG_RAMBOOT */
232
233 /* Retrieve amount of SDRAM available */
234 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
235
236#endif /* CFG_RAMBOOT */
237
238 return dramsize;
239}
240
241#else
242#error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
243#endif
244
245int checkboard (void)
246{
Wolfgang Denkce87cf92006-02-24 01:42:40 +0100247 puts ("Board: MCC200\n");
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100248 return 0;
249}
250
Stefan Roese254a3d02006-02-28 15:33:28 +0100251int misc_init_r (void)
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100252{
Stefan Roese254a3d02006-02-28 15:33:28 +0100253 DECLARE_GLOBAL_DATA_PTR;
254
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100255 /*
Stefan Roese254a3d02006-02-28 15:33:28 +0100256 * Adjust flash start and offset to detected values
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100257 */
Stefan Roese254a3d02006-02-28 15:33:28 +0100258 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
259 gd->bd->bi_flashoffset = 0;
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100260
Stefan Roese254a3d02006-02-28 15:33:28 +0100261 /*
262 * Check if boot FLASH isn't max size
263 */
264 if (gd->bd->bi_flashsize < (0 - CFG_FLASH_BASE)) {
265 /* adjust mapping */
266 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
267 START_REG(gd->bd->bi_flashstart);
268 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
269 STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize);
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100270
Stefan Roese254a3d02006-02-28 15:33:28 +0100271 /*
272 * Re-check to get correct base address
273 */
274 flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100275
Stefan Roese254a3d02006-02-28 15:33:28 +0100276 /*
277 * Re-do flash protection upon new addresses
278 */
279 flash_protect (FLAG_PROTECT_CLEAR,
280 gd->bd->bi_flashstart, 0xffffffff,
281 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100282
Stefan Roese254a3d02006-02-28 15:33:28 +0100283 /* Monitor protection ON by default */
284 flash_protect (FLAG_PROTECT_SET,
285 CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
286 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
287
288 /* Environment protection ON by default */
289 flash_protect (FLAG_PROTECT_SET,
290 CFG_ENV_ADDR,
291 CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
292 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
293
294 /* Redundant environment protection ON by default */
295 flash_protect (FLAG_PROTECT_SET,
296 CFG_ENV_ADDR_REDUND,
297 CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
298 &flash_info[CFG_MAX_FLASH_BANKS - 1]);
299 }
300
Wolfgang Denk07ad17c2006-02-22 00:43:16 +0100301 return (0);
302}
303
304#ifdef CONFIG_PCI
305static struct pci_controller hose;
306
307extern void pci_mpc5xxx_init(struct pci_controller *);
308
309void pci_init_board(void)
310{
311 pci_mpc5xxx_init(&hose);
312}
313#endif
314
315#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
316
317void init_ide_reset (void)
318{
319 debug ("init_ide_reset\n");
320
321}
322
323void ide_set_reset (int idereset)
324{
325 debug ("ide_reset(%d)\n", idereset);
326
327}
328#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
329
330#if (CONFIG_COMMANDS & CFG_CMD_DOC)
331extern void doc_probe (ulong physadr);
332void doc_init (void)
333{
334 doc_probe (CFG_DOC_BASE);
335}
336#endif