blob: 38769e03c536b27ff3b4d6b89a9b11e2bf909141 [file] [log] [blame]
wdenk5da7f2f2004-01-03 00:43:19 +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 */
25
26/*
27 * db64360.c - main board support/init for the Galileo Eval board.
28 */
29
30#include <common.h>
31#include <74xx_7xx.h>
32#include "../include/memory.h"
33#include "../include/pci.h"
34#include "../include/mv_gen_reg.h"
35#include <net.h>
Ben Warren052a5ea2008-08-31 20:37:00 -070036#include <netdev.h>
Wolfgang Denk17725802011-11-29 22:17:48 +000037#include <linux/compiler.h>
wdenk5da7f2f2004-01-03 00:43:19 +000038
39#include "eth.h"
40#include "mpsc.h"
41#include "i2c.h"
42#include "64360.h"
43#include "mv_regs.h"
44
45#undef DEBUG
46/*#define DEBUG */
47
48#define MAP_PCI
49
50#ifdef DEBUG
51#define DP(x) x
52#else
53#define DP(x)
54#endif
55
wdenk5da7f2f2004-01-03 00:43:19 +000056/* ------------------------------------------------------------------------- */
57
58/* this is the current GT register space location */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059/* it starts at CONFIG_SYS_DFL_GT_REGS but moves later to CONFIG_SYS_GT_REGS */
wdenk5da7f2f2004-01-03 00:43:19 +000060
61/* Unfortunately, we cant change it while we are in flash, so we initialize it
62 * to the "final" value. This means that any debug_led calls before
wdenkda55c6e2004-01-20 23:12:12 +000063 * board_early_init_f wont work right (like in cpu_init_f).
wdenk5da7f2f2004-01-03 00:43:19 +000064 * See also my_remap_gt_regs below. (NTL)
65 */
66
67void board_prebootm_init (void);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020068unsigned int INTERNAL_REG_BASE_ADDR = CONFIG_SYS_GT_REGS;
wdenk5da7f2f2004-01-03 00:43:19 +000069int display_mem_map (void);
70
71/* ------------------------------------------------------------------------- */
72
73/*
74 * This is a version of the GT register space remapping function that
75 * doesn't touch globals (meaning, it's ok to run from flash.)
76 *
77 * Unfortunately, this has the side effect that a writable
78 * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
79 */
80
81void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
82{
83 u32 temp;
84
85 /* check and see if it's already moved */
86
87/* original ppcboot 1.1.6 source
88
89 temp = in_le32((u32 *)(new_loc + INTERNAL_SPACE_DECODE));
90 if ((temp & 0xffff) == new_loc >> 20)
91 return;
92
93 temp = (in_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE)) &
94 0xffff0000) | (new_loc >> 20);
95
96 out_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE), temp);
97
98 while (GTREGREAD(INTERNAL_SPACE_DECODE) != temp);
99original ppcboot 1.1.6 source end */
100
101 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
102 if ((temp & 0xffff) == new_loc >> 16)
103 return;
104
105 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
106 0xffff0000) | (new_loc >> 16);
107
108 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
109
110 while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
111}
112
113#ifdef CONFIG_PCI
114
115static void gt_pci_config (void)
116{
117 unsigned int stat;
118 unsigned int val = 0x00fff864; /* DINK32: BusNum 23:16, DevNum 15:11, FuncNum 10:8, RegNum 7:2 */
119
120 /* In PCIX mode devices provide their own bus and device numbers. 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 bus and device.
123 */
124 if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
125 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
126
127 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
128
129 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
130 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
wdenk5da7f2f2004-01-03 00:43:19 +0000132
133 }
134 if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /*if PCI-X */
135 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
136 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
137
138 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
139 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140 (stat & 0xffff0000) | CONFIG_SYS_PCI_IDSEL);
wdenk5da7f2f2004-01-03 00:43:19 +0000141 }
142
143 /* Enable master */
144 PCI_MASTER_ENABLE (0, SELF);
145 PCI_MASTER_ENABLE (1, SELF);
146
147 /* Enable PCI0/1 Mem0 and IO 0 disable all others */
148 GT_REG_READ (BASE_ADDR_ENABLE, &stat);
149 stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) | (1
150 <<
151 18);
152 stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
153 GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
154
155 /* ronen- add write to pci remap registers for 64460.
156 in 64360 when writing to pci base go and overide remap automaticaly,
157 in 64460 it doesn't */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158 GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CONFIG_SYS_PCI0_IO_BASE >> 16);
159 GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CONFIG_SYS_PCI0_IO_BASE >> 16);
160 GT_REG_WRITE (PCI_0_IO_SIZE, (CONFIG_SYS_PCI0_IO_SIZE - 1) >> 16);
wdenk5da7f2f2004-01-03 00:43:19 +0000161
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200162 GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI0_MEM_BASE >> 16);
163 GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI0_MEM_BASE >> 16);
164 GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CONFIG_SYS_PCI0_MEM_SIZE - 1) >> 16);
wdenk5da7f2f2004-01-03 00:43:19 +0000165
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CONFIG_SYS_PCI1_IO_BASE >> 16);
167 GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CONFIG_SYS_PCI1_IO_BASE >> 16);
168 GT_REG_WRITE (PCI_1_IO_SIZE, (CONFIG_SYS_PCI1_IO_SIZE - 1) >> 16);
wdenk5da7f2f2004-01-03 00:43:19 +0000169
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CONFIG_SYS_PCI1_MEM_BASE >> 16);
171 GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CONFIG_SYS_PCI1_MEM_BASE >> 16);
172 GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CONFIG_SYS_PCI1_MEM_SIZE - 1) >> 16);
wdenk5da7f2f2004-01-03 00:43:19 +0000173
174 /* PCI interface settings */
175 /* Timeout set to retry forever */
176 GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
177 GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
178
179 /* ronen - enable only CS0 and Internal reg!! */
180 GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
181 GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
182
183/*ronen update the pci internal registers base address.*/
184#ifdef MAP_PCI
185 for (stat = 0; stat <= PCI_HOST1; stat++)
186 pciWriteConfigReg (stat,
187 PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200188 SELF, CONFIG_SYS_GT_REGS);
wdenk5da7f2f2004-01-03 00:43:19 +0000189#endif
190
191}
192#endif
193
194/* Setup CPU interface paramaters */
195static void gt_cpu_config (void)
196{
197 cpu_t cpu = get_cpu_type ();
198 ulong tmp;
199
200 /* cpu configuration register */
201 tmp = GTREGREAD (CPU_CONFIGURATION);
202
203 /* set the SINGLE_CPU bit see MV64360 P.399 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200204#ifndef CONFIG_SYS_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
wdenk5da7f2f2004-01-03 00:43:19 +0000205 tmp |= CPU_CONF_SINGLE_CPU;
206#endif
207
208 tmp &= ~CPU_CONF_AACK_DELAY_2;
209
210 tmp |= CPU_CONF_DP_VALID;
211 tmp |= CPU_CONF_AP_VALID;
212
213 tmp |= CPU_CONF_PIPELINE;
214
215 GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
216
217 /* CPU master control register */
218 tmp = GTREGREAD (CPU_MASTER_CONTROL);
219
220 tmp |= CPU_MAST_CTL_ARB_EN;
221
222 if ((cpu == CPU_7400) ||
223 (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
224
225 tmp |= CPU_MAST_CTL_CLEAN_BLK;
226 tmp |= CPU_MAST_CTL_FLUSH_BLK;
227
228 } else {
229 /* cleanblock must be cleared for CPUs
230 * that do not support this command (603e, 750)
231 * see Res#1 */
232 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
233 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
234 }
235 GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
236}
237
238/*
wdenkda55c6e2004-01-20 23:12:12 +0000239 * board_early_init_f.
wdenk5da7f2f2004-01-03 00:43:19 +0000240 *
241 * set up gal. device mappings, etc.
242 */
wdenkda55c6e2004-01-20 23:12:12 +0000243int board_early_init_f (void)
wdenk5da7f2f2004-01-03 00:43:19 +0000244{
245 uchar sram_boot = 0;
246
247 /*
248 * set up the GT the way the kernel wants it
249 * the call to move the GT register space will obviously
250 * fail if it has already been done, but we're going to assume
251 * that if it's not at the power-on location, it's where we put
252 * it last time. (huber)
253 */
254
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200255 my_remap_gt_regs (CONFIG_SYS_DFL_GT_REGS, CONFIG_SYS_GT_REGS);
wdenk5da7f2f2004-01-03 00:43:19 +0000256
257 /* No PCI in first release of Port To_do: enable it. */
258#ifdef CONFIG_PCI
259 gt_pci_config ();
260#endif
261 /* mask all external interrupt sources */
262 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
263 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
264 /* new in MV6436x */
265 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
266 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
267 /* --------------------- */
268 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
269 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
270 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
271 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
272 /* does not exist in MV6436x
273 GT_REG_WRITE(CPU_INT_0_MASK, 0);
274 GT_REG_WRITE(CPU_INT_1_MASK, 0);
275 GT_REG_WRITE(CPU_INT_2_MASK, 0);
276 GT_REG_WRITE(CPU_INT_3_MASK, 0);
277 --------------------- */
278
279
280 /* ----- DEVICE BUS SETTINGS ------ */
281
282 /*
283 * EVB
284 * 0 - SRAM ????
285 * 1 - RTC ????
286 * 2 - UART ????
287 * 3 - Flash checked 32Bit Intel Strata
288 * boot - BootCS checked 8Bit 29LV040B
289 *
290 * Zuma
291 * 0 - Flash
292 * boot - BootCS
293 */
294
295 /*
296 * the dual 7450 module requires burst access to the boot
297 * device, so the serial rom copies the boot device to the
298 * on-board sram on the eval board, and updates the correct
299 * registers to boot from the sram. (device0)
300 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200301 if (memoryGetDeviceBaseAddress (DEVICE0) == CONFIG_SYS_DFL_BOOTCS_BASE)
wdenk5da7f2f2004-01-03 00:43:19 +0000302 sram_boot = 1;
303 if (!sram_boot)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200304 memoryMapDeviceSpace (DEVICE0, CONFIG_SYS_DEV0_SPACE, CONFIG_SYS_DEV0_SIZE);
wdenk5da7f2f2004-01-03 00:43:19 +0000305
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200306 memoryMapDeviceSpace (DEVICE1, CONFIG_SYS_DEV1_SPACE, CONFIG_SYS_DEV1_SIZE);
307 memoryMapDeviceSpace (DEVICE2, CONFIG_SYS_DEV2_SPACE, CONFIG_SYS_DEV2_SIZE);
308 memoryMapDeviceSpace (DEVICE3, CONFIG_SYS_DEV3_SPACE, CONFIG_SYS_DEV3_SIZE);
wdenk5da7f2f2004-01-03 00:43:19 +0000309
310
311 /* configure device timing */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200312#ifdef CONFIG_SYS_DEV0_PAR /* set port parameters for SRAM device module access */
wdenk5da7f2f2004-01-03 00:43:19 +0000313 if (!sram_boot)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200314 GT_REG_WRITE (DEVICE_BANK0PARAMETERS, CONFIG_SYS_DEV0_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000315#endif
316
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200317#ifdef CONFIG_SYS_DEV1_PAR /* set port parameters for RTC device module access */
318 GT_REG_WRITE (DEVICE_BANK1PARAMETERS, CONFIG_SYS_DEV1_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000319#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200320#ifdef CONFIG_SYS_DEV2_PAR /* set port parameters for DUART device module access */
321 GT_REG_WRITE (DEVICE_BANK2PARAMETERS, CONFIG_SYS_DEV2_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000322#endif
323
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200324#ifdef CONFIG_SYS_32BIT_BOOT_PAR /* set port parameters for Flash device module access */
wdenk5da7f2f2004-01-03 00:43:19 +0000325 /* detect if we are booting from the 32 bit flash */
326 if (GTREGREAD (DEVICE_BOOT_BANK_PARAMETERS) & (0x3 << 20)) {
327 /* 32 bit boot flash */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200328 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CONFIG_SYS_8BIT_BOOT_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000329 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200330 CONFIG_SYS_32BIT_BOOT_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000331 } else {
332 /* 8 bit boot flash */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200333 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CONFIG_SYS_32BIT_BOOT_PAR);
334 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS, CONFIG_SYS_8BIT_BOOT_PAR);
wdenk5da7f2f2004-01-03 00:43:19 +0000335 }
336#else
337 /* 8 bit boot flash only */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200338/* GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CONFIG_SYS_8BIT_BOOT_PAR);*/
wdenk5da7f2f2004-01-03 00:43:19 +0000339#endif
340
341
342 gt_cpu_config ();
343
344 /* MPP setup */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200345 GT_REG_WRITE (MPP_CONTROL0, CONFIG_SYS_MPP_CONTROL_0);
346 GT_REG_WRITE (MPP_CONTROL1, CONFIG_SYS_MPP_CONTROL_1);
347 GT_REG_WRITE (MPP_CONTROL2, CONFIG_SYS_MPP_CONTROL_2);
348 GT_REG_WRITE (MPP_CONTROL3, CONFIG_SYS_MPP_CONTROL_3);
wdenk5da7f2f2004-01-03 00:43:19 +0000349
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200350 GT_REG_WRITE (GPP_LEVEL_CONTROL, CONFIG_SYS_GPP_LEVEL_CONTROL);
wdenk5da7f2f2004-01-03 00:43:19 +0000351 DEBUG_LED0_ON ();
352 DEBUG_LED1_ON ();
353 DEBUG_LED2_ON ();
354
355 return 0;
356}
357
358/* various things to do after relocation */
359
360int misc_init_r ()
361{
362 icache_enable ();
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200363#ifdef CONFIG_SYS_L2
wdenk5da7f2f2004-01-03 00:43:19 +0000364 l2cache_enable ();
365#endif
366#ifdef CONFIG_MPSC
367
368 mpsc_sdma_init ();
369 mpsc_init2 ();
370#endif
371
372#if 0
373 /* disable the dcache and MMU */
374 dcache_lock ();
375#endif
376 return 0;
377}
378
379void after_reloc (ulong dest_addr, gd_t * gd)
380{
381 /* check to see if we booted from the sram. If so, move things
382 * back to the way they should be. (we're running from main
383 * memory at this point now */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200384 if (memoryGetDeviceBaseAddress (DEVICE0) == CONFIG_SYS_DFL_BOOTCS_BASE) {
385 memoryMapDeviceSpace (DEVICE0, CONFIG_SYS_DEV0_SPACE, CONFIG_SYS_DEV0_SIZE);
386 memoryMapDeviceSpace (BOOT_DEVICE, CONFIG_SYS_DFL_BOOTCS_BASE, _8M);
wdenk5da7f2f2004-01-03 00:43:19 +0000387 }
388 display_mem_map ();
389 /* now, jump to the main ppcboot board init code */
390 board_init_r (gd, dest_addr);
391 /* NOTREACHED */
392}
393
394/* ------------------------------------------------------------------------- */
395
396/*
397 * Check Board Identity:
398 *
399 * right now, assume borad type. (there is just one...after all)
400 */
401
402int checkboard (void)
403{
404 int l_type = 0;
405
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200406 printf ("BOARD: %s\n", CONFIG_SYS_BOARD_NAME);
wdenk5da7f2f2004-01-03 00:43:19 +0000407 return (l_type);
408}
409
410/* utility functions */
411void debug_led (int led, int mode)
412{
413 volatile int *addr = 0;
Wolfgang Denk17725802011-11-29 22:17:48 +0000414 __maybe_unused int dummy;
wdenk5da7f2f2004-01-03 00:43:19 +0000415
416 if (mode == 1) {
417 switch (led) {
418 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200419 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000420 0x08000);
421 break;
422
423 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200424 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000425 0x0c000);
426 break;
427
428 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200429 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000430 0x10000);
431 break;
432 }
433 } else if (mode == 0) {
434 switch (led) {
435 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200436 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000437 0x14000);
438 break;
439
440 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200441 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000442 0x18000);
443 break;
444
445 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200446 addr = (int *) ((unsigned int) CONFIG_SYS_DEV1_SPACE |
wdenk5da7f2f2004-01-03 00:43:19 +0000447 0x1c000);
448 break;
449 }
450 }
451
452 dummy = *addr;
453}
454
455int display_mem_map (void)
456{
457 int i, j;
458 unsigned int base, size, width;
459
460 /* SDRAM */
461 printf ("SD (DDR) RAM\n");
462 for (i = 0; i <= BANK3; i++) {
463 base = memoryGetBankBaseAddress (i);
464 size = memoryGetBankSize (i);
465 if (size != 0) {
466 printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
467 i, base, size >> 20);
468 }
469 }
470
471 /* CPU's PCI windows */
472 for (i = 0; i <= PCI_HOST1; i++) {
473 printf ("\nCPU's PCI %d windows\n", i);
474 base = pciGetSpaceBase (i, PCI_IO);
475 size = pciGetSpaceSize (i, PCI_IO);
476 printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
477 size >> 20);
478 for (j = 0;
479 j <=
480 PCI_REGION0
481 /*ronen currently only first PCI MEM is used 3 */ ;
482 j++) {
483 base = pciGetSpaceBase (i, j);
484 size = pciGetSpaceSize (i, j);
485 printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n", j, base, size >> 20);
486 }
487 }
488
489 /* Devices */
490 printf ("\nDEVICES\n");
491 for (i = 0; i <= DEVICE3; i++) {
492 base = memoryGetDeviceBaseAddress (i);
493 size = memoryGetDeviceSize (i);
494 width = memoryGetDeviceWidth (i) * 8;
495 printf ("DEV %d: base - 0x%08x size - %dM bytes\twidth - %d bits", i, base, size >> 20, width);
496 if (i == 0)
497 printf ("\t- EXT SRAM (actual - 1M)\n");
498 else if (i == 1)
499 printf ("\t- RTC\n");
500 else if (i == 2)
501 printf ("\t- UART\n");
502 else
503 printf ("\t- LARGE FLASH\n");
504 }
505
506 /* Bootrom */
507 base = memoryGetDeviceBaseAddress (BOOT_DEVICE); /* Boot */
508 size = memoryGetDeviceSize (BOOT_DEVICE);
509 width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
510 printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\n",
511 base, size >> 20, width);
512 return (0);
513}
514
515/* DRAM check routines copied from gw8260 */
516
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200517#if defined (CONFIG_SYS_DRAM_TEST)
wdenk5da7f2f2004-01-03 00:43:19 +0000518
519/*********************************************************************/
520/* NAME: move64() - moves a double word (64-bit) */
521/* */
522/* DESCRIPTION: */
523/* this function performs a double word move from the data at */
524/* the source pointer to the location at the destination pointer. */
525/* */
526/* INPUTS: */
527/* unsigned long long *src - pointer to data to move */
528/* */
529/* OUTPUTS: */
530/* unsigned long long *dest - pointer to locate to move data */
531/* */
532/* RETURNS: */
533/* None */
534/* */
535/* RESTRICTIONS/LIMITATIONS: */
536/* May cloober fr0. */
537/* */
538/*********************************************************************/
539static void move64 (unsigned long long *src, unsigned long long *dest)
540{
541 asm ("lfd 0, 0(3)\n\t" /* fpr0 = *scr */
542 "stfd 0, 0(4)" /* *dest = fpr0 */
543 : : : "fr0"); /* Clobbers fr0 */
544 return;
545}
546
547
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200548#if defined (CONFIG_SYS_DRAM_TEST_DATA)
wdenk5da7f2f2004-01-03 00:43:19 +0000549
550unsigned long long pattern[] = {
wdenka0ebde52004-09-08 22:03:11 +0000551 0xaaaaaaaaaaaaaaaaULL,
552 0xccccccccccccccccULL,
553 0xf0f0f0f0f0f0f0f0ULL,
554 0xff00ff00ff00ff00ULL,
555 0xffff0000ffff0000ULL,
556 0xffffffff00000000ULL,
557 0x00000000ffffffffULL,
558 0x0000ffff0000ffffULL,
559 0x00ff00ff00ff00ffULL,
560 0x0f0f0f0f0f0f0f0fULL,
561 0x3333333333333333ULL,
562 0x5555555555555555ULL,
wdenk5da7f2f2004-01-03 00:43:19 +0000563};
564
565/*********************************************************************/
566/* NAME: mem_test_data() - test data lines for shorts and opens */
567/* */
568/* DESCRIPTION: */
569/* Tests data lines for shorts and opens by forcing adjacent data */
570/* to opposite states. Because the data lines could be routed in */
571/* an arbitrary manner the must ensure test patterns ensure that */
572/* every case is tested. By using the following series of binary */
573/* patterns every combination of adjacent bits is test regardless */
574/* of routing. */
575/* */
576/* ...101010101010101010101010 */
577/* ...110011001100110011001100 */
578/* ...111100001111000011110000 */
579/* ...111111110000000011111111 */
580/* */
581/* Carrying this out, gives us six hex patterns as follows: */
582/* */
583/* 0xaaaaaaaaaaaaaaaa */
584/* 0xcccccccccccccccc */
585/* 0xf0f0f0f0f0f0f0f0 */
586/* 0xff00ff00ff00ff00 */
587/* 0xffff0000ffff0000 */
588/* 0xffffffff00000000 */
589/* */
590/* The number test patterns will always be given by: */
591/* */
592/* log(base 2)(number data bits) = log2 (64) = 6 */
593/* */
594/* To test for short and opens to other signals on our boards. we */
595/* simply */
596/* test with the 1's complemnt of the paterns as well. */
597/* */
598/* OUTPUTS: */
599/* Displays failing test pattern */
600/* */
601/* RETURNS: */
602/* 0 - Passed test */
603/* 1 - Failed test */
604/* */
605/* RESTRICTIONS/LIMITATIONS: */
606/* Assumes only one one SDRAM bank */
607/* */
608/*********************************************************************/
609int mem_test_data (void)
610{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200611 unsigned long long *pmem = (unsigned long long *) CONFIG_SYS_MEMTEST_START;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200612 unsigned long long temp64 = 0;
wdenk5da7f2f2004-01-03 00:43:19 +0000613 int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
614 int i;
615 unsigned int hi, lo;
616
617 for (i = 0; i < num_patterns; i++) {
618 move64 (&(pattern[i]), pmem);
619 move64 (pmem, &temp64);
620
621 /* hi = (temp64>>32) & 0xffffffff; */
622 /* lo = temp64 & 0xffffffff; */
623 /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
624
625 hi = (pattern[i] >> 32) & 0xffffffff;
626 lo = pattern[i] & 0xffffffff;
627 /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo); */
628
629 if (temp64 != pattern[i]) {
630 printf ("\n Data Test Failed, pattern 0x%08x%08x",
631 hi, lo);
632 return 1;
633 }
634 }
635
636 return 0;
637}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200638#endif /* CONFIG_SYS_DRAM_TEST_DATA */
wdenk5da7f2f2004-01-03 00:43:19 +0000639
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200640#if defined (CONFIG_SYS_DRAM_TEST_ADDRESS)
wdenk5da7f2f2004-01-03 00:43:19 +0000641/*********************************************************************/
642/* NAME: mem_test_address() - test address lines */
643/* */
644/* DESCRIPTION: */
645/* This function performs a test to verify that each word im */
646/* memory is uniquly addressable. The test sequence is as follows: */
647/* */
648/* 1) write the address of each word to each word. */
649/* 2) verify that each location equals its address */
650/* */
651/* OUTPUTS: */
652/* Displays failing test pattern and address */
653/* */
654/* RETURNS: */
655/* 0 - Passed test */
656/* 1 - Failed test */
657/* */
658/* RESTRICTIONS/LIMITATIONS: */
659/* */
660/* */
661/*********************************************************************/
662int mem_test_address (void)
663{
664 volatile unsigned int *pmem =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200665 (volatile unsigned int *) CONFIG_SYS_MEMTEST_START;
666 const unsigned int size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 4;
wdenk5da7f2f2004-01-03 00:43:19 +0000667 unsigned int i;
668
669 /* write address to each location */
670 for (i = 0; i < size; i++) {
671 pmem[i] = i;
672 }
673
674 /* verify each loaction */
675 for (i = 0; i < size; i++) {
676 if (pmem[i] != i) {
677 printf ("\n Address Test Failed at 0x%x", i);
678 return 1;
679 }
680 }
681 return 0;
682}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200683#endif /* CONFIG_SYS_DRAM_TEST_ADDRESS */
wdenk5da7f2f2004-01-03 00:43:19 +0000684
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200685#if defined (CONFIG_SYS_DRAM_TEST_WALK)
wdenk5da7f2f2004-01-03 00:43:19 +0000686/*********************************************************************/
687/* NAME: mem_march() - memory march */
688/* */
689/* DESCRIPTION: */
690/* Marches up through memory. At each location verifies rmask if */
691/* read = 1. At each location write wmask if write = 1. Displays */
692/* failing address and pattern. */
693/* */
694/* INPUTS: */
695/* volatile unsigned long long * base - start address of test */
696/* unsigned int size - number of dwords(64-bit) to test */
697/* unsigned long long rmask - read verify mask */
698/* unsigned long long wmask - wrtie verify mask */
699/* short read - verifies rmask if read = 1 */
700/* short write - writes wmask if write = 1 */
701/* */
702/* OUTPUTS: */
703/* Displays failing test pattern and address */
704/* */
705/* RETURNS: */
706/* 0 - Passed test */
707/* 1 - Failed test */
708/* */
709/* RESTRICTIONS/LIMITATIONS: */
710/* */
711/* */
712/*********************************************************************/
713int mem_march (volatile unsigned long long *base,
714 unsigned int size,
715 unsigned long long rmask,
716 unsigned long long wmask, short read, short write)
717{
718 unsigned int i;
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200719 unsigned long long temp = 0;
wdenk5da7f2f2004-01-03 00:43:19 +0000720 unsigned int hitemp, lotemp, himask, lomask;
721
722 for (i = 0; i < size; i++) {
723 if (read != 0) {
724 /* temp = base[i]; */
725 move64 ((unsigned long long *) &(base[i]), &temp);
726 if (rmask != temp) {
727 hitemp = (temp >> 32) & 0xffffffff;
728 lotemp = temp & 0xffffffff;
729 himask = (rmask >> 32) & 0xffffffff;
730 lomask = rmask & 0xffffffff;
731
732 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);
733 return 1;
734 }
735 }
736 if (write != 0) {
737 /* base[i] = wmask; */
738 move64 (&wmask, (unsigned long long *) &(base[i]));
739 }
740 }
741 return 0;
742}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200743#endif /* CONFIG_SYS_DRAM_TEST_WALK */
wdenk5da7f2f2004-01-03 00:43:19 +0000744
745/*********************************************************************/
746/* NAME: mem_test_walk() - a simple walking ones test */
747/* */
748/* DESCRIPTION: */
749/* Performs a walking ones through entire physical memory. The */
750/* test uses as series of memory marches, mem_march(), to verify */
751/* and write the test patterns to memory. The test sequence is as */
752/* follows: */
753/* 1) march writing 0000...0001 */
754/* 2) march verifying 0000...0001 , writing 0000...0010 */
755/* 3) repeat step 2 shifting masks left 1 bit each time unitl */
756/* the write mask equals 1000...0000 */
757/* 4) march verifying 1000...0000 */
758/* The test fails if any of the memory marches return a failure. */
759/* */
760/* OUTPUTS: */
761/* Displays which pass on the memory test is executing */
762/* */
763/* RETURNS: */
764/* 0 - Passed test */
765/* 1 - Failed test */
766/* */
767/* RESTRICTIONS/LIMITATIONS: */
768/* */
769/* */
770/*********************************************************************/
771int mem_test_walk (void)
772{
773 unsigned long long mask;
774 volatile unsigned long long *pmem =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200775 (volatile unsigned long long *) CONFIG_SYS_MEMTEST_START;
776 const unsigned long size = (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START) / 8;
wdenk5da7f2f2004-01-03 00:43:19 +0000777
778 unsigned int i;
779
780 mask = 0x01;
781
782 printf ("Initial Pass");
783 mem_march (pmem, size, 0x0, 0x1, 0, 1);
784
785 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
786 printf (" ");
787 printf (" ");
788 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
789
790 for (i = 0; i < 63; i++) {
791 printf ("Pass %2d", i + 2);
792 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
793 /*printf("mask: 0x%x, pass: %d, ", mask, i); */
794 return 1;
795 }
796 mask = mask << 1;
797 printf ("\b\b\b\b\b\b\b");
798 }
799
800 printf ("Last Pass");
801 if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
802 /* printf("mask: 0x%x", mask); */
803 return 1;
804 }
805 printf ("\b\b\b\b\b\b\b\b\b");
806 printf (" ");
807 printf ("\b\b\b\b\b\b\b\b\b");
808
809 return 0;
810}
811
812/*********************************************************************/
813/* NAME: testdram() - calls any enabled memory tests */
814/* */
815/* DESCRIPTION: */
816/* Runs memory tests if the environment test variables are set to */
817/* 'y'. */
818/* */
819/* INPUTS: */
820/* testdramdata - If set to 'y', data test is run. */
821/* testdramaddress - If set to 'y', address test is run. */
822/* testdramwalk - If set to 'y', walking ones test is run */
823/* */
824/* OUTPUTS: */
825/* None */
826/* */
827/* RETURNS: */
828/* 0 - Passed test */
829/* 1 - Failed test */
830/* */
831/* RESTRICTIONS/LIMITATIONS: */
832/* */
833/* */
834/*********************************************************************/
835int testdram (void)
836{
wdenk5da7f2f2004-01-03 00:43:19 +0000837 int rundata, runaddress, runwalk;
838
Joe Hershberger864ec562012-12-11 22:16:22 -0600839 rundata = getenv_yesno("testdramdata") == 1;
840 runaddress = getenv_yesno("testdramaddress") == 1;
841 runwalk = getenv_yesno("testdramwalk") == 1;
wdenk5da7f2f2004-01-03 00:43:19 +0000842
843/* rundata = 1; */
844/* runaddress = 0; */
845/* runwalk = 0; */
846
847 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200848 printf ("Testing RAM from 0x%08x to 0x%08x ... (don't panic... that will take a moment !!!!)\n", CONFIG_SYS_MEMTEST_START, CONFIG_SYS_MEMTEST_END);
wdenk5da7f2f2004-01-03 00:43:19 +0000849 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200850#ifdef CONFIG_SYS_DRAM_TEST_DATA
wdenk5da7f2f2004-01-03 00:43:19 +0000851 if (rundata == 1) {
852 printf ("Test DATA ... ");
853 if (mem_test_data () == 1) {
854 printf ("failed \n");
855 return 1;
856 } else
857 printf ("ok \n");
858 }
859#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200860#ifdef CONFIG_SYS_DRAM_TEST_ADDRESS
wdenk5da7f2f2004-01-03 00:43:19 +0000861 if (runaddress == 1) {
862 printf ("Test ADDRESS ... ");
863 if (mem_test_address () == 1) {
864 printf ("failed \n");
865 return 1;
866 } else
867 printf ("ok \n");
868 }
869#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200870#ifdef CONFIG_SYS_DRAM_TEST_WALK
wdenk5da7f2f2004-01-03 00:43:19 +0000871 if (runwalk == 1) {
872 printf ("Test WALKING ONEs ... ");
873 if (mem_test_walk () == 1) {
874 printf ("failed \n");
875 return 1;
876 } else
877 printf ("ok \n");
878 }
879#endif
880 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
881 printf ("passed\n");
882 }
883 return 0;
884
885}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200886#endif /* CONFIG_SYS_DRAM_TEST */
wdenk5da7f2f2004-01-03 00:43:19 +0000887
888/* ronen - the below functions are used by the bootm function */
889/* - we map the base register to fbe00000 (same mapping as in the LSP) */
890/* - we turn off the RX gig dmas - to prevent the dma from overunning */
891/* the kernel data areas. */
892/* - we diable and invalidate the icache and dcache. */
893void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
894{
895 u32 temp;
896
897 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
898 if ((temp & 0xffff) == new_loc >> 16)
899 return;
900
901 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
902 0xffff0000) | (new_loc >> 16);
903
904 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
905
906 while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
907 new_loc |
908 (INTERNAL_SPACE_DECODE)))))
909 != temp);
910
911}
912
913void board_prebootm_init ()
914{
915
916/* change window size of PCI1 IO in order tp prevent overlaping with REG BASE. */
917 GT_REG_WRITE (PCI_1_IO_SIZE, (_64K - 1) >> 16);
918
919/* Stop GigE Rx DMA engines */
920 GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (0), 0x0000ff00);
921 GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (1), 0x0000ff00);
922/* MV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG(2), 0x0000ff00); */
923
924/* Relocate MV64360 internal regs */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200925 my_remap_gt_regs_bootm (CONFIG_SYS_GT_REGS, BRIDGE_REG_BASE_BOOTM);
wdenk5da7f2f2004-01-03 00:43:19 +0000926
927 icache_disable ();
wdenk5da7f2f2004-01-03 00:43:19 +0000928 dcache_disable ();
929}
Ben Warren052a5ea2008-08-31 20:37:00 -0700930
931int board_eth_init(bd_t *bis)
932{
Marek Vasutdd152fc2012-03-02 22:39:31 +0000933 int ret;
934 ret = pci_eth_init(bis);
935 if (!ret)
936 ret = mv6436x_eth_initialize(bis);
937 return ret;
Ben Warren052a5ea2008-08-31 20:37:00 -0700938}