blob: e1f69a1d25cc5168b40f8249a3083c66feb520f7 [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.
Kumar Gala58e5e9a2008-08-26 15:01:29 -05004 */
5
6/*
7 * Generic driver for Freescale DDR/DDR2/DDR3 memory controller.
8 * Based on code from spd_sdram.c
9 * Author: James Yang [at freescale.com]
10 */
11
12#include <common.h>
Kumar Galac39f44d2011-01-31 22:18:47 -060013#include <i2c.h>
York Sun5614e712013-09-30 09:22:09 -070014#include <fsl_ddr_sdram.h>
York Sun5614e712013-09-30 09:22:09 -070015#include <fsl_ddr.h>
Kumar Gala58e5e9a2008-08-26 15:01:29 -050016
York Sun6b9e3092014-02-10 13:59:43 -080017/*
18 * CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY is the physical address from the view
19 * of DDR controllers. It is the same as CONFIG_SYS_DDR_SDRAM_BASE for
20 * all Power SoCs. But it could be different for ARM SoCs. For example,
21 * fsl_lsch3 has a mapping mechanism to map DDR memory to ranges (in order) of
22 * 0x00_8000_0000 ~ 0x00_ffff_ffff
23 * 0x80_8000_0000 ~ 0xff_ffff_ffff
24 */
25#ifndef CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY
Mario Six133ec602019-01-21 09:18:16 +010026#ifdef CONFIG_MPC83xx
27#define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_SDRAM_BASE
28#else
York Sun6b9e3092014-02-10 13:59:43 -080029#define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_DDR_SDRAM_BASE
30#endif
Mario Six133ec602019-01-21 09:18:16 +010031#endif
York Sun6b9e3092014-02-10 13:59:43 -080032
York Sun9ac4ffb2013-09-30 14:20:51 -070033#ifdef CONFIG_PPC
34#include <asm/fsl_law.h>
35
York Suna4c66502012-08-17 08:22:39 +000036void fsl_ddr_set_lawbar(
Kumar Gala58e5e9a2008-08-26 15:01:29 -050037 const common_timing_params_t *memctl_common_params,
38 unsigned int memctl_interleaved,
39 unsigned int ctrl_num);
York Sun9ac4ffb2013-09-30 14:20:51 -070040#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -050041
York Sun9ac4ffb2013-09-30 14:20:51 -070042void fsl_ddr_set_intl3r(const unsigned int granule_size);
Kumar Galac39f44d2011-01-31 22:18:47 -060043#if defined(SPD_EEPROM_ADDRESS) || \
44 defined(SPD_EEPROM_ADDRESS1) || defined(SPD_EEPROM_ADDRESS2) || \
45 defined(SPD_EEPROM_ADDRESS3) || defined(SPD_EEPROM_ADDRESS4)
York Sun51370d52016-12-28 08:43:45 -080046#if (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
47u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
Kumar Galac39f44d2011-01-31 22:18:47 -060048 [0][0] = SPD_EEPROM_ADDRESS,
49};
York Sun51370d52016-12-28 08:43:45 -080050#elif (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
51u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
York Sun639f3302011-08-26 11:32:41 -070052 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
53 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
54};
York Sun51370d52016-12-28 08:43:45 -080055#elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
56u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
Kumar Galac39f44d2011-01-31 22:18:47 -060057 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
58 [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
59};
York Sun51370d52016-12-28 08:43:45 -080060#elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
61u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
Kumar Galac39f44d2011-01-31 22:18:47 -060062 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
63 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
64 [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
65 [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
66};
York Sun51370d52016-12-28 08:43:45 -080067#elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
68u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
York Suna4c66502012-08-17 08:22:39 +000069 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
70 [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
71 [2][0] = SPD_EEPROM_ADDRESS3, /* controller 3 */
72};
York Sun51370d52016-12-28 08:43:45 -080073#elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
74u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
York Suna4c66502012-08-17 08:22:39 +000075 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
76 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
77 [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
78 [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
79 [2][0] = SPD_EEPROM_ADDRESS5, /* controller 3 */
80 [2][1] = SPD_EEPROM_ADDRESS6, /* controller 3 */
81};
82
Kumar Galac39f44d2011-01-31 22:18:47 -060083#endif
84
York Sun34e026f2014-03-27 17:54:47 -070085#define SPD_SPA0_ADDRESS 0x36
86#define SPD_SPA1_ADDRESS 0x37
87
Kumar Galac39f44d2011-01-31 22:18:47 -060088static void __get_spd(generic_spd_eeprom_t *spd, u8 i2c_address)
89{
Valentin Longchamp0778bbe2013-10-18 11:47:19 +020090 int ret;
York Sun34e026f2014-03-27 17:54:47 -070091#ifdef CONFIG_SYS_FSL_DDR4
92 uint8_t dummy = 0;
93#endif
Valentin Longchamp0778bbe2013-10-18 11:47:19 +020094
95 i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM);
96
York Sun34e026f2014-03-27 17:54:47 -070097#ifdef CONFIG_SYS_FSL_DDR4
98 /*
99 * DDR4 SPD has 384 to 512 bytes
100 * To access the lower 256 bytes, we need to set EE page address to 0
101 * To access the upper 256 bytes, we need to set EE page address to 1
102 * See Jedec standar No. 21-C for detail
103 */
104 i2c_write(SPD_SPA0_ADDRESS, 0, 1, &dummy, 1);
105 ret = i2c_read(i2c_address, 0, 1, (uchar *)spd, 256);
106 if (!ret) {
107 i2c_write(SPD_SPA1_ADDRESS, 0, 1, &dummy, 1);
108 ret = i2c_read(i2c_address, 0, 1,
109 (uchar *)((ulong)spd + 256),
Masahiro Yamadab4141192014-11-07 03:03:31 +0900110 min(256,
111 (int)sizeof(generic_spd_eeprom_t) - 256));
York Sun34e026f2014-03-27 17:54:47 -0700112 }
113#else
Valentin Longchamp0778bbe2013-10-18 11:47:19 +0200114 ret = i2c_read(i2c_address, 0, 1, (uchar *)spd,
Kumar Galac39f44d2011-01-31 22:18:47 -0600115 sizeof(generic_spd_eeprom_t));
York Sun34e026f2014-03-27 17:54:47 -0700116#endif
Kumar Galac39f44d2011-01-31 22:18:47 -0600117
118 if (ret) {
York Sun82968a72012-10-08 07:44:28 +0000119 if (i2c_address ==
120#ifdef SPD_EEPROM_ADDRESS
121 SPD_EEPROM_ADDRESS
122#elif defined(SPD_EEPROM_ADDRESS1)
123 SPD_EEPROM_ADDRESS1
124#endif
125 ) {
126 printf("DDR: failed to read SPD from address %u\n",
127 i2c_address);
128 } else {
129 debug("DDR: failed to read SPD from address %u\n",
130 i2c_address);
131 }
Kumar Galac39f44d2011-01-31 22:18:47 -0600132 memset(spd, 0, sizeof(generic_spd_eeprom_t));
133 }
134}
135
136__attribute__((weak, alias("__get_spd")))
137void get_spd(generic_spd_eeprom_t *spd, u8 i2c_address);
138
York Sunb92557c2015-05-28 14:54:08 +0530139/* This function allows boards to update SPD address */
140__weak void update_spd_address(unsigned int ctrl_num,
141 unsigned int slot,
142 unsigned int *addr)
143{
144}
145
Kumar Galac39f44d2011-01-31 22:18:47 -0600146void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
York Sun1d71efb2014-08-01 15:51:00 -0700147 unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
Kumar Galac39f44d2011-01-31 22:18:47 -0600148{
149 unsigned int i;
150 unsigned int i2c_address = 0;
151
York Sun51370d52016-12-28 08:43:45 -0800152 if (ctrl_num >= CONFIG_SYS_NUM_DDR_CTLRS) {
Kumar Galac39f44d2011-01-31 22:18:47 -0600153 printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
154 return;
155 }
156
York Sun1d71efb2014-08-01 15:51:00 -0700157 for (i = 0; i < dimm_slots_per_ctrl; i++) {
Kumar Galac39f44d2011-01-31 22:18:47 -0600158 i2c_address = spd_i2c_addr[ctrl_num][i];
York Sunb92557c2015-05-28 14:54:08 +0530159 update_spd_address(ctrl_num, i, &i2c_address);
Kumar Galac39f44d2011-01-31 22:18:47 -0600160 get_spd(&(ctrl_dimms_spd[i]), i2c_address);
161 }
162}
163#else
164void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
York Sun1d71efb2014-08-01 15:51:00 -0700165 unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
Kumar Galac39f44d2011-01-31 22:18:47 -0600166{
167}
168#endif /* SPD_EEPROM_ADDRESSx */
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500169
170/*
171 * ASSUMPTIONS:
172 * - Same number of CONFIG_DIMM_SLOTS_PER_CTLR on each controller
173 * - Same memory data bus width on all controllers
174 *
175 * NOTES:
176 *
177 * The memory controller and associated documentation use confusing
178 * terminology when referring to the orgranization of DRAM.
179 *
180 * Here is a terminology translation table:
181 *
182 * memory controller/documention |industry |this code |signals
183 * -------------------------------|-----------|-----------|-----------------
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200184 * physical bank/bank |rank |rank |chip select (CS)
185 * logical bank/sub-bank |bank |bank |bank address (BA)
186 * page/row |row |page |row address
187 * ??? |column |column |column address
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500188 *
189 * The naming confusion is further exacerbated by the descriptions of the
190 * memory controller interleaving feature, where accesses are interleaved
191 * _BETWEEN_ two seperate memory controllers. This is configured only in
192 * CS0_CONFIG[INTLV_CTL] of each memory controller.
193 *
194 * memory controller documentation | number of chip selects
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200195 * | per memory controller supported
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500196 * --------------------------------|-----------------------------------------
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200197 * cache line interleaving | 1 (CS0 only)
198 * page interleaving | 1 (CS0 only)
199 * bank interleaving | 1 (CS0 only)
200 * superbank interleraving | depends on bank (chip select)
201 * | interleraving [rank interleaving]
202 * | mode used on every memory controller
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500203 *
204 * Even further confusing is the existence of the interleaving feature
205 * _WITHIN_ each memory controller. The feature is referred to in
206 * documentation as chip select interleaving or bank interleaving,
207 * although it is configured in the DDR_SDRAM_CFG field.
208 *
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200209 * Name of field | documentation name | this code
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500210 * -----------------------------|-----------------------|------------------
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200211 * DDR_SDRAM_CFG[BA_INTLV_CTL] | Bank (chip select) | rank interleaving
212 * | interleaving
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500213 */
214
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500215const char *step_string_tbl[] = {
216 "STEP_GET_SPD",
217 "STEP_COMPUTE_DIMM_PARMS",
218 "STEP_COMPUTE_COMMON_PARMS",
219 "STEP_GATHER_OPTS",
220 "STEP_ASSIGN_ADDRESSES",
221 "STEP_COMPUTE_REGS",
222 "STEP_PROGRAM_REGS",
223 "STEP_ALL"
224};
225
226const char * step_to_string(unsigned int step) {
227
228 unsigned int s = __ilog2(step);
229
230 if ((1 << s) != step)
231 return step_string_tbl[7];
232
York Sun349689b2014-04-01 14:20:49 -0700233 if (s >= ARRAY_SIZE(step_string_tbl)) {
234 printf("Error for the step in %s\n", __func__);
235 s = 0;
236 }
237
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500238 return step_string_tbl[s];
239}
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500240
York Sunef002272013-03-25 07:39:35 +0000241static unsigned long long __step_assign_addresses(fsl_ddr_info_t *pinfo,
York Suna4c66502012-08-17 08:22:39 +0000242 unsigned int dbw_cap_adj[])
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500243{
York Sun1d71efb2014-08-01 15:51:00 -0700244 unsigned int i, j;
York Suna4c66502012-08-17 08:22:39 +0000245 unsigned long long total_mem, current_mem_base, total_ctlr_mem;
246 unsigned long long rank_density, ctlr_density = 0;
York Sun1d71efb2014-08-01 15:51:00 -0700247 unsigned int first_ctrl = pinfo->first_ctrl;
248 unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500249
250 /*
251 * If a reduced data width is requested, but the SPD
252 * specifies a physically wider device, adjust the
253 * computed dimm capacities accordingly before
254 * assigning addresses.
255 */
York Sun1d71efb2014-08-01 15:51:00 -0700256 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500257 unsigned int found = 0;
258
259 switch (pinfo->memctl_opts[i].data_bus_width) {
260 case 2:
261 /* 16-bit */
York Sun51d498f2011-05-27 07:25:51 +0800262 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
263 unsigned int dw;
264 if (!pinfo->dimm_params[i][j].n_ranks)
265 continue;
266 dw = pinfo->dimm_params[i][j].primary_sdram_width;
267 if ((dw == 72 || dw == 64)) {
268 dbw_cap_adj[i] = 2;
269 break;
270 } else if ((dw == 40 || dw == 32)) {
271 dbw_cap_adj[i] = 1;
272 break;
273 }
274 }
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500275 break;
276
277 case 1:
278 /* 32-bit */
279 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
280 unsigned int dw;
281 dw = pinfo->dimm_params[i][j].data_width;
282 if (pinfo->dimm_params[i][j].n_ranks
283 && (dw == 72 || dw == 64)) {
284 /*
285 * FIXME: can't really do it
286 * like this because this just
287 * further reduces the memory
288 */
289 found = 1;
290 break;
291 }
292 }
293 if (found) {
294 dbw_cap_adj[i] = 1;
295 }
296 break;
297
298 case 0:
299 /* 64-bit */
300 break;
301
302 default:
303 printf("unexpected data bus width "
304 "specified controller %u\n", i);
305 return 1;
306 }
York Suna4c66502012-08-17 08:22:39 +0000307 debug("dbw_cap_adj[%d]=%d\n", i, dbw_cap_adj[i]);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500308 }
309
York Sun1d71efb2014-08-01 15:51:00 -0700310 current_mem_base = pinfo->mem_base;
York Suna4c66502012-08-17 08:22:39 +0000311 total_mem = 0;
York Sun1d71efb2014-08-01 15:51:00 -0700312 if (pinfo->memctl_opts[first_ctrl].memctl_interleaving) {
313 rank_density = pinfo->dimm_params[first_ctrl][0].rank_density >>
314 dbw_cap_adj[first_ctrl];
315 switch (pinfo->memctl_opts[first_ctrl].ba_intlv_ctl &
York Suna4c66502012-08-17 08:22:39 +0000316 FSL_DDR_CS0_CS1_CS2_CS3) {
317 case FSL_DDR_CS0_CS1_CS2_CS3:
318 ctlr_density = 4 * rank_density;
319 break;
320 case FSL_DDR_CS0_CS1:
321 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
322 ctlr_density = 2 * rank_density;
323 break;
324 case FSL_DDR_CS2_CS3:
325 default:
326 ctlr_density = rank_density;
327 break;
328 }
329 debug("rank density is 0x%llx, ctlr density is 0x%llx\n",
330 rank_density, ctlr_density);
York Sun1d71efb2014-08-01 15:51:00 -0700331 for (i = first_ctrl; i <= last_ctrl; i++) {
York Suna4c66502012-08-17 08:22:39 +0000332 if (pinfo->memctl_opts[i].memctl_interleaving) {
333 switch (pinfo->memctl_opts[i].memctl_interleaving_mode) {
York Sun6b1e1252014-02-10 13:59:44 -0800334 case FSL_DDR_256B_INTERLEAVING:
York Suna4c66502012-08-17 08:22:39 +0000335 case FSL_DDR_CACHE_LINE_INTERLEAVING:
336 case FSL_DDR_PAGE_INTERLEAVING:
337 case FSL_DDR_BANK_INTERLEAVING:
338 case FSL_DDR_SUPERBANK_INTERLEAVING:
339 total_ctlr_mem = 2 * ctlr_density;
340 break;
341 case FSL_DDR_3WAY_1KB_INTERLEAVING:
342 case FSL_DDR_3WAY_4KB_INTERLEAVING:
343 case FSL_DDR_3WAY_8KB_INTERLEAVING:
344 total_ctlr_mem = 3 * ctlr_density;
345 break;
346 case FSL_DDR_4WAY_1KB_INTERLEAVING:
347 case FSL_DDR_4WAY_4KB_INTERLEAVING:
348 case FSL_DDR_4WAY_8KB_INTERLEAVING:
349 total_ctlr_mem = 4 * ctlr_density;
350 break;
351 default:
352 panic("Unknown interleaving mode");
353 }
354 pinfo->common_timing_params[i].base_address =
355 current_mem_base;
356 pinfo->common_timing_params[i].total_mem =
357 total_ctlr_mem;
358 total_mem = current_mem_base + total_ctlr_mem;
359 debug("ctrl %d base 0x%llx\n", i, current_mem_base);
360 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
361 } else {
362 /* when 3rd controller not interleaved */
363 current_mem_base = total_mem;
364 total_ctlr_mem = 0;
365 pinfo->common_timing_params[i].base_address =
366 current_mem_base;
367 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
368 unsigned long long cap =
369 pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
370 pinfo->dimm_params[i][j].base_address =
371 current_mem_base;
372 debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
373 current_mem_base += cap;
374 total_ctlr_mem += cap;
375 }
376 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
377 pinfo->common_timing_params[i].total_mem =
378 total_ctlr_mem;
379 total_mem += total_ctlr_mem;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500380 }
381 }
382 } else {
383 /*
384 * Simple linear assignment if memory
385 * controllers are not interleaved.
386 */
York Sun1d71efb2014-08-01 15:51:00 -0700387 for (i = first_ctrl; i <= last_ctrl; i++) {
York Suna4c66502012-08-17 08:22:39 +0000388 total_ctlr_mem = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500389 pinfo->common_timing_params[i].base_address =
York Suna4c66502012-08-17 08:22:39 +0000390 current_mem_base;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500391 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
392 /* Compute DIMM base addresses. */
393 unsigned long long cap =
York Suna4c66502012-08-17 08:22:39 +0000394 pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500395 pinfo->dimm_params[i][j].base_address =
York Suna4c66502012-08-17 08:22:39 +0000396 current_mem_base;
397 debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
398 current_mem_base += cap;
399 total_ctlr_mem += cap;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500400 }
York Suna4c66502012-08-17 08:22:39 +0000401 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500402 pinfo->common_timing_params[i].total_mem =
York Suna4c66502012-08-17 08:22:39 +0000403 total_ctlr_mem;
404 total_mem += total_ctlr_mem;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500405 }
406 }
York Suna4c66502012-08-17 08:22:39 +0000407 debug("Total mem by %s is 0x%llx\n", __func__, total_mem);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500408
York Suna4c66502012-08-17 08:22:39 +0000409 return total_mem;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500410}
411
York Sunef002272013-03-25 07:39:35 +0000412/* Use weak function to allow board file to override the address assignment */
413__attribute__((weak, alias("__step_assign_addresses")))
414unsigned long long step_assign_addresses(fsl_ddr_info_t *pinfo,
415 unsigned int dbw_cap_adj[]);
416
Kumar Galae7563af2009-06-11 23:42:35 -0500417unsigned long long
Haiying Wangfc0c2b62010-12-01 10:35:31 -0500418fsl_ddr_compute(fsl_ddr_info_t *pinfo, unsigned int start_step,
419 unsigned int size_only)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500420{
421 unsigned int i, j;
Kumar Galae7563af2009-06-11 23:42:35 -0500422 unsigned long long total_mem = 0;
York Sun1d71efb2014-08-01 15:51:00 -0700423 int assert_reset = 0;
424 unsigned int first_ctrl = pinfo->first_ctrl;
425 unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
426 __maybe_unused int retval;
427 __maybe_unused bool goodspd = false;
428 __maybe_unused int dimm_slots_per_ctrl = pinfo->dimm_slots_per_ctrl;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500429
430 fsl_ddr_cfg_regs_t *ddr_reg = pinfo->fsl_ddr_config_reg;
431 common_timing_params_t *timing_params = pinfo->common_timing_params;
York Sun1d71efb2014-08-01 15:51:00 -0700432 if (pinfo->board_need_mem_reset)
433 assert_reset = pinfo->board_need_mem_reset();
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500434
435 /* data bus width capacity adjust shift amount */
York Sun51370d52016-12-28 08:43:45 -0800436 unsigned int dbw_capacity_adjust[CONFIG_SYS_NUM_DDR_CTLRS];
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500437
York Sun1d71efb2014-08-01 15:51:00 -0700438 for (i = first_ctrl; i <= last_ctrl; i++)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500439 dbw_capacity_adjust[i] = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500440
441 debug("starting at step %u (%s)\n",
442 start_step, step_to_string(start_step));
443
444 switch (start_step) {
445 case STEP_GET_SPD:
York Sun1b3e3c42011-06-07 09:42:16 +0800446#if defined(CONFIG_DDR_SPD) || defined(CONFIG_SPD_EEPROM)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500447 /* STEP 1: Gather all DIMM SPD data */
York Sun1d71efb2014-08-01 15:51:00 -0700448 for (i = first_ctrl; i <= last_ctrl; i++) {
449 fsl_ddr_get_spd(pinfo->spd_installed_dimms[i], i,
450 dimm_slots_per_ctrl);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500451 }
452
453 case STEP_COMPUTE_DIMM_PARMS:
454 /* STEP 2: Compute DIMM parameters from SPD data */
455
York Sun1d71efb2014-08-01 15:51:00 -0700456 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500457 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500458 generic_spd_eeprom_t *spd =
459 &(pinfo->spd_installed_dimms[i][j]);
460 dimm_params_t *pdimm =
Wolfgang Denkf12e4542008-09-13 02:23:05 +0200461 &(pinfo->dimm_params[i][j]);
York Sun03e664d2015-01-06 13:18:50 -0800462 retval = compute_dimm_parameters(
463 i, spd, pdimm, j);
York Sunf2d264b2011-06-07 09:42:17 +0800464#ifdef CONFIG_SYS_DDR_RAW_TIMING
York Sun66869f92015-03-19 09:30:26 -0700465 if (!j && retval) {
York Suna4c66502012-08-17 08:22:39 +0000466 printf("SPD error on controller %d! "
467 "Trying fallback to raw timing "
468 "calculation\n", i);
York Sun1d71efb2014-08-01 15:51:00 -0700469 retval = fsl_ddr_get_dimm_params(pdimm,
470 i, j);
York Sunf2d264b2011-06-07 09:42:17 +0800471 }
472#else
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500473 if (retval == 2) {
474 printf("Error: compute_dimm_parameters"
475 " non-zero returned FATAL value "
476 "for memctl=%u dimm=%u\n", i, j);
477 return 0;
478 }
York Sunf2d264b2011-06-07 09:42:17 +0800479#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500480 if (retval) {
481 debug("Warning: compute_dimm_parameters"
482 " non-zero return value for memctl=%u "
483 "dimm=%u\n", i, j);
York Sun1d71efb2014-08-01 15:51:00 -0700484 } else {
485 goodspd = true;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500486 }
487 }
488 }
York Sun1d71efb2014-08-01 15:51:00 -0700489 if (!goodspd) {
490 /*
491 * No valid SPD found
492 * Throw an error if this is for main memory, i.e.
493 * first_ctrl == 0. Otherwise, siliently return 0
494 * as the memory size.
495 */
496 if (first_ctrl == 0)
497 printf("Error: No valid SPD detected.\n");
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500498
York Sun1d71efb2014-08-01 15:51:00 -0700499 return 0;
500 }
Shaohui Xie98de3692012-06-28 23:36:38 +0000501#elif defined(CONFIG_SYS_DDR_RAW_TIMING)
York Sun1b3e3c42011-06-07 09:42:16 +0800502 case STEP_COMPUTE_DIMM_PARMS:
York Sun1d71efb2014-08-01 15:51:00 -0700503 for (i = first_ctrl; i <= last_ctrl; i++) {
York Sun1b3e3c42011-06-07 09:42:16 +0800504 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
505 dimm_params_t *pdimm =
506 &(pinfo->dimm_params[i][j]);
507 fsl_ddr_get_dimm_params(pdimm, i, j);
508 }
509 }
510 debug("Filling dimm parameters from board specific file\n");
511#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500512 case STEP_COMPUTE_COMMON_PARMS:
513 /*
514 * STEP 3: Compute a common set of timing parameters
515 * suitable for all of the DIMMs on each memory controller
516 */
York Sun1d71efb2014-08-01 15:51:00 -0700517 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500518 debug("Computing lowest common DIMM"
519 " parameters for memctl=%u\n", i);
York Sun03e664d2015-01-06 13:18:50 -0800520 compute_lowest_common_dimm_parameters
521 (i,
522 pinfo->dimm_params[i],
523 &timing_params[i],
524 CONFIG_DIMM_SLOTS_PER_CTLR);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500525 }
526
527 case STEP_GATHER_OPTS:
528 /* STEP 4: Gather configuration requirements from user */
York Sun1d71efb2014-08-01 15:51:00 -0700529 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500530 debug("Reloading memory controller "
531 "configuration options for memctl=%u\n", i);
532 /*
533 * This "reloads" the memory controller options
534 * to defaults. If the user "edits" an option,
535 * next_step points to the step after this,
536 * which is currently STEP_ASSIGN_ADDRESSES.
537 */
538 populate_memctl_options(
York Sun56848422015-07-23 14:04:48 -0700539 &timing_params[i],
Haiying Wangdfb49102008-10-03 12:36:55 -0400540 &pinfo->memctl_opts[i],
541 pinfo->dimm_params[i], i);
York Sunc63e1372013-06-25 11:37:48 -0700542 /*
543 * For RDIMMs, JEDEC spec requires clocks to be stable
544 * before reset signal is deasserted. For the boards
545 * using fixed parameters, this function should be
546 * be called from board init file.
547 */
Priyanka Jain0dd38a32013-09-25 10:41:19 +0530548 if (timing_params[i].all_dimms_registered)
York Sunc63e1372013-06-25 11:37:48 -0700549 assert_reset = 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500550 }
York Sun1d71efb2014-08-01 15:51:00 -0700551 if (assert_reset && !size_only) {
552 if (pinfo->board_mem_reset) {
553 debug("Asserting mem reset\n");
554 pinfo->board_mem_reset();
555 } else {
556 debug("Asserting mem reset missing\n");
557 }
York Sunc63e1372013-06-25 11:37:48 -0700558 }
559
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500560 case STEP_ASSIGN_ADDRESSES:
561 /* STEP 5: Assign addresses to chip selects */
York Suna4c66502012-08-17 08:22:39 +0000562 check_interleaving_options(pinfo);
563 total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust);
York Sun349689b2014-04-01 14:20:49 -0700564 debug("Total mem %llu assigned\n", total_mem);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500565
566 case STEP_COMPUTE_REGS:
567 /* STEP 6: compute controller register values */
York Suna4c66502012-08-17 08:22:39 +0000568 debug("FSL Memory ctrl register computation\n");
York Sun1d71efb2014-08-01 15:51:00 -0700569 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500570 if (timing_params[i].ndimms_present == 0) {
571 memset(&ddr_reg[i], 0,
572 sizeof(fsl_ddr_cfg_regs_t));
573 continue;
574 }
575
York Sun03e664d2015-01-06 13:18:50 -0800576 compute_fsl_memctl_config_regs
577 (i,
578 &pinfo->memctl_opts[i],
579 &ddr_reg[i], &timing_params[i],
580 pinfo->dimm_params[i],
581 dbw_capacity_adjust[i],
582 size_only);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500583 }
584
585 default:
586 break;
587 }
588
York Suna4c66502012-08-17 08:22:39 +0000589 {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500590 /*
591 * Compute the amount of memory available just by
592 * looking for the highest valid CSn_BNDS value.
593 * This allows us to also experiment with using
594 * only CS0 when using dual-rank DIMMs.
595 */
596 unsigned int max_end = 0;
597
York Sun1d71efb2014-08-01 15:51:00 -0700598 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500599 for (j = 0; j < CONFIG_CHIP_SELECTS_PER_CTRL; j++) {
600 fsl_ddr_cfg_regs_t *reg = &ddr_reg[i];
601 if (reg->cs[j].config & 0x80000000) {
602 unsigned int end;
York Sund8556db2013-06-25 11:37:45 -0700603 /*
604 * 0xfffffff is a special value we put
605 * for unused bnds
606 */
607 if (reg->cs[j].bnds == 0xffffffff)
608 continue;
609 end = reg->cs[j].bnds & 0xffff;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500610 if (end > max_end) {
611 max_end = end;
612 }
613 }
614 }
615 }
616
York Sun00ec3fd2013-10-28 16:36:02 -0700617 total_mem = 1 + (((unsigned long long)max_end << 24ULL) |
York Sun1d71efb2014-08-01 15:51:00 -0700618 0xFFFFFFULL) - pinfo->mem_base;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500619 }
620
621 return total_mem;
622}
623
York Sun1d71efb2014-08-01 15:51:00 -0700624phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500625{
York Sun1d71efb2014-08-01 15:51:00 -0700626 unsigned int i, first_ctrl, last_ctrl;
York Sun9ac4ffb2013-09-30 14:20:51 -0700627#ifdef CONFIG_PPC
York Suna4c66502012-08-17 08:22:39 +0000628 unsigned int law_memctl = LAW_TRGT_IF_DDR_1;
York Sun9ac4ffb2013-09-30 14:20:51 -0700629#endif
Kumar Galae7563af2009-06-11 23:42:35 -0500630 unsigned long long total_memory;
York Sun1d71efb2014-08-01 15:51:00 -0700631 int deassert_reset = 0;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500632
York Sun1d71efb2014-08-01 15:51:00 -0700633 first_ctrl = pinfo->first_ctrl;
634 last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500635
636 /* Compute it once normally. */
York Sun6f5e1dc2011-09-16 13:21:35 -0700637#ifdef CONFIG_FSL_DDR_INTERACTIVE
James Yange8ba6c52013-01-07 14:01:03 +0000638 if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */
York Sun1d71efb2014-08-01 15:51:00 -0700639 total_memory = fsl_ddr_interactive(pinfo, 0);
James Yange8ba6c52013-01-07 14:01:03 +0000640 } else if (fsl_ddr_interactive_env_var_exists()) {
York Sun1d71efb2014-08-01 15:51:00 -0700641 total_memory = fsl_ddr_interactive(pinfo, 1);
York Sune750cfa2013-01-04 08:13:59 +0000642 } else
York Sun6f5e1dc2011-09-16 13:21:35 -0700643#endif
York Sun1d71efb2014-08-01 15:51:00 -0700644 total_memory = fsl_ddr_compute(pinfo, STEP_GET_SPD, 0);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500645
York Sunf31cfd12012-10-08 07:44:24 +0000646 /* setup 3-way interleaving before enabling DDRC */
York Sun1d71efb2014-08-01 15:51:00 -0700647 switch (pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode) {
648 case FSL_DDR_3WAY_1KB_INTERLEAVING:
649 case FSL_DDR_3WAY_4KB_INTERLEAVING:
650 case FSL_DDR_3WAY_8KB_INTERLEAVING:
651 fsl_ddr_set_intl3r(
652 pinfo->memctl_opts[first_ctrl].
653 memctl_interleaving_mode);
654 break;
655 default:
656 break;
York Sunf31cfd12012-10-08 07:44:24 +0000657 }
658
York Sunc63e1372013-06-25 11:37:48 -0700659 /*
660 * Program configuration registers.
661 * JEDEC specs requires clocks to be stable before deasserting reset
662 * for RDIMMs. Clocks start after chip select is enabled and clock
663 * control register is set. During step 1, all controllers have their
664 * registers set but not enabled. Step 2 proceeds after deasserting
665 * reset through board FPGA or GPIO.
666 * For non-registered DIMMs, initialization can go through but it is
667 * also OK to follow the same flow.
668 */
York Sun1d71efb2014-08-01 15:51:00 -0700669 if (pinfo->board_need_mem_reset)
670 deassert_reset = pinfo->board_need_mem_reset();
671 for (i = first_ctrl; i <= last_ctrl; i++) {
672 if (pinfo->common_timing_params[i].all_dimms_registered)
York Sunc63e1372013-06-25 11:37:48 -0700673 deassert_reset = 1;
674 }
York Sun1d71efb2014-08-01 15:51:00 -0700675 for (i = first_ctrl; i <= last_ctrl; i++) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500676 debug("Programming controller %u\n", i);
York Sun1d71efb2014-08-01 15:51:00 -0700677 if (pinfo->common_timing_params[i].ndimms_present == 0) {
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500678 debug("No dimms present on controller %u; "
679 "skipping programming\n", i);
680 continue;
681 }
York Sunc63e1372013-06-25 11:37:48 -0700682 /*
683 * The following call with step = 1 returns before enabling
684 * the controller. It has to finish with step = 2 later.
685 */
York Sun1d71efb2014-08-01 15:51:00 -0700686 fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]), i,
York Sunc63e1372013-06-25 11:37:48 -0700687 deassert_reset ? 1 : 0);
688 }
689 if (deassert_reset) {
690 /* Use board FPGA or GPIO to deassert reset signal */
York Sun1d71efb2014-08-01 15:51:00 -0700691 if (pinfo->board_mem_de_reset) {
692 debug("Deasserting mem reset\n");
693 pinfo->board_mem_de_reset();
694 } else {
695 debug("Deasserting mem reset missing\n");
696 }
697 for (i = first_ctrl; i <= last_ctrl; i++) {
York Sunc63e1372013-06-25 11:37:48 -0700698 /* Call with step = 2 to continue initialization */
York Sun1d71efb2014-08-01 15:51:00 -0700699 fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]),
York Sunc63e1372013-06-25 11:37:48 -0700700 i, 2);
701 }
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500702 }
703
York Sune32d59a2015-01-06 13:18:55 -0800704#ifdef CONFIG_FSL_DDR_SYNC_REFRESH
705 fsl_ddr_sync_memctl_refresh(first_ctrl, last_ctrl);
706#endif
707
York Sun9ac4ffb2013-09-30 14:20:51 -0700708#ifdef CONFIG_PPC
York Suna4c66502012-08-17 08:22:39 +0000709 /* program LAWs */
York Sun1d71efb2014-08-01 15:51:00 -0700710 for (i = first_ctrl; i <= last_ctrl; i++) {
711 if (pinfo->memctl_opts[i].memctl_interleaving) {
712 switch (pinfo->memctl_opts[i].
713 memctl_interleaving_mode) {
York Suna4c66502012-08-17 08:22:39 +0000714 case FSL_DDR_CACHE_LINE_INTERLEAVING:
715 case FSL_DDR_PAGE_INTERLEAVING:
716 case FSL_DDR_BANK_INTERLEAVING:
717 case FSL_DDR_SUPERBANK_INTERLEAVING:
York Sun1d71efb2014-08-01 15:51:00 -0700718 if (i % 2)
719 break;
York Suna4c66502012-08-17 08:22:39 +0000720 if (i == 0) {
721 law_memctl = LAW_TRGT_IF_DDR_INTRLV;
York Sun1d71efb2014-08-01 15:51:00 -0700722 fsl_ddr_set_lawbar(
723 &pinfo->common_timing_params[i],
York Suna4c66502012-08-17 08:22:39 +0000724 law_memctl, i);
725 }
York Sun51370d52016-12-28 08:43:45 -0800726#if CONFIG_SYS_NUM_DDR_CTLRS > 3
York Sun1d71efb2014-08-01 15:51:00 -0700727 else if (i == 2) {
728 law_memctl = LAW_TRGT_IF_DDR_INTLV_34;
729 fsl_ddr_set_lawbar(
730 &pinfo->common_timing_params[i],
731 law_memctl, i);
732 }
733#endif
York Suna4c66502012-08-17 08:22:39 +0000734 break;
735 case FSL_DDR_3WAY_1KB_INTERLEAVING:
736 case FSL_DDR_3WAY_4KB_INTERLEAVING:
737 case FSL_DDR_3WAY_8KB_INTERLEAVING:
738 law_memctl = LAW_TRGT_IF_DDR_INTLV_123;
739 if (i == 0) {
York Sun1d71efb2014-08-01 15:51:00 -0700740 fsl_ddr_set_lawbar(
741 &pinfo->common_timing_params[i],
York Suna4c66502012-08-17 08:22:39 +0000742 law_memctl, i);
743 }
744 break;
745 case FSL_DDR_4WAY_1KB_INTERLEAVING:
746 case FSL_DDR_4WAY_4KB_INTERLEAVING:
747 case FSL_DDR_4WAY_8KB_INTERLEAVING:
748 law_memctl = LAW_TRGT_IF_DDR_INTLV_1234;
749 if (i == 0)
York Sun1d71efb2014-08-01 15:51:00 -0700750 fsl_ddr_set_lawbar(
751 &pinfo->common_timing_params[i],
York Suna4c66502012-08-17 08:22:39 +0000752 law_memctl, i);
753 /* place holder for future 4-way interleaving */
754 break;
755 default:
756 break;
757 }
758 } else {
759 switch (i) {
760 case 0:
761 law_memctl = LAW_TRGT_IF_DDR_1;
762 break;
763 case 1:
764 law_memctl = LAW_TRGT_IF_DDR_2;
765 break;
766 case 2:
767 law_memctl = LAW_TRGT_IF_DDR_3;
768 break;
769 case 3:
770 law_memctl = LAW_TRGT_IF_DDR_4;
771 break;
772 default:
773 break;
774 }
York Sun1d71efb2014-08-01 15:51:00 -0700775 fsl_ddr_set_lawbar(&pinfo->common_timing_params[i],
776 law_memctl, i);
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500777 }
778 }
York Sun9ac4ffb2013-09-30 14:20:51 -0700779#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500780
York Suna4c66502012-08-17 08:22:39 +0000781 debug("total_memory by %s = %llu\n", __func__, total_memory);
Kumar Galae7563af2009-06-11 23:42:35 -0500782
783#if !defined(CONFIG_PHYS_64BIT)
784 /* Check for 4G or more. Bad. */
York Sun1d71efb2014-08-01 15:51:00 -0700785 if ((first_ctrl == 0) && (total_memory >= (1ull << 32))) {
Shruti Kanetkar2f848f92013-08-15 11:25:37 -0500786 puts("Detected ");
787 print_size(total_memory, " of memory\n");
Becky Bruce7ea38712010-12-17 17:17:59 -0600788 printf(" This U-Boot only supports < 4G of DDR\n");
789 printf(" You could rebuild it with CONFIG_PHYS_64BIT\n");
Simon Glassf1683aa2017-04-06 12:47:05 -0600790 printf(" "); /* re-align to match init_dram print */
Kumar Galae7563af2009-06-11 23:42:35 -0500791 total_memory = CONFIG_MAX_MEM_MAPPED;
792 }
793#endif
Kumar Gala58e5e9a2008-08-26 15:01:29 -0500794
795 return total_memory;
796}
Haiying Wangfc0c2b62010-12-01 10:35:31 -0500797
798/*
York Sun1d71efb2014-08-01 15:51:00 -0700799 * fsl_ddr_sdram(void) -- this is the main function to be
Simon Glassf1683aa2017-04-06 12:47:05 -0600800 * called by dram_init() in the board file.
York Sun1d71efb2014-08-01 15:51:00 -0700801 *
802 * It returns amount of memory configured in bytes.
803 */
804phys_size_t fsl_ddr_sdram(void)
805{
806 fsl_ddr_info_t info;
807
808 /* Reset info structure. */
809 memset(&info, 0, sizeof(fsl_ddr_info_t));
810 info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
811 info.first_ctrl = 0;
812 info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
813 info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
814 info.board_need_mem_reset = board_need_mem_reset;
815 info.board_mem_reset = board_assert_mem_reset;
816 info.board_mem_de_reset = board_deassert_mem_reset;
York Sun61bd2f72015-11-04 09:53:10 -0800817 remove_unused_controllers(&info);
York Sun1d71efb2014-08-01 15:51:00 -0700818
819 return __fsl_ddr_sdram(&info);
820}
821
822#ifdef CONFIG_SYS_FSL_OTHER_DDR_NUM_CTRLS
823phys_size_t fsl_other_ddr_sdram(unsigned long long base,
824 unsigned int first_ctrl,
825 unsigned int num_ctrls,
826 unsigned int dimm_slots_per_ctrl,
827 int (*board_need_reset)(void),
828 void (*board_reset)(void),
829 void (*board_de_reset)(void))
830{
831 fsl_ddr_info_t info;
832
833 /* Reset info structure. */
834 memset(&info, 0, sizeof(fsl_ddr_info_t));
835 info.mem_base = base;
836 info.first_ctrl = first_ctrl;
837 info.num_ctrls = num_ctrls;
838 info.dimm_slots_per_ctrl = dimm_slots_per_ctrl;
839 info.board_need_mem_reset = board_need_reset;
840 info.board_mem_reset = board_reset;
841 info.board_mem_de_reset = board_de_reset;
842
843 return __fsl_ddr_sdram(&info);
844}
845#endif
846
847/*
848 * fsl_ddr_sdram_size(first_ctrl, last_intlv) - This function only returns the
849 * size of the total memory without setting ddr control registers.
Haiying Wangfc0c2b62010-12-01 10:35:31 -0500850 */
851phys_size_t
852fsl_ddr_sdram_size(void)
853{
854 fsl_ddr_info_t info;
855 unsigned long long total_memory = 0;
856
857 memset(&info, 0 , sizeof(fsl_ddr_info_t));
York Sun1d71efb2014-08-01 15:51:00 -0700858 info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
859 info.first_ctrl = 0;
860 info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
861 info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
862 info.board_need_mem_reset = NULL;
Ed Swarthout81dfdee2016-01-14 12:28:04 -0600863 remove_unused_controllers(&info);
Haiying Wangfc0c2b62010-12-01 10:35:31 -0500864
865 /* Compute it once normally. */
866 total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 1);
867
868 return total_memory;
869}