blob: 15c934d29b25062509c43ae73880501d93c5e0b2 [file] [log] [blame]
wdenkf1d0ff42005-04-13 23:15:10 +00001/*
2 * (C) Copyright 2005
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenkb21608e2005-04-20 09:28:54 +00005 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
wdenkf1d0ff42005-04-13 23:15:10 +00007 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkf1d0ff42005-04-13 23:15:10 +00009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
13#include <pci.h>
14
wdenkb21608e2005-04-20 09:28:54 +000015#if defined(CONFIG_MPC5200_DDR)
16#include "mt46v16m16-75.h"
17#else
18#include "mt48lc16m32s2-75.h"
wdenkf1d0ff42005-04-13 23:15:10 +000019#endif
20
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020021#ifndef CONFIG_SYS_RAMBOOT
wdenkb21608e2005-04-20 09:28:54 +000022static void sdram_start (int hi_addr)
23{
24 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
wdenkf1d0ff42005-04-13 23:15:10 +000025
26 /* unlock mode register */
wdenkb21608e2005-04-20 09:28:54 +000027 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
28 __asm__ volatile ("sync");
29
wdenkf1d0ff42005-04-13 23:15:10 +000030 /* precharge all banks */
wdenkb21608e2005-04-20 09:28:54 +000031 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
32 __asm__ volatile ("sync");
33
34#if SDRAM_DDR
35 /* set mode register: extended mode */
36 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
37 __asm__ volatile ("sync");
38
39 /* set mode register: reset DLL */
40 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
41 __asm__ volatile ("sync");
wdenkf1d0ff42005-04-13 23:15:10 +000042#endif
wdenkb21608e2005-04-20 09:28:54 +000043
wdenkf1d0ff42005-04-13 23:15:10 +000044 /* precharge all banks */
wdenkb21608e2005-04-20 09:28:54 +000045 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
46 __asm__ volatile ("sync");
47
wdenkf1d0ff42005-04-13 23:15:10 +000048 /* auto refresh */
wdenkb21608e2005-04-20 09:28:54 +000049 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
50 __asm__ volatile ("sync");
51
wdenkf1d0ff42005-04-13 23:15:10 +000052 /* set mode register */
wdenkb21608e2005-04-20 09:28:54 +000053 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
54 __asm__ volatile ("sync");
55
wdenkf1d0ff42005-04-13 23:15:10 +000056 /* normal operation */
wdenkb21608e2005-04-20 09:28:54 +000057 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
58 __asm__ volatile ("sync");
59}
60#endif
61
62/*
63 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020064 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenkb21608e2005-04-20 09:28:54 +000065 * is something else than 0x00000000.
66 */
67
Becky Brucebd99ae72008-06-09 16:03:40 -050068phys_size_t initdram (int board_type)
wdenkb21608e2005-04-20 09:28:54 +000069{
70 ulong dramsize = 0;
71 ulong dramsize2 = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020072#ifndef CONFIG_SYS_RAMBOOT
wdenkb21608e2005-04-20 09:28:54 +000073 ulong test1, test2;
74
75 /* setup SDRAM chip selects */
76 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
77 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
78 __asm__ volatile ("sync");
79
80 /* setup config registers */
81 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
82 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
83 __asm__ volatile ("sync");
84
85#if SDRAM_DDR
86 /* set tap delay */
87 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
88 __asm__ volatile ("sync");
89#endif
90
91 /* find RAM size using SDRAM CS0 only */
92 sdram_start(0);
Wolfgang Denk17e1e782010-09-19 12:59:41 +020093 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb21608e2005-04-20 09:28:54 +000094 sdram_start(1);
Wolfgang Denk17e1e782010-09-19 12:59:41 +020095 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb21608e2005-04-20 09:28:54 +000096 if (test1 > test2) {
97 sdram_start(0);
98 dramsize = test1;
99 } else {
100 dramsize = test2;
101 }
102
103 /* memory smaller than 1MB is impossible */
104 if (dramsize < (1 << 20)) {
105 dramsize = 0;
106 }
107
108 /* set SDRAM CS0 size according to the amount of RAM found */
109 if (dramsize > 0) {
110 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
111 } else {
112 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
113 }
114
115 /* let SDRAM CS1 start right after CS0 */
116 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
117
118 /* find RAM size using SDRAM CS1 only */
wdenke84ec902005-05-05 00:04:14 +0000119 if (!dramsize)
wdenkfaaa6022005-04-21 21:10:22 +0000120 sdram_start(0);
Wolfgang Denk17e1e782010-09-19 12:59:41 +0200121 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000122 if (!dramsize) {
123 sdram_start(1);
Wolfgang Denk17e1e782010-09-19 12:59:41 +0200124 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000125 }
wdenkb21608e2005-04-20 09:28:54 +0000126 if (test1 > test2) {
127 sdram_start(0);
128 dramsize2 = test1;
129 } else {
130 dramsize2 = test2;
131 }
132
133 /* memory smaller than 1MB is impossible */
134 if (dramsize2 < (1 << 20)) {
135 dramsize2 = 0;
136 }
137
138 /* set SDRAM CS1 size according to the amount of RAM found */
139 if (dramsize2 > 0) {
140 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
141 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
142 } else {
143 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
144 }
145
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146#else /* CONFIG_SYS_RAMBOOT */
wdenkb21608e2005-04-20 09:28:54 +0000147
148 /* retrieve size of memory connected to SDRAM CS0 */
149 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
150 if (dramsize >= 0x13) {
151 dramsize = (1 << (dramsize - 0x13)) << 20;
152 } else {
153 dramsize = 0;
154 }
155
156 /* retrieve size of memory connected to SDRAM CS1 */
157 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
158 if (dramsize2 >= 0x13) {
159 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
160 } else {
161 dramsize2 = 0;
162 }
wdenkf1d0ff42005-04-13 23:15:10 +0000163
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164#endif /* CONFIG_SYS_RAMBOOT */
wdenkf1d0ff42005-04-13 23:15:10 +0000165
wdenkb21608e2005-04-20 09:28:54 +0000166 return dramsize + dramsize2;
167}
168
wdenkf1d0ff42005-04-13 23:15:10 +0000169int checkboard (void)
170{
171 puts ("Board: CANMB\n");
172 return 0;
173}
174
175int board_early_init_r (void)
176{
177 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
178 *(vu_long *)MPC5XXX_BOOTCS_START =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200179 *(vu_long *)MPC5XXX_CS0_START = START_REG(CONFIG_SYS_FLASH_BASE);
wdenkf1d0ff42005-04-13 23:15:10 +0000180 *(vu_long *)MPC5XXX_BOOTCS_STOP =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200181 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE);
wdenkf1d0ff42005-04-13 23:15:10 +0000182 return 0;
183}