blob: 3bdbdd17d315c11bd4464e3da6a11c6ee24c7ea3 [file] [log] [blame]
wdenk16f21702002-08-26 21:58:50 +00001/*
2 * (C) Copyright 2000, 2001
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 * Ulrich Lutz, Speech Design GmbH, ulutz@datalab.de.
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenk16f21702002-08-26 21:58:50 +00007 */
8
9#include <common.h>
10#include <mpc8xx.h>
11#include <commproc.h>
12
13#ifdef CONFIG_STATUS_LED
14# include <status_led.h>
15#endif
16
17/* ------------------------------------------------------------------------- */
18
19static long int dram_size (long int, long int *, long int);
20
21/* ------------------------------------------------------------------------- */
22
23#define _NOT_USED_ 0xFFFFFFFF
24
25/*
26 * 50 MHz SHARC access using UPM A
27 */
wdenkc83bf6a2004-01-06 22:38:14 +000028const uint sharc_table[] = {
wdenk16f21702002-08-26 21:58:50 +000029 /*
30 * Single Read. (Offset 0 in UPM RAM)
31 */
32 0x0FF3FC04, 0x0FF3EC00, 0x7FFFEC04, 0xFFFFEC04,
wdenkc83bf6a2004-01-06 22:38:14 +000033 0xFFFFEC05, /* last */
34 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +000035 /*
36 * Burst Read. (Offset 8 in UPM RAM)
37 */
38 /* last */
39 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
40 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
41 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
42 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
43 /*
44 * Single Write. (Offset 18 in UPM RAM)
45 */
46 0x0FAFFC04, 0x0FAFEC00, 0x7FFFEC04, 0xFFFFEC04,
wdenkc83bf6a2004-01-06 22:38:14 +000047 0xFFFFEC05, /* last */
48 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +000049 /*
50 * Burst Write. (Offset 20 in UPM RAM)
51 */
52 /* last */
53 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
54 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
55 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
56 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
57 /*
58 * Refresh (Offset 30 in UPM RAM)
59 */
60 /* last */
61 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
62 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
63 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
64 /*
65 * Exception. (Offset 3c in UPM RAM)
66 */
wdenkc83bf6a2004-01-06 22:38:14 +000067 0x7FFFFC07, /* last */
68 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +000069};
70
71
72/*
73 * 50 MHz SDRAM access using UPM B
74 */
wdenkc83bf6a2004-01-06 22:38:14 +000075const uint sdram_table[] = {
wdenk16f21702002-08-26 21:58:50 +000076 /*
77 * Single Read. (Offset 0 in UPM RAM)
78 */
79 0x0E26FC04, 0x11ADFC04, 0xEFBBBC00, 0x1FF77C45, /* last */
80 _NOT_USED_,
81 /*
82 * SDRAM Initialization (offset 5 in UPM RAM)
83 *
wdenk8bde7f72003-06-27 21:31:46 +000084 * This is no UPM entry point. The following definition uses
85 * the remaining space to establish an initialization
86 * sequence, which is executed by a RUN command.
wdenk16f21702002-08-26 21:58:50 +000087 *
88 */
wdenkc83bf6a2004-01-06 22:38:14 +000089 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
wdenk16f21702002-08-26 21:58:50 +000090 /*
91 * Burst Read. (Offset 8 in UPM RAM)
92 */
93 0x0E26FC04, 0x10ADFC04, 0xF0AFFC00, 0xF0AFFC00,
wdenkc83bf6a2004-01-06 22:38:14 +000094 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C45, /* last */
95 _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +000096 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
97 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
98 /*
99 * Single Write. (Offset 18 in UPM RAM)
100 */
wdenkc83bf6a2004-01-06 22:38:14 +0000101 0x1F27FC04, 0xEEAEBC04, 0x01B93C00, 0x1FF77C45, /* last */
wdenk16f21702002-08-26 21:58:50 +0000102 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
103 /*
104 * Burst Write. (Offset 20 in UPM RAM)
105 */
106 0x0E26BC00, 0x10AD7C00, 0xF0AFFC00, 0xF0AFFC00,
wdenkc83bf6a2004-01-06 22:38:14 +0000107 0xE1BBBC04, 0x1FF77C45, /* last */
108 _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +0000109 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
110 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
111 /*
112 * Refresh (Offset 30 in UPM RAM)
113 */
114 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC84,
wdenkc83bf6a2004-01-06 22:38:14 +0000115 0xFFFFFC05, /* last */
116 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +0000117 _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
118 /*
119 * Exception. (Offset 3c in UPM RAM)
120 */
wdenkc83bf6a2004-01-06 22:38:14 +0000121 0x7FFFFC07, /* last */
122 _NOT_USED_, _NOT_USED_, _NOT_USED_,
wdenk16f21702002-08-26 21:58:50 +0000123};
124
125/* ------------------------------------------------------------------------- */
126
127
128/*
129 * Check Board Identity:
130 *
131 */
132
133int checkboard (void)
134{
135#ifdef CONFIG_IVMS8
136 puts ("Board: IVMS8\n");
137#endif
138#ifdef CONFIG_IVML24
139 puts ("Board: IVM-L8/24\n");
140#endif
141 return (0);
142}
143
144/* ------------------------------------------------------------------------- */
145
Becky Bruce9973e3c2008-06-09 16:03:40 -0500146phys_size_t initdram (int board_type)
wdenk16f21702002-08-26 21:58:50 +0000147{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200148 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkc83bf6a2004-01-06 22:38:14 +0000149 volatile memctl8xx_t *memctl = &immr->im_memctl;
150 long int size_b0;
wdenk16f21702002-08-26 21:58:50 +0000151
wdenkc83bf6a2004-01-06 22:38:14 +0000152 /* enable SDRAM clock ("switch on" SDRAM) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200153 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_SDRAM_CLKE); /* GPIO */
154 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_SDRAM_CLKE); /* active output */
155 immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_SDRAM_CLKE; /* output */
156 immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_SDRAM_CLKE; /* assert SDRAM CLKE */
wdenkc83bf6a2004-01-06 22:38:14 +0000157 udelay (1);
wdenk16f21702002-08-26 21:58:50 +0000158
wdenkc83bf6a2004-01-06 22:38:14 +0000159 /*
160 * Map controller bank 1 for ELIC SACCO
161 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200162 memctl->memc_or1 = CONFIG_SYS_OR1;
163 memctl->memc_br1 = CONFIG_SYS_BR1;
wdenk16f21702002-08-26 21:58:50 +0000164
wdenkc83bf6a2004-01-06 22:38:14 +0000165 /*
166 * Map controller bank 2 for ELIC EPIC
167 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200168 memctl->memc_or2 = CONFIG_SYS_OR2;
169 memctl->memc_br2 = CONFIG_SYS_BR2;
wdenk16f21702002-08-26 21:58:50 +0000170
wdenkc83bf6a2004-01-06 22:38:14 +0000171 /*
172 * Configure UPMA for SHARC
173 */
174 upmconfig (UPMA, (uint *) sharc_table,
175 sizeof (sharc_table) / sizeof (uint));
wdenk16f21702002-08-26 21:58:50 +0000176
177#if defined(CONFIG_IVML24)
wdenkc83bf6a2004-01-06 22:38:14 +0000178 /*
179 * Map controller bank 4 for HDLC Address space
180 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181 memctl->memc_or4 = CONFIG_SYS_OR4;
182 memctl->memc_br4 = CONFIG_SYS_BR4;
wdenk16f21702002-08-26 21:58:50 +0000183#endif
184
wdenkc83bf6a2004-01-06 22:38:14 +0000185 /*
186 * Map controller bank 5 for SHARC
187 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200188 memctl->memc_or5 = CONFIG_SYS_OR5;
189 memctl->memc_br5 = CONFIG_SYS_BR5;
wdenk16f21702002-08-26 21:58:50 +0000190
wdenkc83bf6a2004-01-06 22:38:14 +0000191 memctl->memc_mamr = 0x00001000;
wdenk16f21702002-08-26 21:58:50 +0000192
wdenkc83bf6a2004-01-06 22:38:14 +0000193 /*
194 * Configure UPMB for SDRAM
195 */
196 upmconfig (UPMB, (uint *) sdram_table,
197 sizeof (sdram_table) / sizeof (uint));
wdenk16f21702002-08-26 21:58:50 +0000198
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200199 memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_8K;
wdenk16f21702002-08-26 21:58:50 +0000200
wdenkc83bf6a2004-01-06 22:38:14 +0000201 memctl->memc_mar = 0x00000088;
wdenk16f21702002-08-26 21:58:50 +0000202
wdenkc83bf6a2004-01-06 22:38:14 +0000203 /*
204 * Map controller bank 3 to the SDRAM bank at preliminary address.
205 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200206 memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
207 memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
wdenk16f21702002-08-26 21:58:50 +0000208
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200209 memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL; /* refresh not enabled yet */
wdenk16f21702002-08-26 21:58:50 +0000210
wdenkc83bf6a2004-01-06 22:38:14 +0000211 udelay (200);
212 memctl->memc_mcr = 0x80806105; /* precharge */
213 udelay (1);
214 memctl->memc_mcr = 0x80806106; /* load mode register */
215 udelay (1);
216 memctl->memc_mcr = 0x80806130; /* autorefresh */
217 udelay (1);
218 memctl->memc_mcr = 0x80806130; /* autorefresh */
219 udelay (1);
220 memctl->memc_mcr = 0x80806130; /* autorefresh */
221 udelay (1);
222 memctl->memc_mcr = 0x80806130; /* autorefresh */
223 udelay (1);
224 memctl->memc_mcr = 0x80806130; /* autorefresh */
225 udelay (1);
226 memctl->memc_mcr = 0x80806130; /* autorefresh */
227 udelay (1);
228 memctl->memc_mcr = 0x80806130; /* autorefresh */
229 udelay (1);
230 memctl->memc_mcr = 0x80806130; /* autorefresh */
wdenk16f21702002-08-26 21:58:50 +0000231
wdenkc83bf6a2004-01-06 22:38:14 +0000232 memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */
wdenk16f21702002-08-26 21:58:50 +0000233
wdenkc83bf6a2004-01-06 22:38:14 +0000234 /*
235 * Check Bank 0 Memory Size for re-configuration
236 */
237 size_b0 =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200238 dram_size (CONFIG_SYS_MBMR_8COL, (long *) SDRAM_BASE3_PRELIM,
wdenkc83bf6a2004-01-06 22:38:14 +0000239 SDRAM_MAX_SIZE);
wdenk16f21702002-08-26 21:58:50 +0000240
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200241 memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE;
wdenk16f21702002-08-26 21:58:50 +0000242
wdenkc83bf6a2004-01-06 22:38:14 +0000243 return (size_b0);
wdenk16f21702002-08-26 21:58:50 +0000244}
245
246/* ------------------------------------------------------------------------- */
247
248/*
249 * Check memory range for valid RAM. A simple memory test determines
250 * the actually available RAM size between addresses `base' and
251 * `base + maxsize'. Some (not all) hardware errors are detected:
252 * - short between address lines
253 * - short between data lines
254 */
255
wdenkc83bf6a2004-01-06 22:38:14 +0000256static long int dram_size (long int mamr_value, long int *base,
257 long int maxsize)
wdenk16f21702002-08-26 21:58:50 +0000258{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200259 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenkc83bf6a2004-01-06 22:38:14 +0000260 volatile memctl8xx_t *memctl = &immr->im_memctl;
wdenk16f21702002-08-26 21:58:50 +0000261
wdenkc83bf6a2004-01-06 22:38:14 +0000262 memctl->memc_mbmr = mamr_value;
wdenk16f21702002-08-26 21:58:50 +0000263
wdenkc83bf6a2004-01-06 22:38:14 +0000264 return (get_ram_size (base, maxsize));
wdenk16f21702002-08-26 21:58:50 +0000265}
266
267/* ------------------------------------------------------------------------- */
268
wdenkc83bf6a2004-01-06 22:38:14 +0000269void reset_phy (void)
wdenk16f21702002-08-26 21:58:50 +0000270{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200271 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
wdenk16f21702002-08-26 21:58:50 +0000272
273 /* De-assert Ethernet Powerdown */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200274 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_ETH_POWERDOWN); /* GPIO */
275 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_ETH_POWERDOWN); /* active output */
276 immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_ETH_POWERDOWN; /* output */
277 immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_ETH_POWERDOWN); /* Enable PHY power */
wdenkc83bf6a2004-01-06 22:38:14 +0000278 udelay (1000);
wdenk16f21702002-08-26 21:58:50 +0000279
280 /*
wdenk8bde7f72003-06-27 21:31:46 +0000281 * RESET is implemented by a positive pulse of at least 1 us
282 * at the reset pin.
wdenk16f21702002-08-26 21:58:50 +0000283 *
284 * Configure RESET pins for NS DP83843 PHY, and RESET chip.
285 *
286 * Note: The RESET pin is high active, but there is an
wdenkc83bf6a2004-01-06 22:38:14 +0000287 * inverter on the SPD823TS board...
wdenk16f21702002-08-26 21:58:50 +0000288 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200289 immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_ETH_RESET);
290 immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_ETH_RESET;
wdenk16f21702002-08-26 21:58:50 +0000291 /* assert RESET signal of PHY */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200292 immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_ETH_RESET);
wdenk16f21702002-08-26 21:58:50 +0000293 udelay (10);
294 /* de-assert RESET signal of PHY */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200295 immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_ETH_RESET;
wdenk16f21702002-08-26 21:58:50 +0000296 udelay (10);
297}
298
299/* ------------------------------------------------------------------------- */
300
301void show_boot_progress (int status)
302{
303#if defined(CONFIG_STATUS_LED)
304# if defined(STATUS_LED_YELLOW)
305 status_led_set (STATUS_LED_YELLOW,
306 (status < 0) ? STATUS_LED_ON : STATUS_LED_OFF);
wdenkc83bf6a2004-01-06 22:38:14 +0000307# endif /* STATUS_LED_YELLOW */
wdenk16f21702002-08-26 21:58:50 +0000308# if defined(STATUS_LED_BOOT)
Simon Glass5dc88712012-01-14 15:24:47 +0000309 if (status == BOOTSTAGE_ID_DECOMP_IMAGE)
wdenkc83bf6a2004-01-06 22:38:14 +0000310 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
311# endif /* STATUS_LED_BOOT */
wdenk16f21702002-08-26 21:58:50 +0000312#endif /* CONFIG_STATUS_LED */
313}
314
315/* ------------------------------------------------------------------------- */
316
wdenkc83bf6a2004-01-06 22:38:14 +0000317void ide_set_reset (int on)
wdenk16f21702002-08-26 21:58:50 +0000318{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200319 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Pavel Herrmanne4148c12012-10-07 05:56:07 +0000320 int i;
wdenk16f21702002-08-26 21:58:50 +0000321
322 /*
323 * Configure PC for IDE Reset Pin
324 */
325 if (on) { /* assert RESET */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200326 immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET);
Pavel Herrmanne4148c12012-10-07 05:56:07 +0000327
328#ifdef CONFIG_SYS_PB_12V_ENABLE
329 /* 12V Enable output OFF */
330 immr->im_cpm.cp_pbdat &= ~(CONFIG_SYS_PB_12V_ENABLE);
331
332 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_12V_ENABLE);
333 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_12V_ENABLE);
334 immr->im_cpm.cp_pbdir |= CONFIG_SYS_PB_12V_ENABLE;
335
336 /* wait 500 ms for the voltage to stabilize */
337 for (i = 0; i < 500; ++i)
338 udelay(1000);
339#endif /* CONFIG_SYS_PB_12V_ENABLE */
wdenk16f21702002-08-26 21:58:50 +0000340 } else { /* release RESET */
Pavel Herrmanne4148c12012-10-07 05:56:07 +0000341#ifdef CONFIG_SYS_PB_12V_ENABLE
342 /* 12V Enable output ON */
343 immr->im_cpm.cp_pbdat |= CONFIG_SYS_PB_12V_ENABLE;
344#endif /* CONFIG_SYS_PB_12V_ENABLE */
345
346#ifdef CONFIG_SYS_PB_IDE_MOTOR
347 /* configure IDE Motor voltage monitor pin as input */
348 immr->im_cpm.cp_pbpar &= ~(CONFIG_SYS_PB_IDE_MOTOR);
349 immr->im_cpm.cp_pbodr &= ~(CONFIG_SYS_PB_IDE_MOTOR);
350 immr->im_cpm.cp_pbdir &= ~(CONFIG_SYS_PB_IDE_MOTOR);
351
352/* wait up to 1 s for the motor voltage to stabilize */
353 for (i = 0; i < 1000; ++i) {
354 if ((immr->im_cpm.cp_pbdat
355 & CONFIG_SYS_PB_IDE_MOTOR) != 0)
356 break;
357 udelay(1000);
358 }
359
360 if (i == 1000) { /* Timeout */
361 printf("\nWarning: 5V for IDE Motor missing\n");
362#ifdef CONFIG_STATUS_LED
363#ifdef STATUS_LED_YELLOW
364 status_led_set(STATUS_LED_YELLOW, STATUS_LED_ON);
365#endif
366#ifdef STATUS_LED_GREEN
367 status_led_set(STATUS_LED_GREEN, STATUS_LED_OFF);
368#endif
369#endif /* CONFIG_STATUS_LED */
370 }
371#endif /* CONFIG_SYS_PB_IDE_MOTOR */
372
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200373 immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET;
wdenk16f21702002-08-26 21:58:50 +0000374 }
375
376 /* program port pin as GPIO output */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200377 immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_IDE_RESET);
378 immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_IDE_RESET);
379 immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_IDE_RESET;
wdenk16f21702002-08-26 21:58:50 +0000380}
381
382/* ------------------------------------------------------------------------- */