blob: 19d2c7dd2f46affa43e2f64c98bf30a5c62b85d7 [file] [log] [blame]
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001/*
Stefan Roese8ac41e32008-03-11 15:05:26 +01002 * (C) Copyright 2006 - 2008
Rafal Jaworowski692519b2006-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 Roese4dbee8a2007-10-05 07:57:20 +020023/* define DEBUG for debugging output (obviously ;-)) */
Stefan Roeseff68f662007-10-05 09:22:33 +020024#if 0
Stefan Roese4dbee8a2007-10-05 07:57:20 +020025#define DEBUG
26#endif
27
Rafal Jaworowski692519b2006-08-10 12:43:17 +020028#include <common.h>
29#include <pci.h>
Stefan Roeseb578fb42008-07-10 11:38:26 +020030#include <ppc4xx.h>
31#include <asm/processor.h>
32#include <asm-ppc/io.h>
Stefan Roese06dfaee2009-10-02 14:35:16 +020033#include <asm/errno.h>
Rafal Jaworowski692519b2006-08-10 12:43:17 +020034
Stefan Roese8ac41e32008-03-11 15:05:26 +010035#if (defined(CONFIG_440SPE) || defined(CONFIG_405EX) || \
36 defined(CONFIG_460EX) || defined(CONFIG_460GT)) && \
Dirk Eibach59d1bda2009-02-03 15:15:21 +010037 defined(CONFIG_PCI) && !defined(CONFIG_PCI_DISABLE_PCIE)
Rafal Jaworowski692519b2006-08-10 12:43:17 +020038
Stefan Roesec7c6da22007-10-03 07:34:10 +020039#include <asm/4xx_pcie.h>
Rafal Jaworowski692519b2006-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 Roesed4cb2d12007-10-13 16:43:23 +020051static int validate_endpoint(struct pci_controller *hose)
52{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE0_CFGBASE)
Stefan Roesed4cb2d12007-10-13 16:43:23 +020054 return (is_end_point(0));
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE1_CFGBASE)
Stefan Roesed4cb2d12007-10-13 16:43:23 +020056 return (is_end_point(1));
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057#if CONFIG_SYS_PCIE_NR_PORTS > 2
58 else if (hose->cfg_data == (u8 *)CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roesed4cb2d12007-10-13 16:43:23 +020059 return (is_end_point(2));
60#endif
61
62 return 0;
63}
64
Grzegorz Bernacki7f191392007-09-07 18:20:23 +020065static u8* pcie_get_base(struct pci_controller *hose, unsigned int devfn)
66{
67 u8 *base = (u8*)hose->cfg_data;
68
69 /* use local configuration space for the first bus */
70 if (PCI_BUS(devfn) == 0) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020071 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE0_CFGBASE)
72 base = (u8*)CONFIG_SYS_PCIE0_XCFGBASE;
73 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE1_CFGBASE)
74 base = (u8*)CONFIG_SYS_PCIE1_XCFGBASE;
75#if CONFIG_SYS_PCIE_NR_PORTS > 2
76 if (hose->cfg_data == (u8*)CONFIG_SYS_PCIE2_CFGBASE)
77 base = (u8*)CONFIG_SYS_PCIE2_XCFGBASE;
Stefan Roese97923772007-10-05 09:18:23 +020078#endif
Grzegorz Bernacki7f191392007-09-07 18:20:23 +020079 }
80
81 return base;
82}
83
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020084static void pcie_dmer_disable(void)
Grzegorz Bernackic9240982007-07-31 18:51:48 +020085{
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020086 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE),
87 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) | GPL_DMER_MASK_DISA);
88 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE),
89 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) | GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020091 mtdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE),
92 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) | GPL_DMER_MASK_DISA);
Stefan Roese97923772007-10-05 09:18:23 +020093#endif
Grzegorz Bernackic9240982007-07-31 18:51:48 +020094}
95
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020096static void pcie_dmer_enable(void)
Grzegorz Bernackic9240982007-07-31 18:51:48 +020097{
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020098 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE0_BASE),
99 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE0_BASE)) & ~GPL_DMER_MASK_DISA);
100 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE1_BASE),
101 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE1_BASE)) & ~GPL_DMER_MASK_DISA);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102#if CONFIG_SYS_PCIE_NR_PORTS > 2
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200103 mtdcr (DCRN_PEGPL_CFG (DCRN_PCIE2_BASE),
104 mfdcr (DCRN_PEGPL_CFG(DCRN_PCIE2_BASE)) & ~GPL_DMER_MASK_DISA);
Stefan Roese97923772007-10-05 09:18:23 +0200105#endif
Grzegorz Bernackic9240982007-07-31 18:51:48 +0200106}
107
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200108static int pcie_read_config(struct pci_controller *hose, unsigned int devfn,
109 int offset, int len, u32 *val) {
110
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200111 u8 *address;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200112 *val = 0;
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200113
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200114 if (validate_endpoint(hose))
115 return 0; /* No upstream config access */
116
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200117 /*
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200118 * Bus numbers are relative to hose->first_busno
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200119 */
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200120 devfn -= PCI_BDF(hose->first_busno, 0, 0);
121
122 /*
123 * NOTICE: configuration space ranges are currenlty mapped only for
124 * the first 16 buses, so such limit must be imposed. In case more
125 * buses are required the TLB settings in board/amcc/<board>/init.S
126 * need to be altered accordingly (one bus takes 1 MB of memory space).
127 */
128 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200129 return 0;
130
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200131 /*
132 * Only single device/single function is supported for the primary and
133 * secondary buses of the 440SPe host bridge.
134 */
135 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
136 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
137 return 0;
Stefan Roese738815c2007-10-02 11:44:46 +0200138
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200139 address = pcie_get_base(hose, devfn);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200140 offset += devfn << 4;
141
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200142 /*
143 * Reading from configuration space of non-existing device can
144 * generate transaction errors. For the read duration we suppress
145 * assertion of machine check exceptions to avoid those.
146 */
147 pcie_dmer_disable ();
148
Stefan Roese97923772007-10-05 09:18:23 +0200149 debug("%s: cfg_data=%08x offset=%08x\n", __func__, hose->cfg_data, offset);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200150 switch (len) {
151 case 1:
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200152 *val = in_8(hose->cfg_data + offset);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200153 break;
154 case 2:
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200155 *val = in_le16((u16 *)(hose->cfg_data + offset));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200156 break;
157 default:
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200158 *val = in_le32((u32*)(hose->cfg_data + offset));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200159 break;
160 }
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200161
162 pcie_dmer_enable ();
163
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200164 return 0;
165}
166
167static int pcie_write_config(struct pci_controller *hose, unsigned int devfn,
168 int offset, int len, u32 val) {
169
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200170 u8 *address;
Stefan Roese738815c2007-10-02 11:44:46 +0200171
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200172 if (validate_endpoint(hose))
173 return 0; /* No upstream config access */
174
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200175 /*
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200176 * Bus numbers are relative to hose->first_busno
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200177 */
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200178 devfn -= PCI_BDF(hose->first_busno, 0, 0);
Stefan Roese738815c2007-10-02 11:44:46 +0200179
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200180 /*
181 * Same constraints as in pcie_read_config().
182 */
183 if (PCI_BUS(devfn) >= 16)
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200184 return 0;
185
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200186 if ((!((PCI_FUNC(devfn) == 0) && (PCI_DEV(devfn) == 0))) &&
187 ((PCI_BUS(devfn) == 0) || (PCI_BUS(devfn) == 1)))
188 return 0;
Stefan Roese738815c2007-10-02 11:44:46 +0200189
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200190 address = pcie_get_base(hose, devfn);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200191 offset += devfn << 4;
192
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200193 /*
194 * Suppress MCK exceptions, similar to pcie_read_config()
195 */
196 pcie_dmer_disable ();
197
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200198 switch (len) {
199 case 1:
200 out_8(hose->cfg_data + offset, val);
201 break;
202 case 2:
203 out_le16((u16 *)(hose->cfg_data + offset), val);
204 break;
205 default:
206 out_le32((u32 *)(hose->cfg_data + offset), val);
207 break;
208 }
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200209
210 pcie_dmer_enable ();
211
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200212 return 0;
213}
214
215int pcie_read_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 *val)
216{
217 u32 v;
218 int rv;
219
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200220 rv = pcie_read_config(hose, dev, offset, 1, &v);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200221 *val = (u8)v;
222 return rv;
223}
224
225int pcie_read_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 *val)
226{
227 u32 v;
228 int rv;
229
230 rv = pcie_read_config(hose, dev, offset, 2, &v);
231 *val = (u16)v;
232 return rv;
233}
234
235int pcie_read_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 *val)
236{
237 u32 v;
238 int rv;
239
240 rv = pcie_read_config(hose, dev, offset, 3, &v);
241 *val = (u32)v;
242 return rv;
243}
244
245int pcie_write_config_byte(struct pci_controller *hose,pci_dev_t dev,int offset,u8 val)
246{
247 return pcie_write_config(hose,(u32)dev,offset,1,val);
248}
249
250int pcie_write_config_word(struct pci_controller *hose,pci_dev_t dev,int offset,u16 val)
251{
252 return pcie_write_config(hose,(u32)dev,offset,2,(u32 )val);
253}
254
255int pcie_write_config_dword(struct pci_controller *hose,pci_dev_t dev,int offset,u32 val)
256{
257 return pcie_write_config(hose,(u32)dev,offset,3,(u32 )val);
258}
259
Stefan Roese97923772007-10-05 09:18:23 +0200260#if defined(CONFIG_440SPE)
Stefan Roese026f7112007-10-03 07:48:09 +0200261static void ppc4xx_setup_utl(u32 port) {
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200262
263 volatile void *utl_base = NULL;
264
265 /*
266 * Map UTL registers
267 */
268 switch (port) {
269 case 0:
Rafal Jaworowski36b904a2006-08-11 12:35:52 +0200270 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x0000000c);
271 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), 0x20000000);
272 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200273 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0x68782800);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200274 break;
275
276 case 1:
Rafal Jaworowski36b904a2006-08-11 12:35:52 +0200277 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x0000000c);
278 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), 0x20001000);
279 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200280 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0x68782800);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200281 break;
282
283 case 2:
Rafal Jaworowski36b904a2006-08-11 12:35:52 +0200284 mtdcr(DCRN_PEGPL_REGBAH(PCIE2), 0x0000000c);
285 mtdcr(DCRN_PEGPL_REGBAL(PCIE2), 0x20002000);
286 mtdcr(DCRN_PEGPL_REGMSK(PCIE2), 0x00007001);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200287 mtdcr(DCRN_PEGPL_SPECIAL(PCIE2), 0x68782800);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200288 break;
289 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200290 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Wolfgang Denk16850912006-08-27 18:10:01 +0200291
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200292 /*
293 * Set buffer allocations and then assert VRB and TXE.
294 */
295 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
296 out_be32(utl_base + PEUTL_INTR, 0x02000000);
297 out_be32(utl_base + PEUTL_OPDBSZ, 0x10000000);
298 out_be32(utl_base + PEUTL_PBBSZ, 0x53000000);
299 out_be32(utl_base + PEUTL_IPHBSZ, 0x08000000);
300 out_be32(utl_base + PEUTL_IPDBSZ, 0x10000000);
301 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
Rafal Jaworowski36b904a2006-08-11 12:35:52 +0200302 out_be32(utl_base + PEUTL_PCTL, 0x80800066);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200303}
304
305static int check_error(void)
306{
307 u32 valPE0, valPE1, valPE2;
308 int err = 0;
309
310 /* SDR0_PEGPLLLCT1 reset */
Stefan Roese8ac41e32008-03-11 15:05:26 +0100311 if (!(valPE0 = SDR_READ(PESDR0_PLLLCT1) & 0x01000000))
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200312 printf("PCIE: SDR0_PEGPLLLCT1 reset error 0x%x\n", valPE0);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200313
314 valPE0 = SDR_READ(PESDR0_RCSSET);
315 valPE1 = SDR_READ(PESDR1_RCSSET);
316 valPE2 = SDR_READ(PESDR2_RCSSET);
317
318 /* SDR0_PExRCSSET rstgu */
319 if (!(valPE0 & 0x01000000) ||
320 !(valPE1 & 0x01000000) ||
321 !(valPE2 & 0x01000000)) {
322 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
323 err = -1;
324 }
325
326 /* SDR0_PExRCSSET rstdl */
327 if (!(valPE0 & 0x00010000) ||
328 !(valPE1 & 0x00010000) ||
329 !(valPE2 & 0x00010000)) {
330 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
331 err = -1;
332 }
333
334 /* SDR0_PExRCSSET rstpyn */
335 if ((valPE0 & 0x00001000) ||
336 (valPE1 & 0x00001000) ||
337 (valPE2 & 0x00001000)) {
338 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
339 err = -1;
340 }
341
342 /* SDR0_PExRCSSET hldplb */
343 if ((valPE0 & 0x10000000) ||
344 (valPE1 & 0x10000000) ||
345 (valPE2 & 0x10000000)) {
346 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
347 err = -1;
348 }
349
350 /* SDR0_PExRCSSET rdy */
351 if ((valPE0 & 0x00100000) ||
352 (valPE1 & 0x00100000) ||
353 (valPE2 & 0x00100000)) {
354 printf("PCIE: SDR0_PExRCSSET rdy error\n");
355 err = -1;
356 }
357
358 /* SDR0_PExRCSSET shutdown */
359 if ((valPE0 & 0x00000100) ||
360 (valPE1 & 0x00000100) ||
361 (valPE2 & 0x00000100)) {
362 printf("PCIE: SDR0_PExRCSSET shutdown error\n");
363 err = -1;
364 }
365 return err;
366}
367
368/*
369 * Initialize PCI Express core
370 */
Stefan Roese026f7112007-10-03 07:48:09 +0200371int ppc4xx_init_pcie(void)
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200372{
373 int time_out = 20;
374
375 /* Set PLL clock receiver to LVPECL */
376 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) | 1 << 28);
377
Rupjyoti Sarmahfcdb36b2009-09-21 11:26:19 -0700378 if (check_error()) {
379 printf("ERROR: failed to set PCIe reference clock receiver --"
380 "PESDR0_PLLLCT1 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT1));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200381
Rupjyoti Sarmahfcdb36b2009-09-21 11:26:19 -0700382 return -1;
383 }
384
385 /* Did resistance calibration work? */
386 if (!(SDR_READ(PESDR0_PLLLCT2) & 0x10000)) {
387 printf("ERROR: PCIe resistance calibration failed --"
388 "PESDR0_PLLLCT2 = 0x%08x\n", SDR_READ(PESDR0_PLLLCT2));
389
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200390 return -1;
391 }
392 /* De-assert reset of PCIe PLL, wait for lock */
393 SDR_WRITE(PESDR0_PLLLCT1, SDR_READ(PESDR0_PLLLCT1) & ~(1 << 24));
Rupjyoti Sarmahfcdb36b2009-09-21 11:26:19 -0700394 udelay(300); /* 300 uS is maximum time lock should take */
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200395
Stefan Roese2b393b02006-08-29 08:05:15 +0200396 while (time_out) {
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200397 if (!(SDR_READ(PESDR0_PLLLCT3) & 0x10000000)) {
398 time_out--;
Rupjyoti Sarmahfcdb36b2009-09-21 11:26:19 -0700399 udelay(20); /* Wait 20 uS more if needed */
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200400 } else
401 break;
402 }
403 if (!time_out) {
Rupjyoti Sarmahfcdb36b2009-09-21 11:26:19 -0700404 printf("ERROR: PCIe PLL VCO output not locked to ref clock --"
405 "PESDR0_PLLLCTS=0x%08x\n", SDR_READ(PESDR0_PLLLCT3));
406
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200407 return -1;
408 }
409 return 0;
410}
Stefan Roese8ac41e32008-03-11 15:05:26 +0100411#endif
412
413#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
414static void ppc4xx_setup_utl(u32 port)
415{
416 volatile void *utl_base = NULL;
417
418 /*
419 * Map UTL registers at 0x0801_n000 (4K 0xfff mask) PEGPLn_REGMSK
420 */
421 switch (port) {
422 case 0:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200423 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
424 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE));
Stefan Roese8ac41e32008-03-11 15:05:26 +0100425 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* BAM 11100000=4KB */
426 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
427 break;
428
429 case 1:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200430 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), U64_TO_U32_HIGH(CONFIG_SYS_PCIE0_UTLBASE));
431 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), U64_TO_U32_LOW(CONFIG_SYS_PCIE0_UTLBASE)
Stefan Roese8ac41e32008-03-11 15:05:26 +0100432 + 0x1000);
433 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* BAM 11100000=4KB */
434 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
435 break;
436 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200437 utl_base = (unsigned int *)(CONFIG_SYS_PCIE_BASE + 0x1000 * port);
Stefan Roese8ac41e32008-03-11 15:05:26 +0100438
439 /*
440 * Set buffer allocations and then assert VRB and TXE.
441 */
442 out_be32(utl_base + PEUTL_PBCTL, 0x0800000c); /* PLBME, CRRE */
443 out_be32(utl_base + PEUTL_OUTTR, 0x08000000);
444 out_be32(utl_base + PEUTL_INTR, 0x02000000);
445 out_be32(utl_base + PEUTL_OPDBSZ, 0x04000000); /* OPD = 512 Bytes */
446 out_be32(utl_base + PEUTL_PBBSZ, 0x00000000); /* Max 512 Bytes */
447 out_be32(utl_base + PEUTL_IPHBSZ, 0x02000000);
448 out_be32(utl_base + PEUTL_IPDBSZ, 0x04000000); /* IPD = 512 Bytes */
449 out_be32(utl_base + PEUTL_RCIRQEN, 0x00f00000);
450 out_be32(utl_base + PEUTL_PCTL, 0x80800066); /* VRB,TXE,timeout=default */
451}
452
453/*
454 * TODO: double check PCI express SDR based on the latest user manual
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200455 * Some registers specified here no longer exist.. has to be
456 * updated based on the final EAS spec.
Stefan Roese8ac41e32008-03-11 15:05:26 +0100457 */
458static int check_error(void)
459{
460 u32 valPE0, valPE1;
461 int err = 0;
462
463 valPE0 = SDR_READ(SDRN_PESDR_RCSSET(0));
464 valPE1 = SDR_READ(SDRN_PESDR_RCSSET(1));
465
466 /* SDR0_PExRCSSET rstgu */
467 if (!(valPE0 & PESDRx_RCSSET_RSTGU) || !(valPE1 & PESDRx_RCSSET_RSTGU)) {
468 printf("PCIE: SDR0_PExRCSSET rstgu error\n");
469 err = -1;
470 }
471
472 /* SDR0_PExRCSSET rstdl */
473 if (!(valPE0 & PESDRx_RCSSET_RSTDL) || !(valPE1 & PESDRx_RCSSET_RSTDL)) {
474 printf("PCIE: SDR0_PExRCSSET rstdl error\n");
475 err = -1;
476 }
477
478 /* SDR0_PExRCSSET rstpyn */
479 if ((valPE0 & PESDRx_RCSSET_RSTPYN) || (valPE1 & PESDRx_RCSSET_RSTPYN)) {
480 printf("PCIE: SDR0_PExRCSSET rstpyn error\n");
481 err = -1;
482 }
483
484 /* SDR0_PExRCSSET hldplb */
485 if ((valPE0 & PESDRx_RCSSET_HLDPLB) || (valPE1 & PESDRx_RCSSET_HLDPLB)) {
486 printf("PCIE: SDR0_PExRCSSET hldplb error\n");
487 err = -1;
488 }
489
490 /* SDR0_PExRCSSET rdy */
491 if ((valPE0 & PESDRx_RCSSET_RDY) || (valPE1 & PESDRx_RCSSET_RDY)) {
492 printf("PCIE: SDR0_PExRCSSET rdy error\n");
493 err = -1;
494 }
495
496 return err;
497}
498
499/*
500 * Initialize PCI Express core as described in User Manual
501 * TODO: double check PE SDR PLL Register with the updated user manual.
502 */
503int ppc4xx_init_pcie(void)
504{
505 if (check_error())
506 return -1;
507
508 return 0;
509}
510#endif /* CONFIG_460EX */
511
512#if defined(CONFIG_405EX)
Stefan Roesef31d38b2007-11-16 14:16:54 +0100513static void ppc4xx_setup_utl(u32 port)
514{
515 u32 utl_base;
516
517 /*
518 * Map UTL registers at 0xef4f_n000 (4K 0xfff mask) PEGPLn_REGMSK
519 */
520 switch (port) {
521 case 0:
522 mtdcr(DCRN_PEGPL_REGBAH(PCIE0), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200523 mtdcr(DCRN_PEGPL_REGBAL(PCIE0), CONFIG_SYS_PCIE0_UTLBASE);
Stefan Roese653811a2007-11-18 14:44:44 +0100524 mtdcr(DCRN_PEGPL_REGMSK(PCIE0), 0x00007001); /* 4k region, valid */
Stefan Roesef31d38b2007-11-16 14:16:54 +0100525 mtdcr(DCRN_PEGPL_SPECIAL(PCIE0), 0);
526 break;
527
528 case 1:
529 mtdcr(DCRN_PEGPL_REGBAH(PCIE1), 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200530 mtdcr(DCRN_PEGPL_REGBAL(PCIE1), CONFIG_SYS_PCIE1_UTLBASE);
Stefan Roese653811a2007-11-18 14:44:44 +0100531 mtdcr(DCRN_PEGPL_REGMSK(PCIE1), 0x00007001); /* 4k region, valid */
Stefan Roesef31d38b2007-11-16 14:16:54 +0100532 mtdcr(DCRN_PEGPL_SPECIAL(PCIE1), 0);
533
534 break;
535 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200536 utl_base = (port==0) ? CONFIG_SYS_PCIE0_UTLBASE : CONFIG_SYS_PCIE1_UTLBASE;
Stefan Roesef31d38b2007-11-16 14:16:54 +0100537
538 /*
539 * Set buffer allocations and then assert VRB and TXE.
540 */
541 out_be32((u32 *)(utl_base + PEUTL_OUTTR), 0x02000000);
542 out_be32((u32 *)(utl_base + PEUTL_INTR), 0x02000000);
543 out_be32((u32 *)(utl_base + PEUTL_OPDBSZ), 0x04000000);
544 out_be32((u32 *)(utl_base + PEUTL_PBBSZ), 0x21000000);
545 out_be32((u32 *)(utl_base + PEUTL_IPHBSZ), 0x02000000);
546 out_be32((u32 *)(utl_base + PEUTL_IPDBSZ), 0x04000000);
547 out_be32((u32 *)(utl_base + PEUTL_RCIRQEN), 0x00f00000);
548 out_be32((u32 *)(utl_base + PEUTL_PCTL), 0x80800066);
549
550 out_be32((u32 *)(utl_base + PEUTL_PBCTL), 0x0800000c);
551 out_be32((u32 *)(utl_base + PEUTL_RCSTA),
552 in_be32((u32 *)(utl_base + PEUTL_RCSTA)) | 0x000040000);
553}
554
Stefan Roese97923772007-10-05 09:18:23 +0200555int ppc4xx_init_pcie(void)
556{
557 /*
558 * Nothing to do on 405EX
559 */
560 return 0;
561}
Stefan Roese8ac41e32008-03-11 15:05:26 +0100562#endif /* CONFIG_405EX */
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200563
Stefan Roese2b393b02006-08-29 08:05:15 +0200564/*
Stefan Roese03d344b2007-10-03 10:38:09 +0200565 * Board-specific pcie initialization
566 * Platform code can reimplement ppc4xx_init_pcie_port_hw() if needed
567 */
568
569/*
570 * Initialize various parts of the PCI Express core for our port:
571 *
572 * - Set as a root port and enable max width
573 * (PXIE0 -> X8, PCIE1 and PCIE2 -> X4).
574 * - Set up UTL configuration.
575 * - Increase SERDES drive strength to levels suggested by AMCC.
576 * - De-assert RSTPYN, RSTDL and RSTGU.
577 *
578 * NOTICE for 440SPE revB chip: PESDRn_UTLSET2 is not set - we leave it
579 * with default setting 0x11310000. The register has new fields,
580 * PESDRn_UTLSET2[LKINE] in particular: clearing it leads to PCIE core
581 * hang.
582 */
583#if defined(CONFIG_440SPE)
584int __ppc4xx_init_pcie_port_hw(int port, int rootport)
585{
586 u32 val = 1 << 24;
587 u32 utlset1;
588
589 if (rootport) {
590 val = PTYPE_ROOT_PORT << 20;
591 utlset1 = 0x21222222;
592 } else {
593 val = PTYPE_LEGACY_ENDPOINT << 20;
594 utlset1 = 0x20222222;
595 }
596
597 if (port == 0)
598 val |= LNKW_X8 << 12;
599 else
600 val |= LNKW_X4 << 12;
601
602 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
603 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
604 if (!ppc440spe_revB())
605 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x11000000);
606 SDR_WRITE(SDRN_PESDR_HSSL0SET1(port), 0x35000000);
607 SDR_WRITE(SDRN_PESDR_HSSL1SET1(port), 0x35000000);
608 SDR_WRITE(SDRN_PESDR_HSSL2SET1(port), 0x35000000);
609 SDR_WRITE(SDRN_PESDR_HSSL3SET1(port), 0x35000000);
610 if (port == 0) {
611 SDR_WRITE(PESDR0_HSSL4SET1, 0x35000000);
612 SDR_WRITE(PESDR0_HSSL5SET1, 0x35000000);
613 SDR_WRITE(PESDR0_HSSL6SET1, 0x35000000);
614 SDR_WRITE(PESDR0_HSSL7SET1, 0x35000000);
615 }
616 SDR_WRITE(SDRN_PESDR_RCSSET(port), (SDR_READ(SDRN_PESDR_RCSSET(port)) &
617 ~(1 << 24 | 1 << 16)) | 1 << 12);
618
619 return 0;
620}
621#endif /* CONFIG_440SPE */
622
Stefan Roese8ac41e32008-03-11 15:05:26 +0100623#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
624int __ppc4xx_init_pcie_port_hw(int port, int rootport)
625{
Stefan Roesedd1c5522008-07-01 17:03:19 +0200626 u32 val;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100627 u32 utlset1;
628
Stefan Roesedd1c5522008-07-01 17:03:19 +0200629 if (rootport)
Stefan Roese8ac41e32008-03-11 15:05:26 +0100630 val = PTYPE_ROOT_PORT << 20;
Stefan Roesedd1c5522008-07-01 17:03:19 +0200631 else
Stefan Roese8ac41e32008-03-11 15:05:26 +0100632 val = PTYPE_LEGACY_ENDPOINT << 20;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100633
634 if (port == 0) {
635 val |= LNKW_X1 << 12;
Stefan Roesedd1c5522008-07-01 17:03:19 +0200636 utlset1 = 0x20000000;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100637 } else {
638 val |= LNKW_X4 << 12;
Stefan Roesedd1c5522008-07-01 17:03:19 +0200639 utlset1 = 0x20101101;
Stefan Roese8ac41e32008-03-11 15:05:26 +0100640 }
641
642 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
643 SDR_WRITE(SDRN_PESDR_UTLSET1(port), utlset1);
644 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01210000);
645
646 switch (port) {
647 case 0:
648 SDR_WRITE(PESDR0_L0CDRCTL, 0x00003230);
Tirumala R Marri5d4b3d22008-08-21 21:54:53 -0700649 SDR_WRITE(PESDR0_L0DRV, 0x00000130);
Stefan Roese8ac41e32008-03-11 15:05:26 +0100650 SDR_WRITE(PESDR0_L0CLK, 0x00000006);
651
652 SDR_WRITE(PESDR0_PHY_CTL_RST,0x10000000);
653 break;
654
655 case 1:
656 SDR_WRITE(PESDR1_L0CDRCTL, 0x00003230);
657 SDR_WRITE(PESDR1_L1CDRCTL, 0x00003230);
658 SDR_WRITE(PESDR1_L2CDRCTL, 0x00003230);
659 SDR_WRITE(PESDR1_L3CDRCTL, 0x00003230);
Tirumala R Marri5d4b3d22008-08-21 21:54:53 -0700660 SDR_WRITE(PESDR1_L0DRV, 0x00000130);
661 SDR_WRITE(PESDR1_L1DRV, 0x00000130);
662 SDR_WRITE(PESDR1_L2DRV, 0x00000130);
663 SDR_WRITE(PESDR1_L3DRV, 0x00000130);
Stefan Roese8ac41e32008-03-11 15:05:26 +0100664 SDR_WRITE(PESDR1_L0CLK, 0x00000006);
665 SDR_WRITE(PESDR1_L1CLK, 0x00000006);
666 SDR_WRITE(PESDR1_L2CLK, 0x00000006);
667 SDR_WRITE(PESDR1_L3CLK, 0x00000006);
668
669 SDR_WRITE(PESDR1_PHY_CTL_RST,0x10000000);
670 break;
671 }
672
673 SDR_WRITE(SDRN_PESDR_RCSSET(port), SDR_READ(SDRN_PESDR_RCSSET(port)) |
674 (PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTPYN));
675
676 /* Poll for PHY reset */
677 switch (port) {
678 case 0:
679 while (!(SDR_READ(PESDR0_RSTSTA) & 0x1))
680 udelay(10);
681 break;
682 case 1:
683 while (!(SDR_READ(PESDR1_RSTSTA) & 0x1))
684 udelay(10);
685 break;
686 }
687
688 SDR_WRITE(SDRN_PESDR_RCSSET(port),
689 (SDR_READ(SDRN_PESDR_RCSSET(port)) &
690 ~(PESDRx_RCSSET_RSTGU | PESDRx_RCSSET_RSTDL)) |
691 PESDRx_RCSSET_RSTPYN);
692
693 return 0;
694}
695#endif /* CONFIG_440SPE */
696
Stefan Roese03d344b2007-10-03 10:38:09 +0200697#if defined(CONFIG_405EX)
698int __ppc4xx_init_pcie_port_hw(int port, int rootport)
699{
700 u32 val;
701
702 if (rootport)
703 val = 0x00401000;
704 else
705 val = 0x00101000;
706
707 SDR_WRITE(SDRN_PESDR_DLPSET(port), val);
Stefan Roese7d0a4062007-11-13 08:06:11 +0100708 SDR_WRITE(SDRN_PESDR_UTLSET1(port), 0x00000000);
709 SDR_WRITE(SDRN_PESDR_UTLSET2(port), 0x01010000);
Stefan Roese03d344b2007-10-03 10:38:09 +0200710 SDR_WRITE(SDRN_PESDR_PHYSET1(port), 0x720F0000);
711 SDR_WRITE(SDRN_PESDR_PHYSET2(port), 0x70600003);
712
713 /* Assert the PE0_PHY reset */
714 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01010000);
715 udelay(1000);
716
717 /* deassert the PE0_hotreset */
Stefan Roese5cb4af42007-10-18 07:39:38 +0200718 if (is_end_point(port))
719 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01111000);
720 else
721 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x01101000);
Stefan Roese03d344b2007-10-03 10:38:09 +0200722
723 /* poll for phy !reset */
724 while (!(SDR_READ(SDRN_PESDR_PHYSTA(port)) & 0x00001000))
725 ;
726
727 /* deassert the PE0_gpl_utl_reset */
728 SDR_WRITE(SDRN_PESDR_RCSSET(port), 0x00101000);
729
730 if (port == 0)
731 mtdcr(DCRN_PEGPL_CFG(PCIE0), 0x10000000); /* guarded on */
732 else
733 mtdcr(DCRN_PEGPL_CFG(PCIE1), 0x10000000); /* guarded on */
734
735 return 0;
736}
737#endif /* CONFIG_405EX */
738
739int ppc4xx_init_pcie_port_hw(int port, int rootport)
Stefan Roese653811a2007-11-18 14:44:44 +0100740__attribute__((weak, alias("__ppc4xx_init_pcie_port_hw")));
Stefan Roese03d344b2007-10-03 10:38:09 +0200741
742/*
743 * We map PCI Express configuration access into the 512MB regions
744 *
745 * NOTICE: revB is very strict about PLB real addressess and ranges to
746 * be mapped for config space; it seems to only work with d_nnnn_nnnn
747 * range (hangs the core upon config transaction attempts when set
748 * otherwise) while revA uses c_nnnn_nnnn.
749 *
Stefan Roese8ac41e32008-03-11 15:05:26 +0100750 * For 440SPe revA:
Stefan Roese03d344b2007-10-03 10:38:09 +0200751 * PCIE0: 0xc_4000_0000
752 * PCIE1: 0xc_8000_0000
753 * PCIE2: 0xc_c000_0000
754 *
Stefan Roese8ac41e32008-03-11 15:05:26 +0100755 * For 440SPe revB:
Stefan Roese03d344b2007-10-03 10:38:09 +0200756 * PCIE0: 0xd_0000_0000
757 * PCIE1: 0xd_2000_0000
758 * PCIE2: 0xd_4000_0000
759 *
760 * For 405EX:
761 * PCIE0: 0xa000_0000
762 * PCIE1: 0xc000_0000
Stefan Roese8ac41e32008-03-11 15:05:26 +0100763 *
764 * For 460EX/GT:
765 * PCIE0: 0xd_0000_0000
766 * PCIE1: 0xd_2000_0000
Stefan Roese03d344b2007-10-03 10:38:09 +0200767 */
768static inline u64 ppc4xx_get_cfgaddr(int port)
769{
770#if defined(CONFIG_405EX)
771 if (port == 0)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200772 return (u64)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roese03d344b2007-10-03 10:38:09 +0200773 else
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200774 return (u64)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roese03d344b2007-10-03 10:38:09 +0200775#endif
776#if defined(CONFIG_440SPE)
777 if (ppc440spe_revB()) {
778 switch (port) {
779 default: /* to satisfy compiler */
780 case 0:
781 return 0x0000000d00000000ULL;
782 case 1:
783 return 0x0000000d20000000ULL;
784 case 2:
785 return 0x0000000d40000000ULL;
786 }
787 } else {
788 switch (port) {
789 default: /* to satisfy compiler */
790 case 0:
791 return 0x0000000c40000000ULL;
792 case 1:
793 return 0x0000000c80000000ULL;
794 case 2:
795 return 0x0000000cc0000000ULL;
796 }
797 }
798#endif
Stefan Roese8ac41e32008-03-11 15:05:26 +0100799#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
800 if (port == 0)
801 return 0x0000000d00000000ULL;
802 else
803 return 0x0000000d20000000ULL;
804#endif
Stefan Roese03d344b2007-10-03 10:38:09 +0200805}
806
807/*
808 * 4xx boards as end point and root point setup
Stefan Roese2b393b02006-08-29 08:05:15 +0200809 * and
810 * testing inbound and out bound windows
811 *
Stefan Roese03d344b2007-10-03 10:38:09 +0200812 * 4xx boards can be plugged into another 4xx boards or you can get PCI-E
Stefan Roese2b393b02006-08-29 08:05:15 +0200813 * cable which can be used to setup loop back from one port to another port.
814 * Please rememeber that unless there is a endpoint plugged in to root port it
815 * will not initialize. It is the same in case of endpoint , unless there is
816 * root port attached it will not initialize.
817 *
818 * In this release of software all the PCI-E ports are configured as either
819 * endpoint or rootpoint.In future we will have support for selective ports
820 * setup as endpoint and root point in single board.
821 *
822 * Once your board came up as root point , you can verify by reading
823 * /proc/bus/pci/devices. Where you can see the configuration registers
824 * of end point device attached to the port.
825 *
Stefan Roese03d344b2007-10-03 10:38:09 +0200826 * Enpoint cofiguration can be verified by connecting 4xx board to any
827 * host or another 4xx board. Then try to scan the device. In case of
Stefan Roese2b393b02006-08-29 08:05:15 +0200828 * linux use "lspci" or appripriate os command.
829 *
Stefan Roese03d344b2007-10-03 10:38:09 +0200830 * How do I verify the inbound and out bound windows ? (4xx to 4xx)
Stefan Roese2b393b02006-08-29 08:05:15 +0200831 * in this configuration inbound and outbound windows are setup to access
832 * sram memroy area. SRAM is at 0x4 0000 0000 , on PLB bus. This address
833 * is mapped at 0x90000000. From u-boot prompt write data 0xb000 0000,
834 * This is waere your POM(PLB out bound memory window) mapped. then
Stefan Roese03d344b2007-10-03 10:38:09 +0200835 * read the data from other 4xx board's u-boot prompt at address
Stefan Roese2b393b02006-08-29 08:05:15 +0200836 * 0x9000 0000(SRAM). Data should match.
837 * In case of inbound , write data to u-boot command prompt at 0xb000 0000
838 * which is mapped to 0x4 0000 0000. Now on rootpoint yucca u-boot prompt check
839 * data at 0x9000 0000(SRAM).Data should match.
840 */
Stefan Roese03d344b2007-10-03 10:38:09 +0200841int ppc4xx_init_pcie_port(int port, int rootport)
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200842{
843 static int core_init;
844 volatile u32 val = 0;
845 int attempts;
Stefan Roese03d344b2007-10-03 10:38:09 +0200846 u64 addr;
847 u32 low, high;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200848
849 if (!core_init) {
Stefan Roese026f7112007-10-03 07:48:09 +0200850 if (ppc4xx_init_pcie())
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200851 return -1;
Stefan Roesed4cb2d12007-10-13 16:43:23 +0200852 ++core_init;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200853 }
854
855 /*
Stefan Roese03d344b2007-10-03 10:38:09 +0200856 * Initialize various parts of the PCI Express core for our port
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200857 */
Stefan Roese03d344b2007-10-03 10:38:09 +0200858 ppc4xx_init_pcie_port_hw(port, rootport);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200859
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200860 /*
861 * Notice: the following delay has critical impact on device
862 * initialization - if too short (<50ms) the link doesn't get up.
863 */
864 mdelay(100);
865
Stefan Roese6d952892007-10-03 21:16:32 +0200866 val = SDR_READ(SDRN_PESDR_RCSSTS(port));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200867 if (val & (1 << 20)) {
868 printf("PCIE%d: PGRST failed %08x\n", port, val);
869 return -1;
870 }
871
872 /*
873 * Verify link is up
874 */
Stefan Roese6d952892007-10-03 21:16:32 +0200875 val = SDR_READ(SDRN_PESDR_LOOP(port));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200876 if (!(val & 0x00001000)) {
877 printf("PCIE%d: link is not up.\n", port);
Stefan Roese06dfaee2009-10-02 14:35:16 +0200878 return -ENODEV;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200879 }
880
881 /*
882 * Setup UTL registers - but only on revA!
883 * We use default settings for revB chip.
884 */
885 if (!ppc440spe_revB())
Stefan Roese026f7112007-10-03 07:48:09 +0200886 ppc4xx_setup_utl(port);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200887
888 /*
889 * We map PCI Express configuration access into the 512MB regions
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200890 */
Stefan Roese03d344b2007-10-03 10:38:09 +0200891 addr = ppc4xx_get_cfgaddr(port);
Stefan Roese97923772007-10-05 09:18:23 +0200892 low = U64_TO_U32_LOW(addr);
893 high = U64_TO_U32_HIGH(addr);
Rafal Jaworowski36b904a2006-08-11 12:35:52 +0200894
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200895 switch (port) {
896 case 0:
Stefan Roese03d344b2007-10-03 10:38:09 +0200897 mtdcr(DCRN_PEGPL_CFGBAH(PCIE0), high);
898 mtdcr(DCRN_PEGPL_CFGBAL(PCIE0), low);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200899 mtdcr(DCRN_PEGPL_CFGMSK(PCIE0), 0xe0000001); /* 512MB region, valid */
900 break;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200901 case 1:
Stefan Roese03d344b2007-10-03 10:38:09 +0200902 mtdcr(DCRN_PEGPL_CFGBAH(PCIE1), high);
903 mtdcr(DCRN_PEGPL_CFGBAL(PCIE1), low);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200904 mtdcr(DCRN_PEGPL_CFGMSK(PCIE1), 0xe0000001); /* 512MB region, valid */
905 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200906#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200907 case 2:
Stefan Roese03d344b2007-10-03 10:38:09 +0200908 mtdcr(DCRN_PEGPL_CFGBAH(PCIE2), high);
909 mtdcr(DCRN_PEGPL_CFGBAL(PCIE2), low);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200910 mtdcr(DCRN_PEGPL_CFGMSK(PCIE2), 0xe0000001); /* 512MB region, valid */
911 break;
Stefan Roese97923772007-10-05 09:18:23 +0200912#endif
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200913 }
914
915 /*
916 * Check for VC0 active and assert RDY.
917 */
918 attempts = 10;
Stefan Roese6d952892007-10-03 21:16:32 +0200919 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 16))) {
Stefan Roese03d344b2007-10-03 10:38:09 +0200920 if (!(attempts--)) {
921 printf("PCIE%d: VC0 not active\n", port);
922 return -1;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200923 }
Stefan Roese03d344b2007-10-03 10:38:09 +0200924 mdelay(1000);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200925 }
Stefan Roese6d952892007-10-03 21:16:32 +0200926 SDR_WRITE(SDRN_PESDR_RCSSET(port),
927 SDR_READ(SDRN_PESDR_RCSSET(port)) | 1 << 20);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200928 mdelay(100);
929
930 return 0;
931}
932
Stefan Roese03d344b2007-10-03 10:38:09 +0200933int ppc4xx_init_pcie_rootport(int port)
934{
935 return ppc4xx_init_pcie_port(port, 1);
936}
937
Stefan Roese026f7112007-10-03 07:48:09 +0200938int ppc4xx_init_pcie_endport(int port)
Stefan Roese2b393b02006-08-29 08:05:15 +0200939{
Stefan Roese03d344b2007-10-03 10:38:09 +0200940 return ppc4xx_init_pcie_port(port, 0);
Stefan Roese2b393b02006-08-29 08:05:15 +0200941}
942
Stefan Roese026f7112007-10-03 07:48:09 +0200943void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port)
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200944{
945 volatile void *mbase = NULL;
Stefan Roese2b393b02006-08-29 08:05:15 +0200946 volatile void *rmbase = NULL;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200947
948 pci_set_ops(hose,
Stefan Roese03d344b2007-10-03 10:38:09 +0200949 pcie_read_config_byte,
950 pcie_read_config_word,
951 pcie_read_config_dword,
952 pcie_write_config_byte,
953 pcie_write_config_word,
954 pcie_write_config_dword);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200955
Stefan Roese2b393b02006-08-29 08:05:15 +0200956 switch (port) {
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200957 case 0:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200958 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
959 rmbase = (u32 *)CONFIG_SYS_PCIE0_CFGBASE;
960 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200961 break;
962 case 1:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200963 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
964 rmbase = (u32 *)CONFIG_SYS_PCIE1_CFGBASE;
965 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200966 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200967#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200968 case 2:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200969 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
970 rmbase = (u32 *)CONFIG_SYS_PCIE2_CFGBASE;
971 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200972 break;
Stefan Roese97923772007-10-05 09:18:23 +0200973#endif
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200974 }
975
976 /*
977 * Set bus numbers on our root port
978 */
Grzegorz Bernacki7f191392007-09-07 18:20:23 +0200979 out_8((u8 *)mbase + PCI_PRIMARY_BUS, 0);
980 out_8((u8 *)mbase + PCI_SECONDARY_BUS, 1);
981 out_8((u8 *)mbase + PCI_SUBORDINATE_BUS, 1);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200982
983 /*
984 * Set up outbound translation to hose->mem_space from PLB
985 * addresses at an offset of 0xd_0000_0000. We set the low
986 * bits of the mask to 11 to turn off splitting into 8
987 * subregions and to enable the outbound translation.
988 */
989 out_le32(mbase + PECFG_POM0LAH, 0x00000000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200990 out_le32(mbase + PECFG_POM0LAL, CONFIG_SYS_PCIE_MEMBASE +
991 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese4dbee8a2007-10-05 07:57:20 +0200992 debug("PECFG_POM0LA=%08x.%08x\n", in_le32(mbase + PECFG_POM0LAH),
993 in_le32(mbase + PECFG_POM0LAL));
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200994
995 switch (port) {
996 case 0:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200997 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
998 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
999 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001000 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1001 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001002 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese4dbee8a2007-10-05 07:57:20 +02001003 debug("0:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1004 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE0)),
1005 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE0)),
1006 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE0)),
1007 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE0)));
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001008 break;
1009 case 1:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001010 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1011 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1012 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001013 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1014 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001015 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese4dbee8a2007-10-05 07:57:20 +02001016 debug("1:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1017 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE1)),
1018 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE1)),
1019 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE1)),
1020 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE1)));
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001021 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001022#if CONFIG_SYS_PCIE_NR_PORTS > 2
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001023 case 2:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001024 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1025 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1026 port * CONFIG_SYS_PCIE_MEMSIZE);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001027 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1028 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001029 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese4dbee8a2007-10-05 07:57:20 +02001030 debug("2:PEGPL_OMR1BA=%08x.%08x MSK=%08x.%08x\n",
1031 mfdcr(DCRN_PEGPL_OMR1BAH(PCIE2)),
1032 mfdcr(DCRN_PEGPL_OMR1BAL(PCIE2)),
1033 mfdcr(DCRN_PEGPL_OMR1MSKH(PCIE2)),
1034 mfdcr(DCRN_PEGPL_OMR1MSKL(PCIE2)));
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001035 break;
Stefan Roese97923772007-10-05 09:18:23 +02001036#endif
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001037 }
1038
Stefan Roeseb4996d62009-02-18 13:18:00 +01001039 /* Set up 4GB inbound memory window at 0 */
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001040 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1041 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roeseb4996d62009-02-18 13:18:00 +01001042 out_le32(mbase + PECFG_BAR0HMPA, 0x7ffffff);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001043 out_le32(mbase + PECFG_BAR0LMPA, 0);
Stefan Roese2b393b02006-08-29 08:05:15 +02001044
1045 out_le32(mbase + PECFG_PIM01SAH, 0xffff0000);
1046 out_le32(mbase + PECFG_PIM01SAL, 0x00000000);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001047 out_le32(mbase + PECFG_PIM0LAL, 0);
1048 out_le32(mbase + PECFG_PIM0LAH, 0);
Stefan Roese97923772007-10-05 09:18:23 +02001049 out_le32(mbase + PECFG_PIM1LAL, 0x00000000);
1050 out_le32(mbase + PECFG_PIM1LAH, 0x00000004);
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001051 out_le32(mbase + PECFG_PIMEN, 0x1);
1052
1053 /* Enable I/O, Mem, and Busmaster cycles */
1054 out_le16((u16 *)(mbase + PCI_COMMAND),
1055 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1056 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese738815c2007-10-02 11:44:46 +02001057
Grzegorz Bernacki7f191392007-09-07 18:20:23 +02001058 /* Set Device and Vendor Id */
Stefan Roese97923772007-10-05 09:18:23 +02001059 out_le16(mbase + 0x200, 0xaaa0 + port);
1060 out_le16(mbase + 0x202, 0xbed0 + port);
Grzegorz Bernacki7f191392007-09-07 18:20:23 +02001061
1062 /* Set Class Code to PCI-PCI bridge and Revision Id to 1 */
1063 out_le32(mbase + 0x208, 0x06040001);
1064
Stefan Roese19e93b12007-10-05 14:23:43 +02001065 printf("PCIE%d: successfully set as root-complex\n", port);
Stefan Roese2b393b02006-08-29 08:05:15 +02001066}
1067
Stefan Roese026f7112007-10-03 07:48:09 +02001068int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port)
Stefan Roese2b393b02006-08-29 08:05:15 +02001069{
1070 volatile void *mbase = NULL;
1071 int attempts = 0;
1072
1073 pci_set_ops(hose,
1074 pcie_read_config_byte,
1075 pcie_read_config_word,
1076 pcie_read_config_dword,
1077 pcie_write_config_byte,
1078 pcie_write_config_word,
1079 pcie_write_config_dword);
1080
1081 switch (port) {
1082 case 0:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001083 mbase = (u32 *)CONFIG_SYS_PCIE0_XCFGBASE;
1084 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE0_CFGBASE;
Stefan Roese2b393b02006-08-29 08:05:15 +02001085 break;
1086 case 1:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001087 mbase = (u32 *)CONFIG_SYS_PCIE1_XCFGBASE;
1088 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE1_CFGBASE;
Stefan Roese2b393b02006-08-29 08:05:15 +02001089 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001090#if defined(CONFIG_SYS_PCIE2_CFGBASE)
Stefan Roese2b393b02006-08-29 08:05:15 +02001091 case 2:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001092 mbase = (u32 *)CONFIG_SYS_PCIE2_XCFGBASE;
1093 hose->cfg_data = (u8 *)CONFIG_SYS_PCIE2_CFGBASE;
Stefan Roese2b393b02006-08-29 08:05:15 +02001094 break;
Stefan Roese97923772007-10-05 09:18:23 +02001095#endif
Stefan Roese2b393b02006-08-29 08:05:15 +02001096 }
1097
1098 /*
1099 * Set up outbound translation to hose->mem_space from PLB
1100 * addresses at an offset of 0xd_0000_0000. We set the low
1101 * bits of the mask to 11 to turn off splitting into 8
1102 * subregions and to enable the outbound translation.
1103 */
1104 out_le32(mbase + PECFG_POM0LAH, 0x00001ff8);
1105 out_le32(mbase + PECFG_POM0LAL, 0x00001000);
1106
1107 switch (port) {
1108 case 0:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001109 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE0), CONFIG_SYS_PCIE_ADDR_HIGH);
1110 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE0), CONFIG_SYS_PCIE_MEMBASE +
1111 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese2b393b02006-08-29 08:05:15 +02001112 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE0), 0x7fffffff);
1113 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE0),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001114 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese2b393b02006-08-29 08:05:15 +02001115 break;
1116 case 1:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001117 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE1), CONFIG_SYS_PCIE_ADDR_HIGH);
1118 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE1), CONFIG_SYS_PCIE_MEMBASE +
1119 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese2b393b02006-08-29 08:05:15 +02001120 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE1), 0x7fffffff);
1121 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE1),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001122 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese2b393b02006-08-29 08:05:15 +02001123 break;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001124#if CONFIG_SYS_PCIE_NR_PORTS > 2
Stefan Roese2b393b02006-08-29 08:05:15 +02001125 case 2:
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001126 mtdcr(DCRN_PEGPL_OMR1BAH(PCIE2), CONFIG_SYS_PCIE_ADDR_HIGH);
1127 mtdcr(DCRN_PEGPL_OMR1BAL(PCIE2), CONFIG_SYS_PCIE_MEMBASE +
1128 port * CONFIG_SYS_PCIE_MEMSIZE);
Stefan Roese2b393b02006-08-29 08:05:15 +02001129 mtdcr(DCRN_PEGPL_OMR1MSKH(PCIE2), 0x7fffffff);
1130 mtdcr(DCRN_PEGPL_OMR1MSKL(PCIE2),
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001131 ~(CONFIG_SYS_PCIE_MEMSIZE - 1) | 3);
Stefan Roese2b393b02006-08-29 08:05:15 +02001132 break;
Stefan Roese97923772007-10-05 09:18:23 +02001133#endif
Stefan Roese2b393b02006-08-29 08:05:15 +02001134 }
1135
Stefan Roese5cb4af42007-10-18 07:39:38 +02001136 /* Set up 64MB inbound memory window at 0 */
Stefan Roese2b393b02006-08-29 08:05:15 +02001137 out_le32(mbase + PCI_BASE_ADDRESS_0, 0);
1138 out_le32(mbase + PCI_BASE_ADDRESS_1, 0);
Stefan Roese5cb4af42007-10-18 07:39:38 +02001139
1140 out_le32(mbase + PECFG_PIM01SAH, 0xffffffff);
1141 out_le32(mbase + PECFG_PIM01SAL, 0xfc000000);
1142
1143 /* Setup BAR0 */
1144 out_le32(mbase + PECFG_BAR0HMPA, 0x7fffffff);
1145 out_le32(mbase + PECFG_BAR0LMPA, 0xfc000000 | PCI_BASE_ADDRESS_MEM_TYPE_64);
1146
1147 /* Disable BAR1 & BAR2 */
1148 out_le32(mbase + PECFG_BAR1MPA, 0);
1149 out_le32(mbase + PECFG_BAR2HMPA, 0);
1150 out_le32(mbase + PECFG_BAR2LMPA, 0);
1151
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001152 out_le32(mbase + PECFG_PIM0LAL, U64_TO_U32_LOW(CONFIG_SYS_PCIE_INBOUND_BASE));
1153 out_le32(mbase + PECFG_PIM0LAH, U64_TO_U32_HIGH(CONFIG_SYS_PCIE_INBOUND_BASE));
Stefan Roese2b393b02006-08-29 08:05:15 +02001154 out_le32(mbase + PECFG_PIMEN, 0x1);
1155
1156 /* Enable I/O, Mem, and Busmaster cycles */
1157 out_le16((u16 *)(mbase + PCI_COMMAND),
Stefan Roese03d344b2007-10-03 10:38:09 +02001158 in_le16((u16 *)(mbase + PCI_COMMAND)) |
1159 PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
Stefan Roese97923772007-10-05 09:18:23 +02001160 out_le16(mbase + 0x200, 0xcaad); /* Setting vendor ID */
1161 out_le16(mbase + 0x202, 0xfeed); /* Setting device ID */
Stefan Roese03d344b2007-10-03 10:38:09 +02001162
Stefan Roese5cb4af42007-10-18 07:39:38 +02001163 /* Set Class Code to Processor/PPC */
1164 out_le32(mbase + 0x208, 0x0b200001);
1165
Stefan Roese2b393b02006-08-29 08:05:15 +02001166 attempts = 10;
Stefan Roese6d952892007-10-03 21:16:32 +02001167 while(!(SDR_READ(SDRN_PESDR_RCSSTS(port)) & (1 << 8))) {
Stefan Roese03d344b2007-10-03 10:38:09 +02001168 if (!(attempts--)) {
1169 printf("PCIE%d: BME not active\n", port);
1170 return -1;
Stefan Roese2b393b02006-08-29 08:05:15 +02001171 }
Stefan Roese03d344b2007-10-03 10:38:09 +02001172 mdelay(1000);
Stefan Roese2b393b02006-08-29 08:05:15 +02001173 }
Stefan Roese03d344b2007-10-03 10:38:09 +02001174
Stefan Roese19e93b12007-10-05 14:23:43 +02001175 printf("PCIE%d: successfully set as endpoint\n", port);
Stefan Roese2b393b02006-08-29 08:05:15 +02001176
1177 return 0;
Rafal Jaworowski692519b2006-08-10 12:43:17 +02001178}
Stefan Roese5fb692c2007-01-18 10:25:34 +01001179#endif /* CONFIG_440SPE && CONFIG_PCI */