blob: a87e93b80c112a7191dbdf709779ca8642258e7e [file] [log] [blame]
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001/*
Stefan Roesebdd13d12008-03-11 15:05:26 +01002 * (C) Copyright 2006 - 2008
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (c) 2005 Cisco Systems. All rights reserved.
6 * Roland Dreier <rolandd@cisco.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 */
22
Stefan Roese3dced492007-10-05 07:57:20 +020023/* define DEBUG for debugging output (obviously ;-)) */
Stefan Roesedb4f4542007-10-05 09:22:33 +020024#if 0
Stefan Roese3dced492007-10-05 07:57:20 +020025#define DEBUG
26#endif
27
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020028#include <common.h>
29#include <pci.h>
Stefan Roese247e9d72010-09-09 19:18:00 +020030#include <asm/ppc4xx.h>
Stefan Roese7105abd2008-07-10 11:38:26 +020031#include <asm/processor.h>
Peter Tyser133c0fe2010-04-12 22:28:07 -050032#include <asm/io.h>
Stefan Roese14fd12f2009-10-02 14:35:16 +020033#include <asm/errno.h>
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020034
Stefan Roesebdd13d12008-03-11 15:05:26 +010035#if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \
36 defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
Dirk Eibach6bb88a02009-02-03 15:15:21 +010037 defined(CONFIG_PCI) && !defined(CONFIG_PCI_DISABLE_PCIE)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020038
Stefan Roese216f0632007-10-03 07:34:10 +020039#include <asm/4xx_pcie.h>
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020040
41enum {
42 PTYPE_ENDPOINT = 0x0,
43 PTYPE_LEGACY_ENDPOINT = 0x1,
44 PTYPE_ROOT_PORT = 0x4,
45
46 LNKW_X1 = 0x1,
47 LNKW_X4 = 0x4,
48 LNKW_X8 = 0x8
49};
50
Stefan Roesee53b5cd2009-10-29 15:04:35 +010051static struct pci_controller pcie_hose[CONFIG_SYS_PCIE_NR_PORTS];
52
53/*
54 * Per default, all cards are present, so we need to check if the
55 * link comes up.
56 */
57int __board_pcie_card_present(int port)
58{
59 return 1;
60}
61int board_pcie_card_present(int port)
62 __attribute__((weak, alias("__board_pcie_card_present")));
63
64/*
65 * Some boards have runtime detection of the first and last PCIe
66 * slot used, so let's provide weak default functions for the
67 * common version.
68 */
69int __board_pcie_first(void)
70{
71 return 0;
72}
73int board_pcie_first(void)
74 __attribute__((weak, alias("__board_pcie_first")));
75
76int __board_pcie_last(void)
77{
78 return CONFIG_SYS_PCIE_NR_PORTS - 1;
79}
80int board_pcie_last(void)
81 __attribute__((weak, alias("__board_pcie_last")));
82
83void __board_pcie_setup_port(int port, int rootpoint)
84{
85 /* noting in this weak default implementation */
86}
87void board_pcie_setup_port(int port, int rootpoint)
88 __attribute__((weak, alias("__board_pcie_setup_port")));
89
90void pcie_setup_hoses(int busno)
91{
92 struct pci_controller *hose;
93 int i, bus;
94 int ret = 0;
95 char *env;
96 unsigned int delay;
97 int first = board_pcie_first();
98 int last = board_pcie_last();
99
100 /*
101 * Assume we're called after the PCI(X) hose(s) are initialized,
102 * which takes bus ID 0... and therefore start numbering PCIe's
103 * from the next number.
104 */
105 bus = busno;
106
107 for (i = first; i <= last; i++) {
108 /*
109 * Some boards (e.g. Katmai) can detects via hardware
110 * if a PCIe card is plugged, so let's check this.
111 */
112 if (!board_pcie_card_present(i))
113 continue;
114
115 if (is_end_point(i)) {
116 board_pcie_setup_port(i, 0);
117 ret = ppc4xx_init_pcie_endport(i);
118 } else {
119 board_pcie_setup_port(i, 1);
120 ret = ppc4xx_init_pcie_rootport(i);
121 }
122 if (ret == -ENODEV)
123 continue;
124 if (ret) {
125 printf("PCIE%d: initialization as %s failed\n", i,
126 is_end_point(i) ? "endpoint" : "root-complex");
127 continue;
128 }
129
130 hose = &pcie_hose[i];
131 hose->first_busno = bus;
132 hose->last_busno = bus;
133 hose->current_busno = bus;
134
135 /* setup mem resource */
136 pci_set_region(hose->regions + 0,
137 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
138 CONFIG_SYS_PCIE_MEMBASE + i * CONFIG_SYS_PCIE_MEMSIZE,
139 CONFIG_SYS_PCIE_MEMSIZE,
140 PCI_REGION_MEM);
141 hose->region_count = 1;
142 pci_register_hose(hose);
143
144 if (is_end_point(i)) {
145 ppc4xx_setup_pcie_endpoint(hose, i);
146 /*
147 * Reson for no scanning is endpoint can not generate
148 * upstream configuration accesses.
149 */
150 } else {
151 ppc4xx_setup_pcie_rootpoint(hose, i);
152 env = getenv ("pciscandelay");
153 if (env != NULL) {
154 delay = simple_strtoul(env, NULL, 10);
155 if (delay > 5)
156 printf("Warning, expect noticable delay before "
157 "PCIe scan due to 'pciscandelay' value!\n");
158 mdelay(delay * 1000);
159 }
160
161 /*
162 * Config access can only go down stream
163 */
164 hose->last_busno = pci_hose_scan(hose);
165 bus = hose->last_busno + 1;
166 }
167 }
168}
Stefan Roesee53b5cd2009-10-29 15:04:35 +0100169
Stefan Roese89bac402007-10-13 16:43:23 +0200170static int validate_endpoint(struct pci_controller *hose)
171{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200172 if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200173 return (is_end_point(0));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200174 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200175 return (is_end_point(1));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200176#if CONFIG_SYS_PCIE_NR_PORTS > 2
177 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roese89bac402007-10-13 16:43:23 +0200178 return (is_end_point(2));
179#endif
180
181 return 0;
182}
183
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200184static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
185{
186 u8 *base = (u8*)hose->cfg_data;
187
188 /* use local configuration space for the first bus */
189 if (PCI_BUS(devfn) == 0) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200190 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE)
191 base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE;
192 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE)
193 base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE;
194#if CONFIG_SYS_PCIE_NR_PORTS > 2
195 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE)
196 base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE;
Stefan Roese7a41bde2007-10-05 09:18:23 +0200197#endif
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200198 }
199
200 return base;
201}
202
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200203static void pcie_dmer_disable(void)
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200204{
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200205 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
206 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
207 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
208 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200209#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200210 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
211 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
Stefan Roese7a41bde2007-10-05 09:18:23 +0200212#endif
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200213}
214
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200215static void pcie_dmer_enable(void)
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200216{
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200217 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
218 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
219 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
220 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200221#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200222 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
223 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
Stefan Roese7a41bde2007-10-05 09:18:23 +0200224#endif
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200225}
226
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200227static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
228 int offset, int len, u32 *val) {
229
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200230 u8 *address;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200231 *val = 0;
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200232
Stefan Roese89bac402007-10-13 16:43:23 +0200233 if (validate_endpoint(hose))
234 return 0; /* No upstream config access */
235
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200236 /*
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200237 * Bus numbers are relative to hose->first_busno
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200238 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200239 devfn -= PCI_BDF(hose->first_busno, 0, 0);
240
241 /*
242 * NOTICE: configuration space ranges are currenlty mapped only for
243 * the first 16 buses, so such limit must be imposed. In case more
244 * buses are required the TLB settings in board/amcc/<board>/init.S
245 * need to be altered accordingly (one bus takes 1 MB of memory space).
246 */
247 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200248 return 0;
249
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200250 /*
251 * Only single device/single function is supported for the primary and
252 * secondary buses of the 440SPe host bridge.
253 */
254 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
255 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
256 return 0;
Stefan Roese43867c82007-10-02 11:44:46 +0200257
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200258 address = pcie_get_base(hose, devfn);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200259 offset += devfn << 4;
260
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200261 /*
262 * Reading from configuration space of non-existing device can
263 * generate transaction errors. For the read duration we suppress
264 * assertion of machine check exceptions to avoid those.
265 */
266 pcie_dmer_disable ();
267
Marek Vasut60814902011-10-21 14:17:15 +0000268 debug("%s: cfg_data=%p offset=%08x\n", __func__,
269 hose->cfg_data, offset);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200270 switch (len) {
271 case 1:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200272 *val = in_8(hose->cfg_data + offset);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200273 break;
274 case 2:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200275 *val = in_le16((u16 *)(hose->cfg_data + offset));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200276 break;
277 default:
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200278 *val = in_le32((u32*)(hose->cfg_data + offset));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200279 break;
280 }
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200281
282 pcie_dmer_enable ();
283
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200284 return 0;
285}
286
287static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
288 int offset, int len, u32 val) {
289
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200290 u8 *address;
Stefan Roese43867c82007-10-02 11:44:46 +0200291
Stefan Roese89bac402007-10-13 16:43:23 +0200292 if (validate_endpoint(hose))
293 return 0; /* No upstream config access */
294
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200295 /*
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200296 * Bus numbers are relative to hose->first_busno
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200297 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200298 devfn -= PCI_BDF(hose->first_busno, 0, 0);
Stefan Roese43867c82007-10-02 11:44:46 +0200299
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200300 /*
301 * Same constraints as in pcie_read_config().
302 */
303 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200304 return 0;
305
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200306 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
307 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
308 return 0;
Stefan Roese43867c82007-10-02 11:44:46 +0200309
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200310 address = pcie_get_base(hose, devfn);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200311 offset += devfn << 4;
312
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200313 /*
314 * Suppress MCK exceptions, similar to pcie_read_config()
315 */
316 pcie_dmer_disable ();
317
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200318 switch (len) {
319 case 1:
320 out_8(hose->cfg_data + offset, val);
321 break;
322 case 2:
323 out_le16((u16 *)(hose->cfg_data + offset), val);
324 break;
325 default:
326 out_le32((u32 *)(hose->cfg_data + offset), val);
327 break;
328 }
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200329
330 pcie_dmer_enable ();
331
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200332 return 0;
333}
334
335int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
336{
337 u32 v;
338 int rv;
339
Grzegorz Bernackid2f21332007-09-07 18:20:23 +0200340 rv = pcie_read_config(hose, dev, offset, 1, &v);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200341 *val = (u8)v;
342 return rv;
343}
344
345int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
346{
347 u32 v;
348 int rv;
349
350 rv = pcie_read_config(hose, dev, offset, 2, &v);
351 *val = (u16)v;
352 return rv;
353}
354
355int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
356{
357 u32 v;
358 int rv;
359
360 rv = pcie_read_config(hose, dev, offset, 3, &v);
361 *val = (u32)v;
362 return rv;
363}
364
365int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
366{
367 return pcie_write_config(hose,(u32)dev,offset,1,val);
368}
369
370int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
371{
372 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
373}
374
375int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
376{
377 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
378}
379
Stefan Roese7a41bde2007-10-05 09:18:23 +0200380#if defined(CONFIG_440SPE)
Stefan Roese9c00e512007-10-03 07:48:09 +0200381static void ppc4xx_setup_utl(u32 port) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200382
383 volatile void *utl_base = NULL;
384
385 /*
386 * Map UTL registers
387 */
388 switch (port) {
389 case 0:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200390 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
391 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
392 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200393 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200394 break;
395
396 case 1:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200397 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
398 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
399 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200400 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200401 break;
402
403 case 2:
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200404 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
405 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
406 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200407 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200408 break;
409 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200410 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Wolfgang Denkdd314d12006-08-27 18:10:01 +0200411
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200412 /*
413 * Set buffer allocations and then assert VRB and TXE.
414 */
415 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
416 out_be32(utl_base + PEUTL_INTR, 0x02000000);
417 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
418 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
419 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
420 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
421 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
Rafal Jaworowskie9799092006-08-11 12:35:52 +0200422 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200423}
424
425static int check_error(void)
426{
427 u32 valPE0, valPE1, valPE2;
428 int err = 0;
429
430 /* SDR0_PEGPLLLCT1 reset */
Stefan Roesebdd13d12008-03-11 15:05:26 +0100431 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200432 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200433
434 valPE0 = SDR_READ(PESDR0_RCSSET);
435 valPE1 = SDR_READ(PESDR1_RCSSET);
436 valPE2 = SDR_READ(PESDR2_RCSSET);
437
438 /* SDR0_PExRCSSET rstgu */
439 if (!(valPE0 & 0x01000000) ||
440 !(valPE1 & 0x01000000) ||
441 !(valPE2 & 0x01000000)) {
442 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
443 err = -1;
444 }
445
446 /* SDR0_PExRCSSET rstdl */
447 if (!(valPE0 & 0x00010000) ||
448 !(valPE1 & 0x00010000) ||
449 !(valPE2 & 0x00010000)) {
450 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
451 err = -1;
452 }
453
454 /* SDR0_PExRCSSET rstpyn */
455 if ((valPE0 & 0x00001000) ||
456 (valPE1 & 0x00001000) ||
457 (valPE2 & 0x00001000)) {
458 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
459 err = -1;
460 }
461
462 /* SDR0_PExRCSSET hldplb */
463 if ((valPE0 & 0x10000000) ||
464 (valPE1 & 0x10000000) ||
465 (valPE2 & 0x10000000)) {
466 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
467 err = -1;
468 }
469
470 /* SDR0_PExRCSSET rdy */
471 if ((valPE0 & 0x00100000) ||
472 (valPE1 & 0x00100000) ||
473 (valPE2 & 0x00100000)) {
474 printf("PCIE: SDR0_PExRCSSET rdy error\n");
475 err = -1;
476 }
477
478 /* SDR0_PExRCSSET shutdown */
479 if ((valPE0 & 0x00000100) ||
480 (valPE1 & 0x00000100) ||
481 (valPE2 & 0x00000100)) {
482 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
483 err = -1;
484 }
485 return err;
486}
487
488/*
489 * Initialize PCI Express core
490 */
Stefan Roese9c00e512007-10-03 07:48:09 +0200491int ppc4xx_init_pcie(void)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200492{
493 int time_out = 20;
494
495 /* Set PLL clock receiver to LVPECL */
496 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
497
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700498 if (check_error()) {
499 printf("ERROR: failed to set PCIe reference clock receiver --"
500 "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1));
501
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200502 return -1;
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700503 }
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200504
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700505 /* Did resistance calibration work? */
506 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) {
507 printf("ERROR: PCIe resistance calibration failed --"
508 "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2));
509
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200510 return -1;
511 }
512 /* De-assert reset of PCIe PLL, wait for lock */
513 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700514 udelay(300); /* 300 uS is maximum time lock should take */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200515
Stefan Roese074e9752006-08-29 08:05:15 +0200516 while (time_out) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200517 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
518 time_out--;
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700519 udelay(20); /* Wait 20 uS more if needed */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200520 } else
521 break;
522 }
523 if (!time_out) {
Rupjyoti Sarmah73343ca2009-09-21 11:26:19 -0700524 printf("ERROR: PCIe PLL VCO output not locked to ref clock --"
525 "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3));
526
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200527 return -1;
528 }
Stefan Roesebdd13d12008-03-11 15:05:26 +0100529 return 0;
530}
531#endif
532
533#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
534static void ppc4xx_setup_utl(u32 port)
535{
536 volatile void *utl_base = NULL;
537
538 /*
539 * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
540 */
541 switch (port) {
542 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200543 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
544 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE));
Stefan Roesebdd13d12008-03-11 15:05:26 +0100545 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
546 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
547 break;
548
549 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200550 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
551 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)
Stefan Roesebdd13d12008-03-11 15:05:26 +0100552 + 0x1000);
553 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
554 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
555 break;
556 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200557 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100558
559 /*
560 * Set buffer allocations and then assert VRB and TXE.
561 */
562 out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
563 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
564 out_be32(utl_base + PEUTL_INTR, 0x02000000);
565 out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
566 out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
567 out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
568 out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
569 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
570 out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
571}
572
573/*
574 * TODO: double check PCI express SDR based on the latest user manual
Wolfgang Denka1be4762008-05-20 16:00:29 +0200575 * Some registers specified here no longer exist.. has to be
576 * updated based on the final EAS spec.
Stefan Roesebdd13d12008-03-11 15:05:26 +0100577 */
578static int check_error(void)
579{
580 u32 valPE0, valPE1;
581 int err = 0;
582
583 valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
584 valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
585
586 /* SDR0_PExRCSSET rstgu */
587 if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
588 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
589 err = -1;
590 }
591
592 /* SDR0_PExRCSSET rstdl */
593 if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
594 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
595 err = -1;
596 }
597
598 /* SDR0_PExRCSSET rstpyn */
599 if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
600 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
601 err = -1;
602 }
603
604 /* SDR0_PExRCSSET hldplb */
605 if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
606 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
607 err = -1;
608 }
609
610 /* SDR0_PExRCSSET rdy */
611 if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
612 printf("PCIE: SDR0_PExRCSSET rdy error\n");
613 err = -1;
614 }
615
616 return err;
617}
618
619/*
620 * Initialize PCI Express core as described in User Manual
621 * TODO: double check PE SDR PLL Register with the updated user manual.
622 */
623int ppc4xx_init_pcie(void)
624{
625 if (check_error())
626 return -1;
627
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200628 return 0;
629}
Stefan Roesebdd13d12008-03-11 15:05:26 +0100630#endif /* CONFIG_460EX */
631
632#if defined(CONFIG_405EX)
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100633static void ppc4xx_setup_utl(u32 port)
634{
635 u32 utl_base;
636
637 /*
638 * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
639 */
640 switch (port) {
641 case 0:
642 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200643 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE);
Stefan Roese95805952007-11-18 14:44:44 +0100644 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100645 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
646 break;
647
648 case 1:
649 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200650 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE);
Stefan Roese95805952007-11-18 14:44:44 +0100651 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100652 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
653
654 break;
655 }
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200656 utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE;
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100657
658 /*
659 * Set buffer allocations and then assert VRB and TXE.
660 */
661 out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
662 out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
663 out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
664 out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
665 out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
666 out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
667 out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
668 out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
669
670 out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
671 out_be32((u32 *)(utl_base + PEUTL_RCSTA),
672 in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
673}
674
Stefan Roese7a41bde2007-10-05 09:18:23 +0200675int ppc4xx_init_pcie(void)
676{
677 /*
678 * Nothing to do on 405EX
679 */
680 return 0;
681}
Stefan Roesebdd13d12008-03-11 15:05:26 +0100682#endif /* CONFIG_405EX */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200683
Stefan Roese074e9752006-08-29 08:05:15 +0200684/*
Stefan Roesea0d96342007-10-03 10:38:09 +0200685 * Board-specific pcie initialization
686 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
687 */
688
689/*
690 * Initialize various parts of the PCI Express core for our port:
691 *
692 * - Set as a root port and enable max width
693 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
694 * - Set up UTL configuration.
695 * - Increase SERDES drive strength to levels suggested by AMCC.
696 * - De-assert RSTPYN, RSTDL and RSTGU.
697 *
698 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
699 * with default setting 0x11310000. The register has new fields,
700 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
701 * hang.
702 */
703#if defined(CONFIG_440SPE)
704int __ppc4xx_init_pcie_port_hw(int port, int rootport)
705{
706 u32 val = 1 << 24;
707 u32 utlset1;
708
709 if (rootport) {
710 val = PTYPE_ROOT_PORT << 20;
711 utlset1 = 0x21222222;
712 } else {
713 val = PTYPE_LEGACY_ENDPOINT << 20;
714 utlset1 = 0x20222222;
715 }
716
717 if (port == 0)
718 val |= LNKW_X8 << 12;
719 else
720 val |= LNKW_X4 << 12;
721
722 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
723 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
724 if (!ppc440spe_revB())
725 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
726 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
727 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
728 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
729 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
730 if (port == 0) {
731 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
732 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
733 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
734 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
735 }
736 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
737 ~(1 << 24 | 1 << 16)) | 1 << 12);
738
739 return 0;
740}
741#endif /* CONFIG_440SPE */
742
Stefan Roesebdd13d12008-03-11 15:05:26 +0100743#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
744int __ppc4xx_init_pcie_port_hw(int port, int rootport)
745{
Stefan Roese142b1d42008-07-01 17:03:19 +0200746 u32 val;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100747 u32 utlset1;
748
Stefan Roese142b1d42008-07-01 17:03:19 +0200749 if (rootport)
Stefan Roesebdd13d12008-03-11 15:05:26 +0100750 val = PTYPE_ROOT_PORT << 20;
Stefan Roese142b1d42008-07-01 17:03:19 +0200751 else
Stefan Roesebdd13d12008-03-11 15:05:26 +0100752 val = PTYPE_LEGACY_ENDPOINT << 20;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100753
754 if (port == 0) {
755 val |= LNKW_X1 << 12;
Stefan Roese142b1d42008-07-01 17:03:19 +0200756 utlset1 = 0x20000000;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100757 } else {
758 val |= LNKW_X4 << 12;
Stefan Roese142b1d42008-07-01 17:03:19 +0200759 utlset1 = 0x20101101;
Stefan Roesebdd13d12008-03-11 15:05:26 +0100760 }
761
762 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
763 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
764 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
765
766 switch (port) {
767 case 0:
768 SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
Tirumala R Marri75e22a42008-08-21 21:54:53 -0700769 SDR_WRITE(PESDR0_L0DRV, 0x00000130);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100770 SDR_WRITE(PESDR0_L0CLK, 0x00000006);
771
772 SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
773 break;
774
775 case 1:
776 SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
777 SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
778 SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
779 SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
Tirumala R Marri75e22a42008-08-21 21:54:53 -0700780 SDR_WRITE(PESDR1_L0DRV, 0x00000130);
781 SDR_WRITE(PESDR1_L1DRV, 0x00000130);
782 SDR_WRITE(PESDR1_L2DRV, 0x00000130);
783 SDR_WRITE(PESDR1_L3DRV, 0x00000130);
Stefan Roesebdd13d12008-03-11 15:05:26 +0100784 SDR_WRITE(PESDR1_L0CLK, 0x00000006);
785 SDR_WRITE(PESDR1_L1CLK, 0x00000006);
786 SDR_WRITE(PESDR1_L2CLK, 0x00000006);
787 SDR_WRITE(PESDR1_L3CLK, 0x00000006);
788
789 SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
790 break;
791 }
792
793 SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
794 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
795
796 /* Poll for PHY reset */
797 switch (port) {
798 case 0:
799 while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
800 udelay(10);
801 break;
802 case 1:
803 while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
804 udelay(10);
805 break;
806 }
807
808 SDR_WRITE(SDRN_PESDR_RCSSET(port),
809 (SDR_READ(SDRN_PESDR_RCSSET(port)) &
810 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
811 PESDRx_RCSSET_RSTPYN);
812
813 return 0;
814}
815#endif /* CONFIG_440SPE */
816
Stefan Roesea0d96342007-10-03 10:38:09 +0200817#if defined(CONFIG_405EX)
818int __ppc4xx_init_pcie_port_hw(int port, int rootport)
819{
820 u32 val;
821
822 if (rootport)
823 val = 0x00401000;
824 else
825 val = 0x00101000;
826
827 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
Stefan Roese4aabdc82007-11-13 08:06:11 +0100828 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
829 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
Stefan Roesea0d96342007-10-03 10:38:09 +0200830 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
831 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
832
833 /* Assert the PE0_PHY reset */
834 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
835 udelay(1000);
836
837 /* deassert the PE0_hotreset */
Stefan Roesee7fe4c52007-10-18 07:39:38 +0200838 if (is_end_point(port))
839 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
840 else
841 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
Stefan Roesea0d96342007-10-03 10:38:09 +0200842
843 /* poll for phy !reset */
844 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
845 ;
846
847 /* deassert the PE0_gpl_utl_reset */
848 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
849
850 if (port == 0)
851 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
852 else
853 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
854
855 return 0;
856}
857#endif /* CONFIG_405EX */
858
859int ppc4xx_init_pcie_port_hw(int port, int rootport)
Stefan Roese95805952007-11-18 14:44:44 +0100860__attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
Stefan Roesea0d96342007-10-03 10:38:09 +0200861
862/*
863 * We map PCI Express configuration access into the 512MB regions
864 *
865 * NOTICE: revB is very strict about PLB real addressess and ranges to
866 * be mapped for config space; it seems to only work with d_nnnn_nnnn
867 * range (hangs the core upon config transaction attempts when set
868 * otherwise) while revA uses c_nnnn_nnnn.
869 *
Stefan Roesebdd13d12008-03-11 15:05:26 +0100870 * For 440SPe revA:
Stefan Roesea0d96342007-10-03 10:38:09 +0200871 * PCIE0: 0xc_4000_0000
872 * PCIE1: 0xc_8000_0000
873 * PCIE2: 0xc_c000_0000
874 *
Stefan Roesebdd13d12008-03-11 15:05:26 +0100875 * For 440SPe revB:
Stefan Roesea0d96342007-10-03 10:38:09 +0200876 * PCIE0: 0xd_0000_0000
877 * PCIE1: 0xd_2000_0000
878 * PCIE2: 0xd_4000_0000
879 *
880 * For 405EX:
881 * PCIE0: 0xa000_0000
882 * PCIE1: 0xc000_0000
Stefan Roesebdd13d12008-03-11 15:05:26 +0100883 *
884 * For 460EX/GT:
885 * PCIE0: 0xd_0000_0000
886 * PCIE1: 0xd_2000_0000
Stefan Roesea0d96342007-10-03 10:38:09 +0200887 */
888static inline u64 ppc4xx_get_cfgaddr(int port)
889{
890#if defined(CONFIG_405EX)
891 if (port == 0)
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200892 return (u64)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roesea0d96342007-10-03 10:38:09 +0200893 else
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200894 return (u64)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roesea0d96342007-10-03 10:38:09 +0200895#endif
896#if defined(CONFIG_440SPE)
897 if (ppc440spe_revB()) {
898 switch (port) {
899 default: /* to satisfy compiler */
900 case 0:
901 return 0x0000000d00000000ULL;
902 case 1:
903 return 0x0000000d20000000ULL;
904 case 2:
905 return 0x0000000d40000000ULL;
906 }
907 } else {
908 switch (port) {
909 default: /* to satisfy compiler */
910 case 0:
911 return 0x0000000c40000000ULL;
912 case 1:
913 return 0x0000000c80000000ULL;
914 case 2:
915 return 0x0000000cc0000000ULL;
916 }
917 }
918#endif
Stefan Roesebdd13d12008-03-11 15:05:26 +0100919#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
920 if (port == 0)
921 return 0x0000000d00000000ULL;
922 else
923 return 0x0000000d20000000ULL;
924#endif
Stefan Roesea0d96342007-10-03 10:38:09 +0200925}
926
927/*
Peter Tyser62825a52010-01-17 15:38:26 -0600928 * 4xx boards as endpoint and root point setup
Stefan Roese074e9752006-08-29 08:05:15 +0200929 * and
930 * testing inbound and out bound windows
931 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200932 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
Stefan Roese074e9752006-08-29 08:05:15 +0200933 * cable which can be used to setup loop back from one port to another port.
934 * Please rememeber that unless there is a endpoint plugged in to root port it
935 * will not initialize. It is the same in case of endpoint , unless there is
936 * root port attached it will not initialize.
937 *
938 * In this release of software all the PCI-E ports are configured as either
939 * endpoint or rootpoint.In future we will have support for selective ports
940 * setup as endpoint and root point in single board.
941 *
942 * Once your board came up as root point , you can verify by reading
943 * /proc/bus/pci/devices. Where you can see the configuration registers
Peter Tyser62825a52010-01-17 15:38:26 -0600944 * of endpoint device attached to the port.
Stefan Roese074e9752006-08-29 08:05:15 +0200945 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200946 * Enpoint cofiguration can be verified by connecting 4xx board to any
947 * host or another 4xx board. Then try to scan the device. In case of
Stefan Roese074e9752006-08-29 08:05:15 +0200948 * linux use "lspci" or appripriate os command.
949 *
Stefan Roesea0d96342007-10-03 10:38:09 +0200950 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
Stefan Roese074e9752006-08-29 08:05:15 +0200951 * in this configuration inbound and outbound windows are setup to access
952 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
953 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
954 * This is waere your POM(PLB out bound memory window) mapped. then
Stefan Roesea0d96342007-10-03 10:38:09 +0200955 * read the data from other 4xx board's u-boot prompt at address
Stefan Roese074e9752006-08-29 08:05:15 +0200956 * 0x9000 0000(SRAM). Data should match.
957 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
958 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
959 * data at 0x9000 0000(SRAM).Data should match.
960 */
Stefan Roesea0d96342007-10-03 10:38:09 +0200961int ppc4xx_init_pcie_port(int port, int rootport)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200962{
963 static int core_init;
964 volatile u32 val = 0;
965 int attempts;
Stefan Roesea0d96342007-10-03 10:38:09 +0200966 u64 addr;
967 u32 low, high;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200968
969 if (!core_init) {
Stefan Roese9c00e512007-10-03 07:48:09 +0200970 if (ppc4xx_init_pcie())
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200971 return -1;
Stefan Roese89bac402007-10-13 16:43:23 +0200972 ++core_init;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200973 }
974
975 /*
Stefan Roesea0d96342007-10-03 10:38:09 +0200976 * Initialize various parts of the PCI Express core for our port
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200977 */
Stefan Roesea0d96342007-10-03 10:38:09 +0200978 ppc4xx_init_pcie_port_hw(port, rootport);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200979
Stefan Roese074e9752006-08-29 08:05:15 +0200980 /*
981 * Notice: the following delay has critical impact on device
982 * initialization - if too short (<50ms) the link doesn't get up.
983 */
984 mdelay(100);
985
Stefan Roesebe6fea92007-10-03 21:16:32 +0200986 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
Stefan Roese074e9752006-08-29 08:05:15 +0200987 if (val & (1 << 20)) {
988 printf("PCIE%d: PGRST failed %08x\n", port, val);
989 return -1;
990 }
991
992 /*
993 * Verify link is up
994 */
Stefan Roesebe6fea92007-10-03 21:16:32 +0200995 val = SDR_READ(SDRN_PESDR_LOOP(port));
Stefan Roese074e9752006-08-29 08:05:15 +0200996 if (!(val & 0x00001000)) {
997 printf("PCIE%d: link is not up.\n", port);
Stefan Roese14fd12f2009-10-02 14:35:16 +0200998 return -ENODEV;
Stefan Roese074e9752006-08-29 08:05:15 +0200999 }
1000
1001 /*
1002 * Setup UTL registers - but only on revA!
1003 * We use default settings for revB chip.
1004 */
1005 if (!ppc440spe_revB())
Stefan Roese9c00e512007-10-03 07:48:09 +02001006 ppc4xx_setup_utl(port);
Stefan Roese074e9752006-08-29 08:05:15 +02001007
1008 /*
1009 * We map PCI Express configuration access into the 512MB regions
Stefan Roese074e9752006-08-29 08:05:15 +02001010 */
Stefan Roesea0d96342007-10-03 10:38:09 +02001011 addr = ppc4xx_get_cfgaddr(port);
Stefan Roese7a41bde2007-10-05 09:18:23 +02001012 low = U64_TO_U32_LOW(addr);
1013 high = U64_TO_U32_HIGH(addr);
Stefan Roese074e9752006-08-29 08:05:15 +02001014
1015 switch (port) {
1016 case 0:
Stefan Roesea0d96342007-10-03 10:38:09 +02001017 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
1018 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001019 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
1020 break;
Stefan Roese074e9752006-08-29 08:05:15 +02001021 case 1:
Stefan Roesea0d96342007-10-03 10:38:09 +02001022 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
1023 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001024 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
1025 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001026#if CONFIG_SYS_PCIE_NR_PORTS > 2
Stefan Roese074e9752006-08-29 08:05:15 +02001027 case 2:
Stefan Roesea0d96342007-10-03 10:38:09 +02001028 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
1029 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
Stefan Roese074e9752006-08-29 08:05:15 +02001030 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
1031 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001032#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001033 }
1034
1035 /*
1036 * Check for VC0 active and assert RDY.
1037 */
1038 attempts = 10;
Stefan Roesebe6fea92007-10-03 21:16:32 +02001039 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
Stefan Roesea0d96342007-10-03 10:38:09 +02001040 if (!(attempts--)) {
1041 printf("PCIE%d: VC0 not active\n", port);
1042 return -1;
Stefan Roese074e9752006-08-29 08:05:15 +02001043 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001044 mdelay(1000);
Stefan Roese074e9752006-08-29 08:05:15 +02001045 }
Stefan Roesebe6fea92007-10-03 21:16:32 +02001046 SDR_WRITE(SDRN_PESDR_RCSSET(port),
1047 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
Stefan Roese074e9752006-08-29 08:05:15 +02001048 mdelay(100);
1049
1050 return 0;
1051}
1052
Stefan Roesea0d96342007-10-03 10:38:09 +02001053int ppc4xx_init_pcie_rootport(int port)
Stefan Roese074e9752006-08-29 08:05:15 +02001054{
Stefan Roesea0d96342007-10-03 10:38:09 +02001055 return ppc4xx_init_pcie_port(port, 1);
1056}
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001057
Stefan Roesea0d96342007-10-03 10:38:09 +02001058int ppc4xx_init_pcie_endport(int port)
1059{
1060 return ppc4xx_init_pcie_port(port, 0);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001061}
1062
Stefan Roese9c00e512007-10-03 07:48:09 +02001063void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001064{
1065 volatile void *mbase = NULL;
Stefan Roese074e9752006-08-29 08:05:15 +02001066 volatile void *rmbase = NULL;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001067
1068 pci_set_ops(hose,
Stefan Roesea0d96342007-10-03 10:38:09 +02001069 pcie_read_config_byte,
1070 pcie_read_config_word,
1071 pcie_read_config_dword,
1072 pcie_write_config_byte,
1073 pcie_write_config_word,
1074 pcie_write_config_dword);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001075
Stefan Roese074e9752006-08-29 08:05:15 +02001076 switch (port) {
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001077 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001078 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1079 rmbase = (u32 *)CONFIG_SYS_PCIE0_CFGBASE;
1080 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001081 break;
1082 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001083 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1084 rmbase = (u32 *)CONFIG_SYS_PCIE1_CFGBASE;
1085 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001086 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001087#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001088 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001089 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1090 rmbase = (u32 *)CONFIG_SYS_PCIE2_CFGBASE;
1091 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001092 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001093#endif
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001094 }
1095
1096 /*
1097 * Set bus numbers on our root port
1098 */
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001099 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
1100 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
1101 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001102
1103 /*
1104 * Set up outbound translation to hose->mem_space from PLB
1105 * addresses at an offset of 0xd_0000_0000. We set the low
1106 * bits of the mask to 11 to turn off splitting into 8
1107 * subregions and to enable the outbound translation.
1108 */
1109 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001110 out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE +
1111 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese3dced492007-10-05 07:57:20 +02001112 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
1113 in_le32(mbase + PECFG_POM0LAL));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001114
1115 switch (port) {
1116 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001117 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1118 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1119 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001120 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1121 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001122 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001123 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1124 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
1125 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
1126 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
1127 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001128 break;
1129 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001130 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1131 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1132 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001133 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1134 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001135 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001136 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1137 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
1138 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
1139 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
1140 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001141 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001142#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001143 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001144 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1145 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1146 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001147 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1148 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001149 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese3dced492007-10-05 07:57:20 +02001150 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1151 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
1152 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
1153 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
1154 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001155 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001156#endif
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001157 }
1158
Stefan Roesee2ea0802009-02-18 13:18:00 +01001159 /* Set up 4GB inbound memory window at 0 */
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001160 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1161 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roesee2ea0802009-02-18 13:18:00 +01001162 out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001163 out_le32(mbase + PECFG_BAR0LMPA, 0);
Stefan Roese074e9752006-08-29 08:05:15 +02001164
1165 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1166 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001167 out_le32(mbase + PECFG_PIM0LAL, 0);
1168 out_le32(mbase + PECFG_PIM0LAH, 0);
Stefan Roese7a41bde2007-10-05 09:18:23 +02001169 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1170 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
Stefan Roese074e9752006-08-29 08:05:15 +02001171 out_le32(mbase + PECFG_PIMEN, 0x1);
1172
1173 /* Enable I/O, Mem, and Busmaster cycles */
1174 out_le16((u16 *)(mbase + PCI_COMMAND),
1175 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1176 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese43867c82007-10-02 11:44:46 +02001177
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001178 /* Set Device and Vendor Id */
Stefan Roese7a41bde2007-10-05 09:18:23 +02001179 out_le16(mbase + 0x200, 0xaaa0 + port);
1180 out_le16(mbase + 0x202, 0xbed0 + port);
Grzegorz Bernackid2f21332007-09-07 18:20:23 +02001181
1182 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1183 out_le32(mbase + 0x208, 0x06040001);
1184
Stefan Roese4e456622007-10-05 14:23:43 +02001185 printf("PCIE%d: successfully set as root-complex\n", port);
Stefan Roese074e9752006-08-29 08:05:15 +02001186}
1187
Stefan Roese9c00e512007-10-03 07:48:09 +02001188int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
Stefan Roese074e9752006-08-29 08:05:15 +02001189{
1190 volatile void *mbase = NULL;
1191 int attempts = 0;
1192
1193 pci_set_ops(hose,
1194 pcie_read_config_byte,
1195 pcie_read_config_word,
1196 pcie_read_config_dword,
1197 pcie_write_config_byte,
1198 pcie_write_config_word,
1199 pcie_write_config_dword);
1200
1201 switch (port) {
1202 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001203 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1204 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001205 break;
1206 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001207 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1208 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001209 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001210#if defined(CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roese074e9752006-08-29 08:05:15 +02001211 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001212 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1213 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Stefan Roese074e9752006-08-29 08:05:15 +02001214 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001215#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001216 }
1217
1218 /*
1219 * Set up outbound translation to hose->mem_space from PLB
1220 * addresses at an offset of 0xd_0000_0000. We set the low
1221 * bits of the mask to 11 to turn off splitting into 8
1222 * subregions and to enable the outbound translation.
1223 */
1224 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
1225 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
1226
1227 switch (port) {
1228 case 0:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001229 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1230 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1231 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001232 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1233 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001234 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001235 break;
1236 case 1:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001237 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1238 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1239 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001240 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1241 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001242 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001243 break;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001244#if CONFIG_SYS_PCIE_NR_PORTS > 2
Stefan Roese074e9752006-08-29 08:05:15 +02001245 case 2:
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001246 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1247 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1248 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese074e9752006-08-29 08:05:15 +02001249 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1250 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001251 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese074e9752006-08-29 08:05:15 +02001252 break;
Stefan Roese7a41bde2007-10-05 09:18:23 +02001253#endif
Stefan Roese074e9752006-08-29 08:05:15 +02001254 }
1255
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001256 /* Set up 64MB inbound memory window at 0 */
Stefan Roese074e9752006-08-29 08:05:15 +02001257 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1258 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001259
1260 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
1261 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
1262
1263 /* Setup BAR0 */
1264 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
1265 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
1266
1267 /* Disable BAR1 & BAR2 */
1268 out_le32(mbase + PECFG_BAR1MPA, 0);
1269 out_le32(mbase + PECFG_BAR2HMPA, 0);
1270 out_le32(mbase + PECFG_BAR2LMPA, 0);
1271
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001272 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE));
1273 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE));
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001274 out_le32(mbase + PECFG_PIMEN, 0x1);
1275
1276 /* Enable I/O, Mem, and Busmaster cycles */
1277 out_le16((u16 *)(mbase + PCI_COMMAND),
Stefan Roesea0d96342007-10-03 10:38:09 +02001278 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1279 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese7a41bde2007-10-05 09:18:23 +02001280 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
1281 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
Stefan Roesea0d96342007-10-03 10:38:09 +02001282
Stefan Roesee7fe4c52007-10-18 07:39:38 +02001283 /* Set Class Code to Processor/PPC */
1284 out_le32(mbase + 0x208, 0x0b200001);
1285
Stefan Roese074e9752006-08-29 08:05:15 +02001286 attempts = 10;
Stefan Roesebe6fea92007-10-03 21:16:32 +02001287 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
Stefan Roesea0d96342007-10-03 10:38:09 +02001288 if (!(attempts--)) {
1289 printf("PCIE%d: BME not active\n", port);
1290 return -1;
Stefan Roese074e9752006-08-29 08:05:15 +02001291 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001292 mdelay(1000);
Stefan Roese074e9752006-08-29 08:05:15 +02001293 }
Stefan Roesea0d96342007-10-03 10:38:09 +02001294
Stefan Roese4e456622007-10-05 14:23:43 +02001295 printf("PCIE%d: successfully set as endpoint\n", port);
Stefan Roese074e9752006-08-29 08:05:15 +02001296
1297 return 0;
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001298}
Stefan Roese8d982302007-01-18 10:25:34 +01001299#endif /* CONFIG_440SPE && CONFIG_PCI */