blob: 15c934d29b25062509c43ae73880501d93c5e0b2 [file] [log] [blame]
wdenk5e5f9ed2005-04-13 23:15:10 +00001/*
2 * (C) Copyright 2005
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenkb2323ea2005-04-20 09:28:54 +00005 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
wdenk5e5f9ed2005-04-13 23:15:10 +00007 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk5e5f9ed2005-04-13 23:15:10 +00009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
13#include <pci.h>
14
wdenkb2323ea2005-04-20 09:28:54 +000015#if defined(CONFIG_MPC5200_DDR)
16#include "mt46v16m16-75.h"
17#else
18#include "mt48lc16m32s2-75.h"
19#endif
20
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020021#ifndef CONFIG_SYS_RAMBOOT
wdenkb2323ea2005-04-20 09:28:54 +000022static void sdram_start (int hi_addr)
23{
24 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
25
26 /* unlock mode register */
27 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
28 __asm__ volatile ("sync");
29
30 /* precharge all banks */
31 *(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");
42#endif
43
44 /* precharge all banks */
45 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
46 __asm__ volatile ("sync");
47
48 /* auto refresh */
49 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
50 __asm__ volatile ("sync");
51
52 /* set mode register */
53 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
54 __asm__ volatile ("sync");
55
56 /* normal operation */
57 *(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-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenkb2323ea2005-04-20 09:28:54 +000065 * is something else than 0x00000000.
66 */
67
Becky Bruce9973e3c2008-06-09 16:03:40 -050068phys_size_t initdram (int board_type)
wdenkb2323ea2005-04-20 09:28:54 +000069{
70 ulong dramsize = 0;
71 ulong dramsize2 = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072#ifndef CONFIG_SYS_RAMBOOT
wdenkb2323ea2005-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 Denkff377b12010-09-19 12:59:41 +020093 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb2323ea2005-04-20 09:28:54 +000094 sdram_start(1);
Wolfgang Denkff377b12010-09-19 12:59:41 +020095 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb2323ea2005-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 */
wdenk07cc0992005-05-05 00:04:14 +0000119 if (!dramsize)
wdenka6310922005-04-21 21:10:22 +0000120 sdram_start(0);
Wolfgang Denkff377b12010-09-19 12:59:41 +0200121 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenka6310922005-04-21 21:10:22 +0000122 if (!dramsize) {
123 sdram_start(1);
Wolfgang Denkff377b12010-09-19 12:59:41 +0200124 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenka6310922005-04-21 21:10:22 +0000125 }
wdenkb2323ea2005-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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200146#else /* CONFIG_SYS_RAMBOOT */
wdenkb2323ea2005-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 }
163
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200164#endif /* CONFIG_SYS_RAMBOOT */
wdenkb2323ea2005-04-20 09:28:54 +0000165
166 return dramsize + dramsize2;
167}
168
wdenk5e5f9ed2005-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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200179 *(vu_long *)MPC5XXX_CS0_START = START_REG(CONFIG_SYS_FLASH_BASE);
wdenk5e5f9ed2005-04-13 23:15:10 +0000180 *(vu_long *)MPC5XXX_BOOTCS_STOP =
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200181 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE);
wdenk5e5f9ed2005-04-13 23:15:10 +0000182 return 0;
183}