blob: c3fd19169c95beaa8d22a2ac148c4bcbdfa5b4a8 [file] [log] [blame]
Stefan Roese45993ea2006-11-29 15:42:37 +01001/*
2 * (C) Copyright 2006
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * Based on original work by
6 * Roel Loeffen, (C) Copyright 2006 Prodrive B.V.
7 * Josh Huber, (C) Copyright 2001 Mission Critical Linux, Inc.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 *
27 * modifications for the DB64360 eval board based by Ingo.Assmus@keymile.com
28 * modifications for the cpci750 by reinhard.arlt@esd-electronics.com
29 * modifications for the P3M750 by roel.loeffen@prodrive.nl
30 */
31
32/*
33 * p3m750.c - main board support/init for the Prodrive p3m750/p3m7448.
34 */
35
36#include <common.h>
37#include <74xx_7xx.h>
38#include "../../Marvell/include/memory.h"
39#include "../../Marvell/include/pci.h"
40#include "../../Marvell/include/mv_gen_reg.h"
41#include <net.h>
42#include <i2c.h>
43
44#include "eth.h"
45#include "mpsc.h"
46#include "64460.h"
47#include "mv_regs.h"
Stefan Roese46437f52007-01-18 11:54:52 +010048#include "p3mx.h"
Stefan Roese45993ea2006-11-29 15:42:37 +010049
50DECLARE_GLOBAL_DATA_PTR;
51
52#undef DEBUG
53/*#define DEBUG */
54
55#ifdef CONFIG_PCI
56#define MAP_PCI
57#endif /* of CONFIG_PCI */
58
59#ifdef DEBUG
60#define DP(x) x
61#else
62#define DP(x)
63#endif
64
Stefan Roese45993ea2006-11-29 15:42:37 +010065extern flash_info_t flash_info[];
66
67/* ------------------------------------------------------------------------- */
68
69/* this is the current GT register space location */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070/* it starts at CONFIG_SYS_DFL_GT_REGS but moves later to CONFIG_SYS_GT_REGS */
Stefan Roese45993ea2006-11-29 15:42:37 +010071
72/* Unfortunately, we cant change it while we are in flash, so we initialize it
73 * to the "final" value. This means that any debug_led calls before
74 * board_early_init_f wont work right (like in cpu_init_f).
75 * See also my_remap_gt_regs below. (NTL)
76 */
77
78void board_prebootm_init (void);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079unsigned int INTERNAL_REG_BASE_ADDR = CONFIG_SYS_GT_REGS;
Stefan Roese45993ea2006-11-29 15:42:37 +010080int display_mem_map (void);
Stefan Roese46437f52007-01-18 11:54:52 +010081void set_led(int);
Stefan Roese45993ea2006-11-29 15:42:37 +010082
83/* ------------------------------------------------------------------------- */
84
85/*
86 * This is a version of the GT register space remapping function that
87 * doesn't touch globals (meaning, it's ok to run from flash.)
88 *
89 * Unfortunately, this has the side effect that a writable
90 * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
91 */
92
93void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
94{
95 u32 temp;
96
97 /* check and see if it's already moved */
98 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
99 if ((temp & 0xffff) == new_loc >> 16)
100 return;
101
102 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
103 0xffff0000) | (new_loc >> 16);
104
105 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
106
107 while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
108}
109
110#ifdef CONFIG_PCI
111
112static void gt_pci_config (void)
113{
114 unsigned int stat;
115 unsigned int val = 0x00fff864; /* DINK32: BusNum 23:16, DevNum 15:11, */
116 /* FuncNum 10:8, RegNum 7:2 */
117
118 /*
119 * In PCIX mode devices provide their own bus and device numbers.
120 * We query the Discovery II's
121 * config registers by writing ones to the bus and device.
122 * We then update the Virtual register with the correct value for the
123 * bus and device.
124 */
125 if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
126 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
127
128 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
129
130 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
131 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200132 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
Stefan Roese45993ea2006-11-29 15:42:37 +0100133
134 }
135 if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
136 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
137 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
138
139 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
140 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200141 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
Stefan Roese45993ea2006-11-29 15:42:37 +0100142 }
143
144 /* Enable master */
145 PCI_MASTER_ENABLE (0, SELF);
146 PCI_MASTER_ENABLE (1, SELF);
147
148 /* Enable PCI0/1 Mem0 and IO 0 disable all others */
149 GT_REG_READ (BASE_ADDR_ENABLE, &stat);
150 stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) |
151 (1 << 18);
152 stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
153 GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
154
155 /* ronen:
156 * add write to pci remap registers for 64460.
157 * in 64360 when writing to pci base go and overide remap automaticaly,
158 * in 64460 it doesn't
159 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200160 GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CONFIG_SYS_PCI0_IO_SPACE >> 16);
161 GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CONFIG_SYS_PCI0_IO_SPACE_PCI >> 16);
162 GT_REG_WRITE (PCI_0_IO_SIZE, (CONFIG_SYS_PCI0_IO_SIZE - 1) >> 16);
Stefan Roese45993ea2006-11-29 15:42:37 +0100163
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164 GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI0_MEM_BASE >> 16);
165 GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI0_MEM_BASE >> 16);
166 GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CONFIG_SYS_PCI0_MEM_SIZE - 1) >> 16);
Stefan Roese45993ea2006-11-29 15:42:37 +0100167
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200168 GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CONFIG_SYS_PCI1_IO_SPACE >> 16);
169 GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CONFIG_SYS_PCI1_IO_SPACE_PCI >> 16);
170 GT_REG_WRITE (PCI_1_IO_SIZE, (CONFIG_SYS_PCI1_IO_SIZE - 1) >> 16);
Stefan Roese45993ea2006-11-29 15:42:37 +0100171
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI1_MEM_BASE >> 16);
173 GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI1_MEM_BASE >> 16);
174 GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CONFIG_SYS_PCI1_MEM_SIZE - 1) >> 16);
Stefan Roese45993ea2006-11-29 15:42:37 +0100175
176 /* PCI interface settings */
177 /* Timeout set to retry forever */
178 GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
179 GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
180
181 /* ronen - enable only CS0 and Internal reg!! */
182 GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
183 GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
184
185 /* ronen:
186 * update the pci internal registers base address.
187 */
188#ifdef MAP_PCI
189 for (stat = 0; stat <= PCI_HOST1; stat++)
190 pciWriteConfigReg (stat,
191 PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200192 SELF, CONFIG_SYS_GT_REGS);
Stefan Roese45993ea2006-11-29 15:42:37 +0100193#endif
194
195}
196#endif
197
198/* Setup CPU interface paramaters */
199static void gt_cpu_config (void)
200{
201 cpu_t cpu = get_cpu_type ();
202 ulong tmp;
203
204 /* cpu configuration register */
205 tmp = GTREGREAD (CPU_CONFIGURATION);
206 /* set the SINGLE_CPU bit see MV64460 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200207#ifndef CONFIG_SYS_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
Stefan Roese45993ea2006-11-29 15:42:37 +0100208 tmp |= CPU_CONF_SINGLE_CPU;
209#endif
210 tmp &= ~CPU_CONF_AACK_DELAY_2;
211 tmp |= CPU_CONF_DP_VALID;
212 tmp |= CPU_CONF_AP_VALID;
213 tmp |= CPU_CONF_PIPELINE;
214 GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
215
216 /* CPU master control register */
217 tmp = GTREGREAD (CPU_MASTER_CONTROL);
218 tmp |= CPU_MAST_CTL_ARB_EN;
219
220 if ((cpu == CPU_7400) ||
221 (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
222
223 tmp |= CPU_MAST_CTL_CLEAN_BLK;
224 tmp |= CPU_MAST_CTL_FLUSH_BLK;
225
226 } else {
227 /* cleanblock must be cleared for CPUs
228 * that do not support this command (603e, 750)
229 * see Res#1 */
230 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
231 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
232 }
233 GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
234}
235
236/*
237 * board_early_init_f.
238 *
239 * set up gal. device mappings, etc.
240 */
241int board_early_init_f (void)
242{
243 /* set up the GT the way the kernel wants it
244 * the call to move the GT register space will obviously
245 * fail if it has already been done, but we're going to assume
246 * that if it's not at the power-on location, it's where we put
247 * it last time. (huber)
248 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200249 my_remap_gt_regs (CONFIG_SYS_DFL_GT_REGS, CONFIG_SYS_GT_REGS);
Stefan Roese45993ea2006-11-29 15:42:37 +0100250
251#ifdef CONFIG_PCI
252 gt_pci_config ();
253#endif
254 /* mask all external interrupt sources */
255 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
256 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
257 /* new in >MV6436x */
258 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
259 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
260 /* --------------------- */
261 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
262 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
263 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
264 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
265
266 /* Device and Boot bus settings
267 */
268 memoryMapDeviceSpace(DEVICE0, 0, 0);
269 GT_REG_WRITE(DEVICE_BANK0PARAMETERS, 0);
270 memoryMapDeviceSpace(DEVICE1, 0, 0);
271 GT_REG_WRITE(DEVICE_BANK1PARAMETERS, 0);
272 memoryMapDeviceSpace(DEVICE2, 0, 0);
273 GT_REG_WRITE(DEVICE_BANK2PARAMETERS, 0);
274 memoryMapDeviceSpace(DEVICE3, 0, 0);
275 GT_REG_WRITE(DEVICE_BANK3PARAMETERS, 0);
276
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200277 GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CONFIG_SYS_BOOT_PAR);
Stefan Roese45993ea2006-11-29 15:42:37 +0100278
279 gt_cpu_config();
280
281 /* MPP setup */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200282 GT_REG_WRITE (MPP_CONTROL0, CONFIG_SYS_MPP_CONTROL_0);
283 GT_REG_WRITE (MPP_CONTROL1, CONFIG_SYS_MPP_CONTROL_1);
284 GT_REG_WRITE (MPP_CONTROL2, CONFIG_SYS_MPP_CONTROL_2);
285 GT_REG_WRITE (MPP_CONTROL3, CONFIG_SYS_MPP_CONTROL_3);
Stefan Roese45993ea2006-11-29 15:42:37 +0100286
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200287 GT_REG_WRITE (GPP_LEVEL_CONTROL, CONFIG_SYS_GPP_LEVEL_CONTROL);
Stefan Roese45993ea2006-11-29 15:42:37 +0100288
Stefan Roese46437f52007-01-18 11:54:52 +0100289 set_led(LED_RED);
290
Stefan Roese45993ea2006-11-29 15:42:37 +0100291 return 0;
292}
293
294/* various things to do after relocation */
295
296int misc_init_r ()
297{
298 u8 val;
299
300 icache_enable ();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200301#ifdef CONFIG_SYS_L2
Stefan Roese45993ea2006-11-29 15:42:37 +0100302 l2cache_enable ();
303#endif
304#ifdef CONFIG_MPSC
305 mpsc_sdma_init ();
306 mpsc_init2 ();
307#endif
308
309 /*
310 * Enable trickle changing in RTC upon powerup
311 * No diode, 250 ohm series resistor
312 */
313 val = 0xa5;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200314 i2c_write(CONFIG_SYS_I2C_RTC_ADDR, 8, 1, &val, 1);
Stefan Roese45993ea2006-11-29 15:42:37 +0100315
316 return 0;
317}
318
Stefan Roese45993ea2006-11-29 15:42:37 +0100319void after_reloc (ulong dest_addr, gd_t * gd)
320{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200321 memoryMapDeviceSpace (BOOT_DEVICE, CONFIG_SYS_BOOT_SPACE, CONFIG_SYS_BOOT_SIZE);
Stefan Roese45993ea2006-11-29 15:42:37 +0100322
323/* display_mem_map(); */
324
325 /* now, jump to the main U-Boot board init code */
Stefan Roese46437f52007-01-18 11:54:52 +0100326 set_led(LED_GREEN);
Stefan Roese45993ea2006-11-29 15:42:37 +0100327 board_init_r (gd, dest_addr);
328 /* NOTREACHED */
329}
330
331/*
332 * Check Board Identity:
333 * right now, assume borad type. (there is just one...after all)
334 */
335
336int checkboard (void)
337{
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000338 char buf[64];
339 int i = getenv_f("serial#", buf, sizeof(buf));
Stefan Roese45993ea2006-11-29 15:42:37 +0100340
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200341 printf("Board: %s", CONFIG_SYS_BOARD_NAME);
Stefan Roese45993ea2006-11-29 15:42:37 +0100342
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000343 if (i > 0) {
Stefan Roese45993ea2006-11-29 15:42:37 +0100344 puts(", serial# ");
Wolfgang Denk5c1cfee2011-05-04 10:32:28 +0000345 puts(buf);
Stefan Roese45993ea2006-11-29 15:42:37 +0100346 }
347 putc('\n');
348
349 return (0);
350}
351
Stefan Roese46437f52007-01-18 11:54:52 +0100352void set_led(int col)
Stefan Roese45993ea2006-11-29 15:42:37 +0100353{
Stefan Roese46437f52007-01-18 11:54:52 +0100354 int tmp;
355 int on_pin;
356 int off_pin;
357
358 /* Program Mpp[22] as Gpp[22]
359 * Program Mpp[23] as Gpp[23]
360 */
361 tmp = GTREGREAD(MPP_CONTROL2);
362 tmp &= 0x00ffffff;
363 GT_REG_WRITE(MPP_CONTROL2,tmp);
364
365 /* Program Gpp[22] and Gpp[23] as output
366 */
367 tmp = GTREGREAD(GPP_IO_CONTROL);
368 tmp |= 0x00C00000;
369 GT_REG_WRITE(GPP_IO_CONTROL, tmp);
370
371 /* Program Gpp[22] and Gpp[23] as active high
372 */
373 tmp = GTREGREAD(GPP_LEVEL_CONTROL);
374 tmp &= 0xff3fffff;
375 GT_REG_WRITE(GPP_LEVEL_CONTROL, tmp);
376
377 switch(col) {
378 default:
379 case LED_OFF :
380 on_pin = 0;
381 off_pin = ((1 << 23) | (1 << 22));
382 break;
383 case LED_RED :
384 on_pin = (1 << 23);
385 off_pin = (1 << 22);
386 break;
387 case LED_GREEN :
388 on_pin = (1 << 22);
389 off_pin = (1 << 23);
390 break;
391 case LED_ORANGE :
392 on_pin = ((1 << 23) | (1 << 22));
393 off_pin = 0;
394 break;
395 }
396
397 /* Set output Gpp[22] and Gpp[23]
398 */
399 tmp = GTREGREAD(GPP_VALUE);
400 tmp |= on_pin;
401 tmp &= ~off_pin;
402 GT_REG_WRITE(GPP_VALUE, tmp);
Stefan Roese45993ea2006-11-29 15:42:37 +0100403}
404
405int display_mem_map (void)
406{
Stefan Roese46437f52007-01-18 11:54:52 +0100407 int i;
Stefan Roese45993ea2006-11-29 15:42:37 +0100408 unsigned int base, size, width;
Stefan Roese46437f52007-01-18 11:54:52 +0100409#ifdef CONFIG_PCI
410 int j;
411#endif
Stefan Roese45993ea2006-11-29 15:42:37 +0100412
413 /* SDRAM */
414 printf ("SD (DDR) RAM\n");
415 for (i = 0; i <= BANK3; i++) {
416 base = memoryGetBankBaseAddress (i);
417 size = memoryGetBankSize (i);
418 if (size != 0)
419 printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
420 i, base, size >> 20);
421 }
422#ifdef CONFIG_PCI
423 /* CPU's PCI windows */
424 for (i = 0; i <= PCI_HOST1; i++) {
425 printf ("\nCPU's PCI %d windows\n", i);
426 base = pciGetSpaceBase (i, PCI_IO);
427 size = pciGetSpaceSize (i, PCI_IO);
428 printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
429 size >> 20);
430 /* ronen currently only first PCI MEM is used 3 */
431 for (j = 0; j <= PCI_REGION0; j++) {
432 base = pciGetSpaceBase (i, j);
433 size = pciGetSpaceSize (i, j);
434 printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n",
435 j, base, size >> 20);
436 }
437 }
438#endif /* of CONFIG_PCI */
439
440 /* Bootrom */
441 base = memoryGetDeviceBaseAddress (BOOT_DEVICE); /* Boot */
442 size = memoryGetDeviceSize (BOOT_DEVICE);
443 width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
444 printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\t- FLASH\n",
445 base, size >> 20, width);
446
447 return (0);
448}
449
450/* DRAM check routines copied from gw8260 */
451
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200452#if defined (CONFIG_SYS_DRAM_TEST)
Stefan Roese45993ea2006-11-29 15:42:37 +0100453
454/*********************************************************************/
455/* NAME: move64() - moves a double word (64-bit) */
456/* */
457/* DESCRIPTION: */
458/* this function performs a double word move from the data at */
459/* the source pointer to the location at the destination pointer. */
460/* */
461/* INPUTS: */
462/* unsigned long long *src - pointer to data to move */
463/* */
464/* OUTPUTS: */
465/* unsigned long long *dest - pointer to locate to move data */
466/* */
467/* RETURNS: */
468/* None */
469/* */
470/* RESTRICTIONS/LIMITATIONS: */
471/* May cloober fr0. */
472/* */
473/*********************************************************************/
474static void move64 (unsigned long long *src, unsigned long long *dest)
475{
476 asm ("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
477 "stfd 0, 0(4)" /* *dest = fpr0 */
478 : : : "fr0"); /* Clobbers fr0 */
479 return;
480}
481
482
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200483#if defined (CONFIG_SYS_DRAM_TEST_DATA)
Stefan Roese45993ea2006-11-29 15:42:37 +0100484
485unsigned long long pattern[] = {
486 0xaaaaaaaaaaaaaaaaULL,
487 0xccccccccccccccccULL,
488 0xf0f0f0f0f0f0f0f0ULL,
489 0xff00ff00ff00ff00ULL,
490 0xffff0000ffff0000ULL,
491 0xffffffff00000000ULL,
492 0x00000000ffffffffULL,
493 0x0000ffff0000ffffULL,
494 0x00ff00ff00ff00ffULL,
495 0x0f0f0f0f0f0f0f0fULL,
496 0x3333333333333333ULL,
497 0x5555555555555555ULL
498};
499
500/*********************************************************************/
501/* NAME: mem_test_data() - test data lines for shorts and opens */
502/* */
503/* DESCRIPTION: */
504/* Tests data lines for shorts and opens by forcing adjacent data */
505/* to opposite states. Because the data lines could be routed in */
506/* an arbitrary manner the must ensure test patterns ensure that */
507/* every case is tested. By using the following series of binary */
508/* patterns every combination of adjacent bits is test regardless */
509/* of routing. */
510/* */
511/* ...101010101010101010101010 */
512/* ...110011001100110011001100 */
513/* ...111100001111000011110000 */
514/* ...111111110000000011111111 */
515/* */
516/* Carrying this out, gives us six hex patterns as follows: */
517/* */
518/* 0xaaaaaaaaaaaaaaaa */
519/* 0xcccccccccccccccc */
520/* 0xf0f0f0f0f0f0f0f0 */
521/* 0xff00ff00ff00ff00 */
522/* 0xffff0000ffff0000 */
523/* 0xffffffff00000000 */
524/* */
525/* The number test patterns will always be given by: */
526/* */
527/* log(base 2)(number data bits) = log2 (64) = 6 */
528/* */
529/* To test for short and opens to other signals on our boards. we */
530/* simply */
531/* test with the 1's complemnt of the paterns as well. */
532/* */
533/* OUTPUTS: */
534/* Displays failing test pattern */
535/* */
536/* RETURNS: */
537/* 0 - Passed test */
538/* 1 - Failed test */
539/* */
540/* RESTRICTIONS/LIMITATIONS: */
541/* Assumes only one one SDRAM bank */
542/* */
543/*********************************************************************/
544int mem_test_data (void)
545{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200546 unsigned long long *pmem = (unsigned long long *) CONFIG_SYS_MEMTEST_START;
Stefan Roese45993ea2006-11-29 15:42:37 +0100547 unsigned long long temp64 = 0;
548 int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
549 int i;
550 unsigned int hi, lo;
551
552 for (i = 0; i < num_patterns; i++) {
553 move64 (&(pattern[i]), pmem);
554 move64 (pmem, &temp64);
555
556 /* hi = (temp64>>32) & 0xffffffff; */
557 /* lo = temp64 & 0xffffffff; */
558 /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
559
560 hi = (pattern[i] >> 32) & 0xffffffff;
561 lo = pattern[i] & 0xffffffff;
562 /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
563
564 if (temp64 != pattern[i]) {
565 printf ("\n Data Test Failed, pattern 0x%08x%08x",
566 hi, lo);
567 return 1;
568 }
569 }
570
571 return 0;
572}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200573#endif /* CONFIG_SYS_DRAM_TEST_DATA */
Stefan Roese45993ea2006-11-29 15:42:37 +0100574
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200575#if defined (CONFIG_SYS_DRAM_TEST_ADDRESS)
Stefan Roese45993ea2006-11-29 15:42:37 +0100576/*********************************************************************/
577/* NAME: mem_test_address() - test address lines */
578/* */
579/* DESCRIPTION: */
580/* This function performs a test to verify that each word im */
581/* memory is uniquly addressable. The test sequence is as follows: */
582/* */
583/* 1) write the address of each word to each word. */
584/* 2) verify that each location equals its address */
585/* */
586/* OUTPUTS: */
587/* Displays failing test pattern and address */
588/* */
589/* RETURNS: */
590/* 0 - Passed test */
591/* 1 - Failed test */
592/* */
593/* RESTRICTIONS/LIMITATIONS: */
594/* */
595/* */
596/*********************************************************************/
597int mem_test_address (void)
598{
599 volatile unsigned int *pmem =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200600 (volatile unsigned int *) CONFIG_SYS_MEMTEST_START;
601 const unsigned int size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 4;
Stefan Roese45993ea2006-11-29 15:42:37 +0100602 unsigned int i;
603
604 /* write address to each location */
605 for (i = 0; i < size; i++)
606 pmem[i] = i;
607
608 /* verify each loaction */
609 for (i = 0; i < size; i++) {
610 if (pmem[i] != i) {
611 printf ("\n Address Test Failed at 0x%x", i);
612 return 1;
613 }
614 }
615 return 0;
616}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200617#endif /* CONFIG_SYS_DRAM_TEST_ADDRESS */
Stefan Roese45993ea2006-11-29 15:42:37 +0100618
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200619#if defined (CONFIG_SYS_DRAM_TEST_WALK)
Stefan Roese45993ea2006-11-29 15:42:37 +0100620/*********************************************************************/
621/* NAME: mem_march() - memory march */
622/* */
623/* DESCRIPTION: */
624/* Marches up through memory. At each location verifies rmask if */
625/* read = 1. At each location write wmask if write = 1. Displays */
626/* failing address and pattern. */
627/* */
628/* INPUTS: */
629/* volatile unsigned long long * base - start address of test */
630/* unsigned int size - number of dwords(64-bit) to test */
631/* unsigned long long rmask - read verify mask */
632/* unsigned long long wmask - wrtie verify mask */
633/* short read - verifies rmask if read = 1 */
634/* short write - writes wmask if write = 1 */
635/* */
636/* OUTPUTS: */
637/* Displays failing test pattern and address */
638/* */
639/* RETURNS: */
640/* 0 - Passed test */
641/* 1 - Failed test */
642/* */
643/* RESTRICTIONS/LIMITATIONS: */
644/* */
645/* */
646/*********************************************************************/
647int mem_march (volatile unsigned long long *base,
648 unsigned int size,
649 unsigned long long rmask,
650 unsigned long long wmask, short read, short write)
651{
652 unsigned int i;
653 unsigned long long temp = 0;
654 unsigned int hitemp, lotemp, himask, lomask;
655
656 for (i = 0; i < size; i++) {
657 if (read != 0) {
658 /* temp = base[i]; */
659 move64 ((unsigned long long *) &(base[i]), &temp);
660 if (rmask != temp) {
661 hitemp = (temp >> 32) & 0xffffffff;
662 lotemp = temp & 0xffffffff;
663 himask = (rmask >> 32) & 0xffffffff;
664 lomask = rmask & 0xffffffff;
665
666 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);
667 return 1;
668 }
669 }
670 if (write != 0) {
671 /* base[i] = wmask; */
672 move64 (&wmask, (unsigned long long *) &(base[i]));
673 }
674 }
675 return 0;
676}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200677#endif /* CONFIG_SYS_DRAM_TEST_WALK */
Stefan Roese45993ea2006-11-29 15:42:37 +0100678
679/*********************************************************************/
680/* NAME: mem_test_walk() - a simple walking ones test */
681/* */
682/* DESCRIPTION: */
683/* Performs a walking ones through entire physical memory. The */
684/* test uses as series of memory marches, mem_march(), to verify */
685/* and write the test patterns to memory. The test sequence is as */
686/* follows: */
687/* 1) march writing 0000...0001 */
688/* 2) march verifying 0000...0001 , writing 0000...0010 */
689/* 3) repeat step 2 shifting masks left 1 bit each time unitl */
690/* the write mask equals 1000...0000 */
691/* 4) march verifying 1000...0000 */
692/* The test fails if any of the memory marches return a failure. */
693/* */
694/* OUTPUTS: */
695/* Displays which pass on the memory test is executing */
696/* */
697/* RETURNS: */
698/* 0 - Passed test */
699/* 1 - Failed test */
700/* */
701/* RESTRICTIONS/LIMITATIONS: */
702/* */
703/* */
704/*********************************************************************/
705int mem_test_walk (void)
706{
707 unsigned long long mask;
708 volatile unsigned long long *pmem =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200709 (volatile unsigned long long *) CONFIG_SYS_MEMTEST_START;
710 const unsigned long size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 8;
Stefan Roese45993ea2006-11-29 15:42:37 +0100711
712 unsigned int i;
713
714 mask = 0x01;
715
716 printf ("Initial Pass");
717 mem_march (pmem, size, 0x0, 0x1, 0, 1);
718
719 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
720 printf (" ");
721 printf (" ");
722 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
723
724 for (i = 0; i < 63; i++) {
725 printf ("Pass %2d", i + 2);
726 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
727 /*printf("mask: 0x%x, pass: %d, ", mask, i); */
728 return 1;
729 }
730 mask = mask << 1;
731 printf ("\b\b\b\b\b\b\b");
732 }
733
734 printf ("Last Pass");
735 if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
736 /* printf("mask: 0x%x", mask); */
737 return 1;
738 }
739 printf ("\b\b\b\b\b\b\b\b\b");
740 printf (" ");
741 printf ("\b\b\b\b\b\b\b\b\b");
742
743 return 0;
744}
745
746/*********************************************************************/
747/* NAME: testdram() - calls any enabled memory tests */
748/* */
749/* DESCRIPTION: */
750/* Runs memory tests if the environment test variables are set to */
751/* 'y'. */
752/* */
753/* INPUTS: */
754/* testdramdata - If set to 'y', data test is run. */
755/* testdramaddress - If set to 'y', address test is run. */
756/* testdramwalk - If set to 'y', walking ones test is run */
757/* */
758/* OUTPUTS: */
759/* None */
760/* */
761/* RETURNS: */
762/* 0 - Passed test */
763/* 1 - Failed test */
764/* */
765/* RESTRICTIONS/LIMITATIONS: */
766/* */
767/* */
768/*********************************************************************/
769int testdram (void)
770{
Stefan Roese45993ea2006-11-29 15:42:37 +0100771 int rundata = 0;
772 int runaddress = 0;
773 int runwalk = 0;
774
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200775#ifdef CONFIG_SYS_DRAM_TEST_DATA
Joe Hershberger864ec562012-12-11 22:16:22 -0600776 rundata = getenv_yesno("testdramdata") == 1;
Stefan Roese45993ea2006-11-29 15:42:37 +0100777#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200778#ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
Joe Hershberger864ec562012-12-11 22:16:22 -0600779 runaddress = getenv_yesno("testdramaddress") == 1;
Stefan Roese45993ea2006-11-29 15:42:37 +0100780#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200781#ifdef CONFIG_SYS_DRAM_TEST_WALK
Joe Hershberger864ec562012-12-11 22:16:22 -0600782 runwalk = getenv_yesno("testdramwalk") == 1;
Stefan Roese45993ea2006-11-29 15:42:37 +0100783#endif
784
785 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
786 printf ("Testing RAM from 0x%08x to 0x%08x ... "
787 "(don't panic... that will take a moment !!!!)\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200788 CONFIG_SYS_MEMTEST_START, CONFIG_SYS_MEMTEST_END);
789#ifdef CONFIG_SYS_DRAM_TEST_DATA
Stefan Roese45993ea2006-11-29 15:42:37 +0100790 if (rundata == 1) {
791 printf ("Test DATA ... ");
792 if (mem_test_data () == 1) {
793 printf ("failed \n");
794 return 1;
795 } else
796 printf ("ok \n");
797 }
798#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200799#ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
Stefan Roese45993ea2006-11-29 15:42:37 +0100800 if (runaddress == 1) {
801 printf ("Test ADDRESS ... ");
802 if (mem_test_address () == 1) {
803 printf ("failed \n");
804 return 1;
805 } else
806 printf ("ok \n");
807 }
808#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200809#ifdef CONFIG_SYS_DRAM_TEST_WALK
Stefan Roese45993ea2006-11-29 15:42:37 +0100810 if (runwalk == 1) {
811 printf ("Test WALKING ONEs ... ");
812 if (mem_test_walk () == 1) {
813 printf ("failed \n");
814 return 1;
815 } else
816 printf ("ok \n");
817 }
818#endif
819 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
820 printf ("passed\n");
821 return 0;
822
823}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200824#endif /* CONFIG_SYS_DRAM_TEST */
Stefan Roese45993ea2006-11-29 15:42:37 +0100825
826/* ronen - the below functions are used by the bootm function */
827/* - we map the base register to fbe00000 (same mapping as in the LSP) */
828/* - we turn off the RX gig dmas - to prevent the dma from overunning */
829/* the kernel data areas. */
830/* - we diable and invalidate the icache and dcache. */
831void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
832{
833 u32 temp;
834
835 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
836 if ((temp & 0xffff) == new_loc >> 16)
837 return;
838
839 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
840 0xffff0000) | (new_loc >> 16);
841
842 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
843
844 while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
845 new_loc |
846 (INTERNAL_SPACE_DECODE)))))
847 != temp);
848
849}
Marek Vasut83ce1092012-03-02 22:39:32 +0000850
851int board_eth_init(bd_t *bis)
852{
853 return mv6446x_eth_initialize(bis);
854}