2 * Copyright (C) 2005 Sandburst Corporation
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,
25 #include <asm/processor.h>
27 #include <spd_sdram.h>
29 #include "ppc440gx_i2c.h"
30 #include "sb_common.h"
32 long int fixed_sdram (void);
34 /*************************************************************************
37 * PRI_N - active low signal. If the GPIO pin is low we are the master
39 ************************************************************************/
40 int sbcommon_get_master(void)
42 ppc440_gpio_regs_t *gpio_regs;
44 gpio_regs = (ppc440_gpio_regs_t *)CFG_GPIO_BASE;
46 if (gpio_regs->in & SBCOMMON_GPIO_PRI_N) {
54 /*************************************************************************
55 * metrobox_secondary_present
57 * Figure out if secondary/slave board is present
59 ************************************************************************/
60 int sbcommon_secondary_present(void)
62 ppc440_gpio_regs_t *gpio_regs;
64 gpio_regs = (ppc440_gpio_regs_t *)CFG_GPIO_BASE;
66 if (gpio_regs->in & SBCOMMON_GPIO_SEC_PRES)
72 /*************************************************************************
73 * sbcommon_get_serial_number
75 * Retrieve the board serial number via the mac address in eeprom
77 ************************************************************************/
78 unsigned short sbcommon_get_serial_number(void)
80 unsigned char buff[0x100];
81 unsigned short sernum;
83 /* Get the board serial number from eeprom */
85 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
87 /* Read 256 bytes in EEPROM */
88 i2c_read (0x50, 0, 1, buff, 0x100);
90 memcpy(&sernum, &buff[0xF4], 2);
96 /*************************************************************************
99 * Spin up fans 2 & 3 to get some air moving. OS will take care
100 * of the rest. This is mostly a precaution...
102 * Assumes i2c bus 1 is ready.
104 ************************************************************************/
105 void sbcommon_fans(void)
108 * Attempt to turn on 2 of the fans...
109 * Need to go through the bridge
113 /* select fan4 through the bridge */
114 i2c_reg_write1(0x73, /* addr */
116 0x08); /* val = bus 4 */
127 /* Deselect bus 4 on the bridge */
132 /* select fan3 through the bridge */
133 i2c_reg_write1(0x73, /* addr */
135 0x04); /* val = bus 3 */
146 /* Deselect bus 3 on the bridge */
151 /* select fan2 through the bridge */
152 i2c_reg_write1(0x73, /* addr */
154 0x02); /* val = bus 4 */
165 /* Deselect bus 2 on the bridge */
170 /* select fan1 through the bridge */
171 i2c_reg_write1(0x73, /* addr */
173 0x01); /* val = bus 0 */
184 /* Deselect bus 1 on the bridge */
195 /*************************************************************************
200 ************************************************************************/
201 long int initdram (int board_type)
205 #if defined(CONFIG_SPD_EEPROM)
206 dram_size = spd_sdram (0);
208 dram_size = fixed_sdram ();
214 /*************************************************************************
218 ************************************************************************/
219 #if defined(CFG_DRAM_TEST)
222 uint *pstart = (uint *) CFG_MEMTEST_START;
223 uint *pend = (uint *) CFG_MEMTEST_END;
226 printf("Testing SDRAM: ");
227 for (p = pstart; p < pend; p++)
230 for (p = pstart; p < pend; p++) {
231 if (*p != 0xaaaaaaaa) {
232 printf ("SDRAM test fails at: %08x\n", (uint) p);
237 for (p = pstart; p < pend; p++)
240 for (p = pstart; p < pend; p++) {
241 if (*p != 0x55555555) {
242 printf ("SDRAM test fails at: %08x\n", (uint) p);
252 #if !defined(CONFIG_SPD_EEPROM)
253 /*************************************************************************
254 * fixed sdram init -- doesn't use serial presence detect.
256 * Assumes: 128 MB, non-ECC, non-registered
259 ************************************************************************/
260 long int fixed_sdram (void)
264 /*--------------------------------------------------------------------
266 *------------------------------------------------------------------*/
267 mtsdram (mem_uabba, 0x00000000); /* ubba=0 (default) */
268 mtsdram (mem_slio, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
269 mtsdram (mem_devopt, 0x00000000); /* dll=0 ds=0 (normal) */
270 mtsdram (mem_wddctr, 0x00000000); /* wrcp=0 dcd=0 */
271 mtsdram (mem_clktr, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
273 /*--------------------------------------------------------------------
274 * Setup for board-specific specific mem
275 *------------------------------------------------------------------*/
277 * Following for CAS Latency = 2.5 @ 133 MHz PLB
279 mtsdram (mem_b0cr, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
280 mtsdram (mem_tr0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
282 mtsdram (mem_tr1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
283 mtsdram (mem_rtr, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
284 mtsdram (mem_cfg1, 0x00000000); /* Self-refresh exit, disable PM */
285 udelay (400); /* Delay 200 usecs (min) */
287 /*--------------------------------------------------------------------
288 * Enable the controller, then wait for DCEN to complete
289 *------------------------------------------------------------------*/
290 mtsdram (mem_cfg0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
292 mfsdram (mem_mcsts, reg);
293 if (reg & 0x80000000)
297 return (128 * 1024 * 1024); /* 128 MB */
299 #endif /* !defined(CONFIG_SPD_EEPROM) */
302 /*************************************************************************
305 * This routine is called just prior to registering the hose and gives
306 * the board the opportunity to check things. Returning a value of zero
307 * indicates that things are bad & PCI initialization should be aborted.
309 * Different boards may wish to customize the pci controller structure
310 * (add regions, override default access routines, etc) or perform
311 * certain pre-initialization actions.
313 ************************************************************************/
314 #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
315 int pci_pre_init(struct pci_controller * hose )
319 /*--------------------------------------------------------------------------+
320 * The metrobox is always configured as the host & requires the
321 * PCI arbiter to be enabled.
322 *--------------------------------------------------------------------------*/
323 mfsdr(sdr_sdstp1, strap);
324 if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ){
325 printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
331 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
333 /*************************************************************************
336 * The bootstrap configuration provides default settings for the pci
337 * inbound map (PIM). But the bootstrap config choices are limited and
338 * may not be sufficient for a given board.
340 ************************************************************************/
341 #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
342 void pci_target_init(struct pci_controller * hose )
344 DECLARE_GLOBAL_DATA_PTR;
346 /*--------------------------------------------------------------------------+
348 *--------------------------------------------------------------------------*/
349 out32r( PCIX0_PIM0SA, 0 ); /* disable */
350 out32r( PCIX0_PIM1SA, 0 ); /* disable */
351 out32r( PCIX0_PIM2SA, 0 ); /* disable */
352 out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
354 /*--------------------------------------------------------------------------+
355 * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
356 * options to not support sizes such as 128/256 MB.
357 *--------------------------------------------------------------------------*/
358 out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
359 out32r( PCIX0_PIM0LAH, 0 );
360 out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
362 out32r( PCIX0_BAR0, 0 );
364 /*--------------------------------------------------------------------------+
365 * Program the board's subsystem id/vendor id
366 *--------------------------------------------------------------------------*/
367 out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
368 out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
370 out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
372 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
375 /*************************************************************************
379 ************************************************************************/
380 #if defined(CONFIG_PCI)
381 int is_pci_host(struct pci_controller *hose)
383 /* The metrobox is always configured as host. */
386 #endif /* defined(CONFIG_PCI) */
388 /*************************************************************************
391 * Get the ethernet MAC address for the management ethernet from the
392 * strap EEPROM. Note that is the BASE address for the range of
393 * external ethernet MACs on the board. The base + 31 is the actual
396 ************************************************************************/
397 static int macaddr_idx = 0;
399 void board_get_enetaddr (uchar * enet)
403 unsigned char buff[0x100], *cp;
405 if (0 == macaddr_idx) {
408 i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
410 /* Read 256 bytes in EEPROM */
411 i2c_read (0x50, 0, 1, buff, 0x100);
415 for (i = 0; i < 6; i++,cp++)
418 memcpy(&tmp, &enet[4], 2);
420 memcpy(&enet[4], &tmp, 2);
429 if (1 == sbcommon_get_master() ) {
430 /* Master/Primary card */
433 /* Slave/Secondary card */
443 * Returns 1 if keys pressed to start the power-on long-running tests
444 * Called from board_init_f().
446 int post_hotkeys_pressed(void)