blob: 60051392e713bcad80a550cd5127f1154eedf2ee [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Kumar Gala58e5e9a2008-08-26 15:01:29 -05002/*
York Sun34e026f2014-03-27 17:54:47 -07003 * Copyright 2008-2014 Freescale Semiconductor, Inc.
Priyanka Singha1932ec2021-08-19 11:39:01 +05304 * Copyright 2021 NXP
Kumar Gala58e5e9a2008-08-26 15:01:29 -05005 */
6
7#include <common.h>
York Sun9ac4ffb2013-09-30 14:20:51 -07008#ifdef CONFIG_PPC
Kumar Gala58e5e9a2008-08-26 15:01:29 -05009#include <asm/fsl_law.h>
York Sun9ac4ffb2013-09-30 14:20:51 -070010#endif
Kyle Moffette820a132011-03-15 11:23:47 -040011#include <div64.h>
Simon Glassc05ed002020-05-10 11:40:11 -060012#include <linux/delay.h>
Kumar Gala58e5e9a2008-08-26 15:01:29 -050013
York Sun5614e712013-09-30 09:22:09 -070014#include <fsl_ddr.h>
York Sun9a17eb52013-11-18 10:29:32 -080015#include <fsl_immap.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060016#include <log.h>
York Sun5614e712013-09-30 09:22:09 -070017#include <asm/io.h>
Simon Glass457e51c2017-05-17 08:23:10 -060018#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
19 defined(CONFIG_ARM)
Simon Glass6e2941d2017-05-17 08:23:06 -060020#include <asm/arch/clock.h>
21#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -050022
Kyle Moffette820a132011-03-15 11:23:47 -040023/* To avoid 64-bit full-divides, we factor this here */
Kyle Moffetta2879632011-04-14 13:39:30 -040024#define ULL_2E12 2000000000000ULL
25#define UL_5POW12 244140625UL
26#define UL_2POW13 (1UL << 13)
Kyle Moffette820a132011-03-15 11:23:47 -040027
Kyle Moffetta2879632011-04-14 13:39:30 -040028#define ULL_8FS 0xFFFFFFFFULL
Kyle Moffette820a132011-03-15 11:23:47 -040029
York Sun66869f92015-03-19 09:30:26 -070030u32 fsl_ddr_get_version(unsigned int ctrl_num)
York Sun34e026f2014-03-27 17:54:47 -070031{
32 struct ccsr_ddr __iomem *ddr;
33 u32 ver_major_minor_errata;
34
York Sun66869f92015-03-19 09:30:26 -070035 switch (ctrl_num) {
36 case 0:
Tom Rini6cc04542022-10-28 20:27:13 -040037 ddr = (void *)CFG_SYS_FSL_DDR_ADDR;
York Sun66869f92015-03-19 09:30:26 -070038 break;
Tom Rini6cc04542022-10-28 20:27:13 -040039#if defined(CFG_SYS_FSL_DDR2_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sun66869f92015-03-19 09:30:26 -070040 case 1:
Tom Rini6cc04542022-10-28 20:27:13 -040041 ddr = (void *)CFG_SYS_FSL_DDR2_ADDR;
York Sun66869f92015-03-19 09:30:26 -070042 break;
43#endif
Tom Rini6cc04542022-10-28 20:27:13 -040044#if defined(CFG_SYS_FSL_DDR3_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 2)
York Sun66869f92015-03-19 09:30:26 -070045 case 2:
Tom Rini6cc04542022-10-28 20:27:13 -040046 ddr = (void *)CFG_SYS_FSL_DDR3_ADDR;
York Sun66869f92015-03-19 09:30:26 -070047 break;
48#endif
York Sun51370d52016-12-28 08:43:45 -080049#if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 3)
York Sun66869f92015-03-19 09:30:26 -070050 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 Sun34e026f2014-03-27 17:54:47 -070058 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 Gala58e5e9a2008-08-26 15:01:29 -050064/*
York Sun905acde2011-08-26 11:32:42 -070065 * Round up mclk_ps to nearest 1 ps in memory controller code
66 * if the error is 0.5ps or more.
Kumar Gala58e5e9a2008-08-26 15:01:29 -050067 *
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 Sun03e664d2015-01-06 13:18:50 -080072unsigned int get_memory_clk_period_ps(const unsigned int ctrl_num)
Kumar Gala58e5e9a2008-08-26 15:01:29 -050073{
York Sun03e664d2015-01-06 13:18:50 -080074 unsigned int data_rate = get_ddr_freq(ctrl_num);
Kyle Moffette820a132011-03-15 11:23:47 -040075 unsigned int result;
Kumar Gala58e5e9a2008-08-26 15:01:29 -050076
Kyle Moffette820a132011-03-15 11:23:47 -040077 /* Round to nearest 10ps, being careful about 64-bit multiply/divide */
York Sun905acde2011-08-26 11:32:42 -070078 unsigned long long rem, mclk_ps = ULL_2E12;
Priyanka Singha1932ec2021-08-19 11:39:01 +053079 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 Moffette820a132011-03-15 11:23:47 -040086
York Sun905acde2011-08-26 11:32:42 -070087 return result;
Kumar Gala58e5e9a2008-08-26 15:01:29 -050088}
89
90/* Convert picoseconds into DRAM clock cycles (rounding up if needed). */
York Sun03e664d2015-01-06 13:18:50 -080091unsigned int picos_to_mclk(const unsigned int ctrl_num, unsigned int picos)
Kumar Gala58e5e9a2008-08-26 15:01:29 -050092{
Kyle Moffette820a132011-03-15 11:23:47 -040093 unsigned long long clks, clks_rem;
York Sun03e664d2015-01-06 13:18:50 -080094 unsigned long data_rate = get_ddr_freq(ctrl_num);
Kumar Gala58e5e9a2008-08-26 15:01:29 -050095
Kyle Moffette820a132011-03-15 11:23:47 -040096 /* Short circuit for zero picos */
Kumar Gala58e5e9a2008-08-26 15:01:29 -050097 if (!picos)
98 return 0;
99
Kyle Moffette820a132011-03-15 11:23:47 -0400100 /* First multiply the time by the data rate (32x32 => 64) */
York Sun905acde2011-08-26 11:32:42 -0700101 clks = picos * (unsigned long long)data_rate;
Kyle Moffette820a132011-03-15 11:23:47 -0400102 /*
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 Moffetta2879632011-04-14 13:39:30 -0400106 clks_rem = do_div(clks, UL_5POW12);
York Sun905acde2011-08-26 11:32:42 -0700107 clks_rem += (clks & (UL_2POW13-1)) * UL_5POW12;
Kyle Moffette820a132011-03-15 11:23:47 -0400108 clks >>= 13;
109
York Sun905acde2011-08-26 11:32:42 -0700110 /* If we had a remainder greater than the 1ps error, then round up */
111 if (clks_rem > data_rate)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500112 clks++;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500113
Kyle Moffette820a132011-03-15 11:23:47 -0400114 /* Clamp to the maximum representable value */
Kyle Moffetta2879632011-04-14 13:39:30 -0400115 if (clks > ULL_8FS)
116 clks = ULL_8FS;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500117 return (unsigned int) clks;
118}
119
York Sun03e664d2015-01-06 13:18:50 -0800120unsigned int mclk_to_picos(const unsigned int ctrl_num, unsigned int mclk)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500121{
York Sun03e664d2015-01-06 13:18:50 -0800122 return get_memory_clk_period_ps(ctrl_num) * mclk;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500123}
124
York Sun9ac4ffb2013-09-30 14:20:51 -0700125#ifdef CONFIG_PPC
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500126void
127__fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
York Suna4c66502012-08-17 08:22:39 +0000128 unsigned int law_memctl,
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500129 unsigned int ctrl_num)
130{
Kumar Galae7563af2009-06-11 23:42:35 -0500131 unsigned long long base = memctl_common_params->base_address;
132 unsigned long long size = memctl_common_params->total_mem;
133
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500134 /*
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 Galae7563af2009-06-11 23:42:35 -0500141#if !defined(CONFIG_PHYS_64BIT)
Tom Rini1d457db2022-12-04 10:04:50 -0500142 if (base >= CFG_MAX_MEM_MAPPED)
Kumar Galae7563af2009-06-11 23:42:35 -0500143 return;
Tom Rini1d457db2022-12-04 10:04:50 -0500144 if ((base + size) >= CFG_MAX_MEM_MAPPED)
145 size = CFG_MAX_MEM_MAPPED - base;
Kumar Galae7563af2009-06-11 23:42:35 -0500146#endif
York Suna4c66502012-08-17 08:22:39 +0000147 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 Mengea253ad2022-10-26 12:40:07 +0800150 return;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500151 }
York Suna4c66502012-08-17 08:22:39 +0000152 debug("setup ddr law base = 0x%llx, size 0x%llx, TRGT_ID 0x%x\n",
153 base, size, law_memctl);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500154}
155
156__attribute__((weak, alias("__fsl_ddr_set_lawbar"))) void
157fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
158 unsigned int memctl_interleaved,
159 unsigned int ctrl_num);
York Sun9ac4ffb2013-09-30 14:20:51 -0700160#endif
Peter Tyserd9c147f2009-07-17 10:14:48 -0500161
York Suna4c66502012-08-17 08:22:39 +0000162void 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 Suneb539412012-10-08 07:44:25 +0000171u32 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 Sun1d71efb2014-08-01 15:51:00 -0700181void print_ddr_info(unsigned int start_ctrl)
Peter Tyserd9c147f2009-07-17 10:14:48 -0500182{
York Sun9a17eb52013-11-18 10:29:32 -0800183 struct ccsr_ddr __iomem *ddr =
Tom Rini6cc04542022-10-28 20:27:13 -0400184 (struct ccsr_ddr __iomem *)(CFG_SYS_FSL_DDR_ADDR);
Andy Fleminge76cd5d2012-10-23 19:03:46 -0500185
York Sun51370d52016-12-28 08:43:45 -0800186#if defined(CONFIG_E6500) && (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Suna4c66502012-08-17 08:22:39 +0000187 u32 *mcintl3r = (void *) (CONFIG_SYS_IMMR + 0x18004);
188#endif
York Sun51370d52016-12-28 08:43:45 -0800189#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sun4e5b1bd2014-02-10 13:59:42 -0800190 uint32_t cs0_config = ddr_in32(&ddr->cs0_config);
Peter Tyserd9c147f2009-07-17 10:14:48 -0500191#endif
York Sun4e5b1bd2014-02-10 13:59:42 -0800192 uint32_t sdram_cfg = ddr_in32(&ddr->sdram_cfg);
Peter Tyserd9c147f2009-07-17 10:14:48 -0500193 int cas_lat;
194
York Sun51370d52016-12-28 08:43:45 -0800195#if CONFIG_SYS_NUM_DDR_CTLRS >= 2
York Sun1d71efb2014-08-01 15:51:00 -0700196 if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) ||
197 (start_ctrl == 1)) {
Tom Rini6cc04542022-10-28 20:27:13 -0400198 ddr = (void __iomem *)CFG_SYS_FSL_DDR2_ADDR;
York Sun4e5b1bd2014-02-10 13:59:42 -0800199 sdram_cfg = ddr_in32(&ddr->sdram_cfg);
York Sun123922b2012-10-08 07:44:23 +0000200 }
201#endif
York Sun51370d52016-12-28 08:43:45 -0800202#if CONFIG_SYS_NUM_DDR_CTLRS >= 3
York Sun1d71efb2014-08-01 15:51:00 -0700203 if ((!(sdram_cfg & SDRAM_CFG_MEM_EN)) ||
204 (start_ctrl == 2)) {
Tom Rini6cc04542022-10-28 20:27:13 -0400205 ddr = (void __iomem *)CFG_SYS_FSL_DDR3_ADDR;
York Sun4e5b1bd2014-02-10 13:59:42 -0800206 sdram_cfg = ddr_in32(&ddr->sdram_cfg);
York Sun123922b2012-10-08 07:44:23 +0000207 }
208#endif
York Sun1d71efb2014-08-01 15:51:00 -0700209
210 if (!(sdram_cfg & SDRAM_CFG_MEM_EN)) {
211 puts(" (DDR not enabled)\n");
212 return;
213 }
214
Peter Tyserd9c147f2009-07-17 10:14:48 -0500215 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 Sun34e026f2014-03-27 17:54:47 -0700227 case SDRAM_TYPE_DDR4:
228 puts("4");
229 break;
Peter Tyserd9c147f2009-07-17 10:14:48 -0500230 default:
231 puts("?");
232 break;
233 }
234
235 if (sdram_cfg & SDRAM_CFG_32_BE)
236 puts(", 32-bit");
Poonam Aggrwal0b3b1762011-02-07 15:09:51 +0530237 else if (sdram_cfg & SDRAM_CFG_16_BE)
238 puts(", 16-bit");
Peter Tyserd9c147f2009-07-17 10:14:48 -0500239 else
240 puts(", 64-bit");
241
242 /* Calculate CAS latency based on timing cfg values */
York Sun34e026f2014-03-27 17:54:47 -0700243 cas_lat = ((ddr_in32(&ddr->timing_cfg_1) >> 16) & 0xf);
York Sun66869f92015-03-19 09:30:26 -0700244 if (fsl_ddr_get_version(0) <= 0x40400)
York Sun34e026f2014-03-27 17:54:47 -0700245 cas_lat += 1;
246 else
247 cas_lat += 2;
248 cas_lat += ((ddr_in32(&ddr->timing_cfg_3) >> 12) & 3) << 4;
Peter Tyserd9c147f2009-07-17 10:14:48 -0500249 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 Sun51370d52016-12-28 08:43:45 -0800258#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
York Suna4c66502012-08-17 08:22:39 +0000259#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 Sun51370d52016-12-28 08:43:45 -0800280#if (CONFIG_SYS_NUM_DDR_CTLRS >= 2)
York Sun1d71efb2014-08-01 15:51:00 -0700281 if ((cs0_config & 0x20000000) && (start_ctrl == 0)) {
Peter Tyserd9c147f2009-07-17 10:14:48 -0500282 puts("\n");
283 puts(" DDR Controller Interleaving Mode: ");
284
285 switch ((cs0_config >> 24) & 0xf) {
York Sun6b1e1252014-02-10 13:59:44 -0800286 case FSL_DDR_256B_INTERLEAVING:
287 puts("256B");
288 break;
Peter Tyserd9c147f2009-07-17 10:14:48 -0500289 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 Sun1d71efb2014-08-01 15:51:00 -0700330
331void __weak detail_board_ddr_info(void)
332{
333 print_ddr_info(0);
334}
335
336void board_add_ram_info(int use_default)
337{
338 detail_board_ddr_info();
339}
York Sune32d59a2015-01-06 13:18:55 -0800340
341#ifdef CONFIG_FSL_DDR_SYNC_REFRESH
342#define DDRC_DEBUG20_INIT_DONE 0x80000000
343#define DDRC_DEBUG2_RF 0x00000040
344void fsl_ddr_sync_memctl_refresh(unsigned int first_ctrl,
345 unsigned int last_ctrl)
346{
347 unsigned int i;
348 u32 ddrc_debug20;
York Sun51370d52016-12-28 08:43:45 -0800349 u32 ddrc_debug2[CONFIG_SYS_NUM_DDR_CTLRS] = {};
350 u32 *ddrc_debug2_p[CONFIG_SYS_NUM_DDR_CTLRS] = {};
York Sune32d59a2015-01-06 13:18:55 -0800351 struct ccsr_ddr __iomem *ddr;
352
353 for (i = first_ctrl; i <= last_ctrl; i++) {
354 switch (i) {
355 case 0:
Tom Rini6cc04542022-10-28 20:27:13 -0400356 ddr = (void *)CFG_SYS_FSL_DDR_ADDR;
York Sune32d59a2015-01-06 13:18:55 -0800357 break;
Tom Rini6cc04542022-10-28 20:27:13 -0400358#if defined(CFG_SYS_FSL_DDR2_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 1)
York Sune32d59a2015-01-06 13:18:55 -0800359 case 1:
Tom Rini6cc04542022-10-28 20:27:13 -0400360 ddr = (void *)CFG_SYS_FSL_DDR2_ADDR;
York Sune32d59a2015-01-06 13:18:55 -0800361 break;
362#endif
Tom Rini6cc04542022-10-28 20:27:13 -0400363#if defined(CFG_SYS_FSL_DDR3_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 2)
York Sune32d59a2015-01-06 13:18:55 -0800364 case 2:
Tom Rini6cc04542022-10-28 20:27:13 -0400365 ddr = (void *)CFG_SYS_FSL_DDR3_ADDR;
York Sune32d59a2015-01-06 13:18:55 -0800366 break;
367#endif
York Sun51370d52016-12-28 08:43:45 -0800368#if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_SYS_NUM_DDR_CTLRS > 3)
York Sune32d59a2015-01-06 13:18:55 -0800369 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 Sun61bd2f72015-11-04 09:53:10 -0800395
396void remove_unused_controllers(fsl_ddr_info_t *info)
397{
Ashish Kumar6d9b82d2017-08-31 16:12:53 +0530398#ifdef CONFIG_SYS_FSL_HAS_CCN504
York Sun61bd2f72015-11-04 09:53:10 -0800399 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}