blob: d27d2a965ce7da89ef1fa39d9eebb92d830207fd [file] [log] [blame]
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +02001/*
2 * Copyright (c) 2005 Cisco Systems. All rights reserved.
3 * Roland Dreier <rolandd@cisco.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11#include <ppc4xx.h>
Stefan Roese9c00e512007-10-03 07:48:09 +020012#ifndef __4XX_PCIE_H
13#define __4XX_PCIE_H
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020014
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020015#define DCRN_SDR0_CFGADDR 0x00e
16#define DCRN_SDR0_CFGDATA 0x00f
17
Stefan Roesea0d96342007-10-03 10:38:09 +020018#if defined(CONFIG_440SPE)
Stefan Roese7a41bde2007-10-05 09:18:23 +020019#define CFG_PCIE_NR_PORTS 3
20
21#define CFG_PCIE_ADDR_HIGH 0x0000000d
22
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020023#define DCRN_PCIE0_BASE 0x100
24#define DCRN_PCIE1_BASE 0x120
25#define DCRN_PCIE2_BASE 0x140
Stefan Roese7a41bde2007-10-05 09:18:23 +020026
27#define PCIE0_SDR 0x300
28#define PCIE1_SDR 0x340
29#define PCIE2_SDR 0x370
Stefan Roesea0d96342007-10-03 10:38:09 +020030#endif
31
Stefan Roese50c05332008-03-11 15:07:10 +010032#if defined(CONFIG_460EX) || defined(CONFIG_460GT)
33#define CFG_PCIE_NR_PORTS 2
34
35#define CFG_PCIE_ADDR_HIGH 0x0000000d
36
37#define DCRN_PCIE0_BASE 0x100
38#define DCRN_PCIE1_BASE 0x120
39
40#define PCIE0_SDR 0x300
41#define PCIE1_SDR 0x340
42#endif
43
Stefan Roesea0d96342007-10-03 10:38:09 +020044#if defined(CONFIG_405EX)
Stefan Roese7a41bde2007-10-05 09:18:23 +020045#define CFG_PCIE_NR_PORTS 2
46
47#define CFG_PCIE_ADDR_HIGH 0x00000000
48
Stefan Roesea0d96342007-10-03 10:38:09 +020049#define DCRN_PCIE0_BASE 0x040
50#define DCRN_PCIE1_BASE 0x060
Stefan Roese7a41bde2007-10-05 09:18:23 +020051
52#define PCIE0_SDR 0x400
53#define PCIE1_SDR 0x440
Stefan Roesea0d96342007-10-03 10:38:09 +020054#endif
55
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020056#define PCIE0 DCRN_PCIE0_BASE
57#define PCIE1 DCRN_PCIE1_BASE
58#define PCIE2 DCRN_PCIE2_BASE
59
60#define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
61#define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
62#define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
63#define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
64#define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
65#define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
66#define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
67#define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
68#define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
69#define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
70#define DCRN_PEGPL_REGBAH(base) (base + 0x12)
71#define DCRN_PEGPL_REGBAL(base) (base + 0x13)
72#define DCRN_PEGPL_REGMSK(base) (base + 0x14)
73#define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +020074#define DCRN_PEGPL_CFG(base) (base + 0x16)
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +020075
76/*
77 * System DCRs (SDRs)
78 */
79#define PESDR0_PLLLCT1 0x03a0
80#define PESDR0_PLLLCT2 0x03a1
81#define PESDR0_PLLLCT3 0x03a2
82
Stefan Roese50c05332008-03-11 15:07:10 +010083/* common regs, at for all 4xx with PCIe core */
Stefan Roesea0d96342007-10-03 10:38:09 +020084#define SDRN_PESDR_UTLSET1(n) (sdr_base(n) + 0x00)
85#define SDRN_PESDR_UTLSET2(n) (sdr_base(n) + 0x01)
86#define SDRN_PESDR_DLPSET(n) (sdr_base(n) + 0x02)
87#define SDRN_PESDR_LOOP(n) (sdr_base(n) + 0x03)
88#define SDRN_PESDR_RCSSET(n) (sdr_base(n) + 0x04)
89#define SDRN_PESDR_RCSSTS(n) (sdr_base(n) + 0x05)
90
91#if defined(CONFIG_440SPE)
92#define SDRN_PESDR_HSSL0SET1(n) (sdr_base(n) + 0x06)
93#define SDRN_PESDR_HSSL0SET2(n) (sdr_base(n) + 0x07)
94#define SDRN_PESDR_HSSL0STS(n) (sdr_base(n) + 0x08)
95#define SDRN_PESDR_HSSL1SET1(n) (sdr_base(n) + 0x09)
96#define SDRN_PESDR_HSSL1SET2(n) (sdr_base(n) + 0x0a)
97#define SDRN_PESDR_HSSL1STS(n) (sdr_base(n) + 0x0b)
98#define SDRN_PESDR_HSSL2SET1(n) (sdr_base(n) + 0x0c)
99#define SDRN_PESDR_HSSL2SET2(n) (sdr_base(n) + 0x0d)
100#define SDRN_PESDR_HSSL2STS(n) (sdr_base(n) + 0x0e)
101#define SDRN_PESDR_HSSL3SET1(n) (sdr_base(n) + 0x0f)
102#define SDRN_PESDR_HSSL3SET2(n) (sdr_base(n) + 0x10)
103#define SDRN_PESDR_HSSL3STS(n) (sdr_base(n) + 0x11)
104
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200105#define PESDR0_UTLSET1 0x0300
106#define PESDR0_UTLSET2 0x0301
107#define PESDR0_DLPSET 0x0302
108#define PESDR0_LOOP 0x0303
109#define PESDR0_RCSSET 0x0304
110#define PESDR0_RCSSTS 0x0305
111#define PESDR0_HSSL0SET1 0x0306
112#define PESDR0_HSSL0SET2 0x0307
113#define PESDR0_HSSL0STS 0x0308
114#define PESDR0_HSSL1SET1 0x0309
115#define PESDR0_HSSL1SET2 0x030a
116#define PESDR0_HSSL1STS 0x030b
117#define PESDR0_HSSL2SET1 0x030c
118#define PESDR0_HSSL2SET2 0x030d
119#define PESDR0_HSSL2STS 0x030e
120#define PESDR0_HSSL3SET1 0x030f
121#define PESDR0_HSSL3SET2 0x0310
122#define PESDR0_HSSL3STS 0x0311
123#define PESDR0_HSSL4SET1 0x0312
124#define PESDR0_HSSL4SET2 0x0313
125#define PESDR0_HSSL4STS 0x0314
126#define PESDR0_HSSL5SET1 0x0315
127#define PESDR0_HSSL5SET2 0x0316
128#define PESDR0_HSSL5STS 0x0317
129#define PESDR0_HSSL6SET1 0x0318
130#define PESDR0_HSSL6SET2 0x0319
131#define PESDR0_HSSL6STS 0x031a
132#define PESDR0_HSSL7SET1 0x031b
133#define PESDR0_HSSL7SET2 0x031c
134#define PESDR0_HSSL7STS 0x031d
135#define PESDR0_HSSCTLSET 0x031e
136#define PESDR0_LANE_ABCD 0x031f
137#define PESDR0_LANE_EFGH 0x0320
138
139#define PESDR1_UTLSET1 0x0340
140#define PESDR1_UTLSET2 0x0341
141#define PESDR1_DLPSET 0x0342
142#define PESDR1_LOOP 0x0343
143#define PESDR1_RCSSET 0x0344
144#define PESDR1_RCSSTS 0x0345
145#define PESDR1_HSSL0SET1 0x0346
146#define PESDR1_HSSL0SET2 0x0347
147#define PESDR1_HSSL0STS 0x0348
148#define PESDR1_HSSL1SET1 0x0349
149#define PESDR1_HSSL1SET2 0x034a
150#define PESDR1_HSSL1STS 0x034b
151#define PESDR1_HSSL2SET1 0x034c
152#define PESDR1_HSSL2SET2 0x034d
153#define PESDR1_HSSL2STS 0x034e
154#define PESDR1_HSSL3SET1 0x034f
155#define PESDR1_HSSL3SET2 0x0350
156#define PESDR1_HSSL3STS 0x0351
157#define PESDR1_HSSCTLSET 0x0352
158#define PESDR1_LANE_ABCD 0x0353
159
160#define PESDR2_UTLSET1 0x0370
161#define PESDR2_UTLSET2 0x0371
162#define PESDR2_DLPSET 0x0372
163#define PESDR2_LOOP 0x0373
164#define PESDR2_RCSSET 0x0374
165#define PESDR2_RCSSTS 0x0375
166#define PESDR2_HSSL0SET1 0x0376
167#define PESDR2_HSSL0SET2 0x0377
168#define PESDR2_HSSL0STS 0x0378
169#define PESDR2_HSSL1SET1 0x0379
170#define PESDR2_HSSL1SET2 0x037a
171#define PESDR2_HSSL1STS 0x037b
172#define PESDR2_HSSL2SET1 0x037c
173#define PESDR2_HSSL2SET2 0x037d
174#define PESDR2_HSSL2STS 0x037e
175#define PESDR2_HSSL3SET1 0x037f
176#define PESDR2_HSSL3SET2 0x0380
177#define PESDR2_HSSL3STS 0x0381
178#define PESDR2_HSSCTLSET 0x0382
179#define PESDR2_LANE_ABCD 0x0383
180
Stefan Roesea0d96342007-10-03 10:38:09 +0200181#elif defined(CONFIG_405EX)
182
183#define SDRN_PESDR_PHYSET1(n) (sdr_base(n) + 0x06)
184#define SDRN_PESDR_PHYSET2(n) (sdr_base(n) + 0x07)
185#define SDRN_PESDR_BIST(n) (sdr_base(n) + 0x08)
186#define SDRN_PESDR_LPB(n) (sdr_base(n) + 0x0b)
187#define SDRN_PESDR_PHYSTA(n) (sdr_base(n) + 0x0c)
188
189#define PESDR0_UTLSET1 0x0400
190#define PESDR0_UTLSET2 0x0401
191#define PESDR0_DLPSET 0x0402
192#define PESDR0_LOOP 0x0403
193#define PESDR0_RCSSET 0x0404
194#define PESDR0_RCSSTS 0x0405
195#define PESDR0_PHYSET1 0x0406
196#define PESDR0_PHYSET2 0x0407
197#define PESDR0_BIST 0x0408
198#define PESDR0_LPB 0x040B
199#define PESDR0_PHYSTA 0x040C
200
201#define PESDR1_UTLSET1 0x0440
202#define PESDR1_UTLSET2 0x0441
203#define PESDR1_DLPSET 0x0442
204#define PESDR1_LOOP 0x0443
205#define PESDR1_RCSSET 0x0444
206#define PESDR1_RCSSTS 0x0445
207#define PESDR1_PHYSET1 0x0446
208#define PESDR1_PHYSET2 0x0447
209#define PESDR1_BIST 0x0448
210#define PESDR1_LPB 0x044B
211#define PESDR1_PHYSTA 0x044C
212
Stefan Roese50c05332008-03-11 15:07:10 +0100213#elif defined(CONFIG_460EX) || defined(CONFIG_460GT)
214
215#define PESDR0_L0BIST 0x0308 /* PE0 L0 built in self test */
216#define PESDR0_L0BISTSTS 0x0309 /* PE0 L0 built in self test status */
217#define PESDR0_L0CDRCTL 0x030A /* PE0 L0 CDR control */
218#define PESDR0_L0DRV 0x030B /* PE0 L0 drive */
219#define PESDR0_L0REC 0x030C /* PE0 L0 receiver */
220#define PESDR0_L0LPB 0x030D /* PE0 L0 loopback */
221#define PESDR0_L0CLK 0x030E /* PE0 L0 clocking */
222#define PESDR0_PHY_CTL_RST 0x030F /* PE0 PHY control reset */
223#define PESDR0_RSTSTA 0x0310 /* PE0 reset status */
224#define PESDR0_OBS 0x0311 /* PE0 observation register */
225#define PESDR0_L0ERRC 0x0320 /* PE0 L0 error counter */
226
227#define PESDR1_L0BIST 0x0348 /* PE1 L0 built in self test */
228#define PESDR1_L1BIST 0x0349 /* PE1 L1 built in self test */
229#define PESDR1_L2BIST 0x034A /* PE1 L2 built in self test */
230#define PESDR1_L3BIST 0x034B /* PE1 L3 built in self test */
231#define PESDR1_L0BISTSTS 0x034C /* PE1 L0 built in self test status */
232#define PESDR1_L1BISTSTS 0x034D /* PE1 L1 built in self test status */
233#define PESDR1_L2BISTSTS 0x034E /* PE1 L2 built in self test status */
234#define PESDR1_L3BISTSTS 0x034F /* PE1 L3 built in self test status */
235#define PESDR1_L0CDRCTL 0x0350 /* PE1 L0 CDR control */
236#define PESDR1_L1CDRCTL 0x0351 /* PE1 L1 CDR control */
237#define PESDR1_L2CDRCTL 0x0352 /* PE1 L2 CDR control */
238#define PESDR1_L3CDRCTL 0x0353 /* PE1 L3 CDR control */
239#define PESDR1_L0DRV 0x0354 /* PE1 L0 drive */
240#define PESDR1_L1DRV 0x0355 /* PE1 L1 drive */
241#define PESDR1_L2DRV 0x0356 /* PE1 L2 drive */
242#define PESDR1_L3DRV 0x0357 /* PE1 L3 drive */
243#define PESDR1_L0REC 0x0358 /* PE1 L0 receiver */
244#define PESDR1_L1REC 0x0359 /* PE1 L1 receiver */
245#define PESDR1_L2REC 0x035A /* PE1 L2 receiver */
246#define PESDR1_L3REC 0x035B /* PE1 L3 receiver */
247#define PESDR1_L0LPB 0x035C /* PE1 L0 loopback */
248#define PESDR1_L1LPB 0x035D /* PE1 L1 loopback */
249#define PESDR1_L2LPB 0x035E /* PE1 L2 loopback */
250#define PESDR1_L3LPB 0x035F /* PE1 L3 loopback */
251#define PESDR1_L0CLK 0x0360 /* PE1 L0 clocking */
252#define PESDR1_L1CLK 0x0361 /* PE1 L1 clocking */
253#define PESDR1_L2CLK 0x0362 /* PE1 L2 clocking */
254#define PESDR1_L3CLK 0x0363 /* PE1 L3 clocking */
255#define PESDR1_PHY_CTL_RST 0x0364 /* PE1 PHY control reset */
256#define PESDR1_RSTSTA 0x0365 /* PE1 reset status */
257#define PESDR1_OBS 0x0366 /* PE1 observation register */
258#define PESDR1_L0ERRC 0x0368 /* PE1 L0 error counter */
259#define PESDR1_L1ERRC 0x0369 /* PE1 L1 error counter */
260#define PESDR1_L2ERRC 0x036A /* PE1 L2 error counter */
261#define PESDR1_L3ERRC 0x036B /* PE1 L3 error counter */
262#define PESDR0_IHS1 0x036C /* PE interrupt handler interfact setting 1 */
263#define PESDR0_IHS2 0x036D /* PE interrupt handler interfact setting 2 */
264
Stefan Roesea0d96342007-10-03 10:38:09 +0200265#endif
266
Stefan Roese50c05332008-03-11 15:07:10 +0100267/* SDR Bit Mappings */
268#define PESDRx_RCSSET_HLDPLB 0x10000000
269#define PESDRx_RCSSET_RSTGU 0x01000000
270#define PESDRx_RCSSET_RDY 0x00100000
271#define PESDRx_RCSSET_RSTDL 0x00010000
272#define PESDRx_RCSSET_RSTPYN 0x00001000
273
274#define PESDRx_RCSSTS_PLBIDL 0x10000000
275#define PESDRx_RCSSTS_HRSTRQ 0x01000000
276#define PESDRx_RCSSTS_PGRST 0x00100000
277#define PESDRx_RCSSTS_VC0ACT 0x00010000
278#define PESDRx_RCSSTS_BMEN 0x00000100
279
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200280/*
281 * UTL register offsets
282 */
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100283#define PEUTL_PBCTL 0x00
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200284#define PEUTL_PBBSZ 0x20
285#define PEUTL_OPDBSZ 0x68
286#define PEUTL_IPHBSZ 0x70
287#define PEUTL_IPDBSZ 0x78
288#define PEUTL_OUTTR 0x90
289#define PEUTL_INTR 0x98
290#define PEUTL_PCTL 0xa0
Stefan Roese1ce9fe92007-11-16 14:16:54 +0100291#define PEUTL_RCSTA 0xb0
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200292#define PEUTL_RCIRQEN 0xb8
293
294/*
295 * Config space register offsets
296 */
297#define PECFG_BAR0LMPA 0x210
298#define PECFG_BAR0HMPA 0x214
Stefan Roese074e9752006-08-29 08:05:15 +0200299#define PECFG_BAR1MPA 0x218
Stefan Roesee7fe4c52007-10-18 07:39:38 +0200300#define PECFG_BAR2LMPA 0x220
301#define PECFG_BAR2HMPA 0x224
Stefan Roese074e9752006-08-29 08:05:15 +0200302
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200303#define PECFG_PIMEN 0x33c
304#define PECFG_PIM0LAL 0x340
305#define PECFG_PIM0LAH 0x344
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200306#define PECFG_PIM1LAL 0x348
307#define PECFG_PIM1LAH 0x34c
Stefan Roese074e9752006-08-29 08:05:15 +0200308#define PECFG_PIM01SAL 0x350
309#define PECFG_PIM01SAH 0x354
310
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200311#define PECFG_POM0LAL 0x380
312#define PECFG_POM0LAH 0x384
313
314#define SDR_READ(offset) ({\
315 mtdcr(DCRN_SDR0_CFGADDR, offset); \
316 mfdcr(DCRN_SDR0_CFGDATA);})
317
318#define SDR_WRITE(offset, data) ({\
319 mtdcr(DCRN_SDR0_CFGADDR, offset); \
320 mtdcr(DCRN_SDR0_CFGDATA,data);})
321
Grzegorz Bernackieff9bc12007-09-07 17:46:18 +0200322#define GPL_DMER_MASK_DISA 0x02000000
Grzegorz Bernackid84fe302007-07-31 18:51:48 +0200323
Stefan Roese7a41bde2007-10-05 09:18:23 +0200324#define U64_TO_U32_LOW(val) ((u32)((val) & 0x00000000ffffffffULL))
325#define U64_TO_U32_HIGH(val) ((u32)((val) >> 32))
326
Stefan Roese89bac402007-10-13 16:43:23 +0200327/*
328 * Prototypes
329 */
Stefan Roese9c00e512007-10-03 07:48:09 +0200330int ppc4xx_init_pcie(void);
331int ppc4xx_init_pcie_rootport(int port);
Stefan Roesea0d96342007-10-03 10:38:09 +0200332int ppc4xx_init_pcie_endport(int port);
Stefan Roese9c00e512007-10-03 07:48:09 +0200333void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
334int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
Rafal Jaworowskia2e7ef02006-08-10 12:43:17 +0200335int pcie_hose_scan(struct pci_controller *hose, int bus);
Stefan Roese9c00e512007-10-03 07:48:09 +0200336
Stefan Roese89bac402007-10-13 16:43:23 +0200337/*
338 * Function to determine root port or endport from env variable.
339 */
340static inline int is_end_point(int port)
341{
Stefan Roesee7fe4c52007-10-18 07:39:38 +0200342 char s[10], *tk;
343 char *pcie_mode = getenv("pcie_mode");
344
345 if (pcie_mode == NULL)
346 return 0;
Stefan Roese89bac402007-10-13 16:43:23 +0200347
Stefan Roesee7fe4c52007-10-18 07:39:38 +0200348 strcpy(s, pcie_mode);
Stefan Roese89bac402007-10-13 16:43:23 +0200349 tk = strtok(s, ":");
350
351 switch (port) {
352 case 0:
353 if (tk != NULL) {
354 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
355 return 1;
356 else
357 return 0;
358 }
359 else
360 return 0;
361
362 case 1:
363 tk = strtok(NULL, ":");
364 if (tk != NULL) {
365 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
366 return 1;
367 else
368 return 0;
369 }
370 else
371 return 0;
372
373 case 2:
374 tk = strtok(NULL, ":");
375 if (tk != NULL)
376 tk = strtok(NULL, ":");
377 if (tk != NULL) {
378 if (!(strcmp(tk, "ep") && strcmp(tk, "EP")))
379 return 1;
380 else
381 return 0;
382 }
383 else
384 return 0;
385 }
386
387 return 0;
388}
389
Stefan Roesea0d96342007-10-03 10:38:09 +0200390static inline void mdelay(int n)
391{
392 u32 ms = n;
393
394 while (ms--)
395 udelay(1000);
396}
397
398static inline u32 sdr_base(int port)
399{
400 switch (port) {
401 default: /* to satisfy compiler */
402 case 0:
403 return PCIE0_SDR;
404 case 1:
405 return PCIE1_SDR;
Stefan Roese7a41bde2007-10-05 09:18:23 +0200406#if CFG_PCIE_NR_PORTS > 2
Stefan Roesea0d96342007-10-03 10:38:09 +0200407 case 2:
408 return PCIE2_SDR;
409#endif
410 }
411}
412
Stefan Roese9c00e512007-10-03 07:48:09 +0200413#endif /* __4XX_PCIE_H */