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