blob: baf70d8807b0b7265d4517c124397a46d583bb9d [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Yanokbc8f8c22010-09-17 23:41:50 +02002/*
3 * Copyright (C) 2007 Freescale Semiconductor, Inc.
4 * Copyright (C) 2010 Ilya Yanok, Emcraft Systems, yanok@emcraft.com
5 *
6 * This files is mostly identical to the original from
7 * board/freescale/mpc8308rdb/sdram.c
Ilya Yanokbc8f8c22010-09-17 23:41:50 +02008 */
9
10#include <common.h>
11#include <mpc83xx.h>
12
13#include <asm/bitops.h>
14#include <asm/io.h>
15
16#include <asm/processor.h>
17
18DECLARE_GLOBAL_DATA_PTR;
19
20/* Fixed sdram init -- doesn't use serial presence detect.
21 *
22 * This is useful for faster booting in configs where the RAM is unlikely
23 * to be changed, or for things like NAND booting where space is tight.
24 */
25static long fixed_sdram(void)
26{
27 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
28 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
29 u32 msize_log2 = __ilog2(msize);
30
31 out_be32(&im->sysconf.ddrlaw[0].bar,
Mario Six133ec602019-01-21 09:18:16 +010032 CONFIG_SYS_SDRAM_BASE & 0xfffff000);
Ilya Yanokbc8f8c22010-09-17 23:41:50 +020033 out_be32(&im->sysconf.ddrlaw[0].ar, LBLAWAR_EN | (msize_log2 - 1));
34 out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
35
36 out_be32(&im->ddr.csbnds[0].csbnds, (msize - 1) >> 24);
37 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
38
39 /* Currently we use only one CS, so disable the other bank. */
40 out_be32(&im->ddr.cs_config[1], 0);
41
42 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_SDRAM_CLK_CNTL);
43 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
44 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
45 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
46 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
47
48 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
49 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
50 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
51 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
52
53 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
54 sync();
55
56 /* enable DDR controller */
57 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
58 sync();
59
Mario Six133ec602019-01-21 09:18:16 +010060 return get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Ilya Yanokbc8f8c22010-09-17 23:41:50 +020061}
62
Simon Glassf1683aa2017-04-06 12:47:05 -060063int dram_init(void)
Ilya Yanokbc8f8c22010-09-17 23:41:50 +020064{
65 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
66 u32 msize;
67
68 if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
69 return -1;
70
71 /* DDR SDRAM */
72 msize = fixed_sdram();
73
Simon Glass088454c2017-03-31 08:40:25 -060074 /* set total bus SDRAM size(bytes) -- DDR */
75 gd->ram_size = msize;
76
77 return 0;
Ilya Yanokbc8f8c22010-09-17 23:41:50 +020078}