blob: cd65a7341e6ca360f7ef66d65087671a72678ede [file] [log] [blame]
Peter Tyser1c2b3292008-12-17 16:36:23 -06001/*
2 * Copyright 2008 Extreme Engineering Solutions, Inc.
3 * Copyright 2007-2008 Freescale Semiconductor, Inc.
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 <pci.h>
26#include <asm/immap_85xx.h>
27#include <asm/immap_fsl_pci.h>
28#include <libfdt.h>
29#include <fdt_support.h>
30
31extern int fsl_pci_setup_inbound_windows(struct pci_region *r);
Peter Tyser2143be82008-10-29 12:39:27 -050032extern void fsl_pci_config_unlock(struct pci_controller *hose);
Peter Tyser1c2b3292008-12-17 16:36:23 -060033extern void fsl_pci_init(struct pci_controller *hose);
34
35int first_free_busno = 0;
36
Peter Tyser59b5fdf2008-12-01 13:47:13 -060037#ifdef CONFIG_PCI1
38static struct pci_controller pci1_hose;
39#endif
Peter Tyser1c2b3292008-12-17 16:36:23 -060040#ifdef CONFIG_PCIE1
41static struct pci_controller pcie1_hose;
42#endif
43#ifdef CONFIG_PCIE2
44static struct pci_controller pcie2_hose;
45#endif
46#ifdef CONFIG_PCIE3
47static struct pci_controller pcie3_hose;
48#endif
49
Peter Tyser59b5fdf2008-12-01 13:47:13 -060050#ifdef CONFIG_MPC8572
Peter Tyser1c2b3292008-12-17 16:36:23 -060051/* Correlate host/agent POR bits to usable info. Table 4-14 */
52struct host_agent_cfg_t {
53 uchar pcie_root[3];
54 uchar rio_host;
55} host_agent_cfg[8] = {
56 {{0, 0, 0}, 0},
57 {{0, 1, 1}, 1},
58 {{1, 0, 1}, 0},
59 {{1, 1, 0}, 1},
60 {{0, 0, 1}, 0},
61 {{0, 1, 0}, 1},
62 {{1, 0, 0}, 0},
63 {{1, 1, 1}, 1}
64};
65
66/* Correlate port width POR bits to usable info. Table 4-15 */
67struct io_port_cfg_t {
68 uchar pcie_width[3];
69 uchar rio_width;
70} io_port_cfg[16] = {
71 {{0, 0, 0}, 0},
72 {{0, 0, 0}, 0},
73 {{4, 0, 0}, 0},
74 {{4, 4, 0}, 0},
75 {{0, 0, 0}, 0},
76 {{0, 0, 0}, 0},
77 {{0, 0, 0}, 4},
78 {{4, 2, 2}, 0},
79 {{0, 0, 0}, 0},
80 {{0, 0, 0}, 0},
81 {{0, 0, 0}, 0},
82 {{4, 0, 0}, 4},
83 {{4, 0, 0}, 4},
84 {{0, 0, 0}, 4},
85 {{0, 0, 0}, 4},
86 {{8, 0, 0}, 0},
87};
Peter Tyser59b5fdf2008-12-01 13:47:13 -060088#elif defined CONFIG_MPC8548
89/* Correlate host/agent POR bits to usable info. Table 4-12 */
90struct host_agent_cfg_t {
91 uchar pci_host[2];
92 uchar pcie_root[1];
93 uchar rio_host;
94} host_agent_cfg[8] = {
95 {{1, 1}, {0}, 0},
96 {{1, 1}, {1}, 0},
97 {{1, 1}, {0}, 1},
98 {{0, 0}, {0}, 0}, /* reserved */
99 {{0, 1}, {1}, 0},
100 {{1, 1}, {1}, 0},
101 {{0, 1}, {1}, 1},
102 {{1, 1}, {1}, 1}
103};
Peter Tyser1c2b3292008-12-17 16:36:23 -0600104
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600105/* Correlate port width POR bits to usable info. Table 4-13 */
106struct io_port_cfg_t {
107 uchar pcie_width[1];
108 uchar rio_width;
109} io_port_cfg[8] = {
110 {{0}, 0},
111 {{0}, 0},
112 {{0}, 0},
113 {{4}, 4},
114 {{4}, 4},
115 {{0}, 4},
116 {{0}, 4},
117 {{8}, 0},
118};
119#endif
120
Peter Tyser1c2b3292008-12-17 16:36:23 -0600121void pci_init_board(void)
122{
123 struct pci_controller *hose;
124 volatile ccsr_fsl_pci_t *pci;
125 int width;
126 int host;
127 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
128 uint devdisr = gur->devdisr;
129 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
130 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
131 struct pci_region *r;
132
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600133#ifdef CONFIG_PCI1
134 uint pci_spd_norm = (gur->pordevsr & MPC85xx_PORDEVSR_PCI1_SPD);
135 uint pci_32 = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_PCI32;
136 uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB;
137 uint pcix = gur->pordevsr & MPC85xx_PORDEVSR_PCI1;
138 uint freq = CONFIG_SYS_CLK_FREQ / 1000 / 1000;
139
140 width = 0; /* Silence compiler warning... */
141 io_sel &= 0xf; /* Silence compiler warning... */
142 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
143 hose = &pci1_hose;
144 host = host_agent_cfg[host_agent].pci_host[0];
145 r = hose->regions;
146
147
148 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
149 printf("\n PCI1: %d bit %s, %s %d MHz, %s, %s\n",
150 pci_32 ? 32 : 64,
151 pcix ? "PCIX" : "PCI",
152 pci_spd_norm ? ">=" : "<=",
153 pcix ? freq * 2 : freq,
154 host ? "host" : "agent",
155 pci_arb ? "arbiter" : "external-arbiter");
156
157 /* inbound */
158 r += fsl_pci_setup_inbound_windows(r);
159
160 /* outbound memory */
161 pci_set_region(r++,
162 CONFIG_SYS_PCI1_MEM_BASE,
163 CONFIG_SYS_PCI1_MEM_PHYS,
164 CONFIG_SYS_PCI1_MEM_SIZE,
165 PCI_REGION_MEM);
166
167 /* outbound io */
168 pci_set_region(r++,
169 CONFIG_SYS_PCI1_IO_BASE,
170 CONFIG_SYS_PCI1_IO_PHYS,
171 CONFIG_SYS_PCI1_IO_SIZE,
172 PCI_REGION_IO);
173
174 hose->region_count = r - hose->regions;
Peter Tyser1c2b3292008-12-17 16:36:23 -0600175
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600176 hose->first_busno = first_free_busno;
177 pci_setup_indirect(hose, (int)&pci->cfg_addr,
178 (int)&pci->cfg_data);
179
180 fsl_pci_init(hose);
181
Peter Tyserf3c970c2008-12-23 16:32:00 -0600182 first_free_busno = hose->last_busno + 1;
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600183 printf(" PCI1 on bus %02x - %02x\n",
184 hose->first_busno, hose->last_busno);
185 } else {
186 printf(" PCI1: disabled\n");
187 }
188#elif defined CONFIG_MPC8548
189 /* PCI1 not present on MPC8572 */
190 gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
191#endif
Peter Tyser1c2b3292008-12-17 16:36:23 -0600192#ifdef CONFIG_PCIE1
193 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
194 hose = &pcie1_hose;
195 host = host_agent_cfg[host_agent].pcie_root[0];
196 width = io_port_cfg[io_sel].pcie_width[0];
197 r = hose->regions;
198
199 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
200 printf("\n PCIE1 connected as %s (x%d)",
201 host ? "Root Complex" : "End Point", width);
202 if (pci->pme_msg_det) {
203 pci->pme_msg_det = 0xffffffff;
204 debug(" with errors. Clearing. Now 0x%08x",
205 pci->pme_msg_det);
206 }
207 printf("\n");
208
209 /* inbound */
210 r += fsl_pci_setup_inbound_windows(r);
211
212 /* outbound memory */
213 pci_set_region(r++,
214 CONFIG_SYS_PCIE1_MEM_BASE,
215 CONFIG_SYS_PCIE1_MEM_PHYS,
216 CONFIG_SYS_PCIE1_MEM_SIZE,
217 PCI_REGION_MEM);
218
219 /* outbound io */
220 pci_set_region(r++,
221 CONFIG_SYS_PCIE1_IO_BASE,
222 CONFIG_SYS_PCIE1_IO_PHYS,
223 CONFIG_SYS_PCIE1_IO_SIZE,
224 PCI_REGION_IO);
225
226 hose->region_count = r - hose->regions;
227
228 hose->first_busno = first_free_busno;
229 pci_setup_indirect(hose, (int)&pci->cfg_addr,
230 (int) &pci->cfg_data);
231
232 fsl_pci_init(hose);
233
Peter Tyser2143be82008-10-29 12:39:27 -0500234 /* Unlock inbound PCI configuration cycles */
235 if (!host)
236 fsl_pci_config_unlock(hose);
237
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600238 first_free_busno = hose->last_busno + 1;
Peter Tyser1c2b3292008-12-17 16:36:23 -0600239 printf(" PCIE1 on bus %02x - %02x\n",
240 hose->first_busno, hose->last_busno);
241 }
242#else
243 gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
244#endif /* CONFIG_PCIE1 */
245
246#ifdef CONFIG_PCIE2
247 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
248 hose = &pcie2_hose;
249 host = host_agent_cfg[host_agent].pcie_root[1];
250 width = io_port_cfg[io_sel].pcie_width[1];
251 r = hose->regions;
252
253 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
254 printf("\n PCIE2 connected as %s (x%d)",
255 host ? "Root Complex" : "End Point", width);
256 if (pci->pme_msg_det) {
257 pci->pme_msg_det = 0xffffffff;
258 debug(" with errors. Clearing. Now 0x%08x",
259 pci->pme_msg_det);
260 }
261 printf("\n");
262
263 /* inbound */
264 r += fsl_pci_setup_inbound_windows(r);
265
266 /* outbound memory */
267 pci_set_region(r++,
268 CONFIG_SYS_PCIE2_MEM_BASE,
269 CONFIG_SYS_PCIE2_MEM_PHYS,
270 CONFIG_SYS_PCIE2_MEM_SIZE,
271 PCI_REGION_MEM);
272
273 /* outbound io */
274 pci_set_region(r++,
275 CONFIG_SYS_PCIE2_IO_BASE,
276 CONFIG_SYS_PCIE2_IO_PHYS,
277 CONFIG_SYS_PCIE2_IO_SIZE,
278 PCI_REGION_IO);
279
280 hose->region_count = r - hose->regions;
281
282 hose->first_busno = first_free_busno;
283 pci_setup_indirect(hose, (int)&pci->cfg_addr,
284 (int)&pci->cfg_data);
285
286 fsl_pci_init(hose);
Peter Tyser2143be82008-10-29 12:39:27 -0500287
288 /* Unlock inbound PCI configuration cycles */
289 if (!host)
290 fsl_pci_config_unlock(hose);
291
Peter Tyserf3c970c2008-12-23 16:32:00 -0600292 first_free_busno = hose->last_busno + 1;
Peter Tyser1c2b3292008-12-17 16:36:23 -0600293 printf(" PCIE2 on bus %02x - %02x\n",
294 hose->first_busno, hose->last_busno);
Peter Tyser1c2b3292008-12-17 16:36:23 -0600295 }
296#else
297 gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
298#endif /* CONFIG_PCIE2 */
299
300#ifdef CONFIG_PCIE3
301 pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
302 hose = &pcie3_hose;
303 host = host_agent_cfg[host_agent].pcie_root[2];
304 width = io_port_cfg[io_sel].pcie_width[2];
305 r = hose->regions;
306
307 if (width && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
308 printf("\n PCIE3 connected as %s (x%d)",
309 host ? "Root Complex" : "End Point", width);
310 if (pci->pme_msg_det) {
311 pci->pme_msg_det = 0xffffffff;
312 debug(" with errors. Clearing. Now 0x%08x",
313 pci->pme_msg_det);
314 }
315 printf("\n");
316
317 /* inbound */
318 r += fsl_pci_setup_inbound_windows(r);
319
320 /* outbound memory */
321 pci_set_region(r++,
322 CONFIG_SYS_PCIE3_MEM_BASE,
323 CONFIG_SYS_PCIE3_MEM_PHYS,
324 CONFIG_SYS_PCIE3_MEM_SIZE,
325 PCI_REGION_MEM);
326
327 /* outbound io */
328 pci_set_region(r++,
329 CONFIG_SYS_PCIE3_IO_BASE,
330 CONFIG_SYS_PCIE3_IO_PHYS,
331 CONFIG_SYS_PCIE3_IO_SIZE,
332 PCI_REGION_IO);
333
334 hose->region_count = r - hose->regions;
335
336 hose->first_busno = first_free_busno;
337 pci_setup_indirect(hose, (int)&pci->cfg_addr,
338 (int)&pci->cfg_data);
339
340 fsl_pci_init(hose);
Peter Tyser2143be82008-10-29 12:39:27 -0500341
342 /* Unlock inbound PCI configuration cycles */
343 if (!host)
344 fsl_pci_config_unlock(hose);
345
Peter Tyserf3c970c2008-12-23 16:32:00 -0600346 first_free_busno = hose->last_busno + 1;
Peter Tyser1c2b3292008-12-17 16:36:23 -0600347 printf(" PCIE3 on bus %02x - %02x\n",
348 hose->first_busno, hose->last_busno);
349 }
350#else
351 gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
352#endif /* CONFIG_PCIE3 */
353}
354
355#if defined(CONFIG_OF_BOARD_SETUP)
356extern void ft_fsl_pci_setup(void *blob, const char *pci_alias,
357 struct pci_controller *hose);
358
359void ft_board_pci_setup(void *blob, bd_t *bd)
360{
Peter Tyser59b5fdf2008-12-01 13:47:13 -0600361 /* TODO - make node name (eg pci0) dynamic */
362#ifdef CONFIG_PCI1
363 ft_fsl_pci_setup(blob, "pci0", &pci1_hose);
364#endif
Peter Tyser1c2b3292008-12-17 16:36:23 -0600365#ifdef CONFIG_PCIE1
366 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
367#endif
368#ifdef CONFIG_PCIE2
369 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
370#endif
371#ifdef CONFIG_PCIE3
372 ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
373#endif
374}
375#endif /* CONFIG_OF_BOARD_SETUP */