blob: 898f1f4688511e8e304cc2ee8223457d655efc10 [file] [log] [blame]
wdenk64519362004-07-11 17:40:54 +00001/*
2 * (C) Copyright 2003-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2004
6 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7 *
8 * (C) Copyright 2004
9 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
10 *
11 * See file CREDITS for list of people who contributed to this
12 * project.
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of
17 * the License, or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 * MA 02111-1307 USA
28 */
29
30#include <common.h>
31#include <mpc5xxx.h>
32#include <pci.h>
33
34#if defined(CONFIG_MPC5200_DDR)
35#include "mt46v16m16-75.h"
36#else
37#include "mt48lc16m16a2-75.h"
38#endif
39
40#ifndef CFG_RAMBOOT
41static void sdram_start (int hi_addr)
42{
43 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
44
45 /* unlock mode register */
46 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
47 hi_addr_bit;
48 __asm__ volatile ("sync");
49
50 /* precharge all banks */
51 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
52 hi_addr_bit;
53 __asm__ volatile ("sync");
54
55#if SDRAM_DDR
56 /* set mode register: extended mode */
57 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
58 __asm__ volatile ("sync");
59
60 /* set mode register: reset DLL */
61 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
62 __asm__ volatile ("sync");
63#endif
64
65 /* precharge all banks */
66 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
67 hi_addr_bit;
68 __asm__ volatile ("sync");
69
70 /* auto refresh */
71 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
72 hi_addr_bit;
73 __asm__ volatile ("sync");
74
75 /* set mode register */
76 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
77 __asm__ volatile ("sync");
78
79 /* normal operation */
80 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
81 __asm__ volatile ("sync");
82}
83#endif
84
85/*
86 * ATTENTION: Although partially referenced initdram does NOT make real use
87 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
88 * is something else than 0x00000000.
89 */
90
91#if defined(CONFIG_MPC5200)
92long int initdram (int board_type)
93{
94 ulong dramsize = 0;
95 ulong dramsize2 = 0;
96#ifndef CFG_RAMBOOT
97 ulong test1, test2;
98
99 /* setup SDRAM chip selects */
100 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
101 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
102 __asm__ volatile ("sync");
103
104 /* setup config registers */
105 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
106 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
107 __asm__ volatile ("sync");
108
109#if SDRAM_DDR
110 /* set tap delay */
111 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
112 __asm__ volatile ("sync");
113#endif
114
115 /* find RAM size using SDRAM CS0 only */
116 sdram_start(0);
117 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
118 sdram_start(1);
119 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
120 if (test1 > test2) {
121 sdram_start(0);
122 dramsize = test1;
123 } else {
124 dramsize = test2;
125 }
126
127 /* memory smaller than 1MB is impossible */
128 if (dramsize < (1 << 20)) {
129 dramsize = 0;
130 }
131
132 /* set SDRAM CS0 size according to the amount of RAM found */
133 if (dramsize > 0) {
134 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
135 __builtin_ffs(dramsize >> 20) - 1;
136 } else {
137 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
138 }
139
140 /* let SDRAM CS1 start right after CS0 */
141 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001c; /* 512MB */
142
143 /* find RAM size using SDRAM CS1 only */
144 sdram_start(0);
145 test1 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
146 sdram_start(1);
147 test2 = get_ram_size((ulong *)(CFG_SDRAM_BASE + dramsize), 0x20000000);
148 if (test1 > test2) {
149 sdram_start(0);
150 dramsize2 = test1;
151 } else {
152 dramsize2 = test2;
153 }
154
155 /* memory smaller than 1MB is impossible */
156 if (dramsize2 < (1 << 20)) {
157 dramsize2 = 0;
158 }
159
160 /* set SDRAM CS1 size according to the amount of RAM found */
161 if (dramsize2 > 0) {
162 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
163 | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
164 } else {
165 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
166 }
167
168#else /* CFG_RAMBOOT */
169
170 /* retrieve size of memory connected to SDRAM CS0 */
171 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
172 if (dramsize >= 0x13) {
173 dramsize = (1 << (dramsize - 0x13)) << 20;
174 } else {
175 dramsize = 0;
176 }
177
178 /* retrieve size of memory connected to SDRAM CS1 */
179 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
180 if (dramsize2 >= 0x13) {
181 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
182 } else {
183 dramsize2 = 0;
184 }
185
186#endif /* CFG_RAMBOOT */
187
188/* return dramsize + dramsize2; */
189 return dramsize;
190}
191
192#elif defined(CONFIG_MGT5100)
193
194long int initdram (int board_type)
195{
196 ulong dramsize = 0;
197#ifndef CFG_RAMBOOT
198 ulong test1, test2;
199
200 /* setup and enable SDRAM chip selects */
201 *(vu_long *)MPC5XXX_SDRAM_START = 0x00000000;
202 *(vu_long *)MPC5XXX_SDRAM_STOP = 0x0000ffff;/* 2G */
203 *(vu_long *)MPC5XXX_ADDECR |= (1 << 22); /* Enable SDRAM */
204 __asm__ volatile ("sync");
205
206 /* setup config registers */
207 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
208 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
209
210 /* address select register */
211 *(vu_long *)MPC5XXX_SDRAM_XLBSEL = SDRAM_ADDRSEL;
212 __asm__ volatile ("sync");
213
214 /* find RAM size */
215 sdram_start(0);
216 test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
217 sdram_start(1);
218 test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x80000000);
219 if (test1 > test2) {
220 sdram_start(0);
221 dramsize = test1;
222 } else {
223 dramsize = test2;
224 }
225
226 /* set SDRAM end address according to size */
227 *(vu_long *)MPC5XXX_SDRAM_STOP = ((dramsize - 1) >> 15);
228
229#else /* CFG_RAMBOOT */
230
231 /* Retrieve amount of SDRAM available */
232 dramsize = ((*(vu_long *)MPC5XXX_SDRAM_STOP + 1) << 15);
233
234#endif /* CFG_RAMBOOT */
235
236 return dramsize;
237}
238
239#else
240#error Neither CONFIG_MPC5200 or CONFIG_MGT5100 defined
241#endif
242
243int checkboard (void)
244{
245#if defined (CONFIG_TQM5200_AA)
246 puts ("Board: TQM5200-AA (TQ-Systems GmbH)\n");
247#endif
248#if defined (CONFIG_TQM5200_AB)
249 puts ("Board: TQM5200-AB (TQ-Systems GmbH)\n");
250#endif
251#if defined (CONFIG_TQM5200_AC)
252 puts ("Board: TQM5200-AC (TQ-Systems GmbH)\n");
253#endif
254 return 0;
255}
256
257void flash_preinit(void)
258{
259 /*
260 * Now, when we are in RAM, enable flash write
261 * access for detection process.
262 * Note that CS_BOOT cannot be cleared when
263 * executing in flash.
264 */
265#if defined(CONFIG_MGT5100)
266 *(vu_long *)MPC5XXX_ADDECR &= ~(1 << 25); /* disable CS_BOOT */
267 *(vu_long *)MPC5XXX_ADDECR |= (1 << 16); /* enable CS0 */
268#endif
269 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
270}
271
272
273#ifdef CONFIG_PCI
274static struct pci_controller hose;
275
276extern void pci_mpc5xxx_init(struct pci_controller *);
277
278void pci_init_board(void)
279{
280 pci_mpc5xxx_init(&hose);
281}
282#endif
283
284#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
285
286#if defined (CONFIG_MINIFAP)
287#define SM501_POWER_MODE0_GATE 0x00000040UL
288#define SM501_POWER_MODE1_GATE 0x00000048UL
289#define POWER_MODE_GATE_GPIO_PWM_I2C 0x00000040UL
290#define SM501_GPIO_DATA_DIR_HIGH 0x0001000CUL
291#define SM501_GPIO_DATA_HIGH 0x00010004UL
292#define SM501_GPIO_51 0x00080000UL
293#else
294#define GPIO_PSC1_4 0x01000000UL
295#endif
296
297void init_ide_reset (void)
298{
299 debug ("init_ide_reset\n");
300
301#if defined (CONFIG_MINIFAP)
302 /* Configure GPIO_51 of the SM501 grafic controller as ATA reset */
303
304 /* enable GPIO control (in both power modes) */
305 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE0_GATE) |=
306 POWER_MODE_GATE_GPIO_PWM_I2C;
307 *(vu_long *) (SM501_MMIO_BASE+SM501_POWER_MODE1_GATE) |=
308 POWER_MODE_GATE_GPIO_PWM_I2C;
309 /* configure GPIO51 as output */
310 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_DIR_HIGH) |=
311 SM501_GPIO_51;
312#else
313 /* Configure PSC1_4 as GPIO output for ATA reset */
314 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
315 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
316#endif
317}
318
319void ide_set_reset (int idereset)
320{
321 debug ("ide_reset(%d)\n", idereset);
322
323#if defined (CONFIG_MINIFAP)
324 if (idereset) {
325 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) &=
326 ~SM501_GPIO_51;
327 } else {
328 *(vu_long *) (SM501_MMIO_BASE+SM501_GPIO_DATA_HIGH) |=
329 SM501_GPIO_51;
330 }
331#else
332 if (idereset) {
333 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
334 } else {
335 *(vu_long *) MPC5XXX_WU_GPIO_DATA |= GPIO_PSC1_4;
336 }
337#endif
338}
339#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
340
341#ifdef CONFIG_POST
342/*
343 * Reads GPIO pin PSC6_3. A keypress is reported, if PSC6_3 is low. If PSC6_3
344 * is left open, no keypress is detected.
345 */
346int post_hotkeys_pressed(void)
347{
348 struct mpc5xxx_gpio *gpio;
349
350 gpio = (struct mpc5xxx_gpio*) MPC5XXX_GPIO;
351
352 /*
353 * Configure PSC6_1 and PSC6_3 as GPIO. PSC6 then couldn't be used in
354 * CODEC or UART mode. Consumer IrDA should still be possible.
355 */
356 gpio->port_config &= ~(0x07000000);
357 gpio->port_config |= 0x03000000;
358
359 /* Enable GPIO for GPIO_IRDA_1 (IR_USB_CLK pin) = PSC6_3 */
360 gpio->simple_gpioe |= 0x20000000;
361
362 /* Configure GPIO_IRDA_1 as input */
363 gpio->simple_ddr &= ~(0x20000000);
364
365 return ((gpio->simple_ival & 0x20000000) ? 0 : 1);
366}
367#endif
368
369#if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
370
371void post_word_store (ulong a)
372{
373 volatile ulong *save_addr =
374 (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
375
376 *save_addr = a;
377}
378
379ulong post_word_load (void)
380{
381 volatile ulong *save_addr =
382 (volatile ulong *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
383
384 return *save_addr;
385}
386
387#endif /* CONFIG_POST || CONFIG_LOGBUFFER*/