blob: f90a75124a9d2e44b5d43c5b5262ba75b246e61a [file] [log] [blame]
roy zang4978adf2006-11-02 18:59:15 +08001/*
2 * (C) Copyright 2005 Freescale Semiconductor, Inc.
3 *
4 * Roy Zang <tie-fei.zang@freescale.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 *
24 * modifications for the Tsi108 Emul Board by avb@Tundra
25 */
26
27/*
28 * board support/init functions for the
29 * Freescale MPC7448 HPC2 (High-Performance Computing 2 Platform).
30 */
31
32#include <common.h>
33#include <74xx_7xx.h>
34#if defined(CONFIG_OF_FLAT_TREE)
35#include <ft_build.h>
36extern void ft_cpu_setup(void *blob, bd_t *bd);
37#endif
38
39#undef DEBUG
40
41extern void flush_data_cache(void);
42extern void invalidate_l1_instruction_cache(void);
43extern void tsi108_init_f(void);
44
45int display_mem_map(void);
46
47void after_reloc(ulong dest_addr)
48{
49 DECLARE_GLOBAL_DATA_PTR;
50
51 /*
52 * Jump to the main U-Boot board init code
53 */
54 board_init_r((gd_t *) gd, dest_addr);
55 /* NOTREACHED */
56}
57
58/*
59 * Check Board Identity:
60 *
61 * report board type
62 */
63
64int checkboard(void)
65{
66 int l_type = 0;
67
68 printf("BOARD: %s\n", CFG_BOARD_NAME);
69 return (l_type);
70}
71
72/*
73 * Read Processor ID:
74 *
75 * report calling processor number
76 */
77
78int read_pid(void)
79{
80 return 0; /* we are on single CPU platform for a while */
81}
82
83long int dram_size(int board_type)
84{
85 return 0x20000000; /* 256M bytes */
86}
87
88long int initdram(int board_type)
89{
90 return dram_size(board_type);
91}
92
93/* DRAM check routines copied from gw8260 */
94
95#if defined (CFG_DRAM_TEST)
96
97/*********************************************************************/
98/* NAME: move64() - moves a double word (64-bit) */
99/* */
100/* DESCRIPTION: */
101/* this function performs a double word move from the data at */
102/* the source pointer to the location at the destination pointer. */
103/* */
104/* INPUTS: */
105/* unsigned long long *src - pointer to data to move */
106/* */
107/* OUTPUTS: */
108/* unsigned long long *dest - pointer to locate to move data */
109/* */
110/* RETURNS: */
111/* None */
112/* */
113/* RESTRICTIONS/LIMITATIONS: */
114/* May cloober fr0. */
115/* */
116/*********************************************************************/
117static void move64(unsigned long long *src, unsigned long long *dest)
118{
119 asm("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
120 "stfd 0, 0(4)" /* *dest = fpr0 */
121 : : :"fr0"); /* Clobbers fr0 */
122 return;
123}
124
125#if defined (CFG_DRAM_TEST_DATA)
126
127unsigned long long pattern[] = {
128 0xaaaaaaaaaaaaaaaaULL,
129 0xccccccccccccccccULL,
130 0xf0f0f0f0f0f0f0f0ULL,
131 0xff00ff00ff00ff00ULL,
132 0xffff0000ffff0000ULL,
133 0xffffffff00000000ULL,
134 0x00000000ffffffffULL,
135 0x0000ffff0000ffffULL,
136 0x00ff00ff00ff00ffULL,
137 0x0f0f0f0f0f0f0f0fULL,
138 0x3333333333333333ULL,
139 0x5555555555555555ULL
140};
141
142/*********************************************************************/
143/* NAME: mem_test_data() - test data lines for shorts and opens */
144/* */
145/* DESCRIPTION: */
146/* Tests data lines for shorts and opens by forcing adjacent data */
147/* to opposite states. Because the data lines could be routed in */
148/* an arbitrary manner the must ensure test patterns ensure that */
149/* every case is tested. By using the following series of binary */
150/* patterns every combination of adjacent bits is test regardless */
151/* of routing. */
152/* */
153/* ...101010101010101010101010 */
154/* ...110011001100110011001100 */
155/* ...111100001111000011110000 */
156/* ...111111110000000011111111 */
157/* */
158/* Carrying this out, gives us six hex patterns as follows: */
159/* */
160/* 0xaaaaaaaaaaaaaaaa */
161/* 0xcccccccccccccccc */
162/* 0xf0f0f0f0f0f0f0f0 */
163/* 0xff00ff00ff00ff00 */
164/* 0xffff0000ffff0000 */
165/* 0xffffffff00000000 */
166/* */
167/* The number test patterns will always be given by: */
168/* */
169/* log(base 2)(number data bits) = log2 (64) = 6 */
170/* */
171/* To test for short and opens to other signals on our boards. we */
172/* simply */
173/* test with the 1's complemnt of the paterns as well. */
174/* */
175/* OUTPUTS: */
176/* Displays failing test pattern */
177/* */
178/* RETURNS: */
179/* 0 - Passed test */
180/* 1 - Failed test */
181/* */
182/* RESTRICTIONS/LIMITATIONS: */
183/* Assumes only one one SDRAM bank */
184/* */
185/*********************************************************************/
186int mem_test_data(void)
187{
188 unsigned long long *pmem = (unsigned long long *)CFG_MEMTEST_START;
189 unsigned long long temp64;
190 int num_patterns = sizeof(pattern) / sizeof(pattern[0]);
191 int i;
192 unsigned int hi, lo;
193
194 for (i = 0; i < num_patterns; i++) {
195 move64(&(pattern[i]), pmem);
196 move64(pmem, &temp64);
197
198 /* hi = (temp64>>32) & 0xffffffff; */
199 /* lo = temp64 & 0xffffffff; */
200 /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
201
202 hi = (pattern[i] >> 32) & 0xffffffff;
203 lo = pattern[i] & 0xffffffff;
204 /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
205
206 if (temp64 != pattern[i]) {
207 printf("\n Data Test Failed, pattern 0x%08x%08x",
208 hi, lo);
209 return 1;
210 }
211 }
212
213 return 0;
214}
215#endif /* CFG_DRAM_TEST_DATA */
216
217#if defined (CFG_DRAM_TEST_ADDRESS)
218/*********************************************************************/
219/* NAME: mem_test_address() - test address lines */
220/* */
221/* DESCRIPTION: */
222/* This function performs a test to verify that each word im */
223/* memory is uniquly addressable. The test sequence is as follows: */
224/* */
225/* 1) write the address of each word to each word. */
226/* 2) verify that each location equals its address */
227/* */
228/* OUTPUTS: */
229/* Displays failing test pattern and address */
230/* */
231/* RETURNS: */
232/* 0 - Passed test */
233/* 1 - Failed test */
234/* */
235/* RESTRICTIONS/LIMITATIONS: */
236/* */
237/* */
238/*********************************************************************/
239int mem_test_address(void)
240{
241 volatile unsigned int *pmem =
242 (volatile unsigned int *)CFG_MEMTEST_START;
243 const unsigned int size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 4;
244 unsigned int i;
245
246 /* write address to each location */
247 for (i = 0; i < size; i++) {
248 pmem[i] = i;
249 }
250
251 /* verify each loaction */
252 for (i = 0; i < size; i++) {
253 if (pmem[i] != i) {
254 printf("\n Address Test Failed at 0x%x", i);
255 return 1;
256 }
257 }
258 return 0;
259}
260#endif /* CFG_DRAM_TEST_ADDRESS */
261
262#if defined (CFG_DRAM_TEST_WALK)
263/*********************************************************************/
264/* NAME: mem_march() - memory march */
265/* */
266/* DESCRIPTION: */
267/* Marches up through memory. At each location verifies rmask if */
268/* read = 1. At each location write wmask if write = 1. Displays */
269/* failing address and pattern. */
270/* */
271/* INPUTS: */
272/* volatile unsigned long long * base - start address of test */
273/* unsigned int size - number of dwords(64-bit) to test */
274/* unsigned long long rmask - read verify mask */
275/* unsigned long long wmask - wrtie verify mask */
276/* short read - verifies rmask if read = 1 */
277/* short write - writes wmask if write = 1 */
278/* */
279/* OUTPUTS: */
280/* Displays failing test pattern and address */
281/* */
282/* RETURNS: */
283/* 0 - Passed test */
284/* 1 - Failed test */
285/* */
286/* RESTRICTIONS/LIMITATIONS: */
287/* */
288/* */
289/*********************************************************************/
290int mem_march(volatile unsigned long long *base,
291 unsigned int size,
292 unsigned long long rmask,
293 unsigned long long wmask, short read, short write)
294{
295 unsigned int i;
296 unsigned long long temp;
297 unsigned int hitemp, lotemp, himask, lomask;
298
299 for (i = 0; i < size; i++) {
300 if (read != 0) {
301 /* temp = base[i]; */
302 move64((unsigned long long *)&(base[i]), &temp);
303 if (rmask != temp) {
304 hitemp = (temp >> 32) & 0xffffffff;
305 lotemp = temp & 0xffffffff;
306 himask = (rmask >> 32) & 0xffffffff;
307 lomask = rmask & 0xffffffff;
308
309 printf("\n Walking one's test failed: \
310 address = 0x%08x," "\n\texpected \
311 0x%08x%08x, found 0x%08x%08x", i << 3,\
312 himask, lomask, hitemp, lotemp);
313 return 1;
314 }
315 }
316 if (write != 0) {
317 /* base[i] = wmask; */
318 move64(&wmask, (unsigned long long *)&(base[i]));
319 }
320 }
321 return 0;
322}
323#endif /* CFG_DRAM_TEST_WALK */
324
325/*********************************************************************/
326/* NAME: mem_test_walk() - a simple walking ones test */
327/* */
328/* DESCRIPTION: */
329/* Performs a walking ones through entire physical memory. The */
330/* test uses as series of memory marches, mem_march(), to verify */
331/* and write the test patterns to memory. The test sequence is as */
332/* follows: */
333/* 1) march writing 0000...0001 */
334/* 2) march verifying 0000...0001 , writing 0000...0010 */
335/* 3) repeat step 2 shifting masks left 1 bit each time unitl */
336/* the write mask equals 1000...0000 */
337/* 4) march verifying 1000...0000 */
338/* The test fails if any of the memory marches return a failure. */
339/* */
340/* OUTPUTS: */
341/* Displays which pass on the memory test is executing */
342/* */
343/* RETURNS: */
344/* 0 - Passed test */
345/* 1 - Failed test */
346/* */
347/* RESTRICTIONS/LIMITATIONS: */
348/* */
349/* */
350/*********************************************************************/
351int mem_test_walk(void)
352{
353 unsigned long long mask;
354 volatile unsigned long long *pmem =
355 (volatile unsigned long long *)CFG_MEMTEST_START;
356 const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
357
358 unsigned int i;
359
360 mask = 0x01;
361
362 printf("Initial Pass");
363 mem_march(pmem, size, 0x0, 0x1, 0, 1);
364
365 printf("\b\b\b\b\b\b\b\b\b\b\b\b");
366 printf(" ");
367 printf(" ");
368 printf("\b\b\b\b\b\b\b\b\b\b\b\b");
369
370 for (i = 0; i < 63; i++) {
371 printf("Pass %2d", i + 2);
372 if (mem_march(pmem, size, mask, mask << 1, 1, 1) != 0) {
373 /*printf("mask: 0x%x, pass: %d, ", mask, i); */
374 return 1;
375 }
376 mask = mask << 1;
377 printf("\b\b\b\b\b\b\b");
378 }
379
380 printf("Last Pass");
381 if (mem_march(pmem, size, 0, mask, 0, 1) != 0) {
382 /* printf("mask: 0x%x", mask); */
383 return 1;
384 }
385 printf("\b\b\b\b\b\b\b\b\b");
386 printf(" ");
387 printf("\b\b\b\b\b\b\b\b\b");
388
389 return 0;
390}
391
392/*********************************************************************/
393/* NAME: testdram() - calls any enabled memory tests */
394/* */
395/* DESCRIPTION: */
396/* Runs memory tests if the environment test variables are set to */
397/* 'y'. */
398/* */
399/* INPUTS: */
400/* testdramdata - If set to 'y', data test is run. */
401/* testdramaddress - If set to 'y', address test is run. */
402/* testdramwalk - If set to 'y', walking ones test is run */
403/* */
404/* OUTPUTS: */
405/* None */
406/* */
407/* RETURNS: */
408/* 0 - Passed test */
409/* 1 - Failed test */
410/* */
411/* RESTRICTIONS/LIMITATIONS: */
412/* */
413/* */
414/*********************************************************************/
415int testdram(void)
416{
417 char *s;
418 int rundata, runaddress, runwalk;
419
420 s = getenv("testdramdata");
421 rundata = (s && (*s == 'y')) ? 1 : 0;
422 s = getenv("testdramaddress");
423 runaddress = (s && (*s == 'y')) ? 1 : 0;
424 s = getenv("testdramwalk");
425 runwalk = (s && (*s == 'y')) ? 1 : 0;
426
427/* rundata = 1; */
428/* runaddress = 0; */
429/* runwalk = 0; */
430
431 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
432 printf("Testing RAM from 0x%08x to 0x%08x ... \
433 (don't panic... that will take a moment !!!!)\n", \
434 CFG_MEMTEST_START, CFG_MEMTEST_END);
435 }
436#ifdef CFG_DRAM_TEST_DATA
437 if (rundata == 1) {
438 printf("Test DATA ... ");
439 if (mem_test_data () == 1) {
440 printf("failed \n");
441 return 1;
442 } else
443 printf("ok \n");
444 }
445#endif
446#ifdef CFG_DRAM_TEST_ADDRESS
447 if (runaddress == 1) {
448 printf("Test ADDRESS ... ");
449 if (mem_test_address () == 1) {
450 printf("failed \n");
451 return 1;
452 } else
453 printf("ok \n");
454 }
455#endif
456#ifdef CFG_DRAM_TEST_WALK
457 if (runwalk == 1) {
458 printf("Test WALKING ONEs ... ");
459 if (mem_test_walk() == 1) {
460 printf("failed \n");
461 return 1;
462 } else
463 printf("ok \n");
464 }
465#endif
466 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
467 printf("passed\n");
468 }
469 return 0;
470
471}
472#endif /* CFG_DRAM_TEST */
473
474#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
475void
476ft_board_setup(void *blob, bd_t *bd)
477{
478 u32 *p;
479 int len;
480
481 ft_cpu_setup(blob, bd);
482
483 p = ft_get_prop(blob, "/memory/reg", &len);
484 if (p != NULL) {
485 *p++ = cpu_to_be32(bd->bi_memstart);
486 *p = cpu_to_be32(bd->bi_memsize);
487 }
488}
489#endif