blob: 6340fd16ea9b38f024b18379845000fe19839769 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanok89847ef2010-07-07 20:16:13 +04002/*
3 * Copyright (C) 2007 Freescale Semiconductor, Inc.
4 * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
5 *
6 * Authors: Nick.Spence@freescale.com
7 * Wilson.Lo@freescale.com
8 * scottwood@freescale.com
9 *
10 * This files is mostly identical to the original from
11 * board\freescale\mpc8315erdb\sdram.c
Ilya Yanok89847ef2010-07-07 20:16:13 +040012 */
13
14#include <common.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070015#include <init.h>
Ilya Yanok89847ef2010-07-07 20:16:13 +040016#include <mpc83xx.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Ilya Yanok89847ef2010-07-07 20:16:13 +040018
19#include <asm/bitops.h>
20#include <asm/io.h>
21
22#include <asm/processor.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
Ilya Yanok89847ef2010-07-07 20:16:13 +040026/* Fixed sdram init -- doesn't use serial presence detect.
27 *
28 * This is useful for faster booting in configs where the RAM is unlikely
29 * to be changed, or for things like NAND booting where space is tight.
30 */
31static long fixed_sdram(void)
32{
33 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
34 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
35 u32 msize_log2 = __ilog2(msize);
36
37 out_be32(&im->sysconf.ddrlaw[0].bar,
Mario Six805cac12019-01-21 09:18:16 +010038 CONFIG_SYS_SDRAM_BASE & 0xfffff000);
Ilya Yanok89847ef2010-07-07 20:16:13 +040039 out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1));
40 out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
41
Ilya Yanok89847ef2010-07-07 20:16:13 +040042 out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
43 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
44
45 /* Currently we use only one CS, so disable the other bank. */
46 out_be32(&im->ddr.cs_config[1], 0);
47
48 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
49 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
50 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
51 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
52 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
53
Ilya Yanokdbdc1052010-09-17 23:41:49 +020054 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
Ilya Yanok89847ef2010-07-07 20:16:13 +040055 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
56 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
57 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
58
59 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
60 sync();
61
62 /* enable DDR controller */
63 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
64 sync();
65
Mario Six805cac12019-01-21 09:18:16 +010066 return get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Ilya Yanok89847ef2010-07-07 20:16:13 +040067}
68
Simon Glassd35f3382017-04-06 12:47:05 -060069int dram_init(void)
Ilya Yanok89847ef2010-07-07 20:16:13 +040070{
71 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
72 u32 msize;
73
74 if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
Simon Glass39f90ba2017-03-31 08:40:25 -060075 return -ENXIO;
Ilya Yanok89847ef2010-07-07 20:16:13 +040076
77 /* DDR SDRAM */
78 msize = fixed_sdram();
79
Ilya Yanok89847ef2010-07-07 20:16:13 +040080 /* return total bus SDRAM size(bytes) -- DDR */
Simon Glass39f90ba2017-03-31 08:40:25 -060081 gd->ram_size = msize;
82
83 return 0;
Ilya Yanok89847ef2010-07-07 20:16:13 +040084}