blob: 1f30d454fff3f24e543d05ca8bca61ca9f0f088d [file] [log] [blame]
Stefan Roese99200d22005-08-22 17:51:53 +02001/*
2 * (C) Copyright 2003
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 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27/*
28 * pf5200.c - main board support/init for the esd pf5200.
29 */
30
31#include <common.h>
32#include <mpc5xxx.h>
33#include <pci.h>
34#include <command.h>
35
36#include "mt46v16m16-75.h"
37
38void init_power_switch(void);
39
40static void sdram_start(int hi_addr)
41{
42 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
43
44 /* unlock mode register */
45 *(vu_long *) MPC5XXX_SDRAM_CTRL =
46 SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
47 __asm__ volatile ("sync");
48
49 /* precharge all banks */
50 *(vu_long *) MPC5XXX_SDRAM_CTRL =
51 SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
52 __asm__ volatile ("sync");
53
54 /* set mode register: extended mode */
55 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
56 __asm__ volatile ("sync");
57
58 /* set mode register: reset DLL */
59 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
60 __asm__ volatile ("sync");
61
62 /* precharge all banks */
63 *(vu_long *) MPC5XXX_SDRAM_CTRL =
64 SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
65 __asm__ volatile ("sync");
66
67 /* auto refresh */
68 *(vu_long *) MPC5XXX_SDRAM_CTRL =
69 SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
70 __asm__ volatile ("sync");
71
72 /* set mode register */
73 *(vu_long *) MPC5XXX_SDRAM_MODE = SDRAM_MODE;
74 __asm__ volatile ("sync");
75
76 /* normal operation */
77 *(vu_long *) MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
78 __asm__ volatile ("sync");
79}
80
81/*
82 * ATTENTION: Although partially referenced initdram does NOT make real use
83 * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
84 * is something else than 0x00000000.
85 */
86
87long int initdram(int board_type)
88{
89 ulong dramsize = 0;
90 ulong test1, test2;
91
92 /* setup SDRAM chip selects */
93 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
94 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
95 __asm__ volatile ("sync");
96
97 /* setup config registers */
98 *(vu_long *) MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
99 *(vu_long *) MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
100 __asm__ volatile ("sync");
101
102 /* set tap delay */
103 *(vu_long *) MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
104 __asm__ volatile ("sync");
105
106 /* find RAM size using SDRAM CS0 only */
107 sdram_start(0);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200108 test1 = get_ram_size((long *) CFG_SDRAM_BASE, 0x80000000);
Stefan Roese99200d22005-08-22 17:51:53 +0200109 sdram_start(1);
Wolfgang Denk7fb52662005-10-13 16:45:02 +0200110 test2 = get_ram_size((long *) CFG_SDRAM_BASE, 0x80000000);
Stefan Roese99200d22005-08-22 17:51:53 +0200111
112 if (test1 > test2) {
113 sdram_start(0);
114 dramsize = test1;
115 } else {
116 dramsize = test2;
117 }
118
119 /* memory smaller than 1MB is impossible */
120 if (dramsize < (1 << 20)) {
121 dramsize = 0;
122 }
123
124 /* set SDRAM CS0 size according to the amount of RAM found */
125 if (dramsize > 0) {
126 *(vu_long *) MPC5XXX_SDRAM_CS0CFG =
127 0x13 + __builtin_ffs(dramsize >> 20) - 1;
128 /* let SDRAM CS1 start right after CS0 */
129 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e; /* 2G */
130 } else {
131#if 0
132 *(vu_long *) MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
133 /* let SDRAM CS1 start right after CS0 */
134 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e; /* 2G */
135#else
136 *(vu_long *) MPC5XXX_SDRAM_CS0CFG =
137 0x13 + __builtin_ffs(0x08000000 >> 20) - 1;
138 /* let SDRAM CS1 start right after CS0 */
139 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = 0x08000000 + 0x0000001e; /* 2G */
140#endif
141 }
142
143#if 0
144 /* find RAM size using SDRAM CS1 only */
145 sdram_start(0);
146 get_ram_size((ulong *) (CFG_SDRAM_BASE + dramsize), 0x80000000);
147 sdram_start(1);
148 get_ram_size((ulong *) (CFG_SDRAM_BASE + dramsize), 0x80000000);
149 sdram_start(0);
150#endif
151 /* set SDRAM CS1 size according to the amount of RAM found */
152
153 *(vu_long *) MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
154
155 init_power_switch();
156 return (dramsize);
157}
158
159int checkboard(void)
160{
161 puts("Board: esd ParaFinder (pf5200)\n");
162 return 0;
163}
164
165void flash_preinit(void)
166{
167 /*
168 * Now, when we are in RAM, enable flash write
169 * access for detection process.
170 * Note that CS_BOOT cannot be cleared when
171 * executing in flash.
172 */
173 *(vu_long *) MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
174}
175
176void flash_afterinit(ulong size)
177{
178 if (size == 0x02000000) {
179 /* adjust mapping */
180 *(vu_long *) MPC5XXX_BOOTCS_START =
181 *(vu_long *) MPC5XXX_CS0_START =
182 START_REG(CFG_BOOTCS_START | size);
183 *(vu_long *) MPC5XXX_BOOTCS_STOP =
184 *(vu_long *) MPC5XXX_CS0_STOP =
185 STOP_REG(CFG_BOOTCS_START | size, size);
186 }
187}
188
189#ifdef CONFIG_PCI
190static struct pci_controller hose;
191
192extern void pci_mpc5xxx_init(struct pci_controller *);
193
194void pci_init_board(void
195 ) {
196 pci_mpc5xxx_init(&hose);
197}
198#endif
199
200#if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
201
Stefan Roese99200d22005-08-22 17:51:53 +0200202void init_ide_reset(void)
203{
204 debug("init_ide_reset\n");
205
206 /* Configure PSC1_4 as GPIO output for ATA reset */
207 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
208 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
209}
210
211void ide_set_reset(int idereset)
212{
213 debug("ide_reset(%d)\n", idereset);
214
215 if (idereset) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100216 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
Stefan Roese99200d22005-08-22 17:51:53 +0200217 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100218 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
Stefan Roese99200d22005-08-22 17:51:53 +0200219 }
220}
221#endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
222
223#define MPC5XXX_SIMPLEIO_GPIO_ENABLE (MPC5XXX_GPIO + 0x0004)
224#define MPC5XXX_SIMPLEIO_GPIO_DIR (MPC5XXX_GPIO + 0x000C)
225#define MPC5XXX_SIMPLEIO_GPIO_DATA_OUTPUT (MPC5XXX_GPIO + 0x0010)
226#define MPC5XXX_SIMPLEIO_GPIO_DATA_INPUT (MPC5XXX_GPIO + 0x0014)
227
228#define MPC5XXX_INTERRUPT_GPIO_ENABLE (MPC5XXX_GPIO + 0x0020)
229#define MPC5XXX_INTERRUPT_GPIO_DIR (MPC5XXX_GPIO + 0x0028)
230#define MPC5XXX_INTERRUPT_GPIO_DATA_OUTPUT (MPC5XXX_GPIO + 0x002C)
231#define MPC5XXX_INTERRUPT_GPIO_STATUS (MPC5XXX_GPIO + 0x003C)
232
233#define GPIO_WU6 0x40000000UL
234#define GPIO_USB0 0x00010000UL
235#define GPIO_USB9 0x08000000UL
236#define GPIO_USB9S 0x00080000UL
237
238void init_power_switch(void)
239{
240 debug("init_power_switch\n");
241
242 /* Configure GPIO_WU6 as GPIO output for ATA reset */
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100243 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_WU6;
Stefan Roese99200d22005-08-22 17:51:53 +0200244 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_WU6;
245 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_WU6;
246 __asm__ volatile ("sync");
247
248 *(vu_long *) MPC5XXX_SIMPLEIO_GPIO_DATA_OUTPUT &= ~GPIO_USB0;
249 *(vu_long *) MPC5XXX_SIMPLEIO_GPIO_ENABLE |= GPIO_USB0;
250 *(vu_long *) MPC5XXX_SIMPLEIO_GPIO_DIR |= GPIO_USB0;
251 __asm__ volatile ("sync");
252
253 *(vu_long *) MPC5XXX_INTERRUPT_GPIO_DATA_OUTPUT &= ~GPIO_USB9;
254 *(vu_long *) MPC5XXX_INTERRUPT_GPIO_ENABLE &= ~GPIO_USB9;
255 __asm__ volatile ("sync");
256
257 if ((*(vu_long *) MPC5XXX_INTERRUPT_GPIO_STATUS & GPIO_USB9S) == 0) {
258 *(vu_long *) MPC5XXX_SIMPLEIO_GPIO_DATA_OUTPUT |= GPIO_USB0;
259 __asm__ volatile ("sync");
260 }
261 *(vu_char *) CFG_CS1_START = 0x02; /* Red Power LED on */
262 __asm__ volatile ("sync");
263
264 *(vu_char *) (CFG_CS1_START + 1) = 0x02; /* Disable driver for KB11 */
265 __asm__ volatile ("sync");
266}
267
268void power_set_reset(int power)
269{
270 debug("ide_set_reset(%d)\n", power);
271
272 if (power) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100273 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_WU6;
Stefan Roese99200d22005-08-22 17:51:53 +0200274 *(vu_long *) MPC5XXX_INTERRUPT_GPIO_DATA_OUTPUT &= ~GPIO_USB9;
275 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100276 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_WU6;
Stefan Roese99200d22005-08-22 17:51:53 +0200277 if ((*(vu_long *) MPC5XXX_INTERRUPT_GPIO_STATUS & GPIO_USB9S) ==
278 0) {
279 *(vu_long *) MPC5XXX_SIMPLEIO_GPIO_DATA_OUTPUT |=
280 GPIO_USB0;
281 }
282
283 }
284}
285
286int do_poweroff(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
287{
288 power_set_reset(1);
289 return (0);
290}
291
292U_BOOT_CMD(poweroff, 1, 1, do_poweroff, "poweroff- Switch off power\n", NULL);
293
294int phypower(int flag)
295{
296 u32 addr;
297 vu_long *reg;
298 int status;
299 pci_dev_t dev;
300
301 dev = PCI_BDF(0, 0x18, 0);
302 status = pci_read_config_dword(dev, PCI_BASE_ADDRESS_1, &addr);
303 if (status == 0) {
304 reg = (vu_long *) (addr + 0x00000040);
305 *reg |= 0x40000000;
306 __asm__ volatile ("sync");
307
308 reg = (vu_long *) (addr + 0x001000c);
309 *reg |= 0x20000000;
310 __asm__ volatile ("sync");
311
312 reg = (vu_long *) (addr + 0x0010004);
313 if (flag != 0) {
314 *reg &= ~0x20000000;
315 } else {
316 *reg |= 0x20000000;
317 }
318 __asm__ volatile ("sync");
319 }
320 return (status);
321}
322
323int do_phypower(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
324{
325 int status;
326
327 if (argv[1][0] == '0') {
328 status = phypower(0);
329 } else {
330 status = phypower(1);
331 }
332 return (0);
333}
334
335U_BOOT_CMD(phypower, 2, 2, do_phypower,
336 "phypower- Switch power of ethernet phy\n", NULL);
337
338int do_writepci(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
339{
340 unsigned int addr;
341 unsigned int size;
342 int i;
343 volatile unsigned long *ptr;
344
345 addr = simple_strtol(argv[1], NULL, 16);
346 size = simple_strtol(argv[2], NULL, 16);
347
348 printf("\nWriting at addr %08x, size %08x.\n", addr, size);
349
350 while (1) {
351 ptr = (volatile unsigned long *)addr;
352 for (i = 0; i < (size >> 2); i++) {
353 *ptr++ = i;
354 }
355
356 /* Abort if ctrl-c was pressed */
357 if (ctrlc()) {
358 puts("\nAbort\n");
359 return 0;
360 }
361 putc('.');
362 }
363 return 0;
364}
365
366U_BOOT_CMD(writepci, 3, 1, do_writepci,
367 "writepci- Write some data to pcibus\n",
368 "<addr> <size>\n" " - Write some data to pcibus.\n");