blob: 4392779163d70458862f6c2ccc51847c28be19f6 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
wdenk8bde7f72003-06-27 21:31:46 +000025#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000026#include "w7o.h"
27#include <asm/processor.h>
28
29#include "vpd.h"
30#include "errors.h"
31#include <watchdog.h>
32
wdenkc83bf6a2004-01-06 22:38:14 +000033unsigned long get_dram_size (void);
Stefan Roesebbeff302008-06-02 17:37:28 +020034void sdram_init(void);
wdenkc6097192002-11-03 00:24:07 +000035
wdenkc6097192002-11-03 00:24:07 +000036/* ------------------------------------------------------------------------- */
37
wdenkc837dcb2004-01-20 23:12:12 +000038int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +000039{
40#if defined(CONFIG_W7OLMG)
wdenkc83bf6a2004-01-06 22:38:14 +000041 /*
42 * Setup GPIO pins - reset devices.
43 */
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020044 out32 (PPC405GP_GPIO0_ODR, 0x10000000); /* one open drain pin */
45 out32 (PPC405GP_GPIO0_OR, 0x3E000000); /* set output pins to default */
46 out32 (PPC405GP_GPIO0_TCR, 0x7f800000); /* setup for output */
wdenkc6097192002-11-03 00:24:07 +000047
wdenkc83bf6a2004-01-06 22:38:14 +000048 /*
49 * IRQ 0-15 405GP internally generated; active high; level sensitive
50 * IRQ 16 405GP internally generated; active low; level sensitive
51 * IRQ 17-24 RESERVED
52 * IRQ 25 (EXT IRQ 0) XILINX; active low; level sensitive
53 * IRQ 26 (EXT IRQ 1) PCI INT A; active low; level sensitive
54 * IRQ 27 (EXT IRQ 2) PCI INT B; active low; level sensitive
55 * IRQ 28 (EXT IRQ 3) SAM 2; active low; level sensitive
56 * IRQ 29 (EXT IRQ 4) Battery Bad; active low; level sensitive
57 * IRQ 30 (EXT IRQ 5) Level One PHY; active low; level sensitive
58 * IRQ 31 (EXT IRQ 6) SAM 1; active high; level sensitive
59 */
Stefan Roese952e7762009-09-24 09:55:50 +020060 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
61 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
wdenkc6097192002-11-03 00:24:07 +000062
Stefan Roese952e7762009-09-24 09:55:50 +020063 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
64 mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */
65 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
66 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,
wdenkc83bf6a2004-01-06 22:38:14 +000067 INT0 highest priority */
wdenkc6097192002-11-03 00:24:07 +000068
Stefan Roese952e7762009-09-24 09:55:50 +020069 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +000070
71#elif defined(CONFIG_W7OLMC)
wdenkc83bf6a2004-01-06 22:38:14 +000072 /*
73 * Setup GPIO pins
74 */
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020075 out32 (PPC405GP_GPIO0_ODR, 0x01800000); /* XCV Done Open Drain */
76 out32 (PPC405GP_GPIO0_OR, 0x03800000); /* set out pins to default */
77 out32 (PPC405GP_GPIO0_TCR, 0x66C00000); /* setup for output */
wdenkc6097192002-11-03 00:24:07 +000078
wdenkc83bf6a2004-01-06 22:38:14 +000079 /*
80 * IRQ 0-15 405GP internally generated; active high; level sensitive
81 * IRQ 16 405GP internally generated; active low; level sensitive
82 * IRQ 17-24 RESERVED
83 * IRQ 25 (EXT IRQ 0) DBE 0; active low; level sensitive
84 * IRQ 26 (EXT IRQ 1) DBE 1; active low; level sensitive
85 * IRQ 27 (EXT IRQ 2) DBE 2; active low; level sensitive
86 * IRQ 28 (EXT IRQ 3) DBE Common; active low; level sensitive
87 * IRQ 29 (EXT IRQ 4) PCI; active low; level sensitive
88 * IRQ 30 (EXT IRQ 5) RCMM Reset; active low; level sensitive
89 * IRQ 31 (EXT IRQ 6) PHY; active high; level sensitive
90 */
Stefan Roese952e7762009-09-24 09:55:50 +020091 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
92 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
wdenkc6097192002-11-03 00:24:07 +000093
Stefan Roese952e7762009-09-24 09:55:50 +020094 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
95 mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */
96 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
97 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,
wdenkc83bf6a2004-01-06 22:38:14 +000098 INT0 highest priority */
wdenkc6097192002-11-03 00:24:07 +000099
Stefan Roese952e7762009-09-24 09:55:50 +0200100 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +0000101
wdenkc83bf6a2004-01-06 22:38:14 +0000102#else /* Unknown */
wdenkc6097192002-11-03 00:24:07 +0000103# error "Unknown W7O board configuration"
104#endif
105
wdenkc83bf6a2004-01-06 22:38:14 +0000106 WATCHDOG_RESET (); /* Reset the watchdog */
107 temp_uart_init (); /* init the uart for debug */
108 WATCHDOG_RESET (); /* Reset the watchdog */
109 test_led (); /* test the LEDs */
110 test_sdram (get_dram_size ()); /* test the dram */
111 log_stat (ERR_POST1); /* log status,post1 complete */
112 return 0;
wdenkc6097192002-11-03 00:24:07 +0000113}
114
115
116/* ------------------------------------------------------------------------- */
117
118/*
119 * Check Board Identity:
120 */
121int checkboard (void)
122{
wdenkc83bf6a2004-01-06 22:38:14 +0000123 VPD vpd;
wdenkc6097192002-11-03 00:24:07 +0000124
wdenkc83bf6a2004-01-06 22:38:14 +0000125 puts ("Board: ");
wdenkc6097192002-11-03 00:24:07 +0000126
wdenkc83bf6a2004-01-06 22:38:14 +0000127 /* VPD data present in I2C EEPROM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200128 if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, &vpd) == 0) {
wdenkc83bf6a2004-01-06 22:38:14 +0000129 /*
130 * Known board type.
131 */
132 if (vpd.productId[0] &&
133 ((strncmp (vpd.productId, "GMM", 3) == 0) ||
134 (strncmp (vpd.productId, "CMM", 3) == 0))) {
wdenkc6097192002-11-03 00:24:07 +0000135
wdenkc83bf6a2004-01-06 22:38:14 +0000136 /* Output board information on startup */
137 printf ("\"%s\", revision '%c', serial# %ld, manufacturer %u\n", vpd.productId, vpd.revisionId, vpd.serialNum, vpd.manuID);
138 return (0);
139 }
wdenkc6097192002-11-03 00:24:07 +0000140 }
wdenkc6097192002-11-03 00:24:07 +0000141
wdenkc83bf6a2004-01-06 22:38:14 +0000142 puts ("### Unknown HW ID - assuming NOTHING\n");
143 return (0);
wdenkc6097192002-11-03 00:24:07 +0000144}
145
146/* ------------------------------------------------------------------------- */
147
Becky Bruce9973e3c2008-06-09 16:03:40 -0500148phys_size_t initdram (int board_type)
wdenkc6097192002-11-03 00:24:07 +0000149{
Stefan Roesebbeff302008-06-02 17:37:28 +0200150 /*
151 * ToDo: Move the asm init routine sdram_init() to this C file,
152 * or even better use some common ppc4xx code available
Stefan Roesea47a12b2010-04-15 16:07:28 +0200153 * in arch/powerpc/cpu/ppc4xx
Stefan Roesebbeff302008-06-02 17:37:28 +0200154 */
155 sdram_init();
156
wdenkc83bf6a2004-01-06 22:38:14 +0000157 return get_dram_size ();
wdenkc6097192002-11-03 00:24:07 +0000158}
159
160unsigned long get_dram_size (void)
161{
wdenkc83bf6a2004-01-06 22:38:14 +0000162 int tmp, i, regs[4];
163 int size = 0;
wdenkc6097192002-11-03 00:24:07 +0000164
wdenkc83bf6a2004-01-06 22:38:14 +0000165 /* Get bank Size registers */
Stefan Roese95b602b2009-09-24 13:59:57 +0200166 mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); /* get bank 0 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200167 regs[0] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000168
Stefan Roese95b602b2009-09-24 13:59:57 +0200169 mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR); /* get bank 1 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200170 regs[1] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000171
Stefan Roese95b602b2009-09-24 13:59:57 +0200172 mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR); /* get bank 2 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200173 regs[2] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000174
Stefan Roese95b602b2009-09-24 13:59:57 +0200175 mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR); /* get bank 3 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200176 regs[3] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000177
wdenkc83bf6a2004-01-06 22:38:14 +0000178 /* compute the size, add each bank if enabled */
179 for (i = 0; i < 4; i++) {
180 if (regs[i] & 0x0001) { /* if enabled, */
181 tmp = ((regs[i] >> (31 - 14)) & 0x7); /* get size bits */
182 tmp = 0x400000 << tmp; /* Size bits X 4MB = size */
183 size += tmp;
184 }
wdenkc6097192002-11-03 00:24:07 +0000185 }
wdenkc6097192002-11-03 00:24:07 +0000186
wdenkc83bf6a2004-01-06 22:38:14 +0000187 return size;
wdenkc6097192002-11-03 00:24:07 +0000188}
189
190int misc_init_f (void)
191{
wdenkc83bf6a2004-01-06 22:38:14 +0000192 return 0;
wdenkc6097192002-11-03 00:24:07 +0000193}
194
wdenkc83bf6a2004-01-06 22:38:14 +0000195static void w7o_env_init (VPD * vpd)
wdenkc6097192002-11-03 00:24:07 +0000196{
wdenkc83bf6a2004-01-06 22:38:14 +0000197 /*
198 * Read VPD
199 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200200 if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, vpd) != 0)
wdenkc83bf6a2004-01-06 22:38:14 +0000201 return;
wdenkc6097192002-11-03 00:24:07 +0000202
wdenkc83bf6a2004-01-06 22:38:14 +0000203 /*
204 * Known board type.
205 */
206 if (vpd->productId[0] &&
207 ((strncmp (vpd->productId, "GMM", 3) == 0) ||
208 (strncmp (vpd->productId, "CMM", 3) == 0))) {
209 char buf[30];
210 char *eth;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200211 char *serial = getenv ("serial#");
212 char *ethaddr = getenv ("ethaddr");
wdenkc6097192002-11-03 00:24:07 +0000213
wdenkc83bf6a2004-01-06 22:38:14 +0000214 /* Set 'serial#' envvar if serial# isn't set */
215 if (!serial) {
216 sprintf (buf, "%s-%ld", vpd->productId,
217 vpd->serialNum);
218 setenv ("serial#", buf);
219 }
220
221 /* Set 'ethaddr' envvar if 'ethaddr' envvar is the default */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200222 eth = (char *)(vpd->ethAddrs[0]);
wdenkc83bf6a2004-01-06 22:38:14 +0000223 if (ethaddr
Marek Vasut5368c552012-09-23 17:41:24 +0200224 && (strcmp(ethaddr, __stringify(CONFIG_ETHADDR)) == 0)) {
wdenkc83bf6a2004-01-06 22:38:14 +0000225 /* Now setup ethaddr */
226 sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
227 eth[0], eth[1], eth[2], eth[3], eth[4],
228 eth[5]);
229 setenv ("ethaddr", buf);
230 }
wdenkc6097192002-11-03 00:24:07 +0000231 }
wdenkc83bf6a2004-01-06 22:38:14 +0000232} /* w7o_env_init() */
wdenkc6097192002-11-03 00:24:07 +0000233
234
235int misc_init_r (void)
236{
wdenkc83bf6a2004-01-06 22:38:14 +0000237 VPD vpd; /* VPD information */
wdenkc6097192002-11-03 00:24:07 +0000238
239#if defined(CONFIG_W7OLMG)
wdenkc83bf6a2004-01-06 22:38:14 +0000240 unsigned long greg; /* GPIO Register */
wdenkc6097192002-11-03 00:24:07 +0000241
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200242 greg = in32 (PPC405GP_GPIO0_OR);
wdenkc6097192002-11-03 00:24:07 +0000243
wdenkc83bf6a2004-01-06 22:38:14 +0000244 /*
245 * XXX - Unreset devices - this should be moved into VxWorks driver code
246 */
247 greg |= 0x41800000L; /* SAM, PHY, Galileo */
wdenkc6097192002-11-03 00:24:07 +0000248
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200249 out32 (PPC405GP_GPIO0_OR, greg); /* set output pins to default */
wdenkc6097192002-11-03 00:24:07 +0000250#endif /* CONFIG_W7OLMG */
251
wdenkc83bf6a2004-01-06 22:38:14 +0000252 /*
253 * Initialize W7O environment variables
254 */
255 w7o_env_init (&vpd);
wdenkc6097192002-11-03 00:24:07 +0000256
wdenkc83bf6a2004-01-06 22:38:14 +0000257 /*
258 * Initialize the FPGA(s).
259 */
260 if (init_fpga () == 0)
261 test_fpga ((unsigned short *) CONFIG_FPGAS_BASE);
wdenkc6097192002-11-03 00:24:07 +0000262
wdenkc83bf6a2004-01-06 22:38:14 +0000263 /* More POST testing. */
264 post2 ();
wdenkc6097192002-11-03 00:24:07 +0000265
wdenkc83bf6a2004-01-06 22:38:14 +0000266 /* Done with hardware initialization and POST. */
267 log_stat (ERR_POSTOK);
wdenkc6097192002-11-03 00:24:07 +0000268
wdenkc83bf6a2004-01-06 22:38:14 +0000269 /* Call silly, fail safe boot init routine */
270 init_fsboot ();
wdenkc6097192002-11-03 00:24:07 +0000271
272 return (0);
273}