wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 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 | |
| 24 | #include <common.h> |
| 25 | #include <ppc4xx.h> |
| 26 | #include <asm/processor.h> |
| 27 | #include <pci.h> |
| 28 | |
| 29 | |
| 30 | #ifdef CONFIG_SDRAM_BANK0 |
| 31 | |
| 32 | |
| 33 | #define MAGIC0 0x00000000 |
| 34 | #define MAGIC1 0x11111111 |
| 35 | #define MAGIC2 0x22222222 |
| 36 | #define MAGIC3 0x33333333 |
| 37 | #define MAGIC4 0x44444444 |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 38 | #define MAGIC5 0x55555555 |
| 39 | #define MAGIC6 0x66666666 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 40 | |
| 41 | #define ADDR_ZERO 0x00000000 |
| 42 | #define ADDR_400 0x00000400 |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 43 | #define ADDR_01MB 0x00100000 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 44 | #define ADDR_08MB 0x00800000 |
| 45 | #define ADDR_16MB 0x01000000 |
| 46 | #define ADDR_32MB 0x02000000 |
| 47 | #define ADDR_64MB 0x04000000 |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 48 | #define ADDR_128MB 0x08000000 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | |
| 50 | #define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data) |
| 51 | |
| 52 | |
| 53 | /*----------------------------------------------------------------------- |
| 54 | */ |
| 55 | void sdram_init(void) |
| 56 | { |
| 57 | ulong speed; |
| 58 | ulong sdtr1; |
| 59 | ulong rtr; |
| 60 | |
| 61 | /* |
| 62 | * Determine SDRAM speed |
| 63 | */ |
| 64 | speed = get_bus_freq(0); /* parameter not used on ppc4xx */ |
| 65 | |
| 66 | /* |
| 67 | * Support for 100MHz and 133MHz SDRAM |
| 68 | */ |
| 69 | if (speed > 100000000) { |
| 70 | /* |
| 71 | * 133 MHz SDRAM |
| 72 | */ |
| 73 | sdtr1 = 0x01074015; |
| 74 | rtr = 0x07f00000; |
| 75 | } else { |
| 76 | /* |
| 77 | * default: 100 MHz SDRAM |
| 78 | */ |
| 79 | sdtr1 = 0x0086400d; |
| 80 | rtr = 0x05f00000; |
| 81 | } |
| 82 | |
| 83 | /* |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 84 | * Set MB0CF for bank 0. (0-128MB) Address Mode 3 since 13x10(4) |
| 85 | */ |
| 86 | mtsdram0(mem_mb0cf, 0x000A4001); |
| 87 | |
| 88 | mtsdram0(mem_sdtr1, sdtr1); |
| 89 | mtsdram0(mem_rtr, rtr); |
| 90 | |
| 91 | /* |
| 92 | * Wait for 200us |
| 93 | */ |
| 94 | udelay(200); |
| 95 | |
| 96 | /* |
| 97 | * Set memory controller options reg, MCOPT1. |
| 98 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 99 | * read/prefetch. |
| 100 | */ |
| 101 | mtsdram0(mem_mcopt1, 0x80800000); |
| 102 | |
| 103 | /* |
| 104 | * Wait for 10ms |
| 105 | */ |
| 106 | udelay(10000); |
| 107 | |
| 108 | /* |
| 109 | * Test if 128 MByte are equipped (mirror test) |
| 110 | */ |
| 111 | *(volatile ulong *)ADDR_ZERO = MAGIC0; |
| 112 | *(volatile ulong *)ADDR_08MB = MAGIC1; |
| 113 | *(volatile ulong *)ADDR_16MB = MAGIC2; |
| 114 | *(volatile ulong *)ADDR_32MB = MAGIC3; |
| 115 | *(volatile ulong *)ADDR_64MB = MAGIC4; |
| 116 | |
| 117 | if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) && |
| 118 | (*(volatile ulong *)ADDR_08MB == MAGIC1) && |
| 119 | (*(volatile ulong *)ADDR_16MB == MAGIC2) && |
| 120 | (*(volatile ulong *)ADDR_32MB == MAGIC3)) { |
| 121 | /* |
| 122 | * OK, 128MB detected -> all done |
| 123 | */ |
| 124 | return; |
| 125 | } |
wdenk | e5ad56b | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 126 | |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 127 | /* |
| 128 | * Now test for 64 MByte... |
| 129 | */ |
wdenk | e5ad56b | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 130 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 131 | /* |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 132 | * Disable memory controller. |
| 133 | */ |
| 134 | mtsdram0(mem_mcopt1, 0x00000000); |
| 135 | |
| 136 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | * Set MB0CF for bank 0. (0-64MB) Address Mode 3 since 13x9(4) |
| 138 | */ |
| 139 | mtsdram0(mem_mb0cf, 0x00084001); |
| 140 | |
| 141 | mtsdram0(mem_sdtr1, sdtr1); |
| 142 | mtsdram0(mem_rtr, rtr); |
| 143 | |
| 144 | /* |
| 145 | * Wait for 200us |
| 146 | */ |
| 147 | udelay(200); |
| 148 | |
| 149 | /* |
| 150 | * Set memory controller options reg, MCOPT1. |
| 151 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 152 | * read/prefetch. |
| 153 | */ |
| 154 | mtsdram0(mem_mcopt1, 0x80800000); |
| 155 | |
| 156 | /* |
| 157 | * Wait for 10ms |
| 158 | */ |
| 159 | udelay(10000); |
| 160 | |
| 161 | /* |
| 162 | * Test if 64 MByte are equipped (mirror test) |
| 163 | */ |
| 164 | *(volatile ulong *)ADDR_ZERO = MAGIC0; |
| 165 | *(volatile ulong *)ADDR_08MB = MAGIC1; |
| 166 | *(volatile ulong *)ADDR_16MB = MAGIC2; |
| 167 | *(volatile ulong *)ADDR_32MB = MAGIC3; |
| 168 | |
| 169 | if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) && |
| 170 | (*(volatile ulong *)ADDR_08MB == MAGIC1) && |
| 171 | (*(volatile ulong *)ADDR_16MB == MAGIC2)) { |
| 172 | /* |
| 173 | * OK, 64MB detected -> all done |
| 174 | */ |
| 175 | return; |
| 176 | } |
wdenk | e5ad56b | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 177 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 178 | /* |
| 179 | * Now test for 32 MByte... |
| 180 | */ |
wdenk | e5ad56b | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 181 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 182 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | * Disable memory controller. |
| 184 | */ |
| 185 | mtsdram0(mem_mcopt1, 0x00000000); |
| 186 | |
| 187 | /* |
| 188 | * Set MB0CF for bank 0. (0-32MB) Address Mode 2 since 12x9(4) |
| 189 | */ |
| 190 | mtsdram0(mem_mb0cf, 0x00062001); |
| 191 | |
| 192 | /* |
| 193 | * Set memory controller options reg, MCOPT1. |
| 194 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 195 | * read/prefetch. |
| 196 | */ |
| 197 | mtsdram0(mem_mcopt1, 0x80800000); |
| 198 | |
| 199 | /* |
| 200 | * Wait for 10ms |
| 201 | */ |
| 202 | udelay(10000); |
| 203 | |
| 204 | /* |
| 205 | * Test if 32 MByte are equipped (mirror test) |
| 206 | */ |
| 207 | *(volatile ulong *)ADDR_ZERO = MAGIC0; |
| 208 | *(volatile ulong *)ADDR_400 = MAGIC1; |
| 209 | *(volatile ulong *)ADDR_08MB = MAGIC2; |
| 210 | *(volatile ulong *)ADDR_16MB = MAGIC3; |
| 211 | |
| 212 | if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) && |
| 213 | (*(volatile ulong *)ADDR_400 == MAGIC1) && |
| 214 | (*(volatile ulong *)ADDR_08MB == MAGIC2)) { |
| 215 | /* |
| 216 | * OK, 32MB detected -> all done |
| 217 | */ |
| 218 | return; |
| 219 | } |
| 220 | |
| 221 | /* |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 222 | * Now test for 16 MByte... |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 223 | */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 225 | * Disable memory controller. |
| 226 | */ |
| 227 | mtsdram0(mem_mcopt1, 0x00000000); |
| 228 | |
| 229 | /* |
| 230 | * Set MB0CF for bank 0. (0-16MB) Address Mode 4 since 12x8(4) |
| 231 | */ |
| 232 | mtsdram0(mem_mb0cf, 0x00046001); |
| 233 | |
| 234 | /* |
| 235 | * Set memory controller options reg, MCOPT1. |
| 236 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 237 | * read/prefetch. |
| 238 | */ |
| 239 | mtsdram0(mem_mcopt1, 0x80800000); |
| 240 | |
| 241 | /* |
| 242 | * Wait for 10ms |
| 243 | */ |
| 244 | udelay(10000); |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 245 | |
| 246 | /* |
| 247 | * Test if 16 MByte are equipped (mirror test) |
| 248 | */ |
| 249 | *(volatile ulong *)ADDR_ZERO = MAGIC0; |
| 250 | *(volatile ulong *)ADDR_400 = MAGIC1; |
| 251 | *(volatile ulong *)ADDR_01MB = MAGIC5; |
| 252 | *(volatile ulong *)ADDR_08MB = MAGIC2; |
| 253 | /* *(volatile ulong *)ADDR_16MB = MAGIC3;*/ |
| 254 | |
| 255 | if ((*(volatile ulong *)ADDR_ZERO == MAGIC0) && |
| 256 | (*(volatile ulong *)ADDR_400 == MAGIC1) && |
| 257 | (*(volatile ulong *)ADDR_01MB == MAGIC5) && |
| 258 | (*(volatile ulong *)ADDR_08MB == MAGIC2)) { |
| 259 | /* |
| 260 | * OK, 16MB detected -> all done |
| 261 | */ |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Setup for 4 MByte... |
| 267 | */ |
wdenk | e5ad56b | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 268 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 269 | /* |
stroese | 6177445 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 270 | * Disable memory controller. |
| 271 | */ |
| 272 | mtsdram0(mem_mcopt1, 0x00000000); |
| 273 | |
| 274 | /* |
| 275 | * Set MB0CF for bank 0. (0-4MB) Address Mode 5 since 11x8(2) |
| 276 | */ |
| 277 | mtsdram0(mem_mb0cf, 0x00008001); |
| 278 | |
| 279 | /* |
| 280 | * Set memory controller options reg, MCOPT1. |
| 281 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 282 | * read/prefetch. |
| 283 | */ |
| 284 | mtsdram0(mem_mcopt1, 0x80800000); |
| 285 | |
| 286 | /* |
| 287 | * Wait for 10ms |
| 288 | */ |
| 289 | udelay(10000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | #endif /* CONFIG_SDRAM_BANK0 */ |