3 * Travis B. Sawyer, Sandburst Corporation, tsawyer@sandburst.com
5 * SPDX-License-Identifier: GPL-2.0+
11 #include "metrobox_version.h"
12 #include <timestamp.h>
13 #include <asm/processor.h>
15 #include <spd_sdram.h>
17 #include "../common/sb_common.h"
18 #if defined(CONFIG_HAS_ETH0) || defined(CONFIG_HAS_ETH1) || \
19 defined(CONFIG_HAS_ETH2) || defined(CONFIG_HAS_ETH3)
23 void fpga_init (void);
25 METROBOX_BOARD_ID_ST board_id_as[] =
26 { {"Undefined"}, /* Not specified */
27 {"2x10Gb"}, /* 2 ports, 10 GbE */
28 {"20x1Gb"}, /* 20 ports, 1 GbE */
29 {"Reserved"}, /* Reserved for future use */
32 /*************************************************************************
35 * Setup chip selects, initialize the Opto-FPGA, initialize
36 * interrupt polarity and triggers.
37 ************************************************************************/
38 int board_early_init_f (void)
40 ppc440_gpio_regs_t *gpio_regs;
42 /* Enable GPIO interrupts */
43 mtsdr(SDR0_PFC0, 0x00103E00);
45 /* Setup access for LEDs, and system topology info */
46 gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
47 gpio_regs->open_drain = SBCOMMON_GPIO_SYS_LEDS;
48 gpio_regs->tri_state = SBCOMMON_GPIO_DBGLEDS;
50 /* Turn on all the leds for now */
51 gpio_regs->out = SBCOMMON_GPIO_LEDS;
53 /*--------------------------------------------------------------------+
54 | Initialize EBC CONFIG
55 +-------------------------------------------------------------------*/
57 EBC_CFG_LE_UNLOCK | EBC_CFG_PTD_ENABLE |
58 EBC_CFG_RTC_64PERCLK | EBC_CFG_ATC_PREVIOUS |
59 EBC_CFG_DTC_PREVIOUS | EBC_CFG_CTC_PREVIOUS |
60 EBC_CFG_EMC_DEFAULT | EBC_CFG_PME_DISABLE |
63 /*--------------------------------------------------------------------+
64 | 1/2 MB FLASH. Initialize bank 0 with default values.
65 +-------------------------------------------------------------------*/
67 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(8) |
68 EBC_BXAP_BCE_DISABLE | EBC_BXAP_CSN_ENCODE(1) |
69 EBC_BXAP_OEN_ENCODE(1)| EBC_BXAP_WBN_ENCODE(1) |
70 EBC_BXAP_WBF_ENCODE(1)| EBC_BXAP_TH_ENCODE(1) |
71 EBC_BXAP_RE_DISABLED | EBC_BXAP_BEM_WRITEONLY |
72 EBC_BXAP_PEN_DISABLED);
74 mtebc(PB0CR, EBC_BXCR_BAS_ENCODE(CONFIG_SYS_FLASH_BASE) |
75 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT);
76 /*--------------------------------------------------------------------+
77 | 8KB NVRAM/RTC. Initialize bank 1 with default values.
78 +-------------------------------------------------------------------*/
80 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(10) |
81 EBC_BXAP_BCE_DISABLE | EBC_BXAP_CSN_ENCODE(1) |
82 EBC_BXAP_OEN_ENCODE(1)| EBC_BXAP_WBN_ENCODE(1) |
83 EBC_BXAP_WBF_ENCODE(1)| EBC_BXAP_TH_ENCODE(1) |
84 EBC_BXAP_RE_DISABLED | EBC_BXAP_BEM_WRITEONLY |
85 EBC_BXAP_PEN_DISABLED);
87 mtebc(PB1CR, EBC_BXCR_BAS_ENCODE(0x48000000) |
88 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_8BIT);
90 /*--------------------------------------------------------------------+
91 | Compact Flash, uses 2 Chip Selects (2 & 6)
92 +-------------------------------------------------------------------*/
94 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(8) |
95 EBC_BXAP_BCE_DISABLE | EBC_BXAP_CSN_ENCODE(1) |
96 EBC_BXAP_OEN_ENCODE(1)| EBC_BXAP_WBN_ENCODE(1) |
97 EBC_BXAP_WBF_ENCODE(0)| EBC_BXAP_TH_ENCODE(1) |
98 EBC_BXAP_RE_DISABLED | EBC_BXAP_BEM_WRITEONLY |
99 EBC_BXAP_PEN_DISABLED);
101 mtebc(PB2CR, EBC_BXCR_BAS_ENCODE(0xF0000000) |
102 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT);
104 /*--------------------------------------------------------------------+
105 | OPTO & OFEM FPGA. Initialize bank 3 with default values.
106 +-------------------------------------------------------------------*/
108 EBC_BXAP_RE_ENABLED | EBC_BXAP_SOR_NONDELAYED |
109 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(3) |
110 EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_WBF_ENCODE(0) |
111 EBC_BXAP_CSN_ENCODE(1) | EBC_BXAP_PEN_DISABLED |
112 EBC_BXAP_OEN_ENCODE(1) | EBC_BXAP_BEM_RW);
114 mtebc(PB3CR, EBC_BXCR_BAS_ENCODE(0x48200000) |
115 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT);
117 /*--------------------------------------------------------------------+
119 | MAC A & B for Kamino. OFEM FPGA decodes the addresses
120 | Initialize bank 4 with default values.
121 +-------------------------------------------------------------------*/
123 EBC_BXAP_RE_ENABLED | EBC_BXAP_SOR_NONDELAYED |
124 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(3) |
125 EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_WBF_ENCODE(0) |
126 EBC_BXAP_CSN_ENCODE(1) | EBC_BXAP_PEN_DISABLED |
127 EBC_BXAP_OEN_ENCODE(1) | EBC_BXAP_BEM_RW);
129 mtebc(PB4CR, EBC_BXCR_BAS_ENCODE(0x48600000) |
130 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT);
132 /*--------------------------------------------------------------------+
133 | Metrobox MAC B Initialize bank 5 with default values.
134 | KA REF FPGA Initialize bank 5 with default values.
135 +-------------------------------------------------------------------*/
137 EBC_BXAP_RE_ENABLED | EBC_BXAP_SOR_NONDELAYED |
138 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(3) |
139 EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_WBF_ENCODE(0) |
140 EBC_BXAP_CSN_ENCODE(1) | EBC_BXAP_PEN_DISABLED |
141 EBC_BXAP_OEN_ENCODE(1) | EBC_BXAP_BEM_RW);
143 mtebc(PB5CR, EBC_BXCR_BAS_ENCODE(0x48700000) |
144 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT);
146 /*--------------------------------------------------------------------+
147 | Compact Flash, uses 2 Chip Selects (2 & 6)
148 +-------------------------------------------------------------------*/
150 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(8) |
151 EBC_BXAP_BCE_DISABLE | EBC_BXAP_CSN_ENCODE(1) |
152 EBC_BXAP_OEN_ENCODE(1)| EBC_BXAP_WBN_ENCODE(1) |
153 EBC_BXAP_WBF_ENCODE(0)| EBC_BXAP_TH_ENCODE(1) |
154 EBC_BXAP_RE_DISABLED | EBC_BXAP_BEM_WRITEONLY |
155 EBC_BXAP_PEN_DISABLED);
157 mtebc(PB6CR, EBC_BXCR_BAS_ENCODE(0xF0100000) |
158 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_16BIT);
160 /*--------------------------------------------------------------------+
161 | BME-32. Initialize bank 7 with default values.
162 +-------------------------------------------------------------------*/
164 EBC_BXAP_RE_ENABLED | EBC_BXAP_SOR_NONDELAYED |
165 EBC_BXAP_BME_DISABLED | EBC_BXAP_TWT_ENCODE(3) |
166 EBC_BXAP_TH_ENCODE(1) | EBC_BXAP_WBF_ENCODE(0) |
167 EBC_BXAP_CSN_ENCODE(1) | EBC_BXAP_PEN_DISABLED |
168 EBC_BXAP_OEN_ENCODE(1) | EBC_BXAP_BEM_RW);
170 mtebc(PB7CR, EBC_BXCR_BAS_ENCODE(0x48500000) |
171 EBC_BXCR_BS_1MB | EBC_BXCR_BU_RW | EBC_BXCR_BW_32BIT);
173 /*--------------------------------------------------------------------+
174 * Setup the interrupt controller polarities, triggers, etc.
175 +-------------------------------------------------------------------*/
177 * Because of the interrupt handling rework to handle 440GX interrupts
178 * with the common code, we needed to change names of the UIC registers.
179 * Here the new relationship:
181 * U-Boot name 440GX name
182 * -----------------------
188 mtdcr (UIC1SR, 0xffffffff); /* clear all */
189 mtdcr (UIC1ER, 0x00000000); /* disable all */
190 mtdcr (UIC1CR, 0x00000000); /* all non- critical */
191 mtdcr (UIC1PR, 0xfffffe03); /* polarity */
192 mtdcr (UIC1TR, 0x01c00000); /* trigger edge vs level */
193 mtdcr (UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
194 mtdcr (UIC1SR, 0xffffffff); /* clear all */
196 mtdcr (UIC2SR, 0xffffffff); /* clear all */
197 mtdcr (UIC2ER, 0x00000000); /* disable all */
198 mtdcr (UIC2CR, 0x00000000); /* all non-critical */
199 mtdcr (UIC2PR, 0xffffc8ff); /* polarity */
200 mtdcr (UIC2TR, 0x00ff0000); /* trigger edge vs level */
201 mtdcr (UIC2VR, 0x00000001); /* int31 highest, base=0x000 */
202 mtdcr (UIC2SR, 0xffffffff); /* clear all */
204 mtdcr (UIC3SR, 0xffffffff); /* clear all */
205 mtdcr (UIC3ER, 0x00000000); /* disable all */
206 mtdcr (UIC3CR, 0x00000000); /* all non-critical */
207 mtdcr (UIC3PR, 0xffff83ff); /* polarity */
208 mtdcr (UIC3TR, 0x00ff8c0f); /* trigger edge vs level */
209 mtdcr (UIC3VR, 0x00000001); /* int31 highest, base=0x000 */
210 mtdcr (UIC3SR, 0xffffffff); /* clear all */
212 mtdcr (UIC0SR, 0xfc000000); /* clear all */
213 mtdcr (UIC0ER, 0x00000000); /* disable all */
214 mtdcr (UIC0CR, 0x00000000); /* all non-critical */
215 mtdcr (UIC0PR, 0xfc000000);
216 mtdcr (UIC0TR, 0x00000000);
217 mtdcr (UIC0VR, 0x00000001);
224 /*************************************************************************
227 * Dump pertinent info to the console
228 ************************************************************************/
229 int checkboard (void)
232 unsigned char brd_rev, brd_id;
233 unsigned short sernum;
234 unsigned char opto_rev, opto_id;
235 OPTO_FPGA_REGS_ST *opto_ps;
237 opto_ps = (OPTO_FPGA_REGS_ST *)CONFIG_SYS_FPGA_BASE;
239 opto_rev = (unsigned char)((opto_ps->revision_ul &
240 SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_MASK)
241 >> SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_SHIFT);
243 opto_id = (unsigned char)((opto_ps->revision_ul &
244 SAND_HAL_XC_XCVR_CNTL_REVISION_IDENTIFICATION_MASK)
245 >> SAND_HAL_XC_XCVR_CNTL_REVISION_IDENTIFICATION_SHIFT);
247 brd_rev = (unsigned char)((opto_ps->boardinfo_ul &
248 SAND_HAL_XC_XCVR_CNTL_BRD_INFO_BRD_REV_MASK)
249 >> SAND_HAL_XC_XCVR_CNTL_BRD_INFO_BRD_REV_SHIFT);
251 brd_id = (unsigned char)((opto_ps->boardinfo_ul &
252 SAND_HAL_XC_XCVR_CNTL_BRD_INFO_BRD_ID_MASK)
253 >> SAND_HAL_XC_XCVR_CNTL_BRD_INFO_BRD_ID_SHIFT);
255 get_sys_info (&sysinfo);
257 sernum = sbcommon_get_serial_number();
258 printf ("Board: Sandburst Corporation MetroBox Serial Number: %d\n", sernum);
259 printf ("%s\n", METROBOX_U_BOOT_REL_STR);
261 printf ("Built %s %s by %s\n", U_BOOT_DATE, U_BOOT_TIME, BUILDUSER);
262 if (sbcommon_get_master()) {
263 printf("Slot 0 - Master\nSlave board");
264 if (sbcommon_secondary_present())
265 printf(" present\n");
267 printf(" not detected\n");
269 printf("Slot 1 - Slave\n\n");
272 printf ("OptoFPGA ID:\t0x%02X\tRev: 0x%02X\n", opto_id, opto_rev);
273 printf ("Board Rev:\t0x%02X\tID: %s\n", brd_rev, board_id_as[brd_id].name);
275 /* Fix the ack in the bme 32 */
277 out32(CONFIG_SYS_BME32_BASE + 0x0000000C, 0x00000001);
284 /*************************************************************************
287 * Initialize I2C bus one to gain access to the fans
288 ************************************************************************/
289 int misc_init_f (void)
297 /*************************************************************************
301 ************************************************************************/
302 int misc_init_r (void)
304 unsigned short sernum;
307 unsigned char opto_rev;
308 OPTO_FPGA_REGS_ST *opto_ps;
310 opto_ps = (OPTO_FPGA_REGS_ST *)CONFIG_SYS_FPGA_BASE;
312 if(NULL != getenv("secondserial")) {
313 puts("secondserial is set, switching to second serial port\n");
314 setenv("stderr", "serial1");
315 setenv("stdout", "serial1");
316 setenv("stdin", "serial1");
319 setenv("ubrelver", METROBOX_U_BOOT_REL_STR);
321 memset(envstr, 0, 255);
322 sprintf (envstr, "Built %s %s by %s",
323 U_BOOT_DATE, U_BOOT_TIME, BUILDUSER);
324 setenv("bldstr", envstr);
327 if( getenv("autorecover")) {
328 setenv("autorecover", NULL);
330 sernum = sbcommon_get_serial_number();
332 printf("\nSetting up environment for automatic filesystem recovery\n");
334 * Setup default bootargs
336 memset(envstr, 0, 255);
337 sprintf(envstr, "console=ttyS0,9600 root=/dev/ram0 "
338 "rw ip=10.100.60.%d:::255.255.0.0:metrobox%d:eth0:none idebus=33",
340 setenv("bootargs", envstr);
343 * Setup Default boot command
345 setenv("bootcmd", "fatload ide 0 8000000 pimage.metrobox;"
346 "fatload ide 0 8100000 pramdisk;"
347 "bootm 8000000 8100000");
349 printf("Done. Please type allow the system to continue to boot\n");
352 if( getenv("fakeled")) {
353 setenv("bootdelay", "-1");
355 printf("fakeled is set. use 'setenv fakeled ; setenv bootdelay 5 ; saveenv' to recover\n");
356 opto_rev = (unsigned char)((opto_ps->revision_ul &
357 SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_MASK)
358 >> SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_SHIFT);
360 if(0x12 <= opto_rev) {
361 opto_ps->control_ul &= ~ SAND_HAL_XC_XCVR_CNTL_CNTL_ERROR_LED_MASK;
365 #ifdef CONFIG_HAS_ETH0
366 if (!eth_getenv_enetaddr("ethaddr", enetaddr)) {
367 board_get_enetaddr(0, enetaddr);
368 eth_setenv_enetaddr("ethaddr", enetaddr);
372 #ifdef CONFIG_HAS_ETH1
373 if (!eth_getenv_enetaddr("eth1addr", enetaddr)) {
374 board_get_enetaddr(1, enetaddr);
375 eth_setenv_enetaddr("eth1addr", enetaddr);
379 #ifdef CONFIG_HAS_ETH2
380 if (!eth_getenv_enetaddr("eth2addr", enetaddr)) {
381 board_get_enetaddr(2, enetaddr);
382 eth_setenv_enetaddr("eth2addr", enetaddr);
386 #ifdef CONFIG_HAS_ETH3
387 if (!eth_getenv_enetaddr("eth3addr", enetaddr)) {
388 board_get_enetaddr(3, enetaddr);
389 eth_setenv_enetaddr("eth3addr", enetaddr);
396 /*************************************************************************
398 ************************************************************************/
399 #ifdef CONFIG_IDE_RESET
400 void ide_set_reset(int on)
402 OPTO_FPGA_REGS_ST *opto_ps;
403 opto_ps = (OPTO_FPGA_REGS_ST *)CONFIG_SYS_FPGA_BASE;
405 if (on) { /* assert RESET */
406 opto_ps->reset_ul &= ~SAND_HAL_XC_XCVR_CNTL_RESET_CF_RESET_N_MASK;
407 } else { /* release RESET */
408 opto_ps->reset_ul |= SAND_HAL_XC_XCVR_CNTL_RESET_CF_RESET_N_MASK;
411 #endif /* CONFIG_IDE_RESET */
413 /*************************************************************************
415 ************************************************************************/
418 OPTO_FPGA_REGS_ST *opto_ps;
419 unsigned char opto_rev;
422 /* Ensure we have power all around */
426 * Take appropriate hw bits out of reset
428 opto_ps = (OPTO_FPGA_REGS_ST *)CONFIG_SYS_FPGA_BASE;
431 SAND_HAL_XC_XCVR_CNTL_RESET_MAC1_RESET_N_MASK |
432 SAND_HAL_XC_XCVR_CNTL_RESET_MAC0_RESET_N_MASK |
433 SAND_HAL_XC_XCVR_CNTL_RESET_BME_RESET_N_MASK |
434 SAND_HAL_XC_XCVR_CNTL_RESET_ACE_RESET_N_MASK |
435 SAND_HAL_XC_XCVR_CNTL_RESET_CF_RESET_N_MASK |
436 SAND_HAL_XC_XCVR_CNTL_RESET_QE_A_RESET_N_MASK |
437 SAND_HAL_XC_XCVR_CNTL_RESET_IFE_A_RESET_N_MASK |
438 SAND_HAL_XC_XCVR_CNTL_RESET_EFE_A_RESET_N_MASK |
439 SAND_HAL_XC_XCVR_CNTL_RESET_QE_B_RESET_N_MASK |
440 SAND_HAL_XC_XCVR_CNTL_RESET_IFE_B_RESET_N_MASK |
441 SAND_HAL_XC_XCVR_CNTL_RESET_EFE_B_RESET_N_MASK |
442 SAND_HAL_XC_XCVR_CNTL_RESET_LOCK1_RESET_N_MASK |
443 SAND_HAL_XC_XCVR_CNTL_RESET_LOCK0_RESET_N_MASK |
444 SAND_HAL_XC_XCVR_CNTL_RESET_I2C_MUX1_RESET_N_MASK |
445 SAND_HAL_XC_XCVR_CNTL_RESET_I2C_MUX0_RESET_N_MASK |
446 SAND_HAL_XC_XCVR_CNTL_RESET_PHY0_RESET_N_MASK |
447 SAND_HAL_XC_XCVR_CNTL_RESET_PHY1_RESET_N_MASK |
448 SAND_HAL_XC_XCVR_CNTL_RESET_SLAVE_RESET_N_MASK;
449 opto_ps->reset_ul = tmp;
451 * Turn on the 'Slow Blink' for the System Error Led.
452 * Ensure FPGA rev is up to at least rev 0x12
454 opto_rev = (unsigned char)((opto_ps->revision_ul &
455 SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_MASK)
456 >> SAND_HAL_XC_XCVR_CNTL_REVISION_REVISION_SHIFT);
457 if(0x12 <= opto_rev) {
458 opto_ps->control_ul |= 1 << SAND_HAL_XC_XCVR_CNTL_CNTL_ERROR_LED_SHIFT;
466 int metroboxSetupVars(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
468 unsigned short sernum;
471 sernum = sbcommon_get_serial_number();
473 memset(envstr, 0, 255);
475 * Setup our ip address
477 sprintf(envstr, "10.100.60.%d", sernum);
479 setenv("ipaddr", envstr);
481 * Setup the host ip address
483 setenv("serverip", "10.100.17.10");
486 * Setup default bootargs
488 memset(envstr, 0, 255);
490 sprintf(envstr, "console=ttyS0,9600 root=/dev/nfs "
491 "rw nfsroot=10.100.17.10:/home/metrobox/mbc%d "
492 "nfsaddrs=10.100.60.%d:10.100.17.10:10.100.1.1"
493 ":255.255.0.0:metrobox%d.sandburst.com:eth0:none idebus=33",
494 sernum, sernum, sernum);
496 setenv("bootargs_nfs", envstr);
497 setenv("bootargs", envstr);
502 memset(envstr, 0, 255);
503 sprintf(envstr, "console=ttyS0,9600 root=/dev/hda2 "
504 "rw ip=10.100.60.%d:::255.255.0.0:metrobox%d:eth0:none idebus=33",
507 setenv("bootargs_cf", envstr);
510 * Setup Default boot command
512 setenv("bootcmd_tftp", "tftp 8000000 pImage.metrobox;bootm 8000000");
513 setenv("bootcmd", "tftp 8000000 pImage.metrobox;bootm 8000000");
516 * Setup compact flash boot command
518 setenv("bootcmd_cf", "fatload ide 0 8000000 pimage.metrobox;bootm 8000000");
526 int metroboxRecover(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
528 unsigned short sernum;
531 sernum = sbcommon_get_serial_number();
533 printf("\nSetting up environment for filesystem recovery\n");
535 * Setup default bootargs
537 memset(envstr, 0, 255);
538 sprintf(envstr, "console=ttyS0,9600 root=/dev/ram0 "
539 "rw ip=10.100.60.%d:::255.255.0.0:metrobox%d:eth0:none",
542 setenv("bootargs", envstr);
545 * Setup Default boot command
547 setenv("bootcmd", "fatload ide 0 8000000 pimage.metrobox;"
548 "fatload ide 0 8100000 pramdisk;"
549 "bootm 8000000 8100000");
551 printf("Done. Please type boot<cr>.\nWhen the kernel has booted"
552 " please type fsrecover.sh<cr>\n");
557 U_BOOT_CMD(mbsetup, 1, 1, metroboxSetupVars,
558 "Set environment to factory defaults", "");
560 U_BOOT_CMD(mbrecover, 1, 1, metroboxRecover,
561 "Set environment to allow for fs recovery", "");