blob: dbed5971738324d24a63f9a750958c117533fb09 [file] [log] [blame]
stroesec096c842004-12-16 18:21:17 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
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 * modifications for the DB64360 eval board based by Ingo.Assmus@keymile.com
24 * modifications for the cpci750 by reinhard.arlt@esd-electronics.com
25 */
26
27/*
28 * cpci750.c - main board support/init for the esd cpci750.
29 */
30
31#include <common.h>
32#include <74xx_7xx.h>
33#include "../../Marvell/include/memory.h"
34#include "../../Marvell/include/pci.h"
35#include "../../Marvell/include/mv_gen_reg.h"
36#include <net.h>
37
38#include "eth.h"
39#include "mpsc.h"
40#include "i2c.h"
41#include "64360.h"
42#include "mv_regs.h"
43
44#undef DEBUG
45/*#define DEBUG */
46
47#ifdef CONFIG_PCI
48#define MAP_PCI
49#endif /* of CONFIG_PCI */
50
51#ifdef DEBUG
52#define DP(x) x
53#else
54#define DP(x)
55#endif
56
57extern void flush_data_cache (void);
58extern void invalidate_l1_instruction_cache (void);
Stefan Roese16138f92006-02-08 15:54:15 +010059extern flash_info_t flash_info[];
stroesec096c842004-12-16 18:21:17 +000060
61/* ------------------------------------------------------------------------- */
62
63/* this is the current GT register space location */
64/* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
65
66/* Unfortunately, we cant change it while we are in flash, so we initialize it
67 * to the "final" value. This means that any debug_led calls before
68 * board_early_init_f wont work right (like in cpu_init_f).
69 * See also my_remap_gt_regs below. (NTL)
70 */
71
72void board_prebootm_init (void);
73unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
74int display_mem_map (void);
75
76/* ------------------------------------------------------------------------- */
77
78/*
79 * This is a version of the GT register space remapping function that
80 * doesn't touch globals (meaning, it's ok to run from flash.)
81 *
82 * Unfortunately, this has the side effect that a writable
83 * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
84 */
85
86void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
87{
88 u32 temp;
89
90 /* check and see if it's already moved */
91
92/* original ppcboot 1.1.6 source
93
94 temp = in_le32((u32 *)(new_loc + INTERNAL_SPACE_DECODE));
95 if ((temp & 0xffff) == new_loc >> 20)
96 return;
97
98 temp = (in_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE)) &
99 0xffff0000) | (new_loc >> 20);
100
101 out_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE), temp);
102
103 while (GTREGREAD(INTERNAL_SPACE_DECODE) != temp);
104original ppcboot 1.1.6 source end */
105
106 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
107 if ((temp & 0xffff) == new_loc >> 16)
108 return;
109
110 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
111 0xffff0000) | (new_loc >> 16);
112
113 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
114
115 while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
116}
117
118#ifdef CONFIG_PCI
119
120static void gt_pci_config (void)
121{
122 unsigned int stat;
123 unsigned int val = 0x00fff864; /* DINK32: BusNum 23:16, DevNum 15:11, FuncNum 10:8, RegNum 7:2 */
124
125 /* In PCIX mode devices provide their own bus and device numbers. We query the Discovery II's
126 * config registers by writing ones to the bus and device.
127 * We then update the Virtual register with the correct value for the bus and device.
128 */
129 if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
130 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
131
132 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
133
134 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
135 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
136 (stat & 0xffff0000) | CFG_PCI_IDSEL);
137
138 }
139 if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
140 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
141 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
142
143 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
144 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
145 (stat & 0xffff0000) | CFG_PCI_IDSEL);
146 }
147
148 /* Enable master */
149 PCI_MASTER_ENABLE (0, SELF);
150 PCI_MASTER_ENABLE (1, SELF);
151
152 /* Enable PCI0/1 Mem0 and IO 0 disable all others */
153 GT_REG_READ (BASE_ADDR_ENABLE, &stat);
154 stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) | (1
155 <<
156 18);
157 stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
158 GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
159
160 /* ronen- add write to pci remap registers for 64460.
161 in 64360 when writing to pci base go and overide remap automaticaly,
162 in 64460 it doesn't */
163 GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CFG_PCI0_IO_SPACE >> 16);
164 GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CFG_PCI0_IO_SPACE_PCI >> 16);
165 GT_REG_WRITE (PCI_0_IO_SIZE, (CFG_PCI0_IO_SIZE - 1) >> 16);
166
167 GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CFG_PCI0_MEM_BASE >> 16);
168 GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CFG_PCI0_MEM_BASE >> 16);
169 GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CFG_PCI0_MEM_SIZE - 1) >> 16);
170
171 GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CFG_PCI1_IO_SPACE >> 16);
172 GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CFG_PCI1_IO_SPACE_PCI >> 16);
173 GT_REG_WRITE (PCI_1_IO_SIZE, (CFG_PCI1_IO_SIZE - 1) >> 16);
174
175 GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CFG_PCI1_MEM_BASE >> 16);
176 GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CFG_PCI1_MEM_BASE >> 16);
177 GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CFG_PCI1_MEM_SIZE - 1) >> 16);
178
179 /* PCI interface settings */
180 /* Timeout set to retry forever */
181 GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
182 GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
183
184 /* ronen - enable only CS0 and Internal reg!! */
185 GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
186 GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
187
188/*ronen update the pci internal registers base address.*/
189#ifdef MAP_PCI
190 for (stat = 0; stat <= PCI_HOST1; stat++)
191 pciWriteConfigReg (stat,
192 PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
193 SELF, CFG_GT_REGS);
194#endif
195
196}
197#endif
198
199/* Setup CPU interface paramaters */
200static void gt_cpu_config (void)
201{
202 cpu_t cpu = get_cpu_type ();
203 ulong tmp;
204
205 /* cpu configuration register */
206 tmp = GTREGREAD (CPU_CONFIGURATION);
207
208 /* set the SINGLE_CPU bit see MV64360 P.399 */
209#ifndef CFG_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
210 tmp |= CPU_CONF_SINGLE_CPU;
211#endif
212
213 tmp &= ~CPU_CONF_AACK_DELAY_2;
214
215 tmp |= CPU_CONF_DP_VALID;
216 tmp |= CPU_CONF_AP_VALID;
217
218 tmp |= CPU_CONF_PIPELINE;
219
220 GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
221
222 /* CPU master control register */
223 tmp = GTREGREAD (CPU_MASTER_CONTROL);
224
225 tmp |= CPU_MAST_CTL_ARB_EN;
226
227 if ((cpu == CPU_7400) ||
228 (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
229
230 tmp |= CPU_MAST_CTL_CLEAN_BLK;
231 tmp |= CPU_MAST_CTL_FLUSH_BLK;
232
233 } else {
234 /* cleanblock must be cleared for CPUs
235 * that do not support this command (603e, 750)
236 * see Res#1 */
237 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
238 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
239 }
240 GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
241}
242
243/*
244 * board_early_init_f.
245 *
246 * set up gal. device mappings, etc.
247 */
248int board_early_init_f (void)
249{
250
251 /*
252 * set up the GT the way the kernel wants it
253 * the call to move the GT register space will obviously
254 * fail if it has already been done, but we're going to assume
255 * that if it's not at the power-on location, it's where we put
256 * it last time. (huber)
257 */
258
259 my_remap_gt_regs (CFG_DFL_GT_REGS, CFG_GT_REGS);
260
261 /* No PCI in first release of Port To_do: enable it. */
262#ifdef CONFIG_PCI
263 gt_pci_config ();
264#endif
265 /* mask all external interrupt sources */
266 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
267 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
268 /* new in MV6436x */
269 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
270 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
271 /* --------------------- */
272 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
273 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
274 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
275 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
276 /* does not exist in MV6436x
277 GT_REG_WRITE(CPU_INT_0_MASK, 0);
278 GT_REG_WRITE(CPU_INT_1_MASK, 0);
279 GT_REG_WRITE(CPU_INT_2_MASK, 0);
280 GT_REG_WRITE(CPU_INT_3_MASK, 0);
281 --------------------- */
282
283
284 /* ----- DEVICE BUS SETTINGS ------ */
285
286 /*
287 * EVB
288 * 0 - SRAM ????
289 * 1 - RTC ????
290 * 2 - UART ????
291 * 3 - Flash checked 32Bit Intel Strata
292 * boot - BootCS checked 8Bit 29LV040B
293 *
294 */
295
296 /*
297 * the dual 7450 module requires burst access to the boot
298 * device, so the serial rom copies the boot device to the
299 * on-board sram on the eval board, and updates the correct
300 * registers to boot from the sram. (device0)
301 */
302
303 memoryMapDeviceSpace (DEVICE0, CFG_DEV0_SPACE, CFG_DEV0_SIZE);
304 memoryMapDeviceSpace (DEVICE1, CFG_DEV1_SPACE, CFG_DEV1_SIZE);
305 memoryMapDeviceSpace (DEVICE2, CFG_DEV2_SPACE, CFG_DEV2_SIZE);
306 memoryMapDeviceSpace (DEVICE3, CFG_DEV3_SPACE, CFG_DEV3_SIZE);
307
308
309 /* configure device timing */
310 GT_REG_WRITE (DEVICE_BANK0PARAMETERS, CFG_DEV0_PAR);
311 GT_REG_WRITE (DEVICE_BANK1PARAMETERS, CFG_DEV1_PAR);
312 GT_REG_WRITE (DEVICE_BANK2PARAMETERS, CFG_DEV2_PAR);
313 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_DEV3_PAR);
314
315#ifdef CFG_32BIT_BOOT_PAR /* set port parameters for Flash device module access */
316 /* detect if we are booting from the 32 bit flash */
317 if (GTREGREAD (DEVICE_BOOT_BANK_PARAMETERS) & (0x3 << 20)) {
318 /* 32 bit boot flash */
319 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_8BIT_BOOT_PAR);
320 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS,
321 CFG_32BIT_BOOT_PAR);
322 } else {
323 /* 8 bit boot flash */
324 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_32BIT_BOOT_PAR);
325 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);
326 }
327#else
328 /* 8 bit boot flash only */
329/* GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);*/
330#endif
331
332
333 gt_cpu_config ();
334
335 /* MPP setup */
336 GT_REG_WRITE (MPP_CONTROL0, CFG_MPP_CONTROL_0);
337 GT_REG_WRITE (MPP_CONTROL1, CFG_MPP_CONTROL_1);
338 GT_REG_WRITE (MPP_CONTROL2, CFG_MPP_CONTROL_2);
339 GT_REG_WRITE (MPP_CONTROL3, CFG_MPP_CONTROL_3);
340
341 GT_REG_WRITE (GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
342 DEBUG_LED0_ON ();
343 DEBUG_LED1_ON ();
344 DEBUG_LED2_ON ();
345
346 return 0;
347}
348
349/* various things to do after relocation */
350
351int misc_init_r ()
352{
353 icache_enable ();
354#ifdef CFG_L2
355 l2cache_enable ();
356#endif
357#ifdef CONFIG_MPSC
358
359 mpsc_sdma_init ();
360 mpsc_init2 ();
361#endif
362
363#if 0
364 /* disable the dcache and MMU */
365 dcache_lock ();
366#endif
Stefan Roese16138f92006-02-08 15:54:15 +0100367 if (flash_info[3].size < CFG_FLASH_INCREMENT) {
368 unsigned int flash_offset;
369 unsigned int l;
370
371 flash_offset = CFG_FLASH_INCREMENT - flash_info[3].size;
372 for (l = 0; l < CFG_MAX_FLASH_SECT; l++) {
373 if (flash_info[3].start[l] != 0) {
374 flash_info[3].start[l] += flash_offset;
375 }
376 }
377 flash_protect (FLAG_PROTECT_SET,
378 CFG_MONITOR_BASE,
379 CFG_MONITOR_BASE + monitor_flash_len - 1,
380 &flash_info[3]);
Stefan Roese16138f92006-02-08 15:54:15 +0100381 }
stroesec096c842004-12-16 18:21:17 +0000382 return 0;
383}
384
385void after_reloc (ulong dest_addr, gd_t * gd)
386{
387
388 memoryMapDeviceSpace (BOOT_DEVICE, CFG_BOOT_SPACE, CFG_BOOT_SIZE);
389
390 display_mem_map ();
391 /* now, jump to the main ppcboot board init code */
392 board_init_r (gd, dest_addr);
393 /* NOTREACHED */
394}
395
396/* ------------------------------------------------------------------------- */
397
398/*
399 * Check Board Identity:
400 *
401 * right now, assume borad type. (there is just one...after all)
402 */
403
404int checkboard (void)
405{
406 int l_type = 0;
407
408 printf ("BOARD: %s\n", CFG_BOARD_NAME);
409 return (l_type);
410}
411
412/* utility functions */
413void debug_led (int led, int mode)
414{
415}
416
417int display_mem_map (void)
418{
419 int i, j;
420 unsigned int base, size, width;
421
422 /* SDRAM */
423 printf ("SD (DDR) RAM\n");
424 for (i = 0; i <= BANK3; i++) {
425 base = memoryGetBankBaseAddress (i);
426 size = memoryGetBankSize (i);
427 if (size != 0) {
428 printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
429 i, base, size >> 20);
430 }
431 }
432#ifdef CONFIG_PCI
433 /* CPU's PCI windows */
434 for (i = 0; i <= PCI_HOST1; i++) {
435 printf ("\nCPU's PCI %d windows\n", i);
436 base = pciGetSpaceBase (i, PCI_IO);
437 size = pciGetSpaceSize (i, PCI_IO);
438 printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
439 size >> 20);
440 for (j = 0;
441 j <=
442 PCI_REGION0
443 /*ronen currently only first PCI MEM is used 3 */ ;
444 j++) {
445 base = pciGetSpaceBase (i, j);
446 size = pciGetSpaceSize (i, j);
447 printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n", j, base, size >> 20);
448 }
449 }
450#endif /* of CONFIG_PCI */
451 /* Devices */
452 printf ("\nDEVICES\n");
453 for (i = 0; i <= DEVICE3; i++) {
454 base = memoryGetDeviceBaseAddress (i);
455 size = memoryGetDeviceSize (i);
456 width = memoryGetDeviceWidth (i) * 8;
457 printf ("DEV %d: base - 0x%08x size - %dM bytes\twidth - %d bits", i, base, size >> 20, width);
458 if (i == 0)
459 printf ("\t- FLASH\n");
460 else if (i == 1)
461 printf ("\t- FLASH\n");
462 else if (i == 2)
463 printf ("\t- FLASH\n");
464 else
465 printf ("\t- RTC/REGS/CAN\n");
466 }
467
468 /* Bootrom */
469 base = memoryGetDeviceBaseAddress (BOOT_DEVICE); /* Boot */
470 size = memoryGetDeviceSize (BOOT_DEVICE);
471 width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
472 printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\t- FLASH\n",
473 base, size >> 20, width);
474 return (0);
475}
476
477/* DRAM check routines copied from gw8260 */
478
479#if defined (CFG_DRAM_TEST)
480
481/*********************************************************************/
482/* NAME: move64() - moves a double word (64-bit) */
483/* */
484/* DESCRIPTION: */
485/* this function performs a double word move from the data at */
486/* the source pointer to the location at the destination pointer. */
487/* */
488/* INPUTS: */
489/* unsigned long long *src - pointer to data to move */
490/* */
491/* OUTPUTS: */
492/* unsigned long long *dest - pointer to locate to move data */
493/* */
494/* RETURNS: */
495/* None */
496/* */
497/* RESTRICTIONS/LIMITATIONS: */
498/* May cloober fr0. */
499/* */
500/*********************************************************************/
501static void move64 (unsigned long long *src, unsigned long long *dest)
502{
503 asm ("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
504 "stfd 0, 0(4)" /* *dest = fpr0 */
505 : : : "fr0"); /* Clobbers fr0 */
506 return;
507}
508
509
510#if defined (CFG_DRAM_TEST_DATA)
511
512unsigned long long pattern[] = {
wdenk54070ab2004-12-31 09:32:47 +0000513 0xaaaaaaaaaaaaaaaaLL,
514 0xccccccccccccccccLL,
515 0xf0f0f0f0f0f0f0f0LL,
516 0xff00ff00ff00ff00LL,
517 0xffff0000ffff0000LL,
518 0xffffffff00000000LL,
519 0x00000000ffffffffLL,
520 0x0000ffff0000ffffLL,
521 0x00ff00ff00ff00ffLL,
522 0x0f0f0f0f0f0f0f0fLL,
523 0x3333333333333333LL,
524 0x5555555555555555LL,
stroesec096c842004-12-16 18:21:17 +0000525};
526
527/*********************************************************************/
528/* NAME: mem_test_data() - test data lines for shorts and opens */
529/* */
530/* DESCRIPTION: */
531/* Tests data lines for shorts and opens by forcing adjacent data */
532/* to opposite states. Because the data lines could be routed in */
533/* an arbitrary manner the must ensure test patterns ensure that */
534/* every case is tested. By using the following series of binary */
535/* patterns every combination of adjacent bits is test regardless */
536/* of routing. */
537/* */
538/* ...101010101010101010101010 */
539/* ...110011001100110011001100 */
540/* ...111100001111000011110000 */
541/* ...111111110000000011111111 */
542/* */
543/* Carrying this out, gives us six hex patterns as follows: */
544/* */
545/* 0xaaaaaaaaaaaaaaaa */
546/* 0xcccccccccccccccc */
547/* 0xf0f0f0f0f0f0f0f0 */
548/* 0xff00ff00ff00ff00 */
549/* 0xffff0000ffff0000 */
550/* 0xffffffff00000000 */
551/* */
552/* The number test patterns will always be given by: */
553/* */
554/* log(base 2)(number data bits) = log2 (64) = 6 */
555/* */
556/* To test for short and opens to other signals on our boards. we */
557/* simply */
558/* test with the 1's complemnt of the paterns as well. */
559/* */
560/* OUTPUTS: */
561/* Displays failing test pattern */
562/* */
563/* RETURNS: */
564/* 0 - Passed test */
565/* 1 - Failed test */
566/* */
567/* RESTRICTIONS/LIMITATIONS: */
568/* Assumes only one one SDRAM bank */
569/* */
570/*********************************************************************/
571int mem_test_data (void)
572{
573 unsigned long long *pmem = (unsigned long long *) CFG_MEMTEST_START;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200574 unsigned long long temp64 = 0;
stroesec096c842004-12-16 18:21:17 +0000575 int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
576 int i;
577 unsigned int hi, lo;
578
579 for (i = 0; i < num_patterns; i++) {
580 move64 (&(pattern[i]), pmem);
581 move64 (pmem, &temp64);
582
583 /* hi = (temp64>>32) & 0xffffffff; */
584 /* lo = temp64 & 0xffffffff; */
585 /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
586
587 hi = (pattern[i] >> 32) & 0xffffffff;
588 lo = pattern[i] & 0xffffffff;
589 /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
590
591 if (temp64 != pattern[i]) {
592 printf ("\n Data Test Failed, pattern 0x%08x%08x",
593 hi, lo);
594 return 1;
595 }
596 }
597
598 return 0;
599}
600#endif /* CFG_DRAM_TEST_DATA */
601
602#if defined (CFG_DRAM_TEST_ADDRESS)
603/*********************************************************************/
604/* NAME: mem_test_address() - test address lines */
605/* */
606/* DESCRIPTION: */
607/* This function performs a test to verify that each word im */
608/* memory is uniquly addressable. The test sequence is as follows: */
609/* */
610/* 1) write the address of each word to each word. */
611/* 2) verify that each location equals its address */
612/* */
613/* OUTPUTS: */
614/* Displays failing test pattern and address */
615/* */
616/* RETURNS: */
617/* 0 - Passed test */
618/* 1 - Failed test */
619/* */
620/* RESTRICTIONS/LIMITATIONS: */
621/* */
622/* */
623/*********************************************************************/
624int mem_test_address (void)
625{
626 volatile unsigned int *pmem =
627 (volatile unsigned int *) CFG_MEMTEST_START;
628 const unsigned int size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 4;
629 unsigned int i;
630
631 /* write address to each location */
632 for (i = 0; i < size; i++) {
633 pmem[i] = i;
634 }
635
636 /* verify each loaction */
637 for (i = 0; i < size; i++) {
638 if (pmem[i] != i) {
639 printf ("\n Address Test Failed at 0x%x", i);
640 return 1;
641 }
642 }
643 return 0;
644}
645#endif /* CFG_DRAM_TEST_ADDRESS */
646
647#if defined (CFG_DRAM_TEST_WALK)
648/*********************************************************************/
649/* NAME: mem_march() - memory march */
650/* */
651/* DESCRIPTION: */
652/* Marches up through memory. At each location verifies rmask if */
653/* read = 1. At each location write wmask if write = 1. Displays */
654/* failing address and pattern. */
655/* */
656/* INPUTS: */
657/* volatile unsigned long long * base - start address of test */
658/* unsigned int size - number of dwords(64-bit) to test */
659/* unsigned long long rmask - read verify mask */
660/* unsigned long long wmask - wrtie verify mask */
661/* short read - verifies rmask if read = 1 */
662/* short write - writes wmask if write = 1 */
663/* */
664/* OUTPUTS: */
665/* Displays failing test pattern and address */
666/* */
667/* RETURNS: */
668/* 0 - Passed test */
669/* 1 - Failed test */
670/* */
671/* RESTRICTIONS/LIMITATIONS: */
672/* */
673/* */
674/*********************************************************************/
675int mem_march (volatile unsigned long long *base,
676 unsigned int size,
677 unsigned long long rmask,
678 unsigned long long wmask, short read, short write)
679{
680 unsigned int i;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200681 unsigned long long temp = 0;
stroesec096c842004-12-16 18:21:17 +0000682 unsigned int hitemp, lotemp, himask, lomask;
683
684 for (i = 0; i < size; i++) {
685 if (read != 0) {
686 /* temp = base[i]; */
687 move64 ((unsigned long long *) &(base[i]), &temp);
688 if (rmask != temp) {
689 hitemp = (temp >> 32) & 0xffffffff;
690 lotemp = temp & 0xffffffff;
691 himask = (rmask >> 32) & 0xffffffff;
692 lomask = rmask & 0xffffffff;
693
694 printf ("\n Walking one's test failed: address = 0x%08x," "\n\texpected 0x%08x%08x, found 0x%08x%08x", i << 3, himask, lomask, hitemp, lotemp);
695 return 1;
696 }
697 }
698 if (write != 0) {
699 /* base[i] = wmask; */
700 move64 (&wmask, (unsigned long long *) &(base[i]));
701 }
702 }
703 return 0;
704}
705#endif /* CFG_DRAM_TEST_WALK */
706
707/*********************************************************************/
708/* NAME: mem_test_walk() - a simple walking ones test */
709/* */
710/* DESCRIPTION: */
711/* Performs a walking ones through entire physical memory. The */
712/* test uses as series of memory marches, mem_march(), to verify */
713/* and write the test patterns to memory. The test sequence is as */
714/* follows: */
715/* 1) march writing 0000...0001 */
716/* 2) march verifying 0000...0001 , writing 0000...0010 */
717/* 3) repeat step 2 shifting masks left 1 bit each time unitl */
718/* the write mask equals 1000...0000 */
719/* 4) march verifying 1000...0000 */
720/* The test fails if any of the memory marches return a failure. */
721/* */
722/* OUTPUTS: */
723/* Displays which pass on the memory test is executing */
724/* */
725/* RETURNS: */
726/* 0 - Passed test */
727/* 1 - Failed test */
728/* */
729/* RESTRICTIONS/LIMITATIONS: */
730/* */
731/* */
732/*********************************************************************/
733int mem_test_walk (void)
734{
735 unsigned long long mask;
736 volatile unsigned long long *pmem =
737 (volatile unsigned long long *) CFG_MEMTEST_START;
738 const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
739
740 unsigned int i;
741
742 mask = 0x01;
743
744 printf ("Initial Pass");
745 mem_march (pmem, size, 0x0, 0x1, 0, 1);
746
747 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
748 printf (" ");
749 printf (" ");
750 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
751
752 for (i = 0; i < 63; i++) {
753 printf ("Pass %2d", i + 2);
754 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
755 /*printf("mask: 0x%x, pass: %d, ", mask, i); */
756 return 1;
757 }
758 mask = mask << 1;
759 printf ("\b\b\b\b\b\b\b");
760 }
761
762 printf ("Last Pass");
763 if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
764 /* printf("mask: 0x%x", mask); */
765 return 1;
766 }
767 printf ("\b\b\b\b\b\b\b\b\b");
768 printf (" ");
769 printf ("\b\b\b\b\b\b\b\b\b");
770
771 return 0;
772}
773
774/*********************************************************************/
775/* NAME: testdram() - calls any enabled memory tests */
776/* */
777/* DESCRIPTION: */
778/* Runs memory tests if the environment test variables are set to */
779/* 'y'. */
780/* */
781/* INPUTS: */
782/* testdramdata - If set to 'y', data test is run. */
783/* testdramaddress - If set to 'y', address test is run. */
784/* testdramwalk - If set to 'y', walking ones test is run */
785/* */
786/* OUTPUTS: */
787/* None */
788/* */
789/* RETURNS: */
790/* 0 - Passed test */
791/* 1 - Failed test */
792/* */
793/* RESTRICTIONS/LIMITATIONS: */
794/* */
795/* */
796/*********************************************************************/
797int testdram (void)
798{
799 char *s;
800 int rundata = 0;
801 int runaddress = 0;
802 int runwalk = 0;
803
804#ifdef CFG_DRAM_TEST_DATA
805 s = getenv ("testdramdata");
806 rundata = (s && (*s == 'y')) ? 1 : 0;
807#endif
808#ifdef CFG_DRAM_TEST_ADDRESS
809 s = getenv ("testdramaddress");
810 runaddress = (s && (*s == 'y')) ? 1 : 0;
811#endif
812#ifdef CFG_DRAM_TEST_WALK
813 s = getenv ("testdramwalk");
814 runwalk = (s && (*s == 'y')) ? 1 : 0;
815#endif
816
817 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
818 printf ("Testing RAM from 0x%08x to 0x%08x ... (don't panic... that will take a moment !!!!)\n", CFG_MEMTEST_START, CFG_MEMTEST_END);
819 }
820#ifdef CFG_DRAM_TEST_DATA
821 if (rundata == 1) {
822 printf ("Test DATA ... ");
823 if (mem_test_data () == 1) {
824 printf ("failed \n");
825 return 1;
826 } else
827 printf ("ok \n");
828 }
829#endif
830#ifdef CFG_DRAM_TEST_ADDRESS
831 if (runaddress == 1) {
832 printf ("Test ADDRESS ... ");
833 if (mem_test_address () == 1) {
834 printf ("failed \n");
835 return 1;
836 } else
837 printf ("ok \n");
838 }
839#endif
840#ifdef CFG_DRAM_TEST_WALK
841 if (runwalk == 1) {
842 printf ("Test WALKING ONEs ... ");
843 if (mem_test_walk () == 1) {
844 printf ("failed \n");
845 return 1;
846 } else
847 printf ("ok \n");
848 }
849#endif
850 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
851 printf ("passed\n");
852 }
853 return 0;
854
855}
856#endif /* CFG_DRAM_TEST */
857
858/* ronen - the below functions are used by the bootm function */
859/* - we map the base register to fbe00000 (same mapping as in the LSP) */
860/* - we turn off the RX gig dmas - to prevent the dma from overunning */
861/* the kernel data areas. */
862/* - we diable and invalidate the icache and dcache. */
863void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
864{
865 u32 temp;
866
867 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
868 if ((temp & 0xffff) == new_loc >> 16)
869 return;
870
871 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
872 0xffff0000) | (new_loc >> 16);
873
874 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
875
876 while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
877 new_loc |
878 (INTERNAL_SPACE_DECODE)))))
879 != temp);
880
881}
882
883void board_prebootm_init ()
884{
885
886/* change window size of PCI1 IO in order tp prevent overlaping with REG BASE. */
887 GT_REG_WRITE (PCI_1_IO_SIZE, (_64K - 1) >> 16);
888
889/* Stop GigE Rx DMA engines */
890 GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (0), 0x0000ff00);
891/* GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (1), 0x0000ff00); */
892/* GV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (2), 0x0000ff00); */
893
894/* Relocate MV64360 internal regs */
895 my_remap_gt_regs_bootm (CFG_GT_REGS, CFG_DFL_GT_REGS);
896
897 icache_disable ();
898 invalidate_l1_instruction_cache ();
899 flush_data_cache ();
900 dcache_disable ();
901}