]>
git.ipfire.org Git - people/ms/u-boot.git/blob - board/sandburst/common/sb_common.c
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 "sb_common.h"
31 DECLARE_GLOBAL_DATA_PTR
;
33 long int fixed_sdram (void);
35 /*************************************************************************
38 * PRI_N - active low signal. If the GPIO pin is low we are the master
40 ************************************************************************/
41 int sbcommon_get_master(void)
43 ppc440_gpio_regs_t
*gpio_regs
;
45 gpio_regs
= (ppc440_gpio_regs_t
*)CONFIG_SYS_GPIO_BASE
;
47 if (gpio_regs
->in
& SBCOMMON_GPIO_PRI_N
) {
55 /*************************************************************************
56 * metrobox_secondary_present
58 * Figure out if secondary/slave board is present
60 ************************************************************************/
61 int sbcommon_secondary_present(void)
63 ppc440_gpio_regs_t
*gpio_regs
;
65 gpio_regs
= (ppc440_gpio_regs_t
*)CONFIG_SYS_GPIO_BASE
;
67 if (gpio_regs
->in
& SBCOMMON_GPIO_SEC_PRES
)
73 /*************************************************************************
74 * sbcommon_get_serial_number
76 * Retrieve the board serial number via the mac address in eeprom
78 ************************************************************************/
79 unsigned short sbcommon_get_serial_number(void)
81 unsigned char buff
[0x100];
82 unsigned short sernum
;
84 /* Get the board serial number from eeprom */
88 /* Read 256 bytes in EEPROM */
89 i2c_read (0x50, 0, 1, buff
, 0x100);
91 memcpy(&sernum
, &buff
[0xF4], 2);
97 /*************************************************************************
100 * Spin up fans 2 & 3 to get some air moving. OS will take care
101 * of the rest. This is mostly a precaution...
103 * Assumes i2c bus 1 is ready.
105 ************************************************************************/
106 void sbcommon_fans(void)
109 * Attempt to turn on 2 of the fans...
110 * Need to go through the bridge
115 /* select fan4 through the bridge */
116 i2c_reg_write(0x73, /* addr */
118 0x08); /* val = bus 4 */
129 /* Deselect bus 4 on the bridge */
134 /* select fan3 through the bridge */
135 i2c_reg_write(0x73, /* addr */
137 0x04); /* val = bus 3 */
148 /* Deselect bus 3 on the bridge */
153 /* select fan2 through the bridge */
154 i2c_reg_write(0x73, /* addr */
156 0x02); /* val = bus 4 */
167 /* Deselect bus 2 on the bridge */
172 /* select fan1 through the bridge */
173 i2c_reg_write(0x73, /* addr */
175 0x01); /* val = bus 0 */
186 /* Deselect bus 1 on the bridge */
198 /*************************************************************************
203 ************************************************************************/
204 phys_size_t
initdram (int board_type
)
208 #if defined(CONFIG_SPD_EEPROM)
209 dram_size
= spd_sdram ();
211 dram_size
= fixed_sdram ();
217 /*************************************************************************
221 ************************************************************************/
222 #if defined(CONFIG_SYS_DRAM_TEST)
225 uint
*pstart
= (uint
*) CONFIG_SYS_MEMTEST_START
;
226 uint
*pend
= (uint
*) CONFIG_SYS_MEMTEST_END
;
229 printf("Testing SDRAM: ");
230 for (p
= pstart
; p
< pend
; p
++)
233 for (p
= pstart
; p
< pend
; p
++) {
234 if (*p
!= 0xaaaaaaaa) {
235 printf ("SDRAM test fails at: %08x\n", (uint
) p
);
240 for (p
= pstart
; p
< pend
; p
++)
243 for (p
= pstart
; p
< pend
; p
++) {
244 if (*p
!= 0x55555555) {
245 printf ("SDRAM test fails at: %08x\n", (uint
) p
);
255 #if !defined(CONFIG_SPD_EEPROM)
256 /*************************************************************************
257 * fixed sdram init -- doesn't use serial presence detect.
259 * Assumes: 128 MB, non-ECC, non-registered
262 ************************************************************************/
263 long int fixed_sdram (void)
267 /*--------------------------------------------------------------------
269 *------------------------------------------------------------------*/
270 mtsdram (SDRAM0_UABBA
, 0x00000000); /* ubba=0 (default) */
271 mtsdram (SDRAM0_SLIO
, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
272 mtsdram (SDRAM0_DEVOPT
, 0x00000000); /* dll=0 ds=0 (normal) */
273 mtsdram (SDRAM0_WDDCTR
, 0x00000000); /* wrcp=0 dcd=0 */
274 mtsdram (SDRAM0_CLKTR
, 0x40000000); /* clkp=1 (90 deg wr) dcdt=0 */
276 /*--------------------------------------------------------------------
277 * Setup for board-specific specific mem
278 *------------------------------------------------------------------*/
280 * Following for CAS Latency = 2.5 @ 133 MHz PLB
282 mtsdram (SDRAM0_B0CR
, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
283 mtsdram (SDRAM0_TR0
, 0x410a4012); /* WR=2 WD=1 CL=2.5 PA=3 CP=4 LD=2 */
285 mtsdram (SDRAM0_TR1
, 0x8080082f); /* SS=T2 SL=STAGE 3 CD=1 CT=0x02f */
286 mtsdram (SDRAM0_RTR
, 0x08200000); /* Rate 15.625 ns @ 133 MHz PLB */
287 mtsdram (SDRAM0_CFG1
, 0x00000000); /* Self-refresh exit, disable PM */
288 udelay (400); /* Delay 200 usecs (min) */
290 /*--------------------------------------------------------------------
291 * Enable the controller, then wait for DCEN to complete
292 *------------------------------------------------------------------*/
293 mtsdram (SDRAM0_CFG0
, 0x86000000); /* DCEN=1, PMUD=1, 64-bit */
295 mfsdram (SDRAM0_MCSTS
, reg
);
296 if (reg
& 0x80000000)
300 return (128 * 1024 * 1024); /* 128 MB */
302 #endif /* !defined(CONFIG_SPD_EEPROM) */
304 /*************************************************************************
307 * Get the ethernet MAC address for the management ethernet from the
308 * strap EEPROM. Note that is the BASE address for the range of
309 * external ethernet MACs on the board. The base + 31 is the actual
312 ************************************************************************/
314 void board_get_enetaddr(int macaddr_idx
, uchar
*enet
)
318 unsigned char buff
[0x100], *cp
;
320 if (0 == macaddr_idx
) {
325 /* Read 256 bytes in EEPROM */
326 i2c_read (0x50, 0, 1, buff
, 0x100);
330 for (i
= 0; i
< 6; i
++,cp
++)
333 memcpy(&tmp
, &enet
[4], 2);
335 memcpy(&enet
[4], &tmp
, 2);
343 if (1 == sbcommon_get_master() ) {
344 /* Master/Primary card */
347 /* Slave/Secondary card */
357 * Returns 1 if keys pressed to start the power-on long-running tests
358 * Called from board_init_f().
360 int post_hotkeys_pressed(void)