2 * Copyright (C) 2005 Sandburst Corporation
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/processor.h>
11 #include <spd_sdram.h>
13 #include "ppc440gx_i2c.h"
14 #include "sb_common.h"
16 DECLARE_GLOBAL_DATA_PTR;
18 long int fixed_sdram (void);
20 /*************************************************************************
23 * PRI_N - active low signal. If the GPIO pin is low we are the master
25 ************************************************************************/
26 int sbcommon_get_master(void)
28 ppc440_gpio_regs_t *gpio_regs;
30 gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
32 if (gpio_regs->in & SBCOMMON_GPIO_PRI_N) {
40 /*************************************************************************
41 * metrobox_secondary_present
43 * Figure out if secondary/slave board is present
45 ************************************************************************/
46 int sbcommon_secondary_present(void)
48 ppc440_gpio_regs_t *gpio_regs;
50 gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
52 if (gpio_regs->in & SBCOMMON_GPIO_SEC_PRES)
58 /*************************************************************************
59 * sbcommon_get_serial_number
61 * Retrieve the board serial number via the mac address in eeprom
63 ************************************************************************/
64 unsigned short sbcommon_get_serial_number(void)
66 unsigned char buff[0x100];
67 unsigned short sernum;
69 /* Get the board serial number from eeprom */
71 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
73 /* Read 256 bytes in EEPROM */
74 i2c_read (0x50, 0, 1, buff, 0x100);
76 memcpy(&sernum, &buff[0xF4], 2);
82 /*************************************************************************
85 * Spin up fans 2 & 3 to get some air moving. OS will take care
86 * of the rest. This is mostly a precaution...
88 * Assumes i2c bus 1 is ready.
90 ************************************************************************/
91 void sbcommon_fans(void)
94 * Attempt to turn on 2 of the fans...
95 * Need to go through the bridge
99 /* select fan4 through the bridge */
100 i2c_reg_write1(0x73, /* addr */
102 0x08); /* val = bus 4 */
113 /* Deselect bus 4 on the bridge */
118 /* select fan3 through the bridge */
119 i2c_reg_write1(0x73, /* addr */
121 0x04); /* val = bus 3 */
132 /* Deselect bus 3 on the bridge */
137 /* select fan2 through the bridge */
138 i2c_reg_write1(0x73, /* addr */
140 0x02); /* val = bus 4 */
151 /* Deselect bus 2 on the bridge */
156 /* select fan1 through the bridge */
157 i2c_reg_write1(0x73, /* addr */
159 0x01); /* val = bus 0 */
170 /* Deselect bus 1 on the bridge */
181 /*************************************************************************
186 ************************************************************************/
187 phys_size_t initdram (int board_type)
191 #if defined(CONFIG_SPD_EEPROM)
192 dram_size = spd_sdram ();
194 dram_size = fixed_sdram ();
200 /*************************************************************************
204 ************************************************************************/
205 #if defined(CONFIG_SYS_DRAM_TEST)
208 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
209 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
212 printf("Testing SDRAM: ");
213 for (p = pstart; p < pend; p++)
216 for (p = pstart; p < pend; p++) {
217 if (*p != 0xaaaaaaaa) {
218 printf ("SDRAM test fails at: %08x\n", (uint) p);
223 for (p = pstart; p < pend; p++)
226 for (p = pstart; p < pend; p++) {
227 if (*p != 0x55555555) {
228 printf ("SDRAM test fails at: %08x\n", (uint) p);
238 #if !defined(CONFIG_SPD_EEPROM)
239 /*************************************************************************
240 * fixed sdram init -- doesn't use serial presence detect.
242 * Assumes: 128 MB, non-ECC, non-registered
245 ************************************************************************/
246 long int fixed_sdram (void)
250 /*--------------------------------------------------------------------
252 *------------------------------------------------------------------*/
253 mtsdram (SDRAM0_UABBA, 0x00000000); /* ubba=0 (default) */
254 mtsdram (SDRAM0_SLIO, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
255 mtsdram (SDRAM0_DEVOPT, 0x00000000); /* dll=0 ds=0 (normal) */
256 mtsdram (SDRAM0_WDDCTR, 0x00000000); /* wrcp=0 dcd=0 */
257 mtsdram (SDRAM0_CLKTR, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
259 /*--------------------------------------------------------------------
260 * Setup for board-specific specific mem
261 *------------------------------------------------------------------*/
263 * Following for CAS Latency = 2.5 @ 133 MHz PLB
265 mtsdram (SDRAM0_B0CR, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
266 mtsdram (SDRAM0_TR0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
268 mtsdram (SDRAM0_TR1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
269 mtsdram (SDRAM0_RTR, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
270 mtsdram (SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM */
271 udelay (400); /* Delay 200 usecs (min) */
273 /*--------------------------------------------------------------------
274 * Enable the controller, then wait for DCEN to complete
275 *------------------------------------------------------------------*/
276 mtsdram (SDRAM0_CFG0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
278 mfsdram (SDRAM0_MCSTS, reg);
279 if (reg & 0x80000000)
283 return (128 * 1024 * 1024); /* 128 MB */
285 #endif /* !defined(CONFIG_SPD_EEPROM) */
287 /*************************************************************************
290 * Get the ethernet MAC address for the management ethernet from the
291 * strap EEPROM. Note that is the BASE address for the range of
292 * external ethernet MACs on the board. The base + 31 is the actual
295 ************************************************************************/
297 void board_get_enetaddr(int macaddr_idx, uchar *enet)
301 unsigned char buff[0x100], *cp;
303 if (0 == macaddr_idx) {
306 i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
308 /* Read 256 bytes in EEPROM */
309 i2c_read (0x50, 0, 1, buff, 0x100);
313 for (i = 0; i < 6; i++,cp++)
316 memcpy(&tmp, &enet[4], 2);
318 memcpy(&enet[4], &tmp, 2);
326 if (1 == sbcommon_get_master() ) {
327 /* Master/Primary card */
330 /* Slave/Secondary card */
340 * Returns 1 if keys pressed to start the power-on long-running tests
341 * Called from board_init_f().
343 int post_hotkeys_pressed(void)