#include <fsl_immap.h>
 #include <asm/io.h>
 
-unsigned int picos_to_mclk(unsigned int picos);
-
 /*
  * Determine Rtt value.
  *
  *       16 for <= 2933MT/s
  *       18 for higher
  */
-static inline unsigned int compute_cas_write_latency(void)
+static inline unsigned int compute_cas_write_latency(
+                               const unsigned int ctrl_num)
 {
        unsigned int cwl;
-       const unsigned int mclk_ps = get_memory_clk_period_ps();
+       const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
        if (mclk_ps >= 1250)
                cwl = 9;
        else if (mclk_ps >= 1070)
  *       11 if 0.935ns > tCK >= 0.833ns
  *       12 if 0.833ns > tCK >= 0.75ns
  */
-static inline unsigned int compute_cas_write_latency(void)
+static inline unsigned int compute_cas_write_latency(
+                               const unsigned int ctrl_num)
 {
        unsigned int cwl;
-       const unsigned int mclk_ps = get_memory_clk_period_ps();
+       const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
 
        if (mclk_ps >= 2500)
                cwl = 5;
  * Avoid writing for DDR I.  The new PQ38 DDR controller
  * dreams up non-zero default values to be backwards compatible.
  */
-static void set_timing_cfg_0(fsl_ddr_cfg_regs_t *ddr,
+static void set_timing_cfg_0(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
                                const memctl_options_t *popts,
                                const dimm_params_t *dimm_params)
 {
        /* Mode register set cycle time (tMRD). */
        unsigned char tmrd_mclk;
 #if defined(CONFIG_SYS_FSL_DDR4) || defined(CONFIG_SYS_FSL_DDR3)
-       const unsigned int mclk_ps = get_memory_clk_period_ps();
+       const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
 #endif
 
 #ifdef CONFIG_SYS_FSL_DDR4
        int txp = max((int)mclk_ps * 4, 6000); /* unit=ps */
        trwt_mclk = 2;
        twrt_mclk = 1;
-       act_pd_exit_mclk = picos_to_mclk(txp);
+       act_pd_exit_mclk = picos_to_mclk(ctrl_num, txp);
        pre_pd_exit_mclk = act_pd_exit_mclk;
        /*
         * MRS_CYC = max(tMRD, tMOD)
         * tMRD = 8nCK, tMOD = max(24nCK, 15ns)
         */
-       tmrd_mclk = max(24U, picos_to_mclk(15000));
+       tmrd_mclk = max(24U, picos_to_mclk(ctrl_num, 15000));
 #elif defined(CONFIG_SYS_FSL_DDR3)
-       unsigned int data_rate = get_ddr_freq(0);
+       unsigned int data_rate = get_ddr_freq(ctrl_num);
        int txp;
        unsigned int ip_rev;
        int odt_overlap;
                 * tMRD = 4nCK (8nCK for RDIMM)
                 * tMOD = max(12nCK, 15ns)
                 */
-               tmrd_mclk = max((unsigned int)12, picos_to_mclk(15000));
+               tmrd_mclk = max((unsigned int)12,
+                               picos_to_mclk(ctrl_num, 15000));
        } else {
                /*
                 * MRS_CYC = tMRD
                taxpd_mclk = 1;
        } else {
                /* act_pd_exit_mclk = tXARD, see above */
-               act_pd_exit_mclk = picos_to_mclk(txp);
+               act_pd_exit_mclk = picos_to_mclk(ctrl_num, txp);
                /* Mode register MR0[A12] is '1' - fast exit */
                pre_pd_exit_mclk = act_pd_exit_mclk;
                taxpd_mclk = 1;
 #endif /* !defined(CONFIG_SYS_FSL_DDR1) */
 
 /* DDR SDRAM Timing Configuration 3 (TIMING_CFG_3) */
-static void set_timing_cfg_3(fsl_ddr_cfg_regs_t *ddr,
-                              const memctl_options_t *popts,
-                              const common_timing_params_t *common_dimm,
-                              unsigned int cas_latency,
-                              unsigned int additive_latency)
+static void set_timing_cfg_3(const unsigned int ctrl_num,
+                            fsl_ddr_cfg_regs_t *ddr,
+                            const memctl_options_t *popts,
+                            const common_timing_params_t *common_dimm,
+                            unsigned int cas_latency,
+                            unsigned int additive_latency)
 {
        /* Extended precharge to activate interval (tRP) */
        unsigned int ext_pretoact = 0;
        /* Control Adjust */
        unsigned int cntl_adj = 0;
 
-       ext_pretoact = picos_to_mclk(common_dimm->trp_ps) >> 4;
-       ext_acttopre = picos_to_mclk(common_dimm->tras_ps) >> 4;
-       ext_acttorw = picos_to_mclk(common_dimm->trcd_ps) >> 4;
+       ext_pretoact = picos_to_mclk(ctrl_num, common_dimm->trp_ps) >> 4;
+       ext_acttopre = picos_to_mclk(ctrl_num, common_dimm->tras_ps) >> 4;
+       ext_acttorw = picos_to_mclk(ctrl_num, common_dimm->trcd_ps) >> 4;
        ext_caslat = (2 * cas_latency - 1) >> 4;
        ext_add_lat = additive_latency >> 4;
 #ifdef CONFIG_SYS_FSL_DDR4
-       ext_refrec = (picos_to_mclk(common_dimm->trfc1_ps) - 8) >> 4;
+       ext_refrec = (picos_to_mclk(ctrl_num, common_dimm->trfc1_ps) - 8) >> 4;
 #else
-       ext_refrec = (picos_to_mclk(common_dimm->trfc_ps) - 8) >> 4;
+       ext_refrec = (picos_to_mclk(ctrl_num, common_dimm->trfc_ps) - 8) >> 4;
        /* ext_wrrec only deals with 16 clock and above, or 14 with OTF */
 #endif
-       ext_wrrec = (picos_to_mclk(common_dimm->twr_ps) +
+       ext_wrrec = (picos_to_mclk(ctrl_num, common_dimm->twr_ps) +
                (popts->otf_burst_chop_en ? 2 : 0)) >> 4;
 
        ddr->timing_cfg_3 = (0
 }
 
 /* DDR SDRAM Timing Configuration 1 (TIMING_CFG_1) */
-static void set_timing_cfg_1(fsl_ddr_cfg_regs_t *ddr,
-                              const memctl_options_t *popts,
-                              const common_timing_params_t *common_dimm,
-                              unsigned int cas_latency)
+static void set_timing_cfg_1(const unsigned int ctrl_num,
+                            fsl_ddr_cfg_regs_t *ddr,
+                            const memctl_options_t *popts,
+                            const common_timing_params_t *common_dimm,
+                            unsigned int cas_latency)
 {
        /* Precharge-to-activate interval (tRP) */
        unsigned char pretoact_mclk;
                1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 12, 12, 14, 14, 0, 0};
 #endif
 
-       pretoact_mclk = picos_to_mclk(common_dimm->trp_ps);
-       acttopre_mclk = picos_to_mclk(common_dimm->tras_ps);
-       acttorw_mclk = picos_to_mclk(common_dimm->trcd_ps);
+       pretoact_mclk = picos_to_mclk(ctrl_num, common_dimm->trp_ps);
+       acttopre_mclk = picos_to_mclk(ctrl_num, common_dimm->tras_ps);
+       acttorw_mclk = picos_to_mclk(ctrl_num, common_dimm->trcd_ps);
 
        /*
         * Translate CAS Latency to a DDR controller field value:
 #endif
 
 #ifdef CONFIG_SYS_FSL_DDR4
-       refrec_ctrl = picos_to_mclk(common_dimm->trfc1_ps) - 8;
-       wrrec_mclk = picos_to_mclk(common_dimm->twr_ps);
-       acttoact_mclk = max(picos_to_mclk(common_dimm->trrds_ps), 4U);
-       wrtord_mclk = max(2U, picos_to_mclk(2500));
+       refrec_ctrl = picos_to_mclk(ctrl_num, common_dimm->trfc1_ps) - 8;
+       wrrec_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
+       acttoact_mclk = max(picos_to_mclk(ctrl_num, common_dimm->trrds_ps), 4U);
+       wrtord_mclk = max(2U, picos_to_mclk(ctrl_num, 2500));
        if ((wrrec_mclk < 1) || (wrrec_mclk > 24))
                printf("Error: WRREC doesn't support %d clocks\n", wrrec_mclk);
        else
                wrrec_mclk = wrrec_table[wrrec_mclk - 1];
 #else
-       refrec_ctrl = picos_to_mclk(common_dimm->trfc_ps) - 8;
-       wrrec_mclk = picos_to_mclk(common_dimm->twr_ps);
-       acttoact_mclk = picos_to_mclk(common_dimm->trrd_ps);
-       wrtord_mclk = picos_to_mclk(common_dimm->twtr_ps);
+       refrec_ctrl = picos_to_mclk(ctrl_num, common_dimm->trfc_ps) - 8;
+       wrrec_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
+       acttoact_mclk = picos_to_mclk(ctrl_num, common_dimm->trrd_ps);
+       wrtord_mclk = picos_to_mclk(ctrl_num, common_dimm->twtr_ps);
        if ((wrrec_mclk < 1) || (wrrec_mclk > 16))
                printf("Error: WRREC doesn't support %d clocks\n", wrrec_mclk);
        else
 }
 
 /* DDR SDRAM Timing Configuration 2 (TIMING_CFG_2) */
-static void set_timing_cfg_2(fsl_ddr_cfg_regs_t *ddr,
-                              const memctl_options_t *popts,
-                              const common_timing_params_t *common_dimm,
-                              unsigned int cas_latency,
-                              unsigned int additive_latency)
+static void set_timing_cfg_2(const unsigned int ctrl_num,
+                            fsl_ddr_cfg_regs_t *ddr,
+                            const memctl_options_t *popts,
+                            const common_timing_params_t *common_dimm,
+                            unsigned int cas_latency,
+                            unsigned int additive_latency)
 {
        /* Additive latency */
        unsigned char add_lat_mclk;
        /* Window for four activates (tFAW) */
        unsigned short four_act;
 #ifdef CONFIG_SYS_FSL_DDR3
-       const unsigned int mclk_ps = get_memory_clk_period_ps();
+       const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
 #endif
 
        /* FIXME add check that this must be less than acttorw_mclk */
 #elif defined(CONFIG_SYS_FSL_DDR2)
        wr_lat = cas_latency - 1;
 #else
-       wr_lat = compute_cas_write_latency();
+       wr_lat = compute_cas_write_latency(ctrl_num);
 #endif
 
 #ifdef CONFIG_SYS_FSL_DDR4
-       rd_to_pre = picos_to_mclk(7500);
+       rd_to_pre = picos_to_mclk(ctrl_num, 7500);
 #else
-       rd_to_pre = picos_to_mclk(common_dimm->trtp_ps);
+       rd_to_pre = picos_to_mclk(ctrl_num, common_dimm->trtp_ps);
 #endif
        /*
         * JEDEC has some min requirements for tRTP
        wr_data_delay = popts->write_data_delay;
 #ifdef CONFIG_SYS_FSL_DDR4
        cpo = 0;
-       cke_pls = max(3U, picos_to_mclk(5000));
+       cke_pls = max(3U, picos_to_mclk(ctrl_num, 5000));
 #elif defined(CONFIG_SYS_FSL_DDR3)
        /*
         * cke pulse = max(3nCK, 7.5ns) for DDR3-800
         *             max(3nCK, 5.625ns) for DDR3-1066, 1333
         *             max(3nCK, 5ns) for DDR3-1600, 1866, 2133
         */
-       cke_pls = max(3U, picos_to_mclk(mclk_ps > 1870 ? 7500 :
-                                      (mclk_ps > 1245 ? 5625 : 5000)));
+       cke_pls = max(3U, picos_to_mclk(ctrl_num, mclk_ps > 1870 ? 7500 :
+                                       (mclk_ps > 1245 ? 5625 : 5000)));
 #else
        cke_pls = FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR;
 #endif
-       four_act = picos_to_mclk(popts->tfaw_window_four_activates_ps);
+       four_act = picos_to_mclk(ctrl_num,
+                                popts->tfaw_window_four_activates_ps);
 
        ddr->timing_cfg_2 = (0
                | ((add_lat_mclk & 0xf) << 28)
 }
 
 /* DDR SDRAM control configuration 2 (DDR_SDRAM_CFG_2) */
-static void set_ddr_sdram_cfg_2(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_cfg_2(const unsigned int ctrl_num,
+                              fsl_ddr_cfg_regs_t *ddr,
                               const memctl_options_t *popts,
                               const unsigned int unq_mrs_en)
 {
 #endif
 
 #if (CONFIG_SYS_FSL_DDR_VER >= FSL_DDR_VER_4_7)
-       slow = get_ddr_freq(0) < 1249000000;
+       slow = get_ddr_freq(ctrl_num) < 1249000000;
 #endif
 
        if (popts->registered_dimm_en) {
 
 #ifdef CONFIG_SYS_FSL_DDR4
 /* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
-static void set_ddr_sdram_mode_2(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
                                const memctl_options_t *popts,
                                const common_timing_params_t *common_dimm,
                                const unsigned int unq_mrs_en)
        unsigned int wr_crc = 0;        /* Disable */
        unsigned int rtt_wr = 0;        /* Rtt_WR - dynamic ODT off */
        unsigned int srt = 0;   /* self-refresh temerature, normal range */
-       unsigned int cwl = compute_cas_write_latency() - 9;
+       unsigned int cwl = compute_cas_write_latency(ctrl_num) - 9;
        unsigned int mpr = 0;   /* serial */
        unsigned int wc_lat;
-       const unsigned int mclk_ps = get_memory_clk_period_ps();
+       const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
 
        if (popts->rtt_override)
                rtt_wr = popts->rtt_wr_override_value;
 }
 #elif defined(CONFIG_SYS_FSL_DDR3)
 /* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
-static void set_ddr_sdram_mode_2(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
                                const memctl_options_t *popts,
                                const common_timing_params_t *common_dimm,
                                const unsigned int unq_mrs_en)
        unsigned int rtt_wr = 0;        /* Rtt_WR - dynamic ODT off */
        unsigned int srt = 0;   /* self-refresh temerature, normal range */
        unsigned int asr = 0;   /* auto self-refresh disable */
-       unsigned int cwl = compute_cas_write_latency() - 5;
+       unsigned int cwl = compute_cas_write_latency(ctrl_num) - 5;
        unsigned int pasr = 0;  /* partial array self refresh disable */
 
        if (popts->rtt_override)
 
 #else /* for DDR2 and DDR1 */
 /* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
-static void set_ddr_sdram_mode_2(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
                                const memctl_options_t *popts,
                                const common_timing_params_t *common_dimm,
                                const unsigned int unq_mrs_en)
 }
 
 /* DDR SDRAM Mode configuration 10 (DDR_SDRAM_MODE_10) */
-static void set_ddr_sdram_mode_10(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode_10(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
                                const memctl_options_t *popts,
                                const common_timing_params_t *common_dimm,
                                const unsigned int unq_mrs_en)
        int i;
        unsigned short esdmode6 = 0;    /* Extended SDRAM mode 6 */
        unsigned short esdmode7 = 0;    /* Extended SDRAM mode 7 */
-       unsigned int tccdl_min = picos_to_mclk(common_dimm->tccdl_ps);
+       unsigned int tccdl_min = picos_to_mclk(ctrl_num, common_dimm->tccdl_ps);
 
        esdmode6 = ((tccdl_min - 4) & 0x7) << 10;
 
 #endif
 
 /* DDR SDRAM Interval Configuration (DDR_SDRAM_INTERVAL) */
-static void set_ddr_sdram_interval(fsl_ddr_cfg_regs_t *ddr,
-                              const memctl_options_t *popts,
-                              const common_timing_params_t *common_dimm)
+static void set_ddr_sdram_interval(const unsigned int ctrl_num,
+                               fsl_ddr_cfg_regs_t *ddr,
+                               const memctl_options_t *popts,
+                               const common_timing_params_t *common_dimm)
 {
        unsigned int refint;    /* Refresh interval */
        unsigned int bstopre;   /* Precharge interval */
 
-       refint = picos_to_mclk(common_dimm->refresh_rate_ps);
+       refint = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps);
 
        bstopre = popts->bstopre;
 
 
 #ifdef CONFIG_SYS_FSL_DDR4
 /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
-static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode(const unsigned int ctrl_num,
+                              fsl_ddr_cfg_regs_t *ddr,
                               const memctl_options_t *popts,
                               const common_timing_params_t *common_dimm,
                               unsigned int cas_latency,
         * 1=fast exit DLL on (tXP)
         */
 
-       wr_mclk = picos_to_mclk(common_dimm->twr_ps);
+       wr_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
        if (wr_mclk <= 24) {
                wr = wr_table[wr_mclk - 10];
        } else {
 
 #elif defined(CONFIG_SYS_FSL_DDR3)
 /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
-static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode(const unsigned int ctrl_num,
+                              fsl_ddr_cfg_regs_t *ddr,
                               const memctl_options_t *popts,
                               const common_timing_params_t *common_dimm,
                               unsigned int cas_latency,
         */
        dll_on = 1;
 
-       wr_mclk = picos_to_mclk(common_dimm->twr_ps);
+       wr_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
        if (wr_mclk <= 16) {
                wr = wr_table[wr_mclk - 5];
        } else {
 #else /* !CONFIG_SYS_FSL_DDR3 */
 
 /* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
-static void set_ddr_sdram_mode(fsl_ddr_cfg_regs_t *ddr,
+static void set_ddr_sdram_mode(const unsigned int ctrl_num,
+                              fsl_ddr_cfg_regs_t *ddr,
                               const memctl_options_t *popts,
                               const common_timing_params_t *common_dimm,
                               unsigned int cas_latency,
 #if defined(CONFIG_SYS_FSL_DDR1)
        wr = 0;       /* Historical */
 #elif defined(CONFIG_SYS_FSL_DDR2)
-       wr = picos_to_mclk(common_dimm->twr_ps);
+       wr = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
 #endif
        dll_res = 0;
        mode = 0;
        debug("FSLDDR: timing_cfg_6 = 0x%08x\n", ddr->timing_cfg_6);
 }
 
-static void set_timing_cfg_7(fsl_ddr_cfg_regs_t *ddr,
-                       const common_timing_params_t *common_dimm)
+static void set_timing_cfg_7(const unsigned int ctrl_num,
+                            fsl_ddr_cfg_regs_t *ddr,
+                            const common_timing_params_t *common_dimm)
 {
        unsigned int txpr, tcksre, tcksrx;
        unsigned int cke_rst, cksre, cksrx, par_lat, cs_to_cmd;
 
-       txpr = max(5U, picos_to_mclk(common_dimm->trfc1_ps + 10000));
-       tcksre = max(5U, picos_to_mclk(10000));
-       tcksrx = max(5U, picos_to_mclk(10000));
+       txpr = max(5U, picos_to_mclk(ctrl_num, common_dimm->trfc1_ps + 10000));
+       tcksre = max(5U, picos_to_mclk(ctrl_num, 10000));
+       tcksrx = max(5U, picos_to_mclk(ctrl_num, 10000));
        par_lat = 0;
        cs_to_cmd = 0;
 
        debug("FSLDDR: timing_cfg_7 = 0x%08x\n", ddr->timing_cfg_7);
 }
 
-static void set_timing_cfg_8(fsl_ddr_cfg_regs_t *ddr,
+static void set_timing_cfg_8(const unsigned int ctrl_num,
+                            fsl_ddr_cfg_regs_t *ddr,
                             const memctl_options_t *popts,
                             const common_timing_params_t *common_dimm,
                             unsigned int cas_latency)
 {
        unsigned int rwt_bg, wrt_bg, rrt_bg, wwt_bg;
        unsigned int acttoact_bg, wrtord_bg, pre_all_rec;
-       unsigned int tccdl = picos_to_mclk(common_dimm->tccdl_ps);
+       unsigned int tccdl = picos_to_mclk(ctrl_num, common_dimm->tccdl_ps);
        unsigned int wr_lat = ((ddr->timing_cfg_2 & 0x00780000) >> 19) +
                              ((ddr->timing_cfg_2 & 0x00040000) >> 14);
 
                wwt_bg = tccdl - 4;
        }
 
-       acttoact_bg = picos_to_mclk(common_dimm->trrdl_ps);
-       wrtord_bg = max(4U, picos_to_mclk(7500));
+       acttoact_bg = picos_to_mclk(ctrl_num, common_dimm->trrdl_ps);
+       wrtord_bg = max(4U, picos_to_mclk(ctrl_num, 7500));
        if (popts->otf_burst_chop_en)
                wrtord_bg += 2;
 
 }
 
 unsigned int
-compute_fsl_memctl_config_regs(const memctl_options_t *popts,
+compute_fsl_memctl_config_regs(const unsigned int ctrl_num,
+                              const memctl_options_t *popts,
                               fsl_ddr_cfg_regs_t *ddr,
                               const common_timing_params_t *common_dimm,
                               const dimm_params_t *dimm_params,
        set_ddr_eor(ddr, popts);
 
 #if !defined(CONFIG_SYS_FSL_DDR1)
-       set_timing_cfg_0(ddr, popts, dimm_params);
+       set_timing_cfg_0(ctrl_num, ddr, popts, dimm_params);
 #endif
 
-       set_timing_cfg_3(ddr, popts, common_dimm, cas_latency,
+       set_timing_cfg_3(ctrl_num, ddr, popts, common_dimm, cas_latency,
                         additive_latency);
-       set_timing_cfg_1(ddr, popts, common_dimm, cas_latency);
-       set_timing_cfg_2(ddr, popts, common_dimm,
-                               cas_latency, additive_latency);
+       set_timing_cfg_1(ctrl_num, ddr, popts, common_dimm, cas_latency);
+       set_timing_cfg_2(ctrl_num, ddr, popts, common_dimm,
+                        cas_latency, additive_latency);
 
        set_ddr_cdr1(ddr, popts);
        set_ddr_cdr2(ddr, popts);
        if ((ip_rev > 0x40700) && (popts->cswl_override != 0))
                ddr->debug[18] = popts->cswl_override;
 
-       set_ddr_sdram_cfg_2(ddr, popts, unq_mrs_en);
-       set_ddr_sdram_mode(ddr, popts, common_dimm,
-                               cas_latency, additive_latency, unq_mrs_en);
-       set_ddr_sdram_mode_2(ddr, popts, common_dimm, unq_mrs_en);
+       set_ddr_sdram_cfg_2(ctrl_num, ddr, popts, unq_mrs_en);
+       set_ddr_sdram_mode(ctrl_num, ddr, popts, common_dimm,
+                          cas_latency, additive_latency, unq_mrs_en);
+       set_ddr_sdram_mode_2(ctrl_num, ddr, popts, common_dimm, unq_mrs_en);
 #ifdef CONFIG_SYS_FSL_DDR4
        set_ddr_sdram_mode_9(ddr, popts, common_dimm, unq_mrs_en);
-       set_ddr_sdram_mode_10(ddr, popts, common_dimm, unq_mrs_en);
+       set_ddr_sdram_mode_10(ctrl_num, ddr, popts, common_dimm, unq_mrs_en);
 #endif
-       set_ddr_sdram_interval(ddr, popts, common_dimm);
+       set_ddr_sdram_interval(ctrl_num, ddr, popts, common_dimm);
        set_ddr_data_init(ddr);
        set_ddr_sdram_clk_cntl(ddr, popts);
        set_ddr_init_addr(ddr);
 #ifdef CONFIG_SYS_FSL_DDR4
        set_ddr_sdram_cfg_3(ddr, popts);
        set_timing_cfg_6(ddr);
-       set_timing_cfg_7(ddr, common_dimm);
-       set_timing_cfg_8(ddr, popts, common_dimm, cas_latency);
+       set_timing_cfg_7(ctrl_num, ddr, common_dimm);
+       set_timing_cfg_8(ctrl_num, ddr, popts, common_dimm, cas_latency);
        set_timing_cfg_9(ddr);
        set_ddr_dq_mapping(ddr, dimm_params);
 #endif