blob: 44831c625a932f37f1be1f15ff5696a378f11248 [file] [log] [blame]
wdenk21136db2003-07-16 21:53:01 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenke44b9112004-04-18 23:32:11 +00005 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
wdenk21136db2003-07-16 21:53:01 +00008 * 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>
wdenk02379022003-08-05 18:22:44 +000029#include <pci.h>
wdenk21136db2003-07-16 21:53:01 +000030
Wolfgang Denk315b46a2006-03-17 11:42:53 +010031#if defined(CONFIG_LITE5200B)
32#include "mt46v32m16.h"
wdenke44b9112004-04-18 23:32:11 +000033#else
Wolfgang Denk315b46a2006-03-17 11:42:53 +010034# if defined(CONFIG_MPC5200_DDR)
35# include "mt46v16m16-75.h"
36# else
wdenke44b9112004-04-18 23:32:11 +000037#include "mt48lc16m16a2-75.h"
Wolfgang Denk315b46a2006-03-17 11:42:53 +010038# endif
wdenke44b9112004-04-18 23:32:11 +000039#endif
wdenkb10ba6b2003-08-28 09:41:22 +000040#ifndef CFG_RAMBOOT
wdenk5d841732003-08-17 18:55:18 +000041static void sdram_start (int hi_addr)
42{
43 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
wdenk21136db2003-07-16 21:53:01 +000044
wdenk236d3fc2003-12-20 22:45:10 +000045 /* unlock mode register */
wdenke44b9112004-04-18 23:32:11 +000046 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
47 __asm__ volatile ("sync");
wdenk20c98a62004-04-23 20:32:05 +000048
wdenk236d3fc2003-12-20 22:45:10 +000049 /* precharge all banks */
wdenke44b9112004-04-18 23:32:11 +000050 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
51 __asm__ volatile ("sync");
52
53#if SDRAM_DDR
wdenk236d3fc2003-12-20 22:45:10 +000054 /* set mode register: extended mode */
wdenke44b9112004-04-18 23:32:11 +000055 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
56 __asm__ volatile ("sync");
57
wdenk236d3fc2003-12-20 22:45:10 +000058 /* set mode register: reset DLL */
wdenke44b9112004-04-18 23:32:11 +000059 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
60 __asm__ volatile ("sync");
wdenk5d841732003-08-17 18:55:18 +000061#endif
wdenke44b9112004-04-18 23:32:11 +000062
63 /* precharge all banks */
64 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
65 __asm__ volatile ("sync");
66
wdenk0e2874cb2004-03-02 14:05:39 +000067 /* auto refresh */
wdenke44b9112004-04-18 23:32:11 +000068 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
69 __asm__ volatile ("sync");
70
wdenk21136db2003-07-16 21:53:01 +000071 /* set mode register */
wdenke44b9112004-04-18 23:32:11 +000072 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
73 __asm__ volatile ("sync");
wdenk20c98a62004-04-23 20:32:05 +000074
wdenk21136db2003-07-16 21:53:01 +000075 /* normal operation */
wdenke44b9112004-04-18 23:32:11 +000076 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
77 __asm__ volatile ("sync");
wdenk5d841732003-08-17 18:55:18 +000078}
wdenkb10ba6b2003-08-28 09:41:22 +000079#endif
wdenk5d841732003-08-17 18:55:18 +000080
wdenke44b9112004-04-18 23:32:11 +000081/*
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)
wdenk5d841732003-08-17 18:55:18 +000088long int initdram (int board_type)
89{
wdenkb10ba6b2003-08-28 09:41:22 +000090 ulong dramsize = 0;
wdenk236d3fc2003-12-20 22:45:10 +000091 ulong dramsize2 = 0;
wdenk5d841732003-08-17 18:55:18 +000092#ifndef CFG_RAMBOOT
wdenkb10ba6b2003-08-28 09:41:22 +000093 ulong test1, test2;
wdenk20c98a62004-04-23 20:32:05 +000094
wdenke44b9112004-04-18 23:32:11 +000095 /* setup SDRAM chip selects */
wdenk5d841732003-08-17 18:55:18 +000096 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
97 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
wdenke44b9112004-04-18 23:32:11 +000098 __asm__ volatile ("sync");
wdenk5d841732003-08-17 18:55:18 +000099
wdenk236d3fc2003-12-20 22:45:10 +0000100 /* setup config registers */
wdenke44b9112004-04-18 23:32:11 +0000101 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
102 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
103 __asm__ volatile ("sync");
wdenk1ebf41e2004-01-02 14:00:00 +0000104
wdenke44b9112004-04-18 23:32:11 +0000105#if SDRAM_DDR
106 /* set tap delay */
107 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
108 __asm__ volatile ("sync");
wdenk236d3fc2003-12-20 22:45:10 +0000109#endif
wdenk5d841732003-08-17 18:55:18 +0000110
wdenke44b9112004-04-18 23:32:11 +0000111 /* find RAM size using SDRAM CS0 only */
wdenk5d841732003-08-17 18:55:18 +0000112 sdram_start(0);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200113 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
wdenk5d841732003-08-17 18:55:18 +0000114 sdram_start(1);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200115 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
wdenk5d841732003-08-17 18:55:18 +0000116 if (test1 > test2) {
117 sdram_start(0);
118 dramsize = test1;
119 } else {
120 dramsize = test2;
121 }
wdenke44b9112004-04-18 23:32:11 +0000122
123 /* memory smaller than 1MB is impossible */
124 if (dramsize < (1 << 20)) {
125 dramsize = 0;
126 }
wdenk20c98a62004-04-23 20:32:05 +0000127
wdenke44b9112004-04-18 23:32:11 +0000128 /* 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
wdenke44b9112004-04-18 23:32:11 +0000135 /* let SDRAM CS1 start right after CS0 */
wdenk236d3fc2003-12-20 22:45:10 +0000136 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
wdenke44b9112004-04-18 23:32:11 +0000137
138 /* find RAM size using SDRAM CS1 only */
wdenke84ec902005-05-05 00:04:14 +0000139 if (!dramsize)
wdenkfaaa6022005-04-21 21:10:22 +0000140 sdram_start(0);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200141 test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000142 if (!dramsize) {
143 sdram_start(1);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200144 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000145 }
wdenk236d3fc2003-12-20 22:45:10 +0000146 if (test1 > test2) {
147 sdram_start(0);
148 dramsize2 = test1;
149 } else {
150 dramsize2 = test2;
151 }
wdenk20c98a62004-04-23 20:32:05 +0000152
wdenke44b9112004-04-18 23:32:11 +0000153 /* memory smaller than 1MB is impossible */
154 if (dramsize2 < (1 << 20)) {
155 dramsize2 = 0;
156 }
wdenk20c98a62004-04-23 20:32:05 +0000157
wdenke44b9112004-04-18 23:32:11 +0000158 /* 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
wdenk5d841732003-08-17 18:55:18 +0000189#elif defined(CONFIG_MGT5100)
wdenk5d841732003-08-17 18:55:18 +0000190
wdenke44b9112004-04-18 23:32:11 +0000191long int initdram (int board_type)
192{
193 ulong dramsize = 0;
194#ifndef CFG_RAMBOOT
195 ulong test1, test2;
wdenk20c98a62004-04-23 20:32:05 +0000196
wdenke44b9112004-04-18 23:32:11 +0000197 /* setup and enable SDRAM chip selects */
198 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
199 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
wdenk21136db2003-07-16 21:53:01 +0000200 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
wdenke44b9112004-04-18 23:32:11 +0000201 __asm__ volatile ("sync");
202
203 /* setup config registers */
204 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
205 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
206
207 /* address select register */
208 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
209 __asm__ volatile ("sync");
210
211 /* find RAM size */
212 sdram_start(0);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200213 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
wdenke44b9112004-04-18 23:32:11 +0000214 sdram_start(1);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200215 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
wdenke44b9112004-04-18 23:32:11 +0000216 if (test1 > test2) {
217 sdram_start(0);
218 dramsize = test1;
219 } else {
220 dramsize = test2;
221 }
222
223 /* set SDRAM end address according to size */
224 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
wdenk20c98a62004-04-23 20:32:05 +0000225
wdenke44b9112004-04-18 23:32:11 +0000226#else /* CFG_RAMBOOT */
227
228 /* Retrieve amount of SDRAM available */
wdenkb10ba6b2003-08-28 09:41:22 +0000229 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
wdenke44b9112004-04-18 23:32:11 +0000230
wdenkb10ba6b2003-08-28 09:41:22 +0000231#endif /* CFG_RAMBOOT */
wdenk236d3fc2003-12-20 22:45:10 +0000232
wdenk5d841732003-08-17 18:55:18 +0000233 return dramsize;
wdenk21136db2003-07-16 21:53:01 +0000234}
235
wdenke44b9112004-04-18 23:32:11 +0000236#else
237#error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
238#endif
239
wdenk21136db2003-07-16 21:53:01 +0000240int checkboard (void)
241{
Wolfgang Denk315b46a2006-03-17 11:42:53 +0100242#if defined (CONFIG_LITE5200B)
243 puts ("Board: Freescale Lite5200B\n");
244#elif defined(CONFIG_MPC5200)
wdenk21136db2003-07-16 21:53:01 +0000245 puts ("Board: Motorola MPC5200 (IceCube)\n");
246#elif defined(CONFIG_MGT5100)
247 puts ("Board: Motorola MGT5100 (IceCube)\n");
248#endif
249 return 0;
250}
251
252void flash_preinit(void)
253{
254 /*
255 * Now, when we are in RAM, enable flash write
256 * access for detection process.
257 * Note that CS_BOOT cannot be cleared when
258 * executing in flash.
259 */
260#if defined(CONFIG_MGT5100)
261 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
262 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
263#endif
264 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
265}
wdenk02379022003-08-05 18:22:44 +0000266
wdenkeb20ad32003-09-05 23:19:14 +0000267void flash_afterinit(ulong size)
268{
269 if (size == 0x800000) { /* adjust mapping */
wdenk9c53f402003-10-15 23:53:47 +0000270 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
wdenkeb20ad32003-09-05 23:19:14 +0000271 START_REG(CFG_BOOTCS_START | size);
wdenk9c53f402003-10-15 23:53:47 +0000272 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
wdenkeb20ad32003-09-05 23:19:14 +0000273 STOP_REG(CFG_BOOTCS_START | size, size);
274 }
275}
276
wdenk02379022003-08-05 18:22:44 +0000277#ifdef CONFIG_PCI
278static struct pci_controller hose;
279
280extern void pci_mpc5xxx_init(struct pci_controller *);
281
282void pci_init_board(void)
283{
284 pci_mpc5xxx_init(&hose);
285}
286#endif
wdenkacd9b102004-03-14 00:59:59 +0000287
288#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
289
wdenk369d43d2004-03-14 14:09:05 +0000290#define GPIO_PSC1_4 0x01000000UL
wdenkacd9b102004-03-14 00:59:59 +0000291
292void init_ide_reset (void)
293{
wdenk369d43d2004-03-14 14:09:05 +0000294 debug ("init_ide_reset\n");
wdenkc35ba4e2004-03-14 22:25:36 +0000295
wdenkacd9b102004-03-14 00:59:59 +0000296 /* Configure PSC1_4 as GPIO output for ATA reset */
wdenkacd9b102004-03-14 00:59:59 +0000297 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
wdenk369d43d2004-03-14 14:09:05 +0000298 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
wdenke2d6d742004-09-28 20:34:50 +0000299 /* Deassert reset */
300 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
wdenkacd9b102004-03-14 00:59:59 +0000301}
302
303void ide_set_reset (int idereset)
304{
wdenk369d43d2004-03-14 14:09:05 +0000305 debug ("ide_reset(%d)\n", idereset);
306
wdenkacd9b102004-03-14 00:59:59 +0000307 if (idereset) {
308 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
wdenke2d6d742004-09-28 20:34:50 +0000309 /* Make a delay. MPC5200 spec says 25 usec min */
310 udelay(500000);
wdenkacd9b102004-03-14 00:59:59 +0000311 } else {
wdenk369d43d2004-03-14 14:09:05 +0000312 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
wdenkacd9b102004-03-14 00:59:59 +0000313 }
314}
315#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */