blob: 54de0e267383db0e891cb637ec380f21c9914125 [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
Simon Glass39f90ba2017-03-31 08:40:25 -060021DECLARE_GLOBAL_DATA_PTR;
22
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023#ifndef CONFIG_SYS_RAMBOOT
wdenkb21608e2005-04-20 09:28:54 +000024static void sdram_start (int hi_addr)
25{
26 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
wdenkf1d0ff42005-04-13 23:15:10 +000027
28 /* unlock mode register */
wdenkb21608e2005-04-20 09:28:54 +000029 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
30 __asm__ volatile ("sync");
31
wdenkf1d0ff42005-04-13 23:15:10 +000032 /* precharge all banks */
wdenkb21608e2005-04-20 09:28:54 +000033 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
34 __asm__ volatile ("sync");
35
36#if SDRAM_DDR
37 /* set mode register: extended mode */
38 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
39 __asm__ volatile ("sync");
40
41 /* set mode register: reset DLL */
42 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
43 __asm__ volatile ("sync");
wdenkf1d0ff42005-04-13 23:15:10 +000044#endif
wdenkb21608e2005-04-20 09:28:54 +000045
wdenkf1d0ff42005-04-13 23:15:10 +000046 /* precharge all banks */
wdenkb21608e2005-04-20 09:28:54 +000047 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
48 __asm__ volatile ("sync");
49
wdenkf1d0ff42005-04-13 23:15:10 +000050 /* auto refresh */
wdenkb21608e2005-04-20 09:28:54 +000051 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
52 __asm__ volatile ("sync");
53
wdenkf1d0ff42005-04-13 23:15:10 +000054 /* set mode register */
wdenkb21608e2005-04-20 09:28:54 +000055 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
56 __asm__ volatile ("sync");
57
wdenkf1d0ff42005-04-13 23:15:10 +000058 /* normal operation */
wdenkb21608e2005-04-20 09:28:54 +000059 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
60 __asm__ volatile ("sync");
61}
62#endif
63
64/*
Simon Glassd35f3382017-04-06 12:47:05 -060065 * ATTENTION: Although partially referenced dram_init does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenkb21608e2005-04-20 09:28:54 +000067 * is something else than 0x00000000.
68 */
69
Simon Glassd35f3382017-04-06 12:47:05 -060070int dram_init(void)
wdenkb21608e2005-04-20 09:28:54 +000071{
72 ulong dramsize = 0;
73 ulong dramsize2 = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020074#ifndef CONFIG_SYS_RAMBOOT
wdenkb21608e2005-04-20 09:28:54 +000075 ulong test1, test2;
76
77 /* setup SDRAM chip selects */
78 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
79 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
80 __asm__ volatile ("sync");
81
82 /* setup config registers */
83 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
84 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
85 __asm__ volatile ("sync");
86
87#if SDRAM_DDR
88 /* set tap delay */
89 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
90 __asm__ volatile ("sync");
91#endif
92
93 /* find RAM size using SDRAM CS0 only */
94 sdram_start(0);
Wolfgang Denk17e1e782010-09-19 12:59:41 +020095 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb21608e2005-04-20 09:28:54 +000096 sdram_start(1);
Wolfgang Denk17e1e782010-09-19 12:59:41 +020097 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenkb21608e2005-04-20 09:28:54 +000098 if (test1 > test2) {
99 sdram_start(0);
100 dramsize = test1;
101 } else {
102 dramsize = test2;
103 }
104
105 /* memory smaller than 1MB is impossible */
106 if (dramsize < (1 << 20)) {
107 dramsize = 0;
108 }
109
110 /* set SDRAM CS0 size according to the amount of RAM found */
111 if (dramsize > 0) {
112 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
113 } else {
114 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
115 }
116
117 /* let SDRAM CS1 start right after CS0 */
118 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
119
120 /* find RAM size using SDRAM CS1 only */
wdenke84ec902005-05-05 00:04:14 +0000121 if (!dramsize)
wdenkfaaa6022005-04-21 21:10:22 +0000122 sdram_start(0);
Wolfgang Denk17e1e782010-09-19 12:59:41 +0200123 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000124 if (!dramsize) {
125 sdram_start(1);
Wolfgang Denk17e1e782010-09-19 12:59:41 +0200126 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000127 }
wdenkb21608e2005-04-20 09:28:54 +0000128 if (test1 > test2) {
129 sdram_start(0);
130 dramsize2 = test1;
131 } else {
132 dramsize2 = test2;
133 }
134
135 /* memory smaller than 1MB is impossible */
136 if (dramsize2 < (1 << 20)) {
137 dramsize2 = 0;
138 }
139
140 /* set SDRAM CS1 size according to the amount of RAM found */
141 if (dramsize2 > 0) {
142 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
143 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
144 } else {
145 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
146 }
147
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148#else /* CONFIG_SYS_RAMBOOT */
wdenkb21608e2005-04-20 09:28:54 +0000149
150 /* retrieve size of memory connected to SDRAM CS0 */
151 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
152 if (dramsize >= 0x13) {
153 dramsize = (1 << (dramsize - 0x13)) << 20;
154 } else {
155 dramsize = 0;
156 }
157
158 /* retrieve size of memory connected to SDRAM CS1 */
159 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
160 if (dramsize2 >= 0x13) {
161 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
162 } else {
163 dramsize2 = 0;
164 }
wdenkf1d0ff42005-04-13 23:15:10 +0000165
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166#endif /* CONFIG_SYS_RAMBOOT */
wdenkf1d0ff42005-04-13 23:15:10 +0000167
Simon Glass39f90ba2017-03-31 08:40:25 -0600168 gd->ram_size = dramsize + dramsize2;
169
170 return 0;
wdenkb21608e2005-04-20 09:28:54 +0000171}
172
wdenkf1d0ff42005-04-13 23:15:10 +0000173int checkboard (void)
174{
175 puts ("Board: CANMB\n");
176 return 0;
177}
178
179int board_early_init_r (void)
180{
181 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
182 *(vu_long *)MPC5XXX_BOOTCS_START =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200183 *(vu_long *)MPC5XXX_CS0_START = START_REG(CONFIG_SYS_FLASH_BASE);
wdenkf1d0ff42005-04-13 23:15:10 +0000184 *(vu_long *)MPC5XXX_BOOTCS_STOP =
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200185 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE);
wdenkf1d0ff42005-04-13 23:15:10 +0000186 return 0;
187}