Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2005 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 8 | #include <fdt_support.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 9 | #include <init.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 10 | #include <ioports.h> |
| 11 | #include <mpc83xx.h> |
| 12 | #include <asm/mpc8349_pci.h> |
| 13 | #include <i2c.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 14 | #include <miiphy.h> |
Peter Tyser | 61f2b38 | 2010-04-12 22:28:07 -0500 | [diff] [blame] | 15 | #include <asm/mmu.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 16 | #include <pci.h> |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 17 | #include <flash.h> |
| 18 | #include <mtd/cfi_flash.h> |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 19 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 22 | #define IOSYNC asm("eieio") |
| 23 | #define ISYNC asm("isync") |
| 24 | #define SYNC asm("sync") |
| 25 | #define FPW FLASH_PORT_WIDTH |
| 26 | #define FPWV FLASH_PORT_WIDTHV |
| 27 | |
| 28 | #define DDR_MAX_SIZE_PER_CS 0x20000000 |
| 29 | |
| 30 | #if defined(DDR_CASLAT_20) |
| 31 | #define TIMING_CASLAT TIMING_CFG1_CASLAT_20 |
| 32 | #define MODE_CASLAT DDR_MODE_CASLAT_20 |
| 33 | #else |
| 34 | #define TIMING_CASLAT TIMING_CFG1_CASLAT_25 |
| 35 | #define MODE_CASLAT DDR_MODE_CASLAT_25 |
| 36 | #endif |
| 37 | |
| 38 | #define INITIAL_CS_CONFIG (CSCONFIG_EN | CSCONFIG_ROW_BIT_12 | \ |
| 39 | CSCONFIG_COL_BIT_9) |
| 40 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 41 | /* External definitions */ |
| 42 | ulong flash_get_size (ulong base, int banknum); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 43 | |
| 44 | /* Local functions */ |
| 45 | static int detect_num_flash_banks(void); |
Wolfgang Denk | 982db89 | 2011-07-30 23:50:50 +0200 | [diff] [blame] | 46 | static long int get_ddr_bank_size(short cs, long *base); |
Bin Meng | 4019e54 | 2016-01-25 00:29:55 -0800 | [diff] [blame] | 47 | static void set_cs_bounds(short cs, ulong base, ulong size); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 48 | static void set_cs_config(short cs, long config); |
| 49 | static void set_ddr_config(void); |
| 50 | |
| 51 | /* Local variable */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 52 | static volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 53 | |
| 54 | /************************************************************************** |
| 55 | * Board initialzation after relocation to RAM. Used to detect the number |
| 56 | * of Flash banks on TQM834x. |
| 57 | */ |
| 58 | int board_early_init_r (void) { |
| 59 | /* sanity check, IMMARBAR should be mirrored at offset zero of IMMR */ |
| 60 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) |
| 61 | return 0; |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 62 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 63 | /* detect the number of Flash banks */ |
| 64 | return detect_num_flash_banks(); |
| 65 | } |
| 66 | |
| 67 | /************************************************************************** |
| 68 | * DRAM initalization and size detection |
| 69 | */ |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 70 | int dram_init(void) |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 71 | { |
| 72 | long bank_size; |
| 73 | long size; |
| 74 | int cs; |
| 75 | |
| 76 | /* during size detection, set up the max DDRLAW size */ |
Mario Six | 8a81bfd | 2019-01-21 09:18:15 +0100 | [diff] [blame] | 77 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 78 | im->sysconf.ddrlaw[0].ar = (LAWAR_EN | LAWAR_SIZE_2G); |
| 79 | |
| 80 | /* set CS bounds to maximum size */ |
| 81 | for(cs = 0; cs < 4; ++cs) { |
| 82 | set_cs_bounds(cs, |
Mario Six | 8a81bfd | 2019-01-21 09:18:15 +0100 | [diff] [blame] | 83 | CONFIG_SYS_SDRAM_BASE + (cs * DDR_MAX_SIZE_PER_CS), |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 84 | DDR_MAX_SIZE_PER_CS); |
| 85 | |
| 86 | set_cs_config(cs, INITIAL_CS_CONFIG); |
| 87 | } |
| 88 | |
| 89 | /* configure ddr controller */ |
| 90 | set_ddr_config(); |
| 91 | |
| 92 | udelay(200); |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 93 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 94 | /* enable DDR controller */ |
| 95 | im->ddr.sdram_cfg = (SDRAM_CFG_MEM_EN | |
| 96 | SDRAM_CFG_SREN | |
Kim Phillips | bbea46f | 2007-08-16 22:52:48 -0500 | [diff] [blame] | 97 | SDRAM_CFG_SDRAM_TYPE_DDR1); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 98 | SYNC; |
| 99 | |
| 100 | /* size detection */ |
| 101 | debug("\n"); |
| 102 | size = 0; |
| 103 | for(cs = 0; cs < 4; ++cs) { |
| 104 | debug("\nDetecting Bank%d\n", cs); |
| 105 | |
| 106 | bank_size = get_ddr_bank_size(cs, |
Mario Six | 8a81bfd | 2019-01-21 09:18:15 +0100 | [diff] [blame] | 107 | (long *)(CONFIG_SYS_SDRAM_BASE + size)); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 108 | size += bank_size; |
| 109 | |
Marek Vasut | 3d54639 | 2011-10-21 14:17:10 +0000 | [diff] [blame] | 110 | debug("DDR Bank%d size: %ld MiB\n\n", cs, bank_size >> 20); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 111 | |
| 112 | /* exit if less than one bank */ |
| 113 | if(size < DDR_MAX_SIZE_PER_CS) break; |
| 114 | } |
| 115 | |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 116 | gd->ram_size = size; |
| 117 | |
| 118 | return 0; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /************************************************************************** |
| 122 | * checkboard() |
| 123 | */ |
| 124 | int checkboard (void) |
| 125 | { |
| 126 | puts("Board: TQM834x\n"); |
| 127 | |
| 128 | #ifdef CONFIG_PCI |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 129 | volatile immap_t * immr; |
| 130 | u32 w, f; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 131 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 132 | immr = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | e080313 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 133 | if (!(immr->reset.rcwh & HRCWH_PCI_HOST)) { |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 134 | printf("PCI: NOT in host mode..?!\n"); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | /* get bus width */ |
| 139 | w = 32; |
Dave Liu | e080313 | 2006-12-07 21:11:58 +0800 | [diff] [blame] | 140 | if (immr->reset.rcwh & HRCWH_64_BIT_PCI) |
Rafal Jaworowski | 6902df5 | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 141 | w = 64; |
| 142 | |
| 143 | /* get clock */ |
| 144 | f = gd->pci_clk; |
| 145 | |
| 146 | printf("PCI1: %d bit, %d MHz\n", w, f / 1000000); |
| 147 | #else |
| 148 | printf("PCI: disabled\n"); |
| 149 | #endif |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 153 | |
| 154 | /************************************************************************** |
| 155 | * |
| 156 | * Local functions |
| 157 | * |
| 158 | *************************************************************************/ |
| 159 | |
| 160 | /************************************************************************** |
| 161 | * Detect the number of flash banks (1 or 2). Store it in |
| 162 | * a global variable tqm834x_num_flash_banks. |
| 163 | * Bank detection code based on the Monitor code. |
| 164 | */ |
| 165 | static int detect_num_flash_banks(void) |
| 166 | { |
| 167 | typedef unsigned long FLASH_PORT_WIDTH; |
| 168 | typedef volatile unsigned long FLASH_PORT_WIDTHV; |
| 169 | FPWV *bank1_base; |
| 170 | FPWV *bank2_base; |
| 171 | FPW bank1_read; |
| 172 | FPW bank2_read; |
| 173 | ulong bank1_size; |
| 174 | ulong bank2_size; |
| 175 | ulong total_size; |
| 176 | |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 177 | cfi_flash_num_flash_banks = 2; /* assume two banks */ |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 178 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 179 | /* Get bank 1 and 2 information */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 180 | bank1_size = flash_get_size(CONFIG_SYS_FLASH_BASE, 0); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 181 | debug("Bank1 size: %lu\n", bank1_size); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 182 | bank2_size = flash_get_size(CONFIG_SYS_FLASH_BASE + bank1_size, 1); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 183 | debug("Bank2 size: %lu\n", bank2_size); |
| 184 | total_size = bank1_size + bank2_size; |
| 185 | |
| 186 | if (bank2_size > 0) { |
| 187 | /* Seems like we've got bank 2, but maybe it's mirrored 1 */ |
| 188 | |
| 189 | /* Set the base addresses */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 190 | bank1_base = (FPWV *) (CONFIG_SYS_FLASH_BASE); |
| 191 | bank2_base = (FPWV *) (CONFIG_SYS_FLASH_BASE + bank1_size); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 192 | |
| 193 | /* Put bank 2 into CFI command mode and read */ |
| 194 | bank2_base[0x55] = 0x00980098; |
| 195 | IOSYNC; |
| 196 | ISYNC; |
| 197 | bank2_read = bank2_base[0x10]; |
| 198 | |
| 199 | /* Read from bank 1 (it's in read mode) */ |
| 200 | bank1_read = bank1_base[0x10]; |
| 201 | |
| 202 | /* Reset Flash */ |
| 203 | bank1_base[0] = 0x00F000F0; |
| 204 | bank2_base[0] = 0x00F000F0; |
| 205 | |
| 206 | if (bank2_read == bank1_read) { |
| 207 | /* |
| 208 | * Looks like just one bank, but not sure yet. Let's |
| 209 | * read from bank 2 in autosoelect mode. |
| 210 | */ |
| 211 | bank2_base[0x0555] = 0x00AA00AA; |
| 212 | bank2_base[0x02AA] = 0x00550055; |
| 213 | bank2_base[0x0555] = 0x00900090; |
| 214 | IOSYNC; |
| 215 | ISYNC; |
| 216 | bank2_read = bank2_base[0x10]; |
| 217 | |
| 218 | /* Read from bank 1 (it's in read mode) */ |
| 219 | bank1_read = bank1_base[0x10]; |
| 220 | |
| 221 | /* Reset Flash */ |
| 222 | bank1_base[0] = 0x00F000F0; |
| 223 | bank2_base[0] = 0x00F000F0; |
| 224 | |
| 225 | if (bank2_read == bank1_read) { |
| 226 | /* |
| 227 | * In both CFI command and autoselect modes, |
| 228 | * we got the some data reading from Flash. |
| 229 | * There is only one mirrored bank. |
| 230 | */ |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 231 | cfi_flash_num_flash_banks = 1; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 232 | total_size = bank1_size; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
Stefan Roese | ca5def3 | 2010-08-31 10:00:10 +0200 | [diff] [blame] | 237 | debug("Number of flash banks detected: %d\n", cfi_flash_num_flash_banks); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 238 | |
| 239 | /* set OR0 and BR0 */ |
Mario Six | 87ee510 | 2019-01-21 09:18:00 +0100 | [diff] [blame] | 240 | set_lbc_or(0, OR_GPCM_CSNT | OR_GPCM_ACS_DIV4 | OR_GPCM_SCY_5 | |
| 241 | OR_GPCM_TRLX | (-(total_size) & OR_GPCM_AM)); |
Becky Bruce | f51cdaf | 2010-06-17 11:37:20 -0500 | [diff] [blame] | 242 | set_lbc_br(0, (CONFIG_SYS_FLASH_BASE & BR_BA) | |
| 243 | (BR_MS_GPCM | BR_PS_32 | BR_V)); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 244 | |
| 245 | return (0); |
| 246 | } |
| 247 | |
| 248 | /************************************************************************* |
| 249 | * Detect the size of a ddr bank. Sets CS bounds and CS config accordingly. |
| 250 | */ |
Wolfgang Denk | 982db89 | 2011-07-30 23:50:50 +0200 | [diff] [blame] | 251 | static long int get_ddr_bank_size(short cs, long *base) |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 252 | { |
| 253 | /* This array lists all valid DDR SDRAM configurations, with |
| 254 | * Bank sizes in bytes. (Refer to Table 9-27 in the MPC8349E RM). |
| 255 | * The last entry has to to have size equal 0 and is igonred during |
| 256 | * autodection. Bank sizes must be in increasing order of size |
| 257 | */ |
| 258 | struct { |
| 259 | long row; |
| 260 | long col; |
| 261 | long size; |
| 262 | } conf[] = { |
| 263 | {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_8, 32 << 20}, |
| 264 | {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_9, 64 << 20}, |
| 265 | {CSCONFIG_ROW_BIT_12, CSCONFIG_COL_BIT_10, 128 << 20}, |
| 266 | {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_9, 128 << 20}, |
| 267 | {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_10, 256 << 20}, |
| 268 | {CSCONFIG_ROW_BIT_13, CSCONFIG_COL_BIT_11, 512 << 20}, |
| 269 | {CSCONFIG_ROW_BIT_14, CSCONFIG_COL_BIT_10, 512 << 20}, |
| 270 | {CSCONFIG_ROW_BIT_14, CSCONFIG_COL_BIT_11, 1024 << 20}, |
| 271 | {0, 0, 0} |
| 272 | }; |
| 273 | |
| 274 | int i; |
| 275 | int detected; |
| 276 | long size; |
| 277 | |
| 278 | detected = -1; |
| 279 | for(i = 0; conf[i].size != 0; ++i) { |
| 280 | |
| 281 | /* set sdram bank configuration */ |
| 282 | set_cs_config(cs, CSCONFIG_EN | conf[i].col | conf[i].row); |
| 283 | |
| 284 | debug("Getting RAM size...\n"); |
| 285 | size = get_ram_size(base, DDR_MAX_SIZE_PER_CS); |
| 286 | |
| 287 | if((size == conf[i].size) && (i == detected + 1)) |
| 288 | detected = i; |
| 289 | |
| 290 | debug("Trying %ld x %ld (%ld MiB) at addr %p, detected: %ld MiB\n", |
| 291 | conf[i].row, |
| 292 | conf[i].col, |
| 293 | conf[i].size >> 20, |
| 294 | base, |
| 295 | size >> 20); |
| 296 | } |
| 297 | |
| 298 | if(detected == -1){ |
| 299 | /* disable empty cs */ |
| 300 | debug("\nNo valid configurations for CS%d, disabling...\n", cs); |
| 301 | set_cs_config(cs, 0); |
| 302 | return 0; |
| 303 | } |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 304 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 305 | debug("\nDetected configuration %ld x %ld (%ld MiB) at addr %p\n", |
| 306 | conf[detected].row, conf[detected].col, conf[detected].size >> 20, base); |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 307 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 308 | /* configure cs ro detected params */ |
| 309 | set_cs_config(cs, CSCONFIG_EN | conf[detected].row | |
| 310 | conf[detected].col); |
| 311 | |
| 312 | set_cs_bounds(cs, (long)base, conf[detected].size); |
| 313 | |
| 314 | return(conf[detected].size); |
| 315 | } |
| 316 | |
| 317 | /************************************************************************** |
| 318 | * Sets DDR bank CS bounds. |
| 319 | */ |
Bin Meng | 4019e54 | 2016-01-25 00:29:55 -0800 | [diff] [blame] | 320 | static void set_cs_bounds(short cs, ulong base, ulong size) |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 321 | { |
Marek Vasut | 3d54639 | 2011-10-21 14:17:10 +0000 | [diff] [blame] | 322 | debug("Setting bounds %08lx, %08lx for cs %d\n", base, size, cs); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 323 | if(size == 0){ |
| 324 | im->ddr.csbnds[cs].csbnds = 0x00000000; |
| 325 | } else { |
| 326 | im->ddr.csbnds[cs].csbnds = |
| 327 | ((base >> CSBNDS_SA_SHIFT) & CSBNDS_SA) | |
| 328 | (((base + size - 1) >> CSBNDS_EA_SHIFT) & |
| 329 | CSBNDS_EA); |
| 330 | } |
| 331 | SYNC; |
| 332 | } |
| 333 | |
| 334 | /************************************************************************** |
| 335 | * Sets DDR banks CS configuration. |
| 336 | * config == 0x00000000 disables the CS. |
| 337 | */ |
| 338 | static void set_cs_config(short cs, long config) |
| 339 | { |
Marek Vasut | 3d54639 | 2011-10-21 14:17:10 +0000 | [diff] [blame] | 340 | debug("Setting config %08lx for cs %d\n", config, cs); |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 341 | im->ddr.cs_config[cs] = config; |
| 342 | SYNC; |
| 343 | } |
| 344 | |
| 345 | /************************************************************************** |
| 346 | * Sets DDR clocks, timings and configuration. |
| 347 | */ |
| 348 | static void set_ddr_config(void) { |
| 349 | /* clock control */ |
| 350 | im->ddr.sdram_clk_cntl = DDR_SDRAM_CLK_CNTL_SS_EN | |
| 351 | DDR_SDRAM_CLK_CNTL_CLK_ADJUST_05; |
| 352 | SYNC; |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 353 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 354 | /* timing configuration */ |
| 355 | im->ddr.timing_cfg_1 = |
| 356 | (4 << TIMING_CFG1_PRETOACT_SHIFT) | |
| 357 | (7 << TIMING_CFG1_ACTTOPRE_SHIFT) | |
| 358 | (4 << TIMING_CFG1_ACTTORW_SHIFT) | |
| 359 | (5 << TIMING_CFG1_REFREC_SHIFT) | |
| 360 | (3 << TIMING_CFG1_WRREC_SHIFT) | |
| 361 | (3 << TIMING_CFG1_ACTTOACT_SHIFT) | |
| 362 | (1 << TIMING_CFG1_WRTORD_SHIFT) | |
| 363 | (TIMING_CFG1_CASLAT & TIMING_CASLAT); |
| 364 | |
| 365 | im->ddr.timing_cfg_2 = |
| 366 | TIMING_CFG2_CPO_DEF | |
| 367 | (2 << TIMING_CFG2_WR_DATA_DELAY_SHIFT); |
| 368 | SYNC; |
| 369 | |
| 370 | /* don't enable DDR controller yet */ |
| 371 | im->ddr.sdram_cfg = |
| 372 | SDRAM_CFG_SREN | |
Kim Phillips | bbea46f | 2007-08-16 22:52:48 -0500 | [diff] [blame] | 373 | SDRAM_CFG_SDRAM_TYPE_DDR1; |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 374 | SYNC; |
Wolfgang Denk | f013dac | 2005-12-04 00:40:34 +0100 | [diff] [blame] | 375 | |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 376 | /* Set SDRAM mode */ |
| 377 | im->ddr.sdram_mode = |
| 378 | ((DDR_MODE_EXT_MODEREG | DDR_MODE_WEAK) << |
| 379 | SDRAM_MODE_ESD_SHIFT) | |
| 380 | ((DDR_MODE_MODEREG | DDR_MODE_BLEN_4) << |
| 381 | SDRAM_MODE_SD_SHIFT) | |
| 382 | ((DDR_MODE_CASLAT << SDRAM_MODE_SD_SHIFT) & |
| 383 | MODE_CASLAT); |
| 384 | SYNC; |
| 385 | |
| 386 | /* Set fast SDRAM refresh rate */ |
| 387 | im->ddr.sdram_interval = |
| 388 | (DDR_REFINT_166MHZ_7US << SDRAM_INTERVAL_REFINT_SHIFT) | |
| 389 | (DDR_BSTOPRE << SDRAM_INTERVAL_BSTOPRE_SHIFT); |
| 390 | SYNC; |
Wolfgang Denk | 10af6d5 | 2006-06-16 16:53:06 +0200 | [diff] [blame] | 391 | |
| 392 | /* Workaround for DDR6 Erratum |
| 393 | * see MPC8349E Device Errata Rev.8, 2/2006 |
| 394 | * This workaround influences the MPC internal "input enables" |
| 395 | * dependent on CAS latency and MPC revision. According to errata |
| 396 | * sheet the internal reserved registers for this workaround are |
| 397 | * not available from revision 2.0 and up. |
| 398 | */ |
| 399 | |
| 400 | /* Get REVID from register SPRIDR. Skip workaround if rev >= 2.0 |
| 401 | * (0x200) |
| 402 | */ |
| 403 | if ((im->sysconf.spridr & SPRIDR_REVID) < 0x200) { |
| 404 | |
| 405 | /* There is a internal reserved register at IMMRBAR+0x2F00 |
| 406 | * which has to be written with a certain value defined by |
| 407 | * errata sheet. |
| 408 | */ |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 409 | u32 *reserved_p = (u32 *)((u8 *)im + 0x2f00); |
| 410 | |
Wolfgang Denk | 10af6d5 | 2006-06-16 16:53:06 +0200 | [diff] [blame] | 411 | #if defined(DDR_CASLAT_20) |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 412 | *reserved_p = 0x201c0000; |
Wolfgang Denk | 10af6d5 | 2006-06-16 16:53:06 +0200 | [diff] [blame] | 413 | #else |
Wolfgang Denk | 966083e | 2006-07-21 15:24:56 +0200 | [diff] [blame] | 414 | *reserved_p = 0x202c0000; |
Wolfgang Denk | 10af6d5 | 2006-06-16 16:53:06 +0200 | [diff] [blame] | 415 | #endif |
| 416 | } |
Marian Balakowicz | e6f2e90 | 2005-10-11 19:09:42 +0200 | [diff] [blame] | 417 | } |
Wolfgang Denk | 4681e67 | 2009-05-14 23:18:34 +0200 | [diff] [blame] | 418 | |
| 419 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 420 | int ft_board_setup(void *blob, bd_t *bd) |
Wolfgang Denk | 4681e67 | 2009-05-14 23:18:34 +0200 | [diff] [blame] | 421 | { |
| 422 | ft_cpu_setup(blob, bd); |
| 423 | |
| 424 | #ifdef CONFIG_PCI |
| 425 | ft_pci_setup(blob, bd); |
| 426 | #endif /* CONFIG_PCI */ |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 427 | |
| 428 | return 0; |
Wolfgang Denk | 4681e67 | 2009-05-14 23:18:34 +0200 | [diff] [blame] | 429 | } |
| 430 | #endif /* CONFIG_OF_BOARD_SETUP */ |