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