1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2008-2014 Freescale Semiconductor, Inc.
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]
15 #include <fsl_ddr_sdram.h>
21 * CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY is the physical address from the view
22 * of DDR controllers. It is the same as CONFIG_SYS_DDR_SDRAM_BASE for
23 * all Power SoCs. But it could be different for ARM SoCs. For example,
24 * fsl_lsch3 has a mapping mechanism to map DDR memory to ranges (in order) of
25 * 0x00_8000_0000 ~ 0x00_ffff_ffff
26 * 0x80_8000_0000 ~ 0xff_ffff_ffff
28 #ifndef CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY
30 #define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_SDRAM_BASE
32 #define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_DDR_SDRAM_BASE
37 #include <asm/fsl_law.h>
39 void fsl_ddr_set_lawbar(
40 const common_timing_params_t *memctl_common_params,
41 unsigned int memctl_interleaved,
42 unsigned int ctrl_num);
45 void fsl_ddr_set_intl3r(const unsigned int granule_size);
46 #if defined(SPD_EEPROM_ADDRESS) || \
47 defined(SPD_EEPROM_ADDRESS1) || defined(SPD_EEPROM_ADDRESS2) || \
48 defined(SPD_EEPROM_ADDRESS3) || defined(SPD_EEPROM_ADDRESS4)
49 #if (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
50 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
51 [0][0] = SPD_EEPROM_ADDRESS,
53 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
54 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
55 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
56 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
58 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
59 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
60 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
61 [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
63 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
64 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
65 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
66 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
67 [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
68 [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
70 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
71 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
72 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
73 [1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
74 [2][0] = SPD_EEPROM_ADDRESS3, /* controller 3 */
76 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
77 u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
78 [0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
79 [0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
80 [1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
81 [1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
82 [2][0] = SPD_EEPROM_ADDRESS5, /* controller 3 */
83 [2][1] = SPD_EEPROM_ADDRESS6, /* controller 3 */
88 #if defined(CONFIG_DM_I2C)
89 #define DEV_TYPE struct udevice
96 #define DEV_TYPE struct ludevice
100 #define SPD_SPA0_ADDRESS 0x36
101 #define SPD_SPA1_ADDRESS 0x37
103 static int ddr_i2c_read(DEV_TYPE *dev, unsigned int addr,
104 int alen, uint8_t *buf, int len)
109 ret = dm_i2c_read(dev, 0, buf, len);
111 ret = i2c_read(dev->chip, addr, alen, buf, len);
117 #ifdef CONFIG_SYS_FSL_DDR4
118 static int ddr_i2c_dummy_write(unsigned int chip_addr)
126 ret = i2c_get_chip_for_busnum(CONFIG_SYS_SPD_BUS_NUM, chip_addr,
129 printf("%s: Cannot find udev for a bus %d\n", __func__,
130 CONFIG_SYS_SPD_BUS_NUM);
134 return dm_i2c_write(dev, 0, &buf, 1);
136 return i2c_write(chip_addr, 0, 1, &buf, 1);
143 static void __get_spd(generic_spd_eeprom_t *spd, u8 i2c_address)
148 #if defined(CONFIG_DM_I2C)
149 ret = i2c_get_chip_for_busnum(CONFIG_SYS_SPD_BUS_NUM, i2c_address,
152 printf("%s: Cannot find udev for a bus %d\n", __func__,
153 CONFIG_SYS_SPD_BUS_NUM);
156 #else /* Non DM I2C support - will be removed */
157 struct ludevice ldev = {
162 i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM);
165 #ifdef CONFIG_SYS_FSL_DDR4
167 * DDR4 SPD has 384 to 512 bytes
168 * To access the lower 256 bytes, we need to set EE page address to 0
169 * To access the upper 256 bytes, we need to set EE page address to 1
170 * See Jedec standar No. 21-C for detail
172 ddr_i2c_dummy_write(SPD_SPA0_ADDRESS);
173 ret = ddr_i2c_read(dev, 0, 1, (uchar *)spd, 256);
175 ddr_i2c_dummy_write(SPD_SPA1_ADDRESS);
176 ret = ddr_i2c_read(dev, 0, 1, (uchar *)((ulong)spd + 256),
178 (int)sizeof(generic_spd_eeprom_t)
183 ret = ddr_i2c_read(dev, 0, 1, (uchar *)spd,
184 sizeof(generic_spd_eeprom_t));
189 #ifdef SPD_EEPROM_ADDRESS
191 #elif defined(SPD_EEPROM_ADDRESS1)
195 printf("DDR: failed to read SPD from address %u\n",
198 debug("DDR: failed to read SPD from address %u\n",
201 memset(spd, 0, sizeof(generic_spd_eeprom_t));
205 __attribute__((weak, alias("__get_spd")))
206 void get_spd(generic_spd_eeprom_t *spd, u8 i2c_address);
208 /* This function allows boards to update SPD address */
209 __weak void update_spd_address(unsigned int ctrl_num,
215 void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
216 unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
219 unsigned int i2c_address = 0;
221 if (ctrl_num >= CONFIG_SYS_NUM_DDR_CTLRS) {
222 printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
226 for (i = 0; i < dimm_slots_per_ctrl; i++) {
227 i2c_address = spd_i2c_addr[ctrl_num][i];
228 update_spd_address(ctrl_num, i, &i2c_address);
229 get_spd(&(ctrl_dimms_spd[i]), i2c_address);
233 void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
234 unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
237 #endif /* SPD_EEPROM_ADDRESSx */
241 * - Same number of CONFIG_DIMM_SLOTS_PER_CTLR on each controller
242 * - Same memory data bus width on all controllers
246 * The memory controller and associated documentation use confusing
247 * terminology when referring to the orgranization of DRAM.
249 * Here is a terminology translation table:
251 * memory controller/documention |industry |this code |signals
252 * -------------------------------|-----------|-----------|-----------------
253 * physical bank/bank |rank |rank |chip select (CS)
254 * logical bank/sub-bank |bank |bank |bank address (BA)
255 * page/row |row |page |row address
256 * ??? |column |column |column address
258 * The naming confusion is further exacerbated by the descriptions of the
259 * memory controller interleaving feature, where accesses are interleaved
260 * _BETWEEN_ two seperate memory controllers. This is configured only in
261 * CS0_CONFIG[INTLV_CTL] of each memory controller.
263 * memory controller documentation | number of chip selects
264 * | per memory controller supported
265 * --------------------------------|-----------------------------------------
266 * cache line interleaving | 1 (CS0 only)
267 * page interleaving | 1 (CS0 only)
268 * bank interleaving | 1 (CS0 only)
269 * superbank interleraving | depends on bank (chip select)
270 * | interleraving [rank interleaving]
271 * | mode used on every memory controller
273 * Even further confusing is the existence of the interleaving feature
274 * _WITHIN_ each memory controller. The feature is referred to in
275 * documentation as chip select interleaving or bank interleaving,
276 * although it is configured in the DDR_SDRAM_CFG field.
278 * Name of field | documentation name | this code
279 * -----------------------------|-----------------------|------------------
280 * DDR_SDRAM_CFG[BA_INTLV_CTL] | Bank (chip select) | rank interleaving
284 const char *step_string_tbl[] = {
286 "STEP_COMPUTE_DIMM_PARMS",
287 "STEP_COMPUTE_COMMON_PARMS",
289 "STEP_ASSIGN_ADDRESSES",
295 const char * step_to_string(unsigned int step) {
297 unsigned int s = __ilog2(step);
299 if ((1 << s) != step)
300 return step_string_tbl[7];
302 if (s >= ARRAY_SIZE(step_string_tbl)) {
303 printf("Error for the step in %s\n", __func__);
307 return step_string_tbl[s];
310 static unsigned long long __step_assign_addresses(fsl_ddr_info_t *pinfo,
311 unsigned int dbw_cap_adj[])
314 unsigned long long total_mem, current_mem_base, total_ctlr_mem;
315 unsigned long long rank_density, ctlr_density = 0;
316 unsigned int first_ctrl = pinfo->first_ctrl;
317 unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
320 * If a reduced data width is requested, but the SPD
321 * specifies a physically wider device, adjust the
322 * computed dimm capacities accordingly before
323 * assigning addresses.
325 for (i = first_ctrl; i <= last_ctrl; i++) {
326 unsigned int found = 0;
328 switch (pinfo->memctl_opts[i].data_bus_width) {
331 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
333 if (!pinfo->dimm_params[i][j].n_ranks)
335 dw = pinfo->dimm_params[i][j].primary_sdram_width;
336 if ((dw == 72 || dw == 64)) {
339 } else if ((dw == 40 || dw == 32)) {
348 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
350 dw = pinfo->dimm_params[i][j].data_width;
351 if (pinfo->dimm_params[i][j].n_ranks
352 && (dw == 72 || dw == 64)) {
354 * FIXME: can't really do it
355 * like this because this just
356 * further reduces the memory
372 printf("unexpected data bus width "
373 "specified controller %u\n", i);
376 debug("dbw_cap_adj[%d]=%d\n", i, dbw_cap_adj[i]);
379 current_mem_base = pinfo->mem_base;
381 if (pinfo->memctl_opts[first_ctrl].memctl_interleaving) {
382 rank_density = pinfo->dimm_params[first_ctrl][0].rank_density >>
383 dbw_cap_adj[first_ctrl];
384 switch (pinfo->memctl_opts[first_ctrl].ba_intlv_ctl &
385 FSL_DDR_CS0_CS1_CS2_CS3) {
386 case FSL_DDR_CS0_CS1_CS2_CS3:
387 ctlr_density = 4 * rank_density;
389 case FSL_DDR_CS0_CS1:
390 case FSL_DDR_CS0_CS1_AND_CS2_CS3:
391 ctlr_density = 2 * rank_density;
393 case FSL_DDR_CS2_CS3:
395 ctlr_density = rank_density;
398 debug("rank density is 0x%llx, ctlr density is 0x%llx\n",
399 rank_density, ctlr_density);
400 for (i = first_ctrl; i <= last_ctrl; i++) {
401 if (pinfo->memctl_opts[i].memctl_interleaving) {
402 switch (pinfo->memctl_opts[i].memctl_interleaving_mode) {
403 case FSL_DDR_256B_INTERLEAVING:
404 case FSL_DDR_CACHE_LINE_INTERLEAVING:
405 case FSL_DDR_PAGE_INTERLEAVING:
406 case FSL_DDR_BANK_INTERLEAVING:
407 case FSL_DDR_SUPERBANK_INTERLEAVING:
408 total_ctlr_mem = 2 * ctlr_density;
410 case FSL_DDR_3WAY_1KB_INTERLEAVING:
411 case FSL_DDR_3WAY_4KB_INTERLEAVING:
412 case FSL_DDR_3WAY_8KB_INTERLEAVING:
413 total_ctlr_mem = 3 * ctlr_density;
415 case FSL_DDR_4WAY_1KB_INTERLEAVING:
416 case FSL_DDR_4WAY_4KB_INTERLEAVING:
417 case FSL_DDR_4WAY_8KB_INTERLEAVING:
418 total_ctlr_mem = 4 * ctlr_density;
421 panic("Unknown interleaving mode");
423 pinfo->common_timing_params[i].base_address =
425 pinfo->common_timing_params[i].total_mem =
427 total_mem = current_mem_base + total_ctlr_mem;
428 debug("ctrl %d base 0x%llx\n", i, current_mem_base);
429 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
431 /* when 3rd controller not interleaved */
432 current_mem_base = total_mem;
434 pinfo->common_timing_params[i].base_address =
436 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
437 unsigned long long cap =
438 pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
439 pinfo->dimm_params[i][j].base_address =
441 debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
442 current_mem_base += cap;
443 total_ctlr_mem += cap;
445 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
446 pinfo->common_timing_params[i].total_mem =
448 total_mem += total_ctlr_mem;
453 * Simple linear assignment if memory
454 * controllers are not interleaved.
456 for (i = first_ctrl; i <= last_ctrl; i++) {
458 pinfo->common_timing_params[i].base_address =
460 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
461 /* Compute DIMM base addresses. */
462 unsigned long long cap =
463 pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
464 pinfo->dimm_params[i][j].base_address =
466 debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
467 current_mem_base += cap;
468 total_ctlr_mem += cap;
470 debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
471 pinfo->common_timing_params[i].total_mem =
473 total_mem += total_ctlr_mem;
476 debug("Total mem by %s is 0x%llx\n", __func__, total_mem);
481 /* Use weak function to allow board file to override the address assignment */
482 __attribute__((weak, alias("__step_assign_addresses")))
483 unsigned long long step_assign_addresses(fsl_ddr_info_t *pinfo,
484 unsigned int dbw_cap_adj[]);
487 fsl_ddr_compute(fsl_ddr_info_t *pinfo, unsigned int start_step,
488 unsigned int size_only)
491 unsigned long long total_mem = 0;
492 int assert_reset = 0;
493 unsigned int first_ctrl = pinfo->first_ctrl;
494 unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
495 __maybe_unused int retval;
496 __maybe_unused bool goodspd = false;
497 __maybe_unused int dimm_slots_per_ctrl = pinfo->dimm_slots_per_ctrl;
499 fsl_ddr_cfg_regs_t *ddr_reg = pinfo->fsl_ddr_config_reg;
500 common_timing_params_t *timing_params = pinfo->common_timing_params;
501 if (pinfo->board_need_mem_reset)
502 assert_reset = pinfo->board_need_mem_reset();
504 /* data bus width capacity adjust shift amount */
505 unsigned int dbw_capacity_adjust[CONFIG_SYS_NUM_DDR_CTLRS];
507 for (i = first_ctrl; i <= last_ctrl; i++)
508 dbw_capacity_adjust[i] = 0;
510 debug("starting at step %u (%s)\n",
511 start_step, step_to_string(start_step));
513 switch (start_step) {
515 #if defined(CONFIG_DDR_SPD) || defined(CONFIG_SPD_EEPROM)
516 /* STEP 1: Gather all DIMM SPD data */
517 for (i = first_ctrl; i <= last_ctrl; i++) {
518 fsl_ddr_get_spd(pinfo->spd_installed_dimms[i], i,
519 dimm_slots_per_ctrl);
522 case STEP_COMPUTE_DIMM_PARMS:
523 /* STEP 2: Compute DIMM parameters from SPD data */
525 for (i = first_ctrl; i <= last_ctrl; i++) {
526 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
527 generic_spd_eeprom_t *spd =
528 &(pinfo->spd_installed_dimms[i][j]);
529 dimm_params_t *pdimm =
530 &(pinfo->dimm_params[i][j]);
531 retval = compute_dimm_parameters(
533 #ifdef CONFIG_SYS_DDR_RAW_TIMING
535 printf("SPD error on controller %d! "
536 "Trying fallback to raw timing "
538 retval = fsl_ddr_get_dimm_params(pdimm,
543 printf("Error: compute_dimm_parameters"
544 " non-zero returned FATAL value "
545 "for memctl=%u dimm=%u\n", i, j);
550 debug("Warning: compute_dimm_parameters"
551 " non-zero return value for memctl=%u "
561 * Throw an error if this is for main memory, i.e.
562 * first_ctrl == 0. Otherwise, siliently return 0
563 * as the memory size.
566 printf("Error: No valid SPD detected.\n");
570 #elif defined(CONFIG_SYS_DDR_RAW_TIMING)
571 case STEP_COMPUTE_DIMM_PARMS:
572 for (i = first_ctrl; i <= last_ctrl; i++) {
573 for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
574 dimm_params_t *pdimm =
575 &(pinfo->dimm_params[i][j]);
576 fsl_ddr_get_dimm_params(pdimm, i, j);
579 debug("Filling dimm parameters from board specific file\n");
581 case STEP_COMPUTE_COMMON_PARMS:
583 * STEP 3: Compute a common set of timing parameters
584 * suitable for all of the DIMMs on each memory controller
586 for (i = first_ctrl; i <= last_ctrl; i++) {
587 debug("Computing lowest common DIMM"
588 " parameters for memctl=%u\n", i);
589 compute_lowest_common_dimm_parameters
591 pinfo->dimm_params[i],
593 CONFIG_DIMM_SLOTS_PER_CTLR);
596 case STEP_GATHER_OPTS:
597 /* STEP 4: Gather configuration requirements from user */
598 for (i = first_ctrl; i <= last_ctrl; i++) {
599 debug("Reloading memory controller "
600 "configuration options for memctl=%u\n", i);
602 * This "reloads" the memory controller options
603 * to defaults. If the user "edits" an option,
604 * next_step points to the step after this,
605 * which is currently STEP_ASSIGN_ADDRESSES.
607 populate_memctl_options(
609 &pinfo->memctl_opts[i],
610 pinfo->dimm_params[i], i);
612 * For RDIMMs, JEDEC spec requires clocks to be stable
613 * before reset signal is deasserted. For the boards
614 * using fixed parameters, this function should be
615 * be called from board init file.
617 if (timing_params[i].all_dimms_registered)
620 if (assert_reset && !size_only) {
621 if (pinfo->board_mem_reset) {
622 debug("Asserting mem reset\n");
623 pinfo->board_mem_reset();
625 debug("Asserting mem reset missing\n");
629 case STEP_ASSIGN_ADDRESSES:
630 /* STEP 5: Assign addresses to chip selects */
631 check_interleaving_options(pinfo);
632 total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust);
633 debug("Total mem %llu assigned\n", total_mem);
635 case STEP_COMPUTE_REGS:
636 /* STEP 6: compute controller register values */
637 debug("FSL Memory ctrl register computation\n");
638 for (i = first_ctrl; i <= last_ctrl; i++) {
639 if (timing_params[i].ndimms_present == 0) {
640 memset(&ddr_reg[i], 0,
641 sizeof(fsl_ddr_cfg_regs_t));
645 compute_fsl_memctl_config_regs
647 &pinfo->memctl_opts[i],
648 &ddr_reg[i], &timing_params[i],
649 pinfo->dimm_params[i],
650 dbw_capacity_adjust[i],
660 * Compute the amount of memory available just by
661 * looking for the highest valid CSn_BNDS value.
662 * This allows us to also experiment with using
663 * only CS0 when using dual-rank DIMMs.
665 unsigned int max_end = 0;
667 for (i = first_ctrl; i <= last_ctrl; i++) {
668 for (j = 0; j < CONFIG_CHIP_SELECTS_PER_CTRL; j++) {
669 fsl_ddr_cfg_regs_t *reg = &ddr_reg[i];
670 if (reg->cs[j].config & 0x80000000) {
673 * 0xfffffff is a special value we put
676 if (reg->cs[j].bnds == 0xffffffff)
678 end = reg->cs[j].bnds & 0xffff;
686 total_mem = 1 + (((unsigned long long)max_end << 24ULL) |
687 0xFFFFFFULL) - pinfo->mem_base;
693 phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
695 unsigned int i, first_ctrl, last_ctrl;
697 unsigned int law_memctl = LAW_TRGT_IF_DDR_1;
699 unsigned long long total_memory;
700 int deassert_reset = 0;
702 first_ctrl = pinfo->first_ctrl;
703 last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
705 /* Compute it once normally. */
706 #ifdef CONFIG_FSL_DDR_INTERACTIVE
707 if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */
708 total_memory = fsl_ddr_interactive(pinfo, 0);
709 } else if (fsl_ddr_interactive_env_var_exists()) {
710 total_memory = fsl_ddr_interactive(pinfo, 1);
713 total_memory = fsl_ddr_compute(pinfo, STEP_GET_SPD, 0);
715 /* setup 3-way interleaving before enabling DDRC */
716 switch (pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode) {
717 case FSL_DDR_3WAY_1KB_INTERLEAVING:
718 case FSL_DDR_3WAY_4KB_INTERLEAVING:
719 case FSL_DDR_3WAY_8KB_INTERLEAVING:
721 pinfo->memctl_opts[first_ctrl].
722 memctl_interleaving_mode);
729 * Program configuration registers.
730 * JEDEC specs requires clocks to be stable before deasserting reset
731 * for RDIMMs. Clocks start after chip select is enabled and clock
732 * control register is set. During step 1, all controllers have their
733 * registers set but not enabled. Step 2 proceeds after deasserting
734 * reset through board FPGA or GPIO.
735 * For non-registered DIMMs, initialization can go through but it is
736 * also OK to follow the same flow.
738 if (pinfo->board_need_mem_reset)
739 deassert_reset = pinfo->board_need_mem_reset();
740 for (i = first_ctrl; i <= last_ctrl; i++) {
741 if (pinfo->common_timing_params[i].all_dimms_registered)
744 for (i = first_ctrl; i <= last_ctrl; i++) {
745 debug("Programming controller %u\n", i);
746 if (pinfo->common_timing_params[i].ndimms_present == 0) {
747 debug("No dimms present on controller %u; "
748 "skipping programming\n", i);
752 * The following call with step = 1 returns before enabling
753 * the controller. It has to finish with step = 2 later.
755 fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]), i,
756 deassert_reset ? 1 : 0);
758 if (deassert_reset) {
759 /* Use board FPGA or GPIO to deassert reset signal */
760 if (pinfo->board_mem_de_reset) {
761 debug("Deasserting mem reset\n");
762 pinfo->board_mem_de_reset();
764 debug("Deasserting mem reset missing\n");
766 for (i = first_ctrl; i <= last_ctrl; i++) {
767 /* Call with step = 2 to continue initialization */
768 fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]),
773 #ifdef CONFIG_FSL_DDR_SYNC_REFRESH
774 fsl_ddr_sync_memctl_refresh(first_ctrl, last_ctrl);
779 for (i = first_ctrl; i <= last_ctrl; i++) {
780 if (pinfo->memctl_opts[i].memctl_interleaving) {
781 switch (pinfo->memctl_opts[i].
782 memctl_interleaving_mode) {
783 case FSL_DDR_CACHE_LINE_INTERLEAVING:
784 case FSL_DDR_PAGE_INTERLEAVING:
785 case FSL_DDR_BANK_INTERLEAVING:
786 case FSL_DDR_SUPERBANK_INTERLEAVING:
790 law_memctl = LAW_TRGT_IF_DDR_INTRLV;
792 &pinfo->common_timing_params[i],
795 #if CONFIG_SYS_NUM_DDR_CTLRS > 3
797 law_memctl = LAW_TRGT_IF_DDR_INTLV_34;
799 &pinfo->common_timing_params[i],
804 case FSL_DDR_3WAY_1KB_INTERLEAVING:
805 case FSL_DDR_3WAY_4KB_INTERLEAVING:
806 case FSL_DDR_3WAY_8KB_INTERLEAVING:
807 law_memctl = LAW_TRGT_IF_DDR_INTLV_123;
810 &pinfo->common_timing_params[i],
814 case FSL_DDR_4WAY_1KB_INTERLEAVING:
815 case FSL_DDR_4WAY_4KB_INTERLEAVING:
816 case FSL_DDR_4WAY_8KB_INTERLEAVING:
817 law_memctl = LAW_TRGT_IF_DDR_INTLV_1234;
820 &pinfo->common_timing_params[i],
822 /* place holder for future 4-way interleaving */
830 law_memctl = LAW_TRGT_IF_DDR_1;
833 law_memctl = LAW_TRGT_IF_DDR_2;
836 law_memctl = LAW_TRGT_IF_DDR_3;
839 law_memctl = LAW_TRGT_IF_DDR_4;
844 fsl_ddr_set_lawbar(&pinfo->common_timing_params[i],
850 debug("total_memory by %s = %llu\n", __func__, total_memory);
852 #if !defined(CONFIG_PHYS_64BIT)
853 /* Check for 4G or more. Bad. */
854 if ((first_ctrl == 0) && (total_memory >= (1ull << 32))) {
856 print_size(total_memory, " of memory\n");
857 printf(" This U-Boot only supports < 4G of DDR\n");
858 printf(" You could rebuild it with CONFIG_PHYS_64BIT\n");
859 printf(" "); /* re-align to match init_dram print */
860 total_memory = CONFIG_MAX_MEM_MAPPED;
868 * fsl_ddr_sdram(void) -- this is the main function to be
869 * called by dram_init() in the board file.
871 * It returns amount of memory configured in bytes.
873 phys_size_t fsl_ddr_sdram(void)
877 /* Reset info structure. */
878 memset(&info, 0, sizeof(fsl_ddr_info_t));
879 info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
881 info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
882 info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
883 info.board_need_mem_reset = board_need_mem_reset;
884 info.board_mem_reset = board_assert_mem_reset;
885 info.board_mem_de_reset = board_deassert_mem_reset;
886 remove_unused_controllers(&info);
888 return __fsl_ddr_sdram(&info);
891 #ifdef CONFIG_SYS_FSL_OTHER_DDR_NUM_CTRLS
892 phys_size_t fsl_other_ddr_sdram(unsigned long long base,
893 unsigned int first_ctrl,
894 unsigned int num_ctrls,
895 unsigned int dimm_slots_per_ctrl,
896 int (*board_need_reset)(void),
897 void (*board_reset)(void),
898 void (*board_de_reset)(void))
902 /* Reset info structure. */
903 memset(&info, 0, sizeof(fsl_ddr_info_t));
904 info.mem_base = base;
905 info.first_ctrl = first_ctrl;
906 info.num_ctrls = num_ctrls;
907 info.dimm_slots_per_ctrl = dimm_slots_per_ctrl;
908 info.board_need_mem_reset = board_need_reset;
909 info.board_mem_reset = board_reset;
910 info.board_mem_de_reset = board_de_reset;
912 return __fsl_ddr_sdram(&info);
917 * fsl_ddr_sdram_size(first_ctrl, last_intlv) - This function only returns the
918 * size of the total memory without setting ddr control registers.
921 fsl_ddr_sdram_size(void)
924 unsigned long long total_memory = 0;
926 memset(&info, 0 , sizeof(fsl_ddr_info_t));
927 info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
929 info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
930 info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
931 info.board_need_mem_reset = NULL;
932 remove_unused_controllers(&info);
934 /* Compute it once normally. */
935 total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 1);