]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/mcc200/mcc200.c
Merge /home/roy/CVS/7448/Open_Source/u-boot.git.dev
[karo-tx-uboot.git] / board / mcc200 / mcc200.c
1 /*
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 #include <asm/processor.h>
31
32 /* Two MT48LC8M32B2 for 32 MB */
33 /* #include "mt48lc8m32b2-6-7.h" */
34
35 /* One MT48LC16M32S2 for 64 MB */
36 /* #include "mt48lc16m32s2-75.h" */
37 #if defined (CONFIG_MCC200_SDRAM)
38 #include "mt48lc16m16a2-75.h"
39 #else
40 #include "mt46v16m16-75.h"
41 #endif
42
43 DECLARE_GLOBAL_DATA_PTR;
44
45 extern flash_info_t flash_info[];       /* FLASH chips info */
46
47 ulong flash_get_size (ulong base, int banknum);
48
49 #ifndef CFG_RAMBOOT
50 static void sdram_start (int hi_addr)
51 {
52         long hi_addr_bit = hi_addr ? 0x01000000 : 0;
53
54         /* unlock mode register */
55         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
56         __asm__ volatile ("sync");
57
58         /* precharge all banks */
59         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
60         __asm__ volatile ("sync");
61
62 #if SDRAM_DDR
63         /* set mode register: extended mode */
64         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
65         __asm__ volatile ("sync");
66
67         /* set mode register: reset DLL */
68         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
69         __asm__ volatile ("sync");
70 #endif
71
72         /* precharge all banks */
73         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
74         __asm__ volatile ("sync");
75
76         /* auto refresh */
77         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
78         __asm__ volatile ("sync");
79
80         /* set mode register */
81         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
82         __asm__ volatile ("sync");
83
84         /* normal operation */
85         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
86         __asm__ volatile ("sync");
87
88         udelay(10);
89 }
90 #endif
91
92 /*
93  * ATTENTION: Although partially referenced initdram does NOT make real use
94  *            use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
95  *            is something else than 0x00000000.
96  */
97
98 long int initdram (int board_type)
99 {
100         ulong dramsize = 0;
101         ulong dramsize2 = 0;
102         uint svr, pvr;
103 #ifndef CFG_RAMBOOT
104         ulong test1, test2;
105
106         /* setup SDRAM chip selects */
107         *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
108         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
109         __asm__ volatile ("sync");
110
111         /* setup config registers */
112         *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
113         *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
114         __asm__ volatile ("sync");
115
116 #if SDRAM_DDR
117         /* set tap delay */
118         *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
119         __asm__ volatile ("sync");
120 #endif
121
122         /* find RAM size using SDRAM CS0 only */
123         sdram_start(0);
124         test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
125         sdram_start(1);
126         test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
127         if (test1 > test2) {
128                 sdram_start(0);
129                 dramsize = test1;
130         } else {
131                 dramsize = test2;
132         }
133
134         /* memory smaller than 1MB is impossible */
135         if (dramsize < (1 << 20)) {
136                 dramsize = 0;
137         }
138
139         /* set SDRAM CS0 size according to the amount of RAM found */
140         if (dramsize > 0) {
141                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
142         } else {
143                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
144         }
145
146         /* let SDRAM CS1 start right after CS0 */
147         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
148
149         /* find RAM size using SDRAM CS1 only */
150         if (!dramsize)
151                 sdram_start(0);
152         test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
153         if (!dramsize) {
154                 sdram_start(1);
155                 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
156         }
157         if (test1 > test2) {
158                 sdram_start(0);
159                 dramsize2 = test1;
160         } else {
161                 dramsize2 = test2;
162         }
163
164         /* memory smaller than 1MB is impossible */
165         if (dramsize2 < (1 << 20)) {
166                 dramsize2 = 0;
167         }
168
169         /* set SDRAM CS1 size according to the amount of RAM found */
170         if (dramsize2 > 0) {
171                 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
172                         | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
173         } else {
174                 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
175         }
176
177 #else /* CFG_RAMBOOT */
178
179         /* retrieve size of memory connected to SDRAM CS0 */
180         dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
181         if (dramsize >= 0x13) {
182                 dramsize = (1 << (dramsize - 0x13)) << 20;
183         } else {
184                 dramsize = 0;
185         }
186
187         /* retrieve size of memory connected to SDRAM CS1 */
188         dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
189         if (dramsize2 >= 0x13) {
190                 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
191         } else {
192                 dramsize2 = 0;
193         }
194
195 #endif /* CFG_RAMBOOT */
196
197         /*
198          * On MPC5200B we need to set the special configuration delay in the
199          * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
200          * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
201          *
202          * "The SDelay should be written to a value of 0x00000004. It is
203          * required to account for changes caused by normal wafer processing
204          * parameters."
205          */
206         svr = get_svr();
207         pvr = get_pvr();
208         if ((SVR_MJREV(svr) >= 2) && (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
209                 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
210                 __asm__ volatile ("sync");
211         }
212
213         return dramsize + dramsize2;
214 }
215
216 int checkboard (void)
217 {
218 #if defined(CONFIG_PRS200)
219         puts ("Board: PRS200\n");
220 #else
221         puts ("Board: MCC200\n");
222 #endif
223         return 0;
224 }
225
226 int misc_init_r (void)
227 {
228         ulong flash_sup_end, snum;
229
230         /*
231          * Adjust flash start and offset to detected values
232          */
233         gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
234         gd->bd->bi_flashoffset = 0;
235
236         /*
237          * Check if boot FLASH isn't max size
238          */
239         if (gd->bd->bi_flashsize < (0 - CFG_FLASH_BASE)) {
240                 /* adjust mapping */
241                 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
242                         START_REG(gd->bd->bi_flashstart);
243                 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
244                         STOP_REG(gd->bd->bi_flashstart, gd->bd->bi_flashsize);
245
246                 /*
247                  * Re-check to get correct base address
248                  */
249                 flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
250
251                 /*
252                  * Re-do flash protection upon new addresses
253                  */
254                 flash_protect (FLAG_PROTECT_CLEAR,
255                                gd->bd->bi_flashstart, 0xffffffff,
256                                &flash_info[CFG_MAX_FLASH_BANKS - 1]);
257
258                 /* Monitor protection ON by default */
259                 flash_protect (FLAG_PROTECT_SET,
260                                CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
261                                &flash_info[CFG_MAX_FLASH_BANKS - 1]);
262
263                 /* Environment protection ON by default */
264                 flash_protect (FLAG_PROTECT_SET,
265                                CFG_ENV_ADDR,
266                                CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
267                                &flash_info[CFG_MAX_FLASH_BANKS - 1]);
268
269                 /* Redundant environment protection ON by default */
270                 flash_protect (FLAG_PROTECT_SET,
271                                CFG_ENV_ADDR_REDUND,
272                                CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
273                                &flash_info[CFG_MAX_FLASH_BANKS - 1]);
274         }
275
276         if (gd->bd->bi_flashsize > (32 << 20)) {
277                 /* Unprotect the upper bank of the Flash */
278                 *(volatile int*)MPC5XXX_CS0_CFG |= (1 << 6);
279                 flash_protect (FLAG_PROTECT_CLEAR,
280                                flash_info[0].start[0] + flash_info[0].size / 2,
281                                (flash_info[0].start[0] - 1) + flash_info[0].size,
282                                &flash_info[0]);
283                 *(volatile int*)MPC5XXX_CS0_CFG &= ~(1 << 6);
284                 printf ("Warning: Only 32 of 64 MB of Flash are accessible from U-Boot\n");
285                 flash_info[0].size = 32 << 20;
286                 for (snum = 0, flash_sup_end = gd->bd->bi_flashstart + (32<<20);
287                         flash_info[0].start[snum] < flash_sup_end;
288                         snum++);
289                 flash_info[0].sector_count = snum;
290         }
291
292         return (0);
293 }
294
295 #ifdef  CONFIG_PCI
296 static struct pci_controller hose;
297
298 extern void pci_mpc5xxx_init(struct pci_controller *);
299
300 void pci_init_board(void)
301 {
302         pci_mpc5xxx_init(&hose);
303 }
304 #endif
305
306 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
307
308 void init_ide_reset (void)
309 {
310         debug ("init_ide_reset\n");
311
312 }
313
314 void ide_set_reset (int idereset)
315 {
316         debug ("ide_reset(%d)\n", idereset);
317
318 }
319 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
320
321 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
322 extern void doc_probe (ulong physadr);
323 void doc_init (void)
324 {
325         doc_probe (CFG_DOC_BASE);
326 }
327 #endif