blob: 96c0dd460039b3acefc6d5deed0c36ff6d81e7b8 [file] [log] [blame]
Stefan Roese7de9fc72007-10-05 17:11:30 +02001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <ppc4xx.h>
26#include <ppc405.h>
27#include <libfdt.h>
28#include <asm/processor.h>
Stefan Roese15668052007-10-23 10:10:08 +020029#include <asm/io.h>
Stefan Roese7de9fc72007-10-05 17:11:30 +020030
31#if defined(CONFIG_PCI)
32#include <pci.h>
33#include <asm/4xx_pcie.h>
34#endif
35
36DECLARE_GLOBAL_DATA_PTR;
37
38extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
39
Stefan Roese7de9fc72007-10-05 17:11:30 +020040/*
41 * Board early initialization function
42 */
43int board_early_init_f (void)
44{
45 u32 val;
46
47 /*--------------------------------------------------------------------+
48 | Interrupt controller setup for the AMCC 405EX(r) PINE evaluation board.
49 +--------------------------------------------------------------------+
50 +---------------------------------------------------------------------+
51 |Interrupt| Source | Pol. | Sensi.| Crit. |
52 +---------+-----------------------------------+-------+-------+-------+
53 | IRQ 00 | UART0 | High | Level | Non |
54 | IRQ 01 | UART1 | High | Level | Non |
55 | IRQ 02 | IIC0 | High | Level | Non |
56 | IRQ 03 | TBD | High | Level | Non |
57 | IRQ 04 | TBD | High | Level | Non |
58 | IRQ 05 | EBM | High | Level | Non |
59 | IRQ 06 | BGI | High | Level | Non |
60 | IRQ 07 | IIC1 | Rising| Edge | Non |
61 | IRQ 08 | SPI | High | Lvl/ed| Non |
62 | IRQ 09 | External IRQ 0 - (PCI-Express) | pgm H | Pgm | Non |
63 | IRQ 10 | MAL TX EOB | High | Level | Non |
64 | IRQ 11 | MAL RX EOB | High | Level | Non |
65 | IRQ 12 | DMA Channel 0 FIFO Full | High | Level | Non |
66 | IRQ 13 | DMA Channel 0 Stat FIFO | High | Level | Non |
67 | IRQ 14 | DMA Channel 1 FIFO Full | High | Level | Non |
68 | IRQ 15 | DMA Channel 1 Stat FIFO | High | Level | Non |
69 | IRQ 16 | PCIE0 AL | high | Level | Non |
70 | IRQ 17 | PCIE0 VPD access | rising| Edge | Non |
71 | IRQ 18 | PCIE0 hot reset request | rising| Edge | Non |
72 | IRQ 19 | PCIE0 hot reset request | faling| Edge | Non |
73 | IRQ 20 | PCIE0 TCR | High | Level | Non |
74 | IRQ 21 | PCIE0 MSI level0 | High | Level | Non |
75 | IRQ 22 | PCIE0 MSI level1 | High | Level | Non |
76 | IRQ 23 | Security EIP-94 | High | Level | Non |
77 | IRQ 24 | EMAC0 interrupt | High | Level | Non |
78 | IRQ 25 | EMAC1 interrupt | High | Level | Non |
79 | IRQ 26 | PCIE0 MSI level2 | High | Level | Non |
80 | IRQ 27 | External IRQ 4 | pgm H | Pgm | Non |
81 | IRQ 28 | UIC2 Non-critical Int. | High | Level | Non |
82 | IRQ 29 | UIC2 Critical Interrupt | High | Level | Crit. |
83 | IRQ 30 | UIC1 Non-critical Int. | High | Level | Non |
84 | IRQ 31 | UIC1 Critical Interrupt | High | Level | Crit. |
85 |----------------------------------------------------------------------
86 | IRQ 32 | MAL Serr | High | Level | Non |
87 | IRQ 33 | MAL Txde | High | Level | Non |
88 | IRQ 34 | MAL Rxde | High | Level | Non |
89 | IRQ 35 | PCIE0 bus master VC0 |falling| Edge | Non |
90 | IRQ 36 | PCIE0 DCR Error | High | Level | Non |
91 | IRQ 37 | EBC | High |Lvl Edg| Non |
92 | IRQ 38 | NDFC | High | Level | Non |
93 | IRQ 39 | GPT Compare Timer 8 | Risin | Edge | Non |
94 | IRQ 40 | GPT Compare Timer 9 | Risin | Edge | Non |
95 | IRQ 41 | PCIE1 AL | high | Level | Non |
96 | IRQ 42 | PCIE1 VPD access | rising| edge | Non |
97 | IRQ 43 | PCIE1 hot reset request | rising| Edge | Non |
98 | IRQ 44 | PCIE1 hot reset request | faling| Edge | Non |
99 | IRQ 45 | PCIE1 TCR | High | Level | Non |
100 | IRQ 46 | PCIE1 bus master VC0 |falling| Edge | Non |
101 | IRQ 47 | GPT Compare Timer 3 | Risin | Edge | Non |
102 | IRQ 48 | GPT Compare Timer 4 | Risin | Edge | Non |
103 | IRQ 49 | Ext. IRQ 7 |pgm/Fal|pgm/Lvl| Non |
104 | IRQ 50 | Ext. IRQ 8 - |pgm (H)|pgm/Lvl| Non |
105 | IRQ 51 | Ext. IRQ 9 |pgm (H)|pgm/Lvl| Non |
106 | IRQ 52 | GPT Compare Timer 5 | high | Edge | Non |
107 | IRQ 53 | GPT Compare Timer 6 | high | Edge | Non |
108 | IRQ 54 | GPT Compare Timer 7 | high | Edge | Non |
109 | IRQ 55 | Serial ROM | High | Level | Non |
110 | IRQ 56 | GPT Decrement Pulse | High | Level | Non |
111 | IRQ 57 | Ext. IRQ 2 |pgm/Fal|pgm/Lvl| Non |
112 | IRQ 58 | Ext. IRQ 5 |pgm/Fal|pgm/Lvl| Non |
113 | IRQ 59 | Ext. IRQ 6 |pgm/Fal|pgm/Lvl| Non |
114 | IRQ 60 | EMAC0 Wake-up | High | Level | Non |
115 | IRQ 61 | Ext. IRQ 1 |pgm/Fal|pgm/Lvl| Non |
116 | IRQ 62 | EMAC1 Wake-up | High | Level | Non |
117 |----------------------------------------------------------------------
118 | IRQ 64 | PE0 AL | High | Level | Non |
119 | IRQ 65 | PE0 VPD Access | Risin | Edge | Non |
120 | IRQ 66 | PE0 Hot Reset Request | Risin | Edge | Non |
121 | IRQ 67 | PE0 Hot Reset Request | Falli | Edge | Non |
122 | IRQ 68 | PE0 TCR | High | Level | Non |
123 | IRQ 69 | PE0 BusMaster VCO | Falli | Edge | Non |
124 | IRQ 70 | PE0 DCR Error | High | Level | Non |
125 | IRQ 71 | Reserved | N/A | N/A | Non |
126 | IRQ 72 | PE1 AL | High | Level | Non |
127 | IRQ 73 | PE1 VPD Access | Risin | Edge | Non |
128 | IRQ 74 | PE1 Hot Reset Request | Risin | Edge | Non |
129 | IRQ 75 | PE1 Hot Reset Request | Falli | Edge | Non |
130 | IRQ 76 | PE1 TCR | High | Level | Non |
131 | IRQ 77 | PE1 BusMaster VCO | Falli | Edge | Non |
132 | IRQ 78 | PE1 DCR Error | High | Level | Non |
133 | IRQ 79 | Reserved | N/A | N/A | Non |
134 | IRQ 80 | PE2 AL | High | Level | Non |
135 | IRQ 81 | PE2 VPD Access | Risin | Edge | Non |
136 | IRQ 82 | PE2 Hot Reset Request | Risin | Edge | Non |
137 | IRQ 83 | PE2 Hot Reset Request | Falli | Edge | Non |
138 | IRQ 84 | PE2 TCR | High | Level | Non |
139 | IRQ 85 | PE2 BusMaster VCO | Falli | Edge | Non |
140 | IRQ 86 | PE2 DCR Error | High | Level | Non |
141 | IRQ 87 | Reserved | N/A | N/A | Non |
142 | IRQ 88 | External IRQ(5) | Progr | Progr | Non |
143 | IRQ 89 | External IRQ 4 - Ethernet | Progr | Progr | Non |
144 | IRQ 90 | External IRQ 3 - PCI-X | Progr | Progr | Non |
145 | IRQ 91 | External IRQ 2 - PCI-X | Progr | Progr | Non |
146 | IRQ 92 | External IRQ 1 - PCI-X | Progr | Progr | Non |
147 | IRQ 93 | External IRQ 0 - PCI-X | Progr | Progr | Non |
148 | IRQ 94 | Reserved | N/A | N/A | Non |
149 | IRQ 95 | Reserved | N/A | N/A | Non |
150 |---------------------------------------------------------------------
151 +---------+-----------------------------------+-------+-------+------*/
152 /*--------------------------------------------------------------------+
153 | Initialise UIC registers. Clear all interrupts. Disable all
154 | interrupts.
155 | Set critical interrupt values. Set interrupt polarities. Set
156 | interrupt trigger levels. Make bit 0 High priority. Clear all
157 | interrupts again.
158 +-------------------------------------------------------------------*/
159
160 mtdcr (uic2sr, 0xffffffff); /* Clear all interrupts */
161 mtdcr (uic2er, 0x00000000); /* disable all interrupts */
162 mtdcr (uic2cr, 0x00000000); /* Set Critical / Non Critical interrupts */
163 mtdcr (uic2pr, 0xf7ffffff); /* Set Interrupt Polarities */
164 mtdcr (uic2tr, 0x01e1fff8); /* Set Interrupt Trigger Levels */
165 mtdcr (uic2vr, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
166 mtdcr (uic2sr, 0x00000000); /* clear all interrupts */
167 mtdcr (uic2sr, 0xffffffff); /* clear all interrupts */
168
169 mtdcr (uic1sr, 0xffffffff); /* Clear all interrupts */
170 mtdcr (uic1er, 0x00000000); /* disable all interrupts */
171 mtdcr (uic1cr, 0x00000000); /* Set Critical / Non Critical interrupts */
172 mtdcr (uic1pr, 0xfffac785); /* Set Interrupt Polarities */
173 mtdcr (uic1tr, 0x001d0040); /* Set Interrupt Trigger Levels */
174 mtdcr (uic1vr, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
175 mtdcr (uic1sr, 0x00000000); /* clear all interrupts */
176 mtdcr (uic1sr, 0xffffffff); /* clear all interrupts */
177
178 mtdcr (uic0sr, 0xffffffff); /* Clear all interrupts */
179 mtdcr (uic0er, 0x0000000a); /* Disable all interrupts */
180 /* Except cascade UIC0 and UIC1 */
181 mtdcr (uic0cr, 0x00000000); /* Set Critical / Non Critical interrupts */
182 mtdcr (uic0pr, 0xffbfefef); /* Set Interrupt Polarities */
183 mtdcr (uic0tr, 0x00007000); /* Set Interrupt Trigger Levels */
184 mtdcr (uic0vr, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
185 mtdcr (uic0sr, 0x00000000); /* clear all interrupts */
186 mtdcr (uic0sr, 0xffffffff); /* clear all interrupts */
187
188 /*
189 * Note: Some cores are still in reset when the chip starts, so
190 * take them out of reset
191 */
192 mtsdr(SDR0_SRST, 0);
193
Stefan Roese1fd81ff2007-11-30 07:15:41 +0100194 /*
195 * Configure FPGA register with PCIe reset
196 */
197 out_be32((void *)CFG_FPGA_BASE, 0xff570cc0); /* assert PCIe reset */
198 mdelay(50);
199 out_be32((void *)CFG_FPGA_BASE, 0xff570cc3); /* deassert PCIe reset */
Stefan Roese7de9fc72007-10-05 17:11:30 +0200200
201 /* Configure 405EX for NAND usage */
202 val = SDR0_CUST0_MUX_NDFC_SEL |
203 SDR0_CUST0_NDFC_ENABLE |
204 SDR0_CUST0_NDFC_BW_8_BIT |
205 SDR0_CUST0_NRB_BUSY |
206 (0x80000000 >> (28 + CFG_NAND_CS));
207 mtsdr(SDR0_CUST0, val);
208
Stefan Roesee971ead2007-12-08 14:47:34 +0100209 /*
210 * Configure PFC (Pin Function Control) registers
211 * -> Enable USB
212 */
213 val = SDR0_PFC1_USBEN | SDR0_PFC1_USBBIGEN | SDR0_PFC1_GPT_FREQ;
214 mtsdr(SDR0_PFC1, val);
215
Stefan Roese7de9fc72007-10-05 17:11:30 +0200216 return 0;
217}
218
219int misc_init_r(void)
220{
221#ifdef CFG_ENV_IS_IN_FLASH
222 /* Monitor protection ON by default */
223 flash_protect(FLAG_PROTECT_SET,
224 -CFG_MONITOR_LEN,
225 0xffffffff,
226 &flash_info[0]);
227#endif
228
229 return 0;
230}
231
Stefan Roese15668052007-10-23 10:10:08 +0200232int board_emac_count(void)
233{
234 u32 pvr = get_pvr();
235
236 /*
237 * 405EXr only has one EMAC interface, 405EX has two
238 */
239 if ((pvr == PVR_405EXR1_RA) || (pvr == PVR_405EXR2_RA))
240 return 1;
241 else
242 return 2;
243}
244
245static int board_pcie_count(void)
246{
247 u32 pvr = get_pvr();
248
249 /*
250 * 405EXr only has one EMAC interface, 405EX has two
251 */
252 if ((pvr == PVR_405EXR1_RA) || (pvr == PVR_405EXR2_RA))
253 return 1;
254 else
255 return 2;
256}
257
Stefan Roese7de9fc72007-10-05 17:11:30 +0200258int checkboard (void)
259{
260 char *s = getenv("serial#");
Stefan Roese15668052007-10-23 10:10:08 +0200261 u32 pvr = get_pvr();
Stefan Roese7de9fc72007-10-05 17:11:30 +0200262
Stefan Roese15668052007-10-23 10:10:08 +0200263 if ((pvr == PVR_405EXR1_RA) || (pvr == PVR_405EXR2_RA))
264 printf("Board: Haleakala - AMCC PPC405EXr Evaluation Board");
265 else
266 printf("Board: Kilauea - AMCC PPC405EX Evaluation Board");
Stefan Roese7de9fc72007-10-05 17:11:30 +0200267
268 if (s != NULL) {
269 puts(", serial# ");
270 puts(s);
271 }
272 putc('\n');
273
274 return (0);
275}
276
277/*************************************************************************
278 * pci_pre_init
279 *
280 * This routine is called just prior to registering the hose and gives
281 * the board the opportunity to check things. Returning a value of zero
282 * indicates that things are bad & PCI initialization should be aborted.
283 *
284 * Different boards may wish to customize the pci controller structure
285 * (add regions, override default access routines, etc) or perform
286 * certain pre-initialization actions.
287 *
288 ************************************************************************/
289#if defined(CONFIG_PCI)
290int pci_pre_init(struct pci_controller * hose )
291{
292 return 0;
293}
294#endif /* defined(CONFIG_PCI) */
295
Stefan Roese7de9fc72007-10-05 17:11:30 +0200296#ifdef CONFIG_PCI
Stefan Roese7de9fc72007-10-05 17:11:30 +0200297static struct pci_controller pcie_hose[2] = {{0},{0}};
298
299void pcie_setup_hoses(int busno)
300{
301 struct pci_controller *hose;
302 int i, bus;
Stefan Roese89bac402007-10-13 16:43:23 +0200303 int ret = 0;
Stefan Roese7de9fc72007-10-05 17:11:30 +0200304 bus = busno;
305 char *env;
306 unsigned int delay;
307
Stefan Roese15668052007-10-23 10:10:08 +0200308 for (i = 0; i < board_pcie_count(); i++) {
Stefan Roese7de9fc72007-10-05 17:11:30 +0200309
Stefan Roese7e3e2682007-11-05 07:43:05 +0100310 if (is_end_point(i))
Stefan Roese89bac402007-10-13 16:43:23 +0200311 ret = ppc4xx_init_pcie_endport(i);
Stefan Roese7e3e2682007-11-05 07:43:05 +0100312 else
Stefan Roese89bac402007-10-13 16:43:23 +0200313 ret = ppc4xx_init_pcie_rootport(i);
Stefan Roese89bac402007-10-13 16:43:23 +0200314 if (ret) {
Stefan Roese7e3e2682007-11-05 07:43:05 +0100315 printf("PCIE%d: initialization as %s failed\n", i,
316 is_end_point(i) ? "endpoint" : "root-complex");
Stefan Roese89bac402007-10-13 16:43:23 +0200317 continue;
Stefan Roese7de9fc72007-10-05 17:11:30 +0200318 }
319
320 hose = &pcie_hose[i];
321 hose->first_busno = bus;
322 hose->last_busno = bus;
323 hose->current_busno = bus;
324
325 /* setup mem resource */
326 pci_set_region(hose->regions + 0,
327 CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
328 CFG_PCIE_MEMBASE + i * CFG_PCIE_MEMSIZE,
329 CFG_PCIE_MEMSIZE,
330 PCI_REGION_MEM);
331 hose->region_count = 1;
332 pci_register_hose(hose);
333
Stefan Roese89bac402007-10-13 16:43:23 +0200334 if (is_end_point(i)) {
335 ppc4xx_setup_pcie_endpoint(hose, i);
336 /*
337 * Reson for no scanning is endpoint can not generate
338 * upstream configuration accesses.
339 */
340 } else {
341 ppc4xx_setup_pcie_rootpoint(hose, i);
342 env = getenv ("pciscandelay");
343 if (env != NULL) {
344 delay = simple_strtoul(env, NULL, 10);
345 if (delay > 5)
346 printf("Warning, expect noticable delay before "
347 "PCIe scan due to 'pciscandelay' value!\n");
348 mdelay(delay * 1000);
349 }
Stefan Roese7de9fc72007-10-05 17:11:30 +0200350
Stefan Roese89bac402007-10-13 16:43:23 +0200351 /*
352 * Config access can only go down stream
353 */
354 hose->last_busno = pci_hose_scan(hose);
355 bus = hose->last_busno + 1;
Stefan Roese7de9fc72007-10-05 17:11:30 +0200356 }
Stefan Roese7de9fc72007-10-05 17:11:30 +0200357 }
358}
359#endif
360
361#if defined(CONFIG_POST)
362/*
363 * Returns 1 if keys pressed to start the power-on long-running tests
364 * Called from board_init_f().
365 */
366int post_hotkeys_pressed(void)
367{
368 return 0; /* No hotkeys supported */
369}
370#endif /* CONFIG_POST */
371
372#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
373void ft_board_setup(void *blob, bd_t *bd)
374{
Stefan Roese2ae6b912007-10-11 11:15:59 +0200375 u32 val[4];
376 int rc;
377
Stefan Roese7de9fc72007-10-05 17:11:30 +0200378 ft_cpu_setup(blob, bd);
Stefan Roese2ae6b912007-10-11 11:15:59 +0200379
380 /* Fixup NOR mapping */
381 val[0] = 0; /* chip select number */
382 val[1] = 0; /* always 0 */
383 val[2] = gd->bd->bi_flashstart;
384 val[3] = gd->bd->bi_flashsize;
385 rc = fdt_find_and_setprop(blob, "/plb/opb/ebc", "ranges",
386 val, sizeof(val), 1);
387 if (rc)
388 printf("Unable to update property NOR mapping, err=%s\n",
389 fdt_strerror(rc));
Stefan Roese7de9fc72007-10-05 17:11:30 +0200390}
391#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */