blob: dd2e1916e045de9d793ab5dfc0a2189917da2f06 [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
39//###CHD: wenn RAMBOOT gehen wuerde, ....
40#ifndef CFG_RAMBOOT
41static void sdram_start (int hi_addr)
42{
43 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
44
45 /* unlock mode register */
46 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
47 __asm__ volatile ("sync");
48
49 /* precharge all banks */
50 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
51 __asm__ volatile ("sync");
52
53#if SDRAM_DDR
54 /* set mode register: extended mode */
55 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
56 __asm__ volatile ("sync");
57
58 /* set mode register: reset DLL */
59 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
60 __asm__ volatile ("sync");
61#endif
62
63 /* precharge all banks */
64 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
65 __asm__ volatile ("sync");
66
67 /* auto refresh */
68 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
69 __asm__ volatile ("sync");
70
71 /* set mode register */
72 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
73 __asm__ volatile ("sync");
74
75 /* normal operation */
76 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
77 __asm__ volatile ("sync");
78}
79#endif
80
81/*
82 * ATTENTION: Although partially referenced initdram does NOT make real use
83 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
84 * is something else than 0x00000000.
85 */
86
87#if defined(CONFIG_MPC5200)
88long int initdram (int board_type)
89{
90 ulong dramsize = 0;
91 ulong dramsize2 = 0;
92#ifndef CFG_RAMBOOT
93 ulong test1, test2;
94
95 /* setup SDRAM chip selects */
96 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
97 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
98 __asm__ volatile ("sync");
99
100 /* setup config registers */
101 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
102 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
103 __asm__ volatile ("sync");
104
105#if SDRAM_DDR
106 /* set tap delay */
107 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
108 __asm__ volatile ("sync");
109#endif
110
111 /* find RAM size using SDRAM CS0 only */
112 sdram_start(0);
113 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
114 sdram_start(1);
115 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
116 if (test1 > test2) {
117 sdram_start(0);
118 dramsize = test1;
119 } else {
120 dramsize = test2;
121 }
122
123 /* memory smaller than 1MB is impossible */
124 if (dramsize < (1 << 20)) {
125 dramsize = 0;
126 }
127
128 /* set SDRAM CS0 size according to the amount of RAM found */
129 if (dramsize > 0) {
130 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
131 } else {
132 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
133 }
134
135 /* let SDRAM CS1 start right after CS0 */
136 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
137
138 /* find RAM size using SDRAM CS1 only */
139 if (!dramsize)
140 sdram_start(0);
141 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
142 if (!dramsize) {
143 sdram_start(1);
144 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
145 }
146 if (test1 > test2) {
147 sdram_start(0);
148 dramsize2 = test1;
149 } else {
150 dramsize2 = test2;
151 }
152
153 /* memory smaller than 1MB is impossible */
154 if (dramsize2 < (1 << 20)) {
155 dramsize2 = 0;
156 }
157
158 /* set SDRAM CS1 size according to the amount of RAM found */
159 if (dramsize2 > 0) {
160 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
161 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
162 } else {
163 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
164 }
165
166#else /* CFG_RAMBOOT */
167
168 /* retrieve size of memory connected to SDRAM CS0 */
169 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
170 if (dramsize >= 0x13) {
171 dramsize = (1 << (dramsize - 0x13)) << 20;
172 } else {
173 dramsize = 0;
174 }
175
176 /* retrieve size of memory connected to SDRAM CS1 */
177 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
178 if (dramsize2 >= 0x13) {
179 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
180 } else {
181 dramsize2 = 0;
182 }
183
184#endif /* CFG_RAMBOOT */
185
186 return dramsize + dramsize2;
187}
188
189//###CHD: sowas gibt es bei usn nicht!
190#elif defined(CONFIG_MGT5100)
191
192long int initdram (int board_type)
193{
194 ulong dramsize = 0;
195#ifndef CFG_RAMBOOT
196 ulong test1, test2;
197
198 /* setup and enable SDRAM chip selects */
199 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
200 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
201 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
202 __asm__ volatile ("sync");
203
204 /* setup config registers */
205 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
206 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
207
208 /* address select register */
209 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
210 __asm__ volatile ("sync");
211
212 /* find RAM size */
213 sdram_start(0);
214 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
215 sdram_start(1);
216 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
217 if (test1 > test2) {
218 sdram_start(0);
219 dramsize = test1;
220 } else {
221 dramsize = test2;
222 }
223
224 /* set SDRAM end address according to size */
225 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
226
227#else /* CFG_RAMBOOT */
228
229 /* Retrieve amount of SDRAM available */
230 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
231
232#endif /* CFG_RAMBOOT */
233
234 return dramsize;
235}
236
237#else
238#error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
239#endif
240
241int checkboard (void)
242{
243 puts("Board: Bluetechnix DevMPC5200Leica \n");
244/*
245#if defined(CONFIG_MPC5200)
246 puts ("Board: MicroSys PM520 \n");
247#elif defined(CONFIG_MGT5100)
248 puts ("Board: MicroSys PM510 \n");
249#endif*/
250 return 0;
251}
252
253void flash_preinit(void)
254{
255 /*
256 * Now, when we are in RAM, enable flash write
257 * access for detection process.
258 * Note that CS_BOOT cannot be cleared when
259 * executing in flash.
260 */
261#if defined(CONFIG_MGT5100)
262 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
263 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
264#endif
265 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
266}
267
268void flash_afterinit(ulong start, ulong size)
269{
270#if defined(CONFIG_BOOT_ROM)
271 /* adjust mapping */
272 *(vu_long *)MPC5XXX_CS1_START =
273 START_REG(start);
274 *(vu_long *)MPC5XXX_CS1_STOP =
275 STOP_REG(start, size);
276#else
277 /* adjust mapping */
278 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
279 START_REG(start);
280 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
281 STOP_REG(start, size);
282#endif
283}
284
285
286extern flash_info_t flash_info[]; /* info for FLASH chips */
287
288int misc_init_r (void)
289{
290 DECLARE_GLOBAL_DATA_PTR;
291 /* adjust flash start */
292 gd->bd->bi_flashstart = flash_info[0].start[0];
293 return (0);
294}
295
296#ifdef CONFIG_PCI
297static struct pci_controller hose;
298
299extern void pci_mpc5xxx_init(struct pci_controller *);
300
301void pci_init_board(void)
302{
303 pci_mpc5xxx_init(&hose);
304}
305#endif
306
307#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
308
309void init_ide_reset (void)
310{
311 debug ("init_ide_reset\n");
312
313}
314
315void ide_set_reset (int idereset)
316{
317 debug ("ide_reset(%d)\n", idereset);
318
319}
320#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
321
322#if (CONFIG_COMMANDS & CFG_CMD_DOC)
323extern void doc_probe (ulong physadr);
324void doc_init (void)
325{
326 doc_probe (CFG_DOC_BASE);
327}
328#endif