blob: 5cd822a7fa6b9b63dc7fd50b8284e00023bbf8b5 [file] [log] [blame]
Stefan Roese566806c2007-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>
Stefan Roese8697e6a2007-12-13 14:52:53 +010028#include <fdt_support.h>
Stefan Roese566806c2007-10-05 17:11:30 +020029#include <asm/processor.h>
Stefan Roese353f2682007-10-23 10:10:08 +020030#include <asm/io.h>
Stefan Roese06dfaee2009-10-02 14:35:16 +020031#include <asm/errno.h>
Stefan Roese566806c2007-10-05 17:11:30 +020032
33#if defined(CONFIG_PCI)
34#include <pci.h>
35#include <asm/4xx_pcie.h>
36#endif
37
38DECLARE_GLOBAL_DATA_PTR;
39
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020040extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roese566806c2007-10-05 17:11:30 +020041
Stefan Roese566806c2007-10-05 17:11:30 +020042/*
43 * Board early initialization function
44 */
45int board_early_init_f (void)
46{
47 u32 val;
48
49 /*--------------------------------------------------------------------+
50 | Interrupt controller setup for the AMCC 405EX(r) PINE evaluation board.
51 +--------------------------------------------------------------------+
52 +---------------------------------------------------------------------+
53 |Interrupt| Source | Pol. | Sensi.| Crit. |
54 +---------+-----------------------------------+-------+-------+-------+
55 | IRQ 00 | UART0 | High | Level | Non |
56 | IRQ 01 | UART1 | High | Level | Non |
57 | IRQ 02 | IIC0 | High | Level | Non |
58 | IRQ 03 | TBD | High | Level | Non |
59 | IRQ 04 | TBD | High | Level | Non |
60 | IRQ 05 | EBM | High | Level | Non |
61 | IRQ 06 | BGI | High | Level | Non |
62 | IRQ 07 | IIC1 | Rising| Edge | Non |
63 | IRQ 08 | SPI | High | Lvl/ed| Non |
64 | IRQ 09 | External IRQ 0 - (PCI-Express) | pgm H | Pgm | Non |
65 | IRQ 10 | MAL TX EOB | High | Level | Non |
66 | IRQ 11 | MAL RX EOB | High | Level | Non |
67 | IRQ 12 | DMA Channel 0 FIFO Full | High | Level | Non |
68 | IRQ 13 | DMA Channel 0 Stat FIFO | High | Level | Non |
69 | IRQ 14 | DMA Channel 1 FIFO Full | High | Level | Non |
70 | IRQ 15 | DMA Channel 1 Stat FIFO | High | Level | Non |
71 | IRQ 16 | PCIE0 AL | high | Level | Non |
72 | IRQ 17 | PCIE0 VPD access | rising| Edge | Non |
73 | IRQ 18 | PCIE0 hot reset request | rising| Edge | Non |
74 | IRQ 19 | PCIE0 hot reset request | faling| Edge | Non |
75 | IRQ 20 | PCIE0 TCR | High | Level | Non |
76 | IRQ 21 | PCIE0 MSI level0 | High | Level | Non |
77 | IRQ 22 | PCIE0 MSI level1 | High | Level | Non |
78 | IRQ 23 | Security EIP-94 | High | Level | Non |
79 | IRQ 24 | EMAC0 interrupt | High | Level | Non |
80 | IRQ 25 | EMAC1 interrupt | High | Level | Non |
81 | IRQ 26 | PCIE0 MSI level2 | High | Level | Non |
82 | IRQ 27 | External IRQ 4 | pgm H | Pgm | Non |
83 | IRQ 28 | UIC2 Non-critical Int. | High | Level | Non |
84 | IRQ 29 | UIC2 Critical Interrupt | High | Level | Crit. |
85 | IRQ 30 | UIC1 Non-critical Int. | High | Level | Non |
86 | IRQ 31 | UIC1 Critical Interrupt | High | Level | Crit. |
87 |----------------------------------------------------------------------
88 | IRQ 32 | MAL Serr | High | Level | Non |
89 | IRQ 33 | MAL Txde | High | Level | Non |
90 | IRQ 34 | MAL Rxde | High | Level | Non |
91 | IRQ 35 | PCIE0 bus master VC0 |falling| Edge | Non |
92 | IRQ 36 | PCIE0 DCR Error | High | Level | Non |
93 | IRQ 37 | EBC | High |Lvl Edg| Non |
94 | IRQ 38 | NDFC | High | Level | Non |
95 | IRQ 39 | GPT Compare Timer 8 | Risin | Edge | Non |
96 | IRQ 40 | GPT Compare Timer 9 | Risin | Edge | Non |
97 | IRQ 41 | PCIE1 AL | high | Level | Non |
98 | IRQ 42 | PCIE1 VPD access | rising| edge | Non |
99 | IRQ 43 | PCIE1 hot reset request | rising| Edge | Non |
100 | IRQ 44 | PCIE1 hot reset request | faling| Edge | Non |
101 | IRQ 45 | PCIE1 TCR | High | Level | Non |
102 | IRQ 46 | PCIE1 bus master VC0 |falling| Edge | Non |
103 | IRQ 47 | GPT Compare Timer 3 | Risin | Edge | Non |
104 | IRQ 48 | GPT Compare Timer 4 | Risin | Edge | Non |
105 | IRQ 49 | Ext. IRQ 7 |pgm/Fal|pgm/Lvl| Non |
106 | IRQ 50 | Ext. IRQ 8 - |pgm (H)|pgm/Lvl| Non |
107 | IRQ 51 | Ext. IRQ 9 |pgm (H)|pgm/Lvl| Non |
108 | IRQ 52 | GPT Compare Timer 5 | high | Edge | Non |
109 | IRQ 53 | GPT Compare Timer 6 | high | Edge | Non |
110 | IRQ 54 | GPT Compare Timer 7 | high | Edge | Non |
111 | IRQ 55 | Serial ROM | High | Level | Non |
112 | IRQ 56 | GPT Decrement Pulse | High | Level | Non |
113 | IRQ 57 | Ext. IRQ 2 |pgm/Fal|pgm/Lvl| Non |
114 | IRQ 58 | Ext. IRQ 5 |pgm/Fal|pgm/Lvl| Non |
115 | IRQ 59 | Ext. IRQ 6 |pgm/Fal|pgm/Lvl| Non |
116 | IRQ 60 | EMAC0 Wake-up | High | Level | Non |
117 | IRQ 61 | Ext. IRQ 1 |pgm/Fal|pgm/Lvl| Non |
118 | IRQ 62 | EMAC1 Wake-up | High | Level | Non |
119 |----------------------------------------------------------------------
120 | IRQ 64 | PE0 AL | High | Level | Non |
121 | IRQ 65 | PE0 VPD Access | Risin | Edge | Non |
122 | IRQ 66 | PE0 Hot Reset Request | Risin | Edge | Non |
123 | IRQ 67 | PE0 Hot Reset Request | Falli | Edge | Non |
124 | IRQ 68 | PE0 TCR | High | Level | Non |
125 | IRQ 69 | PE0 BusMaster VCO | Falli | Edge | Non |
126 | IRQ 70 | PE0 DCR Error | High | Level | Non |
127 | IRQ 71 | Reserved | N/A | N/A | Non |
128 | IRQ 72 | PE1 AL | High | Level | Non |
129 | IRQ 73 | PE1 VPD Access | Risin | Edge | Non |
130 | IRQ 74 | PE1 Hot Reset Request | Risin | Edge | Non |
131 | IRQ 75 | PE1 Hot Reset Request | Falli | Edge | Non |
132 | IRQ 76 | PE1 TCR | High | Level | Non |
133 | IRQ 77 | PE1 BusMaster VCO | Falli | Edge | Non |
134 | IRQ 78 | PE1 DCR Error | High | Level | Non |
135 | IRQ 79 | Reserved | N/A | N/A | Non |
136 | IRQ 80 | PE2 AL | High | Level | Non |
137 | IRQ 81 | PE2 VPD Access | Risin | Edge | Non |
138 | IRQ 82 | PE2 Hot Reset Request | Risin | Edge | Non |
139 | IRQ 83 | PE2 Hot Reset Request | Falli | Edge | Non |
140 | IRQ 84 | PE2 TCR | High | Level | Non |
141 | IRQ 85 | PE2 BusMaster VCO | Falli | Edge | Non |
142 | IRQ 86 | PE2 DCR Error | High | Level | Non |
143 | IRQ 87 | Reserved | N/A | N/A | Non |
144 | IRQ 88 | External IRQ(5) | Progr | Progr | Non |
145 | IRQ 89 | External IRQ 4 - Ethernet | Progr | Progr | Non |
146 | IRQ 90 | External IRQ 3 - PCI-X | Progr | Progr | Non |
147 | IRQ 91 | External IRQ 2 - PCI-X | Progr | Progr | Non |
148 | IRQ 92 | External IRQ 1 - PCI-X | Progr | Progr | Non |
149 | IRQ 93 | External IRQ 0 - PCI-X | Progr | Progr | Non |
150 | IRQ 94 | Reserved | N/A | N/A | Non |
151 | IRQ 95 | Reserved | N/A | N/A | Non |
152 |---------------------------------------------------------------------
153 +---------+-----------------------------------+-------+-------+------*/
154 /*--------------------------------------------------------------------+
155 | Initialise UIC registers. Clear all interrupts. Disable all
156 | interrupts.
157 | Set critical interrupt values. Set interrupt polarities. Set
158 | interrupt trigger levels. Make bit 0 High priority. Clear all
159 | interrupts again.
160 +-------------------------------------------------------------------*/
161
Stefan Roese952e7762009-09-24 09:55:50 +0200162 mtdcr (UIC2SR, 0xffffffff); /* Clear all interrupts */
163 mtdcr (UIC2ER, 0x00000000); /* disable all interrupts */
164 mtdcr (UIC2CR, 0x00000000); /* Set Critical / Non Critical interrupts */
165 mtdcr (UIC2PR, 0xf7ffffff); /* Set Interrupt Polarities */
166 mtdcr (UIC2TR, 0x01e1fff8); /* Set Interrupt Trigger Levels */
167 mtdcr (UIC2VR, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
168 mtdcr (UIC2SR, 0x00000000); /* clear all interrupts */
169 mtdcr (UIC2SR, 0xffffffff); /* clear all interrupts */
Stefan Roese566806c2007-10-05 17:11:30 +0200170
Stefan Roese952e7762009-09-24 09:55:50 +0200171 mtdcr (UIC1SR, 0xffffffff); /* Clear all interrupts */
172 mtdcr (UIC1ER, 0x00000000); /* disable all interrupts */
173 mtdcr (UIC1CR, 0x00000000); /* Set Critical / Non Critical interrupts */
174 mtdcr (UIC1PR, 0xfffac785); /* Set Interrupt Polarities */
175 mtdcr (UIC1TR, 0x001d0040); /* Set Interrupt Trigger Levels */
176 mtdcr (UIC1VR, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
177 mtdcr (UIC1SR, 0x00000000); /* clear all interrupts */
178 mtdcr (UIC1SR, 0xffffffff); /* clear all interrupts */
Stefan Roese566806c2007-10-05 17:11:30 +0200179
Stefan Roese952e7762009-09-24 09:55:50 +0200180 mtdcr (UIC0SR, 0xffffffff); /* Clear all interrupts */
181 mtdcr (UIC0ER, 0x0000000a); /* Disable all interrupts */
Stefan Roese566806c2007-10-05 17:11:30 +0200182 /* Except cascade UIC0 and UIC1 */
Stefan Roese952e7762009-09-24 09:55:50 +0200183 mtdcr (UIC0CR, 0x00000000); /* Set Critical / Non Critical interrupts */
184 mtdcr (UIC0PR, 0xffbfefef); /* Set Interrupt Polarities */
185 mtdcr (UIC0TR, 0x00007000); /* Set Interrupt Trigger Levels */
186 mtdcr (UIC0VR, 0x00000001); /* Set Vect base=0,INT31 Highest priority */
187 mtdcr (UIC0SR, 0x00000000); /* clear all interrupts */
188 mtdcr (UIC0SR, 0xffffffff); /* clear all interrupts */
Stefan Roese566806c2007-10-05 17:11:30 +0200189
190 /*
191 * Note: Some cores are still in reset when the chip starts, so
192 * take them out of reset
193 */
194 mtsdr(SDR0_SRST, 0);
195
Stefan Roese566806c2007-10-05 17:11:30 +0200196 /* Configure 405EX for NAND usage */
197 val = SDR0_CUST0_MUX_NDFC_SEL |
198 SDR0_CUST0_NDFC_ENABLE |
199 SDR0_CUST0_NDFC_BW_8_BIT |
200 SDR0_CUST0_NRB_BUSY |
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200201 (0x80000000 >> (28 + CONFIG_SYS_NAND_CS));
Stefan Roese566806c2007-10-05 17:11:30 +0200202 mtsdr(SDR0_CUST0, val);
203
Stefan Roese7cfc12a2007-12-08 14:47:34 +0100204 /*
205 * Configure PFC (Pin Function Control) registers
206 * -> Enable USB
207 */
208 val = SDR0_PFC1_USBEN | SDR0_PFC1_USBBIGEN | SDR0_PFC1_GPT_FREQ;
209 mtsdr(SDR0_PFC1, val);
210
Stefan Roesea0dd99d2008-01-14 10:05:05 +0100211 /*
212 * Configure FPGA register with PCIe reset
213 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200214 out_be32((void *)CONFIG_SYS_FPGA_BASE, 0xff570cc4); /* assert PCIe reset */
Stefan Roesea0dd99d2008-01-14 10:05:05 +0100215 mdelay(50);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200216 out_be32((void *)CONFIG_SYS_FPGA_BASE, 0xff570cc7); /* deassert PCIe reset */
Stefan Roesea0dd99d2008-01-14 10:05:05 +0100217
Stefan Roese566806c2007-10-05 17:11:30 +0200218 return 0;
219}
220
221int misc_init_r(void)
222{
Jean-Christophe PLAGNIOL-VILLARD5a1aceb2008-09-10 22:48:04 +0200223#ifdef CONFIG_ENV_IS_IN_FLASH
Stefan Roese566806c2007-10-05 17:11:30 +0200224 /* Monitor protection ON by default */
225 flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200226 -CONFIG_SYS_MONITOR_LEN,
Stefan Roese566806c2007-10-05 17:11:30 +0200227 0xffffffff,
228 &flash_info[0]);
229#endif
230
231 return 0;
232}
233
Stefan Roese70fab192008-05-13 20:22:01 +0200234static int is_405exr(void)
Stefan Roese353f2682007-10-23 10:10:08 +0200235{
236 u32 pvr = get_pvr();
237
Stefan Roese70fab192008-05-13 20:22:01 +0200238 if (pvr & 0x00000004)
239 return 0; /* bit 2 set -> 405EX */
240
241 return 1; /* bit 2 cleared -> 405EXr */
242}
243
244int board_emac_count(void)
245{
Stefan Roese353f2682007-10-23 10:10:08 +0200246 /*
247 * 405EXr only has one EMAC interface, 405EX has two
248 */
Stefan Roese70fab192008-05-13 20:22:01 +0200249 if (is_405exr())
Stefan Roese353f2682007-10-23 10:10:08 +0200250 return 1;
251 else
252 return 2;
253}
254
255static int board_pcie_count(void)
256{
Stefan Roese353f2682007-10-23 10:10:08 +0200257 /*
258 * 405EXr only has one EMAC interface, 405EX has two
259 */
Stefan Roese70fab192008-05-13 20:22:01 +0200260 if (is_405exr())
Stefan Roese353f2682007-10-23 10:10:08 +0200261 return 1;
262 else
263 return 2;
264}
265
Stefan Roese566806c2007-10-05 17:11:30 +0200266int checkboard (void)
267{
268 char *s = getenv("serial#");
269
Stefan Roese70fab192008-05-13 20:22:01 +0200270 if (is_405exr())
Stefan Roese353f2682007-10-23 10:10:08 +0200271 printf("Board: Haleakala - AMCC PPC405EXr Evaluation Board");
272 else
273 printf("Board: Kilauea - AMCC PPC405EX Evaluation Board");
Stefan Roese566806c2007-10-05 17:11:30 +0200274
275 if (s != NULL) {
276 puts(", serial# ");
277 puts(s);
278 }
279 putc('\n');
280
281 return (0);
282}
283
284/*************************************************************************
285 * pci_pre_init
286 *
287 * This routine is called just prior to registering the hose and gives
288 * the board the opportunity to check things. Returning a value of zero
289 * indicates that things are bad & PCI initialization should be aborted.
290 *
291 * Different boards may wish to customize the pci controller structure
292 * (add regions, override default access routines, etc) or perform
293 * certain pre-initialization actions.
294 *
295 ************************************************************************/
296#if defined(CONFIG_PCI)
297int pci_pre_init(struct pci_controller * hose )
298{
299 return 0;
300}
301#endif /* defined(CONFIG_PCI) */
302
Stefan Roese566806c2007-10-05 17:11:30 +0200303#ifdef CONFIG_PCI
Stefan Roese566806c2007-10-05 17:11:30 +0200304static struct pci_controller pcie_hose[2] = {{0},{0}};
305
306void pcie_setup_hoses(int busno)
307{
308 struct pci_controller *hose;
309 int i, bus;
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200310 int ret = 0;
Stefan Roese566806c2007-10-05 17:11:30 +0200311 bus = busno;
312 char *env;
313 unsigned int delay;
314
Stefan Roese353f2682007-10-23 10:10:08 +0200315 for (i = 0; i < board_pcie_count(); i++) {
Stefan Roese566806c2007-10-05 17:11:30 +0200316
Stefan Roese654f38b2007-11-05 07:43:05 +0100317 if (is_end_point(i))
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200318 ret = ppc4xx_init_pcie_endport(i);
Stefan Roese654f38b2007-11-05 07:43:05 +0100319 else
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200320 ret = ppc4xx_init_pcie_rootport(i);
Stefan Roese06dfaee2009-10-02 14:35:16 +0200321 if (ret == -ENODEV)
322 continue;
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200323 if (ret) {
Stefan Roese654f38b2007-11-05 07:43:05 +0100324 printf("PCIE%d: initialization as %s failed\n", i,
325 is_end_point(i) ? "endpoint" : "root-complex");
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200326 continue;
Stefan Roese566806c2007-10-05 17:11:30 +0200327 }
328
329 hose = &pcie_hose[i];
330 hose->first_busno = bus;
331 hose->last_busno = bus;
332 hose->current_busno = bus;
333
334 /* setup mem resource */
335 pci_set_region(hose->regions + 0,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200336 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
337 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
338 CONFIG_SYS_PCIE_MEMSIZE,
Stefan Roese566806c2007-10-05 17:11:30 +0200339 PCI_REGION_MEM);
340 hose->region_count = 1;
341 pci_register_hose(hose);
342
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200343 if (is_end_point(i)) {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200344 ppc4xx_setup_pcie_endpoint(hose, i);
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200345 /*
346 * Reson for no scanning is endpoint can not generate
347 * upstream configuration accesses.
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200348 */
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200349 } else {
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200350 ppc4xx_setup_pcie_rootpoint(hose, i);
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200351 env = getenv ("pciscandelay");
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200352 if (env != NULL) {
353 delay = simple_strtoul(env, NULL, 10);
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200354 if (delay > 5)
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200355 printf("Warning, expect noticable delay before "
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200356 "PCIe scan due to 'pciscandelay' value!\n");
357 mdelay(delay * 1000);
358 }
Stefan Roese566806c2007-10-05 17:11:30 +0200359
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200360 /*
361 * Config access can only go down stream
362 */
363 hose->last_busno = pci_hose_scan(hose);
364 bus = hose->last_busno + 1;
Stefan Roese566806c2007-10-05 17:11:30 +0200365 }
Stefan Roese566806c2007-10-05 17:11:30 +0200366 }
367}
368#endif
369
370#if defined(CONFIG_POST)
371/*
372 * Returns 1 if keys pressed to start the power-on long-running tests
373 * Called from board_init_f().
374 */
375int post_hotkeys_pressed(void)
376{
377 return 0; /* No hotkeys supported */
378}
379#endif /* CONFIG_POST */