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