wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net |
| 4 | * |
| 5 | * (C) Copyright 2001-2002 |
| 6 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <malloc.h> |
| 13 | #include <mpc8xx.h> |
Heiko Schocher | 50219e6 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 14 | #include <net.h> |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 15 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 16 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 17 | |
| 18 | static long int dram_size (long int, long int *, long int); |
| 19 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 20 | #define _NOT_USED_ 0xFFFFFFFF |
| 21 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 22 | const uint sdram_table[] = { |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 23 | #if (MPC8XX_SPEED <= 50000000L) |
| 24 | /* |
| 25 | * Single Read. (Offset 0 in UPMA RAM) |
| 26 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 27 | 0x0F07EC04, 0x01BBD804, 0x1FF7F440, 0xFFFFFC07, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 28 | 0xFFFFFFFF, |
| 29 | |
| 30 | /* |
| 31 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 32 | * |
| 33 | * This is no UPM entry point. The following definition uses |
| 34 | * the remaining space to establish an initialization |
| 35 | * sequence, which is executed by a RUN command. |
| 36 | * |
| 37 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 38 | 0x1FE7F434, 0xEFABE834, 0x1FA7D435, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Burst Read. (Offset 8 in UPMA RAM) |
| 42 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 43 | 0x0F07EC04, 0x10EFDC04, 0xF0AFFC00, 0xF0AFFC00, |
| 44 | 0xF1AFFC00, 0xFFAFFC40, 0xFFAFFC07, 0xFFFFFFFF, |
| 45 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 46 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 47 | |
| 48 | /* |
| 49 | * Single Write. (Offset 18 in UPMA RAM) |
| 50 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 51 | 0x0E07E804, 0x01BBD000, 0x1FF7F447, 0xFFFFFFFF, |
| 52 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 53 | |
| 54 | /* |
| 55 | * Burst Write. (Offset 20 in UPMA RAM) |
| 56 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 57 | 0x0E07E800, 0x10EFD400, 0xF0AFFC00, 0xF0AFFC00, |
| 58 | 0xF1AFFC47, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 59 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 60 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * Refresh (Offset 30 in UPMA RAM) |
| 64 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 65 | 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC84, 0xFFFFFC07, |
| 66 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
| 67 | 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | * Exception. (Offset 3c in UPMA RAM) |
| 71 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 72 | 0x7FFFFC07, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 73 | #else |
| 74 | |
| 75 | /* |
| 76 | * Single Read. (Offset 0 in UPMA RAM) |
| 77 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 78 | 0x1F07FC04, 0xEEAFEC04, 0x11AFDC04, 0xEFBBF800, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 79 | 0x1FF7F447, |
| 80 | |
| 81 | /* |
| 82 | * SDRAM Initialization (offset 5 in UPMA RAM) |
| 83 | * |
| 84 | * 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. |
| 87 | * |
| 88 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 89 | 0x1FF7F434, 0xEFEBE834, 0x1FB7D435, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Burst Read. (Offset 8 in UPMA RAM) |
| 93 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 94 | 0x1F07FC04, 0xEEAFEC04, 0x10AFDC04, 0xF0AFFC00, |
| 95 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBF800, 0x1FF7F447, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 96 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 97 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 98 | |
| 99 | /* |
| 100 | * Single Write. (Offset 18 in UPMA RAM) |
| 101 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 102 | 0x1F07FC04, 0xEEAFE800, 0x01BBD004, 0x1FF7F447, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 103 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 104 | |
| 105 | /* |
| 106 | * Burst Write. (Offset 20 in UPMA RAM) |
| 107 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 108 | 0x1F07FC04, 0xEEAFE800, 0x10AFD400, 0xF0AFFC00, |
| 109 | 0xF0AFFC00, 0xE1BBF804, 0x1FF7F447, _NOT_USED_, |
| 110 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 111 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 112 | |
| 113 | /* |
| 114 | * Refresh (Offset 30 in UPMA RAM) |
| 115 | */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 116 | 0x1FF7DC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 117 | 0xFFFFFC84, 0xFFFFFC07, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 118 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 119 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 120 | |
| 121 | /* |
| 122 | * Exception. (Offset 3c in UPMA RAM) |
| 123 | */ |
| 124 | 0x7FFFFC07, /* last */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 125 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 126 | #endif |
| 127 | }; |
| 128 | |
| 129 | /* ------------------------------------------------------------------------- */ |
| 130 | |
| 131 | |
| 132 | /* |
| 133 | * Check Board Identity: |
| 134 | * |
| 135 | */ |
| 136 | |
| 137 | int checkboard (void) |
| 138 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 139 | printf ("Board: Nexus NX823"); |
| 140 | return (0); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* ------------------------------------------------------------------------- */ |
| 144 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 145 | phys_size_t initdram (int board_type) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 146 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 147 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 148 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 149 | long int size_b0, size_b1, size8, size9; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 150 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 151 | upmconfig (UPMA, (uint *) sdram_table, |
| 152 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 153 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Up to 2 Banks of 64Mbit x 2 devices |
| 156 | * Initial builds only have 1 |
| 157 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 158 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_4K; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 159 | memctl->memc_mar = 0x00000088; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 160 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 161 | /* |
| 162 | * Map controller SDRAM bank 0 |
| 163 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 164 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 165 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
| 166 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 167 | udelay (200); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 168 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 169 | /* |
| 170 | * Map controller SDRAM bank 1 |
| 171 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 172 | memctl->memc_or2 = CONFIG_SYS_OR2_PRELIM; |
| 173 | memctl->memc_br2 = CONFIG_SYS_BR2_PRELIM; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 174 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 175 | /* |
| 176 | * Perform SDRAM initializsation sequence |
| 177 | */ |
| 178 | memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */ |
| 179 | udelay (1); |
| 180 | memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - execute twice */ |
| 181 | udelay (1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 182 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 183 | memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */ |
| 184 | udelay (1); |
| 185 | memctl->memc_mcr = 0x80004230; /* SDRAM bank 1 - execute twice */ |
| 186 | udelay (1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 187 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 188 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
| 189 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 190 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 191 | /* |
| 192 | * Preliminary prescaler for refresh (depends on number of |
| 193 | * banks): This value is selected for four cycles every 62.4 us |
| 194 | * with two SDRAM banks or four cycles every 31.2 us with one |
| 195 | * bank. It will be adjusted after memory sizing. |
| 196 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 197 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 198 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 199 | memctl->memc_mar = 0x00000088; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 200 | |
| 201 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 202 | /* |
| 203 | * Check Bank 0 Memory Size for re-configuration |
| 204 | * |
| 205 | * try 8 column mode |
| 206 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 207 | size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE1_PRELIM, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 208 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 209 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 210 | udelay (1000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 211 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 212 | /* |
| 213 | * try 9 column mode |
| 214 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 215 | size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE1_PRELIM, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 216 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 217 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 218 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 219 | size_b0 = size9; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 220 | /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 221 | } else { /* back to 8 columns */ |
| 222 | size_b0 = size8; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 223 | memctl->memc_mamr = CONFIG_SYS_MAMR_8COL; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 224 | udelay (500); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 225 | /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 226 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 227 | |
| 228 | /* |
| 229 | * Check Bank 1 Memory Size |
| 230 | * use current column settings |
| 231 | * [9 column SDRAM may also be used in 8 column mode, |
| 232 | * but then only half the real size will be used.] |
| 233 | */ |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 234 | size_b1 = dram_size (memctl->memc_mamr, (long *) SDRAM_BASE2_PRELIM, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 235 | SDRAM_MAX_SIZE); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 236 | /* debug ("SDRAM Bank 1: %ld MB\n", size8 >> 20); */ |
| 237 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 238 | udelay (1000); |
| 239 | |
| 240 | /* |
| 241 | * Adjust refresh rate depending on SDRAM type, both banks |
| 242 | * For types > 128 MBit leave it at the current (fast) rate |
| 243 | */ |
| 244 | if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) { |
| 245 | /* reduce to 15.6 us (62.4 us / quad) */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 246 | memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 247 | udelay (1000); |
| 248 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 249 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 250 | /* |
| 251 | * Final mapping: map bigger bank first |
| 252 | */ |
| 253 | if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 254 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 255 | memctl->memc_or2 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 256 | ((-size_b1) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 257 | memctl->memc_br2 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 258 | (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 259 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 260 | if (size_b0 > 0) { |
| 261 | /* |
| 262 | * Position Bank 0 immediately above Bank 1 |
| 263 | */ |
| 264 | memctl->memc_or1 = |
| 265 | ((-size_b0) & 0xFFFF0000) | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 266 | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 267 | memctl->memc_br1 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 268 | ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 269 | BR_V) |
| 270 | + size_b1; |
| 271 | } else { |
| 272 | unsigned long reg; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 273 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 274 | /* |
| 275 | * No bank 0 |
| 276 | * |
| 277 | * invalidate bank |
| 278 | */ |
| 279 | memctl->memc_br1 = 0; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 280 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 281 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 282 | reg = memctl->memc_mptpr; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 283 | reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 284 | memctl->memc_mptpr = reg; |
| 285 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 286 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 287 | } else { /* SDRAM Bank 0 is bigger - map first */ |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 288 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 289 | memctl->memc_or1 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 290 | ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 291 | memctl->memc_br1 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 292 | (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 293 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 294 | if (size_b1 > 0) { |
| 295 | /* |
| 296 | * Position Bank 1 immediately above Bank 0 |
| 297 | */ |
| 298 | memctl->memc_or2 = |
| 299 | ((-size_b1) & 0xFFFF0000) | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 300 | CONFIG_SYS_OR_TIMING_SDRAM; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 301 | memctl->memc_br2 = |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 302 | ((CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 303 | BR_V) |
| 304 | + size_b0; |
| 305 | } else { |
| 306 | unsigned long reg; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 307 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 308 | /* |
| 309 | * No bank 1 |
| 310 | * |
| 311 | * invalidate bank |
| 312 | */ |
| 313 | memctl->memc_br2 = 0; |
| 314 | |
| 315 | /* adjust refresh rate depending on SDRAM type, one bank */ |
| 316 | reg = memctl->memc_mptpr; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 317 | reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 318 | memctl->memc_mptpr = reg; |
| 319 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 320 | } |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 321 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 322 | udelay (10000); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 323 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 324 | return (size_b0 + size_b1); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /* ------------------------------------------------------------------------- */ |
| 328 | |
| 329 | /* |
| 330 | * Check memory range for valid RAM. A simple memory test determines |
| 331 | * the actually available RAM size between addresses `base' and |
| 332 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 333 | * - short between address lines |
| 334 | * - short between data lines |
| 335 | */ |
| 336 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 337 | static long int dram_size (long int mamr_value, long int *base, |
| 338 | long int maxsize) |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 339 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 340 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 341 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 342 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 343 | memctl->memc_mamr = mamr_value; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 344 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 345 | return (get_ram_size (base, maxsize)); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 346 | } |
| 347 | |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 348 | int misc_init_r (void) |
| 349 | { |
Mike Frysinger | 5a3d56d | 2009-02-11 19:36:20 -0500 | [diff] [blame] | 350 | int i; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 351 | char tmp[50]; |
Mike Frysinger | 5a3d56d | 2009-02-11 19:36:20 -0500 | [diff] [blame] | 352 | uchar ethaddr[6]; |
| 353 | bd_t *bd = gd->bd; |
Heiko Schocher | 50219e6 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 354 | ulong *my_sernum = (unsigned long *)&bd->bi_sernum; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 355 | |
Mike Frysinger | 5a3d56d | 2009-02-11 19:36:20 -0500 | [diff] [blame] | 356 | /* load unique serial number */ |
| 357 | for (i = 0; i < 8; ++i) |
| 358 | bd->bi_sernum[i] = *(u_char *) (CONFIG_SYS_FLASH_SN_BASE + i); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 359 | |
| 360 | /* save env variables according to sernum */ |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 361 | sprintf (tmp, "%08lx%08lx", my_sernum[0], my_sernum[1]); |
| 362 | setenv ("serial#", tmp); |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 363 | |
Mike Frysinger | 5a3d56d | 2009-02-11 19:36:20 -0500 | [diff] [blame] | 364 | if (!eth_getenv_enetaddr("ethaddr", ethaddr)) { |
| 365 | ethaddr[0] = 0x10; |
| 366 | ethaddr[1] = 0x20; |
| 367 | ethaddr[2] = 0x30; |
| 368 | ethaddr[3] = bd->bi_sernum[1] << 4 | bd->bi_sernum[2]; |
| 369 | ethaddr[4] = bd->bi_sernum[5]; |
| 370 | ethaddr[5] = bd->bi_sernum[6]; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 371 | } |
Mike Frysinger | 5a3d56d | 2009-02-11 19:36:20 -0500 | [diff] [blame] | 372 | |
| 373 | return 0; |
wdenk | f8cac65 | 2002-08-26 22:36:39 +0000 | [diff] [blame] | 374 | } |