xref: /rk3399_rockchip-uboot/board/mpc8308_p1m/sdram.c (revision bc8f8c2614c8e104a66198633d8d765b720ed907)
1*bc8f8c26SIlya Yanok /*
2*bc8f8c26SIlya Yanok  * Copyright (C) 2007 Freescale Semiconductor, Inc.
3*bc8f8c26SIlya Yanok  * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
4*bc8f8c26SIlya Yanok  *
5*bc8f8c26SIlya Yanok  * This files is  mostly identical to the original from
6*bc8f8c26SIlya Yanok  * board/freescale/mpc8308rdb/sdram.c
7*bc8f8c26SIlya Yanok  *
8*bc8f8c26SIlya Yanok  * See file CREDITS for list of people who contributed to this
9*bc8f8c26SIlya Yanok  * project.
10*bc8f8c26SIlya Yanok  *
11*bc8f8c26SIlya Yanok  * This program is free software; you can redistribute it and/or
12*bc8f8c26SIlya Yanok  * modify it under the terms of the GNU General Public License as
13*bc8f8c26SIlya Yanok  * published by the Free Software Foundation; either version 2 of
14*bc8f8c26SIlya Yanok  * the License, or (at your option) any later version.
15*bc8f8c26SIlya Yanok  *
16*bc8f8c26SIlya Yanok  * This program is distributed in the hope that it will be useful,
17*bc8f8c26SIlya Yanok  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18*bc8f8c26SIlya Yanok  * MERCHANTABILITY or FITNESS for A PARTICULAR PURPOSE.  See the
19*bc8f8c26SIlya Yanok  * GNU General Public License for more details.
20*bc8f8c26SIlya Yanok  *
21*bc8f8c26SIlya Yanok  * You should have received a copy of the GNU General Public License
22*bc8f8c26SIlya Yanok  * along with this program; if not, write to the Free Software
23*bc8f8c26SIlya Yanok  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24*bc8f8c26SIlya Yanok  * MA 02111-1307 USA
25*bc8f8c26SIlya Yanok  */
26*bc8f8c26SIlya Yanok 
27*bc8f8c26SIlya Yanok #include <common.h>
28*bc8f8c26SIlya Yanok #include <mpc83xx.h>
29*bc8f8c26SIlya Yanok 
30*bc8f8c26SIlya Yanok #include <asm/bitops.h>
31*bc8f8c26SIlya Yanok #include <asm/io.h>
32*bc8f8c26SIlya Yanok 
33*bc8f8c26SIlya Yanok #include <asm/processor.h>
34*bc8f8c26SIlya Yanok 
35*bc8f8c26SIlya Yanok DECLARE_GLOBAL_DATA_PTR;
36*bc8f8c26SIlya Yanok 
37*bc8f8c26SIlya Yanok /* Fixed sdram init -- doesn't use serial presence detect.
38*bc8f8c26SIlya Yanok  *
39*bc8f8c26SIlya Yanok  * This is useful for faster booting in configs where the RAM is unlikely
40*bc8f8c26SIlya Yanok  * to be changed, or for things like NAND booting where space is tight.
41*bc8f8c26SIlya Yanok  */
42*bc8f8c26SIlya Yanok static long fixed_sdram(void)
43*bc8f8c26SIlya Yanok {
44*bc8f8c26SIlya Yanok 	immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
45*bc8f8c26SIlya Yanok 	u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
46*bc8f8c26SIlya Yanok 	u32 msize_log2 = __ilog2(msize);
47*bc8f8c26SIlya Yanok 
48*bc8f8c26SIlya Yanok 	out_be32(&im->sysconf.ddrlaw[0].bar,
49*bc8f8c26SIlya Yanok 			CONFIG_SYS_DDR_SDRAM_BASE  & 0xfffff000);
50*bc8f8c26SIlya Yanok 	out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1));
51*bc8f8c26SIlya Yanok 	out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
52*bc8f8c26SIlya Yanok 
53*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
54*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
55*bc8f8c26SIlya Yanok 
56*bc8f8c26SIlya Yanok 	/* Currently we use only one CS, so disable the other bank. */
57*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.cs_config[1], 0);
58*bc8f8c26SIlya Yanok 
59*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
60*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
61*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
62*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
63*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
64*bc8f8c26SIlya Yanok 
65*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
66*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
67*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
68*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
69*bc8f8c26SIlya Yanok 
70*bc8f8c26SIlya Yanok 	out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
71*bc8f8c26SIlya Yanok 	sync();
72*bc8f8c26SIlya Yanok 
73*bc8f8c26SIlya Yanok 	/* enable DDR controller */
74*bc8f8c26SIlya Yanok 	setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
75*bc8f8c26SIlya Yanok 	sync();
76*bc8f8c26SIlya Yanok 
77*bc8f8c26SIlya Yanok 	return get_ram_size(CONFIG_SYS_DDR_SDRAM_BASE, msize);
78*bc8f8c26SIlya Yanok }
79*bc8f8c26SIlya Yanok 
80*bc8f8c26SIlya Yanok phys_size_t initdram(int board_type)
81*bc8f8c26SIlya Yanok {
82*bc8f8c26SIlya Yanok 	immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
83*bc8f8c26SIlya Yanok 	u32 msize;
84*bc8f8c26SIlya Yanok 
85*bc8f8c26SIlya Yanok 	if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
86*bc8f8c26SIlya Yanok 		return -1;
87*bc8f8c26SIlya Yanok 
88*bc8f8c26SIlya Yanok 	/* DDR SDRAM */
89*bc8f8c26SIlya Yanok 	msize = fixed_sdram();
90*bc8f8c26SIlya Yanok 
91*bc8f8c26SIlya Yanok 	/* return total bus SDRAM size(bytes)  -- DDR */
92*bc8f8c26SIlya Yanok 	return msize;
93*bc8f8c26SIlya Yanok }
94