Merge tag 'ti-v2020.07-rc3' of https://gitlab.denx.de/u-boot/custodians/u-boot-ti
[oweals/u-boot.git] / drivers / ddr / fsl / options.c
index b45a8797e449c0a675c415626360fe9bc43bcd75..c000a45f8ea83e18cd053cb116eed652a7157455 100644 (file)
@@ -1,26 +1,35 @@
+// 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>
+#include <env.h>
 #include <hwconfig.h>
 #include <fsl_ddr_sdram.h>
+#include <log.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;
@@ -738,21 +747,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 +1298,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 +1314,7 @@ done:
                else
                        popts->rcw_2 = 0x00300000;
        }
+#endif
 
        fsl_ddr_board_options(popts, pdimm, ctrl_num);
 
@@ -1388,15 +1402,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)) {