2 * Copyright (C) 2004 PaulReynolds@lhsolutions.com
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/processor.h>
27 #include <spd_sdram.h>
28 #include <440gx_enet.h>
30 #define BOOT_SMALL_FLASH 32 /* 00100000 */
31 #define FLASH_ONBD_N 2 /* 00000010 */
32 #define FLASH_SRAM_SEL 1 /* 00000001 */
34 long int fixed_sdram (void);
35 void fpga_init (void);
37 int board_early_init_f (void)
40 /*-------------------------------------------------------------------------+
41 | Initialize EBC CONFIG
42 +-------------------------------------------------------------------------*/
43 mtebc(xbcfg, EBC_CFG_LE_UNLOCK |
44 EBC_CFG_PTD_ENABLE | EBC_CFG_RTC_64PERCLK |
45 EBC_CFG_ATC_PREVIOUS | EBC_CFG_DTC_PREVIOUS |
46 EBC_CFG_CTC_PREVIOUS | EBC_CFG_EMC_NONDEFAULT |
47 EBC_CFG_PME_DISABLE | EBC_CFG_PR_32);
49 /*-------------------------------------------------------------------------+
50 | 1 MB FLASH / 1 MB SRAM. Initialize bank 0 with default values.
51 +-------------------------------------------------------------------------*/
52 mtebc(pb0ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(8)|
54 EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
55 EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
56 EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
57 EBC_BXAP_BEM_WRITEONLY|
58 EBC_BXAP_PEN_DISABLED);
59 mtebc(pb0cr, EBC_BXCR_BAS_ENCODE(0xFFE00000)|
60 EBC_BXCR_BS_2MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
62 /*-------------------------------------------------------------------------+
63 | 8KB NVRAM/RTC. Initialize bank 1 with default values.
64 +-------------------------------------------------------------------------*/
65 mtebc(pb1ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(10)|
67 EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
68 EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
69 EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
70 EBC_BXAP_BEM_WRITEONLY|
71 EBC_BXAP_PEN_DISABLED);
72 mtebc(pb1cr, EBC_BXCR_BAS_ENCODE(0x48000000)|
73 EBC_BXCR_BS_1MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
75 /*-------------------------------------------------------------------------+
76 | 4 MB FLASH. Initialize bank 2 with default values.
77 +-------------------------------------------------------------------------*/
78 mtebc(pb2ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(10)|
80 EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
81 EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
82 EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
83 EBC_BXAP_BEM_WRITEONLY|
84 EBC_BXAP_PEN_DISABLED);
85 mtebc(pb2cr, EBC_BXCR_BAS_ENCODE(0xFF800000)|
86 EBC_BXCR_BS_4MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
88 /*-------------------------------------------------------------------------+
89 | FPGA. Initialize bank 7 with default values.
90 +-------------------------------------------------------------------------*/
91 mtebc(pb7ap, EBC_BXAP_BME_DISABLED|EBC_BXAP_TWT_ENCODE(7)|
93 EBC_BXAP_CSN_ENCODE(1)|EBC_BXAP_OEN_ENCODE(1)|
94 EBC_BXAP_WBN_ENCODE(1)|EBC_BXAP_WBF_ENCODE(1)|
95 EBC_BXAP_TH_ENCODE(1)|EBC_BXAP_RE_DISABLED|
96 EBC_BXAP_BEM_WRITEONLY|
97 EBC_BXAP_PEN_DISABLED);
98 mtebc(pb7cr, EBC_BXCR_BAS_ENCODE(0x48300000)|
99 EBC_BXCR_BS_1MB|EBC_BXCR_BU_RW|EBC_BXCR_BW_8BIT);
101 /*--------------------------------------------------------------------
102 * Setup the interrupt controller polarities, triggers, etc.
103 *-------------------------------------------------------------------*/
104 mtdcr (uic0sr, 0xffffffff); /* clear all */
105 mtdcr (uic0er, 0x00000000); /* disable all */
106 mtdcr (uic0cr, 0x00000009); /* SMI & UIC1 crit are critical */
107 mtdcr (uic0pr, 0xfffffe13); /* per ref-board manual */
108 mtdcr (uic0tr, 0x01c00008); /* per ref-board manual */
109 mtdcr (uic0vr, 0x00000001); /* int31 highest, base=0x000 */
110 mtdcr (uic0sr, 0xffffffff); /* clear all */
112 mtdcr (uic1sr, 0xffffffff); /* clear all */
113 mtdcr (uic1er, 0x00000000); /* disable all */
114 mtdcr (uic1cr, 0x00000000); /* all non-critical */
115 mtdcr (uic1pr, 0xffffe0ff); /* per ref-board manual */
116 mtdcr (uic1tr, 0x00ffc000); /* per ref-board manual */
117 mtdcr (uic1vr, 0x00000001); /* int31 highest, base=0x000 */
118 mtdcr (uic1sr, 0xffffffff); /* clear all */
120 mtdcr (uic2sr, 0xffffffff); /* clear all */
121 mtdcr (uic2er, 0x00000000); /* disable all */
122 mtdcr (uic2cr, 0x00000000); /* all non-critical */
123 mtdcr (uic2pr, 0xffffffff); /* per ref-board manual */
124 mtdcr (uic2tr, 0x00ff8c0f); /* per ref-board manual */
125 mtdcr (uic2vr, 0x00000001); /* int31 highest, base=0x000 */
126 mtdcr (uic2sr, 0xffffffff); /* clear all */
128 mtdcr (uicb0sr, 0xfc000000); /* clear all */
129 mtdcr (uicb0er, 0x00000000); /* disable all */
130 mtdcr (uicb0cr, 0x00000000); /* all non-critical */
131 mtdcr (uicb0pr, 0xfc000000); /* */
132 mtdcr (uicb0tr, 0x00000000); /* */
133 mtdcr (uicb0vr, 0x00000001); /* */
134 mfsdr (sdr_mfr, mfr);
135 mfr &= ~SDR0_MFR_ECS_MASK;
136 /* mtsdr(sdr_mfr, mfr); */
143 int checkboard (void)
147 get_sys_info (&sysinfo);
149 printf ("Board: IBM 440GX Evaluation Board\n");
150 printf ("\tVCO: %lu MHz\n", sysinfo.freqVCOMhz / 1000000);
151 printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
152 printf ("\tPLB: %lu MHz\n", sysinfo.freqPLB / 1000000);
153 printf ("\tOPB: %lu MHz\n", sysinfo.freqOPB / 1000000);
154 printf ("\tEPB: %lu MHz\n", sysinfo.freqEPB / 1000000);
159 long int initdram (int board_type)
163 #if defined(CONFIG_SPD_EEPROM)
164 dram_size = spd_sdram (0);
166 dram_size = fixed_sdram ();
172 #if defined(CFG_DRAM_TEST)
175 uint *pstart = (uint *) 0x00000000;
176 uint *pend = (uint *) 0x08000000;
179 for (p = pstart; p < pend; p++)
182 for (p = pstart; p < pend; p++) {
183 if (*p != 0xaaaaaaaa) {
184 printf ("SDRAM test fails at: %08x\n", (uint) p);
189 for (p = pstart; p < pend; p++)
192 for (p = pstart; p < pend; p++) {
193 if (*p != 0x55555555) {
194 printf ("SDRAM test fails at: %08x\n", (uint) p);
202 #if !defined(CONFIG_SPD_EEPROM)
203 /*************************************************************************
204 * fixed sdram init -- doesn't use serial presence detect.
206 * Assumes: 128 MB, non-ECC, non-registered
209 ************************************************************************/
210 long int fixed_sdram (void)
214 /*--------------------------------------------------------------------
216 *------------------------------------------------------------------*/
217 mtsdram (mem_uabba, 0x00000000); /* ubba=0 (default) */
218 mtsdram (mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
219 mtsdram (mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
220 mtsdram (mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
221 mtsdram (mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
223 /*--------------------------------------------------------------------
224 * Setup for board-specific specific mem
225 *------------------------------------------------------------------*/
227 * Following for CAS Latency = 2.5 @ 133 MHz PLB
229 mtsdram (mem_b0cr, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
230 mtsdram (mem_tr0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
232 mtsdram (mem_tr1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
233 mtsdram (mem_rtr, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
234 mtsdram (mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM */
235 udelay (400); /* Delay 200 usecs (min) */
237 /*--------------------------------------------------------------------
238 * Enable the controller, then wait for DCEN to complete
239 *------------------------------------------------------------------*/
240 mtsdram (mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
242 mfsdram (mem_mcsts, reg);
243 if (reg & 0x80000000)
247 return (128 * 1024 * 1024); /* 128 MB */
249 #endif /* !defined(CONFIG_SPD_EEPROM) */
252 /*************************************************************************
255 * This routine is called just prior to registering the hose and gives
256 * the board the opportunity to check things. Returning a value of zero
257 * indicates that things are bad & PCI initialization should be aborted.
259 * Different boards may wish to customize the pci controller structure
260 * (add regions, override default access routines, etc) or perform
261 * certain pre-initialization actions.
263 ************************************************************************/
264 #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
265 int pci_pre_init(struct pci_controller * hose )
269 /*--------------------------------------------------------------------------+
270 * The ocotea board is always configured as the host & requires the
271 * PCI arbiter to be enabled.
272 *--------------------------------------------------------------------------*/
273 mfsdr(sdr_sdstp1, strap);
274 if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
275 printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
281 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
283 /*************************************************************************
286 * The bootstrap configuration provides default settings for the pci
287 * inbound map (PIM). But the bootstrap config choices are limited and
288 * may not be sufficient for a given board.
290 ************************************************************************/
291 #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
292 void pci_target_init(struct pci_controller * hose )
294 DECLARE_GLOBAL_DATA_PTR;
296 /*--------------------------------------------------------------------------+
298 *--------------------------------------------------------------------------*/
299 out32r( PCIX0_PIM0SA, 0 ); /* disable */
300 out32r( PCIX0_PIM1SA, 0 ); /* disable */
301 out32r( PCIX0_PIM2SA, 0 ); /* disable */
302 out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
304 /*--------------------------------------------------------------------------+
305 * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
306 * options to not support sizes such as 128/256 MB.
307 *--------------------------------------------------------------------------*/
308 out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
309 out32r( PCIX0_PIM0LAH, 0 );
310 out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
312 out32r( PCIX0_BAR0, 0 );
314 /*--------------------------------------------------------------------------+
315 * Program the board's subsystem id/vendor id
316 *--------------------------------------------------------------------------*/
317 out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
318 out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
320 out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
322 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
325 /*************************************************************************
328 * This routine is called to determine if a pci scan should be
329 * performed. With various hardware environments (especially cPCI and
330 * PPMC) it's insufficient to depend on the state of the arbiter enable
331 * bit in the strap register, or generic host/adapter assumptions.
333 * Rather than hard-code a bad assumption in the general 440 code, the
334 * 440 pci code requires the board to decide at runtime.
336 * Return 0 for adapter mode, non-zero for host (monarch) mode.
339 ************************************************************************/
340 #if defined(CONFIG_PCI)
341 int is_pci_host(struct pci_controller *hose)
343 /* The ocotea board is always configured as host. */
346 #endif /* defined(CONFIG_PCI) */
352 unsigned long sdr0_pfc0;
353 unsigned long sdr0_pfc1;
354 unsigned long sdr0_cust0;
357 mfsdr (sdr_pfc0, sdr0_pfc0);
358 mfsdr (sdr_pfc1, sdr0_pfc1);
359 group = SDR0_PFC1_EPS_DECODE(sdr0_pfc1);
362 sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_GEIE_MASK) | SDR0_PFC0_GEIE_TRE;
363 if ( ((pvr == PVR_440GX_RA) || (pvr == PVR_440GX_RB)) && ((group == 4) || (group == 5))) {
364 sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_TRE_MASK) | SDR0_PFC0_TRE_DISABLE;
365 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_EMS;
366 out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
367 FPGA_REG2_EXT_INTFACE_ENABLE);
368 mtsdr (sdr_pfc0, sdr0_pfc0);
369 mtsdr (sdr_pfc1, sdr0_pfc1);
371 sdr0_pfc0 = (sdr0_pfc0 & ~SDR0_PFC0_TRE_MASK) | SDR0_PFC0_TRE_ENABLE;
378 out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
379 FPGA_REG2_EXT_INTFACE_ENABLE);
380 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_EMS;
381 mtsdr (sdr_pfc0, sdr0_pfc0);
382 mtsdr (sdr_pfc1, sdr0_pfc1);
388 /* CPU trace B - Over EBMI */
389 sdr0_pfc1 = (sdr0_pfc1 & ~SDR0_PFC1_CTEMS_MASK) | SDR0_PFC1_CTEMS_CPUTRACE;
390 mtsdr (sdr_pfc0, sdr0_pfc0);
391 mtsdr (sdr_pfc1, sdr0_pfc1);
392 out8(FPGA_REG2, (in8(FPGA_REG2) & ~FPGA_REG2_EXT_INTFACE_MASK) |
393 FPGA_REG2_EXT_INTFACE_DISABLE);
398 /* Initialize the ethernet specific functions in the fpga */
399 mfsdr(sdr_pfc1, sdr0_pfc1);
400 mfsdr(sdr_cust0, sdr0_cust0);
401 if ( (SDR0_PFC1_EPS_DECODE(sdr0_pfc1) == 4) &&
402 ((SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_GMII) ||
403 (SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_TBI)))
405 if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
407 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK1) |
408 FPGA_REG3_ENET_GROUP7);
412 if (SDR0_CUST0_RGMII2_DECODE(sdr0_cust0) == RGMII_FER_GMII)
414 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
415 FPGA_REG3_ENET_GROUP7);
419 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
420 FPGA_REG3_ENET_GROUP8);
426 if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
428 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK1) |
429 FPGA_REG3_ENET_ENCODE1(SDR0_PFC1_EPS_DECODE(sdr0_pfc1)));
433 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_ENET_MASK2) |
434 FPGA_REG3_ENET_ENCODE2(SDR0_PFC1_EPS_DECODE(sdr0_pfc1)));
437 out8(FPGA_REG4, FPGA_REG4_GPHY_MODE10 |
438 FPGA_REG4_GPHY_MODE100 | FPGA_REG4_GPHY_MODE1000 |
439 FPGA_REG4_GPHY_FRC_DPLX | FPGA_REG4_CONNECT_PHYS);
441 /* reset the gigabyte phy if necessary */
442 if (SDR0_PFC1_EPS_DECODE(sdr0_pfc1) >= 3)
444 if ((in8(FPGA_REG0) & FPGA_REG0_ECLS_MASK) == FPGA_REG0_ECLS_VER1)
446 out8(FPGA_REG3, in8(FPGA_REG3) & ~FPGA_REG3_GIGABIT_RESET_DISABLE);
448 out8(FPGA_REG3, in8(FPGA_REG3) | FPGA_REG3_GIGABIT_RESET_DISABLE);
452 out8(FPGA_REG2, in8(FPGA_REG2) & ~FPGA_REG2_GIGABIT_RESET_DISABLE);
454 out8(FPGA_REG2, in8(FPGA_REG2) | FPGA_REG2_GIGABIT_RESET_DISABLE);
458 /* Turn off the LED's */
459 out8(FPGA_REG3, (in8(FPGA_REG3) & ~FPGA_REG3_STAT_MASK) |
460 FPGA_REG3_STAT_LED8_DISAB | FPGA_REG3_STAT_LED4_DISAB |
461 FPGA_REG3_STAT_LED2_DISAB | FPGA_REG3_STAT_LED1_DISAB);
468 * Returns 1 if keys pressed to start the power-on long-running tests
469 * Called from board_init_f().
471 int post_hotkeys_pressed(void)