blob: 1bd7efa0baebaa7bdd8ca86e6648d4ea5d42d0a3 [file] [log] [blame]
Stefan Roese99644742005-11-29 18:18:21 +01001/*
2 * (C) Copyright 2005
3 * John Otken, jotken@softadvances.com
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <ppc4xx.h>
27#include <asm/processor.h>
28#include <spd_sdram.h>
29#include "epld.h"
30
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
Stefan Roese99644742005-11-29 18:18:21 +010032
33extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
34
35
36/*************************************************************************
37 * int board_early_init_f()
38 *
39 ************************************************************************/
40int board_early_init_f(void)
41{
Stefan Roese99644742005-11-29 18:18:21 +010042 mtebc( pb0ap, 0x03800000 ); /* set chip selects */
43 mtebc( pb0cr, 0xffc58000 ); /* ebc0_b0cr, 4MB at 0xffc00000 CS0 */
44 mtebc( pb1ap, 0x03800000 );
45 mtebc( pb1cr, 0xff018000 ); /* ebc0_b1cr, 1MB at 0xff000000 CS1 */
46 mtebc( pb2ap, 0x03800000 );
47 mtebc( pb2cr, 0xff838000 ); /* ebc0_b2cr, 2MB at 0xff800000 CS2 */
48
49 mtdcr( uic1sr, 0xffffffff ); /* Clear all interrupts */
50 mtdcr( uic1er, 0x00000000 ); /* disable all interrupts */
51 mtdcr( uic1cr, 0x00000000 ); /* Set Critical / Non Critical interrupts */
52 mtdcr( uic1pr, 0x7fff83ff ); /* Set Interrupt Polarities */
53 mtdcr( uic1tr, 0x001f8000 ); /* Set Interrupt Trigger Levels */
54 mtdcr( uic1vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
55 mtdcr( uic1sr, 0x00000000 ); /* clear all interrupts */
56 mtdcr( uic1sr, 0xffffffff );
57
58 mtdcr( uic0sr, 0xffffffff ); /* Clear all interrupts */
59 mtdcr( uic0er, 0x00000000 ); /* disable all interrupts excepted cascade */
60 mtdcr( uic0cr, 0x00000001 ); /* Set Critical / Non Critical interrupts */
61 mtdcr( uic0pr, 0xffffffff ); /* Set Interrupt Polarities */
62 mtdcr( uic0tr, 0x01000004 ); /* Set Interrupt Trigger Levels */
63 mtdcr( uic0vr, 0x00000001 ); /* Set Vect base=0,INT31 Highest priority */
64 mtdcr( uic0sr, 0x00000000 ); /* clear all interrupts */
65 mtdcr( uic0sr, 0xffffffff );
66
Stefan Roese99644742005-11-29 18:18:21 +010067 return 0;
68}
69
70
71/*************************************************************************
72 * int misc_init_r()
73 *
74 ************************************************************************/
75int misc_init_r(void)
76{
77 volatile epld_t *x = (epld_t *) CFG_EPLD_BASE;
Grzegorz Bernacki2462bbd2007-10-01 09:51:50 +020078
79 /* set modes of operation */
80 x->ethuart |= EPLD2_ETH_MODE_10 | EPLD2_ETH_MODE_100 |
81 EPLD2_ETH_MODE_1000 | EPLD2_ETH_DUPLEX_MODE;
82 /* clear ETHERNET_AUTO_NEGO bit to turn on autonegotiation */
83 x->ethuart &= ~EPLD2_ETH_AUTO_NEGO;
84
85 /* put Ethernet+PHY in reset */
86 x->ethuart &= ~EPLD2_RESET_ETH_N;
87 udelay(10000);
88 /* take Ethernet+PHY out of reset */
89 x->ethuart |= EPLD2_RESET_ETH_N;
Stefan Roese99644742005-11-29 18:18:21 +010090
91 return 0;
92}
93
94
95/*************************************************************************
96 * int checkboard()
97 *
98 ************************************************************************/
99int checkboard(void)
100{
101 char *s = getenv("serial#");
102
103 printf("Board: Luan - AMCC PPC440SP Evaluation Board");
104
105 if (s != NULL) {
106 puts(", serial# ");
107 puts(s);
108 }
109 putc('\n');
110
111 return 0;
112}
113
Stefan Roeseac4d06e2007-07-16 10:01:38 +0200114/*
115 * Override the default functions in cpu/ppc4xx/44x_spd_ddr2.c with
116 * board specific values.
117 */
118u32 ddr_clktr(u32 default_val) {
119 return (SDRAM_CLKTR_CLKP_180_DEG_ADV);
120}
Stefan Roese99644742005-11-29 18:18:21 +0100121
122/*************************************************************************
Stefan Roese99644742005-11-29 18:18:21 +0100123 * int testdram()
124 *
125 ************************************************************************/
126#if defined(CFG_DRAM_TEST)
127int testdram(void)
128{
129 unsigned long *mem = (unsigned long *) 0;
130 const unsigned long kend = (1024 / sizeof(unsigned long));
131 unsigned long k, n;
132
133 mtmsr(0);
134
135 for (k = 0; k < CFG_KBYTES_SDRAM;
136 ++k, mem += (1024 / sizeof(unsigned long))) {
137 if ((k & 1023) == 0) {
138 printf("%3d MB\r", k / 1024);
139 }
140
141 memset(mem, 0xaaaaaaaa, 1024);
142 for (n = 0; n < kend; ++n) {
143 if (mem[n] != 0xaaaaaaaa) {
144 printf("SDRAM test fails at: %08x\n",
145 (uint) & mem[n]);
146 return 1;
147 }
148 }
149
150 memset(mem, 0x55555555, 1024);
151 for (n = 0; n < kend; ++n) {
152 if (mem[n] != 0x55555555) {
153 printf("SDRAM test fails at: %08x\n",
154 (uint) & mem[n]);
155 return 1;
156 }
157 }
158 }
159 printf("SDRAM test passes\n");
160
161 return 0;
162}
163#endif
164
165
166/*************************************************************************
167 * pci_pre_init
168 *
169 * This routine is called just prior to registering the hose and gives
170 * the board the opportunity to check things. Returning a value of zero
171 * indicates that things are bad & PCI initialization should be aborted.
172 *
173 * Different boards may wish to customize the pci controller structure
174 * (add regions, override default access routines, etc) or perform
175 * certain pre-initialization actions.
176 *
177 ************************************************************************/
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200178#if defined(CONFIG_PCI)
Stefan Roese99644742005-11-29 18:18:21 +0100179int pci_pre_init( struct pci_controller *hose )
180{
181 unsigned long strap;
182
183 /*--------------------------------------------------------------------------+
184 * The luan board is always configured as the host & requires the
185 * PCI arbiter to be enabled.
186 *--------------------------------------------------------------------------*/
187 mfsdr(sdr_sdstp1, strap);
188 if( (strap & SDR0_SDSTP1_PAE_MASK) == 0 ) {
189 printf("PCI: SDR0_STRP1[%08lX] - PCI Arbiter disabled.\n",strap);
190
191 return 0;
192 }
193
194 return 1;
195}
Stefan Roese54ef7fd2007-06-25 15:57:39 +0200196#endif /* defined(CONFIG_PCI) */
Stefan Roese99644742005-11-29 18:18:21 +0100197
198
199/*************************************************************************
200 * pci_target_init
201 *
202 * The bootstrap configuration provides default settings for the pci
203 * inbound map (PIM). But the bootstrap config choices are limited and
204 * may not be sufficient for a given board.
205 *
206 ************************************************************************/
207#if defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT)
208void pci_target_init(struct pci_controller *hose)
209{
Stefan Roese99644742005-11-29 18:18:21 +0100210 /*--------------------------------------------------------------------------+
211 * Disable everything
212 *--------------------------------------------------------------------------*/
213 out32r( PCIX0_PIM0SA, 0 ); /* disable */
214 out32r( PCIX0_PIM1SA, 0 ); /* disable */
215 out32r( PCIX0_PIM2SA, 0 ); /* disable */
216 out32r( PCIX0_EROMBA, 0 ); /* disable expansion rom */
217
218 /*--------------------------------------------------------------------------+
219 * Map all of SDRAM to PCI address 0x0000_0000. Note that the 440 strapping
220 * options to not support sizes such as 128/256 MB.
221 *--------------------------------------------------------------------------*/
222 out32r( PCIX0_PIM0LAL, CFG_SDRAM_BASE );
223 out32r( PCIX0_PIM0LAH, 0 );
224 out32r( PCIX0_PIM0SA, ~(gd->ram_size - 1) | 1 );
225
226 out32r( PCIX0_BAR0, 0 );
227
228 /*--------------------------------------------------------------------------+
229 * Program the board's subsystem id/vendor id
230 *--------------------------------------------------------------------------*/
231 out16r( PCIX0_SBSYSVID, CFG_PCI_SUBSYS_VENDORID );
232 out16r( PCIX0_SBSYSID, CFG_PCI_SUBSYS_DEVICEID );
233
234 out16r( PCIX0_CMD, in16r(PCIX0_CMD) | PCI_COMMAND_MEMORY );
235}
236#endif /* defined(CONFIG_PCI) && defined(CFG_PCI_TARGET_INIT) */
237
238
239/*************************************************************************
240 * is_pci_host
241 *
242 * This routine is called to determine if a pci scan should be
243 * performed. With various hardware environments (especially cPCI and
244 * PPMC) it's insufficient to depend on the state of the arbiter enable
245 * bit in the strap register, or generic host/adapter assumptions.
246 *
247 * Rather than hard-code a bad assumption in the general 440 code, the
248 * 440 pci code requires the board to decide at runtime.
249 *
250 * Return 0 for adapter mode, non-zero for host (monarch) mode.
251 *
252 *
253 ************************************************************************/
254#if defined(CONFIG_PCI)
255int is_pci_host(struct pci_controller *hose)
256{
257 return 1;
258}
259#endif /* defined(CONFIG_PCI) */
260
261
262/*************************************************************************
263 * hw_watchdog_reset
264 *
265 * This routine is called to reset (keep alive) the watchdog timer
266 *
267 ************************************************************************/
268#if defined(CONFIG_HW_WATCHDOG)
269void hw_watchdog_reset(void)
270{
271}
272#endif
273
274
275/*************************************************************************
276 * int on_off()
277 *
278 ************************************************************************/
279static int on_off( const char *s )
280{
281 if (strcmp(s, "on") == 0) {
282 return 1;
283 } else if (strcmp(s, "off") == 0) {
284 return 0;
285 }
286 return -1;
287}
288
289
290/*************************************************************************
291 * void l2cache_disable()
292 *
293 ************************************************************************/
294static void l2cache_disable(void)
295{
296 mtdcr( l2_cache_cfg, 0 );
297}
298
299
300/*************************************************************************
301 * void l2cache_enable()
302 *
303 ************************************************************************/
304static void l2cache_enable(void) /* see p258 7.4.1 Enabling L2 Cache */
305{
306 mtdcr( l2_cache_cfg, 0x80000000 ); /* enable L2_MODE L2_CFG[L2M] */
307
308 mtdcr( l2_cache_addr, 0 ); /* set L2_ADDR with all zeros */
309
310 mtdcr( l2_cache_cmd, 0x80000000 ); /* issue HCLEAR command via L2_CMD */
311
312 while (!(mfdcr( l2_cache_stat ) & 0x80000000 )) ;; /* poll L2_SR for completion */
313
314 mtdcr( l2_cache_cmd, 0x10000000 ); /* clear cache errors L2_CMD[CCP] */
315
316 mtdcr( l2_cache_cmd, 0x08000000 ); /* clear tag errors L2_CMD[CTE] */
317
318 mtdcr( l2_cache_snp0, 0 ); /* snoop registers */
319 mtdcr( l2_cache_snp1, 0 );
320
321 __asm__ volatile ("sync"); /* msync */
322
323 mtdcr( l2_cache_cfg, 0xe0000000 ); /* inst and data use L2 */
324
325 __asm__ volatile ("sync");
326}
327
328
329/*************************************************************************
330 * int l2cache_status()
331 *
332 ************************************************************************/
333static int l2cache_status(void)
334{
335 return (mfdcr( l2_cache_cfg ) & 0x60000000) != 0;
336}
337
338
339/*************************************************************************
340 * int do_l2cache()
341 *
342 ************************************************************************/
343int do_l2cache( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] )
344{
345 switch (argc) {
346 case 2: /* on / off */
347 switch (on_off(argv[1])) {
348 case 0: l2cache_disable();
349 break;
350 case 1: l2cache_enable();
351 break;
352 }
353 /* FALL TROUGH */
354 case 1: /* get status */
355 printf ("L2 Cache is %s\n",
356 l2cache_status() ? "ON" : "OFF");
357 return 0;
358 default:
359 printf ("Usage:\n%s\n", cmdtp->usage);
360 return 1;
361 }
362
363 return 0;
364}
365
366
367U_BOOT_CMD(
368 l2cache, 2, 1, do_l2cache,
369 "l2cache - enable or disable L2 cache\n",
370 "[on, off]\n"
371 " - enable or disable L2 cache\n"
372 );