Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 1 | /* |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 2 | * Copyright 2008-2014 Freescale Semiconductor, Inc. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * Version 2 as published by the Free Software Foundation. |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 10 | #ifdef CONFIG_PPC |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 11 | #include <asm/fsl_law.h> |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 12 | #endif |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 13 | #include <div64.h> |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 14 | |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 15 | #include <fsl_ddr.h> |
York Sun | a21803d | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 16 | #include <fsl_immap.h> |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 17 | #include <asm/io.h> |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 18 | |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 19 | /* To avoid 64-bit full-divides, we factor this here */ |
Kyle Moffett | 313e827 | 2011-04-14 13:39:30 -0400 | [diff] [blame] | 20 | #define ULL_2E12 2000000000000ULL |
| 21 | #define UL_5POW12 244140625UL |
| 22 | #define UL_2POW13 (1UL << 13) |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 23 | |
Kyle Moffett | 313e827 | 2011-04-14 13:39:30 -0400 | [diff] [blame] | 24 | #define ULL_8FS 0xFFFFFFFFULL |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 25 | |
York Sun | 55eb5fa | 2015-03-19 09:30:26 -0700 | [diff] [blame^] | 26 | u32 fsl_ddr_get_version(unsigned int ctrl_num) |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 27 | { |
| 28 | struct ccsr_ddr __iomem *ddr; |
| 29 | u32 ver_major_minor_errata; |
| 30 | |
York Sun | 55eb5fa | 2015-03-19 09:30:26 -0700 | [diff] [blame^] | 31 | switch (ctrl_num) { |
| 32 | case 0: |
| 33 | ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 34 | break; |
| 35 | #if defined(CONFIG_SYS_FSL_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1) |
| 36 | case 1: |
| 37 | ddr = (void *)CONFIG_SYS_FSL_DDR2_ADDR; |
| 38 | break; |
| 39 | #endif |
| 40 | #if defined(CONFIG_SYS_FSL_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2) |
| 41 | case 2: |
| 42 | ddr = (void *)CONFIG_SYS_FSL_DDR3_ADDR; |
| 43 | break; |
| 44 | #endif |
| 45 | #if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3) |
| 46 | case 3: |
| 47 | ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR; |
| 48 | break; |
| 49 | #endif |
| 50 | default: |
| 51 | printf("%s unexpected ctrl_num = %u\n", __func__, ctrl_num); |
| 52 | return 0; |
| 53 | } |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 54 | ver_major_minor_errata = (ddr_in32(&ddr->ip_rev1) & 0xFFFF) << 8; |
| 55 | ver_major_minor_errata |= (ddr_in32(&ddr->ip_rev2) & 0xFF00) >> 8; |
| 56 | |
| 57 | return ver_major_minor_errata; |
| 58 | } |
| 59 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 60 | /* |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 61 | * Round up mclk_ps to nearest 1 ps in memory controller code |
| 62 | * if the error is 0.5ps or more. |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 63 | * |
| 64 | * If an imprecise data rate is too high due to rounding error |
| 65 | * propagation, compute a suitably rounded mclk_ps to compute |
| 66 | * a working memory controller configuration. |
| 67 | */ |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 68 | unsigned int get_memory_clk_period_ps(const unsigned int ctrl_num) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 69 | { |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 70 | unsigned int data_rate = get_ddr_freq(ctrl_num); |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 71 | unsigned int result; |
| 72 | |
| 73 | /* Round to nearest 10ps, being careful about 64-bit multiply/divide */ |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 74 | unsigned long long rem, mclk_ps = ULL_2E12; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 75 | |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 76 | /* Now perform the big divide, the result fits in 32-bits */ |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 77 | rem = do_div(mclk_ps, data_rate); |
| 78 | result = (rem >= (data_rate >> 1)) ? mclk_ps + 1 : mclk_ps; |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 79 | |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 80 | return result; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /* Convert picoseconds into DRAM clock cycles (rounding up if needed). */ |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 84 | unsigned int picos_to_mclk(const unsigned int ctrl_num, unsigned int picos) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 85 | { |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 86 | unsigned long long clks, clks_rem; |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 87 | unsigned long data_rate = get_ddr_freq(ctrl_num); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 88 | |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 89 | /* Short circuit for zero picos */ |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 90 | if (!picos) |
| 91 | return 0; |
| 92 | |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 93 | /* First multiply the time by the data rate (32x32 => 64) */ |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 94 | clks = picos * (unsigned long long)data_rate; |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 95 | /* |
| 96 | * Now divide by 5^12 and track the 32-bit remainder, then divide |
| 97 | * by 2*(2^12) using shifts (and updating the remainder). |
| 98 | */ |
Kyle Moffett | 313e827 | 2011-04-14 13:39:30 -0400 | [diff] [blame] | 99 | clks_rem = do_div(clks, UL_5POW12); |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 100 | clks_rem += (clks & (UL_2POW13-1)) * UL_5POW12; |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 101 | clks >>= 13; |
| 102 | |
York Sun | dc4d40c | 2011-08-26 11:32:42 -0700 | [diff] [blame] | 103 | /* If we had a remainder greater than the 1ps error, then round up */ |
| 104 | if (clks_rem > data_rate) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 105 | clks++; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 106 | |
Kyle Moffett | e37716a | 2011-03-15 11:23:47 -0400 | [diff] [blame] | 107 | /* Clamp to the maximum representable value */ |
Kyle Moffett | 313e827 | 2011-04-14 13:39:30 -0400 | [diff] [blame] | 108 | if (clks > ULL_8FS) |
| 109 | clks = ULL_8FS; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 110 | return (unsigned int) clks; |
| 111 | } |
| 112 | |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 113 | unsigned int mclk_to_picos(const unsigned int ctrl_num, unsigned int mclk) |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 114 | { |
York Sun | 2c0b62d | 2015-01-06 13:18:50 -0800 | [diff] [blame] | 115 | return get_memory_clk_period_ps(ctrl_num) * mclk; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 116 | } |
| 117 | |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 118 | #ifdef CONFIG_PPC |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 119 | void |
| 120 | __fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params, |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 121 | unsigned int law_memctl, |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 122 | unsigned int ctrl_num) |
| 123 | { |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 124 | unsigned long long base = memctl_common_params->base_address; |
| 125 | unsigned long long size = memctl_common_params->total_mem; |
| 126 | |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 127 | /* |
| 128 | * If no DIMMs on this controller, do not proceed any further. |
| 129 | */ |
| 130 | if (!memctl_common_params->ndimms_present) { |
| 131 | return; |
| 132 | } |
| 133 | |
Kumar Gala | 68ef4bd | 2009-06-11 23:42:35 -0500 | [diff] [blame] | 134 | #if !defined(CONFIG_PHYS_64BIT) |
| 135 | if (base >= CONFIG_MAX_MEM_MAPPED) |
| 136 | return; |
| 137 | if ((base + size) >= CONFIG_MAX_MEM_MAPPED) |
| 138 | size = CONFIG_MAX_MEM_MAPPED - base; |
| 139 | #endif |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 140 | if (set_ddr_laws(base, size, law_memctl) < 0) { |
| 141 | printf("%s: ERROR (ctrl #%d, TRGT ID=%x)\n", __func__, ctrl_num, |
| 142 | law_memctl); |
| 143 | return ; |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 144 | } |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 145 | debug("setup ddr law base = 0x%llx, size 0x%llx, TRGT_ID 0x%x\n", |
| 146 | base, size, law_memctl); |
Kumar Gala | 124b082 | 2008-08-26 15:01:29 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | __attribute__((weak, alias("__fsl_ddr_set_lawbar"))) void |
| 150 | fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params, |
| 151 | unsigned int memctl_interleaved, |
| 152 | unsigned int ctrl_num); |
York Sun | 461c939 | 2013-09-30 14:20:51 -0700 | [diff] [blame] | 153 | #endif |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 154 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 155 | void fsl_ddr_set_intl3r(const unsigned int granule_size) |
| 156 | { |
| 157 | #ifdef CONFIG_E6500 |
| 158 | u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004); |
| 159 | *mcintl3r = 0x80000000 | (granule_size & 0x1f); |
| 160 | debug("Enable MCINTL3R with granule size 0x%x\n", granule_size); |
| 161 | #endif |
| 162 | } |
| 163 | |
York Sun | a28496f | 2012-10-08 07:44:25 +0000 | [diff] [blame] | 164 | u32 fsl_ddr_get_intl3r(void) |
| 165 | { |
| 166 | u32 val = 0; |
| 167 | #ifdef CONFIG_E6500 |
| 168 | u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004); |
| 169 | val = *mcintl3r; |
| 170 | #endif |
| 171 | return val; |
| 172 | } |
| 173 | |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 174 | void print_ddr_info(unsigned int start_ctrl) |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 175 | { |
York Sun | a21803d | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 176 | struct ccsr_ddr __iomem *ddr = |
| 177 | (struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR); |
Andy Fleming | 992562c | 2012-10-23 19:03:46 -0500 | [diff] [blame] | 178 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 179 | #if defined(CONFIG_E6500) && (CONFIG_NUM_DDR_CONTROLLERS == 3) |
| 180 | u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004); |
| 181 | #endif |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 182 | #if (CONFIG_NUM_DDR_CONTROLLERS > 1) |
York Sun | 29647ab | 2014-02-10 13:59:42 -0800 | [diff] [blame] | 183 | uint32_t cs0_config = ddr_in32(&ddr->cs0_config); |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 184 | #endif |
York Sun | 29647ab | 2014-02-10 13:59:42 -0800 | [diff] [blame] | 185 | uint32_t sdram_cfg = ddr_in32(&ddr->sdram_cfg); |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 186 | int cas_lat; |
| 187 | |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 188 | #if CONFIG_NUM_DDR_CONTROLLERS >= 2 |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 189 | if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) || |
| 190 | (start_ctrl == 1)) { |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 191 | ddr = (void __iomem *)CONFIG_SYS_FSL_DDR2_ADDR; |
York Sun | 29647ab | 2014-02-10 13:59:42 -0800 | [diff] [blame] | 192 | sdram_cfg = ddr_in32(&ddr->sdram_cfg); |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 193 | } |
| 194 | #endif |
| 195 | #if CONFIG_NUM_DDR_CONTROLLERS >= 3 |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 196 | if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) || |
| 197 | (start_ctrl == 2)) { |
York Sun | f062659 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 198 | ddr = (void __iomem *)CONFIG_SYS_FSL_DDR3_ADDR; |
York Sun | 29647ab | 2014-02-10 13:59:42 -0800 | [diff] [blame] | 199 | sdram_cfg = ddr_in32(&ddr->sdram_cfg); |
York Sun | 98df4d1 | 2012-10-08 07:44:23 +0000 | [diff] [blame] | 200 | } |
| 201 | #endif |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 202 | |
| 203 | if (!(sdram_cfg & SDRAM_CFG_MEM_EN)) { |
| 204 | puts(" (DDR not enabled)\n"); |
| 205 | return; |
| 206 | } |
| 207 | |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 208 | puts(" (DDR"); |
| 209 | switch ((sdram_cfg & SDRAM_CFG_SDRAM_TYPE_MASK) >> |
| 210 | SDRAM_CFG_SDRAM_TYPE_SHIFT) { |
| 211 | case SDRAM_TYPE_DDR1: |
| 212 | puts("1"); |
| 213 | break; |
| 214 | case SDRAM_TYPE_DDR2: |
| 215 | puts("2"); |
| 216 | break; |
| 217 | case SDRAM_TYPE_DDR3: |
| 218 | puts("3"); |
| 219 | break; |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 220 | case SDRAM_TYPE_DDR4: |
| 221 | puts("4"); |
| 222 | break; |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 223 | default: |
| 224 | puts("?"); |
| 225 | break; |
| 226 | } |
| 227 | |
| 228 | if (sdram_cfg & SDRAM_CFG_32_BE) |
| 229 | puts(", 32-bit"); |
Poonam Aggrwal | 42d3640 | 2011-02-07 15:09:51 +0530 | [diff] [blame] | 230 | else if (sdram_cfg & SDRAM_CFG_16_BE) |
| 231 | puts(", 16-bit"); |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 232 | else |
| 233 | puts(", 64-bit"); |
| 234 | |
| 235 | /* Calculate CAS latency based on timing cfg values */ |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 236 | cas_lat = ((ddr_in32(&ddr->timing_cfg_1) >> 16) & 0xf); |
York Sun | 55eb5fa | 2015-03-19 09:30:26 -0700 | [diff] [blame^] | 237 | if (fsl_ddr_get_version(0) <= 0x40400) |
York Sun | 2896cb7 | 2014-03-27 17:54:47 -0700 | [diff] [blame] | 238 | cas_lat += 1; |
| 239 | else |
| 240 | cas_lat += 2; |
| 241 | cas_lat += ((ddr_in32(&ddr->timing_cfg_3) >> 12) & 3) << 4; |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 242 | printf(", CL=%d", cas_lat >> 1); |
| 243 | if (cas_lat & 0x1) |
| 244 | puts(".5"); |
| 245 | |
| 246 | if (sdram_cfg & SDRAM_CFG_ECC_EN) |
| 247 | puts(", ECC on)"); |
| 248 | else |
| 249 | puts(", ECC off)"); |
| 250 | |
York Sun | e8dc17b | 2012-08-17 08:22:39 +0000 | [diff] [blame] | 251 | #if (CONFIG_NUM_DDR_CONTROLLERS == 3) |
| 252 | #ifdef CONFIG_E6500 |
| 253 | if (*mcintl3r & 0x80000000) { |
| 254 | puts("\n"); |
| 255 | puts(" DDR Controller Interleaving Mode: "); |
| 256 | switch (*mcintl3r & 0x1f) { |
| 257 | case FSL_DDR_3WAY_1KB_INTERLEAVING: |
| 258 | puts("3-way 1KB"); |
| 259 | break; |
| 260 | case FSL_DDR_3WAY_4KB_INTERLEAVING: |
| 261 | puts("3-way 4KB"); |
| 262 | break; |
| 263 | case FSL_DDR_3WAY_8KB_INTERLEAVING: |
| 264 | puts("3-way 8KB"); |
| 265 | break; |
| 266 | default: |
| 267 | puts("3-way UNKNOWN"); |
| 268 | break; |
| 269 | } |
| 270 | } |
| 271 | #endif |
| 272 | #endif |
| 273 | #if (CONFIG_NUM_DDR_CONTROLLERS >= 2) |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 274 | if ((cs0_config & 0x20000000) && (start_ctrl == 0)) { |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 275 | puts("\n"); |
| 276 | puts(" DDR Controller Interleaving Mode: "); |
| 277 | |
| 278 | switch ((cs0_config >> 24) & 0xf) { |
York Sun | c459ae6 | 2014-02-10 13:59:44 -0800 | [diff] [blame] | 279 | case FSL_DDR_256B_INTERLEAVING: |
| 280 | puts("256B"); |
| 281 | break; |
Peter Tyser | f4018f9 | 2009-07-17 10:14:48 -0500 | [diff] [blame] | 282 | case FSL_DDR_CACHE_LINE_INTERLEAVING: |
| 283 | puts("cache line"); |
| 284 | break; |
| 285 | case FSL_DDR_PAGE_INTERLEAVING: |
| 286 | puts("page"); |
| 287 | break; |
| 288 | case FSL_DDR_BANK_INTERLEAVING: |
| 289 | puts("bank"); |
| 290 | break; |
| 291 | case FSL_DDR_SUPERBANK_INTERLEAVING: |
| 292 | puts("super-bank"); |
| 293 | break; |
| 294 | default: |
| 295 | puts("invalid"); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | #endif |
| 300 | |
| 301 | if ((sdram_cfg >> 8) & 0x7f) { |
| 302 | puts("\n"); |
| 303 | puts(" DDR Chip-Select Interleaving Mode: "); |
| 304 | switch(sdram_cfg >> 8 & 0x7f) { |
| 305 | case FSL_DDR_CS0_CS1_CS2_CS3: |
| 306 | puts("CS0+CS1+CS2+CS3"); |
| 307 | break; |
| 308 | case FSL_DDR_CS0_CS1: |
| 309 | puts("CS0+CS1"); |
| 310 | break; |
| 311 | case FSL_DDR_CS2_CS3: |
| 312 | puts("CS2+CS3"); |
| 313 | break; |
| 314 | case FSL_DDR_CS0_CS1_AND_CS2_CS3: |
| 315 | puts("CS0+CS1 and CS2+CS3"); |
| 316 | break; |
| 317 | default: |
| 318 | puts("invalid"); |
| 319 | break; |
| 320 | } |
| 321 | } |
| 322 | } |
York Sun | 79a779b | 2014-08-01 15:51:00 -0700 | [diff] [blame] | 323 | |
| 324 | void __weak detail_board_ddr_info(void) |
| 325 | { |
| 326 | print_ddr_info(0); |
| 327 | } |
| 328 | |
| 329 | void board_add_ram_info(int use_default) |
| 330 | { |
| 331 | detail_board_ddr_info(); |
| 332 | } |
York Sun | 8ced050 | 2015-01-06 13:18:55 -0800 | [diff] [blame] | 333 | |
| 334 | #ifdef CONFIG_FSL_DDR_SYNC_REFRESH |
| 335 | #define DDRC_DEBUG20_INIT_DONE 0x80000000 |
| 336 | #define DDRC_DEBUG2_RF 0x00000040 |
| 337 | void fsl_ddr_sync_memctl_refresh(unsigned int first_ctrl, |
| 338 | unsigned int last_ctrl) |
| 339 | { |
| 340 | unsigned int i; |
| 341 | u32 ddrc_debug20; |
| 342 | u32 ddrc_debug2[CONFIG_NUM_DDR_CONTROLLERS] = {}; |
| 343 | u32 *ddrc_debug2_p[CONFIG_NUM_DDR_CONTROLLERS] = {}; |
| 344 | struct ccsr_ddr __iomem *ddr; |
| 345 | |
| 346 | for (i = first_ctrl; i <= last_ctrl; i++) { |
| 347 | switch (i) { |
| 348 | case 0: |
| 349 | ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR; |
| 350 | break; |
| 351 | #if defined(CONFIG_SYS_FSL_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1) |
| 352 | case 1: |
| 353 | ddr = (void *)CONFIG_SYS_FSL_DDR2_ADDR; |
| 354 | break; |
| 355 | #endif |
| 356 | #if defined(CONFIG_SYS_FSL_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2) |
| 357 | case 2: |
| 358 | ddr = (void *)CONFIG_SYS_FSL_DDR3_ADDR; |
| 359 | break; |
| 360 | #endif |
| 361 | #if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3) |
| 362 | case 3: |
| 363 | ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR; |
| 364 | break; |
| 365 | #endif |
| 366 | default: |
| 367 | printf("%s unexpected ctrl = %u\n", __func__, i); |
| 368 | return; |
| 369 | } |
| 370 | ddrc_debug20 = ddr_in32(&ddr->debug[19]); |
| 371 | ddrc_debug2_p[i] = &ddr->debug[1]; |
| 372 | while (!(ddrc_debug20 & DDRC_DEBUG20_INIT_DONE)) { |
| 373 | /* keep polling until DDRC init is done */ |
| 374 | udelay(100); |
| 375 | ddrc_debug20 = ddr_in32(&ddr->debug[19]); |
| 376 | } |
| 377 | ddrc_debug2[i] = ddr_in32(&ddr->debug[1]) | DDRC_DEBUG2_RF; |
| 378 | } |
| 379 | /* |
| 380 | * Sync refresh |
| 381 | * This is put together to make sure the refresh reqeusts are sent |
| 382 | * closely to each other. |
| 383 | */ |
| 384 | for (i = first_ctrl; i <= last_ctrl; i++) |
| 385 | ddr_out32(ddrc_debug2_p[i], ddrc_debug2[i]); |
| 386 | } |
| 387 | #endif /* CONFIG_FSL_DDR_SYNC_REFRESH */ |