blob: 5aa713fa0be4bb4a650d27e982e9d4e569933b50 [file] [log] [blame]
wdenk5b1d7132002-11-03 00:07:02 +00001/*
2 * (C) Copyright 2001
3 * Stäubli Faverges - <www.staubli.com>
4 * Pierre AUBERT p.aubert@staubli.com
5 * U-Boot port on RPXClassic LF (CLLF_BW31) board
6 *
7 * (C) Copyright 2000
8 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 *
10 * See file CREDITS for list of people who contributed to this
11 * project.
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 * MA 02111-1307 USA
27 */
28
29#include <common.h>
30#include <i2c.h>
31#include <config.h>
32#include <mpc8xx.h>
33
34/* ------------------------------------------------------------------------- */
35
36static long int dram_size (long int, long int *, long int);
37static unsigned char aschex_to_byte (unsigned char *cp);
38
39/* ------------------------------------------------------------------------- */
40
41#define _NOT_USED_ 0xFFFFCC25
42
43const uint sdram_table[] =
44{
45 /*
46 * Single Read. (Offset 00h in UPMA RAM)
47 */
48 0xCFFFCC24, 0x0FFFCC04, 0X0CAFCC04, 0X03AFCC08,
49 0x3FBFCC27, /* last */
50 _NOT_USED_, _NOT_USED_, _NOT_USED_,
51
52 /*
53 * Burst Read. (Offset 08h in UPMA RAM)
54 */
55 0xCFFFCC24, 0x0FFFCC04, 0x0CAFCC84, 0x03AFCC88,
56 0x3FBFCC27, /* last */
57 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
58 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
59 _NOT_USED_, _NOT_USED_, _NOT_USED_,
60
61 /*
62 * Single Write. (Offset 18h in UPMA RAM)
63 */
64 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC04, 0x03FFCC00,
65 0x3FFFCC27, /* last */
66 _NOT_USED_, _NOT_USED_, _NOT_USED_,
67
68 /*
69 * Burst Write. (Offset 20h in UPMA RAM)
70 */
71 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC80, 0x03FFCC8C,
72 0x0CFFCC00, 0x33FFCC27, /* last */
73 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
74 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
75 _NOT_USED_, _NOT_USED_,
76
77 /*
78 * Refresh. (Offset 30h in UPMA RAM)
79 */
80 0xC0FFCC24, 0x03FFCC24, 0x0FFFCC24, 0x0FFFCC24,
81 0x3FFFCC27, /* last */
82 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
83 _NOT_USED_, _NOT_USED_, _NOT_USED_,
84
85 /*
86 * Exception. (Offset 3Ch in UPMA RAM)
87 */
88 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_
89};
90
91/* ------------------------------------------------------------------------- */
92
93
94/*
95 * Check Board Identity:
96 */
97
98int checkboard (void)
99{
100 puts ("Board: RPXClassic\n");
101 return (0);
102}
103
104/*-----------------------------------------------------------------------------
105 * board_get_enetaddr -- Read the MAC Address in the I2C EEPROM
106 *-----------------------------------------------------------------------------
107 */
Mike Frysingerd8d21e62009-02-16 18:03:14 -0500108static void board_get_enetaddr(uchar *enet)
wdenk5b1d7132002-11-03 00:07:02 +0000109{
110 int i;
111 char buff[256], *cp;
112
113 /* Initialize I2C */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
wdenk5b1d7132002-11-03 00:07:02 +0000115
116 /* Read 256 bytes in EEPROM */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200117 i2c_read (0x54, 0, 1, (uchar *)buff, 128);
118 i2c_read (0x54, 128, 1, (uchar *)buff + 128, 128);
wdenk5b1d7132002-11-03 00:07:02 +0000119
120 /* Retrieve MAC address in buffer (key EA) */
121 for (cp = buff;;) {
122 if (cp[0] == 'E' && cp[1] == 'A') {
123 cp += 3;
124 /* Read MAC address */
125 for (i = 0; i < 6; i++, cp += 2) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200126 enet[i] = aschex_to_byte ((unsigned char *)cp);
wdenk5b1d7132002-11-03 00:07:02 +0000127 }
128 }
129 /* Scan to the end of the record */
wdenkb2184c32002-11-19 23:01:07 +0000130 while ((*cp != '\n') && (*cp != (char)0xff)) {
wdenk5b1d7132002-11-03 00:07:02 +0000131 cp++;
132 }
133 /* If the next character is a \n, 0 or ff, we are done. */
134 cp++;
wdenkb2184c32002-11-19 23:01:07 +0000135 if ((*cp == '\n') || (*cp == 0) || (*cp == (char)0xff))
wdenk5b1d7132002-11-03 00:07:02 +0000136 break;
137 }
138
139#ifdef CONFIG_FEC_ENET
140 /* The MAC address is the same as normal ethernet except the 3rd byte */
141 /* (See the E.P. Planet Core Overview manual */
142 enet[3] |= 0x80;
wdenk5b1d7132002-11-03 00:07:02 +0000143#endif
144
Mike Frysingerd8d21e62009-02-16 18:03:14 -0500145 printf("MAC address = %pM\n", enet);
146}
wdenk5b1d7132002-11-03 00:07:02 +0000147
Mike Frysingerd8d21e62009-02-16 18:03:14 -0500148int misc_init_r(void)
149{
150 uchar enetaddr[6];
151
152 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
153 board_get_enetaddr(enetaddr);
154 eth_putenv_enetaddr("ethaddr", enetaddr);
155 }
156
157 return 0;
wdenk5b1d7132002-11-03 00:07:02 +0000158}
159
160void rpxclassic_init (void)
161{
162 /* Enable NVRAM */
163 *((uchar *) BCSR0) |= BCSR0_ENNVRAM;
164
wdenkb2184c32002-11-19 23:01:07 +0000165#ifdef CONFIG_FEC_ENET
166
167 /* Validate the fast ethernet tranceiver */
168 *((volatile uchar *) BCSR2) &= ~BCSR2_MIICTL;
169 *((volatile uchar *) BCSR2) &= ~BCSR2_MIIPWRDWN;
170 *((volatile uchar *) BCSR2) |= BCSR2_MIIRST;
171 *((volatile uchar *) BCSR2) |= BCSR2_MIIPWRDWN;
172#endif
173
wdenk5b1d7132002-11-03 00:07:02 +0000174}
175
176/* ------------------------------------------------------------------------- */
177
Becky Bruce9973e3c2008-06-09 16:03:40 -0500178phys_size_t initdram (int board_type)
wdenk5b1d7132002-11-03 00:07:02 +0000179{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200180 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk5b1d7132002-11-03 00:07:02 +0000181 volatile memctl8xx_t *memctl = &immap->im_memctl;
182 long int size10;
183
184 upmconfig (UPMA, (uint *) sdram_table,
185 sizeof (sdram_table) / sizeof (uint));
186
187 /* Refresh clock prescalar */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
wdenk5b1d7132002-11-03 00:07:02 +0000189
190 memctl->memc_mar = 0x00000000;
191
192 /* Map controller banks 1 to the SDRAM bank */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200193 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
194 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
wdenk5b1d7132002-11-03 00:07:02 +0000195
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200196 memctl->memc_mamr = CONFIG_SYS_MAMR_10COL & (~(MAMR_PTAE)); /* no refresh yet */
wdenk5b1d7132002-11-03 00:07:02 +0000197
198 udelay (200);
199
200 /* perform SDRAM initializsation sequence */
201
202 memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - refresh twice */
203 udelay (1);
204
205 memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
206
207 udelay (1000);
208
209 /* Check Bank 0 Memory Size
210 * try 10 column mode
211 */
212
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200213 size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE_PRELIM,
wdenk5b1d7132002-11-03 00:07:02 +0000214 SDRAM_MAX_SIZE);
215
216 return (size10);
217}
218
219/* ------------------------------------------------------------------------- */
220
221/*
222 * Check memory range for valid RAM. A simple memory test determines
223 * the actually available RAM size between addresses `base' and
224 * `base + maxsize'. Some (not all) hardware errors are detected:
225 * - short between address lines
226 * - short between data lines
227 */
228
229static long int dram_size (long int mamr_value, long int *base, long int maxsize)
230{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200231 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
wdenk5b1d7132002-11-03 00:07:02 +0000232 volatile memctl8xx_t *memctl = &immap->im_memctl;
wdenk5b1d7132002-11-03 00:07:02 +0000233
234 memctl->memc_mamr = mamr_value;
235
wdenkc83bf6a2004-01-06 22:38:14 +0000236 return (get_ram_size(base, maxsize));
wdenk5b1d7132002-11-03 00:07:02 +0000237}
wdenkb2184c32002-11-19 23:01:07 +0000238/*-----------------------------------------------------------------------------
wdenk8bde7f72003-06-27 21:31:46 +0000239 * aschex_to_byte --
wdenkb2184c32002-11-19 23:01:07 +0000240 *-----------------------------------------------------------------------------
241 */
wdenk5b1d7132002-11-03 00:07:02 +0000242static unsigned char aschex_to_byte (unsigned char *cp)
243{
244 u_char byte, c;
245
246 c = *cp++;
247
248 if ((c >= 'A') && (c <= 'F')) {
249 c -= 'A';
250 c += 10;
251 } else if ((c >= 'a') && (c <= 'f')) {
252 c -= 'a';
253 c += 10;
254 } else {
255 c -= '0';
256 }
257
258 byte = c * 16;
259
260 c = *cp;
261
262 if ((c >= 'A') && (c <= 'F')) {
263 c -= 'A';
264 c += 10;
265 } else if ((c >= 'a') && (c <= 'f')) {
266 c -= 'a';
267 c += 10;
268 } else {
269 c -= '0';
270 }
271
272 byte += c;
273
274 return (byte);
275}