Merge branch 'master' of git://git.denx.de/u-boot-sunxi
[platform/kernel/u-boot.git] / drivers / ddr / fsl / options.c
index cee97fe..4573ffa 100644 (file)
@@ -1,7 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
- * Copyright 2008, 2010-2014 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright 2008, 2010-2016 Freescale Semiconductor, Inc.
+ * Copyright 2017-2018 NXP Semiconductor
  */
 
 #include <common.h>
@@ -9,18 +9,25 @@
 #include <fsl_ddr_sdram.h>
 
 #include <fsl_ddr.h>
+#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
+       defined(CONFIG_ARM)
+#include <asm/arch/clock.h>
+#endif
 
 /*
  * Use our own stack based buffer before relocation to allow accessing longer
  * hwconfig strings that might be in the environment before we've relocated.
  * This is pretty fragile on both the use of stack and if the buffer is big
- * enough. However we will get a warning from getenv_f for the later.
+ * enough. However we will get a warning from env_get_f() for the latter.
  */
 
 /* Board-specific functions defined in each board's ddr.c */
-extern void fsl_ddr_board_options(memctl_options_t *popts,
-               dimm_params_t *pdimm,
-               unsigned int ctrl_num);
+void __weak fsl_ddr_board_options(memctl_options_t *popts,
+                                 dimm_params_t *pdimm,
+                                 unsigned int ctrl_num)
+{
+       return;
+}
 
 struct dynamic_odt {
        unsigned int odt_rd_cfg;
@@ -33,7 +40,7 @@ struct dynamic_odt {
 /* Quad rank is not verified yet due availability.
  * Replacing 20 OHM with 34 OHM since DDR4 doesn't have 20 OHM option
  */
-static const struct dynamic_odt single_Q[4] = {
+static __maybe_unused const struct dynamic_odt single_Q[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS_AND_OTHER_DIMM,
@@ -60,7 +67,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,
@@ -77,7 +84,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,
@@ -89,7 +96,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,
@@ -116,7 +123,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,
@@ -137,7 +144,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,
@@ -159,7 +166,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,
@@ -176,7 +183,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,
@@ -193,7 +200,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 */
@@ -210,7 +217,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,
@@ -223,7 +230,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 */
@@ -236,7 +243,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,
@@ -263,7 +270,7 @@ static const struct dynamic_odt odt_unknown[4] = {
        }
 };
 #elif defined(CONFIG_SYS_FSL_DDR3)
-static const struct dynamic_odt single_Q[4] = {
+static __maybe_unused const struct dynamic_odt single_Q[4] = {
        {       /* cs0 */
                FSL_DDR_ODT_NEVER,
                FSL_DDR_ODT_CS_AND_OTHER_DIMM,
@@ -290,7 +297,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,
@@ -307,7 +314,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,
@@ -319,7 +326,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,
@@ -346,7 +353,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,
@@ -367,7 +374,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,
@@ -389,7 +396,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,
@@ -406,7 +413,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,
@@ -423,7 +430,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 */
@@ -440,7 +447,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,
@@ -453,7 +460,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 */
@@ -466,7 +473,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,
@@ -493,14 +500,14 @@ static const struct dynamic_odt odt_unknown[4] = {
        }
 };
 #else  /* CONFIG_SYS_FSL_DDR3 */
-static const struct dynamic_odt single_Q[4] = {
+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,
@@ -517,7 +524,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,
@@ -529,7 +536,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,
@@ -556,7 +563,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,
@@ -578,7 +585,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,
@@ -600,7 +607,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,
@@ -617,7 +624,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,
@@ -634,7 +641,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 */
@@ -651,7 +658,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,
@@ -664,7 +671,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 */
@@ -677,7 +684,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,
@@ -738,21 +745,22 @@ unsigned int populate_memctl_options(const common_timing_params_t *common_dimm,
                        unsigned int ctrl_num)
 {
        unsigned int i;
-       char buffer[HWCONFIG_BUFFER_SIZE];
-       char *buf = NULL;
+       char buf[HWCONFIG_BUFFER_SIZE];
 #if defined(CONFIG_SYS_FSL_DDR3) || \
        defined(CONFIG_SYS_FSL_DDR2) || \
        defined(CONFIG_SYS_FSL_DDR4)
        const struct dynamic_odt *pdodt = odt_unknown;
 #endif
+#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
        ulong ddr_freq;
+#endif
 
        /*
         * Extract hwconfig from environment since we have not properly setup
         * the environment but need it for ddr config params
         */
-       if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
-               buf = buffer;
+       if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
+               buf[0] = '\0';
 
 #if defined(CONFIG_SYS_FSL_DDR3) || \
        defined(CONFIG_SYS_FSL_DDR2) || \
@@ -1288,6 +1296,9 @@ done:
        if (pdimm[0].n_ranks == 4)
                popts->quad_rank_present = 1;
 
+       popts->package_3ds = pdimm->package_3ds;
+
+#if (CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4)
        ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
        if (popts->registered_dimm_en) {
                popts->rcw_override = 1;
@@ -1301,6 +1312,7 @@ done:
                else
                        popts->rcw_2 = 0x00300000;
        }
+#endif
 
        fsl_ddr_board_options(popts, pdimm, ctrl_num);
 
@@ -1388,15 +1400,14 @@ int fsl_use_spd(void)
        int use_spd = 0;
 
 #ifdef CONFIG_DDR_SPD
-       char buffer[HWCONFIG_BUFFER_SIZE];
-       char *buf = NULL;
+       char buf[HWCONFIG_BUFFER_SIZE];
 
        /*
         * Extract hwconfig from environment since we have not properly setup
         * the environment but need it for ddr config params
         */
-       if (getenv_f("hwconfig", buffer, sizeof(buffer)) > 0)
-               buf = buffer;
+       if (env_get_f("hwconfig", buf, sizeof(buf)) < 0)
+               buf[0] = '\0';
 
        /* if hwconfig is not enabled, or "sdram" is not defined, use spd */
        if (hwconfig_sub_f("fsl_ddr", "sdram", buf)) {