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 "sb_common.h"
15
DECLARE_GLOBAL_DATA_PTR;
17
long int fixed_sdram (void);
19
/*************************************************************************
22
* PRI_N - active low signal. If the GPIO pin is low we are the master
24
************************************************************************/
25
int sbcommon_get_master(void)
27
ppc440_gpio_regs_t *gpio_regs;
29
gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
31
if (gpio_regs->in & SBCOMMON_GPIO_PRI_N) {
39
/*************************************************************************
40
* metrobox_secondary_present
42
* Figure out if secondary/slave board is present
44
************************************************************************/
45
int sbcommon_secondary_present(void)
47
ppc440_gpio_regs_t *gpio_regs;
49
gpio_regs = (ppc440_gpio_regs_t *)CONFIG_SYS_GPIO_BASE;
51
if (gpio_regs->in & SBCOMMON_GPIO_SEC_PRES)
57
/*************************************************************************
58
* sbcommon_get_serial_number
60
* Retrieve the board serial number via the mac address in eeprom
62
************************************************************************/
63
unsigned short sbcommon_get_serial_number(void)
65
unsigned char buff[0x100];
66
unsigned short sernum;
68
/* Get the board serial number from eeprom */
72
/* Read 256 bytes in EEPROM */
73
i2c_read (0x50, 0, 1, buff, 0x100);
75
memcpy(&sernum, &buff[0xF4], 2);
81
/*************************************************************************
84
* Spin up fans 2 & 3 to get some air moving. OS will take care
85
* of the rest. This is mostly a precaution...
87
* Assumes i2c bus 1 is ready.
89
************************************************************************/
90
void sbcommon_fans(void)
93
* Attempt to turn on 2 of the fans...
94
* Need to go through the bridge
99
/* select fan4 through the bridge */
100
i2c_reg_write(0x73, /* addr */
102
0x08); /* val = bus 4 */
113
/* Deselect bus 4 on the bridge */
118
/* select fan3 through the bridge */
119
i2c_reg_write(0x73, /* addr */
121
0x04); /* val = bus 3 */
132
/* Deselect bus 3 on the bridge */
137
/* select fan2 through the bridge */
138
i2c_reg_write(0x73, /* addr */
140
0x02); /* val = bus 4 */
151
/* Deselect bus 2 on the bridge */
156
/* select fan1 through the bridge */
157
i2c_reg_write(0x73, /* addr */
159
0x01); /* val = bus 0 */
170
/* Deselect bus 1 on the bridge */
182
/*************************************************************************
187
************************************************************************/
188
phys_size_t initdram (int board_type)
192
#if defined(CONFIG_SPD_EEPROM)
193
dram_size = spd_sdram ();
195
dram_size = fixed_sdram ();
201
/*************************************************************************
205
************************************************************************/
206
#if defined(CONFIG_SYS_DRAM_TEST)
209
uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
210
uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
213
printf("Testing SDRAM: ");
214
for (p = pstart; p < pend; p++)
217
for (p = pstart; p < pend; p++) {
218
if (*p != 0xaaaaaaaa) {
219
printf ("SDRAM test fails at: %08x\n", (uint) p);
224
for (p = pstart; p < pend; p++)
227
for (p = pstart; p < pend; p++) {
228
if (*p != 0x55555555) {
229
printf ("SDRAM test fails at: %08x\n", (uint) p);
239
#if !defined(CONFIG_SPD_EEPROM)
240
/*************************************************************************
241
* fixed sdram init -- doesn't use serial presence detect.
243
* Assumes: 128 MB, non-ECC, non-registered
246
************************************************************************/
247
long int fixed_sdram (void)
251
/*--------------------------------------------------------------------
253
*------------------------------------------------------------------*/
254
mtsdram (SDRAM0_UABBA, 0x00000000); /* ubba=0 (default) */
255
mtsdram (SDRAM0_SLIO, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
256
mtsdram (SDRAM0_DEVOPT, 0x00000000); /* dll=0 ds=0 (normal) */
257
mtsdram (SDRAM0_WDDCTR, 0x00000000); /* wrcp=0 dcd=0 */
258
mtsdram (SDRAM0_CLKTR, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
260
/*--------------------------------------------------------------------
261
* Setup for board-specific specific mem
262
*------------------------------------------------------------------*/
264
* Following for CAS Latency = 2.5 @ 133 MHz PLB
266
mtsdram (SDRAM0_B0CR, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
267
mtsdram (SDRAM0_TR0, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
269
mtsdram (SDRAM0_TR1, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
270
mtsdram (SDRAM0_RTR, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
271
mtsdram (SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM */
272
udelay (400); /* Delay 200 usecs (min) */
274
/*--------------------------------------------------------------------
275
* Enable the controller, then wait for DCEN to complete
276
*------------------------------------------------------------------*/
277
mtsdram (SDRAM0_CFG0, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
279
mfsdram (SDRAM0_MCSTS, reg);
280
if (reg & 0x80000000)
284
return (128 * 1024 * 1024); /* 128 MB */
286
#endif /* !defined(CONFIG_SPD_EEPROM) */
288
/*************************************************************************
291
* Get the ethernet MAC address for the management ethernet from the
292
* strap EEPROM. Note that is the BASE address for the range of
293
* external ethernet MACs on the board. The base + 31 is the actual
296
************************************************************************/
298
void board_get_enetaddr(int macaddr_idx, uchar *enet)
302
unsigned char buff[0x100], *cp;
304
if (0 == macaddr_idx) {
309
/* Read 256 bytes in EEPROM */
310
i2c_read (0x50, 0, 1, buff, 0x100);
314
for (i = 0; i < 6; i++,cp++)
317
memcpy(&tmp, &enet[4], 2);
319
memcpy(&enet[4], &tmp, 2);
327
if (1 == sbcommon_get_master() ) {
328
/* Master/Primary card */
331
/* Slave/Secondary card */
341
* Returns 1 if keys pressed to start the power-on long-running tests
342
* Called from board_init_f().
344
int post_hotkeys_pressed(void)