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