]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
96b8a054 SW |
2 | /* |
3 | * Copyright (C) Freescale Semiconductor, Inc. 2006-2007 | |
4 | * | |
5 | * Authors: [email protected] | |
6 | * [email protected] | |
7 | * [email protected] | |
96b8a054 SW |
8 | */ |
9 | ||
10 | #include <common.h> | |
11 | #include <mpc83xx.h> | |
12 | #include <spd_sdram.h> | |
13 | ||
14 | #include <asm/bitops.h> | |
15 | #include <asm/io.h> | |
16 | ||
17 | #include <asm/processor.h> | |
18 | ||
1218abf1 WD |
19 | DECLARE_GLOBAL_DATA_PTR; |
20 | ||
6d0f6bcf | 21 | #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC |
96b8a054 SW |
22 | static void resume_from_sleep(void) |
23 | { | |
96b8a054 SW |
24 | u32 magic = *(u32 *)0; |
25 | ||
26 | typedef void (*func_t)(void); | |
27 | func_t resume = *(func_t *)4; | |
28 | ||
29 | if (magic == 0xf5153ae5) | |
30 | resume(); | |
31 | ||
32 | gd->flags &= ~GD_FLG_SILENT; | |
33 | puts("\nResume from sleep failed: bad magic word\n"); | |
34 | } | |
35 | #endif | |
36 | ||
37 | /* Fixed sdram init -- doesn't use serial presence detect. | |
38 | * | |
39 | * This is useful for faster booting in configs where the RAM is unlikely | |
40 | * to be changed, or for things like NAND booting where space is tight. | |
41 | */ | |
42 | static long fixed_sdram(void) | |
43 | { | |
6d0f6bcf | 44 | u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
e4c09508 | 45 | |
6d0f6bcf JCPV |
46 | #ifndef CONFIG_SYS_RAMBOOT |
47 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; | |
96b8a054 SW |
48 | u32 msize_log2 = __ilog2(msize); |
49 | ||
6d0f6bcf | 50 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
96b8a054 | 51 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
6d0f6bcf | 52 | im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; |
96b8a054 SW |
53 | |
54 | /* | |
55 | * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg], | |
56 | * or the DDR2 controller may fail to initialize correctly. | |
57 | */ | |
3eb90bad | 58 | __udelay(50000); |
96b8a054 | 59 | |
2e651b24 JH |
60 | #if ((CONFIG_SYS_DDR_SDRAM_BASE & 0x00FFFFFF) != 0) |
61 | #warning Chip select bounds is only configurable in 16MB increments | |
62 | #endif | |
63 | im->ddr.csbnds[0].csbnds = | |
64 | ((CONFIG_SYS_DDR_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) | | |
65 | (((CONFIG_SYS_DDR_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) & | |
66 | CSBNDS_EA); | |
67 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; | |
96b8a054 SW |
68 | |
69 | /* Currently we use only one CS, so disable the other bank. */ | |
70 | im->ddr.cs_config[1] = 0; | |
71 | ||
6d0f6bcf JCPV |
72 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL; |
73 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; | |
74 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; | |
75 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; | |
76 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; | |
96b8a054 | 77 | |
6d0f6bcf | 78 | #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC |
96b8a054 | 79 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
6d0f6bcf | 80 | im->ddr.sdram_cfg = CONFIG_SYS_SDRAM_CFG | SDRAM_CFG_BI; |
96b8a054 SW |
81 | else |
82 | #endif | |
6d0f6bcf | 83 | im->ddr.sdram_cfg = CONFIG_SYS_SDRAM_CFG; |
96b8a054 | 84 | |
6d0f6bcf JCPV |
85 | im->ddr.sdram_cfg2 = CONFIG_SYS_SDRAM_CFG2; |
86 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; | |
87 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE_2; | |
96b8a054 | 88 | |
6d0f6bcf | 89 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
96b8a054 SW |
90 | sync(); |
91 | ||
92 | /* enable DDR controller */ | |
93 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; | |
e4c09508 | 94 | #endif |
96b8a054 SW |
95 | |
96 | return msize; | |
97 | } | |
98 | ||
f1683aa7 | 99 | int dram_init(void) |
96b8a054 | 100 | { |
6d0f6bcf | 101 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
f51cdaf1 | 102 | volatile fsl_lbc_t *lbc = &im->im_lbc; |
96b8a054 SW |
103 | u32 msize; |
104 | ||
105 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im) | |
088454cd | 106 | return -ENXIO; |
96b8a054 | 107 | |
96b8a054 SW |
108 | /* DDR SDRAM - Main SODIMM */ |
109 | msize = fixed_sdram(); | |
110 | ||
111 | /* Local Bus setup lbcr and mrtpr */ | |
6d0f6bcf JCPV |
112 | lbc->lbcr = CONFIG_SYS_LBC_LBCR; |
113 | lbc->mrtpr = CONFIG_SYS_LBC_MRTPR; | |
96b8a054 SW |
114 | sync(); |
115 | ||
6d0f6bcf | 116 | #ifndef CONFIG_SYS_8313ERDB_BROKEN_PMC |
96b8a054 SW |
117 | if (im->pmc.pmccr1 & PMCCR1_POWER_OFF) |
118 | resume_from_sleep(); | |
119 | #endif | |
120 | ||
96b8a054 | 121 | /* return total bus SDRAM size(bytes) -- DDR */ |
088454cd SG |
122 | gd->ram_size = msize; |
123 | ||
124 | return 0; | |
96b8a054 | 125 | } |