blob: 1bb8fc7ed13d403dd0d567ff26281f9144d33328 [file] [log] [blame]
Rafal Jaworowski692519b2006-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 Roese026f7112007-10-03 07:48:09 +020012#ifndef __4XX_PCIE_H
13#define __4XX_PCIE_H
Rafal Jaworowski692519b2006-08-10 12:43:17 +020014
Rafal Jaworowski692519b2006-08-10 12:43:17 +020015#define DCRN_SDR0_CFGADDR 0x00e
16#define DCRN_SDR0_CFGDATA 0x00f
17
Stefan Roese03d344b2007-10-03 10:38:09 +020018#if defined(CONFIG_440SPE)
Rafal Jaworowski692519b2006-08-10 12:43:17 +020019#define DCRN_PCIE0_BASE 0x100
20#define DCRN_PCIE1_BASE 0x120
21#define DCRN_PCIE2_BASE 0x140
Stefan Roese03d344b2007-10-03 10:38:09 +020022#endif
23
24#if defined(CONFIG_405EX)
25#define DCRN_PCIE0_BASE 0x040
26#define DCRN_PCIE1_BASE 0x060
27#endif
28
Rafal Jaworowski692519b2006-08-10 12:43:17 +020029#define PCIE0 DCRN_PCIE0_BASE
30#define PCIE1 DCRN_PCIE1_BASE
31#define PCIE2 DCRN_PCIE2_BASE
32
33#define DCRN_PEGPL_CFGBAH(base) (base + 0x00)
34#define DCRN_PEGPL_CFGBAL(base) (base + 0x01)
35#define DCRN_PEGPL_CFGMSK(base) (base + 0x02)
36#define DCRN_PEGPL_MSGBAH(base) (base + 0x03)
37#define DCRN_PEGPL_MSGBAL(base) (base + 0x04)
38#define DCRN_PEGPL_MSGMSK(base) (base + 0x05)
39#define DCRN_PEGPL_OMR1BAH(base) (base + 0x06)
40#define DCRN_PEGPL_OMR1BAL(base) (base + 0x07)
41#define DCRN_PEGPL_OMR1MSKH(base) (base + 0x08)
42#define DCRN_PEGPL_OMR1MSKL(base) (base + 0x09)
43#define DCRN_PEGPL_REGBAH(base) (base + 0x12)
44#define DCRN_PEGPL_REGBAL(base) (base + 0x13)
45#define DCRN_PEGPL_REGMSK(base) (base + 0x14)
46#define DCRN_PEGPL_SPECIAL(base) (base + 0x15)
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +020047#define DCRN_PEGPL_CFG(base) (base + 0x16)
Rafal Jaworowski692519b2006-08-10 12:43:17 +020048
49/*
50 * System DCRs (SDRs)
51 */
52#define PESDR0_PLLLCT1 0x03a0
53#define PESDR0_PLLLCT2 0x03a1
54#define PESDR0_PLLLCT3 0x03a2
55
Stefan Roese03d344b2007-10-03 10:38:09 +020056#if defined(CONFIG_440SPE)
57#define PCIE0_SDR 0x300
58#define PCIE1_SDR 0x340
59#define PCIE2_SDR 0x370
60#endif
61
62#if defined(CONFIG_405EX)
63#define PCIE0_SDR 0x400
64#define PCIE1_SDR 0x440
65#endif
66
67/* common regs, at least for 405EX and 440SPe */
68#define SDRN_PESDR_UTLSET1(n) (sdr_base(n) + 0x00)
69#define SDRN_PESDR_UTLSET2(n) (sdr_base(n) + 0x01)
70#define SDRN_PESDR_DLPSET(n) (sdr_base(n) + 0x02)
71#define SDRN_PESDR_LOOP(n) (sdr_base(n) + 0x03)
72#define SDRN_PESDR_RCSSET(n) (sdr_base(n) + 0x04)
73#define SDRN_PESDR_RCSSTS(n) (sdr_base(n) + 0x05)
74
75#if defined(CONFIG_440SPE)
76#define SDRN_PESDR_HSSL0SET1(n) (sdr_base(n) + 0x06)
77#define SDRN_PESDR_HSSL0SET2(n) (sdr_base(n) + 0x07)
78#define SDRN_PESDR_HSSL0STS(n) (sdr_base(n) + 0x08)
79#define SDRN_PESDR_HSSL1SET1(n) (sdr_base(n) + 0x09)
80#define SDRN_PESDR_HSSL1SET2(n) (sdr_base(n) + 0x0a)
81#define SDRN_PESDR_HSSL1STS(n) (sdr_base(n) + 0x0b)
82#define SDRN_PESDR_HSSL2SET1(n) (sdr_base(n) + 0x0c)
83#define SDRN_PESDR_HSSL2SET2(n) (sdr_base(n) + 0x0d)
84#define SDRN_PESDR_HSSL2STS(n) (sdr_base(n) + 0x0e)
85#define SDRN_PESDR_HSSL3SET1(n) (sdr_base(n) + 0x0f)
86#define SDRN_PESDR_HSSL3SET2(n) (sdr_base(n) + 0x10)
87#define SDRN_PESDR_HSSL3STS(n) (sdr_base(n) + 0x11)
88
Rafal Jaworowski692519b2006-08-10 12:43:17 +020089#define PESDR0_UTLSET1 0x0300
90#define PESDR0_UTLSET2 0x0301
91#define PESDR0_DLPSET 0x0302
92#define PESDR0_LOOP 0x0303
93#define PESDR0_RCSSET 0x0304
94#define PESDR0_RCSSTS 0x0305
95#define PESDR0_HSSL0SET1 0x0306
96#define PESDR0_HSSL0SET2 0x0307
97#define PESDR0_HSSL0STS 0x0308
98#define PESDR0_HSSL1SET1 0x0309
99#define PESDR0_HSSL1SET2 0x030a
100#define PESDR0_HSSL1STS 0x030b
101#define PESDR0_HSSL2SET1 0x030c
102#define PESDR0_HSSL2SET2 0x030d
103#define PESDR0_HSSL2STS 0x030e
104#define PESDR0_HSSL3SET1 0x030f
105#define PESDR0_HSSL3SET2 0x0310
106#define PESDR0_HSSL3STS 0x0311
107#define PESDR0_HSSL4SET1 0x0312
108#define PESDR0_HSSL4SET2 0x0313
109#define PESDR0_HSSL4STS 0x0314
110#define PESDR0_HSSL5SET1 0x0315
111#define PESDR0_HSSL5SET2 0x0316
112#define PESDR0_HSSL5STS 0x0317
113#define PESDR0_HSSL6SET1 0x0318
114#define PESDR0_HSSL6SET2 0x0319
115#define PESDR0_HSSL6STS 0x031a
116#define PESDR0_HSSL7SET1 0x031b
117#define PESDR0_HSSL7SET2 0x031c
118#define PESDR0_HSSL7STS 0x031d
119#define PESDR0_HSSCTLSET 0x031e
120#define PESDR0_LANE_ABCD 0x031f
121#define PESDR0_LANE_EFGH 0x0320
122
123#define PESDR1_UTLSET1 0x0340
124#define PESDR1_UTLSET2 0x0341
125#define PESDR1_DLPSET 0x0342
126#define PESDR1_LOOP 0x0343
127#define PESDR1_RCSSET 0x0344
128#define PESDR1_RCSSTS 0x0345
129#define PESDR1_HSSL0SET1 0x0346
130#define PESDR1_HSSL0SET2 0x0347
131#define PESDR1_HSSL0STS 0x0348
132#define PESDR1_HSSL1SET1 0x0349
133#define PESDR1_HSSL1SET2 0x034a
134#define PESDR1_HSSL1STS 0x034b
135#define PESDR1_HSSL2SET1 0x034c
136#define PESDR1_HSSL2SET2 0x034d
137#define PESDR1_HSSL2STS 0x034e
138#define PESDR1_HSSL3SET1 0x034f
139#define PESDR1_HSSL3SET2 0x0350
140#define PESDR1_HSSL3STS 0x0351
141#define PESDR1_HSSCTLSET 0x0352
142#define PESDR1_LANE_ABCD 0x0353
143
144#define PESDR2_UTLSET1 0x0370
145#define PESDR2_UTLSET2 0x0371
146#define PESDR2_DLPSET 0x0372
147#define PESDR2_LOOP 0x0373
148#define PESDR2_RCSSET 0x0374
149#define PESDR2_RCSSTS 0x0375
150#define PESDR2_HSSL0SET1 0x0376
151#define PESDR2_HSSL0SET2 0x0377
152#define PESDR2_HSSL0STS 0x0378
153#define PESDR2_HSSL1SET1 0x0379
154#define PESDR2_HSSL1SET2 0x037a
155#define PESDR2_HSSL1STS 0x037b
156#define PESDR2_HSSL2SET1 0x037c
157#define PESDR2_HSSL2SET2 0x037d
158#define PESDR2_HSSL2STS 0x037e
159#define PESDR2_HSSL3SET1 0x037f
160#define PESDR2_HSSL3SET2 0x0380
161#define PESDR2_HSSL3STS 0x0381
162#define PESDR2_HSSCTLSET 0x0382
163#define PESDR2_LANE_ABCD 0x0383
164
Stefan Roese03d344b2007-10-03 10:38:09 +0200165#elif defined(CONFIG_405EX)
166
167#define SDRN_PESDR_PHYSET1(n) (sdr_base(n) + 0x06)
168#define SDRN_PESDR_PHYSET2(n) (sdr_base(n) + 0x07)
169#define SDRN_PESDR_BIST(n) (sdr_base(n) + 0x08)
170#define SDRN_PESDR_LPB(n) (sdr_base(n) + 0x0b)
171#define SDRN_PESDR_PHYSTA(n) (sdr_base(n) + 0x0c)
172
173#define PESDR0_UTLSET1 0x0400
174#define PESDR0_UTLSET2 0x0401
175#define PESDR0_DLPSET 0x0402
176#define PESDR0_LOOP 0x0403
177#define PESDR0_RCSSET 0x0404
178#define PESDR0_RCSSTS 0x0405
179#define PESDR0_PHYSET1 0x0406
180#define PESDR0_PHYSET2 0x0407
181#define PESDR0_BIST 0x0408
182#define PESDR0_LPB 0x040B
183#define PESDR0_PHYSTA 0x040C
184
185#define PESDR1_UTLSET1 0x0440
186#define PESDR1_UTLSET2 0x0441
187#define PESDR1_DLPSET 0x0442
188#define PESDR1_LOOP 0x0443
189#define PESDR1_RCSSET 0x0444
190#define PESDR1_RCSSTS 0x0445
191#define PESDR1_PHYSET1 0x0446
192#define PESDR1_PHYSET2 0x0447
193#define PESDR1_BIST 0x0448
194#define PESDR1_LPB 0x044B
195#define PESDR1_PHYSTA 0x044C
196
197#endif
198
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200199/*
200 * UTL register offsets
201 */
202#define PEUTL_PBBSZ 0x20
203#define PEUTL_OPDBSZ 0x68
204#define PEUTL_IPHBSZ 0x70
205#define PEUTL_IPDBSZ 0x78
206#define PEUTL_OUTTR 0x90
207#define PEUTL_INTR 0x98
208#define PEUTL_PCTL 0xa0
209#define PEUTL_RCIRQEN 0xb8
210
211/*
212 * Config space register offsets
213 */
214#define PECFG_BAR0LMPA 0x210
215#define PECFG_BAR0HMPA 0x214
Stefan Roese2b393b02006-08-29 08:05:15 +0200216#define PECFG_BAR1MPA 0x218
217#define PECFG_BAR2MPA 0x220
218
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200219#define PECFG_PIMEN 0x33c
220#define PECFG_PIM0LAL 0x340
221#define PECFG_PIM0LAH 0x344
Grzegorz Bernackic9240982007-07-31 18:51:48 +0200222#define PECFG_PIM1LAL 0x348
223#define PECFG_PIM1LAH 0x34c
Stefan Roese2b393b02006-08-29 08:05:15 +0200224#define PECFG_PIM01SAL 0x350
225#define PECFG_PIM01SAH 0x354
226
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200227#define PECFG_POM0LAL 0x380
228#define PECFG_POM0LAH 0x384
229
230#define SDR_READ(offset) ({\
231 mtdcr(DCRN_SDR0_CFGADDR, offset); \
232 mfdcr(DCRN_SDR0_CFGDATA);})
233
234#define SDR_WRITE(offset, data) ({\
235 mtdcr(DCRN_SDR0_CFGADDR, offset); \
236 mtdcr(DCRN_SDR0_CFGDATA,data);})
237
Grzegorz Bernacki15ee4732007-09-07 17:46:18 +0200238#define GPL_DMER_MASK_DISA 0x02000000
Grzegorz Bernackic9240982007-07-31 18:51:48 +0200239
Stefan Roese026f7112007-10-03 07:48:09 +0200240int ppc4xx_init_pcie(void);
241int ppc4xx_init_pcie_rootport(int port);
Stefan Roese03d344b2007-10-03 10:38:09 +0200242int ppc4xx_init_pcie_endport(int port);
Stefan Roese026f7112007-10-03 07:48:09 +0200243void ppc4xx_setup_pcie_rootpoint(struct pci_controller *hose, int port);
244int ppc4xx_setup_pcie_endpoint(struct pci_controller *hose, int port);
Rafal Jaworowski692519b2006-08-10 12:43:17 +0200245int pcie_hose_scan(struct pci_controller *hose, int bus);
Stefan Roese026f7112007-10-03 07:48:09 +0200246
Stefan Roese03d344b2007-10-03 10:38:09 +0200247static inline void mdelay(int n)
248{
249 u32 ms = n;
250
251 while (ms--)
252 udelay(1000);
253}
254
255static inline u32 sdr_base(int port)
256{
257 switch (port) {
258 default: /* to satisfy compiler */
259 case 0:
260 return PCIE0_SDR;
261 case 1:
262 return PCIE1_SDR;
263#if defined(PCIE2_SDR)
264 case 2:
265 return PCIE2_SDR;
266#endif
267 }
268}
269
Stefan Roese026f7112007-10-03 07:48:09 +0200270#endif /* __4XX_PCIE_H */