blob: afbbaf58e5bd90dd8f23e5e776e67bcb90d4512a [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Erik Theisen, Wave 7 Optics, etheisen@mindspring.com.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
7
8#include <common.h>
wdenk8bde7f72003-06-27 21:31:46 +00009#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000010#include "w7o.h"
11#include <asm/processor.h>
12
13#include "vpd.h"
14#include "errors.h"
15#include <watchdog.h>
16
wdenkc83bf6a2004-01-06 22:38:14 +000017unsigned long get_dram_size (void);
Stefan Roesebbeff302008-06-02 17:37:28 +020018void sdram_init(void);
wdenkc6097192002-11-03 00:24:07 +000019
wdenkc6097192002-11-03 00:24:07 +000020/* ------------------------------------------------------------------------- */
21
wdenkc837dcb2004-01-20 23:12:12 +000022int board_early_init_f (void)
wdenkc6097192002-11-03 00:24:07 +000023{
24#if defined(CONFIG_W7OLMG)
wdenkc83bf6a2004-01-06 22:38:14 +000025 /*
26 * Setup GPIO pins - reset devices.
27 */
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020028 out32 (PPC405GP_GPIO0_ODR, 0x10000000); /* one open drain pin */
29 out32 (PPC405GP_GPIO0_OR, 0x3E000000); /* set output pins to default */
30 out32 (PPC405GP_GPIO0_TCR, 0x7f800000); /* setup for output */
wdenkc6097192002-11-03 00:24:07 +000031
wdenkc83bf6a2004-01-06 22:38:14 +000032 /*
33 * IRQ 0-15 405GP internally generated; active high; level sensitive
34 * IRQ 16 405GP internally generated; active low; level sensitive
35 * IRQ 17-24 RESERVED
36 * IRQ 25 (EXT IRQ 0) XILINX; active low; level sensitive
37 * IRQ 26 (EXT IRQ 1) PCI INT A; active low; level sensitive
38 * IRQ 27 (EXT IRQ 2) PCI INT B; active low; level sensitive
39 * IRQ 28 (EXT IRQ 3) SAM 2; active low; level sensitive
40 * IRQ 29 (EXT IRQ 4) Battery Bad; active low; level sensitive
41 * IRQ 30 (EXT IRQ 5) Level One PHY; active low; level sensitive
42 * IRQ 31 (EXT IRQ 6) SAM 1; active high; level sensitive
43 */
Stefan Roese952e7762009-09-24 09:55:50 +020044 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
45 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
wdenkc6097192002-11-03 00:24:07 +000046
Stefan Roese952e7762009-09-24 09:55:50 +020047 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
48 mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */
49 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
50 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,
wdenkc83bf6a2004-01-06 22:38:14 +000051 INT0 highest priority */
wdenkc6097192002-11-03 00:24:07 +000052
Stefan Roese952e7762009-09-24 09:55:50 +020053 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +000054
55#elif defined(CONFIG_W7OLMC)
wdenkc83bf6a2004-01-06 22:38:14 +000056 /*
57 * Setup GPIO pins
58 */
Wolfgang Denk0c8721a2005-09-23 11:05:55 +020059 out32 (PPC405GP_GPIO0_ODR, 0x01800000); /* XCV Done Open Drain */
60 out32 (PPC405GP_GPIO0_OR, 0x03800000); /* set out pins to default */
61 out32 (PPC405GP_GPIO0_TCR, 0x66C00000); /* setup for output */
wdenkc6097192002-11-03 00:24:07 +000062
wdenkc83bf6a2004-01-06 22:38:14 +000063 /*
64 * IRQ 0-15 405GP internally generated; active high; level sensitive
65 * IRQ 16 405GP internally generated; active low; level sensitive
66 * IRQ 17-24 RESERVED
67 * IRQ 25 (EXT IRQ 0) DBE 0; active low; level sensitive
68 * IRQ 26 (EXT IRQ 1) DBE 1; active low; level sensitive
69 * IRQ 27 (EXT IRQ 2) DBE 2; active low; level sensitive
70 * IRQ 28 (EXT IRQ 3) DBE Common; active low; level sensitive
71 * IRQ 29 (EXT IRQ 4) PCI; active low; level sensitive
72 * IRQ 30 (EXT IRQ 5) RCMM Reset; active low; level sensitive
73 * IRQ 31 (EXT IRQ 6) PHY; active high; level sensitive
74 */
Stefan Roese952e7762009-09-24 09:55:50 +020075 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
76 mtdcr (UIC0ER, 0x00000000); /* disable all ints */
wdenkc6097192002-11-03 00:24:07 +000077
Stefan Roese952e7762009-09-24 09:55:50 +020078 mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */
79 mtdcr (UIC0PR, 0xFFFFFF80); /* set int polarities */
80 mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
81 mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,
wdenkc83bf6a2004-01-06 22:38:14 +000082 INT0 highest priority */
wdenkc6097192002-11-03 00:24:07 +000083
Stefan Roese952e7762009-09-24 09:55:50 +020084 mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +000085
wdenkc83bf6a2004-01-06 22:38:14 +000086#else /* Unknown */
wdenkc6097192002-11-03 00:24:07 +000087# error "Unknown W7O board configuration"
88#endif
89
wdenkc83bf6a2004-01-06 22:38:14 +000090 WATCHDOG_RESET (); /* Reset the watchdog */
91 temp_uart_init (); /* init the uart for debug */
92 WATCHDOG_RESET (); /* Reset the watchdog */
93 test_led (); /* test the LEDs */
94 test_sdram (get_dram_size ()); /* test the dram */
95 log_stat (ERR_POST1); /* log status,post1 complete */
96 return 0;
wdenkc6097192002-11-03 00:24:07 +000097}
98
99
100/* ------------------------------------------------------------------------- */
101
102/*
103 * Check Board Identity:
104 */
105int checkboard (void)
106{
wdenkc83bf6a2004-01-06 22:38:14 +0000107 VPD vpd;
wdenkc6097192002-11-03 00:24:07 +0000108
wdenkc83bf6a2004-01-06 22:38:14 +0000109 puts ("Board: ");
wdenkc6097192002-11-03 00:24:07 +0000110
wdenkc83bf6a2004-01-06 22:38:14 +0000111 /* VPD data present in I2C EEPROM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112 if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, &vpd) == 0) {
wdenkc83bf6a2004-01-06 22:38:14 +0000113 /*
114 * Known board type.
115 */
116 if (vpd.productId[0] &&
117 ((strncmp (vpd.productId, "GMM", 3) == 0) ||
118 (strncmp (vpd.productId, "CMM", 3) == 0))) {
wdenkc6097192002-11-03 00:24:07 +0000119
wdenkc83bf6a2004-01-06 22:38:14 +0000120 /* Output board information on startup */
121 printf ("\"%s\", revision '%c', serial# %ld, manufacturer %u\n", vpd.productId, vpd.revisionId, vpd.serialNum, vpd.manuID);
122 return (0);
123 }
wdenkc6097192002-11-03 00:24:07 +0000124 }
wdenkc6097192002-11-03 00:24:07 +0000125
wdenkc83bf6a2004-01-06 22:38:14 +0000126 puts ("### Unknown HW ID - assuming NOTHING\n");
127 return (0);
wdenkc6097192002-11-03 00:24:07 +0000128}
129
130/* ------------------------------------------------------------------------- */
131
Becky Bruce9973e3c2008-06-09 16:03:40 -0500132phys_size_t initdram (int board_type)
wdenkc6097192002-11-03 00:24:07 +0000133{
Stefan Roesebbeff302008-06-02 17:37:28 +0200134 /*
135 * ToDo: Move the asm init routine sdram_init() to this C file,
136 * or even better use some common ppc4xx code available
Stefan Roesea47a12b2010-04-15 16:07:28 +0200137 * in arch/powerpc/cpu/ppc4xx
Stefan Roesebbeff302008-06-02 17:37:28 +0200138 */
139 sdram_init();
140
wdenkc83bf6a2004-01-06 22:38:14 +0000141 return get_dram_size ();
wdenkc6097192002-11-03 00:24:07 +0000142}
143
144unsigned long get_dram_size (void)
145{
wdenkc83bf6a2004-01-06 22:38:14 +0000146 int tmp, i, regs[4];
147 int size = 0;
wdenkc6097192002-11-03 00:24:07 +0000148
wdenkc83bf6a2004-01-06 22:38:14 +0000149 /* Get bank Size registers */
Stefan Roese95b602b2009-09-24 13:59:57 +0200150 mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR); /* get bank 0 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200151 regs[0] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000152
Stefan Roese95b602b2009-09-24 13:59:57 +0200153 mtdcr (SDRAM0_CFGADDR, SDRAM0_B1CR); /* get bank 1 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200154 regs[1] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000155
Stefan Roese95b602b2009-09-24 13:59:57 +0200156 mtdcr (SDRAM0_CFGADDR, SDRAM0_B2CR); /* get bank 2 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200157 regs[2] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000158
Stefan Roese95b602b2009-09-24 13:59:57 +0200159 mtdcr (SDRAM0_CFGADDR, SDRAM0_B3CR); /* get bank 3 config reg */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200160 regs[3] = mfdcr (SDRAM0_CFGDATA);
wdenkc6097192002-11-03 00:24:07 +0000161
wdenkc83bf6a2004-01-06 22:38:14 +0000162 /* compute the size, add each bank if enabled */
163 for (i = 0; i < 4; i++) {
164 if (regs[i] & 0x0001) { /* if enabled, */
165 tmp = ((regs[i] >> (31 - 14)) & 0x7); /* get size bits */
166 tmp = 0x400000 << tmp; /* Size bits X 4MB = size */
167 size += tmp;
168 }
wdenkc6097192002-11-03 00:24:07 +0000169 }
wdenkc6097192002-11-03 00:24:07 +0000170
wdenkc83bf6a2004-01-06 22:38:14 +0000171 return size;
wdenkc6097192002-11-03 00:24:07 +0000172}
173
174int misc_init_f (void)
175{
wdenkc83bf6a2004-01-06 22:38:14 +0000176 return 0;
wdenkc6097192002-11-03 00:24:07 +0000177}
178
wdenkc83bf6a2004-01-06 22:38:14 +0000179static void w7o_env_init (VPD * vpd)
wdenkc6097192002-11-03 00:24:07 +0000180{
wdenkc83bf6a2004-01-06 22:38:14 +0000181 /*
182 * Read VPD
183 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200184 if (vpd_get_data (CONFIG_SYS_DEF_EEPROM_ADDR, vpd) != 0)
wdenkc83bf6a2004-01-06 22:38:14 +0000185 return;
wdenkc6097192002-11-03 00:24:07 +0000186
wdenkc83bf6a2004-01-06 22:38:14 +0000187 /*
188 * Known board type.
189 */
190 if (vpd->productId[0] &&
191 ((strncmp (vpd->productId, "GMM", 3) == 0) ||
192 (strncmp (vpd->productId, "CMM", 3) == 0))) {
193 char buf[30];
194 char *eth;
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200195 char *serial = getenv ("serial#");
196 char *ethaddr = getenv ("ethaddr");
wdenkc6097192002-11-03 00:24:07 +0000197
wdenkc83bf6a2004-01-06 22:38:14 +0000198 /* Set 'serial#' envvar if serial# isn't set */
199 if (!serial) {
200 sprintf (buf, "%s-%ld", vpd->productId,
201 vpd->serialNum);
202 setenv ("serial#", buf);
203 }
204
205 /* Set 'ethaddr' envvar if 'ethaddr' envvar is the default */
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200206 eth = (char *)(vpd->ethAddrs[0]);
wdenkc83bf6a2004-01-06 22:38:14 +0000207 if (ethaddr
Marek Vasut5368c552012-09-23 17:41:24 +0200208 && (strcmp(ethaddr, __stringify(CONFIG_ETHADDR)) == 0)) {
wdenkc83bf6a2004-01-06 22:38:14 +0000209 /* Now setup ethaddr */
210 sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
211 eth[0], eth[1], eth[2], eth[3], eth[4],
212 eth[5]);
213 setenv ("ethaddr", buf);
214 }
wdenkc6097192002-11-03 00:24:07 +0000215 }
wdenkc83bf6a2004-01-06 22:38:14 +0000216} /* w7o_env_init() */
wdenkc6097192002-11-03 00:24:07 +0000217
218
219int misc_init_r (void)
220{
wdenkc83bf6a2004-01-06 22:38:14 +0000221 VPD vpd; /* VPD information */
wdenkc6097192002-11-03 00:24:07 +0000222
223#if defined(CONFIG_W7OLMG)
wdenkc83bf6a2004-01-06 22:38:14 +0000224 unsigned long greg; /* GPIO Register */
wdenkc6097192002-11-03 00:24:07 +0000225
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200226 greg = in32 (PPC405GP_GPIO0_OR);
wdenkc6097192002-11-03 00:24:07 +0000227
wdenkc83bf6a2004-01-06 22:38:14 +0000228 /*
229 * XXX - Unreset devices - this should be moved into VxWorks driver code
230 */
231 greg |= 0x41800000L; /* SAM, PHY, Galileo */
wdenkc6097192002-11-03 00:24:07 +0000232
Wolfgang Denk0c8721a2005-09-23 11:05:55 +0200233 out32 (PPC405GP_GPIO0_OR, greg); /* set output pins to default */
wdenkc6097192002-11-03 00:24:07 +0000234#endif /* CONFIG_W7OLMG */
235
wdenkc83bf6a2004-01-06 22:38:14 +0000236 /*
237 * Initialize W7O environment variables
238 */
239 w7o_env_init (&vpd);
wdenkc6097192002-11-03 00:24:07 +0000240
wdenkc83bf6a2004-01-06 22:38:14 +0000241 /*
242 * Initialize the FPGA(s).
243 */
244 if (init_fpga () == 0)
245 test_fpga ((unsigned short *) CONFIG_FPGAS_BASE);
wdenkc6097192002-11-03 00:24:07 +0000246
wdenkc83bf6a2004-01-06 22:38:14 +0000247 /* More POST testing. */
248 post2 ();
wdenkc6097192002-11-03 00:24:07 +0000249
wdenkc83bf6a2004-01-06 22:38:14 +0000250 /* Done with hardware initialization and POST. */
251 log_stat (ERR_POSTOK);
wdenkc6097192002-11-03 00:24:07 +0000252
wdenkc83bf6a2004-01-06 22:38:14 +0000253 /* Call silly, fail safe boot init routine */
254 init_fsboot ();
wdenkc6097192002-11-03 00:24:07 +0000255
256 return (0);
257}