blob: 07c25ed8ab5f8b2bb2c673ec64bb88366ec7375a [file] [log] [blame]
wdenk945af8d2003-07-16 21:53:01 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenke35745b2004-04-18 23:32:11 +00005 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
wdenk945af8d2003-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>
wdenk96e48cf2003-08-05 18:22:44 +000029#include <pci.h>
wdenk945af8d2003-07-16 21:53:01 +000030
wdenke35745b2004-04-18 23:32:11 +000031#if defined(CONFIG_MPC5200_DDR)
32#include "mt46v16m16-75.h"
33#else
34#include "mt48lc16m16a2-75.h"
35#endif
36
wdenkd94f92c2003-08-28 09:41:22 +000037#ifndef CFG_RAMBOOT
wdenke0ac62d2003-08-17 18:55:18 +000038static void sdram_start (int hi_addr)
39{
40 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
41
wdenkb2001f22003-12-20 22:45:10 +000042 /* unlock mode register */
wdenke35745b2004-04-18 23:32:11 +000043 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
44 __asm__ volatile ("sync");
wdenk5cf91d62004-04-23 20:32:05 +000045
wdenkb2001f22003-12-20 22:45:10 +000046 /* precharge all banks */
wdenke35745b2004-04-18 23:32:11 +000047 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
48 __asm__ volatile ("sync");
49
50#if SDRAM_DDR
wdenkb2001f22003-12-20 22:45:10 +000051 /* set mode register: extended mode */
wdenke35745b2004-04-18 23:32:11 +000052 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
53 __asm__ volatile ("sync");
54
wdenkb2001f22003-12-20 22:45:10 +000055 /* set mode register: reset DLL */
wdenke35745b2004-04-18 23:32:11 +000056 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
57 __asm__ volatile ("sync");
wdenke0ac62d2003-08-17 18:55:18 +000058#endif
wdenke35745b2004-04-18 23:32:11 +000059
60 /* precharge all banks */
61 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
62 __asm__ volatile ("sync");
63
wdenkf8d813e2004-03-02 14:05:39 +000064 /* auto refresh */
wdenke35745b2004-04-18 23:32:11 +000065 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
66 __asm__ volatile ("sync");
67
wdenke0ac62d2003-08-17 18:55:18 +000068 /* set mode register */
wdenke35745b2004-04-18 23:32:11 +000069 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
70 __asm__ volatile ("sync");
wdenk5cf91d62004-04-23 20:32:05 +000071
wdenke0ac62d2003-08-17 18:55:18 +000072 /* normal operation */
wdenke35745b2004-04-18 23:32:11 +000073 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
74 __asm__ volatile ("sync");
wdenke0ac62d2003-08-17 18:55:18 +000075}
wdenkd94f92c2003-08-28 09:41:22 +000076#endif
wdenke0ac62d2003-08-17 18:55:18 +000077
wdenke35745b2004-04-18 23:32:11 +000078/*
79 * ATTENTION: Although partially referenced initdram does NOT make real use
80 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
81 * is something else than 0x00000000.
82 */
83
84#if defined(CONFIG_MPC5200)
wdenk945af8d2003-07-16 21:53:01 +000085long int initdram (int board_type)
86{
wdenkd94f92c2003-08-28 09:41:22 +000087 ulong dramsize = 0;
wdenkb2001f22003-12-20 22:45:10 +000088 ulong dramsize2 = 0;
wdenk945af8d2003-07-16 21:53:01 +000089#ifndef CFG_RAMBOOT
wdenkd94f92c2003-08-28 09:41:22 +000090 ulong test1, test2;
wdenk5cf91d62004-04-23 20:32:05 +000091
wdenke35745b2004-04-18 23:32:11 +000092 /* setup SDRAM chip selects */
wdenke0ac62d2003-08-17 18:55:18 +000093 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
94 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
wdenke35745b2004-04-18 23:32:11 +000095 __asm__ volatile ("sync");
wdenk945af8d2003-07-16 21:53:01 +000096
wdenkb2001f22003-12-20 22:45:10 +000097 /* setup config registers */
wdenke35745b2004-04-18 23:32:11 +000098 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
99 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
100 __asm__ volatile ("sync");
wdenkd4ca31c2004-01-02 14:00:00 +0000101
wdenke35745b2004-04-18 23:32:11 +0000102#if SDRAM_DDR
103 /* set tap delay */
104 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
105 __asm__ volatile ("sync");
wdenkb2001f22003-12-20 22:45:10 +0000106#endif
wdenk945af8d2003-07-16 21:53:01 +0000107
wdenke35745b2004-04-18 23:32:11 +0000108 /* find RAM size using SDRAM CS0 only */
wdenke0ac62d2003-08-17 18:55:18 +0000109 sdram_start(0);
wdenkc83bf6a2004-01-06 22:38:14 +0000110 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
wdenke0ac62d2003-08-17 18:55:18 +0000111 sdram_start(1);
wdenkc83bf6a2004-01-06 22:38:14 +0000112 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
wdenke0ac62d2003-08-17 18:55:18 +0000113 if (test1 > test2) {
114 sdram_start(0);
115 dramsize = test1;
116 } else {
117 dramsize = test2;
118 }
wdenke35745b2004-04-18 23:32:11 +0000119
120 /* memory smaller than 1MB is impossible */
121 if (dramsize < (1 << 20)) {
122 dramsize = 0;
123 }
wdenk5cf91d62004-04-23 20:32:05 +0000124
wdenke35745b2004-04-18 23:32:11 +0000125 /* set SDRAM CS0 size according to the amount of RAM found */
126 if (dramsize > 0) {
127 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
128 } else {
129 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
130 }
131
wdenke35745b2004-04-18 23:32:11 +0000132 /* let SDRAM CS1 start right after CS0 */
wdenkb2001f22003-12-20 22:45:10 +0000133 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
wdenke35745b2004-04-18 23:32:11 +0000134
135 /* find RAM size using SDRAM CS1 only */
wdenkb2001f22003-12-20 22:45:10 +0000136 sdram_start(0);
wdenkc83bf6a2004-01-06 22:38:14 +0000137 test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
wdenkb2001f22003-12-20 22:45:10 +0000138 sdram_start(1);
wdenkc83bf6a2004-01-06 22:38:14 +0000139 test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
wdenkb2001f22003-12-20 22:45:10 +0000140 if (test1 > test2) {
141 sdram_start(0);
142 dramsize2 = test1;
143 } else {
144 dramsize2 = test2;
145 }
wdenk5cf91d62004-04-23 20:32:05 +0000146
wdenke35745b2004-04-18 23:32:11 +0000147 /* memory smaller than 1MB is impossible */
148 if (dramsize2 < (1 << 20)) {
149 dramsize2 = 0;
150 }
wdenk5cf91d62004-04-23 20:32:05 +0000151
wdenke35745b2004-04-18 23:32:11 +0000152 /* set SDRAM CS1 size according to the amount of RAM found */
153 if (dramsize2 > 0) {
154 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
155 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
156 } else {
157 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
158 }
wdenke0ac62d2003-08-17 18:55:18 +0000159
wdenke35745b2004-04-18 23:32:11 +0000160#else /* CFG_RAMBOOT */
161
162 /* retrieve size of memory connected to SDRAM CS0 */
163 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
164 if (dramsize >= 0x13) {
165 dramsize = (1 << (dramsize - 0x13)) << 20;
166 } else {
167 dramsize = 0;
168 }
169
170 /* retrieve size of memory connected to SDRAM CS1 */
171 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
172 if (dramsize2 >= 0x13) {
173 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
174 } else {
175 dramsize2 = 0;
176 }
177
wdenkd94f92c2003-08-28 09:41:22 +0000178#endif /* CFG_RAMBOOT */
wdenkb2001f22003-12-20 22:45:10 +0000179
wdenke35745b2004-04-18 23:32:11 +0000180 return dramsize + dramsize2;
181}
182
183#elif defined(CONFIG_MGT5100)
184
185long int initdram (int board_type)
186{
187 ulong dramsize = 0;
188#ifndef CFG_RAMBOOT
189 ulong test1, test2;
wdenk5cf91d62004-04-23 20:32:05 +0000190
wdenke35745b2004-04-18 23:32:11 +0000191 /* setup and enable SDRAM chip selects */
192 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
193 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
194 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
195 __asm__ volatile ("sync");
196
197 /* setup config registers */
198 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
199 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
200
201 /* address select register */
202 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
203 __asm__ volatile ("sync");
204
205 /* find RAM size */
206 sdram_start(0);
207 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
208 sdram_start(1);
209 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
210 if (test1 > test2) {
211 sdram_start(0);
212 dramsize = test1;
213 } else {
214 dramsize = test2;
215 }
216
217 /* set SDRAM end address according to size */
218 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
wdenk5cf91d62004-04-23 20:32:05 +0000219
wdenke35745b2004-04-18 23:32:11 +0000220#else /* CFG_RAMBOOT */
221
222 /* Retrieve amount of SDRAM available */
223 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
224
225#endif /* CFG_RAMBOOT */
226
wdenke0ac62d2003-08-17 18:55:18 +0000227 return dramsize;
wdenk945af8d2003-07-16 21:53:01 +0000228}
229
wdenke35745b2004-04-18 23:32:11 +0000230#else
231#error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
232#endif
233
wdenk945af8d2003-07-16 21:53:01 +0000234int checkboard (void)
235{
236#if defined(CONFIG_MPC5200)
237 puts ("Board: Motorola MPC5200 (IceCube)\n");
238#elif defined(CONFIG_MGT5100)
239 puts ("Board: Motorola MGT5100 (IceCube)\n");
240#endif
241 return 0;
242}
243
244void flash_preinit(void)
245{
246 /*
247 * Now, when we are in RAM, enable flash write
248 * access for detection process.
249 * Note that CS_BOOT cannot be cleared when
250 * executing in flash.
251 */
252#if defined(CONFIG_MGT5100)
253 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
254 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
255#endif
256 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
257}
wdenk96e48cf2003-08-05 18:22:44 +0000258
wdenk7152b1d2003-09-05 23:19:14 +0000259void flash_afterinit(ulong size)
260{
261 if (size == 0x800000) { /* adjust mapping */
wdenk42d1f032003-10-15 23:53:47 +0000262 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
wdenk7152b1d2003-09-05 23:19:14 +0000263 START_REG(CFG_BOOTCS_START | size);
wdenk42d1f032003-10-15 23:53:47 +0000264 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
wdenk7152b1d2003-09-05 23:19:14 +0000265 STOP_REG(CFG_BOOTCS_START | size, size);
266 }
267}
268
wdenk96e48cf2003-08-05 18:22:44 +0000269#ifdef CONFIG_PCI
270static struct pci_controller hose;
271
272extern void pci_mpc5xxx_init(struct pci_controller *);
273
274void pci_init_board(void)
275{
276 pci_mpc5xxx_init(&hose);
277}
278#endif
wdenkc3f9d492004-03-14 00:59:59 +0000279
280#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
281
wdenk4d13cba2004-03-14 14:09:05 +0000282#define GPIO_PSC1_4 0x01000000UL
wdenkc3f9d492004-03-14 00:59:59 +0000283
284void init_ide_reset (void)
285{
wdenk4d13cba2004-03-14 14:09:05 +0000286 debug ("init_ide_reset\n");
wdenk42dfe7a2004-03-14 22:25:36 +0000287
wdenkc3f9d492004-03-14 00:59:59 +0000288 /* Configure PSC1_4 as GPIO output for ATA reset */
wdenkc3f9d492004-03-14 00:59:59 +0000289 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
wdenk4d13cba2004-03-14 14:09:05 +0000290 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
wdenk64f70be2004-09-28 20:34:50 +0000291 /* Deassert reset */
292 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
wdenkc3f9d492004-03-14 00:59:59 +0000293}
294
295void ide_set_reset (int idereset)
296{
wdenk4d13cba2004-03-14 14:09:05 +0000297 debug ("ide_reset(%d)\n", idereset);
298
wdenkc3f9d492004-03-14 00:59:59 +0000299 if (idereset) {
300 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
wdenk64f70be2004-09-28 20:34:50 +0000301 /* Make a delay. MPC5200 spec says 25 usec min */
302 udelay(500000);
wdenkc3f9d492004-03-14 00:59:59 +0000303 } else {
wdenk4d13cba2004-03-14 14:09:05 +0000304 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
wdenkc3f9d492004-03-14 00:59:59 +0000305 }
306}
307#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */