blob: 536a5152a66f22f96ad08649a7df3e982241b621 [file] [log] [blame]
wdenkc1896002003-12-28 11:44:59 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2003
6 * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de
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/*****************************************************************************
32 * initialize SDRAM/DDRAM controller.
33 * TBD: get data from I2C EEPROM
34 *****************************************************************************/
35long int initdram (int board_type)
36{
37 ulong dramsize = 0;
38#ifndef CFG_RAMBOOT
39 ulong t;
40 ulong tap_del;
41
42 #define MODE_EN 0x80000000
43 #define SOFT_PRE 2
44 #define SOFT_REF 4
45
46 /* configure SDRAM start/end */
47 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = (CFG_SDRAM_BASE & 0xFFF00000) | CFG_DRAM_RAM_SIZE;
48 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
49
50 /* setup config registers */
51 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = CFG_DRAM_CONFIG1;
52 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = CFG_DRAM_CONFIG2;
53
54 /* unlock mode register */
55 *(vu_long *)MPC5XXX_SDRAM_CTRL = CFG_DRAM_CONTROL | MODE_EN;
56 /* precharge all banks */
57 *(vu_long *)MPC5XXX_SDRAM_CTRL = CFG_DRAM_CONTROL | MODE_EN | SOFT_PRE;
58#if CFG_DRAM_DDR
59 /* set extended mode register */
60 *(vu_short *)MPC5XXX_SDRAM_MODE = CFG_DRAM_EMODE;
61#endif
62 /* set mode register */
63 *(vu_short *)MPC5XXX_SDRAM_MODE = CFG_DRAM_MODE | 0x0400;
64 /* precharge all banks */
65 *(vu_long *)MPC5XXX_SDRAM_CTRL = CFG_DRAM_CONTROL | MODE_EN | SOFT_PRE;
66 /* auto refresh */
67 *(vu_long *)MPC5XXX_SDRAM_CTRL = CFG_DRAM_CONTROL | MODE_EN | SOFT_REF;
68 /* set mode register */
69 *(vu_short *)MPC5XXX_SDRAM_MODE = CFG_DRAM_MODE;
70 /* normal operation */
71 *(vu_long *)MPC5XXX_SDRAM_CTRL = CFG_DRAM_CONTROL;
72 /* write default TAP delay */
73 *(vu_long *)MPC5XXX_CDM_PORCFG = CFG_DRAM_TAP_DEL << 24;
74
75#if 0
76 for (tap_del = 0; tap_del < 32; tap_del++) {
77 *(vu_long *)MPC5XXX_CDM_PORCFG = tap_del << 24;
78
79 printf ("\nTAP Delay:%x Filling DRAM...", *(vu_long *)MPC5XXX_CDM_PORCFG);
80 for (t = 0; t < 0x04000000; t+=4)
81 *(vu_long *) t = t;
82 printf ("Checking DRAM...\n");
83 for (t = 0; t < 0x04000000; t+=4) {
84 ulong rval = *(vu_long *) t;
85 if (rval != t) {
86 printf ("mismatch at %x: ", t);
87 printf (" 1.read %x", rval);
88 printf (" 2.read %x", *(vu_long *) t);
89 printf (" 3.read %x", *(vu_long *) t);
90 break;
91 }
92 }
93 }
94#endif
95#endif /* CFG_RAMBOOT */
96
97 dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20);
98
99 /* return total ram size */
100 return dramsize;
101}
102
103/*****************************************************************************
104 * print board identification
105 *****************************************************************************/
106int checkboard (void)
107{
108#if defined (CONFIG_EVAL5200)
109 puts ("Board: EMK TOP5200 on EVAL5200\n");
110#else
111#if defined (CONFIG_MINI5200)
112 puts ("Board: EMK TOP5200 on MINI5200\n");
113#else
114 puts ("Board: EMK TOP5200\n");
115#endif
116#endif
117 return 0;
118}
119
120/*****************************************************************************
121 * prepare for FLASH detection
122 *****************************************************************************/
123void flash_preinit(void)
124{
125 /*
126 * Now, when we are in RAM, enable flash write
127 * access for detection process.
128 * Note that CS_BOOT cannot be cleared when
129 * executing in flash.
130 */
131 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
132}
133
134/*****************************************************************************
135 * finalize FLASH setup
136 *****************************************************************************/
137void flash_afterinit(uint bank, ulong start, ulong size)
138{
139 if (bank == 0) { /* adjust mapping */
140 *(vu_long *)MPC5XXX_BOOTCS_START =
141 *(vu_long *)MPC5XXX_CS0_START = START_REG(start);
142 *(vu_long *)MPC5XXX_BOOTCS_STOP =
143 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(start, size);
144 }
145}
146
147/*****************************************************************************
148 * otherinits after RAM is there and we are relocated to RAM
149 * note: though this is an int function, nobody cares for the result!
150 *****************************************************************************/
151int misc_init_r (void)
152{
153 /* read 'factory' part of EEPROM */
154 uchar buf[81];
155 uchar *p;
156 uint length;
157 uint addr;
158 uint len;
159
160 /* get length first */
161 addr = CFG_FACT_OFFSET;
162 if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, 2)) {
163bailout:
164 printf ("cannot read factory configuration\n");
165 printf ("be sure to set ethaddr yourself!\n");
166 return 0;
167 }
168 length = buf[0] + (buf[1] << 8);
169 addr += 2;
170
171 /* sanity check */
172 if (length < 20 || length > CFG_FACT_SIZE - 2)
173 goto bailout;
174
175 /* read lines */
176 while (length > 0) {
177 /* read one line */
178 len = length > 80 ? 80 : length;
179 if (eeprom_read (CFG_I2C_FACT_ADDR, addr, buf, len))
180 goto bailout;
181 /* mark end of buffer */
182 buf[len] = 0;
183 /* search end of line */
184 for (p = buf; *p && *p != 0x0a; p++);
185 if (!*p)
186 goto bailout;
187 *p++ = 0;
188 /* advance to next line start */
189 length -= p - buf;
190 addr += p - buf;
191 /*printf ("%s\n", buf); */
192 /* search for our specific entry */
193 if (!strncmp ((char *) buf, "[RLA/lan/Ethernet] ", 19)) {
194 setenv ("ethaddr", buf + 19);
195 } else if (!strncmp ((char *) buf, "[BOARD/SERIAL] ", 15)) {
196 setenv ("serial#", buf + 15);
197 } else if (!strncmp ((char *) buf, "[BOARD/TYPE] ", 13)) {
198 setenv ("board_id", buf + 13);
199 }
200 }
201 return (0);
202}
203
204/*****************************************************************************
205 * initialize the PCI system
206 *****************************************************************************/
207#ifdef CONFIG_PCI
208static struct pci_controller hose;
209
210extern void pci_mpc5xxx_init(struct pci_controller *);
211
212void pci_init_board(void)
213{
214 pci_mpc5xxx_init(&hose);
215}
216#endif