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