]> git.sur5r.net Git - u-boot/blobdiff - drivers/ddr/fsl/options.c
drivers: ddr: fsl: fix unused-const-variable warnings
[u-boot] / drivers / ddr / fsl / options.c
index bf0d1da7cfa44688b362b1fbf9c117c710d24aaa..1b81a7a2500f74957ab4ecb0315803857bb957ba 100644 (file)
@@ -29,8 +29,241 @@ struct dynamic_odt {
        unsigned int odt_rtt_wr;
 };
 
-#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
-static const struct dynamic_odt single_Q[4] = {
+#ifdef CONFIG_SYS_FSL_DDR4
+/* Quad rank is not verified yet due availability.
+ * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
+ */
+static __maybe_unused const struct dynamic_odt single_Q[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS_AND_OTHER_DIMM,
+               DDR4_RTT_34_OHM,        /* unverified */
+               DDR4_RTT_120_OHM
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_NEVER,
+               DDR4_RTT_OFF,
+               DDR4_RTT_120_OHM
+       },
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS_AND_OTHER_DIMM,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_120_OHM
+       },
+       {       /* cs3 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_NEVER,      /* tied high */
+               DDR4_RTT_OFF,
+               DDR4_RTT_120_OHM
+       }
+};
+
+static __maybe_unused const struct dynamic_odt single_D[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_NEVER,
+               DDR4_RTT_OFF,
+               DDR4_RTT_OFF
+       },
+       {0, 0, 0, 0},
+       {0, 0, 0, 0}
+};
+
+static __maybe_unused const struct dynamic_odt single_S[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {0, 0, 0, 0},
+       {0, 0, 0, 0},
+       {0, 0, 0, 0},
+};
+
+static __maybe_unused const struct dynamic_odt dual_DD[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_OTHER_DIMM,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs3 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_OTHER_DIMM,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_OFF
+       }
+};
+
+static __maybe_unused const struct dynamic_odt dual_DS[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_OTHER_DIMM,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs2 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_120_OHM
+       },
+       {0, 0, 0, 0}
+};
+static __maybe_unused const struct dynamic_odt dual_SD[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_120_OHM
+       },
+       {0, 0, 0, 0},
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs3 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_OTHER_DIMM,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_OFF
+       }
+};
+
+static __maybe_unused const struct dynamic_odt dual_SS[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_120_OHM
+       },
+       {0, 0, 0, 0},
+       {       /* cs2 */
+               FSL_DDR_ODT_OTHER_DIMM,
+               FSL_DDR_ODT_ALL,
+               DDR4_RTT_34_OHM,
+               DDR4_RTT_120_OHM
+       },
+       {0, 0, 0, 0}
+};
+
+static __maybe_unused const struct dynamic_odt dual_D0[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_NEVER,
+               DDR4_RTT_OFF,
+               DDR4_RTT_OFF
+       },
+       {0, 0, 0, 0},
+       {0, 0, 0, 0}
+};
+
+static __maybe_unused const struct dynamic_odt dual_0D[4] = {
+       {0, 0, 0, 0},
+       {0, 0, 0, 0},
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_SAME_DIMM,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs3 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_NEVER,
+               DDR4_RTT_OFF,
+               DDR4_RTT_OFF
+       }
+};
+
+static __maybe_unused const struct dynamic_odt dual_S0[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {0, 0, 0, 0},
+       {0, 0, 0, 0},
+       {0, 0, 0, 0}
+
+};
+
+static __maybe_unused const struct dynamic_odt dual_0S[4] = {
+       {0, 0, 0, 0},
+       {0, 0, 0, 0},
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_40_OHM,
+               DDR4_RTT_OFF
+       },
+       {0, 0, 0, 0}
+
+};
+
+static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
+       {       /* cs0 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs1 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs2 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       },
+       {       /* cs3 */
+               FSL_DDR_ODT_NEVER,
+               FSL_DDR_ODT_CS,
+               DDR4_RTT_120_OHM,
+               DDR4_RTT_OFF
+       }
+};
+#elif defined(CONFIG_SYS_FSL_DDR3)
+static __maybe_unused const struct dynamic_odt single_Q[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS_AND_OTHER_DIMM,
@@ -57,7 +290,7 @@ static const struct dynamic_odt single_Q[4] = {
        }
 };
 
-static const struct dynamic_odt single_D[4] = {
+static __maybe_unused const struct dynamic_odt single_D[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_ALL,
@@ -74,7 +307,7 @@ static const struct dynamic_odt single_D[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt single_S[4] = {
+static __maybe_unused const struct dynamic_odt single_S[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_ALL,
@@ -86,7 +319,7 @@ static const struct dynamic_odt single_S[4] = {
        {0, 0, 0, 0},
 };
 
-static const struct dynamic_odt dual_DD[4] = {
+static __maybe_unused const struct dynamic_odt dual_DD[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_SAME_DIMM,
@@ -113,7 +346,7 @@ static const struct dynamic_odt dual_DD[4] = {
        }
 };
 
-static const struct dynamic_odt dual_DS[4] = {
+static __maybe_unused const struct dynamic_odt dual_DS[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_SAME_DIMM,
@@ -134,7 +367,7 @@ static const struct dynamic_odt dual_DS[4] = {
        },
        {0, 0, 0, 0}
 };
-static const struct dynamic_odt dual_SD[4] = {
+static __maybe_unused const struct dynamic_odt dual_SD[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_ALL,
@@ -156,7 +389,7 @@ static const struct dynamic_odt dual_SD[4] = {
        }
 };
 
-static const struct dynamic_odt dual_SS[4] = {
+static __maybe_unused const struct dynamic_odt dual_SS[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_ALL,
@@ -173,7 +406,7 @@ static const struct dynamic_odt dual_SS[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt dual_D0[4] = {
+static __maybe_unused const struct dynamic_odt dual_D0[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_SAME_DIMM,
@@ -190,7 +423,7 @@ static const struct dynamic_odt dual_D0[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt dual_0D[4] = {
+static __maybe_unused const struct dynamic_odt dual_0D[4] = {
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {       /* cs2 */
@@ -207,7 +440,7 @@ static const struct dynamic_odt dual_0D[4] = {
        }
 };
 
-static const struct dynamic_odt dual_S0[4] = {
+static __maybe_unused const struct dynamic_odt dual_S0[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS,
@@ -220,7 +453,7 @@ static const struct dynamic_odt dual_S0[4] = {
 
 };
 
-static const struct dynamic_odt dual_0S[4] = {
+static __maybe_unused const struct dynamic_odt dual_0S[4] = {
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {       /* cs2 */
@@ -233,7 +466,7 @@ static const struct dynamic_odt dual_0S[4] = {
 
 };
 
-static const struct dynamic_odt odt_unknown[4] = {
+static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS,
@@ -259,15 +492,15 @@ static const struct dynamic_odt odt_unknown[4] = {
                DDR3_RTT_OFF
        }
 };
-#else  /* CONFIG_SYS_FSL_DDR3 || CONFIG_SYS_FSL_DDR4 */
-static const struct dynamic_odt single_Q[4] = {
+#else  /* CONFIG_SYS_FSL_DDR3 */
+static __maybe_unused const struct dynamic_odt single_Q[4] = {
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt single_D[4] = {
+static __maybe_unused const struct dynamic_odt single_D[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_ALL,
@@ -284,7 +517,7 @@ static const struct dynamic_odt single_D[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt single_S[4] = {
+static __maybe_unused const struct dynamic_odt single_S[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_ALL,
@@ -296,7 +529,7 @@ static const struct dynamic_odt single_S[4] = {
        {0, 0, 0, 0},
 };
 
-static const struct dynamic_odt dual_DD[4] = {
+static __maybe_unused const struct dynamic_odt dual_DD[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_OTHER_DIMM,
@@ -323,7 +556,7 @@ static const struct dynamic_odt dual_DD[4] = {
        }
 };
 
-static const struct dynamic_odt dual_DS[4] = {
+static __maybe_unused const struct dynamic_odt dual_DS[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_OTHER_DIMM,
@@ -345,7 +578,7 @@ static const struct dynamic_odt dual_DS[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt dual_SD[4] = {
+static __maybe_unused const struct dynamic_odt dual_SD[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_OTHER_DIMM,
@@ -367,7 +600,7 @@ static const struct dynamic_odt dual_SD[4] = {
        }
 };
 
-static const struct dynamic_odt dual_SS[4] = {
+static __maybe_unused const struct dynamic_odt dual_SS[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_OTHER_DIMM,
                FSL_DDR_ODT_OTHER_DIMM,
@@ -384,7 +617,7 @@ static const struct dynamic_odt dual_SS[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt dual_D0[4] = {
+static __maybe_unused const struct dynamic_odt dual_D0[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_ALL,
@@ -401,7 +634,7 @@ static const struct dynamic_odt dual_D0[4] = {
        {0, 0, 0, 0}
 };
 
-static const struct dynamic_odt dual_0D[4] = {
+static __maybe_unused const struct dynamic_odt dual_0D[4] = {
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {       /* cs2 */
@@ -418,7 +651,7 @@ static const struct dynamic_odt dual_0D[4] = {
        }
 };
 
-static const struct dynamic_odt dual_S0[4] = {
+static __maybe_unused const struct dynamic_odt dual_S0[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS,
@@ -431,7 +664,7 @@ static const struct dynamic_odt dual_S0[4] = {
 
 };
 
-static const struct dynamic_odt dual_0S[4] = {
+static __maybe_unused const struct dynamic_odt dual_0S[4] = {
        {0, 0, 0, 0},
        {0, 0, 0, 0},
        {       /* cs2 */
@@ -444,7 +677,7 @@ static const struct dynamic_odt dual_0S[4] = {
 
 };
 
-static const struct dynamic_odt odt_unknown[4] = {
+static __maybe_unused const struct dynamic_odt odt_unknown[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS,
@@ -499,7 +732,7 @@ static inline unsigned int auto_bank_intlv(dimm_params_t *pdimm)
        return 0;
 }
 
-unsigned int populate_memctl_options(int all_dimms_registered,
+unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
                        memctl_options_t *popts,
                        dimm_params_t *pdimm,
                        unsigned int ctrl_num)
@@ -525,67 +758,66 @@ unsigned int populate_memctl_options(int all_dimms_registered,
        defined(CONFIG_SYS_FSL_DDR2) || \
        defined(CONFIG_SYS_FSL_DDR4)
        /* Chip select options. */
-       if (CONFIG_DIMM_SLOTS_PER_CTLR == 1) {
-               switch (pdimm[0].n_ranks) {
-               case 1:
-                       pdodt = single_S;
-                       break;
+#if (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
+       switch (pdimm[0].n_ranks) {
+       case 1:
+               pdodt = single_S;
+               break;
+       case 2:
+               pdodt = single_D;
+               break;
+       case 4:
+               pdodt = single_Q;
+               break;
+       }
+#elif (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
+       switch (pdimm[0].n_ranks) {
+#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
+       case 4:
+               pdodt = single_Q;
+               if (pdimm[1].n_ranks)
+                       printf("Error: Quad- and Dual-rank DIMMs cannot be used together\n");
+               break;
+#endif
+       case 2:
+               switch (pdimm[1].n_ranks) {
                case 2:
-                       pdodt = single_D;
+                       pdodt = dual_DD;
                        break;
-               case 4:
-                       pdodt = single_Q;
+               case 1:
+                       pdodt = dual_DS;
                        break;
-               }
-       } else if (CONFIG_DIMM_SLOTS_PER_CTLR == 2) {
-               switch (pdimm[0].n_ranks) {
-#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
-               case 4:
-                       pdodt = single_Q;
-                       if (pdimm[1].n_ranks)
-                               printf("Error: Quad- and Dual-rank DIMMs "
-                                       "cannot be used together\n");
+               case 0:
+                       pdodt = dual_D0;
                        break;
-#endif
+               }
+               break;
+       case 1:
+               switch (pdimm[1].n_ranks) {
                case 2:
-                       switch (pdimm[1].n_ranks) {
-                       case 2:
-                               pdodt = dual_DD;
-                               break;
-                       case 1:
-                               pdodt = dual_DS;
-                               break;
-                       case 0:
-                               pdodt = dual_D0;
-                               break;
-                       }
+                       pdodt = dual_SD;
                        break;
                case 1:
-                       switch (pdimm[1].n_ranks) {
-                       case 2:
-                               pdodt = dual_SD;
-                               break;
-                       case 1:
-                               pdodt = dual_SS;
-                               break;
-                       case 0:
-                               pdodt = dual_S0;
-                               break;
-                       }
+                       pdodt = dual_SS;
                        break;
                case 0:
-                       switch (pdimm[1].n_ranks) {
-                       case 2:
-                               pdodt = dual_0D;
-                               break;
-                       case 1:
-                               pdodt = dual_0S;
-                               break;
-                       }
+                       pdodt = dual_S0;
                        break;
                }
+               break;
+       case 0:
+               switch (pdimm[1].n_ranks) {
+               case 2:
+                       pdodt = dual_0D;
+                       break;
+               case 1:
+                       pdodt = dual_0S;
+                       break;
+               }
+               break;
        }
-#endif
+#endif /* CONFIG_DIMM_SLOTS_PER_CTLR */
+#endif /* CONFIG_SYS_FSL_DDR2, 3, 4 */
 
        /* Pick chip-select local options. */
        for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
@@ -641,7 +873,7 @@ unsigned int populate_memctl_options(int all_dimms_registered,
        popts->ba_intlv_ctl = 0;
 
        /* Memory Organization Parameters */
-       popts->registered_dimm_en = all_dimms_registered;
+       popts->registered_dimm_en = common_dimm->all_dimms_registered;
 
        /* Operational Mode Paramters */
 
@@ -654,7 +886,8 @@ unsigned int populate_memctl_options(int all_dimms_registered,
        } else
                popts->ecc_mode = 1;
 #endif
-       popts->ecc_init_using_memctl = 1; /* 0 = use DMA, 1 = use memctl */
+       /* 1 = use memory controler to init data */
+       popts->ecc_init_using_memctl = popts->ecc_mode ? 1 : 0;
 
        /*
         * Choose DQS config
@@ -729,11 +962,16 @@ unsigned int populate_memctl_options(int all_dimms_registered,
 
        /* Choose ddr controller address mirror mode */
 #if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
-       popts->mirrored_dimm = pdimm[0].mirrored_dimm;
+       for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
+               if (pdimm[i].n_ranks) {
+                       popts->mirrored_dimm = pdimm[i].mirrored_dimm;
+                       break;
+               }
+       }
 #endif
 
        /* Global Timing Parameters. */
-       debug("mclk_ps = %u ps\n", get_memory_clk_period_ps());
+       debug("mclk_ps = %u ps\n", get_memory_clk_period_ps(ctrl_num));
 
        /* Pick a caslat override. */
        popts->cas_latency_override = 0;
@@ -765,8 +1003,19 @@ unsigned int populate_memctl_options(int all_dimms_registered,
        popts->twot_en = 0;
        popts->threet_en = 0;
 
-       /* for RDIMM, address parity enable */
-       popts->ap_en = 1;
+       /* for RDIMM and DDR4 UDIMM/discrete memory, address parity enable */
+       if (popts->registered_dimm_en)
+               popts->ap_en = 1; /* 0 = disable,  1 = enable */
+       else
+               popts->ap_en = 0; /* disabled for DDR4 UDIMM/discrete default */
+
+       if (hwconfig_sub_f("fsl_ddr", "parity", buf)) {
+               if (hwconfig_subarg_cmp_f("fsl_ddr", "parity", "on", buf)) {
+                       if (popts->registered_dimm_en ||
+                           (CONFIG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4))
+                               popts->ap_en = 1;
+               }
+       }
 
        /*
         * BSTTOPRE precharge interval
@@ -774,13 +1023,11 @@ unsigned int populate_memctl_options(int all_dimms_registered,
         * Set this to 0 for global auto precharge
         * The value of 0x100 has been used for DDR1, DDR2, DDR3.
         * It is not wrong. Any value should be OK. The performance depends on
-        * applications. There is no one good value for all.
+        * applications. There is no one good value for all. One way to set
+        * is to use 1/4 of refint value.
         */
-       popts->bstopre = 0x100;
-
-       /* Minimum CKE pulse width -- tCKE(MIN) */
-       popts->tcke_clock_pulse_width_ps
-               = mclk_to_picos(FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR);
+       popts->bstopre = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps)
+                        >> 2;
 
        /*
         * Window for four activates -- tFAW
@@ -790,7 +1037,7 @@ unsigned int populate_memctl_options(int all_dimms_registered,
         * FIXME: width, was considering looking at pdimm->primary_sdram_width
         */
 #if defined(CONFIG_SYS_FSL_DDR1)
-       popts->tfaw_window_four_activates_ps = mclk_to_picos(1);
+       popts->tfaw_window_four_activates_ps = mclk_to_picos(ctrl_num, 1);
 
 #elif defined(CONFIG_SYS_FSL_DDR2)
        /*
@@ -830,7 +1077,7 @@ unsigned int populate_memctl_options(int all_dimms_registered,
         * if CONFIG_SYS_FSL_DDR_INTLV_256B is defined, mandatory interleaving
         * with 256 Byte is enabled.
         */
-#if (CONFIG_NUM_DDR_CONTROLLERS > 1)
+#if (CONFIG_SYS_NUM_DDR_CTLRS > 1)
        if (!hwconfig_sub_f("fsl_ddr", "ctlr_intlv", buf))
 #ifdef CONFIG_SYS_FSL_DDR_INTLV_256B
                ;
@@ -847,8 +1094,7 @@ unsigned int populate_memctl_options(int all_dimms_registered,
        popts->memctl_interleaving_mode = FSL_DDR_256B_INTERLEAVING;
        popts->memctl_interleaving = 1;
        debug("256 Byte interleaving\n");
-       goto done;
-#endif
+#else
        /*
         * test null first. if CONFIG_HWCONFIG is not defined
         * hwconfig_arg_cmp returns non-zero
@@ -861,39 +1107,39 @@ unsigned int populate_memctl_options(int all_dimms_registered,
                                        "ctlr_intlv",
                                        "cacheline", buf)) {
                popts->memctl_interleaving_mode =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : FSL_DDR_CACHE_LINE_INTERLEAVING;
                popts->memctl_interleaving =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : 1;
        } else if (hwconfig_subarg_cmp_f("fsl_ddr",
                                        "ctlr_intlv",
                                        "page", buf)) {
                popts->memctl_interleaving_mode =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : FSL_DDR_PAGE_INTERLEAVING;
                popts->memctl_interleaving =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : 1;
        } else if (hwconfig_subarg_cmp_f("fsl_ddr",
                                        "ctlr_intlv",
                                        "bank", buf)) {
                popts->memctl_interleaving_mode =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : FSL_DDR_BANK_INTERLEAVING;
                popts->memctl_interleaving =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : 1;
        } else if (hwconfig_subarg_cmp_f("fsl_ddr",
                                        "ctlr_intlv",
                                        "superbank", buf)) {
                popts->memctl_interleaving_mode =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : FSL_DDR_SUPERBANK_INTERLEAVING;
                popts->memctl_interleaving =
-                       ((CONFIG_NUM_DDR_CONTROLLERS == 3) && ctrl_num == 2) ?
+                       ((CONFIG_SYS_NUM_DDR_CTLRS == 3) && ctrl_num == 2) ?
                        0 : 1;
-#if (CONFIG_NUM_DDR_CONTROLLERS == 3)
+#if (CONFIG_SYS_NUM_DDR_CTLRS == 3)
        } else if (hwconfig_subarg_cmp_f("fsl_ddr",
                                        "ctlr_intlv",
                                        "3way_1KB", buf)) {
@@ -909,7 +1155,7 @@ unsigned int populate_memctl_options(int all_dimms_registered,
                                        "3way_8KB", buf)) {
                popts->memctl_interleaving_mode =
                        FSL_DDR_3WAY_8KB_INTERLEAVING;
-#elif (CONFIG_NUM_DDR_CONTROLLERS == 4)
+#elif (CONFIG_SYS_NUM_DDR_CTLRS == 4)
        } else if (hwconfig_subarg_cmp_f("fsl_ddr",
                                        "ctlr_intlv",
                                        "4way_1KB", buf)) {
@@ -930,8 +1176,9 @@ unsigned int populate_memctl_options(int all_dimms_registered,
                popts->memctl_interleaving = 0;
                printf("hwconfig has unrecognized parameter for ctlr_intlv.\n");
        }
+#endif /* CONFIG_SYS_FSL_DDR_INTLV_256B */
 done:
-#endif
+#endif /* CONFIG_SYS_NUM_DDR_CTLRS > 1 */
        if ((hwconfig_sub_f("fsl_ddr", "bank_intlv", buf)) &&
                (CONFIG_CHIP_SELECTS_PER_CTRL > 1)) {
                /* test null first. if CONFIG_HWCONFIG is not defined,
@@ -1041,7 +1288,7 @@ done:
        if (pdimm[0].n_ranks == 4)
                popts->quad_rank_present = 1;
 
-       ddr_freq = get_ddr_freq(0) / 1000000;
+       ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
        if (popts->registered_dimm_en) {
                popts->rcw_override = 1;
                popts->rcw_1 = 0x000a5a00;
@@ -1066,18 +1313,21 @@ void check_interleaving_options(fsl_ddr_info_t *pinfo)
        unsigned int check_intlv, check_n_row_addr, check_n_col_addr;
        unsigned long long check_rank_density;
        struct dimm_params_s *dimm;
+       int first_ctrl = pinfo->first_ctrl;
+       int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
+
        /*
         * Check if all controllers are configured for memory
         * controller interleaving. Identical dimms are recommended. At least
         * the size, row and col address should be checked.
         */
        j = 0;
-       check_n_ranks = pinfo->dimm_params[0][0].n_ranks;
-       check_rank_density = pinfo->dimm_params[0][0].rank_density;
-       check_n_row_addr =  pinfo->dimm_params[0][0].n_row_addr;
-       check_n_col_addr = pinfo->dimm_params[0][0].n_col_addr;
-       check_intlv = pinfo->memctl_opts[0].memctl_interleaving_mode;
-       for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++) {
+       check_n_ranks = pinfo->dimm_params[first_ctrl][0].n_ranks;
+       check_rank_density = pinfo->dimm_params[first_ctrl][0].rank_density;
+       check_n_row_addr =  pinfo->dimm_params[first_ctrl][0].n_row_addr;
+       check_n_col_addr = pinfo->dimm_params[first_ctrl][0].n_col_addr;
+       check_intlv = pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode;
+       for (i = first_ctrl; i <= last_ctrl; i++) {
                dimm = &pinfo->dimm_params[i][0];
                if (!pinfo->memctl_opts[i].memctl_interleaving) {
                        continue;
@@ -1095,7 +1345,7 @@ void check_interleaving_options(fsl_ddr_info_t *pinfo)
 
        }
        if (intlv_invalid) {
-               for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
+               for (i = first_ctrl; i <= last_ctrl; i++)
                        pinfo->memctl_opts[i].memctl_interleaving = 0;
                printf("Not all DIMMs are identical. "
                        "Memory controller interleaving disabled.\n");
@@ -1106,10 +1356,11 @@ void check_interleaving_options(fsl_ddr_info_t *pinfo)
                case FSL_DDR_PAGE_INTERLEAVING:
                case FSL_DDR_BANK_INTERLEAVING:
                case FSL_DDR_SUPERBANK_INTERLEAVING:
-                       if (3 == CONFIG_NUM_DDR_CONTROLLERS)
+#if (3 == CONFIG_SYS_NUM_DDR_CTLRS)
                                k = 2;
-                       else
-                               k = CONFIG_NUM_DDR_CONTROLLERS;
+#else
+                               k = CONFIG_SYS_NUM_DDR_CTLRS;
+#endif
                        break;
                case FSL_DDR_3WAY_1KB_INTERLEAVING:
                case FSL_DDR_3WAY_4KB_INTERLEAVING:
@@ -1118,15 +1369,15 @@ void check_interleaving_options(fsl_ddr_info_t *pinfo)
                case FSL_DDR_4WAY_4KB_INTERLEAVING:
                case FSL_DDR_4WAY_8KB_INTERLEAVING:
                default:
-                       k = CONFIG_NUM_DDR_CONTROLLERS;
+                       k = CONFIG_SYS_NUM_DDR_CTLRS;
                        break;
                }
                debug("%d of %d controllers are interleaving.\n", j, k);
                if (j && (j != k)) {
-                       for (i = 0; i < CONFIG_NUM_DDR_CONTROLLERS; i++)
+                       for (i = first_ctrl; i <= last_ctrl; i++)
                                pinfo->memctl_opts[i].memctl_interleaving = 0;
-                       printf("Not all controllers have compatible "
-                               "interleaving mode. All disabled.\n");
+                       if ((last_ctrl - first_ctrl) > 1)
+                               puts("Not all controllers have compatible interleaving mode. All disabled.\n");
                }
        }
        debug("Checking interleaving options completed\n");