xref: /rk3399_rockchip-uboot/board/freescale/p1_twr/ddr.c (revision f15ea6e1d67782a1626d4a4922b6c20e380085e5)
149f5befaSXie Xiaobo /*
249f5befaSXie Xiaobo  * Copyright 2013 Freescale Semiconductor, Inc.
349f5befaSXie Xiaobo  *
43aab0cd8SYork Sun  * SPDX-License-Identifier:	GPL-2.0+
549f5befaSXie Xiaobo  */
649f5befaSXie Xiaobo 
749f5befaSXie Xiaobo #include <common.h>
849f5befaSXie Xiaobo #include <asm/mmu.h>
949f5befaSXie Xiaobo #include <asm/immap_85xx.h>
1049f5befaSXie Xiaobo #include <asm/processor.h>
11*5614e71bSYork Sun #include <fsl_ddr_sdram.h>
12*5614e71bSYork Sun #include <fsl_ddr_dimm_params.h>
1349f5befaSXie Xiaobo #include <asm/io.h>
1449f5befaSXie Xiaobo #include <asm/fsl_law.h>
1549f5befaSXie Xiaobo 
1649f5befaSXie Xiaobo /* Fixed sdram init -- doesn't use serial presence detect. */
fixed_sdram(void)1749f5befaSXie Xiaobo phys_size_t fixed_sdram(void)
1849f5befaSXie Xiaobo {
1949f5befaSXie Xiaobo 	sys_info_t sysinfo;
2049f5befaSXie Xiaobo 	char buf[32];
2149f5befaSXie Xiaobo 	size_t ddr_size;
2249f5befaSXie Xiaobo 	fsl_ddr_cfg_regs_t ddr_cfg_regs = {
2349f5befaSXie Xiaobo 		.cs[0].bnds = CONFIG_SYS_DDR_CS0_BNDS,
2449f5befaSXie Xiaobo 		.cs[0].config = CONFIG_SYS_DDR_CS0_CONFIG,
2549f5befaSXie Xiaobo 		.cs[0].config_2 = CONFIG_SYS_DDR_CS0_CONFIG_2,
2649f5befaSXie Xiaobo #if CONFIG_CHIP_SELECTS_PER_CTRL > 1
2749f5befaSXie Xiaobo 		.cs[1].bnds = CONFIG_SYS_DDR_CS1_BNDS,
2849f5befaSXie Xiaobo 		.cs[1].config = CONFIG_SYS_DDR_CS1_CONFIG,
2949f5befaSXie Xiaobo 		.cs[1].config_2 = CONFIG_SYS_DDR_CS1_CONFIG_2,
3049f5befaSXie Xiaobo #endif
3149f5befaSXie Xiaobo 		.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3,
3249f5befaSXie Xiaobo 		.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0,
3349f5befaSXie Xiaobo 		.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1,
3449f5befaSXie Xiaobo 		.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2,
3549f5befaSXie Xiaobo 		.ddr_sdram_cfg = CONFIG_SYS_DDR_CONTROL,
3649f5befaSXie Xiaobo 		.ddr_sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL_2,
3749f5befaSXie Xiaobo 		.ddr_sdram_mode = CONFIG_SYS_DDR_MODE_1,
3849f5befaSXie Xiaobo 		.ddr_sdram_mode_2 = CONFIG_SYS_DDR_MODE_2,
3949f5befaSXie Xiaobo 		.ddr_sdram_md_cntl = CONFIG_SYS_DDR_MODE_CONTROL,
4049f5befaSXie Xiaobo 		.ddr_sdram_interval = CONFIG_SYS_DDR_INTERVAL,
4149f5befaSXie Xiaobo 		.ddr_data_init = CONFIG_SYS_DDR_DATA_INIT,
4249f5befaSXie Xiaobo 		.ddr_sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL,
4349f5befaSXie Xiaobo 		.ddr_init_addr = CONFIG_SYS_DDR_INIT_ADDR,
4449f5befaSXie Xiaobo 		.ddr_init_ext_addr = CONFIG_SYS_DDR_INIT_EXT_ADDR,
4549f5befaSXie Xiaobo 		.timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4,
4649f5befaSXie Xiaobo 		.timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5,
4749f5befaSXie Xiaobo 		.ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CONTROL,
4849f5befaSXie Xiaobo 		.ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CONTROL,
4949f5befaSXie Xiaobo 		.ddr_sr_cntr = CONFIG_SYS_DDR_SR_CNTR,
5049f5befaSXie Xiaobo 		.ddr_sdram_rcw_1 = CONFIG_SYS_DDR_RCW_1,
5149f5befaSXie Xiaobo 		.ddr_sdram_rcw_2 = CONFIG_SYS_DDR_RCW_2
5249f5befaSXie Xiaobo 	};
5349f5befaSXie Xiaobo 
5449f5befaSXie Xiaobo 	get_sys_info(&sysinfo);
5549f5befaSXie Xiaobo 	printf("Configuring DDR for %s MT/s data rate\n",
56997399faSPrabhakar Kushwaha 			strmhz(buf, sysinfo.freq_ddrbus));
5749f5befaSXie Xiaobo 
5849f5befaSXie Xiaobo 	ddr_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
5949f5befaSXie Xiaobo 
60c63e1370SYork Sun 	fsl_ddr_set_memctl_regs(&ddr_cfg_regs, 0, 0);
6149f5befaSXie Xiaobo 
6249f5befaSXie Xiaobo 	if (set_ddr_laws(CONFIG_SYS_DDR_SDRAM_BASE,
6349f5befaSXie Xiaobo 				ddr_size, LAW_TRGT_IF_DDR_1) < 0) {
6449f5befaSXie Xiaobo 		printf("ERROR setting Local Access Windows for DDR\n");
6549f5befaSXie Xiaobo 		return 0;
6649f5befaSXie Xiaobo 	};
6749f5befaSXie Xiaobo 
6849f5befaSXie Xiaobo 	return ddr_size;
6949f5befaSXie Xiaobo }
70