3 * John Otken, jotken@softadvances.com
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/processor.h>
28 #include <spd_sdram.h>
31 DECLARE_GLOBAL_DATA_PTR;
33 extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
36 /*************************************************************************
37 * int board_early_init_f()
39 ************************************************************************/
40 int board_early_init_f(void)
42 volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
44 mtebc( pb0ap, 0x03800000 ); /* set chip selects */
45 mtebc( pb0cr, 0xffc58000 ); /* ebc0_b0cr, 4MB at 0xffc00000 CS0 */
46 mtebc( pb1ap, 0x03800000 );
47 mtebc( pb1cr, 0xff018000 ); /* ebc0_b1cr, 1MB at 0xff000000 CS1 */
48 mtebc( pb2ap, 0x03800000 );
49 mtebc( pb2cr, 0xff838000 ); /* ebc0_b2cr, 2MB at 0xff800000 CS2 */
51 mtdcr( uic1sr, 0xffffffff ); /* Clear all interrupts */
52 mtdcr( uic1er, 0x00000000 ); /* disable all interrupts */
53 mtdcr( uic1cr, 0x00000000 ); /* Set Critical / Non Critical interrupts */
54 mtdcr( uic1pr, 0x7fff83ff ); /* Set Interrupt Polarities */
55 mtdcr( uic1tr, 0x001f8000 ); /* Set Interrupt Trigger Levels */
56 mtdcr( uic1vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
57 mtdcr( uic1sr, 0x00000000 ); /* clear all interrupts */
58 mtdcr( uic1sr, 0xffffffff );
60 mtdcr( uic0sr, 0xffffffff ); /* Clear all interrupts */
61 mtdcr( uic0er, 0x00000000 ); /* disable all interrupts excepted cascade */
62 mtdcr( uic0cr, 0x00000001 ); /* Set Critical / Non Critical interrupts */
63 mtdcr( uic0pr, 0xffffffff ); /* Set Interrupt Polarities */
64 mtdcr( uic0tr, 0x01000004 ); /* Set Interrupt Trigger Levels */
65 mtdcr( uic0vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
66 mtdcr( uic0sr, 0x00000000 ); /* clear all interrupts */
67 mtdcr( uic0sr, 0xffffffff );
69 x->ethuart &= ~EPLD2_RESET_ETH_N; /* put Ethernet+PHY in reset */
75 /*************************************************************************
78 ************************************************************************/
81 volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
82 x->ethuart |= EPLD2_RESET_ETH_N; /* take Ethernet+PHY out of reset */
88 /*************************************************************************
91 ************************************************************************/
94 char *s = getenv("serial#");
96 printf("Board: Luan - AMCC PPC440SP Evaluation Board");
108 /*************************************************************************
109 * long int fixed_sdram()
111 ************************************************************************/
112 static long int fixed_sdram(void)
113 { /* DDR2 init from BDI2000 script */
114 mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - zero DCEN bit */
115 mtdcr( 0x11, 0x84000000 );
116 mtdcr( 0x10, 0x00000020 ); /* MCIF0_MCOPT1 - no ECC, 64 bits, 4 banks, DDR2 */
117 mtdcr( 0x11, 0x2D122000 );
118 mtdcr( 0x10, 0x00000026 ); /* MCIF0_CODT - die termination on */
119 mtdcr( 0x11, 0x00800026 );
120 mtdcr( 0x10, 0x00000081 ); /* MCIF0_WRDTR - Write DQS Adv 90 + Fractional DQS Delay */
121 mtdcr( 0x11, 0x82000800 );
122 mtdcr( 0x10, 0x00000080 ); /* MCIF0_CLKTR - advance addr clock by 180 deg */
123 mtdcr( 0x11, 0x80000000 );
124 mtdcr( 0x10, 0x00000040 ); /* MCIF0_MB0CF - turn on CS0, N x 10 coll */
125 mtdcr( 0x11, 0x00000201 );
126 mtdcr( 0x10, 0x00000044 ); /* MCIF0_MB1CF - turn on CS0, N x 10 coll */
127 mtdcr( 0x11, 0x00000201 );
128 mtdcr( 0x10, 0x00000030 ); /* MCIF0_RTR - refresh every 7.8125uS */
129 mtdcr( 0x11, 0x08200000 );
130 mtdcr( 0x10, 0x00000085 ); /* MCIF0_SDTR1 - timing register 1 */
131 mtdcr( 0x11, 0x80201000 );
132 mtdcr( 0x10, 0x00000086 ); /* MCIF0_SDTR2 - timing register 2 */
133 mtdcr( 0x11, 0x42103242 );
134 mtdcr( 0x10, 0x00000087 ); /* MCIF0_SDTR3 - timing register 3 */
135 mtdcr( 0x11, 0x0C100D14 );
136 mtdcr( 0x10, 0x00000088 ); /* MCIF0_MMODE - CAS is 4 cycles */
137 mtdcr( 0x11, 0x00000642 );
138 mtdcr( 0x10, 0x00000089 ); /* MCIF0_MEMODE - diff DQS disabled */
139 mtdcr( 0x11, 0x00000400 ); /* ODT term disabled */
141 mtdcr( 0x10, 0x00000050 ); /* MCIF0_INITPLR0 - NOP */
142 mtdcr( 0x11, 0x81b80000 );
143 mtdcr( 0x10, 0x00000051 ); /* MCIF0_INITPLR1 - PRE */
144 mtdcr( 0x11, 0x82100400 );
145 mtdcr( 0x10, 0x00000052 ); /* MCIF0_INITPLR2 - EMR2 */
146 mtdcr( 0x11, 0x80820000 );
147 mtdcr( 0x10, 0x00000053 ); /* MCIF0_INITPLR3 - EMR3 */
148 mtdcr( 0x11, 0x80830000 );
149 mtdcr( 0x10, 0x00000054 ); /* MCIF0_INITPLR4 - EMR DLL ENABLE */
150 mtdcr( 0x11, 0x80810000 );
151 mtdcr( 0x10, 0x00000055 ); /* MCIF0_INITPLR5 - MR DLL RESET */
152 mtdcr( 0x11, 0x80800542 );
153 mtdcr( 0x10, 0x00000056 ); /* MCIF0_INITPLR6 - PRE */
154 mtdcr( 0x11, 0x82100400 );
155 mtdcr( 0x10, 0x00000057 ); /* MCIF0_INITPLR7 - refresh */
156 mtdcr( 0x11, 0x99080000 );
157 mtdcr( 0x10, 0x00000058 ); /* MCIF0_INITPLR8 */
158 mtdcr( 0x11, 0x99080000 );
159 mtdcr( 0x10, 0x00000059 ); /* MCIF0_INITPLR9 */
160 mtdcr( 0x11, 0x99080000 );
161 mtdcr( 0x10, 0x0000005A ); /* MCIF0_INITPLR10 */
162 mtdcr( 0x11, 0x99080000 );
163 mtdcr( 0x10, 0x0000005B ); /* MCIF0_INITPLR11 - MR */
164 mtdcr( 0x11, 0x80800442 );
165 mtdcr( 0x10, 0x0000005C ); /* MCIF0_INITPLR12 - EMR OCD Default */
166 mtdcr( 0x11, 0x80810380 );
167 mtdcr( 0x10, 0x0000005D ); /* MCIF0_INITPLR13 - EMR OCD exit */
168 mtdcr( 0x11, 0x80810000 );
171 mtdcr( 0x10, 0x00000021 ); /* MCIF0_MCOPT2 - execute preloaded init */
172 mtdcr( 0x11, 0x28000000 ); /* set DC_EN */
175 mtdcr( 0x40, 0x0000F800 ); /* MQ0_B0BAS: base addr 00000000 / 256MB */
176 mtdcr( 0x41, 0x1000F800 ); /* MQ0_B1BAS: base addr 10000000 / 256MB */
178 mtdcr( 0x10, 0x00000078 ); /* MCIF0_RDCC - auto set read stage */
179 mtdcr( 0x11, 0x00000000 );
180 mtdcr( 0x10, 0x00000070 ); /* MCIF0_RQDC - read DQS delay control */
181 mtdcr( 0x11, 0x8000003A ); /* enabled, frac DQS delay */
182 mtdcr( 0x10, 0x00000074 ); /* MCIF0_RFDC - two clock feedback delay */
183 mtdcr( 0x11, 0x00000200 );
189 /*************************************************************************
192 ************************************************************************/
193 long int initdram( int board_type )
197 #if defined(CONFIG_SPD_EEPROM)
198 dram_size = spd_sdram (0);
200 dram_size = fixed_sdram ();
207 /*************************************************************************
210 ************************************************************************/
211 #if defined(CFG_DRAM_TEST)
214 unsigned long *mem = (unsigned long *) 0;
215 const unsigned long kend = (1024 / sizeof(unsigned long));
220 for (k = 0; k < CFG_KBYTES_SDRAM;
221 ++k, mem += (1024 / sizeof(unsigned long))) {
222 if ((k & 1023) == 0) {
223 printf("%3d MB\r", k / 1024);
226 memset(mem, 0xaaaaaaaa, 1024);
227 for (n = 0; n < kend; ++n) {
228 if (mem[n] != 0xaaaaaaaa) {
229 printf("SDRAM test fails at: %08x\n",
235 memset(mem, 0x55555555, 1024);
236 for (n = 0; n < kend; ++n) {
237 if (mem[n] != 0x55555555) {
238 printf("SDRAM test fails at: %08x\n",
244 printf("SDRAM test passes\n");
251 /*************************************************************************
254 * This routine is called just prior to registering the hose and gives
255 * the board the opportunity to check things. Returning a value of zero
256 * indicates that things are bad & PCI initialization should be aborted.
258 * Different boards may wish to customize the pci controller structure
259 * (add regions, override default access routines, etc) or perform
260 * certain pre-initialization actions.
262 ************************************************************************/
263 #if defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT)
264 int pci_pre_init( struct pci_controller *hose )
268 /*--------------------------------------------------------------------------+
269 * The luan board is always configured as the host & requires the
270 * PCI arbiter to be enabled.
271 *--------------------------------------------------------------------------*/
272 mfsdr(sdr_sdstp1, strap);
273 if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) {
274 printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
281 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_PRE_INIT) */
284 /*************************************************************************
287 * The bootstrap configuration provides default settings for the pci
288 * inbound map (PIM). But the bootstrap config choices are limited and
289 * may not be sufficient for a given board.
291 ************************************************************************/
292 #if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
293 void pci_target_init(struct pci_controller *hose)
295 /*--------------------------------------------------------------------------+
297 *--------------------------------------------------------------------------*/
298 out32r( PCIX0_PIM0SA, 0 ); /* disable */
299 out32r( PCIX0_PIM1SA, 0 ); /* disable */
300 out32r( PCIX0_PIM2SA, 0 ); /* disable */
301 out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
303 /*--------------------------------------------------------------------------+
304 * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
305 * options to not support sizes such as 128/256 MB.
306 *--------------------------------------------------------------------------*/
307 out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
308 out32r( PCIX0_PIM0LAH, 0 );
309 out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
311 out32r( PCIX0_BAR0, 0 );
313 /*--------------------------------------------------------------------------+
314 * Program the board's subsystem id/vendor id
315 *--------------------------------------------------------------------------*/
316 out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
317 out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
319 out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
321 #endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
324 /*************************************************************************
327 * This routine is called to determine if a pci scan should be
328 * performed. With various hardware environments (especially cPCI and
329 * PPMC) it's insufficient to depend on the state of the arbiter enable
330 * bit in the strap register, or generic host/adapter assumptions.
332 * Rather than hard-code a bad assumption in the general 440 code, the
333 * 440 pci code requires the board to decide at runtime.
335 * Return 0 for adapter mode, non-zero for host (monarch) mode.
338 ************************************************************************/
339 #if defined(CONFIG_PCI)
340 int is_pci_host(struct pci_controller *hose)
344 #endif /* defined(CONFIG_PCI) */
347 /*************************************************************************
350 * This routine is called to reset (keep alive) the watchdog timer
352 ************************************************************************/
353 #if defined(CONFIG_HW_WATCHDOG)
354 void hw_watchdog_reset(void)
360 /*************************************************************************
363 ************************************************************************/
364 static int on_off( const char *s )
366 if (strcmp(s, "on") == 0) {
368 } else if (strcmp(s, "off") == 0) {
375 /*************************************************************************
376 * void l2cache_disable()
378 ************************************************************************/
379 static void l2cache_disable(void)
381 mtdcr( l2_cache_cfg, 0 );
385 /*************************************************************************
386 * void l2cache_enable()
388 ************************************************************************/
389 static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */
391 mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */
393 mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */
395 mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */
397 while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */
399 mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */
401 mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */
403 mtdcr( l2_cache_snp0, 0 ); /* snoop registers */
404 mtdcr( l2_cache_snp1, 0 );
406 __asm__ volatile ("sync"); /* msync */
408 mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */
410 __asm__ volatile ("sync");
414 /*************************************************************************
415 * int l2cache_status()
417 ************************************************************************/
418 static int l2cache_status(void)
420 return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0;
424 /*************************************************************************
427 ************************************************************************/
428 int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
431 case 2: /* on / off */
432 switch (on_off(argv[1])) {
433 case 0: l2cache_disable();
435 case 1: l2cache_enable();
439 case 1: /* get status */
440 printf ("L2 Cache is %s\n",
441 l2cache_status() ? "ON" : "OFF");
444 printf ("Usage:\n%s\n", cmdtp->usage);
453 l2cache, 2, 1, do_l2cache,
454 "l2cache - enable or disable L2 cache\n",
456 " - enable or disable L2 cache\n"