2 * Copyright 2008, 2010-2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fsl_ddr_sdram.h>
14 * Use our own stack based buffer before relocation to allow accessing longer
15 * hwconfig strings that might be in the environment before we've relocated.
16 * This is pretty fragile on both the use of stack and if the buffer is big
17 * enough. However we will get a warning from getenv_f for the later.
20 /* Board-specific functions defined in each board's ddr.c */
21 extern void fsl_ddr_board_options(memctl_options_t
*popts
,
23 unsigned int ctrl_num
);
26 unsigned int odt_rd_cfg
;
27 unsigned int odt_wr_cfg
;
28 unsigned int odt_rtt_norm
;
29 unsigned int odt_rtt_wr
;
32 #ifdef CONFIG_SYS_FSL_DDR4
33 /* Quad rank is not verified yet due availability.
34 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
36 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
39 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
40 DDR4_RTT_34_OHM
, /* unverified */
51 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
57 FSL_DDR_ODT_NEVER
, /* tied high */
63 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
80 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
92 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
95 FSL_DDR_ODT_SAME_DIMM
,
100 FSL_DDR_ODT_OTHER_DIMM
,
101 FSL_DDR_ODT_OTHER_DIMM
,
107 FSL_DDR_ODT_SAME_DIMM
,
112 FSL_DDR_ODT_OTHER_DIMM
,
113 FSL_DDR_ODT_OTHER_DIMM
,
119 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
122 FSL_DDR_ODT_SAME_DIMM
,
127 FSL_DDR_ODT_OTHER_DIMM
,
128 FSL_DDR_ODT_OTHER_DIMM
,
133 FSL_DDR_ODT_OTHER_DIMM
,
140 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
142 FSL_DDR_ODT_OTHER_DIMM
,
150 FSL_DDR_ODT_SAME_DIMM
,
155 FSL_DDR_ODT_OTHER_DIMM
,
156 FSL_DDR_ODT_OTHER_DIMM
,
162 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
164 FSL_DDR_ODT_OTHER_DIMM
,
171 FSL_DDR_ODT_OTHER_DIMM
,
179 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
182 FSL_DDR_ODT_SAME_DIMM
,
196 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
201 FSL_DDR_ODT_SAME_DIMM
,
213 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
226 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
239 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
265 #elif defined(CONFIG_SYS_FSL_DDR3)
266 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
269 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
275 FSL_DDR_ODT_NEVER
, /* tied high */
281 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
287 FSL_DDR_ODT_NEVER
, /* tied high */
293 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
310 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
322 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
325 FSL_DDR_ODT_SAME_DIMM
,
330 FSL_DDR_ODT_OTHER_DIMM
,
331 FSL_DDR_ODT_OTHER_DIMM
,
337 FSL_DDR_ODT_SAME_DIMM
,
342 FSL_DDR_ODT_OTHER_DIMM
,
343 FSL_DDR_ODT_OTHER_DIMM
,
349 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
352 FSL_DDR_ODT_SAME_DIMM
,
357 FSL_DDR_ODT_OTHER_DIMM
,
358 FSL_DDR_ODT_OTHER_DIMM
,
363 FSL_DDR_ODT_OTHER_DIMM
,
370 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
372 FSL_DDR_ODT_OTHER_DIMM
,
380 FSL_DDR_ODT_SAME_DIMM
,
385 FSL_DDR_ODT_OTHER_DIMM
,
386 FSL_DDR_ODT_OTHER_DIMM
,
392 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
394 FSL_DDR_ODT_OTHER_DIMM
,
401 FSL_DDR_ODT_OTHER_DIMM
,
409 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
412 FSL_DDR_ODT_SAME_DIMM
,
426 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
431 FSL_DDR_ODT_SAME_DIMM
,
443 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
456 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
469 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
495 #else /* CONFIG_SYS_FSL_DDR3 */
496 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
503 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
520 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
532 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
534 FSL_DDR_ODT_OTHER_DIMM
,
535 FSL_DDR_ODT_OTHER_DIMM
,
546 FSL_DDR_ODT_OTHER_DIMM
,
547 FSL_DDR_ODT_OTHER_DIMM
,
559 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
561 FSL_DDR_ODT_OTHER_DIMM
,
562 FSL_DDR_ODT_OTHER_DIMM
,
573 FSL_DDR_ODT_OTHER_DIMM
,
574 FSL_DDR_ODT_OTHER_DIMM
,
581 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
583 FSL_DDR_ODT_OTHER_DIMM
,
584 FSL_DDR_ODT_OTHER_DIMM
,
590 FSL_DDR_ODT_OTHER_DIMM
,
591 FSL_DDR_ODT_OTHER_DIMM
,
603 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
605 FSL_DDR_ODT_OTHER_DIMM
,
606 FSL_DDR_ODT_OTHER_DIMM
,
612 FSL_DDR_ODT_OTHER_DIMM
,
613 FSL_DDR_ODT_OTHER_DIMM
,
620 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
637 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
654 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
667 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
680 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
709 * Automatically seleect bank interleaving mode based on DIMMs
710 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
711 * This function only deal with one or two slots per controller.
713 static inline unsigned int auto_bank_intlv(dimm_params_t
*pdimm
)
715 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
716 if (pdimm
[0].n_ranks
== 4)
717 return FSL_DDR_CS0_CS1_CS2_CS3
;
718 else if (pdimm
[0].n_ranks
== 2)
719 return FSL_DDR_CS0_CS1
;
720 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
721 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
722 if (pdimm
[0].n_ranks
== 4)
723 return FSL_DDR_CS0_CS1_CS2_CS3
;
725 if (pdimm
[0].n_ranks
== 2) {
726 if (pdimm
[1].n_ranks
== 2)
727 return FSL_DDR_CS0_CS1_CS2_CS3
;
729 return FSL_DDR_CS0_CS1
;
735 unsigned int populate_memctl_options(const common_timing_params_t
*common_dimm
,
736 memctl_options_t
*popts
,
737 dimm_params_t
*pdimm
,
738 unsigned int ctrl_num
)
741 char buffer
[HWCONFIG_BUFFER_SIZE
];
743 #if defined(CONFIG_SYS_FSL_DDR3) || \
744 defined(CONFIG_SYS_FSL_DDR2) || \
745 defined(CONFIG_SYS_FSL_DDR4)
746 const struct dynamic_odt
*pdodt
= odt_unknown
;
751 * Extract hwconfig from environment since we have not properly setup
752 * the environment but need it for ddr config params
754 if (getenv_f("hwconfig", buffer
, sizeof(buffer
)) > 0)
757 #if defined(CONFIG_SYS_FSL_DDR3) || \
758 defined(CONFIG_SYS_FSL_DDR2) || \
759 defined(CONFIG_SYS_FSL_DDR4)
760 /* Chip select options. */
761 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
762 switch (pdimm
[0].n_ranks
) {
773 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
774 switch (pdimm
[0].n_ranks
) {
775 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
778 if (pdimm
[1].n_ranks
)
779 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
783 switch (pdimm
[1].n_ranks
) {
796 switch (pdimm
[1].n_ranks
) {
809 switch (pdimm
[1].n_ranks
) {
819 #endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
820 #endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
822 /* Pick chip-select local options. */
823 for (i
= 0; i
< CONFIG_CHIP_SELECTS_PER_CTRL
; i
++) {
824 #if defined(CONFIG_SYS_FSL_DDR3) || \
825 defined(CONFIG_SYS_FSL_DDR2) || \
826 defined(CONFIG_SYS_FSL_DDR4)
827 popts
->cs_local_opts
[i
].odt_rd_cfg
= pdodt
[i
].odt_rd_cfg
;
828 popts
->cs_local_opts
[i
].odt_wr_cfg
= pdodt
[i
].odt_wr_cfg
;
829 popts
->cs_local_opts
[i
].odt_rtt_norm
= pdodt
[i
].odt_rtt_norm
;
830 popts
->cs_local_opts
[i
].odt_rtt_wr
= pdodt
[i
].odt_rtt_wr
;
832 popts
->cs_local_opts
[i
].odt_rd_cfg
= FSL_DDR_ODT_NEVER
;
833 popts
->cs_local_opts
[i
].odt_wr_cfg
= FSL_DDR_ODT_CS
;
835 popts
->cs_local_opts
[i
].auto_precharge
= 0;
838 /* Pick interleaving mode. */
841 * 0 = no interleaving
842 * 1 = interleaving between 2 controllers
844 popts
->memctl_interleaving
= 0;
850 * 3 = superbank (only if CS interleaving is enabled)
852 popts
->memctl_interleaving_mode
= 0;
855 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
856 * 1: page: bit to the left of the column bits selects the memctl
857 * 2: bank: bit to the left of the bank bits selects the memctl
858 * 3: superbank: bit to the left of the chip select selects the memctl
860 * NOTE: ba_intlv (rank interleaving) is independent of memory
861 * controller interleaving; it is only within a memory controller.
862 * Must use superbank interleaving if rank interleaving is used and
863 * memory controller interleaving is enabled.
870 * 0x60 = CS0,CS1 + CS2,CS3
871 * 0x04 = CS0,CS1,CS2,CS3
873 popts
->ba_intlv_ctl
= 0;
875 /* Memory Organization Parameters */
876 popts
->registered_dimm_en
= common_dimm
->all_dimms_registered
;
878 /* Operational Mode Paramters */
881 popts
->ecc_mode
= 0; /* 0 = disabled, 1 = enabled */
882 #ifdef CONFIG_DDR_ECC
883 if (hwconfig_sub_f("fsl_ddr", "ecc", buf
)) {
884 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf
))
889 /* 1 = use memory controler to init data */
890 popts
->ecc_init_using_memctl
= popts
->ecc_mode
? 1 : 0;
897 #if defined(CONFIG_SYS_FSL_DDR1)
898 popts
->dqs_config
= 0;
899 #elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
900 popts
->dqs_config
= 1;
903 /* Choose self-refresh during sleep. */
904 popts
->self_refresh_in_sleep
= 1;
906 /* Choose dynamic power management mode. */
907 popts
->dynamic_power
= 0;
910 * check first dimm for primary sdram width
911 * presuming all dimms are similar
912 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
914 #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
915 if (pdimm
[0].n_ranks
!= 0) {
916 if ((pdimm
[0].data_width
>= 64) && \
917 (pdimm
[0].data_width
<= 72))
918 popts
->data_bus_width
= 0;
919 else if ((pdimm
[0].data_width
>= 32) && \
920 (pdimm
[0].data_width
<= 40))
921 popts
->data_bus_width
= 1;
923 panic("Error: data width %u is invalid!\n",
924 pdimm
[0].data_width
);
928 if (pdimm
[0].n_ranks
!= 0) {
929 if (pdimm
[0].primary_sdram_width
== 64)
930 popts
->data_bus_width
= 0;
931 else if (pdimm
[0].primary_sdram_width
== 32)
932 popts
->data_bus_width
= 1;
933 else if (pdimm
[0].primary_sdram_width
== 16)
934 popts
->data_bus_width
= 2;
936 panic("Error: primary sdram width %u is invalid!\n",
937 pdimm
[0].primary_sdram_width
);
942 popts
->x4_en
= (pdimm
[0].device_width
== 4) ? 1 : 0;
944 /* Choose burst length. */
945 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
946 #if defined(CONFIG_E500MC)
947 popts
->otf_burst_chop_en
= 0; /* on-the-fly burst chop disable */
948 popts
->burst_length
= DDR_BL8
; /* Fixed 8-beat burst len */
950 if ((popts
->data_bus_width
== 1) || (popts
->data_bus_width
== 2)) {
951 /* 32-bit or 16-bit bus */
952 popts
->otf_burst_chop_en
= 0;
953 popts
->burst_length
= DDR_BL8
;
955 popts
->otf_burst_chop_en
= 1; /* on-the-fly burst chop */
956 popts
->burst_length
= DDR_OTF
; /* on-the-fly BC4 and BL8 */
960 popts
->burst_length
= DDR_BL4
; /* has to be 4 for DDR2 */
963 /* Choose ddr controller address mirror mode */
964 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
965 for (i
= 0; i
< CONFIG_DIMM_SLOTS_PER_CTLR
; i
++) {
966 if (pdimm
[i
].n_ranks
) {
967 popts
->mirrored_dimm
= pdimm
[i
].mirrored_dimm
;
973 /* Global Timing Parameters. */
974 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num
));
976 /* Pick a caslat override. */
977 popts
->cas_latency_override
= 0;
978 popts
->cas_latency_override_value
= 3;
979 if (popts
->cas_latency_override
) {
980 debug("using caslat override value = %u\n",
981 popts
->cas_latency_override_value
);
984 /* Decide whether to use the computed derated latency */
985 popts
->use_derated_caslat
= 0;
987 /* Choose an additive latency. */
988 popts
->additive_latency_override
= 0;
989 popts
->additive_latency_override_value
= 3;
990 if (popts
->additive_latency_override
) {
991 debug("using additive latency override value = %u\n",
992 popts
->additive_latency_override_value
);
998 * Factors to consider for 2T_EN:
999 * - number of DIMMs installed
1000 * - number of components, number of active ranks
1001 * - how much time you want to spend playing around
1004 popts
->threet_en
= 0;
1006 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1007 if (popts
->registered_dimm_en
)
1008 popts
->ap_en
= 1; /* 0 = disable, 1 = enable */
1010 popts
->ap_en
= 0; /* disabled for DDR4 UDIMM/discrete default */
1012 if (hwconfig_sub_f("fsl_ddr", "parity", buf
)) {
1013 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf
)) {
1014 if (popts
->registered_dimm_en
||
1015 (CONFIG_FSL_SDRAM_TYPE
== SDRAM_TYPE_DDR4
))
1021 * BSTTOPRE precharge interval
1023 * Set this to 0 for global auto precharge
1024 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1025 * It is not wrong. Any value should be OK. The performance depends on
1026 * applications. There is no one good value for all. One way to set
1027 * is to use 1/4 of refint value.
1029 popts
->bstopre
= picos_to_mclk(ctrl_num
, common_dimm
->refresh_rate_ps
)
1033 * Window for four activates -- tFAW
1035 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1036 * FIXME: varies depending upon number of column addresses or data
1037 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1039 #if defined(CONFIG_SYS_FSL_DDR1)
1040 popts
->tfaw_window_four_activates_ps
= mclk_to_picos(ctrl_num
, 1);
1042 #elif defined(CONFIG_SYS_FSL_DDR2)
1044 * x4/x8; some datasheets have 35000
1045 * x16 wide columns only? Use 50000?
1047 popts
->tfaw_window_four_activates_ps
= 37500;
1050 popts
->tfaw_window_four_activates_ps
= pdimm
[0].tfaw_ps
;
1053 popts
->wrlvl_en
= 0;
1054 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
1056 * due to ddr3 dimm is fly-by topology
1057 * we suggest to enable write leveling to
1058 * meet the tQDSS under different loading.
1060 popts
->wrlvl_en
= 1;
1062 popts
->wrlvl_override
= 0;
1066 * Check interleaving configuration from environment.
1067 * Please refer to doc/README.fsl-ddr for the detail.
1069 * If memory controller interleaving is enabled, then the data
1070 * bus widths must be programmed identically for all memory controllers.
1072 * Attempt to set all controllers to the same chip select
1073 * interleaving mode. It will do a best effort to get the
1074 * requested ranks interleaved together such that the result
1075 * should be a subset of the requested configuration.
1077 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1078 * with 256 Byte is enabled.
1080 #if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
1081 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf
))
1082 #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1087 if (pdimm
[0].n_ranks
== 0) {
1088 printf("There is no rank on CS0 for controller %d.\n", ctrl_num
);
1089 popts
->memctl_interleaving
= 0;
1092 popts
->memctl_interleaving
= 1;
1093 #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1094 popts
->memctl_interleaving_mode
= FSL_DDR_256B_INTERLEAVING
;
1095 popts
->memctl_interleaving
= 1;
1096 debug("256 Byte interleaving\n");
1099 * test null first. if CONFIG_HWCONFIG is not defined
1100 * hwconfig_arg_cmp returns non-zero
1102 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1104 popts
->memctl_interleaving
= 0;
1105 debug("memory controller interleaving disabled.\n");
1106 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1108 "cacheline", buf
)) {
1109 popts
->memctl_interleaving_mode
=
1110 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1111 0 : FSL_DDR_CACHE_LINE_INTERLEAVING
;
1112 popts
->memctl_interleaving
=
1113 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1115 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1118 popts
->memctl_interleaving_mode
=
1119 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1120 0 : FSL_DDR_PAGE_INTERLEAVING
;
1121 popts
->memctl_interleaving
=
1122 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1124 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1127 popts
->memctl_interleaving_mode
=
1128 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1129 0 : FSL_DDR_BANK_INTERLEAVING
;
1130 popts
->memctl_interleaving
=
1131 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1133 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1135 "superbank", buf
)) {
1136 popts
->memctl_interleaving_mode
=
1137 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1138 0 : FSL_DDR_SUPERBANK_INTERLEAVING
;
1139 popts
->memctl_interleaving
=
1140 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1142 #if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
1143 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1146 popts
->memctl_interleaving_mode
=
1147 FSL_DDR_3WAY_1KB_INTERLEAVING
;
1148 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1151 popts
->memctl_interleaving_mode
=
1152 FSL_DDR_3WAY_4KB_INTERLEAVING
;
1153 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1156 popts
->memctl_interleaving_mode
=
1157 FSL_DDR_3WAY_8KB_INTERLEAVING
;
1158 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
1159 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1162 popts
->memctl_interleaving_mode
=
1163 FSL_DDR_4WAY_1KB_INTERLEAVING
;
1164 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1167 popts
->memctl_interleaving_mode
=
1168 FSL_DDR_4WAY_4KB_INTERLEAVING
;
1169 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1172 popts
->memctl_interleaving_mode
=
1173 FSL_DDR_4WAY_8KB_INTERLEAVING
;
1176 popts
->memctl_interleaving
= 0;
1177 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
1179 #endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
1181 #endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
1182 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf
)) &&
1183 (CONFIG_CHIP_SELECTS_PER_CTRL
> 1)) {
1184 /* test null first. if CONFIG_HWCONFIG is not defined,
1185 * hwconfig_subarg_cmp_f returns non-zero */
1186 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1188 debug("bank interleaving disabled.\n");
1189 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1191 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1
;
1192 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1194 popts
->ba_intlv_ctl
= FSL_DDR_CS2_CS3
;
1195 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1196 "cs0_cs1_and_cs2_cs3", buf
))
1197 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1_AND_CS2_CS3
;
1198 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1199 "cs0_cs1_cs2_cs3", buf
))
1200 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1_CS2_CS3
;
1201 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1203 popts
->ba_intlv_ctl
= auto_bank_intlv(pdimm
);
1205 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
1206 switch (popts
->ba_intlv_ctl
& FSL_DDR_CS0_CS1_CS2_CS3
) {
1207 case FSL_DDR_CS0_CS1_CS2_CS3
:
1208 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1209 if (pdimm
[0].n_ranks
< 4) {
1210 popts
->ba_intlv_ctl
= 0;
1211 printf("Not enough bank(chip-select) for "
1212 "CS0+CS1+CS2+CS3 on controller %d, "
1213 "interleaving disabled!\n", ctrl_num
);
1215 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1216 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1217 if (pdimm
[0].n_ranks
== 4)
1220 if ((pdimm
[0].n_ranks
< 2) && (pdimm
[1].n_ranks
< 2)) {
1221 popts
->ba_intlv_ctl
= 0;
1222 printf("Not enough bank(chip-select) for "
1223 "CS0+CS1+CS2+CS3 on controller %d, "
1224 "interleaving disabled!\n", ctrl_num
);
1226 if (pdimm
[0].capacity
!= pdimm
[1].capacity
) {
1227 popts
->ba_intlv_ctl
= 0;
1228 printf("Not identical DIMM size for "
1229 "CS0+CS1+CS2+CS3 on controller %d, "
1230 "interleaving disabled!\n", ctrl_num
);
1234 case FSL_DDR_CS0_CS1
:
1235 if (pdimm
[0].n_ranks
< 2) {
1236 popts
->ba_intlv_ctl
= 0;
1237 printf("Not enough bank(chip-select) for "
1238 "CS0+CS1 on controller %d, "
1239 "interleaving disabled!\n", ctrl_num
);
1242 case FSL_DDR_CS2_CS3
:
1243 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1244 if (pdimm
[0].n_ranks
< 4) {
1245 popts
->ba_intlv_ctl
= 0;
1246 printf("Not enough bank(chip-select) for CS2+CS3 "
1247 "on controller %d, interleaving disabled!\n", ctrl_num
);
1249 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1250 if (pdimm
[1].n_ranks
< 2) {
1251 popts
->ba_intlv_ctl
= 0;
1252 printf("Not enough bank(chip-select) for CS2+CS3 "
1253 "on controller %d, interleaving disabled!\n", ctrl_num
);
1257 case FSL_DDR_CS0_CS1_AND_CS2_CS3
:
1258 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1259 if (pdimm
[0].n_ranks
< 4) {
1260 popts
->ba_intlv_ctl
= 0;
1261 printf("Not enough bank(CS) for CS0+CS1 and "
1262 "CS2+CS3 on controller %d, "
1263 "interleaving disabled!\n", ctrl_num
);
1265 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1266 if ((pdimm
[0].n_ranks
< 2) || (pdimm
[1].n_ranks
< 2)) {
1267 popts
->ba_intlv_ctl
= 0;
1268 printf("Not enough bank(CS) for CS0+CS1 and "
1269 "CS2+CS3 on controller %d, "
1270 "interleaving disabled!\n", ctrl_num
);
1275 popts
->ba_intlv_ctl
= 0;
1280 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf
)) {
1281 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf
))
1282 popts
->addr_hash
= 0;
1283 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1285 popts
->addr_hash
= 1;
1288 if (pdimm
[0].n_ranks
== 4)
1289 popts
->quad_rank_present
= 1;
1291 ddr_freq
= get_ddr_freq(ctrl_num
) / 1000000;
1292 if (popts
->registered_dimm_en
) {
1293 popts
->rcw_override
= 1;
1294 popts
->rcw_1
= 0x000a5a00;
1295 if (ddr_freq
<= 800)
1296 popts
->rcw_2
= 0x00000000;
1297 else if (ddr_freq
<= 1066)
1298 popts
->rcw_2
= 0x00100000;
1299 else if (ddr_freq
<= 1333)
1300 popts
->rcw_2
= 0x00200000;
1302 popts
->rcw_2
= 0x00300000;
1305 fsl_ddr_board_options(popts
, pdimm
, ctrl_num
);
1310 void check_interleaving_options(fsl_ddr_info_t
*pinfo
)
1312 int i
, j
, k
, check_n_ranks
, intlv_invalid
= 0;
1313 unsigned int check_intlv
, check_n_row_addr
, check_n_col_addr
;
1314 unsigned long long check_rank_density
;
1315 struct dimm_params_s
*dimm
;
1316 int first_ctrl
= pinfo
->first_ctrl
;
1317 int last_ctrl
= first_ctrl
+ pinfo
->num_ctrls
- 1;
1320 * Check if all controllers are configured for memory
1321 * controller interleaving. Identical dimms are recommended. At least
1322 * the size, row and col address should be checked.
1325 check_n_ranks
= pinfo
->dimm_params
[first_ctrl
][0].n_ranks
;
1326 check_rank_density
= pinfo
->dimm_params
[first_ctrl
][0].rank_density
;
1327 check_n_row_addr
= pinfo
->dimm_params
[first_ctrl
][0].n_row_addr
;
1328 check_n_col_addr
= pinfo
->dimm_params
[first_ctrl
][0].n_col_addr
;
1329 check_intlv
= pinfo
->memctl_opts
[first_ctrl
].memctl_interleaving_mode
;
1330 for (i
= first_ctrl
; i
<= last_ctrl
; i
++) {
1331 dimm
= &pinfo
->dimm_params
[i
][0];
1332 if (!pinfo
->memctl_opts
[i
].memctl_interleaving
) {
1334 } else if (((check_rank_density
!= dimm
->rank_density
) ||
1335 (check_n_ranks
!= dimm
->n_ranks
) ||
1336 (check_n_row_addr
!= dimm
->n_row_addr
) ||
1337 (check_n_col_addr
!= dimm
->n_col_addr
) ||
1339 pinfo
->memctl_opts
[i
].memctl_interleaving_mode
))){
1347 if (intlv_invalid
) {
1348 for (i
= first_ctrl
; i
<= last_ctrl
; i
++)
1349 pinfo
->memctl_opts
[i
].memctl_interleaving
= 0;
1350 printf("Not all DIMMs are identical. "
1351 "Memory controller interleaving disabled.\n");
1353 switch (check_intlv
) {
1354 case FSL_DDR_256B_INTERLEAVING
:
1355 case FSL_DDR_CACHE_LINE_INTERLEAVING
:
1356 case FSL_DDR_PAGE_INTERLEAVING
:
1357 case FSL_DDR_BANK_INTERLEAVING
:
1358 case FSL_DDR_SUPERBANK_INTERLEAVING
:
1359 #if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
1362 k
= CONFIG_SYS_NUM_DDR_CTLRS
;
1365 case FSL_DDR_3WAY_1KB_INTERLEAVING
:
1366 case FSL_DDR_3WAY_4KB_INTERLEAVING
:
1367 case FSL_DDR_3WAY_8KB_INTERLEAVING
:
1368 case FSL_DDR_4WAY_1KB_INTERLEAVING
:
1369 case FSL_DDR_4WAY_4KB_INTERLEAVING
:
1370 case FSL_DDR_4WAY_8KB_INTERLEAVING
:
1372 k
= CONFIG_SYS_NUM_DDR_CTLRS
;
1375 debug("%d of %d controllers are interleaving.\n", j
, k
);
1376 if (j
&& (j
!= k
)) {
1377 for (i
= first_ctrl
; i
<= last_ctrl
; i
++)
1378 pinfo
->memctl_opts
[i
].memctl_interleaving
= 0;
1379 if ((last_ctrl
- first_ctrl
) > 1)
1380 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
1383 debug("Checking interleaving options completed\n");
1386 int fsl_use_spd(void)
1390 #ifdef CONFIG_DDR_SPD
1391 char buffer
[HWCONFIG_BUFFER_SIZE
];
1395 * Extract hwconfig from environment since we have not properly setup
1396 * the environment but need it for ddr config params
1398 if (getenv_f("hwconfig", buffer
, sizeof(buffer
)) > 0)
1401 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
1402 if (hwconfig_sub_f("fsl_ddr", "sdram", buf
)) {
1403 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf
))
1405 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",