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