xref: /openbmc/u-boot/drivers/ddr/fsl/fsl_ddr_gen4.c (revision 03e664d8f4065010ccb6c75648192200a832fd8b)
134e026f9SYork Sun /*
234e026f9SYork Sun  * Copyright 2014 Freescale Semiconductor, Inc.
334e026f9SYork Sun  *
434e026f9SYork Sun  * SPDX-License-Identifier:	GPL-2.0+
534e026f9SYork Sun  */
634e026f9SYork Sun 
734e026f9SYork Sun #include <common.h>
834e026f9SYork Sun #include <asm/io.h>
934e026f9SYork Sun #include <fsl_ddr_sdram.h>
1034e026f9SYork Sun #include <asm/processor.h>
118340e7acSYork Sun #include <fsl_immap.h>
1234e026f9SYork Sun #include <fsl_ddr.h>
1334e026f9SYork Sun 
1434e026f9SYork Sun #if (CONFIG_CHIP_SELECTS_PER_CTRL > 4)
1534e026f9SYork Sun #error Invalid setting for CONFIG_CHIP_SELECTS_PER_CTRL
1634e026f9SYork Sun #endif
1734e026f9SYork Sun 
1834e026f9SYork Sun /*
1934e026f9SYork Sun  * regs has the to-be-set values for DDR controller registers
2034e026f9SYork Sun  * ctrl_num is the DDR controller number
2134e026f9SYork Sun  * step: 0 goes through the initialization in one pass
2234e026f9SYork Sun  *       1 sets registers and returns before enabling controller
2334e026f9SYork Sun  *       2 resumes from step 1 and continues to initialize
2434e026f9SYork Sun  * Dividing the initialization to two steps to deassert DDR reset signal
2534e026f9SYork Sun  * to comply with JEDEC specs for RDIMMs.
2634e026f9SYork Sun  */
2734e026f9SYork Sun void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
2834e026f9SYork Sun 			     unsigned int ctrl_num, int step)
2934e026f9SYork Sun {
3034e026f9SYork Sun 	unsigned int i, bus_width;
3134e026f9SYork Sun 	struct ccsr_ddr __iomem *ddr;
3234e026f9SYork Sun 	u32 temp_sdram_cfg;
3334e026f9SYork Sun 	u32 total_gb_size_per_controller;
3434e026f9SYork Sun 	int timeout;
3549fd1f3fSYork Sun #if defined(CONFIG_SYS_FSL_ERRATUM_A008336) || \
3649fd1f3fSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_A008514)
379955b4abSYork Sun 	u32 *eddrtqcr1;
389955b4abSYork Sun #endif
3934e026f9SYork Sun 
4034e026f9SYork Sun 	switch (ctrl_num) {
4134e026f9SYork Sun 	case 0:
4234e026f9SYork Sun 		ddr = (void *)CONFIG_SYS_FSL_DDR_ADDR;
4349fd1f3fSYork Sun #if defined(CONFIG_SYS_FSL_ERRATUM_A008336) || \
4449fd1f3fSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_A008514)
459955b4abSYork Sun 		eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR_ADDR + 0x800;
469955b4abSYork Sun #endif
4734e026f9SYork Sun 		break;
4834e026f9SYork Sun #if defined(CONFIG_SYS_FSL_DDR2_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 1)
4934e026f9SYork Sun 	case 1:
5034e026f9SYork Sun 		ddr = (void *)CONFIG_SYS_FSL_DDR2_ADDR;
5149fd1f3fSYork Sun #if defined(CONFIG_SYS_FSL_ERRATUM_A008336) || \
5249fd1f3fSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_A008514)
539955b4abSYork Sun 		eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR2_ADDR + 0x800;
549955b4abSYork Sun #endif
5534e026f9SYork Sun 		break;
5634e026f9SYork Sun #endif
5734e026f9SYork Sun #if defined(CONFIG_SYS_FSL_DDR3_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 2)
5834e026f9SYork Sun 	case 2:
5934e026f9SYork Sun 		ddr = (void *)CONFIG_SYS_FSL_DDR3_ADDR;
6049fd1f3fSYork Sun #if defined(CONFIG_SYS_FSL_ERRATUM_A008336) || \
6149fd1f3fSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_A008514)
629955b4abSYork Sun 		eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR3_ADDR + 0x800;
639955b4abSYork Sun #endif
6434e026f9SYork Sun 		break;
6534e026f9SYork Sun #endif
6634e026f9SYork Sun #if defined(CONFIG_SYS_FSL_DDR4_ADDR) && (CONFIG_NUM_DDR_CONTROLLERS > 3)
6734e026f9SYork Sun 	case 3:
6834e026f9SYork Sun 		ddr = (void *)CONFIG_SYS_FSL_DDR4_ADDR;
6949fd1f3fSYork Sun #if defined(CONFIG_SYS_FSL_ERRATUM_A008336) || \
7049fd1f3fSYork Sun 	defined(CONFIG_SYS_FSL_ERRATUM_A008514)
719955b4abSYork Sun 		eddrtqcr1 = (void *)CONFIG_SYS_FSL_DCSR_DDR4_ADDR + 0x800;
729955b4abSYork Sun #endif
7334e026f9SYork Sun 		break;
7434e026f9SYork Sun #endif
7534e026f9SYork Sun 	default:
7634e026f9SYork Sun 		printf("%s unexpected ctrl_num = %u\n", __func__, ctrl_num);
7734e026f9SYork Sun 		return;
7834e026f9SYork Sun 	}
7934e026f9SYork Sun 
8034e026f9SYork Sun 	if (step == 2)
8134e026f9SYork Sun 		goto step2;
8234e026f9SYork Sun 
839955b4abSYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A008336
849955b4abSYork Sun #ifdef CONFIG_LS2085A
859955b4abSYork Sun 	/* A008336 only applies to general DDR controllers */
869955b4abSYork Sun 	if ((ctrl_num == 0) || (ctrl_num == 1))
879955b4abSYork Sun #endif
889955b4abSYork Sun 		ddr_out32(eddrtqcr1, 0x63b30002);
899955b4abSYork Sun #endif
9049fd1f3fSYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A008514
9149fd1f3fSYork Sun #ifdef CONFIG_LS2085A
9249fd1f3fSYork Sun 	/* A008514 only applies to DP-DDR controler */
9349fd1f3fSYork Sun 	if (ctrl_num == 2)
9449fd1f3fSYork Sun #endif
9549fd1f3fSYork Sun 		ddr_out32(eddrtqcr1, 0x63b20002);
9649fd1f3fSYork Sun #endif
9734e026f9SYork Sun 	if (regs->ddr_eor)
9834e026f9SYork Sun 		ddr_out32(&ddr->eor, regs->ddr_eor);
9934e026f9SYork Sun 
10034e026f9SYork Sun 	ddr_out32(&ddr->sdram_clk_cntl, regs->ddr_sdram_clk_cntl);
10134e026f9SYork Sun 
10234e026f9SYork Sun 	for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
10334e026f9SYork Sun 		if (i == 0) {
10434e026f9SYork Sun 			ddr_out32(&ddr->cs0_bnds, regs->cs[i].bnds);
10534e026f9SYork Sun 			ddr_out32(&ddr->cs0_config, regs->cs[i].config);
10634e026f9SYork Sun 			ddr_out32(&ddr->cs0_config_2, regs->cs[i].config_2);
10734e026f9SYork Sun 
10834e026f9SYork Sun 		} else if (i == 1) {
10934e026f9SYork Sun 			ddr_out32(&ddr->cs1_bnds, regs->cs[i].bnds);
11034e026f9SYork Sun 			ddr_out32(&ddr->cs1_config, regs->cs[i].config);
11134e026f9SYork Sun 			ddr_out32(&ddr->cs1_config_2, regs->cs[i].config_2);
11234e026f9SYork Sun 
11334e026f9SYork Sun 		} else if (i == 2) {
11434e026f9SYork Sun 			ddr_out32(&ddr->cs2_bnds, regs->cs[i].bnds);
11534e026f9SYork Sun 			ddr_out32(&ddr->cs2_config, regs->cs[i].config);
11634e026f9SYork Sun 			ddr_out32(&ddr->cs2_config_2, regs->cs[i].config_2);
11734e026f9SYork Sun 
11834e026f9SYork Sun 		} else if (i == 3) {
11934e026f9SYork Sun 			ddr_out32(&ddr->cs3_bnds, regs->cs[i].bnds);
12034e026f9SYork Sun 			ddr_out32(&ddr->cs3_config, regs->cs[i].config);
12134e026f9SYork Sun 			ddr_out32(&ddr->cs3_config_2, regs->cs[i].config_2);
12234e026f9SYork Sun 		}
12334e026f9SYork Sun 	}
12434e026f9SYork Sun 
12534e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_3, regs->timing_cfg_3);
12634e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_0, regs->timing_cfg_0);
12734e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_1, regs->timing_cfg_1);
12834e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_2, regs->timing_cfg_2);
12934e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_4, regs->timing_cfg_4);
13034e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_5, regs->timing_cfg_5);
13134e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_6, regs->timing_cfg_6);
13234e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_7, regs->timing_cfg_7);
13334e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_8, regs->timing_cfg_8);
13434e026f9SYork Sun 	ddr_out32(&ddr->timing_cfg_9, regs->timing_cfg_9);
13534e026f9SYork Sun 	ddr_out32(&ddr->ddr_zq_cntl, regs->ddr_zq_cntl);
13634e026f9SYork Sun 	ddr_out32(&ddr->dq_map_0, regs->dq_map_0);
13734e026f9SYork Sun 	ddr_out32(&ddr->dq_map_1, regs->dq_map_1);
13834e026f9SYork Sun 	ddr_out32(&ddr->dq_map_2, regs->dq_map_2);
13934e026f9SYork Sun 	ddr_out32(&ddr->dq_map_3, regs->dq_map_3);
14034e026f9SYork Sun 	ddr_out32(&ddr->sdram_cfg_3, regs->ddr_sdram_cfg_3);
14134e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode, regs->ddr_sdram_mode);
14234e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_2, regs->ddr_sdram_mode_2);
14334e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_3, regs->ddr_sdram_mode_3);
14434e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_4, regs->ddr_sdram_mode_4);
14534e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_5, regs->ddr_sdram_mode_5);
14634e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_6, regs->ddr_sdram_mode_6);
14734e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_7, regs->ddr_sdram_mode_7);
14834e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_8, regs->ddr_sdram_mode_8);
14934e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_9, regs->ddr_sdram_mode_9);
15034e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_10, regs->ddr_sdram_mode_10);
15134e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_11, regs->ddr_sdram_mode_11);
15234e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_12, regs->ddr_sdram_mode_12);
15334e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_13, regs->ddr_sdram_mode_13);
15434e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_14, regs->ddr_sdram_mode_14);
15534e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_15, regs->ddr_sdram_mode_15);
15634e026f9SYork Sun 	ddr_out32(&ddr->sdram_mode_16, regs->ddr_sdram_mode_16);
15734e026f9SYork Sun 	ddr_out32(&ddr->sdram_md_cntl, regs->ddr_sdram_md_cntl);
15834e026f9SYork Sun 	ddr_out32(&ddr->sdram_interval, regs->ddr_sdram_interval);
15934e026f9SYork Sun 	ddr_out32(&ddr->sdram_data_init, regs->ddr_data_init);
16034e026f9SYork Sun 	ddr_out32(&ddr->ddr_wrlvl_cntl, regs->ddr_wrlvl_cntl);
16134e026f9SYork Sun #ifndef CONFIG_SYS_FSL_DDR_EMU
16234e026f9SYork Sun 	/*
16334e026f9SYork Sun 	 * Skip these two registers if running on emulator
16434e026f9SYork Sun 	 * because emulator doesn't have skew between bytes.
16534e026f9SYork Sun 	 */
16634e026f9SYork Sun 
16734e026f9SYork Sun 	if (regs->ddr_wrlvl_cntl_2)
16834e026f9SYork Sun 		ddr_out32(&ddr->ddr_wrlvl_cntl_2, regs->ddr_wrlvl_cntl_2);
16934e026f9SYork Sun 	if (regs->ddr_wrlvl_cntl_3)
17034e026f9SYork Sun 		ddr_out32(&ddr->ddr_wrlvl_cntl_3, regs->ddr_wrlvl_cntl_3);
17134e026f9SYork Sun #endif
17234e026f9SYork Sun 
17334e026f9SYork Sun 	ddr_out32(&ddr->ddr_sr_cntr, regs->ddr_sr_cntr);
17434e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_1, regs->ddr_sdram_rcw_1);
17534e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_2, regs->ddr_sdram_rcw_2);
17634e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_3, regs->ddr_sdram_rcw_3);
17734e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_4, regs->ddr_sdram_rcw_4);
17834e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_5, regs->ddr_sdram_rcw_5);
17934e026f9SYork Sun 	ddr_out32(&ddr->ddr_sdram_rcw_6, regs->ddr_sdram_rcw_6);
18034e026f9SYork Sun 	ddr_out32(&ddr->ddr_cdr1, regs->ddr_cdr1);
181a7787b78STang Yuantian #ifdef CONFIG_DEEP_SLEEP
182a7787b78STang Yuantian 	if (is_warm_boot()) {
183a7787b78STang Yuantian 		ddr_out32(&ddr->sdram_cfg_2,
184a7787b78STang Yuantian 			  regs->ddr_sdram_cfg_2 & ~SDRAM_CFG2_D_INIT);
185a7787b78STang Yuantian 		ddr_out32(&ddr->init_addr, CONFIG_SYS_SDRAM_BASE);
186a7787b78STang Yuantian 		ddr_out32(&ddr->init_ext_addr, DDR_INIT_ADDR_EXT_UIA);
187a7787b78STang Yuantian 
188a7787b78STang Yuantian 		/* DRAM VRef will not be trained */
189a7787b78STang Yuantian 		ddr_out32(&ddr->ddr_cdr2,
190a7787b78STang Yuantian 			  regs->ddr_cdr2 & ~DDR_CDR2_VREF_TRAIN_EN);
191a7787b78STang Yuantian 	} else
192a7787b78STang Yuantian #endif
193a7787b78STang Yuantian 	{
194a7787b78STang Yuantian 		ddr_out32(&ddr->sdram_cfg_2, regs->ddr_sdram_cfg_2);
195a7787b78STang Yuantian 		ddr_out32(&ddr->init_addr, regs->ddr_init_addr);
196a7787b78STang Yuantian 		ddr_out32(&ddr->init_ext_addr, regs->ddr_init_ext_addr);
19734e026f9SYork Sun 		ddr_out32(&ddr->ddr_cdr2, regs->ddr_cdr2);
198a7787b78STang Yuantian 	}
19934e026f9SYork Sun 	ddr_out32(&ddr->err_disable, regs->err_disable);
20034e026f9SYork Sun 	ddr_out32(&ddr->err_int_en, regs->err_int_en);
20134e026f9SYork Sun 	for (i = 0; i < 32; i++) {
20234e026f9SYork Sun 		if (regs->debug[i]) {
20334e026f9SYork Sun 			debug("Write to debug_%d as %08x\n",
20434e026f9SYork Sun 			      i+1, regs->debug[i]);
20534e026f9SYork Sun 			ddr_out32(&ddr->debug[i], regs->debug[i]);
20634e026f9SYork Sun 		}
20734e026f9SYork Sun 	}
208dda3b610SYork Sun #ifdef CONFIG_SYS_FSL_ERRATUM_A008378
209dda3b610SYork Sun 	/* Erratum applies when accumulated ECC is used, or DBI is enabled */
210dda3b610SYork Sun #define IS_ACC_ECC_EN(v) ((v) & 0x4)
211dda3b610SYork Sun #define IS_DBI(v) ((((v) >> 12) & 0x3) == 0x2)
212dda3b610SYork Sun 	if (IS_ACC_ECC_EN(regs->ddr_sdram_cfg) ||
213dda3b610SYork Sun 	    IS_DBI(regs->ddr_sdram_cfg_3))
214dda3b610SYork Sun 		ddr_setbits32(ddr->debug[28], 0x9 << 20);
215dda3b610SYork Sun #endif
21634e026f9SYork Sun 
21734e026f9SYork Sun 	/*
21834e026f9SYork Sun 	 * For RDIMMs, JEDEC spec requires clocks to be stable before reset is
21934e026f9SYork Sun 	 * deasserted. Clocks start when any chip select is enabled and clock
22034e026f9SYork Sun 	 * control register is set. Because all DDR components are connected to
22134e026f9SYork Sun 	 * one reset signal, this needs to be done in two steps. Step 1 is to
22234e026f9SYork Sun 	 * get the clocks started. Step 2 resumes after reset signal is
22334e026f9SYork Sun 	 * deasserted.
22434e026f9SYork Sun 	 */
22534e026f9SYork Sun 	if (step == 1) {
22634e026f9SYork Sun 		udelay(200);
22734e026f9SYork Sun 		return;
22834e026f9SYork Sun 	}
22934e026f9SYork Sun 
23034e026f9SYork Sun step2:
23134e026f9SYork Sun 	/* Set, but do not enable the memory */
23234e026f9SYork Sun 	temp_sdram_cfg = regs->ddr_sdram_cfg;
23334e026f9SYork Sun 	temp_sdram_cfg &= ~(SDRAM_CFG_MEM_EN);
23434e026f9SYork Sun 	ddr_out32(&ddr->sdram_cfg, temp_sdram_cfg);
23534e026f9SYork Sun 
23634e026f9SYork Sun 	/*
23734e026f9SYork Sun 	 * 500 painful micro-seconds must elapse between
23834e026f9SYork Sun 	 * the DDR clock setup and the DDR config enable.
23934e026f9SYork Sun 	 * DDR2 need 200 us, and DDR3 need 500 us from spec,
24034e026f9SYork Sun 	 * we choose the max, that is 500 us for all of case.
24134e026f9SYork Sun 	 */
24234e026f9SYork Sun 	udelay(500);
2438340e7acSYork Sun 	mb();
2448340e7acSYork Sun 	isb();
24534e026f9SYork Sun 
246a7787b78STang Yuantian #ifdef CONFIG_DEEP_SLEEP
247a7787b78STang Yuantian 	if (is_warm_boot()) {
248a7787b78STang Yuantian 		/* enter self-refresh */
249a7787b78STang Yuantian 		temp_sdram_cfg = ddr_in32(&ddr->sdram_cfg_2);
250a7787b78STang Yuantian 		temp_sdram_cfg |= SDRAM_CFG2_FRC_SR;
251a7787b78STang Yuantian 		ddr_out32(&ddr->sdram_cfg_2, temp_sdram_cfg);
252a7787b78STang Yuantian 		/* do board specific memory setup */
253a7787b78STang Yuantian 		board_mem_sleep_setup();
254a7787b78STang Yuantian 
255a7787b78STang Yuantian 		temp_sdram_cfg = (ddr_in32(&ddr->sdram_cfg) | SDRAM_CFG_BI);
256a7787b78STang Yuantian 	} else
257a7787b78STang Yuantian #endif
25834e026f9SYork Sun 		temp_sdram_cfg = ddr_in32(&ddr->sdram_cfg) & ~SDRAM_CFG_BI;
259a7787b78STang Yuantian 	/* Let the controller go */
26034e026f9SYork Sun 	ddr_out32(&ddr->sdram_cfg, temp_sdram_cfg | SDRAM_CFG_MEM_EN);
2618340e7acSYork Sun 	mb();
2628340e7acSYork Sun 	isb();
26334e026f9SYork Sun 
26434e026f9SYork Sun 	total_gb_size_per_controller = 0;
26534e026f9SYork Sun 	for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
26634e026f9SYork Sun 		if (!(regs->cs[i].config & 0x80000000))
26734e026f9SYork Sun 			continue;
26834e026f9SYork Sun 		total_gb_size_per_controller += 1 << (
26934e026f9SYork Sun 			((regs->cs[i].config >> 14) & 0x3) + 2 +
27034e026f9SYork Sun 			((regs->cs[i].config >> 8) & 0x7) + 12 +
27134e026f9SYork Sun 			((regs->cs[i].config >> 4) & 0x3) + 0 +
27234e026f9SYork Sun 			((regs->cs[i].config >> 0) & 0x7) + 8 +
27334e026f9SYork Sun 			3 - ((regs->ddr_sdram_cfg >> 19) & 0x3) -
27434e026f9SYork Sun 			26);			/* minus 26 (count of 64M) */
27534e026f9SYork Sun 	}
27634e026f9SYork Sun 	if (fsl_ddr_get_intl3r() & 0x80000000)	/* 3-way interleaving */
27734e026f9SYork Sun 		total_gb_size_per_controller *= 3;
27834e026f9SYork Sun 	else if (regs->cs[0].config & 0x20000000) /* 2-way interleaving */
27934e026f9SYork Sun 		total_gb_size_per_controller <<= 1;
28034e026f9SYork Sun 	/*
28134e026f9SYork Sun 	 * total memory / bus width = transactions needed
28234e026f9SYork Sun 	 * transactions needed / data rate = seconds
28334e026f9SYork Sun 	 * to add plenty of buffer, double the time
28434e026f9SYork Sun 	 * For example, 2GB on 666MT/s 64-bit bus takes about 402ms
28534e026f9SYork Sun 	 * Let's wait for 800ms
28634e026f9SYork Sun 	 */
287f80d6472SYork Sun 	bus_width = 3 - ((ddr_in32(&ddr->sdram_cfg) & SDRAM_CFG_DBW_MASK)
28834e026f9SYork Sun 			>> SDRAM_CFG_DBW_SHIFT);
28934e026f9SYork Sun 	timeout = ((total_gb_size_per_controller << (6 - bus_width)) * 100 /
290*03e664d8SYork Sun 		(get_ddr_freq(ctrl_num) >> 20)) << 2;
29134e026f9SYork Sun 	total_gb_size_per_controller >>= 4;	/* shift down to gb size */
29234e026f9SYork Sun 	debug("total %d GB\n", total_gb_size_per_controller);
29334e026f9SYork Sun 	debug("Need to wait up to %d * 10ms\n", timeout);
29434e026f9SYork Sun 
29534e026f9SYork Sun 	/* Poll DDR_SDRAM_CFG_2[D_INIT] bit until auto-data init is done.  */
29634e026f9SYork Sun 	while ((ddr_in32(&ddr->sdram_cfg_2) & SDRAM_CFG2_D_INIT) &&
29734e026f9SYork Sun 		(timeout >= 0)) {
29834e026f9SYork Sun 		udelay(10000);		/* throttle polling rate */
29934e026f9SYork Sun 		timeout--;
30034e026f9SYork Sun 	}
30134e026f9SYork Sun 
30234e026f9SYork Sun 	if (timeout <= 0)
30334e026f9SYork Sun 		printf("Waiting for D_INIT timeout. Memory may not work.\n");
304a7787b78STang Yuantian #ifdef CONFIG_DEEP_SLEEP
305a7787b78STang Yuantian 	if (is_warm_boot()) {
306a7787b78STang Yuantian 		/* exit self-refresh */
307a7787b78STang Yuantian 		temp_sdram_cfg = ddr_in32(&ddr->sdram_cfg_2);
308a7787b78STang Yuantian 		temp_sdram_cfg &= ~SDRAM_CFG2_FRC_SR;
309a7787b78STang Yuantian 		ddr_out32(&ddr->sdram_cfg_2, temp_sdram_cfg);
310a7787b78STang Yuantian 	}
311a7787b78STang Yuantian #endif
31234e026f9SYork Sun }
313