blob: 0a73170e41835adeaa34bbf94db5eeb493eb124b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kumar Gala124b0822008-08-26 15:01:29 -05002/*
York Sun2896cb72014-03-27 17:54:47 -07003 * Copyright 2008-2014 Freescale Semiconductor, Inc.
Priyanka Singhbc4ef9c2021-08-19 11:39:01 +05304 * Copyright 2021 NXP
Kumar Gala124b0822008-08-26 15:01:29 -05005 */
6
Tom Rinidec7ea02024-05-20 13:35:03 -06007#include <config.h>
York Sun461c9392013-09-30 14:20:51 -07008#ifdef CONFIG_PPC
Kumar Gala124b0822008-08-26 15:01:29 -05009#include <asm/fsl_law.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060010#include <asm/ppc.h>
York Sun461c9392013-09-30 14:20:51 -070011#endif
Kyle Moffette37716a2011-03-15 11:23:47 -040012#include <div64.h>
Simon Glassdbd79542020-05-10 11:40:11 -060013#include <linux/delay.h>
Kumar Gala124b0822008-08-26 15:01:29 -050014
York Sunf0626592013-09-30 09:22:09 -070015#include <fsl_ddr.h>
York Suna21803d2013-11-18 10:29:32 -080016#include <fsl_immap.h>
Simon Glass0f2af882020-05-10 11:40:05 -060017#include <log.h>
York Sunf0626592013-09-30 09:22:09 -070018#include <asm/io.h>
Simon Glass89e0a3a2017-05-17 08:23:10 -060019#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
20 defined(CONFIG_ARM)
Simon Glass243182c2017-05-17 08:23:06 -060021#include <asm/arch/clock.h>
22#endif
Kumar Gala124b0822008-08-26 15:01:29 -050023
Kyle Moffette37716a2011-03-15 11:23:47 -040024/* To avoid 64-bit full-divides, we factor this here */
Kyle Moffett313e8272011-04-14 13:39:30 -040025#define ULL_2E12 2000000000000ULL
26#define UL_5POW12 244140625UL
27#define UL_2POW13 (1UL << 13)
Kyle Moffette37716a2011-03-15 11:23:47 -040028
Kyle Moffett313e8272011-04-14 13:39:30 -040029#define ULL_8FS 0xFFFFFFFFULL
Kyle Moffette37716a2011-03-15 11:23:47 -040030
York Sun55eb5fa2015-03-19 09:30:26 -070031u32 fsl_ddr_get_version(unsigned int ctrl_num)
York Sun2896cb72014-03-27 17:54:47 -070032{
33 struct ccsr_ddr __iomem *ddr;
34 u32 ver_major_minor_errata;
35
York Sun55eb5fa2015-03-19 09:30:26 -070036 switch (ctrl_num) {
37 case 0:
Tom Rini376b88a2022-10-28 20:27:13 -040038 ddr = (void *)CFG_SYS_FSL_DDR_ADDR;
York Sun55eb5fa2015-03-19 09:30:26 -070039 break;
Tom Rini376b88a2022-10-28 20:27:13 -040040#if defined(CFG_SYS_FSL_DDR2_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sun55eb5fa2015-03-19 09:30:26 -070041 case 1:
Tom Rini376b88a2022-10-28 20:27:13 -040042 ddr = (void *)CFG_SYS_FSL_DDR2_ADDR;
York Sun55eb5fa2015-03-19 09:30:26 -070043 break;
44#endif
Tom Rini376b88a2022-10-28 20:27:13 -040045#if defined(CFG_SYS_FSL_DDR3_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 2)
York Sun55eb5fa2015-03-19 09:30:26 -070046 case 2:
Tom Rini376b88a2022-10-28 20:27:13 -040047 ddr = (void *)CFG_SYS_FSL_DDR3_ADDR;
York Sun55eb5fa2015-03-19 09:30:26 -070048 break;
49#endif
York Sunfe845072016-12-28 08:43:45 -080050#if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 3)
York Sun55eb5fa2015-03-19 09:30:26 -070051 case 3:
52 ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR;
53 break;
54#endif
55 default:
56 printf("%s unexpected ctrl_num = %u\n", __func__, ctrl_num);
57 return 0;
58 }
York Sun2896cb72014-03-27 17:54:47 -070059 ver_major_minor_errata = (ddr_in32(&ddr->ip_rev1) & 0xFFFF) << 8;
60 ver_major_minor_errata |= (ddr_in32(&ddr->ip_rev2) & 0xFF00) >> 8;
61
62 return ver_major_minor_errata;
63}
64
Kumar Gala124b0822008-08-26 15:01:29 -050065/*
York Sundc4d40c2011-08-26 11:32:42 -070066 * Round up mclk_ps to nearest 1 ps in memory controller code
67 * if the error is 0.5ps or more.
Kumar Gala124b0822008-08-26 15:01:29 -050068 *
69 * If an imprecise data rate is too high due to rounding error
70 * propagation, compute a suitably rounded mclk_ps to compute
71 * a working memory controller configuration.
72 */
York Sun2c0b62d2015-01-06 13:18:50 -080073unsigned int get_memory_clk_period_ps(const unsigned int ctrl_num)
Kumar Gala124b0822008-08-26 15:01:29 -050074{
York Sun2c0b62d2015-01-06 13:18:50 -080075 unsigned int data_rate = get_ddr_freq(ctrl_num);
Kyle Moffette37716a2011-03-15 11:23:47 -040076 unsigned int result;
77
78 /* Round to nearest 10ps, being careful about 64-bit multiply/divide */
York Sundc4d40c2011-08-26 11:32:42 -070079 unsigned long long rem, mclk_ps = ULL_2E12;
Priyanka Singhbc4ef9c2021-08-19 11:39:01 +053080 if (data_rate) {
81 /* Now perform the big divide, the result fits in 32-bits */
82 rem = do_div(mclk_ps, data_rate);
83 result = (rem >= (data_rate >> 1)) ? mclk_ps + 1 : mclk_ps;
84 } else {
85 result = 0;
86 }
Kyle Moffette37716a2011-03-15 11:23:47 -040087
York Sundc4d40c2011-08-26 11:32:42 -070088 return result;
Kumar Gala124b0822008-08-26 15:01:29 -050089}
90
91/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
York Sun2c0b62d2015-01-06 13:18:50 -080092unsigned int picos_to_mclk(const unsigned int ctrl_num, unsigned int picos)
Kumar Gala124b0822008-08-26 15:01:29 -050093{
Kyle Moffette37716a2011-03-15 11:23:47 -040094 unsigned long long clks, clks_rem;
York Sun2c0b62d2015-01-06 13:18:50 -080095 unsigned long data_rate = get_ddr_freq(ctrl_num);
Kumar Gala124b0822008-08-26 15:01:29 -050096
Kyle Moffette37716a2011-03-15 11:23:47 -040097 /* Short circuit for zero picos */
Kumar Gala124b0822008-08-26 15:01:29 -050098 if (!picos)
99 return 0;
100
Kyle Moffette37716a2011-03-15 11:23:47 -0400101 /* First multiply the time by the data rate (32x32 => 64) */
York Sundc4d40c2011-08-26 11:32:42 -0700102 clks = picos * (unsigned long long)data_rate;
Kyle Moffette37716a2011-03-15 11:23:47 -0400103 /*
104 * Now divide by 5^12 and track the 32-bit remainder, then divide
105 * by 2*(2^12) using shifts (and updating the remainder).
106 */
Kyle Moffett313e8272011-04-14 13:39:30 -0400107 clks_rem = do_div(clks, UL_5POW12);
York Sundc4d40c2011-08-26 11:32:42 -0700108 clks_rem += (clks & (UL_2POW13-1)) * UL_5POW12;
Kyle Moffette37716a2011-03-15 11:23:47 -0400109 clks >>= 13;
110
York Sundc4d40c2011-08-26 11:32:42 -0700111 /* If we had a remainder greater than the 1ps error, then round up */
112 if (clks_rem > data_rate)
Kumar Gala124b0822008-08-26 15:01:29 -0500113 clks++;
Kumar Gala124b0822008-08-26 15:01:29 -0500114
Kyle Moffette37716a2011-03-15 11:23:47 -0400115 /* Clamp to the maximum representable value */
Kyle Moffett313e8272011-04-14 13:39:30 -0400116 if (clks > ULL_8FS)
117 clks = ULL_8FS;
Kumar Gala124b0822008-08-26 15:01:29 -0500118 return (unsigned int) clks;
119}
120
York Sun2c0b62d2015-01-06 13:18:50 -0800121unsigned int mclk_to_picos(const unsigned int ctrl_num, unsigned int mclk)
Kumar Gala124b0822008-08-26 15:01:29 -0500122{
York Sun2c0b62d2015-01-06 13:18:50 -0800123 return get_memory_clk_period_ps(ctrl_num) * mclk;
Kumar Gala124b0822008-08-26 15:01:29 -0500124}
125
York Sun461c9392013-09-30 14:20:51 -0700126#ifdef CONFIG_PPC
Kumar Gala124b0822008-08-26 15:01:29 -0500127void
128__fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
York Sune8dc17b2012-08-17 08:22:39 +0000129 unsigned int law_memctl,
Kumar Gala124b0822008-08-26 15:01:29 -0500130 unsigned int ctrl_num)
131{
Kumar Gala68ef4bd2009-06-11 23:42:35 -0500132 unsigned long long base = memctl_common_params->base_address;
133 unsigned long long size = memctl_common_params->total_mem;
134
Kumar Gala124b0822008-08-26 15:01:29 -0500135 /*
136 * If no DIMMs on this controller, do not proceed any further.
137 */
138 if (!memctl_common_params->ndimms_present) {
139 return;
140 }
141
Kumar Gala68ef4bd2009-06-11 23:42:35 -0500142#if !defined(CONFIG_PHYS_64BIT)
Tom Rinibc9d46b2022-12-04 10:04:50 -0500143 if (base >= CFG_MAX_MEM_MAPPED)
Kumar Gala68ef4bd2009-06-11 23:42:35 -0500144 return;
Tom Rinibc9d46b2022-12-04 10:04:50 -0500145 if ((base + size) >= CFG_MAX_MEM_MAPPED)
146 size = CFG_MAX_MEM_MAPPED - base;
Kumar Gala68ef4bd2009-06-11 23:42:35 -0500147#endif
York Sune8dc17b2012-08-17 08:22:39 +0000148 if (set_ddr_laws(base, size, law_memctl) < 0) {
149 printf("%s: ERROR (ctrl #%d, TRGT ID=%x)\n", __func__, ctrl_num,
150 law_memctl);
Bin Meng75a6a372022-10-26 12:40:07 +0800151 return;
Kumar Gala124b0822008-08-26 15:01:29 -0500152 }
York Sune8dc17b2012-08-17 08:22:39 +0000153 debug("setup ddr law base = 0x%llx, size 0x%llx, TRGT_ID 0x%x\n",
154 base, size, law_memctl);
Kumar Gala124b0822008-08-26 15:01:29 -0500155}
156
157__attribute__((weak, alias("__fsl_ddr_set_lawbar"))) void
158fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
159 unsigned int memctl_interleaved,
160 unsigned int ctrl_num);
York Sun461c9392013-09-30 14:20:51 -0700161#endif
Peter Tyserf4018f92009-07-17 10:14:48 -0500162
York Sune8dc17b2012-08-17 08:22:39 +0000163void fsl_ddr_set_intl3r(const unsigned int granule_size)
164{
165#ifdef CONFIG_E6500
166 u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004);
167 *mcintl3r = 0x80000000 | (granule_size & 0x1f);
168 debug("Enable MCINTL3R with granule size 0x%x\n", granule_size);
169#endif
170}
171
York Suna28496f2012-10-08 07:44:25 +0000172u32 fsl_ddr_get_intl3r(void)
173{
174 u32 val = 0;
175#ifdef CONFIG_E6500
176 u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004);
177 val = *mcintl3r;
178#endif
179 return val;
180}
181
York Sun79a779b2014-08-01 15:51:00 -0700182void print_ddr_info(unsigned int start_ctrl)
Peter Tyserf4018f92009-07-17 10:14:48 -0500183{
York Suna21803d2013-11-18 10:29:32 -0800184 struct ccsr_ddr __iomem *ddr =
Tom Rini376b88a2022-10-28 20:27:13 -0400185 (struct ccsr_ddr __iomem *)(CFG_SYS_FSL_DDR_ADDR);
Andy Fleming992562c2012-10-23 19:03:46 -0500186
York Sunfe845072016-12-28 08:43:45 -0800187#if defined(CONFIG_E6500) && (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Sune8dc17b2012-08-17 08:22:39 +0000188 u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004);
189#endif
York Sunfe845072016-12-28 08:43:45 -0800190#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sun29647ab2014-02-10 13:59:42 -0800191 uint32_t cs0_config = ddr_in32(&ddr->cs0_config);
Peter Tyserf4018f92009-07-17 10:14:48 -0500192#endif
York Sun29647ab2014-02-10 13:59:42 -0800193 uint32_t sdram_cfg = ddr_in32(&ddr->sdram_cfg);
Peter Tyserf4018f92009-07-17 10:14:48 -0500194 int cas_lat;
195
York Sunfe845072016-12-28 08:43:45 -0800196#if CONFIG_SYS_NUM_DDR_CTLRS >= 2
York Sun79a779b2014-08-01 15:51:00 -0700197 if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) ||
198 (start_ctrl == 1)) {
Tom Rini376b88a2022-10-28 20:27:13 -0400199 ddr = (void __iomem *)CFG_SYS_FSL_DDR2_ADDR;
York Sun29647ab2014-02-10 13:59:42 -0800200 sdram_cfg = ddr_in32(&ddr->sdram_cfg);
York Sun98df4d12012-10-08 07:44:23 +0000201 }
202#endif
York Sunfe845072016-12-28 08:43:45 -0800203#if CONFIG_SYS_NUM_DDR_CTLRS >= 3
York Sun79a779b2014-08-01 15:51:00 -0700204 if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) ||
205 (start_ctrl == 2)) {
Tom Rini376b88a2022-10-28 20:27:13 -0400206 ddr = (void __iomem *)CFG_SYS_FSL_DDR3_ADDR;
York Sun29647ab2014-02-10 13:59:42 -0800207 sdram_cfg = ddr_in32(&ddr->sdram_cfg);
York Sun98df4d12012-10-08 07:44:23 +0000208 }
209#endif
York Sun79a779b2014-08-01 15:51:00 -0700210
211 if (!(sdram_cfg & SDRAM_CFG_MEM_EN)) {
212 puts(" (DDR not enabled)\n");
213 return;
214 }
215
Peter Tyserf4018f92009-07-17 10:14:48 -0500216 puts(" (DDR");
217 switch ((sdram_cfg & SDRAM_CFG_SDRAM_TYPE_MASK) >>
218 SDRAM_CFG_SDRAM_TYPE_SHIFT) {
219 case SDRAM_TYPE_DDR1:
220 puts("1");
221 break;
222 case SDRAM_TYPE_DDR2:
223 puts("2");
224 break;
225 case SDRAM_TYPE_DDR3:
226 puts("3");
227 break;
York Sun2896cb72014-03-27 17:54:47 -0700228 case SDRAM_TYPE_DDR4:
229 puts("4");
230 break;
Peter Tyserf4018f92009-07-17 10:14:48 -0500231 default:
232 puts("?");
233 break;
234 }
235
236 if (sdram_cfg & SDRAM_CFG_32_BE)
237 puts(", 32-bit");
Poonam Aggrwal42d36402011-02-07 15:09:51 +0530238 else if (sdram_cfg & SDRAM_CFG_16_BE)
239 puts(", 16-bit");
Peter Tyserf4018f92009-07-17 10:14:48 -0500240 else
241 puts(", 64-bit");
242
243 /* Calculate CAS latency based on timing cfg values */
York Sun2896cb72014-03-27 17:54:47 -0700244 cas_lat = ((ddr_in32(&ddr->timing_cfg_1) >> 16) & 0xf);
York Sun55eb5fa2015-03-19 09:30:26 -0700245 if (fsl_ddr_get_version(0) <= 0x40400)
York Sun2896cb72014-03-27 17:54:47 -0700246 cas_lat += 1;
247 else
248 cas_lat += 2;
249 cas_lat += ((ddr_in32(&ddr->timing_cfg_3) >> 12) & 3) << 4;
Peter Tyserf4018f92009-07-17 10:14:48 -0500250 printf(", CL=%d", cas_lat >> 1);
251 if (cas_lat & 0x1)
252 puts(".5");
253
254 if (sdram_cfg & SDRAM_CFG_ECC_EN)
255 puts(", ECC on)");
256 else
257 puts(", ECC off)");
258
York Sunfe845072016-12-28 08:43:45 -0800259#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Sune8dc17b2012-08-17 08:22:39 +0000260#ifdef CONFIG_E6500
261 if (*mcintl3r & 0x80000000) {
262 puts("\n");
263 puts(" DDR Controller Interleaving Mode: ");
264 switch (*mcintl3r & 0x1f) {
265 case FSL_DDR_3WAY_1KB_INTERLEAVING:
266 puts("3-way 1KB");
267 break;
268 case FSL_DDR_3WAY_4KB_INTERLEAVING:
269 puts("3-way 4KB");
270 break;
271 case FSL_DDR_3WAY_8KB_INTERLEAVING:
272 puts("3-way 8KB");
273 break;
274 default:
275 puts("3-way UNKNOWN");
276 break;
277 }
278 }
279#endif
280#endif
York Sunfe845072016-12-28 08:43:45 -0800281#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun79a779b2014-08-01 15:51:00 -0700282 if ((cs0_config & 0x20000000) && (start_ctrl == 0)) {
Peter Tyserf4018f92009-07-17 10:14:48 -0500283 puts("\n");
284 puts(" DDR Controller Interleaving Mode: ");
285
286 switch ((cs0_config >> 24) & 0xf) {
York Sunc459ae62014-02-10 13:59:44 -0800287 case FSL_DDR_256B_INTERLEAVING:
288 puts("256B");
289 break;
Peter Tyserf4018f92009-07-17 10:14:48 -0500290 case FSL_DDR_CACHE_LINE_INTERLEAVING:
291 puts("cache line");
292 break;
293 case FSL_DDR_PAGE_INTERLEAVING:
294 puts("page");
295 break;
296 case FSL_DDR_BANK_INTERLEAVING:
297 puts("bank");
298 break;
299 case FSL_DDR_SUPERBANK_INTERLEAVING:
300 puts("super-bank");
301 break;
302 default:
303 puts("invalid");
304 break;
305 }
306 }
307#endif
308
309 if ((sdram_cfg >> 8) & 0x7f) {
310 puts("\n");
311 puts(" DDR Chip-Select Interleaving Mode: ");
312 switch(sdram_cfg >> 8 & 0x7f) {
313 case FSL_DDR_CS0_CS1_CS2_CS3:
314 puts("CS0+CS1+CS2+CS3");
315 break;
316 case FSL_DDR_CS0_CS1:
317 puts("CS0+CS1");
318 break;
319 case FSL_DDR_CS2_CS3:
320 puts("CS2+CS3");
321 break;
322 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
323 puts("CS0+CS1 and CS2+CS3");
324 break;
325 default:
326 puts("invalid");
327 break;
328 }
329 }
330}
York Sun79a779b2014-08-01 15:51:00 -0700331
332void __weak detail_board_ddr_info(void)
333{
334 print_ddr_info(0);
335}
336
337void board_add_ram_info(int use_default)
338{
339 detail_board_ddr_info();
340}
York Sun8ced0502015-01-06 13:18:55 -0800341
342#ifdef CONFIG_FSL_DDR_SYNC_REFRESH
343#define DDRC_DEBUG20_INIT_DONE 0x80000000
344#define DDRC_DEBUG2_RF 0x00000040
345void fsl_ddr_sync_memctl_refresh(unsigned int first_ctrl,
346 unsigned int last_ctrl)
347{
348 unsigned int i;
349 u32 ddrc_debug20;
York Sunfe845072016-12-28 08:43:45 -0800350 u32 ddrc_debug2[CONFIG_SYS_NUM_DDR_CTLRS] = {};
351 u32 *ddrc_debug2_p[CONFIG_SYS_NUM_DDR_CTLRS] = {};
York Sun8ced0502015-01-06 13:18:55 -0800352 struct ccsr_ddr __iomem *ddr;
353
354 for (i = first_ctrl; i <= last_ctrl; i++) {
355 switch (i) {
356 case 0:
Tom Rini376b88a2022-10-28 20:27:13 -0400357 ddr = (void *)CFG_SYS_FSL_DDR_ADDR;
York Sun8ced0502015-01-06 13:18:55 -0800358 break;
Tom Rini376b88a2022-10-28 20:27:13 -0400359#if defined(CFG_SYS_FSL_DDR2_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sun8ced0502015-01-06 13:18:55 -0800360 case 1:
Tom Rini376b88a2022-10-28 20:27:13 -0400361 ddr = (void *)CFG_SYS_FSL_DDR2_ADDR;
York Sun8ced0502015-01-06 13:18:55 -0800362 break;
363#endif
Tom Rini376b88a2022-10-28 20:27:13 -0400364#if defined(CFG_SYS_FSL_DDR3_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 2)
York Sun8ced0502015-01-06 13:18:55 -0800365 case 2:
Tom Rini376b88a2022-10-28 20:27:13 -0400366 ddr = (void *)CFG_SYS_FSL_DDR3_ADDR;
York Sun8ced0502015-01-06 13:18:55 -0800367 break;
368#endif
York Sunfe845072016-12-28 08:43:45 -0800369#if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 3)
York Sun8ced0502015-01-06 13:18:55 -0800370 case 3:
371 ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR;
372 break;
373#endif
374 default:
375 printf("%s unexpected ctrl = %u\n", __func__, i);
376 return;
377 }
378 ddrc_debug20 = ddr_in32(&ddr->debug[19]);
379 ddrc_debug2_p[i] = &ddr->debug[1];
380 while (!(ddrc_debug20 & DDRC_DEBUG20_INIT_DONE)) {
381 /* keep polling until DDRC init is done */
382 udelay(100);
383 ddrc_debug20 = ddr_in32(&ddr->debug[19]);
384 }
385 ddrc_debug2[i] = ddr_in32(&ddr->debug[1]) | DDRC_DEBUG2_RF;
386 }
387 /*
388 * Sync refresh
389 * This is put together to make sure the refresh reqeusts are sent
390 * closely to each other.
391 */
392 for (i = first_ctrl; i <= last_ctrl; i++)
393 ddr_out32(ddrc_debug2_p[i], ddrc_debug2[i]);
394}
395#endif /* CONFIG_FSL_DDR_SYNC_REFRESH */
York Sund957a672015-11-04 09:53:10 -0800396
397void remove_unused_controllers(fsl_ddr_info_t *info)
398{
Ashish Kumarb25faa22017-08-31 16:12:53 +0530399#ifdef CONFIG_SYS_FSL_HAS_CCN504
York Sund957a672015-11-04 09:53:10 -0800400 int i;
401 u64 nodeid;
402 void *hnf_sam_ctrl = (void *)(CCI_HN_F_0_BASE + CCN_HN_F_SAM_CTL);
403 bool ddr0_used = false;
404 bool ddr1_used = false;
405
406 for (i = 0; i < 8; i++) {
407 nodeid = in_le64(hnf_sam_ctrl) & CCN_HN_F_SAM_NODEID_MASK;
408 if (nodeid == CCN_HN_F_SAM_NODEID_DDR0) {
409 ddr0_used = true;
410 } else if (nodeid == CCN_HN_F_SAM_NODEID_DDR1) {
411 ddr1_used = true;
412 } else {
413 printf("Unknown nodeid in HN-F SAM control: 0x%llx\n",
414 nodeid);
415 }
416 hnf_sam_ctrl += (CCI_HN_F_1_BASE - CCI_HN_F_0_BASE);
417 }
418 if (!ddr0_used && !ddr1_used) {
419 printf("Invalid configuration in HN-F SAM control\n");
420 return;
421 }
422
423 if (!ddr0_used && info->first_ctrl == 0) {
424 info->first_ctrl = 1;
425 info->num_ctrls = 1;
426 debug("First DDR controller disabled\n");
427 return;
428 }
429
430 if (!ddr1_used && info->first_ctrl + info->num_ctrls > 1) {
431 info->num_ctrls = 1;
432 debug("Second DDR controller disabled\n");
433 }
434#endif
435}