blob: 4ec4505e8d0381c20e23f39660c8b5ae43918779 [file] [log] [blame]
wdenkc12081a2004-03-23 20:18:25 +00001/*
2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
wdenk9e930b62004-06-19 21:19:10 +00005 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenkc12081a2004-03-23 20:18:25 +00009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
13#include <pci.h>
Ben Warrenf2c1acb2008-08-31 10:03:22 -070014#include <netdev.h>
wdenkc12081a2004-03-23 20:18:25 +000015
wdenk9e930b62004-06-19 21:19:10 +000016#if defined(CONFIG_MPC5200_DDR)
17#include "mt46v16m16-75.h"
18#else
19#include "mt48lc16m16a2-75.h"
20#endif
wdenkc12081a2004-03-23 20:18:25 +000021
Wolfgang Denk6405a152006-03-31 18:32:53 +020022DECLARE_GLOBAL_DATA_PTR;
23
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020024#ifndef CONFIG_SYS_RAMBOOT
wdenkc12081a2004-03-23 20:18:25 +000025static void sdram_start (int hi_addr)
26{
27 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
28
29 /* unlock mode register */
wdenk9e930b62004-06-19 21:19:10 +000030 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
31 __asm__ volatile ("sync");
32
wdenkc12081a2004-03-23 20:18:25 +000033 /* precharge all banks */
wdenk9e930b62004-06-19 21:19:10 +000034 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
35 __asm__ volatile ("sync");
36
37#if SDRAM_DDR
38 /* set mode register: extended mode */
39 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
40 __asm__ volatile ("sync");
41
42 /* set mode register: reset DLL */
43 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
44 __asm__ volatile ("sync");
wdenkc12081a2004-03-23 20:18:25 +000045#endif
wdenk9e930b62004-06-19 21:19:10 +000046
wdenkc12081a2004-03-23 20:18:25 +000047 /* precharge all banks */
wdenk9e930b62004-06-19 21:19:10 +000048 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
49 __asm__ volatile ("sync");
50
wdenkc12081a2004-03-23 20:18:25 +000051 /* auto refresh */
wdenk9e930b62004-06-19 21:19:10 +000052 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
53 __asm__ volatile ("sync");
54
wdenkc12081a2004-03-23 20:18:25 +000055 /* set mode register */
wdenk9e930b62004-06-19 21:19:10 +000056 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
57 __asm__ volatile ("sync");
58
wdenkc12081a2004-03-23 20:18:25 +000059 /* normal operation */
wdenk9e930b62004-06-19 21:19:10 +000060 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
61 __asm__ volatile ("sync");
wdenkc12081a2004-03-23 20:18:25 +000062}
63#endif
64
wdenk9e930b62004-06-19 21:19:10 +000065/*
66 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020067 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenk9e930b62004-06-19 21:19:10 +000068 * is something else than 0x00000000.
69 */
70
Becky Brucebd99ae72008-06-09 16:03:40 -050071phys_size_t initdram (int board_type)
wdenkc12081a2004-03-23 20:18:25 +000072{
73 ulong dramsize = 0;
wdenk9e930b62004-06-19 21:19:10 +000074 ulong dramsize2 = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075#ifndef CONFIG_SYS_RAMBOOT
wdenkc12081a2004-03-23 20:18:25 +000076 ulong test1, test2;
77
wdenk9e930b62004-06-19 21:19:10 +000078 /* setup SDRAM chip selects */
wdenkc12081a2004-03-23 20:18:25 +000079 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;/* 2G at 0x0 */
80 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;/* disabled */
wdenk9e930b62004-06-19 21:19:10 +000081 __asm__ volatile ("sync");
wdenkc12081a2004-03-23 20:18:25 +000082
83 /* setup config registers */
wdenk9e930b62004-06-19 21:19:10 +000084 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
85 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
86 __asm__ volatile ("sync");
87
88#if SDRAM_DDR
89 /* set tap delay */
90 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
91 __asm__ volatile ("sync");
92#endif
93
94 /* find RAM size using SDRAM CS0 only */
95 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020096 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenk9e930b62004-06-19 21:19:10 +000097 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
wdenk9e930b62004-06-19 21:19:10 +000099 if (test1 > test2) {
100 sdram_start(0);
101 dramsize = test1;
102 } else {
103 dramsize = test2;
104 }
105
106 /* memory smaller than 1MB is impossible */
107 if (dramsize < (1 << 20)) {
108 dramsize = 0;
109 }
110
111 /* set SDRAM CS0 size according to the amount of RAM found */
112 if (dramsize > 0) {
113 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
114 } else {
115 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
116 }
117
118 /* let SDRAM CS1 start right after CS0 */
119 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
120
121 /* find RAM size using SDRAM CS1 only */
wdenke84ec902005-05-05 00:04:14 +0000122 if (!dramsize)
wdenkfaaa6022005-04-21 21:10:22 +0000123 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200124 test2 = test1 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000125 if (!dramsize) {
126 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127 test2 = get_ram_size((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x80000000);
wdenkfaaa6022005-04-21 21:10:22 +0000128 }
wdenk9e930b62004-06-19 21:19:10 +0000129 if (test1 > test2) {
130 sdram_start(0);
131 dramsize2 = test1;
132 } else {
133 dramsize2 = test2;
134 }
135
136 /* memory smaller than 1MB is impossible */
137 if (dramsize2 < (1 << 20)) {
138 dramsize2 = 0;
139 }
140
141 /* set SDRAM CS1 size according to the amount of RAM found */
142 if (dramsize2 > 0) {
143 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
144 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
145 } else {
146 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
147 }
148
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149#else /* CONFIG_SYS_RAMBOOT */
wdenk9e930b62004-06-19 21:19:10 +0000150
151 /* retrieve size of memory connected to SDRAM CS0 */
152 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
153 if (dramsize >= 0x13) {
154 dramsize = (1 << (dramsize - 0x13)) << 20;
155 } else {
156 dramsize = 0;
157 }
158
159 /* retrieve size of memory connected to SDRAM CS1 */
160 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
161 if (dramsize2 >= 0x13) {
162 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
163 } else {
164 dramsize2 = 0;
165 }
166
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200167#endif /* CONFIG_SYS_RAMBOOT */
wdenk9e930b62004-06-19 21:19:10 +0000168
169 return dramsize + dramsize2;
170}
wdenkc12081a2004-03-23 20:18:25 +0000171
wdenkc12081a2004-03-23 20:18:25 +0000172int checkboard (void)
173{
wdenkc12081a2004-03-23 20:18:25 +0000174 puts ("Board: MicroSys PM520 \n");
wdenkc12081a2004-03-23 20:18:25 +0000175 return 0;
176}
177
178void flash_preinit(void)
179{
180 /*
181 * Now, when we are in RAM, enable flash write
182 * access for detection process.
183 * Note that CS_BOOT cannot be cleared when
184 * executing in flash.
185 */
wdenkc12081a2004-03-23 20:18:25 +0000186 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
187}
188
wdenk9e930b62004-06-19 21:19:10 +0000189void flash_afterinit(ulong start, ulong size)
wdenkc12081a2004-03-23 20:18:25 +0000190{
wdenk9e930b62004-06-19 21:19:10 +0000191#if defined(CONFIG_BOOT_ROM)
192 /* adjust mapping */
193 *(vu_long *)MPC5XXX_CS1_START =
194 START_REG(start);
195 *(vu_long *)MPC5XXX_CS1_STOP =
196 STOP_REG(start, size);
197#else
198 /* adjust mapping */
199 *(vu_long *)MPC5XXX_BOOTCS_START = *(vu_long *)MPC5XXX_CS0_START =
200 START_REG(start);
201 *(vu_long *)MPC5XXX_BOOTCS_STOP = *(vu_long *)MPC5XXX_CS0_STOP =
202 STOP_REG(start, size);
203#endif
204}
205
206
207extern flash_info_t flash_info[]; /* info for FLASH chips */
208
209int misc_init_r (void)
210{
wdenk9e930b62004-06-19 21:19:10 +0000211 /* adjust flash start */
212 gd->bd->bi_flashstart = flash_info[0].start[0];
213 return (0);
wdenkc12081a2004-03-23 20:18:25 +0000214}
215
216#ifdef CONFIG_PCI
217static struct pci_controller hose;
218
219extern void pci_mpc5xxx_init(struct pci_controller *);
220
221void pci_init_board(void)
222{
223 pci_mpc5xxx_init(&hose);
224}
225#endif
wdenk9e930b62004-06-19 21:19:10 +0000226
Jon Loeliger761ea742007-07-10 10:48:22 -0500227#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk9e930b62004-06-19 21:19:10 +0000228
229void init_ide_reset (void)
230{
231 debug ("init_ide_reset\n");
232
233}
234
235void ide_set_reset (int idereset)
236{
237 debug ("ide_reset(%d)\n", idereset);
238
239}
Jon Loeliger761ea742007-07-10 10:48:22 -0500240#endif
wdenk9e930b62004-06-19 21:19:10 +0000241
Jon Loeliger145318c2007-07-09 18:38:39 -0500242#if defined(CONFIG_CMD_DOC)
wdenk9e930b62004-06-19 21:19:10 +0000243void doc_init (void)
244{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200245 doc_probe (CONFIG_SYS_DOC_BASE);
wdenk9e930b62004-06-19 21:19:10 +0000246}
247#endif
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700248
249int board_eth_init(bd_t *bis)
250{
Ben Warrencba88512008-08-31 10:39:12 -0700251 cpu_eth_init(bis); /* Built in FEC comes first */
Ben Warrenf2c1acb2008-08-31 10:03:22 -0700252 return pci_eth_init(bis);
253}