wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * Ulrich Lutz, Speech Design GmbH, ulutz@datalab.de. |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <mpc8xx.h> |
| 11 | #include <commproc.h> |
| 12 | |
| 13 | /* ------------------------------------------------------------------------- */ |
| 14 | |
| 15 | static long int dram_size (long int, long int *, long int); |
| 16 | |
| 17 | /* ------------------------------------------------------------------------- */ |
| 18 | |
| 19 | #define _NOT_USED_ 0xFFFFFFFF |
| 20 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 21 | const uint sharc_table[] = { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Single Read. (Offset 0 in UPM RAM) |
| 24 | */ |
| 25 | 0x0FF3FC04, 0x0FF3EC00, 0x7FFFEC04, 0xFFFFEC04, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 26 | 0xFFFFEC05, /* last */ |
| 27 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Burst Read. (Offset 8 in UPM RAM) |
| 30 | */ |
| 31 | /* last */ |
| 32 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 33 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 34 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 35 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 36 | /* |
| 37 | * Single Write. (Offset 18 in UPM RAM) |
| 38 | */ |
| 39 | 0x0FAFFC04, 0x0FAFEC00, 0x7FFFEC04, 0xFFFFEC04, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 40 | 0xFFFFEC05, /* last */ |
| 41 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 42 | /* |
| 43 | * Burst Write. (Offset 20 in UPM RAM) |
| 44 | */ |
| 45 | /* last */ |
| 46 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 47 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 48 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 49 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 50 | /* |
| 51 | * Refresh (Offset 30 in UPM RAM) |
| 52 | */ |
| 53 | /* last */ |
| 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 | * Exception. (Offset 3c in UPM RAM) |
| 59 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 60 | 0x7FFFFC07, /* last */ |
| 61 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 65 | const uint sdram_table[] = { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 66 | /* |
| 67 | * Single Read. (Offset 0 in UPM RAM) |
| 68 | */ |
| 69 | 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 70 | 0x1FF77C47, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 71 | /* |
| 72 | * SDRAM Initialization (offset 5 in UPM RAM) |
| 73 | * |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | * This is no UPM entry point. The following definition uses |
| 75 | * the remaining space to establish an initialization |
| 76 | * sequence, which is executed by a RUN command. |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 77 | * |
| 78 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 79 | 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 80 | /* |
| 81 | * Burst Read. (Offset 8 in UPM RAM) |
| 82 | */ |
| 83 | 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 84 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 85 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 86 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 87 | /* |
| 88 | * Single Write. (Offset 18 in UPM RAM) |
| 89 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 90 | 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 91 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 92 | /* |
| 93 | * Burst Write. (Offset 20 in UPM RAM) |
| 94 | */ |
| 95 | 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 96 | 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */ |
| 97 | _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 98 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 99 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 100 | /* |
| 101 | * Refresh (Offset 30 in UPM RAM) |
| 102 | */ |
| 103 | 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 104 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 105 | _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 106 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 107 | /* |
| 108 | * Exception. (Offset 3c in UPM RAM) |
| 109 | */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 110 | 0x7FFFFC07, /* last */ |
| 111 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | /* ------------------------------------------------------------------------- */ |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * Check Board Identity: |
| 119 | * |
| 120 | */ |
| 121 | |
| 122 | int checkboard (void) |
| 123 | { |
| 124 | puts ("Board: SPD823TS\n"); |
| 125 | return (0); |
| 126 | } |
| 127 | |
| 128 | /* ------------------------------------------------------------------------- */ |
| 129 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 130 | phys_size_t initdram (int board_type) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 131 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 133 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 134 | long int size_b0; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 135 | |
| 136 | #if 0 |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 137 | /* |
| 138 | * Map controller bank 2 to the SRAM bank at preliminary address. |
| 139 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | memctl->memc_or2 = CONFIG_SYS_OR2; |
| 141 | memctl->memc_br2 = CONFIG_SYS_BR2; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 144 | /* |
| 145 | * Map controller bank 4 to the PER8 bank. |
| 146 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | memctl->memc_or4 = CONFIG_SYS_OR4; |
| 148 | memctl->memc_br4 = CONFIG_SYS_BR4; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 149 | |
| 150 | #if 0 |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 151 | /* Configure SHARC at UMA */ |
| 152 | upmconfig (UPMA, (uint *) sharc_table, |
| 153 | sizeof (sharc_table) / sizeof (uint)); |
| 154 | /* Map controller bank 5 to the SHARC */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 155 | memctl->memc_or5 = CONFIG_SYS_OR5; |
| 156 | memctl->memc_br5 = CONFIG_SYS_BR5; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 157 | #endif |
| 158 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 159 | memctl->memc_mamr = 0x00001000; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 160 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 161 | /* Configure SDRAM at UMB */ |
| 162 | upmconfig (UPMB, (uint *) sdram_table, |
| 163 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 164 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 165 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_8K; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 166 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 167 | memctl->memc_mar = 0x00000088; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 168 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 169 | /* |
| 170 | * Map controller bank 3 to the SDRAM bank at preliminary address. |
| 171 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM; |
| 173 | memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 174 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 175 | memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL; /* refresh not enabled yet */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 176 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 177 | udelay (200); |
| 178 | memctl->memc_mcr = 0x80806105; |
| 179 | udelay (1); |
| 180 | memctl->memc_mcr = 0x80806130; |
| 181 | udelay (1); |
| 182 | memctl->memc_mcr = 0x80806130; |
| 183 | udelay (1); |
| 184 | memctl->memc_mcr = 0x80806106; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 185 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 186 | memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 187 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 188 | /* |
| 189 | * Check Bank 0 Memory Size for re-configuration |
| 190 | */ |
| 191 | size_b0 = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 192 | dram_size (CONFIG_SYS_MBMR_8COL, SDRAM_BASE3_PRELIM, |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 193 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 194 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 195 | memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 196 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 197 | return (size_b0); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* ------------------------------------------------------------------------- */ |
| 201 | |
| 202 | /* |
| 203 | * Check memory range for valid RAM. A simple memory test determines |
| 204 | * the actually available RAM size between addresses `base' and |
| 205 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 206 | * - short between address lines |
| 207 | * - short between data lines |
| 208 | */ |
| 209 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 210 | static long int dram_size (long int mamr_value, long int *base, |
| 211 | long int maxsize) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 212 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 213 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 214 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 215 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 216 | memctl->memc_mbmr = mamr_value; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 217 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 218 | return (get_ram_size (base, maxsize)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* ------------------------------------------------------------------------- */ |
| 222 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 223 | void reset_phy (void) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 224 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 226 | ushort sreg; |
| 227 | |
| 228 | /* Configure extra port pins for NS DP83843 PHY */ |
| 229 | immr->im_ioport.iop_papar &= ~(PA_ENET_MDC | PA_ENET_MDIO); |
| 230 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 231 | sreg = immr->im_ioport.iop_padir; |
| 232 | sreg |= PA_ENET_MDC; /* Mgmt. Data Clock is Output */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 233 | sreg &= ~(PA_ENET_MDIO); /* Mgmt. Data I/O is bidirect. => Input */ |
| 234 | immr->im_ioport.iop_padir = sreg; |
| 235 | |
| 236 | immr->im_ioport.iop_padat &= ~(PA_ENET_MDC); /* set MDC = 0 */ |
| 237 | |
| 238 | /* |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 239 | * RESET in implemented by a positive pulse of at least 1 us |
| 240 | * at the reset pin. |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 241 | * |
| 242 | * Configure RESET pins for NS DP83843 PHY, and RESET chip. |
| 243 | * |
| 244 | * Note: The RESET pin is high active, but there is an |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 245 | * inverter on the SPD823TS board... |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 246 | */ |
| 247 | immr->im_ioport.iop_pcpar &= ~(PC_ENET_RESET); |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 248 | immr->im_ioport.iop_pcdir |= PC_ENET_RESET; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 249 | /* assert RESET signal of PHY */ |
| 250 | immr->im_ioport.iop_pcdat &= ~(PC_ENET_RESET); |
| 251 | udelay (10); |
| 252 | /* de-assert RESET signal of PHY */ |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 253 | immr->im_ioport.iop_pcdat |= PC_ENET_RESET; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 254 | udelay (10); |
| 255 | } |
| 256 | |
| 257 | /* ------------------------------------------------------------------------- */ |
| 258 | |
wdenk | c83bf6a | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 259 | void ide_set_reset (int on) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 260 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 261 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 262 | |
| 263 | /* |
| 264 | * Configure PC for IDE Reset Pin |
| 265 | */ |
| 266 | if (on) { /* assert RESET */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 267 | immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 268 | } else { /* release RESET */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 269 | immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* program port pin as GPIO output */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 273 | immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_IDE_RESET); |
| 274 | immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_IDE_RESET); |
| 275 | immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_IDE_RESET; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* ------------------------------------------------------------------------- */ |