2 * Copyright 2008, 2010-2014 Freescale Semiconductor, Inc.
4 * SPDX-License-Identifier: GPL-2.0+
9 #include <fsl_ddr_sdram.h>
12 #if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3)
13 #include <asm/arch/clock.h>
17 * Use our own stack based buffer before relocation to allow accessing longer
18 * hwconfig strings that might be in the environment before we've relocated.
19 * This is pretty fragile on both the use of stack and if the buffer is big
20 * enough. However we will get a warning from getenv_f for the later.
23 /* Board-specific functions defined in each board's ddr.c */
24 extern void fsl_ddr_board_options(memctl_options_t
*popts
,
26 unsigned int ctrl_num
);
29 unsigned int odt_rd_cfg
;
30 unsigned int odt_wr_cfg
;
31 unsigned int odt_rtt_norm
;
32 unsigned int odt_rtt_wr
;
35 #ifdef CONFIG_SYS_FSL_DDR4
36 /* Quad rank is not verified yet due availability.
37 * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
39 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
42 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
43 DDR4_RTT_34_OHM
, /* unverified */
54 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
60 FSL_DDR_ODT_NEVER
, /* tied high */
66 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
83 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
95 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
98 FSL_DDR_ODT_SAME_DIMM
,
103 FSL_DDR_ODT_OTHER_DIMM
,
104 FSL_DDR_ODT_OTHER_DIMM
,
110 FSL_DDR_ODT_SAME_DIMM
,
115 FSL_DDR_ODT_OTHER_DIMM
,
116 FSL_DDR_ODT_OTHER_DIMM
,
122 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
125 FSL_DDR_ODT_SAME_DIMM
,
130 FSL_DDR_ODT_OTHER_DIMM
,
131 FSL_DDR_ODT_OTHER_DIMM
,
136 FSL_DDR_ODT_OTHER_DIMM
,
143 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
145 FSL_DDR_ODT_OTHER_DIMM
,
153 FSL_DDR_ODT_SAME_DIMM
,
158 FSL_DDR_ODT_OTHER_DIMM
,
159 FSL_DDR_ODT_OTHER_DIMM
,
165 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
167 FSL_DDR_ODT_OTHER_DIMM
,
174 FSL_DDR_ODT_OTHER_DIMM
,
182 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
185 FSL_DDR_ODT_SAME_DIMM
,
199 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
204 FSL_DDR_ODT_SAME_DIMM
,
216 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
229 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
242 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
268 #elif defined(CONFIG_SYS_FSL_DDR3)
269 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
272 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
278 FSL_DDR_ODT_NEVER
, /* tied high */
284 FSL_DDR_ODT_CS_AND_OTHER_DIMM
,
290 FSL_DDR_ODT_NEVER
, /* tied high */
296 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
313 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
325 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
328 FSL_DDR_ODT_SAME_DIMM
,
333 FSL_DDR_ODT_OTHER_DIMM
,
334 FSL_DDR_ODT_OTHER_DIMM
,
340 FSL_DDR_ODT_SAME_DIMM
,
345 FSL_DDR_ODT_OTHER_DIMM
,
346 FSL_DDR_ODT_OTHER_DIMM
,
352 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
355 FSL_DDR_ODT_SAME_DIMM
,
360 FSL_DDR_ODT_OTHER_DIMM
,
361 FSL_DDR_ODT_OTHER_DIMM
,
366 FSL_DDR_ODT_OTHER_DIMM
,
373 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
375 FSL_DDR_ODT_OTHER_DIMM
,
383 FSL_DDR_ODT_SAME_DIMM
,
388 FSL_DDR_ODT_OTHER_DIMM
,
389 FSL_DDR_ODT_OTHER_DIMM
,
395 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
397 FSL_DDR_ODT_OTHER_DIMM
,
404 FSL_DDR_ODT_OTHER_DIMM
,
412 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
415 FSL_DDR_ODT_SAME_DIMM
,
429 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
434 FSL_DDR_ODT_SAME_DIMM
,
446 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
459 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
472 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
498 #else /* CONFIG_SYS_FSL_DDR3 */
499 static __maybe_unused
const struct dynamic_odt single_Q
[4] = {
506 static __maybe_unused
const struct dynamic_odt single_D
[4] = {
523 static __maybe_unused
const struct dynamic_odt single_S
[4] = {
535 static __maybe_unused
const struct dynamic_odt dual_DD
[4] = {
537 FSL_DDR_ODT_OTHER_DIMM
,
538 FSL_DDR_ODT_OTHER_DIMM
,
549 FSL_DDR_ODT_OTHER_DIMM
,
550 FSL_DDR_ODT_OTHER_DIMM
,
562 static __maybe_unused
const struct dynamic_odt dual_DS
[4] = {
564 FSL_DDR_ODT_OTHER_DIMM
,
565 FSL_DDR_ODT_OTHER_DIMM
,
576 FSL_DDR_ODT_OTHER_DIMM
,
577 FSL_DDR_ODT_OTHER_DIMM
,
584 static __maybe_unused
const struct dynamic_odt dual_SD
[4] = {
586 FSL_DDR_ODT_OTHER_DIMM
,
587 FSL_DDR_ODT_OTHER_DIMM
,
593 FSL_DDR_ODT_OTHER_DIMM
,
594 FSL_DDR_ODT_OTHER_DIMM
,
606 static __maybe_unused
const struct dynamic_odt dual_SS
[4] = {
608 FSL_DDR_ODT_OTHER_DIMM
,
609 FSL_DDR_ODT_OTHER_DIMM
,
615 FSL_DDR_ODT_OTHER_DIMM
,
616 FSL_DDR_ODT_OTHER_DIMM
,
623 static __maybe_unused
const struct dynamic_odt dual_D0
[4] = {
640 static __maybe_unused
const struct dynamic_odt dual_0D
[4] = {
657 static __maybe_unused
const struct dynamic_odt dual_S0
[4] = {
670 static __maybe_unused
const struct dynamic_odt dual_0S
[4] = {
683 static __maybe_unused
const struct dynamic_odt odt_unknown
[4] = {
712 * Automatically seleect bank interleaving mode based on DIMMs
713 * in this order: cs0_cs1_cs2_cs3, cs0_cs1, null.
714 * This function only deal with one or two slots per controller.
716 static inline unsigned int auto_bank_intlv(dimm_params_t
*pdimm
)
718 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
719 if (pdimm
[0].n_ranks
== 4)
720 return FSL_DDR_CS0_CS1_CS2_CS3
;
721 else if (pdimm
[0].n_ranks
== 2)
722 return FSL_DDR_CS0_CS1
;
723 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
724 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
725 if (pdimm
[0].n_ranks
== 4)
726 return FSL_DDR_CS0_CS1_CS2_CS3
;
728 if (pdimm
[0].n_ranks
== 2) {
729 if (pdimm
[1].n_ranks
== 2)
730 return FSL_DDR_CS0_CS1_CS2_CS3
;
732 return FSL_DDR_CS0_CS1
;
738 unsigned int populate_memctl_options(const common_timing_params_t
*common_dimm
,
739 memctl_options_t
*popts
,
740 dimm_params_t
*pdimm
,
741 unsigned int ctrl_num
)
744 char buffer
[HWCONFIG_BUFFER_SIZE
];
746 #if defined(CONFIG_SYS_FSL_DDR3) || \
747 defined(CONFIG_SYS_FSL_DDR2) || \
748 defined(CONFIG_SYS_FSL_DDR4)
749 const struct dynamic_odt
*pdodt
= odt_unknown
;
754 * Extract hwconfig from environment since we have not properly setup
755 * the environment but need it for ddr config params
757 if (getenv_f("hwconfig", buffer
, sizeof(buffer
)) > 0)
760 #if defined(CONFIG_SYS_FSL_DDR3) || \
761 defined(CONFIG_SYS_FSL_DDR2) || \
762 defined(CONFIG_SYS_FSL_DDR4)
763 /* Chip select options. */
764 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
765 switch (pdimm
[0].n_ranks
) {
776 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
777 switch (pdimm
[0].n_ranks
) {
778 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
781 if (pdimm
[1].n_ranks
)
782 printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
786 switch (pdimm
[1].n_ranks
) {
799 switch (pdimm
[1].n_ranks
) {
812 switch (pdimm
[1].n_ranks
) {
822 #endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
823 #endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
825 /* Pick chip-select local options. */
826 for (i
= 0; i
< CONFIG_CHIP_SELECTS_PER_CTRL
; i
++) {
827 #if defined(CONFIG_SYS_FSL_DDR3) || \
828 defined(CONFIG_SYS_FSL_DDR2) || \
829 defined(CONFIG_SYS_FSL_DDR4)
830 popts
->cs_local_opts
[i
].odt_rd_cfg
= pdodt
[i
].odt_rd_cfg
;
831 popts
->cs_local_opts
[i
].odt_wr_cfg
= pdodt
[i
].odt_wr_cfg
;
832 popts
->cs_local_opts
[i
].odt_rtt_norm
= pdodt
[i
].odt_rtt_norm
;
833 popts
->cs_local_opts
[i
].odt_rtt_wr
= pdodt
[i
].odt_rtt_wr
;
835 popts
->cs_local_opts
[i
].odt_rd_cfg
= FSL_DDR_ODT_NEVER
;
836 popts
->cs_local_opts
[i
].odt_wr_cfg
= FSL_DDR_ODT_CS
;
838 popts
->cs_local_opts
[i
].auto_precharge
= 0;
841 /* Pick interleaving mode. */
844 * 0 = no interleaving
845 * 1 = interleaving between 2 controllers
847 popts
->memctl_interleaving
= 0;
853 * 3 = superbank (only if CS interleaving is enabled)
855 popts
->memctl_interleaving_mode
= 0;
858 * 0: cacheline: bit 30 of the 36-bit physical addr selects the memctl
859 * 1: page: bit to the left of the column bits selects the memctl
860 * 2: bank: bit to the left of the bank bits selects the memctl
861 * 3: superbank: bit to the left of the chip select selects the memctl
863 * NOTE: ba_intlv (rank interleaving) is independent of memory
864 * controller interleaving; it is only within a memory controller.
865 * Must use superbank interleaving if rank interleaving is used and
866 * memory controller interleaving is enabled.
873 * 0x60 = CS0,CS1 + CS2,CS3
874 * 0x04 = CS0,CS1,CS2,CS3
876 popts
->ba_intlv_ctl
= 0;
878 /* Memory Organization Parameters */
879 popts
->registered_dimm_en
= common_dimm
->all_dimms_registered
;
881 /* Operational Mode Paramters */
884 popts
->ecc_mode
= 0; /* 0 = disabled, 1 = enabled */
885 #ifdef CONFIG_DDR_ECC
886 if (hwconfig_sub_f("fsl_ddr", "ecc", buf
)) {
887 if (hwconfig_subarg_cmp_f("fsl_ddr", "ecc", "on", buf
))
892 /* 1 = use memory controler to init data */
893 popts
->ecc_init_using_memctl
= popts
->ecc_mode
? 1 : 0;
900 #if defined(CONFIG_SYS_FSL_DDR1)
901 popts
->dqs_config
= 0;
902 #elif defined(CONFIG_SYS_FSL_DDR2) || defined(CONFIG_SYS_FSL_DDR3)
903 popts
->dqs_config
= 1;
906 /* Choose self-refresh during sleep. */
907 popts
->self_refresh_in_sleep
= 1;
909 /* Choose dynamic power management mode. */
910 popts
->dynamic_power
= 0;
913 * check first dimm for primary sdram width
914 * presuming all dimms are similar
915 * 0 = 64-bit, 1 = 32-bit, 2 = 16-bit
917 #if defined(CONFIG_SYS_FSL_DDR1) || defined(CONFIG_SYS_FSL_DDR2)
918 if (pdimm
[0].n_ranks
!= 0) {
919 if ((pdimm
[0].data_width
>= 64) && \
920 (pdimm
[0].data_width
<= 72))
921 popts
->data_bus_width
= 0;
922 else if ((pdimm
[0].data_width
>= 32) && \
923 (pdimm
[0].data_width
<= 40))
924 popts
->data_bus_width
= 1;
926 panic("Error: data width %u is invalid!\n",
927 pdimm
[0].data_width
);
931 if (pdimm
[0].n_ranks
!= 0) {
932 if (pdimm
[0].primary_sdram_width
== 64)
933 popts
->data_bus_width
= 0;
934 else if (pdimm
[0].primary_sdram_width
== 32)
935 popts
->data_bus_width
= 1;
936 else if (pdimm
[0].primary_sdram_width
== 16)
937 popts
->data_bus_width
= 2;
939 panic("Error: primary sdram width %u is invalid!\n",
940 pdimm
[0].primary_sdram_width
);
945 popts
->x4_en
= (pdimm
[0].device_width
== 4) ? 1 : 0;
947 /* Choose burst length. */
948 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
949 #if defined(CONFIG_E500MC)
950 popts
->otf_burst_chop_en
= 0; /* on-the-fly burst chop disable */
951 popts
->burst_length
= DDR_BL8
; /* Fixed 8-beat burst len */
953 if ((popts
->data_bus_width
== 1) || (popts
->data_bus_width
== 2)) {
954 /* 32-bit or 16-bit bus */
955 popts
->otf_burst_chop_en
= 0;
956 popts
->burst_length
= DDR_BL8
;
958 popts
->otf_burst_chop_en
= 1; /* on-the-fly burst chop */
959 popts
->burst_length
= DDR_OTF
; /* on-the-fly BC4 and BL8 */
963 popts
->burst_length
= DDR_BL4
; /* has to be 4 for DDR2 */
966 /* Choose ddr controller address mirror mode */
967 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
968 for (i
= 0; i
< CONFIG_DIMM_SLOTS_PER_CTLR
; i
++) {
969 if (pdimm
[i
].n_ranks
) {
970 popts
->mirrored_dimm
= pdimm
[i
].mirrored_dimm
;
976 /* Global Timing Parameters. */
977 debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num
));
979 /* Pick a caslat override. */
980 popts
->cas_latency_override
= 0;
981 popts
->cas_latency_override_value
= 3;
982 if (popts
->cas_latency_override
) {
983 debug("using caslat override value = %u\n",
984 popts
->cas_latency_override_value
);
987 /* Decide whether to use the computed derated latency */
988 popts
->use_derated_caslat
= 0;
990 /* Choose an additive latency. */
991 popts
->additive_latency_override
= 0;
992 popts
->additive_latency_override_value
= 3;
993 if (popts
->additive_latency_override
) {
994 debug("using additive latency override value = %u\n",
995 popts
->additive_latency_override_value
);
1001 * Factors to consider for 2T_EN:
1002 * - number of DIMMs installed
1003 * - number of components, number of active ranks
1004 * - how much time you want to spend playing around
1007 popts
->threet_en
= 0;
1009 /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
1010 if (popts
->registered_dimm_en
)
1011 popts
->ap_en
= 1; /* 0 = disable, 1 = enable */
1013 popts
->ap_en
= 0; /* disabled for DDR4 UDIMM/discrete default */
1015 if (hwconfig_sub_f("fsl_ddr", "parity", buf
)) {
1016 if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf
)) {
1017 if (popts
->registered_dimm_en
||
1018 (CONFIG_FSL_SDRAM_TYPE
== SDRAM_TYPE_DDR4
))
1024 * BSTTOPRE precharge interval
1026 * Set this to 0 for global auto precharge
1027 * The value of 0x100 has been used for DDR1, DDR2, DDR3.
1028 * It is not wrong. Any value should be OK. The performance depends on
1029 * applications. There is no one good value for all. One way to set
1030 * is to use 1/4 of refint value.
1032 popts
->bstopre
= picos_to_mclk(ctrl_num
, common_dimm
->refresh_rate_ps
)
1036 * Window for four activates -- tFAW
1038 * FIXME: UM: applies only to DDR2/DDR3 with eight logical banks only
1039 * FIXME: varies depending upon number of column addresses or data
1040 * FIXME: width, was considering looking at pdimm->primary_sdram_width
1042 #if defined(CONFIG_SYS_FSL_DDR1)
1043 popts
->tfaw_window_four_activates_ps
= mclk_to_picos(ctrl_num
, 1);
1045 #elif defined(CONFIG_SYS_FSL_DDR2)
1047 * x4/x8; some datasheets have 35000
1048 * x16 wide columns only? Use 50000?
1050 popts
->tfaw_window_four_activates_ps
= 37500;
1053 popts
->tfaw_window_four_activates_ps
= pdimm
[0].tfaw_ps
;
1056 popts
->wrlvl_en
= 0;
1057 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
1059 * due to ddr3 dimm is fly-by topology
1060 * we suggest to enable write leveling to
1061 * meet the tQDSS under different loading.
1063 popts
->wrlvl_en
= 1;
1065 popts
->wrlvl_override
= 0;
1069 * Check interleaving configuration from environment.
1070 * Please refer to doc/README.fsl-ddr for the detail.
1072 * If memory controller interleaving is enabled, then the data
1073 * bus widths must be programmed identically for all memory controllers.
1075 * Attempt to set all controllers to the same chip select
1076 * interleaving mode. It will do a best effort to get the
1077 * requested ranks interleaved together such that the result
1078 * should be a subset of the requested configuration.
1080 * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
1081 * with 256 Byte is enabled.
1083 #if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
1084 if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf
))
1085 #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1090 if (pdimm
[0].n_ranks
== 0) {
1091 printf("There is no rank on CS0 for controller %d.\n", ctrl_num
);
1092 popts
->memctl_interleaving
= 0;
1095 popts
->memctl_interleaving
= 1;
1096 #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
1097 popts
->memctl_interleaving_mode
= FSL_DDR_256B_INTERLEAVING
;
1098 popts
->memctl_interleaving
= 1;
1099 debug("256 Byte interleaving\n");
1102 * test null first. if CONFIG_HWCONFIG is not defined
1103 * hwconfig_arg_cmp returns non-zero
1105 if (hwconfig_subarg_cmp_f("fsl_ddr", "ctlr_intlv",
1107 popts
->memctl_interleaving
= 0;
1108 debug("memory controller interleaving disabled.\n");
1109 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1111 "cacheline", buf
)) {
1112 popts
->memctl_interleaving_mode
=
1113 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1114 0 : FSL_DDR_CACHE_LINE_INTERLEAVING
;
1115 popts
->memctl_interleaving
=
1116 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1118 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1121 popts
->memctl_interleaving_mode
=
1122 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1123 0 : FSL_DDR_PAGE_INTERLEAVING
;
1124 popts
->memctl_interleaving
=
1125 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1127 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1130 popts
->memctl_interleaving_mode
=
1131 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1132 0 : FSL_DDR_BANK_INTERLEAVING
;
1133 popts
->memctl_interleaving
=
1134 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1136 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1138 "superbank", buf
)) {
1139 popts
->memctl_interleaving_mode
=
1140 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1141 0 : FSL_DDR_SUPERBANK_INTERLEAVING
;
1142 popts
->memctl_interleaving
=
1143 ((CONFIG_SYS_NUM_DDR_CTLRS
== 3) && ctrl_num
== 2) ?
1145 #if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
1146 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1149 popts
->memctl_interleaving_mode
=
1150 FSL_DDR_3WAY_1KB_INTERLEAVING
;
1151 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1154 popts
->memctl_interleaving_mode
=
1155 FSL_DDR_3WAY_4KB_INTERLEAVING
;
1156 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1159 popts
->memctl_interleaving_mode
=
1160 FSL_DDR_3WAY_8KB_INTERLEAVING
;
1161 #elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
1162 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1165 popts
->memctl_interleaving_mode
=
1166 FSL_DDR_4WAY_1KB_INTERLEAVING
;
1167 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1170 popts
->memctl_interleaving_mode
=
1171 FSL_DDR_4WAY_4KB_INTERLEAVING
;
1172 } else if (hwconfig_subarg_cmp_f("fsl_ddr",
1175 popts
->memctl_interleaving_mode
=
1176 FSL_DDR_4WAY_8KB_INTERLEAVING
;
1179 popts
->memctl_interleaving
= 0;
1180 printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
1182 #endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
1184 #endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
1185 if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf
)) &&
1186 (CONFIG_CHIP_SELECTS_PER_CTRL
> 1)) {
1187 /* test null first. if CONFIG_HWCONFIG is not defined,
1188 * hwconfig_subarg_cmp_f returns non-zero */
1189 if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1191 debug("bank interleaving disabled.\n");
1192 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1194 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1
;
1195 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1197 popts
->ba_intlv_ctl
= FSL_DDR_CS2_CS3
;
1198 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1199 "cs0_cs1_and_cs2_cs3", buf
))
1200 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1_AND_CS2_CS3
;
1201 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1202 "cs0_cs1_cs2_cs3", buf
))
1203 popts
->ba_intlv_ctl
= FSL_DDR_CS0_CS1_CS2_CS3
;
1204 else if (hwconfig_subarg_cmp_f("fsl_ddr", "bank_intlv",
1206 popts
->ba_intlv_ctl
= auto_bank_intlv(pdimm
);
1208 printf("hwconfig has unrecognized parameter for bank_intlv.\n");
1209 switch (popts
->ba_intlv_ctl
& FSL_DDR_CS0_CS1_CS2_CS3
) {
1210 case FSL_DDR_CS0_CS1_CS2_CS3
:
1211 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1212 if (pdimm
[0].n_ranks
< 4) {
1213 popts
->ba_intlv_ctl
= 0;
1214 printf("Not enough bank(chip-select) for "
1215 "CS0+CS1+CS2+CS3 on controller %d, "
1216 "interleaving disabled!\n", ctrl_num
);
1218 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1219 #ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
1220 if (pdimm
[0].n_ranks
== 4)
1223 if ((pdimm
[0].n_ranks
< 2) && (pdimm
[1].n_ranks
< 2)) {
1224 popts
->ba_intlv_ctl
= 0;
1225 printf("Not enough bank(chip-select) for "
1226 "CS0+CS1+CS2+CS3 on controller %d, "
1227 "interleaving disabled!\n", ctrl_num
);
1229 if (pdimm
[0].capacity
!= pdimm
[1].capacity
) {
1230 popts
->ba_intlv_ctl
= 0;
1231 printf("Not identical DIMM size for "
1232 "CS0+CS1+CS2+CS3 on controller %d, "
1233 "interleaving disabled!\n", ctrl_num
);
1237 case FSL_DDR_CS0_CS1
:
1238 if (pdimm
[0].n_ranks
< 2) {
1239 popts
->ba_intlv_ctl
= 0;
1240 printf("Not enough bank(chip-select) for "
1241 "CS0+CS1 on controller %d, "
1242 "interleaving disabled!\n", ctrl_num
);
1245 case FSL_DDR_CS2_CS3
:
1246 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1247 if (pdimm
[0].n_ranks
< 4) {
1248 popts
->ba_intlv_ctl
= 0;
1249 printf("Not enough bank(chip-select) for CS2+CS3 "
1250 "on controller %d, interleaving disabled!\n", ctrl_num
);
1252 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1253 if (pdimm
[1].n_ranks
< 2) {
1254 popts
->ba_intlv_ctl
= 0;
1255 printf("Not enough bank(chip-select) for CS2+CS3 "
1256 "on controller %d, interleaving disabled!\n", ctrl_num
);
1260 case FSL_DDR_CS0_CS1_AND_CS2_CS3
:
1261 #if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
1262 if (pdimm
[0].n_ranks
< 4) {
1263 popts
->ba_intlv_ctl
= 0;
1264 printf("Not enough bank(CS) for CS0+CS1 and "
1265 "CS2+CS3 on controller %d, "
1266 "interleaving disabled!\n", ctrl_num
);
1268 #elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
1269 if ((pdimm
[0].n_ranks
< 2) || (pdimm
[1].n_ranks
< 2)) {
1270 popts
->ba_intlv_ctl
= 0;
1271 printf("Not enough bank(CS) for CS0+CS1 and "
1272 "CS2+CS3 on controller %d, "
1273 "interleaving disabled!\n", ctrl_num
);
1278 popts
->ba_intlv_ctl
= 0;
1283 if (hwconfig_sub_f("fsl_ddr", "addr_hash", buf
)) {
1284 if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash", "null", buf
))
1285 popts
->addr_hash
= 0;
1286 else if (hwconfig_subarg_cmp_f("fsl_ddr", "addr_hash",
1288 popts
->addr_hash
= 1;
1291 if (pdimm
[0].n_ranks
== 4)
1292 popts
->quad_rank_present
= 1;
1294 ddr_freq
= get_ddr_freq(ctrl_num
) / 1000000;
1295 if (popts
->registered_dimm_en
) {
1296 popts
->rcw_override
= 1;
1297 popts
->rcw_1
= 0x000a5a00;
1298 if (ddr_freq
<= 800)
1299 popts
->rcw_2
= 0x00000000;
1300 else if (ddr_freq
<= 1066)
1301 popts
->rcw_2
= 0x00100000;
1302 else if (ddr_freq
<= 1333)
1303 popts
->rcw_2
= 0x00200000;
1305 popts
->rcw_2
= 0x00300000;
1308 fsl_ddr_board_options(popts
, pdimm
, ctrl_num
);
1313 void check_interleaving_options(fsl_ddr_info_t
*pinfo
)
1315 int i
, j
, k
, check_n_ranks
, intlv_invalid
= 0;
1316 unsigned int check_intlv
, check_n_row_addr
, check_n_col_addr
;
1317 unsigned long long check_rank_density
;
1318 struct dimm_params_s
*dimm
;
1319 int first_ctrl
= pinfo
->first_ctrl
;
1320 int last_ctrl
= first_ctrl
+ pinfo
->num_ctrls
- 1;
1323 * Check if all controllers are configured for memory
1324 * controller interleaving. Identical dimms are recommended. At least
1325 * the size, row and col address should be checked.
1328 check_n_ranks
= pinfo
->dimm_params
[first_ctrl
][0].n_ranks
;
1329 check_rank_density
= pinfo
->dimm_params
[first_ctrl
][0].rank_density
;
1330 check_n_row_addr
= pinfo
->dimm_params
[first_ctrl
][0].n_row_addr
;
1331 check_n_col_addr
= pinfo
->dimm_params
[first_ctrl
][0].n_col_addr
;
1332 check_intlv
= pinfo
->memctl_opts
[first_ctrl
].memctl_interleaving_mode
;
1333 for (i
= first_ctrl
; i
<= last_ctrl
; i
++) {
1334 dimm
= &pinfo
->dimm_params
[i
][0];
1335 if (!pinfo
->memctl_opts
[i
].memctl_interleaving
) {
1337 } else if (((check_rank_density
!= dimm
->rank_density
) ||
1338 (check_n_ranks
!= dimm
->n_ranks
) ||
1339 (check_n_row_addr
!= dimm
->n_row_addr
) ||
1340 (check_n_col_addr
!= dimm
->n_col_addr
) ||
1342 pinfo
->memctl_opts
[i
].memctl_interleaving_mode
))){
1350 if (intlv_invalid
) {
1351 for (i
= first_ctrl
; i
<= last_ctrl
; i
++)
1352 pinfo
->memctl_opts
[i
].memctl_interleaving
= 0;
1353 printf("Not all DIMMs are identical. "
1354 "Memory controller interleaving disabled.\n");
1356 switch (check_intlv
) {
1357 case FSL_DDR_256B_INTERLEAVING
:
1358 case FSL_DDR_CACHE_LINE_INTERLEAVING
:
1359 case FSL_DDR_PAGE_INTERLEAVING
:
1360 case FSL_DDR_BANK_INTERLEAVING
:
1361 case FSL_DDR_SUPERBANK_INTERLEAVING
:
1362 #if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
1365 k
= CONFIG_SYS_NUM_DDR_CTLRS
;
1368 case FSL_DDR_3WAY_1KB_INTERLEAVING
:
1369 case FSL_DDR_3WAY_4KB_INTERLEAVING
:
1370 case FSL_DDR_3WAY_8KB_INTERLEAVING
:
1371 case FSL_DDR_4WAY_1KB_INTERLEAVING
:
1372 case FSL_DDR_4WAY_4KB_INTERLEAVING
:
1373 case FSL_DDR_4WAY_8KB_INTERLEAVING
:
1375 k
= CONFIG_SYS_NUM_DDR_CTLRS
;
1378 debug("%d of %d controllers are interleaving.\n", j
, k
);
1379 if (j
&& (j
!= k
)) {
1380 for (i
= first_ctrl
; i
<= last_ctrl
; i
++)
1381 pinfo
->memctl_opts
[i
].memctl_interleaving
= 0;
1382 if ((last_ctrl
- first_ctrl
) > 1)
1383 puts("Not all controllers have compatible interleaving mode. All disabled.\n");
1386 debug("Checking interleaving options completed\n");
1389 int fsl_use_spd(void)
1393 #ifdef CONFIG_DDR_SPD
1394 char buffer
[HWCONFIG_BUFFER_SIZE
];
1398 * Extract hwconfig from environment since we have not properly setup
1399 * the environment but need it for ddr config params
1401 if (getenv_f("hwconfig", buffer
, sizeof(buffer
)) > 0)
1404 /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
1405 if (hwconfig_sub_f("fsl_ddr", "sdram", buf
)) {
1406 if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram", "spd", buf
))
1408 else if (hwconfig_subarg_cmp_f("fsl_ddr", "sdram",