9e0fa1b278f4159dc9de9350380f26642c5f8e11
[openwrt/svn-archive/archive.git] / target / linux / lantiq / patches-3.10 / 0001-MIPS-lantiq-add-pcie-driver.patch
1 From 1b5fced71edb0a4e71012d79be29f1003c7b099f Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Wed, 13 Mar 2013 09:39:02 +0100
4 Subject: [PATCH 01/34] MIPS: lantiq: add pcie driver
5
6 ---
7 arch/mips/lantiq/Kconfig | 10 +
8 arch/mips/lantiq/xway/sysctrl.c | 2 +
9 arch/mips/pci/Makefile | 2 +
10 arch/mips/pci/fixup-lantiq-pcie.c | 82 +++
11 arch/mips/pci/fixup-lantiq.c | 5 +-
12 arch/mips/pci/ifxmips_pci_common.h | 57 ++
13 arch/mips/pci/ifxmips_pcie.c | 1099 ++++++++++++++++++++++++++++++
14 arch/mips/pci/ifxmips_pcie.h | 135 ++++
15 arch/mips/pci/ifxmips_pcie_ar10.h | 290 ++++++++
16 arch/mips/pci/ifxmips_pcie_msi.c | 392 +++++++++++
17 arch/mips/pci/ifxmips_pcie_phy.c | 478 +++++++++++++
18 arch/mips/pci/ifxmips_pcie_pm.c | 176 +++++
19 arch/mips/pci/ifxmips_pcie_pm.h | 36 +
20 arch/mips/pci/ifxmips_pcie_reg.h | 1001 +++++++++++++++++++++++++++
21 arch/mips/pci/ifxmips_pcie_vr9.h | 271 ++++++++
22 arch/mips/pci/pci.c | 25 +
23 arch/mips/pci/pcie-lantiq.h | 1305 ++++++++++++++++++++++++++++++++++++
24 drivers/pci/pcie/aer/Kconfig | 2 +-
25 include/linux/pci.h | 2 +
26 include/linux/pci_ids.h | 6 +
27 20 files changed, 5374 insertions(+), 2 deletions(-)
28 create mode 100644 arch/mips/pci/fixup-lantiq-pcie.c
29 create mode 100644 arch/mips/pci/ifxmips_pci_common.h
30 create mode 100644 arch/mips/pci/ifxmips_pcie.c
31 create mode 100644 arch/mips/pci/ifxmips_pcie.h
32 create mode 100644 arch/mips/pci/ifxmips_pcie_ar10.h
33 create mode 100644 arch/mips/pci/ifxmips_pcie_msi.c
34 create mode 100644 arch/mips/pci/ifxmips_pcie_phy.c
35 create mode 100644 arch/mips/pci/ifxmips_pcie_pm.c
36 create mode 100644 arch/mips/pci/ifxmips_pcie_pm.h
37 create mode 100644 arch/mips/pci/ifxmips_pcie_reg.h
38 create mode 100644 arch/mips/pci/ifxmips_pcie_vr9.h
39 create mode 100644 arch/mips/pci/pcie-lantiq.h
40
41 diff --git a/arch/mips/lantiq/Kconfig b/arch/mips/lantiq/Kconfig
42 index c002191..1621b1d 100644
43 --- a/arch/mips/lantiq/Kconfig
44 +++ b/arch/mips/lantiq/Kconfig
45 @@ -17,6 +17,7 @@ config SOC_XWAY
46 bool "XWAY"
47 select SOC_TYPE_XWAY
48 select HW_HAS_PCI
49 + select ARCH_SUPPORTS_MSI
50
51 config SOC_FALCON
52 bool "FALCON"
53 @@ -36,6 +37,15 @@ config PCI_LANTIQ
54 bool "PCI Support"
55 depends on SOC_XWAY && PCI
56
57 +config PCIE_LANTIQ
58 + bool "PCIE Support"
59 + depends on SOC_XWAY && PCI
60 +
61 +config PCIE_LANTIQ_MSI
62 + bool
63 + depends on PCIE_LANTIQ && PCI_MSI
64 + default y
65 +
66 config XRX200_PHY_FW
67 bool "XRX200 PHY firmware loader"
68 depends on SOC_XWAY
69 diff --git a/arch/mips/lantiq/xway/sysctrl.c b/arch/mips/lantiq/xway/sysctrl.c
70 index c24924f..e30dde8 100644
71 --- a/arch/mips/lantiq/xway/sysctrl.c
72 +++ b/arch/mips/lantiq/xway/sysctrl.c
73 @@ -377,6 +377,8 @@ void __init ltq_soc_init(void)
74 PMU_PPE_EMA | PMU_PPE_TC | PMU_PPE_SLL01 |
75 PMU_PPE_QSB | PMU_PPE_TOP);
76 clkdev_add_pmu("1f203000.rcu", "gphy", 0, PMU_GPHY);
77 + pmu_w32(~0, PMU_PWDSR1);
78 + pmu_w32(pmu_r32(PMU_PWDSR) & ~PMU_PCIE_CLK, PMU_PWDSR);
79 } else if (of_machine_is_compatible("lantiq,ar9")) {
80 clkdev_add_static(ltq_ar9_cpu_hz(), ltq_ar9_fpi_hz(),
81 ltq_ar9_fpi_hz(), CLOCK_250M);
82 diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile
83 index 2cb1d31..8ba7fff 100644
84 --- a/arch/mips/pci/Makefile
85 +++ b/arch/mips/pci/Makefile
86 @@ -41,6 +41,8 @@ obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1480.o pci-bcm1480ht.o
87 obj-$(CONFIG_SNI_RM) += fixup-sni.o ops-sni.o
88 obj-$(CONFIG_LANTIQ) += fixup-lantiq.o
89 obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o ops-lantiq.o
90 +obj-$(CONFIG_PCIE_LANTIQ) += ifxmips_pcie_phy.o ifxmips_pcie.o fixup-lantiq-pcie.o
91 +obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
92 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
93 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
94 obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
95 diff --git a/arch/mips/pci/fixup-lantiq-pcie.c b/arch/mips/pci/fixup-lantiq-pcie.c
96 new file mode 100644
97 index 0000000..3325e24
98 --- /dev/null
99 +++ b/arch/mips/pci/fixup-lantiq-pcie.c
100 @@ -0,0 +1,82 @@
101 +/******************************************************************************
102 +**
103 +** FILE NAME : ifxmips_fixup_pcie.c
104 +** PROJECT : IFX UEIP for VRX200
105 +** MODULES : PCIe
106 +**
107 +** DATE : 02 Mar 2009
108 +** AUTHOR : Lei Chuanhua
109 +** DESCRIPTION : PCIe Root Complex Driver
110 +** COPYRIGHT : Copyright (c) 2009
111 +** Infineon Technologies AG
112 +** Am Campeon 1-12, 85579 Neubiberg, Germany
113 +**
114 +** This program is free software; you can redistribute it and/or modify
115 +** it under the terms of the GNU General Public License as published by
116 +** the Free Software Foundation; either version 2 of the License, or
117 +** (at your option) any later version.
118 +** HISTORY
119 +** $Version $Date $Author $Comment
120 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
121 +*******************************************************************************/
122 +/*!
123 + \file ifxmips_fixup_pcie.c
124 + \ingroup IFX_PCIE
125 + \brief PCIe Fixup functions source file
126 +*/
127 +#include <linux/pci.h>
128 +#include <linux/pci_regs.h>
129 +#include <linux/pci_ids.h>
130 +
131 +#include <lantiq_soc.h>
132 +
133 +#include "pcie-lantiq.h"
134 +
135 +#define PCI_VENDOR_ID_INFINEON 0x15D1
136 +#define PCI_DEVICE_ID_INFINEON_DANUBE 0x000F
137 +#define PCI_DEVICE_ID_INFINEON_PCIE 0x0011
138 +#define PCI_VENDOR_ID_LANTIQ 0x1BEF
139 +#define PCI_DEVICE_ID_LANTIQ_PCIE 0x0011
140 +
141 +
142 +
143 +static void
144 +ifx_pcie_fixup_resource(struct pci_dev *dev)
145 +{
146 + u32 reg;
147 +
148 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
149 +
150 + printk("%s: fixup host controller %s (%04x:%04x)\n",
151 + __func__, pci_name(dev), dev->vendor, dev->device);
152 +
153 + /* Setup COMMAND register */
154 + reg = PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER /* |
155 + PCI_COMMAND_INTX_DISABLE */| PCI_COMMAND_SERR;
156 + pci_write_config_word(dev, PCI_COMMAND, reg);
157 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
158 +}
159 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE, ifx_pcie_fixup_resource);
160 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_VENDOR_ID_LANTIQ, ifx_pcie_fixup_resource);
161 +
162 +static void
163 +ifx_pcie_rc_class_early_fixup(struct pci_dev *dev)
164 +{
165 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
166 +
167 + if (dev->devfn == PCI_DEVFN(0, 0) &&
168 + (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
169 +
170 + dev->class = (PCI_CLASS_BRIDGE_PCI << 8) | (dev->class & 0xff);
171 +
172 + printk(KERN_INFO "%s: fixed pcie host bridge to pci-pci bridge\n", __func__);
173 + }
174 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
175 + mdelay(10);
176 +}
177 +
178 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE,
179 + ifx_pcie_rc_class_early_fixup);
180 +
181 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_DEVICE_ID_LANTIQ_PCIE,
182 + ifx_pcie_rc_class_early_fixup);
183 diff --git a/arch/mips/pci/fixup-lantiq.c b/arch/mips/pci/fixup-lantiq.c
184 index 6c829df..50ec0b5 100644
185 --- a/arch/mips/pci/fixup-lantiq.c
186 +++ b/arch/mips/pci/fixup-lantiq.c
187 @@ -11,11 +11,12 @@
188
189 int (*ltq_pci_plat_arch_init)(struct pci_dev *dev) = NULL;
190 int (*ltq_pci_plat_dev_init)(struct pci_dev *dev) = NULL;
191 +int (*ltq_pci_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
192
193 int pcibios_plat_dev_init(struct pci_dev *dev)
194 {
195 if (ltq_pci_plat_arch_init)
196 - return ltq_pci_plat_arch_init(dev);
197 + ltq_pci_plat_arch_init(dev);
198
199 if (ltq_pci_plat_dev_init)
200 return ltq_pci_plat_dev_init(dev);
201 @@ -28,6 +29,8 @@ int __init pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
202 struct of_irq dev_irq;
203 int irq;
204
205 + if (ltq_pci_map_irq)
206 + return ltq_pci_map_irq(dev, slot, pin);
207 if (of_irq_map_pci(dev, &dev_irq)) {
208 dev_err(&dev->dev, "trying to map irq for unknown slot:%d pin:%d\n",
209 slot, pin);
210 diff --git a/arch/mips/pci/ifxmips_pci_common.h b/arch/mips/pci/ifxmips_pci_common.h
211 new file mode 100644
212 index 0000000..46f4cb2
213 --- /dev/null
214 +++ b/arch/mips/pci/ifxmips_pci_common.h
215 @@ -0,0 +1,57 @@
216 +/******************************************************************************
217 +**
218 +** FILE NAME : ifxmips_pci_common.h
219 +** PROJECT : IFX UEIP
220 +** MODULES : PCI subsystem
221 +**
222 +** DATE : 30 June 2009
223 +** AUTHOR : Lei Chuanhua
224 +** DESCRIPTION : PCIe Root Complex Driver
225 +** COPYRIGHT : Copyright (c) 2009
226 +** Infineon Technologies AG
227 +** Am Campeon 1-12, 85579 Neubiberg, Germany
228 +**
229 +** This program is free software; you can redistribute it and/or modify
230 +** it under the terms of the GNU General Public License as published by
231 +** the Free Software Foundation; either version 2 of the License, or
232 +** (at your option) any later version.
233 +** HISTORY
234 +** $Version $Date $Author $Comment
235 +** 0.0.1 30 June,2009 Lei Chuanhua Initial version
236 +*******************************************************************************/
237 +
238 +#ifndef IFXMIPS_PCI_COMMON_H
239 +#define IFXMIPS_PCI_COMMON_H
240 +#include <linux/version.h>
241 +/*!
242 + \defgroup IFX_PCI_COM IFX PCI/PCIe common parts for OS integration
243 + \brief PCI/PCIe common parts
244 +*/
245 +
246 +/*!
247 + \defgroup IFX_PCI_COM_OS OS APIs
248 + \ingroup IFX_PCI_COM
249 + \brief PCI/PCIe bus driver OS interface functions
250 +*/
251 +/*!
252 + \file ifxmips_pci_common.h
253 + \ingroup IFX_PCI_COM
254 + \brief PCI/PCIe bus driver common OS header file
255 +*/
256 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
257 +#define IFX_PCI_CONST
258 +#else
259 +#define IFX_PCI_CONST const
260 +#endif
261 +#ifdef CONFIG_IFX_PCI
262 +extern int ifx_pci_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
263 +extern int ifx_pci_bios_plat_dev_init(struct pci_dev *dev);
264 +#endif /* COFNIG_IFX_PCI */
265 +
266 +#ifdef CONFIG_IFX_PCIE
267 +extern int ifx_pcie_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin);
268 +extern int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev);
269 +#endif
270 +
271 +#endif /* IFXMIPS_PCI_COMMON_H */
272 +
273 diff --git a/arch/mips/pci/ifxmips_pcie.c b/arch/mips/pci/ifxmips_pcie.c
274 new file mode 100644
275 index 0000000..4128898
276 --- /dev/null
277 +++ b/arch/mips/pci/ifxmips_pcie.c
278 @@ -0,0 +1,1099 @@
279 +/*
280 + * This program is free software; you can redistribute it and/or modify it
281 + * under the terms of the GNU General Public License version 2 as published
282 + * by the Free Software Foundation.
283 + *
284 + * Copyright (C) 2009 Lei Chuanhua <chuanhua.lei@infineon.com>
285 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
286 + */
287 +
288 +#include <linux/types.h>
289 +#include <linux/pci.h>
290 +#include <linux/kernel.h>
291 +#include <linux/init.h>
292 +#include <linux/delay.h>
293 +#include <linux/mm.h>
294 +#include <asm/paccess.h>
295 +#include <linux/pci.h>
296 +#include <linux/pci_regs.h>
297 +#include <linux/module.h>
298 +
299 +#include "ifxmips_pcie.h"
300 +#include "ifxmips_pcie_reg.h"
301 +
302 +/* Enable 32bit io due to its mem mapped io nature */
303 +#define IFX_PCIE_ERROR_INT
304 +#define IFX_PCIE_IO_32BIT
305 +
306 +#define IFX_PCIE_IR (INT_NUM_IM4_IRL0 + 25)
307 +#define IFX_PCIE_INTA (INT_NUM_IM4_IRL0 + 8)
308 +#define IFX_PCIE_INTB (INT_NUM_IM4_IRL0 + 9)
309 +#define IFX_PCIE_INTC (INT_NUM_IM4_IRL0 + 10)
310 +#define IFX_PCIE_INTD (INT_NUM_IM4_IRL0 + 11)
311 +#define MS(_v, _f) (((_v) & (_f)) >> _f##_S)
312 +#define SM(_v, _f) (((_v) << _f##_S) & (_f))
313 +#define IFX_REG_SET_BIT(_f, _r) \
314 + IFX_REG_W32((IFX_REG_R32((_r)) &~ (_f)) | (_f), (_r))
315 +
316 +#define IFX_PCIE_LTSSM_ENABLE_TIMEOUT 10
317 +
318 +static DEFINE_SPINLOCK(ifx_pcie_lock);
319 +
320 +u32 g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
321 +
322 +static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
323 + {
324 + .ir_irq = {
325 + .irq = IFX_PCIE_IR,
326 + .name = "ifx_pcie_rc0",
327 + },
328 +
329 + .legacy_irq = {
330 + {
331 + .irq_bit = PCIE_IRN_INTA,
332 + .irq = IFX_PCIE_INTA,
333 + },
334 + {
335 + .irq_bit = PCIE_IRN_INTB,
336 + .irq = IFX_PCIE_INTB,
337 + },
338 + {
339 + .irq_bit = PCIE_IRN_INTC,
340 + .irq = IFX_PCIE_INTC,
341 + },
342 + {
343 + .irq_bit = PCIE_IRN_INTD,
344 + .irq = IFX_PCIE_INTD,
345 + },
346 + },
347 + },
348 +
349 +};
350 +
351 +void ifx_pcie_debug(const char *fmt, ...)
352 +{
353 + static char buf[256] = {0}; /* XXX */
354 + va_list ap;
355 +
356 + va_start(ap, fmt);
357 + vsnprintf(buf, sizeof(buf), fmt, ap);
358 + va_end(ap);
359 +
360 + printk("%s", buf);
361 +}
362 +
363 +
364 +static inline int pcie_ltssm_enable(int pcie_port)
365 +{
366 + int i;
367 +
368 + /* Enable LTSSM */
369 + IFX_REG_W32(PCIE_RC_CCR_LTSSM_ENABLE, PCIE_RC_CCR(pcie_port));
370 +
371 + /* Wait for the link to come up */
372 + for (i = 0; i < IFX_PCIE_LTSSM_ENABLE_TIMEOUT; i++) {
373 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_RETRAIN_PENDING))
374 + return 0;
375 + udelay(10);
376 + }
377 +
378 + printk("%s link timeout!!!!!\n", __func__);
379 + return -1;
380 +}
381 +
382 +static inline void pcie_status_register_clear(int pcie_port)
383 +{
384 + IFX_REG_W32(0, PCIE_RC_DR(pcie_port));
385 + IFX_REG_W32(0, PCIE_PCICMDSTS(pcie_port));
386 + IFX_REG_W32(0, PCIE_DCTLSTS(pcie_port));
387 + IFX_REG_W32(0, PCIE_LCTLSTS(pcie_port));
388 + IFX_REG_W32(0, PCIE_SLCTLSTS(pcie_port));
389 + IFX_REG_W32(0, PCIE_RSTS(pcie_port));
390 + IFX_REG_W32(0, PCIE_UES_R(pcie_port));
391 + IFX_REG_W32(0, PCIE_UEMR(pcie_port));
392 + IFX_REG_W32(0, PCIE_UESR(pcie_port));
393 + IFX_REG_W32(0, PCIE_CESR(pcie_port));
394 + IFX_REG_W32(0, PCIE_CEMR(pcie_port));
395 + IFX_REG_W32(0, PCIE_RESR(pcie_port));
396 + IFX_REG_W32(0, PCIE_PVCCRSR(pcie_port));
397 + IFX_REG_W32(0, PCIE_VC0_RSR0(pcie_port));
398 + IFX_REG_W32(0, PCIE_TPFCS(pcie_port));
399 + IFX_REG_W32(0, PCIE_TNPFCS(pcie_port));
400 + IFX_REG_W32(0, PCIE_TCFCS(pcie_port));
401 + IFX_REG_W32(0, PCIE_QSR(pcie_port));
402 + IFX_REG_W32(0, PCIE_IOBLSECS(pcie_port));
403 +}
404 +
405 +static inline int ifx_pcie_link_up(int pcie_port)
406 +{
407 + return (IFX_REG_R32(PCIE_PHY_SR(pcie_port)) & PCIE_PHY_SR_PHY_LINK_UP) ? 1 : 0;
408 +}
409 +
410 +
411 +static inline void pcie_mem_io_setup(int pcie_port)
412 +{
413 + u32 reg;
414 + /*
415 + * BAR[0:1] readonly register
416 + * RC contains only minimal BARs for packets mapped to this device
417 + * Mem/IO filters defines a range of memory occupied by memory mapped IO devices that
418 + * reside on the downstream side fo the bridge.
419 + */
420 + reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_MBML_MEM_LIMIT_ADDR)
421 + | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_MBML_MEM_BASE_ADDR);
422 +
423 + IFX_REG_W32(reg, PCIE_MBML(pcie_port));
424 +
425 +
426 +#ifdef IFX_PCIE_PREFETCH_MEM_64BIT
427 + reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_PMBL_END_ADDR)
428 + | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_PMBL_UPPER_12BIT)
429 + | PCIE_PMBL_64BIT_ADDR;
430 + IFX_REG_W32(reg, PCIE_PMBL(pcie_port));
431 +
432 + /* Must configure upper 32bit */
433 + IFX_REG_W32(0, PCIE_PMBU32(pcie_port));
434 + IFX_REG_W32(0, PCIE_PMLU32(pcie_port));
435 +#else
436 + /* PCIe_PBML, same as MBML */
437 + IFX_REG_W32(IFX_REG_R32(PCIE_MBML(pcie_port)), PCIE_PMBL(pcie_port));
438 +#endif
439 +
440 + /* IO Address Range */
441 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 12), PCIE_IOBLSECS_IO_LIMIT_ADDR)
442 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 12), PCIE_IOBLSECS_IO_BASE_ADDR);
443 +#ifdef IFX_PCIE_IO_32BIT
444 + reg |= PCIE_IOBLSECS_32BIT_IO_ADDR;
445 +#endif /* IFX_PCIE_IO_32BIT */
446 + IFX_REG_W32(reg, PCIE_IOBLSECS(pcie_port));
447 +
448 +#ifdef IFX_PCIE_IO_32BIT
449 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT)
450 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_BASE);
451 + IFX_REG_W32(reg, PCIE_IO_BANDL(pcie_port));
452 +
453 +#endif /* IFX_PCIE_IO_32BIT */
454 +}
455 +
456 +static inline void
457 +pcie_device_setup(int pcie_port)
458 +{
459 + u32 reg;
460 +
461 + /* Device capability register, set up Maximum payload size */
462 + reg = IFX_REG_R32(PCIE_DCAP(pcie_port));
463 + reg |= PCIE_DCAP_ROLE_BASE_ERR_REPORT;
464 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCAP_MAX_PAYLOAD_SIZE);
465 +
466 + /* Only available for EP */
467 + reg &= ~(PCIE_DCAP_EP_L0S_LATENCY | PCIE_DCAP_EP_L1_LATENCY);
468 + IFX_REG_W32(reg, PCIE_DCAP(pcie_port));
469 +
470 + /* Device control and status register */
471 + /* Set Maximum Read Request size for the device as a Requestor */
472 + reg = IFX_REG_R32(PCIE_DCTLSTS(pcie_port));
473 +
474 + /*
475 + * Request size can be larger than the MPS used, but the completions returned
476 + * for the read will be bounded by the MPS size.
477 + * In our system, Max request size depends on AHB burst size. It is 64 bytes.
478 + * but we set it as 128 as minimum one.
479 + */
480 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_READ_SIZE)
481 + | SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_PAYLOAD_SIZE);
482 +
483 + /* Enable relaxed ordering, no snoop, and all kinds of errors */
484 + reg |= PCIE_DCTLSTS_RELAXED_ORDERING_EN | PCIE_DCTLSTS_ERR_EN | PCIE_DCTLSTS_NO_SNOOP_EN;
485 +
486 + IFX_REG_W32(reg, PCIE_DCTLSTS(pcie_port));
487 +}
488 +
489 +static inline void
490 +pcie_link_setup(int pcie_port)
491 +{
492 + u32 reg;
493 +
494 + /*
495 + * XXX, Link capability register, bit 18 for EP CLKREQ# dynamic clock management for L1, L2/3 CPM
496 + * L0s is reported during link training via TS1 order set by N_FTS
497 + */
498 + reg = IFX_REG_R32(PCIE_LCAP(pcie_port));
499 + reg &= ~PCIE_LCAP_L0S_EIXT_LATENCY;
500 + reg |= SM(3, PCIE_LCAP_L0S_EIXT_LATENCY);
501 + IFX_REG_W32(reg, PCIE_LCAP(pcie_port));
502 +
503 + /* Link control and status register */
504 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
505 +
506 + /* Link Enable, ASPM enabled */
507 + reg &= ~PCIE_LCTLSTS_LINK_DISABLE;
508 +
509 +#ifdef CONFIG_PCIEASPM
510 + /*
511 + * We use the same physical reference clock that the platform provides on the connector
512 + * It paved the way for ASPM to calculate the new exit Latency
513 + */
514 + reg |= PCIE_LCTLSTS_SLOT_CLK_CFG;
515 + reg |= PCIE_LCTLSTS_COM_CLK_CFG;
516 + /*
517 + * We should disable ASPM by default except that we have dedicated power management support
518 + * Enable ASPM will cause the system hangup/instability, performance degration
519 + */
520 + reg |= PCIE_LCTLSTS_ASPM_ENABLE;
521 +#else
522 + reg &= ~PCIE_LCTLSTS_ASPM_ENABLE;
523 +#endif /* CONFIG_PCIEASPM */
524 +
525 + /*
526 + * The maximum size of any completion with data packet is bounded by the MPS setting
527 + * in device control register
528 + */
529 +
530 + /* RCB may cause multiple split transactions, two options available, we use 64 byte RCB */
531 + reg &= ~ PCIE_LCTLSTS_RCB128;
532 +
533 + IFX_REG_W32(reg, PCIE_LCTLSTS(pcie_port));
534 +}
535 +
536 +static inline void pcie_error_setup(int pcie_port)
537 +{
538 + u32 reg;
539 +
540 + /*
541 + * Forward ERR_COR, ERR_NONFATAL, ERR_FATAL to the backbone
542 + * Poisoned write TLPs and completions indicating poisoned TLPs will set the PCIe_PCICMDSTS.MDPE
543 + */
544 + reg = IFX_REG_R32(PCIE_INTRBCTRL(pcie_port));
545 + reg |= PCIE_INTRBCTRL_SERR_ENABLE | PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE;
546 +
547 + IFX_REG_W32(reg, PCIE_INTRBCTRL(pcie_port));
548 +
549 + /* Uncorrectable Error Mask Register, Unmask <enable> all bits in PCIE_UESR */
550 + reg = IFX_REG_R32(PCIE_UEMR(pcie_port));
551 + reg &= ~PCIE_ALL_UNCORRECTABLE_ERR;
552 + IFX_REG_W32(reg, PCIE_UEMR(pcie_port));
553 +
554 + /* Uncorrectable Error Severity Register, ALL errors are FATAL */
555 + IFX_REG_W32(PCIE_ALL_UNCORRECTABLE_ERR, PCIE_UESR(pcie_port));
556 +
557 + /* Correctable Error Mask Register, unmask <enable> all bits */
558 + reg = IFX_REG_R32(PCIE_CEMR(pcie_port));
559 + reg &= ~PCIE_CORRECTABLE_ERR;
560 + IFX_REG_W32(reg, PCIE_CEMR(pcie_port));
561 +
562 + /* Advanced Error Capabilities and Control Registr */
563 + reg = IFX_REG_R32(PCIE_AECCR(pcie_port));
564 + reg |= PCIE_AECCR_ECRC_CHECK_EN | PCIE_AECCR_ECRC_GEN_EN;
565 + IFX_REG_W32(reg, PCIE_AECCR(pcie_port));
566 +
567 + /* Root Error Command Register, Report all types of errors */
568 + reg = IFX_REG_R32(PCIE_RECR(pcie_port));
569 + reg |= PCIE_RECR_ERR_REPORT_EN;
570 + IFX_REG_W32(reg, PCIE_RECR(pcie_port));
571 +
572 + /* Clear the Root status register */
573 + reg = IFX_REG_R32(PCIE_RESR(pcie_port));
574 + IFX_REG_W32(reg, PCIE_RESR(pcie_port));
575 +}
576 +
577 +static inline void pcie_port_logic_setup(int pcie_port)
578 +{
579 + u32 reg;
580 +
581 + /* FTS number, default 12, increase to 63, may increase time from/to L0s to L0 */
582 + reg = IFX_REG_R32(PCIE_AFR(pcie_port));
583 + reg &= ~(PCIE_AFR_FTS_NUM | PCIE_AFR_COM_FTS_NUM);
584 + reg |= SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_FTS_NUM)
585 + | SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_COM_FTS_NUM);
586 + /* L0s and L1 entry latency */
587 + reg &= ~(PCIE_AFR_L0S_ENTRY_LATENCY | PCIE_AFR_L1_ENTRY_LATENCY);
588 + reg |= SM(PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L0S_ENTRY_LATENCY)
589 + | SM(PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L1_ENTRY_LATENCY);
590 + IFX_REG_W32(reg, PCIE_AFR(pcie_port));
591 +
592 +
593 + /* Port Link Control Register */
594 + reg = IFX_REG_R32(PCIE_PLCR(pcie_port));
595 + reg |= PCIE_PLCR_DLL_LINK_EN; /* Enable the DLL link */
596 + IFX_REG_W32(reg, PCIE_PLCR(pcie_port));
597 +
598 + /* Lane Skew Register */
599 + reg = IFX_REG_R32(PCIE_LSR(pcie_port));
600 + /* Enable ACK/NACK and FC */
601 + reg &= ~(PCIE_LSR_ACKNAK_DISABLE | PCIE_LSR_FC_DISABLE);
602 + IFX_REG_W32(reg, PCIE_LSR(pcie_port));
603 +
604 + /* Symbol Timer Register and Filter Mask Register 1 */
605 + reg = IFX_REG_R32(PCIE_STRFMR(pcie_port));
606 +
607 + /* Default SKP interval is very accurate already, 5us */
608 + /* Enable IO/CFG transaction */
609 + reg |= PCIE_STRFMR_RX_CFG_TRANS_ENABLE | PCIE_STRFMR_RX_IO_TRANS_ENABLE;
610 + /* Disable FC WDT */
611 + reg &= ~PCIE_STRFMR_FC_WDT_DISABLE;
612 + IFX_REG_W32(reg, PCIE_STRFMR(pcie_port));
613 +
614 + /* Filter Masker Register 2 */
615 + reg = IFX_REG_R32(PCIE_FMR2(pcie_port));
616 + reg |= PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 | PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1;
617 + IFX_REG_W32(reg, PCIE_FMR2(pcie_port));
618 +
619 + /* VC0 Completion Receive Queue Control Register */
620 + reg = IFX_REG_R32(PCIE_VC0_CRQCR(pcie_port));
621 + reg &= ~PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE;
622 + reg |= SM(PCIE_VC0_TLP_QUEUE_MODE_BYPASS, PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE);
623 + IFX_REG_W32(reg, PCIE_VC0_CRQCR(pcie_port));
624 +}
625 +
626 +static inline void pcie_rc_cfg_reg_setup(int pcie_port)
627 +{
628 + u32 reg;
629 +
630 + /* Disable LTSSM */
631 + IFX_REG_W32(0, PCIE_RC_CCR(pcie_port)); /* Disable LTSSM */
632 +
633 + pcie_mem_io_setup(pcie_port);
634 +
635 + /* XXX, MSI stuff should only apply to EP */
636 + /* MSI Capability: Only enable 32-bit addresses */
637 + reg = IFX_REG_R32(PCIE_MCAPR(pcie_port));
638 + reg &= ~PCIE_MCAPR_ADDR64_CAP;
639 +
640 + reg |= PCIE_MCAPR_MSI_ENABLE;
641 +
642 + /* Disable multiple message */
643 + reg &= ~(PCIE_MCAPR_MULTI_MSG_CAP | PCIE_MCAPR_MULTI_MSG_ENABLE);
644 + IFX_REG_W32(reg, PCIE_MCAPR(pcie_port));
645 +
646 +
647 + /* Enable PME, Soft reset enabled */
648 + reg = IFX_REG_R32(PCIE_PM_CSR(pcie_port));
649 + reg |= PCIE_PM_CSR_PME_ENABLE | PCIE_PM_CSR_SW_RST;
650 + IFX_REG_W32(reg, PCIE_PM_CSR(pcie_port));
651 +
652 + /* setup the bus */
653 + reg = SM(0, PCIE_BNR_PRIMARY_BUS_NUM) | SM(1, PCIE_PNR_SECONDARY_BUS_NUM) | SM(0xFF, PCIE_PNR_SUB_BUS_NUM);
654 + IFX_REG_W32(reg, PCIE_BNR(pcie_port));
655 +
656 +
657 + pcie_device_setup(pcie_port);
658 + pcie_link_setup(pcie_port);
659 + pcie_error_setup(pcie_port);
660 +
661 + /* Root control and capabilities register */
662 + reg = IFX_REG_R32(PCIE_RCTLCAP(pcie_port));
663 + reg |= PCIE_RCTLCAP_SERR_ENABLE | PCIE_RCTLCAP_PME_INT_EN;
664 + IFX_REG_W32(reg, PCIE_RCTLCAP(pcie_port));
665 +
666 + /* Port VC Capability Register 2 */
667 + reg = IFX_REG_R32(PCIE_PVC2(pcie_port));
668 + reg &= ~PCIE_PVC2_VC_ARB_WRR;
669 + reg |= PCIE_PVC2_VC_ARB_16P_FIXED_WRR;
670 + IFX_REG_W32(reg, PCIE_PVC2(pcie_port));
671 +
672 + /* VC0 Resource Capability Register */
673 + reg = IFX_REG_R32(PCIE_VC0_RC(pcie_port));
674 + reg &= ~PCIE_VC0_RC_REJECT_SNOOP;
675 + IFX_REG_W32(reg, PCIE_VC0_RC(pcie_port));
676 +
677 + pcie_port_logic_setup(pcie_port);
678 +}
679 +
680 +static int ifx_pcie_wait_phy_link_up(int pcie_port)
681 +{
682 +#define IFX_PCIE_PHY_LINK_UP_TIMEOUT 1000 /* XXX, tunable */
683 + int i;
684 +
685 + /* Wait for PHY link is up */
686 + for (i = 0; i < IFX_PCIE_PHY_LINK_UP_TIMEOUT; i++) {
687 + if (ifx_pcie_link_up(pcie_port)) {
688 + break;
689 + }
690 + udelay(100);
691 + }
692 + if (i >= IFX_PCIE_PHY_LINK_UP_TIMEOUT) {
693 + printk(KERN_ERR "%s timeout\n", __func__);
694 + return -1;
695 + }
696 +
697 + /* Check data link up or not */
698 + if (!(IFX_REG_R32(PCIE_RC_DR(pcie_port)) & PCIE_RC_DR_DLL_UP)) {
699 + printk(KERN_ERR "%s DLL link is still down\n", __func__);
700 + return -1;
701 + }
702 +
703 + /* Check Data link active or not */
704 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_DLL_ACTIVE)) {
705 + printk(KERN_ERR "%s DLL is not active\n", __func__);
706 + return -1;
707 + }
708 + return 0;
709 +}
710 +
711 +static inline int pcie_app_loigc_setup(int pcie_port)
712 +{
713 + /* supress ahb bus errrors */
714 + IFX_REG_W32(PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS, PCIE_AHB_CTRL(pcie_port));
715 +
716 + /* Pull PCIe EP out of reset */
717 + pcie_device_rst_deassert(pcie_port);
718 +
719 + /* Start LTSSM training between RC and EP */
720 + pcie_ltssm_enable(pcie_port);
721 +
722 + /* Check PHY status after enabling LTSSM */
723 + if (ifx_pcie_wait_phy_link_up(pcie_port) != 0)
724 + return -1;
725 +
726 + return 0;
727 +}
728 +
729 +/*
730 + * The numbers below are directly from the PCIe spec table 3-4/5.
731 + */
732 +static inline void pcie_replay_time_update(int pcie_port)
733 +{
734 + u32 reg;
735 + int nlw;
736 + int rtl;
737 +
738 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
739 +
740 + nlw = MS(reg, PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH);
741 + switch (nlw) {
742 + case PCIE_MAX_LENGTH_WIDTH_X1:
743 + rtl = 1677;
744 + break;
745 + case PCIE_MAX_LENGTH_WIDTH_X2:
746 + rtl = 867;
747 + break;
748 + case PCIE_MAX_LENGTH_WIDTH_X4:
749 + rtl = 462;
750 + break;
751 + case PCIE_MAX_LENGTH_WIDTH_X8:
752 + rtl = 258;
753 + break;
754 + default:
755 + rtl = 1677;
756 + break;
757 + }
758 + reg = IFX_REG_R32(PCIE_ALTRT(pcie_port));
759 + reg &= ~PCIE_ALTRT_REPLAY_TIME_LIMIT;
760 + reg |= SM(rtl, PCIE_ALTRT_REPLAY_TIME_LIMIT);
761 + IFX_REG_W32(reg, PCIE_ALTRT(pcie_port));
762 +}
763 +
764 +/*
765 + * Table 359 Enhanced Configuration Address Mapping1)
766 + * 1) This table is defined in Table 7-1, page 341, PCI Express Base Specification v1.1
767 + * Memory Address PCI Express Configuration Space
768 + * A[(20+n-1):20] Bus Number 1 < n < 8
769 + * A[19:15] Device Number
770 + * A[14:12] Function Number
771 + * A[11:8] Extended Register Number
772 + * A[7:2] Register Number
773 + * A[1:0] Along with size of the access, used to generate Byte Enables
774 + * For VR9, only the address bits [22:0] are mapped to the configuration space:
775 + * . Address bits [22:20] select the target bus (1-of-8)1)
776 + * . Address bits [19:15] select the target device (1-of-32) on the bus
777 + * . Address bits [14:12] select the target function (1-of-8) within the device.
778 + * . Address bits [11:2] selects the target dword (1-of-1024) within the selected function.s configuration space
779 + * . Address bits [1:0] define the start byte location within the selected dword.
780 + */
781 +static inline u32 pcie_bus_addr(u8 bus_num, u16 devfn, int where)
782 +{
783 + u32 addr;
784 + u8 bus;
785 +
786 + if (!bus_num) {
787 + /* type 0 */
788 + addr = ((PCI_SLOT(devfn) & 0x1F) << 15) | ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF)& ~3);
789 + } else {
790 + bus = bus_num;
791 + /* type 1, only support 8 buses */
792 + addr = ((bus & 0x7) << 20) | ((PCI_SLOT(devfn) & 0x1F) << 15) |
793 + ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF) & ~3);
794 + }
795 + return addr;
796 +}
797 +
798 +static int pcie_valid_config(int pcie_port, int bus, int dev)
799 +{
800 + /* RC itself */
801 + if ((bus == 0) && (dev == 0)) {
802 + return 1;
803 + }
804 +
805 + /* No physical link */
806 + if (!ifx_pcie_link_up(pcie_port)) {
807 + return 0;
808 + }
809 +
810 + /* Bus zero only has RC itself
811 + * XXX, check if EP will be integrated
812 + */
813 + if ((bus == 0) && (dev != 0)) {
814 + return 0;
815 + }
816 +
817 + /* Maximum 8 buses supported for VRX */
818 + if (bus > 9) {
819 + return 0;
820 + }
821 +
822 + /*
823 + * PCIe is PtP link, one bus only supports only one device
824 + * except bus zero and PCIe switch which is virtual bus device
825 + * The following two conditions really depends on the system design
826 + * and attached the device.
827 + * XXX, how about more new switch
828 + */
829 + if ((bus == 1) && (dev != 0)) {
830 + return 0;
831 + }
832 +
833 + if ((bus >= 3) && (dev != 0)) {
834 + return 0;
835 + }
836 + return 1;
837 +}
838 +
839 +static inline u32 ifx_pcie_cfg_rd(int pcie_port, u32 reg)
840 +{
841 + return IFX_REG_R32((volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
842 +}
843 +
844 +static inline void ifx_pcie_cfg_wr(int pcie_port, unsigned int reg, u32 val)
845 +{
846 + IFX_REG_W32( val, (volatile u32 *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
847 +}
848 +
849 +static inline u32 ifx_pcie_rc_cfg_rd(int pcie_port, u32 reg)
850 +{
851 + return IFX_REG_R32((volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
852 +}
853 +
854 +static inline void ifx_pcie_rc_cfg_wr(int pcie_port, unsigned int reg, u32 val)
855 +{
856 + IFX_REG_W32(val, (volatile u32 *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
857 +}
858 +
859 +u32 ifx_pcie_bus_enum_read_hack(int where, u32 value)
860 +{
861 + u32 tvalue = value;
862 +
863 + if (where == PCI_PRIMARY_BUS) {
864 + u8 primary, secondary, subordinate;
865 +
866 + primary = tvalue & 0xFF;
867 + secondary = (tvalue >> 8) & 0xFF;
868 + subordinate = (tvalue >> 16) & 0xFF;
869 + primary += pcibios_1st_host_bus_nr();
870 + secondary += pcibios_1st_host_bus_nr();
871 + subordinate += pcibios_1st_host_bus_nr();
872 + tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
873 + }
874 + return tvalue;
875 +}
876 +
877 +u32 ifx_pcie_bus_enum_write_hack(int where, u32 value)
878 +{
879 + u32 tvalue = value;
880 +
881 + if (where == PCI_PRIMARY_BUS) {
882 + u8 primary, secondary, subordinate;
883 +
884 + primary = tvalue & 0xFF;
885 + secondary = (tvalue >> 8) & 0xFF;
886 + subordinate = (tvalue >> 16) & 0xFF;
887 + if (primary > 0 && primary != 0xFF) {
888 + primary -= pcibios_1st_host_bus_nr();
889 + }
890 +
891 + if (secondary > 0 && secondary != 0xFF) {
892 + secondary -= pcibios_1st_host_bus_nr();
893 + }
894 + if (subordinate > 0 && subordinate != 0xFF) {
895 + subordinate -= pcibios_1st_host_bus_nr();
896 + }
897 + tvalue = (tvalue & 0xFF000000) | (u32)primary | (u32)(secondary << 8) | (u32)(subordinate << 16);
898 + }
899 + else if (where == PCI_SUBORDINATE_BUS) {
900 + u8 subordinate = tvalue & 0xFF;
901 +
902 + subordinate = subordinate > 0 ? subordinate - pcibios_1st_host_bus_nr() : 0;
903 + tvalue = subordinate;
904 + }
905 + return tvalue;
906 +}
907 +
908 +static int ifx_pcie_read_config(struct pci_bus *bus, u32 devfn,
909 + int where, int size, u32 *value)
910 +{
911 + u32 data = 0;
912 + int bus_number = bus->number;
913 + static const u32 mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
914 + int ret = PCIBIOS_SUCCESSFUL;
915 + struct ifx_pci_controller *ctrl = bus->sysdata;
916 + int pcie_port = ctrl->port;
917 +
918 + if (unlikely(size != 1 && size != 2 && size != 4)){
919 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
920 + goto out;
921 + }
922 +
923 + /* Make sure the address is aligned to natural boundary */
924 + if (unlikely(((size - 1) & where))) {
925 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
926 + goto out;
927 + }
928 +
929 + /*
930 + * If we are second controller, we have to cheat OS so that it assume
931 + * its bus number starts from 0 in host controller
932 + */
933 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
934 +
935 + /*
936 + * We need to force the bus number to be zero on the root
937 + * bus. Linux numbers the 2nd root bus to start after all
938 + * busses on root 0.
939 + */
940 + if (bus->parent == NULL) {
941 + bus_number = 0;
942 + }
943 +
944 + /*
945 + * PCIe only has a single device connected to it. It is
946 + * always device ID 0. Don't bother doing reads for other
947 + * device IDs on the first segment.
948 + */
949 + if ((bus_number == 0) && (PCI_SLOT(devfn) != 0)) {
950 + ret = PCIBIOS_FUNC_NOT_SUPPORTED;
951 + goto out;
952 + }
953 +
954 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
955 + *value = 0xffffffff;
956 + ret = PCIBIOS_DEVICE_NOT_FOUND;
957 + goto out;
958 + }
959 +
960 + PCIE_IRQ_LOCK(ifx_pcie_lock);
961 + if (bus_number == 0) { /* RC itself */
962 + u32 t;
963 +
964 + t = (where & ~3);
965 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
966 + } else {
967 + u32 addr = pcie_bus_addr(bus_number, devfn, where);
968 +
969 + data = ifx_pcie_cfg_rd(pcie_port, addr);
970 + #ifdef CONFIG_IFX_PCIE_HW_SWAP
971 + data = le32_to_cpu(data);
972 + #endif /* CONFIG_IFX_PCIE_HW_SWAP */
973 + }
974 + /* To get a correct PCI topology, we have to restore the bus number to OS */
975 + data = ifx_pcie_bus_enum_hack(bus, devfn, where, data, pcie_port, 1);
976 +
977 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
978 +
979 + *value = (data >> (8 * (where & 3))) & mask[size & 7];
980 +out:
981 + return ret;
982 +}
983 +
984 +static u32 ifx_pcie_size_to_value(int where, int size, u32 data, u32 value)
985 +{
986 + u32 shift;
987 + u32 tdata = data;
988 +
989 + switch (size) {
990 + case 1:
991 + shift = (where & 0x3) << 3;
992 + tdata &= ~(0xffU << shift);
993 + tdata |= ((value & 0xffU) << shift);
994 + break;
995 + case 2:
996 + shift = (where & 3) << 3;
997 + tdata &= ~(0xffffU << shift);
998 + tdata |= ((value & 0xffffU) << shift);
999 + break;
1000 + case 4:
1001 + tdata = value;
1002 + break;
1003 + }
1004 + return tdata;
1005 +}
1006 +
1007 +static int ifx_pcie_write_config(struct pci_bus *bus, u32 devfn,
1008 + int where, int size, u32 value)
1009 +{
1010 + int bus_number = bus->number;
1011 + int ret = PCIBIOS_SUCCESSFUL;
1012 + struct ifx_pci_controller *ctrl = bus->sysdata;
1013 + int pcie_port = ctrl->port;
1014 + u32 tvalue = value;
1015 + u32 data;
1016 +
1017 + /* Make sure the address is aligned to natural boundary */
1018 + if (unlikely(((size - 1) & where))) {
1019 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
1020 + goto out;
1021 + }
1022 + /*
1023 + * If we are second controller, we have to cheat OS so that it assume
1024 + * its bus number starts from 0 in host controller
1025 + */
1026 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
1027 +
1028 + /*
1029 + * We need to force the bus number to be zero on the root
1030 + * bus. Linux numbers the 2nd root bus to start after all
1031 + * busses on root 0.
1032 + */
1033 + if (bus->parent == NULL) {
1034 + bus_number = 0;
1035 + }
1036 +
1037 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1038 + ret = PCIBIOS_DEVICE_NOT_FOUND;
1039 + goto out;
1040 + }
1041 +
1042 + /* XXX, some PCIe device may need some delay */
1043 + PCIE_IRQ_LOCK(ifx_pcie_lock);
1044 +
1045 + /*
1046 + * To configure the correct bus topology using native way, we have to cheat Os so that
1047 + * it can configure the PCIe hardware correctly.
1048 + */
1049 + tvalue = ifx_pcie_bus_enum_hack(bus, devfn, where, value, pcie_port, 0);
1050 +
1051 + if (bus_number == 0) { /* RC itself */
1052 + u32 t;
1053 +
1054 + t = (where & ~3);
1055 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1056 +
1057 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1058 +
1059 + ifx_pcie_rc_cfg_wr(pcie_port, t, data);
1060 + } else {
1061 + u32 addr = pcie_bus_addr(bus_number, devfn, where);
1062 +
1063 + data = ifx_pcie_cfg_rd(pcie_port, addr);
1064 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1065 + data = le32_to_cpu(data);
1066 +#endif
1067 +
1068 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1069 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1070 + data = cpu_to_le32(data);
1071 +#endif
1072 + ifx_pcie_cfg_wr(pcie_port, addr, data);
1073 + }
1074 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1075 +out:
1076 + return ret;
1077 +}
1078 +
1079 +static struct resource ifx_pcie_io_resource = {
1080 + .name = "PCIe0 I/O space",
1081 + .start = PCIE_IO_PHY_BASE,
1082 + .end = PCIE_IO_PHY_END,
1083 + .flags = IORESOURCE_IO,
1084 +};
1085 +
1086 +static struct resource ifx_pcie_mem_resource = {
1087 + .name = "PCIe0 Memory space",
1088 + .start = PCIE_MEM_PHY_BASE,
1089 + .end = PCIE_MEM_PHY_END,
1090 + .flags = IORESOURCE_MEM,
1091 +};
1092 +
1093 +static struct pci_ops ifx_pcie_ops = {
1094 + .read = ifx_pcie_read_config,
1095 + .write = ifx_pcie_write_config,
1096 +};
1097 +
1098 +static struct ifx_pci_controller ifx_pcie_controller[IFX_PCIE_CORE_NR] = {
1099 + {
1100 + .pcic = {
1101 + .pci_ops = &ifx_pcie_ops,
1102 + .mem_resource = &ifx_pcie_mem_resource,
1103 + .io_resource = &ifx_pcie_io_resource,
1104 + },
1105 + .port = IFX_PCIE_PORT0,
1106 + },
1107 +};
1108 +
1109 +#ifdef IFX_PCIE_ERROR_INT
1110 +
1111 +static irqreturn_t pcie_rc_core_isr(int irq, void *dev_id)
1112 +{
1113 + struct ifx_pci_controller *ctrl = (struct ifx_pci_controller *)dev_id;
1114 + int pcie_port = ctrl->port;
1115 + u32 reg;
1116 +
1117 + printk("PCIe RC error intr %d\n", irq);
1118 + reg = IFX_REG_R32(PCIE_IRNCR(pcie_port));
1119 + reg &= PCIE_RC_CORE_COMBINED_INT;
1120 + IFX_REG_W32(reg, PCIE_IRNCR(pcie_port));
1121 +
1122 + return IRQ_HANDLED;
1123 +}
1124 +
1125 +static int
1126 +pcie_rc_core_int_init(int pcie_port)
1127 +{
1128 + int ret;
1129 +
1130 + /* Enable core interrupt */
1131 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNEN(pcie_port));
1132 +
1133 + /* Clear it first */
1134 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNCR(pcie_port));
1135 + ret = request_irq(pcie_irqs[pcie_port].ir_irq.irq, pcie_rc_core_isr, 0,
1136 + pcie_irqs[pcie_port].ir_irq.name, &ifx_pcie_controller[pcie_port]);
1137 + if (ret)
1138 + printk(KERN_ERR "%s request irq %d failed\n", __func__, IFX_PCIE_IR);
1139 +
1140 + return ret;
1141 +}
1142 +#endif
1143 +
1144 +int ifx_pcie_bios_map_irq(IFX_PCI_CONST struct pci_dev *dev, u8 slot, u8 pin)
1145 +{
1146 + u32 irq_bit = 0;
1147 + int irq = 0;
1148 + struct ifx_pci_controller *ctrl = dev->bus->sysdata;
1149 + int pcie_port = ctrl->port;
1150 +
1151 + printk("%s port %d dev %s slot %d pin %d \n", __func__, pcie_port, pci_name(dev), slot, pin);
1152 +
1153 + if ((pin == PCIE_LEGACY_DISABLE) || (pin > PCIE_LEGACY_INT_MAX)) {
1154 + printk(KERN_WARNING "WARNING: dev %s: invalid interrupt pin %d\n", pci_name(dev), pin);
1155 + return -1;
1156 + }
1157 +
1158 + /* Pin index so minus one */
1159 + irq_bit = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq_bit;
1160 + irq = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq;
1161 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNEN(pcie_port));
1162 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNCR(pcie_port));
1163 + printk("%s dev %s irq %d assigned\n", __func__, pci_name(dev), irq);
1164 + return irq;
1165 +}
1166 +
1167 +int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1168 +{
1169 + u16 config;
1170 +#ifdef IFX_PCIE_ERROR_INT
1171 + u32 dconfig;
1172 + int pos;
1173 +#endif
1174 +
1175 + /* Enable reporting System errors and parity errors on all devices */
1176 + /* Enable parity checking and error reporting */
1177 + pci_read_config_word(dev, PCI_COMMAND, &config);
1178 + config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR /*| PCI_COMMAND_INVALIDATE |
1179 + PCI_COMMAND_FAST_BACK*/;
1180 + pci_write_config_word(dev, PCI_COMMAND, config);
1181 +
1182 + if (dev->subordinate) {
1183 + /* Set latency timers on sub bridges */
1184 + pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 0x40); /* XXX, */
1185 + /* More bridge error detection */
1186 + pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
1187 + config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
1188 + pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
1189 + }
1190 +#ifdef IFX_PCIE_ERROR_INT
1191 + /* Enable the PCIe normal error reporting */
1192 + pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1193 + if (pos) {
1194 +
1195 + /* Disable system error generation in response to error messages */
1196 + pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &config);
1197 + config &= ~(PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE | PCI_EXP_RTCTL_SEFEE);
1198 + pci_write_config_word(dev, pos + PCI_EXP_RTCTL, config);
1199 +
1200 + /* Clear PCIE Capability's Device Status */
1201 + pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &config);
1202 + pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, config);
1203 +
1204 + /* Update Device Control */
1205 + pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
1206 + /* Correctable Error Reporting */
1207 + config |= PCI_EXP_DEVCTL_CERE;
1208 + /* Non-Fatal Error Reporting */
1209 + config |= PCI_EXP_DEVCTL_NFERE;
1210 + /* Fatal Error Reporting */
1211 + config |= PCI_EXP_DEVCTL_FERE;
1212 + /* Unsupported Request */
1213 + config |= PCI_EXP_DEVCTL_URRE;
1214 + pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
1215 + }
1216 +
1217 + /* Find the Advanced Error Reporting capability */
1218 + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
1219 + if (pos) {
1220 + /* Clear Uncorrectable Error Status */
1221 + pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &dconfig);
1222 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, dconfig);
1223 + /* Enable reporting of all uncorrectable errors */
1224 + /* Uncorrectable Error Mask - turned on bits disable errors */
1225 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
1226 + /*
1227 + * Leave severity at HW default. This only controls if
1228 + * errors are reported as uncorrectable or
1229 + * correctable, not if the error is reported.
1230 + */
1231 + /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
1232 + /* Clear Correctable Error Status */
1233 + pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
1234 + pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
1235 + /* Enable reporting of all correctable errors */
1236 + /* Correctable Error Mask - turned on bits disable errors */
1237 + pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
1238 + /* Advanced Error Capabilities */
1239 + pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
1240 + /* ECRC Generation Enable */
1241 + if (dconfig & PCI_ERR_CAP_ECRC_GENC) {
1242 + dconfig |= PCI_ERR_CAP_ECRC_GENE;
1243 + }
1244 + /* ECRC Check Enable */
1245 + if (dconfig & PCI_ERR_CAP_ECRC_CHKC) {
1246 + dconfig |= PCI_ERR_CAP_ECRC_CHKE;
1247 + }
1248 + pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
1249 +
1250 + /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
1251 + /* Enable Root Port's interrupt in response to error messages */
1252 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
1253 + PCI_ERR_ROOT_CMD_COR_EN |
1254 + PCI_ERR_ROOT_CMD_NONFATAL_EN |
1255 + PCI_ERR_ROOT_CMD_FATAL_EN);
1256 + /* Clear the Root status register */
1257 + pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
1258 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
1259 + }
1260 +#endif /* IFX_PCIE_ERROR_INT */
1261 + /* WAR, only 128 MRRS is supported, force all EPs to support this value */
1262 + pcie_set_readrq(dev, 128);
1263 + return 0;
1264 +}
1265 +
1266 +static int
1267 +pcie_rc_initialize(int pcie_port)
1268 +{
1269 + int i;
1270 +#define IFX_PCIE_PHY_LOOP_CNT 5
1271 +
1272 + pcie_rcu_endian_setup(pcie_port);
1273 +
1274 + pcie_ep_gpio_rst_init(pcie_port);
1275 +
1276 + /*
1277 + * XXX, PCIe elastic buffer bug will cause not to be detected. One more
1278 + * reset PCIe PHY will solve this issue
1279 + */
1280 + for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
1281 + /* Disable PCIe PHY Analog part for sanity check */
1282 + pcie_phy_pmu_disable(pcie_port);
1283 +
1284 + pcie_phy_rst_assert(pcie_port);
1285 + pcie_phy_rst_deassert(pcie_port);
1286 +
1287 + /* Make sure PHY PLL is stable */
1288 + udelay(20);
1289 +
1290 + /* PCIe Core reset enabled, low active, sw programmed */
1291 + pcie_core_rst_assert(pcie_port);
1292 +
1293 + /* Put PCIe EP in reset status */
1294 + pcie_device_rst_assert(pcie_port);
1295 +
1296 + /* PCI PHY & Core reset disabled, high active, sw programmed */
1297 + pcie_core_rst_deassert(pcie_port);
1298 +
1299 + /* Already in a quiet state, program PLL, enable PHY, check ready bit */
1300 + pcie_phy_clock_mode_setup(pcie_port);
1301 +
1302 + /* Enable PCIe PHY and Clock */
1303 + pcie_core_pmu_setup(pcie_port);
1304 +
1305 + /* Clear status registers */
1306 + pcie_status_register_clear(pcie_port);
1307 +
1308 +#ifdef CONFIG_PCI_MSI
1309 + pcie_msi_init(pcie_port);
1310 +#endif /* CONFIG_PCI_MSI */
1311 + pcie_rc_cfg_reg_setup(pcie_port);
1312 +
1313 + /* Once link is up, break out */
1314 + if (pcie_app_loigc_setup(pcie_port) == 0)
1315 + break;
1316 + }
1317 + if (i >= IFX_PCIE_PHY_LOOP_CNT) {
1318 + printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
1319 + return -EIO;
1320 + }
1321 + /* NB, don't increase ACK/NACK timer timeout value, which will cause a lot of COR errors */
1322 + pcie_replay_time_update(pcie_port);
1323 + return 0;
1324 +}
1325 +
1326 +extern int (*ltq_pci_plat_arch_init)(struct pci_dev *dev);
1327 +extern int (*ltq_pci_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
1328 +
1329 +static int __init ifx_pcie_bios_init(void)
1330 +{
1331 + void __iomem *io_map_base;
1332 + int pcie_port;
1333 + int startup_port;
1334 +
1335 +
1336 + ltq_pci_map_irq = ifx_pcie_bios_map_irq;
1337 + ltq_pci_plat_arch_init = ifx_pcie_bios_plat_dev_init;
1338 +
1339 + /* Enable AHB Master/ Slave */
1340 + pcie_ahb_pmu_setup();
1341 +
1342 + startup_port = IFX_PCIE_PORT0;
1343 +
1344 + for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
1345 + if (pcie_rc_initialize(pcie_port) == 0) {
1346 + IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: ifx_pcie_cfg_base 0x%p\n",
1347 + __func__, PCIE_CFG_PORT_TO_BASE(pcie_port));
1348 + /* Otherwise, warning will pop up */
1349 + io_map_base = ioremap(PCIE_IO_PHY_PORT_TO_BASE(pcie_port), PCIE_IO_SIZE);
1350 + if (io_map_base == NULL) {
1351 + IFX_PCIE_PRINT(PCIE_MSG_ERR, "%s io space ioremap failed\n", __func__);
1352 + return -ENOMEM;
1353 + }
1354 + ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
1355 +
1356 + register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
1357 + /* XXX, clear error status */
1358 +
1359 + IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s: mem_resource 0x%p, io_resource 0x%p\n",
1360 + __func__, &ifx_pcie_controller[pcie_port].pcic.mem_resource,
1361 + &ifx_pcie_controller[pcie_port].pcic.io_resource);
1362 +
1363 + #ifdef IFX_PCIE_ERROR_INT
1364 + pcie_rc_core_int_init(pcie_port);
1365 + #endif /* IFX_PCIE_ERROR_INT */
1366 + }
1367 + }
1368 +
1369 + return 0;
1370 +}
1371 +arch_initcall(ifx_pcie_bios_init);
1372 +
1373 +MODULE_LICENSE("GPL");
1374 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
1375 +MODULE_SUPPORTED_DEVICE("Infineon builtin PCIe RC module");
1376 +MODULE_DESCRIPTION("Infineon builtin PCIe RC driver");
1377 +
1378 diff --git a/arch/mips/pci/ifxmips_pcie.h b/arch/mips/pci/ifxmips_pcie.h
1379 new file mode 100644
1380 index 0000000..c6f92f5
1381 --- /dev/null
1382 +++ b/arch/mips/pci/ifxmips_pcie.h
1383 @@ -0,0 +1,135 @@
1384 +/******************************************************************************
1385 +**
1386 +** FILE NAME : ifxmips_pcie.h
1387 +** PROJECT : IFX UEIP for VRX200
1388 +** MODULES : PCIe module
1389 +**
1390 +** DATE : 02 Mar 2009
1391 +** AUTHOR : Lei Chuanhua
1392 +** DESCRIPTION : PCIe Root Complex Driver
1393 +** COPYRIGHT : Copyright (c) 2009
1394 +** Infineon Technologies AG
1395 +** Am Campeon 1-12, 85579 Neubiberg, Germany
1396 +**
1397 +** This program is free software; you can redistribute it and/or modify
1398 +** it under the terms of the GNU General Public License as published by
1399 +** the Free Software Foundation; either version 2 of the License, or
1400 +** (at your option) any later version.
1401 +** HISTORY
1402 +** $Version $Date $Author $Comment
1403 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
1404 +*******************************************************************************/
1405 +#ifndef IFXMIPS_PCIE_H
1406 +#define IFXMIPS_PCIE_H
1407 +#include <linux/version.h>
1408 +#include <linux/types.h>
1409 +#include <linux/pci.h>
1410 +#include <linux/interrupt.h>
1411 +#include "ifxmips_pci_common.h"
1412 +#include "ifxmips_pcie_reg.h"
1413 +
1414 +/*!
1415 + \defgroup IFX_PCIE PCI Express bus driver module
1416 + \brief PCI Express IP module support VRX200
1417 +*/
1418 +
1419 +/*!
1420 + \defgroup IFX_PCIE_OS OS APIs
1421 + \ingroup IFX_PCIE
1422 + \brief PCIe bus driver OS interface functions
1423 +*/
1424 +
1425 +/*!
1426 + \file ifxmips_pcie.h
1427 + \ingroup IFX_PCIE
1428 + \brief header file for PCIe module common header file
1429 +*/
1430 +#define PCIE_IRQ_LOCK(lock) do { \
1431 + unsigned long flags; \
1432 + spin_lock_irqsave(&(lock), flags);
1433 +#define PCIE_IRQ_UNLOCK(lock) \
1434 + spin_unlock_irqrestore(&(lock), flags); \
1435 +} while (0)
1436 +
1437 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
1438 +#define IRQF_SHARED SA_SHIRQ
1439 +#endif
1440 +
1441 +#define PCIE_MSG_MSI 0x00000001
1442 +#define PCIE_MSG_ISR 0x00000002
1443 +#define PCIE_MSG_FIXUP 0x00000004
1444 +#define PCIE_MSG_READ_CFG 0x00000008
1445 +#define PCIE_MSG_WRITE_CFG 0x00000010
1446 +#define PCIE_MSG_CFG (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
1447 +#define PCIE_MSG_REG 0x00000020
1448 +#define PCIE_MSG_INIT 0x00000040
1449 +#define PCIE_MSG_ERR 0x00000080
1450 +#define PCIE_MSG_PHY 0x00000100
1451 +#define PCIE_MSG_ANY 0x000001ff
1452 +
1453 +#define IFX_PCIE_PORT0 0
1454 +#define IFX_PCIE_PORT1 1
1455 +
1456 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1457 +#define IFX_PCIE_CORE_NR 2
1458 +#else
1459 +#define IFX_PCIE_CORE_NR 1
1460 +#endif
1461 +
1462 +#define IFX_PCIE_ERROR_INT
1463 +
1464 +//#define IFX_PCIE_DBG
1465 +
1466 +#if defined(IFX_PCIE_DBG)
1467 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do { \
1468 + ifx_pcie_debug((_fmt), ##args); \
1469 +} while (0)
1470 +
1471 +#define INLINE
1472 +#else
1473 +#define IFX_PCIE_PRINT(_m, _fmt, args...) \
1474 + do {} while(0)
1475 +#define INLINE inline
1476 +#endif
1477 +
1478 +struct ifx_pci_controller {
1479 + struct pci_controller pcic;
1480 +
1481 + /* RC specific, per host bus information */
1482 + u32 port; /* Port index, 0 -- 1st core, 1 -- 2nd core */
1483 +};
1484 +
1485 +typedef struct ifx_pcie_ir_irq {
1486 + const unsigned int irq;
1487 + const char name[16];
1488 +}ifx_pcie_ir_irq_t;
1489 +
1490 +typedef struct ifx_pcie_legacy_irq{
1491 + const u32 irq_bit;
1492 + const int irq;
1493 +}ifx_pcie_legacy_irq_t;
1494 +
1495 +typedef struct ifx_pcie_irq {
1496 + ifx_pcie_ir_irq_t ir_irq;
1497 + ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
1498 +}ifx_pcie_irq_t;
1499 +
1500 +extern u32 g_pcie_debug_flag;
1501 +extern void ifx_pcie_debug(const char *fmt, ...);
1502 +extern void pcie_phy_clock_mode_setup(int pcie_port);
1503 +extern void pcie_msi_pic_init(int pcie_port);
1504 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
1505 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
1506 +
1507 +#define CONFIG_VR9
1508 +
1509 +#ifdef CONFIG_VR9
1510 +#include "ifxmips_pcie_vr9.h"
1511 +#elif defined (CONFIG_AR10)
1512 +#include "ifxmips_pcie_ar10.h"
1513 +#else
1514 +#error "PCIE: platform not defined"
1515 +#endif /* CONFIG_VR9 */
1516 +
1517 +#endif /* IFXMIPS_PCIE_H */
1518 +
1519 diff --git a/arch/mips/pci/ifxmips_pcie_ar10.h b/arch/mips/pci/ifxmips_pcie_ar10.h
1520 new file mode 100644
1521 index 0000000..99ff463
1522 --- /dev/null
1523 +++ b/arch/mips/pci/ifxmips_pcie_ar10.h
1524 @@ -0,0 +1,290 @@
1525 +/****************************************************************************
1526 + Copyright (c) 2010
1527 + Lantiq Deutschland GmbH
1528 + Am Campeon 3; 85579 Neubiberg, Germany
1529 +
1530 + For licensing information, see the file 'LICENSE' in the root folder of
1531 + this software module.
1532 +
1533 + *****************************************************************************/
1534 +/*!
1535 + \file ifxmips_pcie_ar10.h
1536 + \ingroup IFX_PCIE
1537 + \brief PCIe RC driver ar10 specific file
1538 +*/
1539 +
1540 +#ifndef IFXMIPS_PCIE_AR10_H
1541 +#define IFXMIPS_PCIE_AR10_H
1542 +#ifndef AUTOCONF_INCLUDED
1543 +#include <linux/config.h>
1544 +#endif /* AUTOCONF_INCLUDED */
1545 +#include <linux/types.h>
1546 +#include <linux/delay.h>
1547 +
1548 +/* Project header file */
1549 +#include <asm/ifx/ifx_types.h>
1550 +#include <asm/ifx/ifx_pmu.h>
1551 +#include <asm/ifx/ifx_gpio.h>
1552 +#include <asm/ifx/ifx_ebu_led.h>
1553 +
1554 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
1555 +{
1556 + ifx_ebu_led_enable();
1557 + if (pcie_port == 0) {
1558 + ifx_ebu_led_set_data(11, 1);
1559 + }
1560 + else {
1561 + ifx_ebu_led_set_data(12, 1);
1562 + }
1563 +}
1564 +
1565 +static inline void pcie_ahb_pmu_setup(void)
1566 +{
1567 + /* XXX, moved to CGU to control AHBM */
1568 +}
1569 +
1570 +static inline void pcie_rcu_endian_setup(int pcie_port)
1571 +{
1572 + u32 reg;
1573 +
1574 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
1575 + /* Inbound, big endian */
1576 + reg |= IFX_RCU_BE_AHB4S;
1577 + if (pcie_port == 0) {
1578 + reg |= IFX_RCU_BE_PCIE0M;
1579 +
1580 + #ifdef CONFIG_IFX_PCIE_HW_SWAP
1581 + /* Outbound, software swap needed */
1582 + reg |= IFX_RCU_BE_AHB3M;
1583 + reg &= ~IFX_RCU_BE_PCIE0S;
1584 + #else
1585 + /* Outbound little endian */
1586 + reg &= ~IFX_RCU_BE_AHB3M;
1587 + reg &= ~IFX_RCU_BE_PCIE0S;
1588 + #endif
1589 + }
1590 + else {
1591 + reg |= IFX_RCU_BE_PCIE1M;
1592 + #ifdef CONFIG_IFX_PCIE1_HW_SWAP
1593 + /* Outbound, software swap needed */
1594 + reg |= IFX_RCU_BE_AHB3M;
1595 + reg &= ~IFX_RCU_BE_PCIE1S;
1596 + #else
1597 + /* Outbound little endian */
1598 + reg &= ~IFX_RCU_BE_AHB3M;
1599 + reg &= ~IFX_RCU_BE_PCIE1S;
1600 + #endif
1601 + }
1602 +
1603 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
1604 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
1605 +}
1606 +
1607 +static inline void pcie_phy_pmu_enable(int pcie_port)
1608 +{
1609 + if (pcie_port == 0) { /* XXX, should use macro*/
1610 + PCIE0_PHY_PMU_SETUP(IFX_PMU_ENABLE);
1611 + }
1612 + else {
1613 + PCIE1_PHY_PMU_SETUP(IFX_PMU_ENABLE);
1614 + }
1615 +}
1616 +
1617 +static inline void pcie_phy_pmu_disable(int pcie_port)
1618 +{
1619 + if (pcie_port == 0) { /* XXX, should use macro*/
1620 + PCIE0_PHY_PMU_SETUP(IFX_PMU_DISABLE);
1621 + }
1622 + else {
1623 + PCIE1_PHY_PMU_SETUP(IFX_PMU_DISABLE);
1624 + }
1625 +}
1626 +
1627 +static inline void pcie_pdi_big_endian(int pcie_port)
1628 +{
1629 + u32 reg;
1630 +
1631 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
1632 + if (pcie_port == 0) {
1633 + /* Config AHB->PCIe and PDI endianness */
1634 + reg |= IFX_RCU_BE_PCIE0_PDI;
1635 + }
1636 + else {
1637 + /* Config AHB->PCIe and PDI endianness */
1638 + reg |= IFX_RCU_BE_PCIE1_PDI;
1639 + }
1640 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
1641 +}
1642 +
1643 +static inline void pcie_pdi_pmu_enable(int pcie_port)
1644 +{
1645 + if (pcie_port == 0) {
1646 + /* Enable PDI to access PCIe PHY register */
1647 + PDI0_PMU_SETUP(IFX_PMU_ENABLE);
1648 + }
1649 + else {
1650 + PDI1_PMU_SETUP(IFX_PMU_ENABLE);
1651 + }
1652 +}
1653 +
1654 +static inline void pcie_core_rst_assert(int pcie_port)
1655 +{
1656 + u32 reg;
1657 +
1658 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1659 +
1660 + /* Reset Core, bit 22 */
1661 + if (pcie_port == 0) {
1662 + reg |= 0x00400000;
1663 + }
1664 + else {
1665 + reg |= 0x08000000; /* Bit 27 */
1666 + }
1667 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1668 +}
1669 +
1670 +static inline void pcie_core_rst_deassert(int pcie_port)
1671 +{
1672 + u32 reg;
1673 +
1674 + /* Make sure one micro-second delay */
1675 + udelay(1);
1676 +
1677 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1678 + if (pcie_port == 0) {
1679 + reg &= ~0x00400000; /* bit 22 */
1680 + }
1681 + else {
1682 + reg &= ~0x08000000; /* Bit 27 */
1683 + }
1684 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1685 +}
1686 +
1687 +static inline void pcie_phy_rst_assert(int pcie_port)
1688 +{
1689 + u32 reg;
1690 +
1691 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1692 + if (pcie_port == 0) {
1693 + reg |= 0x00001000; /* Bit 12 */
1694 + }
1695 + else {
1696 + reg |= 0x00002000; /* Bit 13 */
1697 + }
1698 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1699 +}
1700 +
1701 +static inline void pcie_phy_rst_deassert(int pcie_port)
1702 +{
1703 + u32 reg;
1704 +
1705 + /* Make sure one micro-second delay */
1706 + udelay(1);
1707 +
1708 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
1709 + if (pcie_port == 0) {
1710 + reg &= ~0x00001000; /* Bit 12 */
1711 + }
1712 + else {
1713 + reg &= ~0x00002000; /* Bit 13 */
1714 + }
1715 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
1716 +}
1717 +
1718 +static inline void pcie_device_rst_assert(int pcie_port)
1719 +{
1720 + if (pcie_port == 0) {
1721 + ifx_ebu_led_set_data(11, 0);
1722 + }
1723 + else {
1724 + ifx_ebu_led_set_data(12, 0);
1725 + }
1726 +}
1727 +
1728 +static inline void pcie_device_rst_deassert(int pcie_port)
1729 +{
1730 + mdelay(100);
1731 + if (pcie_port == 0) {
1732 + ifx_ebu_led_set_data(11, 1);
1733 + }
1734 + else {
1735 + ifx_ebu_led_set_data(12, 1);
1736 + }
1737 + ifx_ebu_led_disable();
1738 +}
1739 +
1740 +static inline void pcie_core_pmu_setup(int pcie_port)
1741 +{
1742 + if (pcie_port == 0) {
1743 + PCIE0_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
1744 + }
1745 + else {
1746 + PCIE1_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
1747 + }
1748 +}
1749 +
1750 +static inline void pcie_msi_init(int pcie_port)
1751 +{
1752 + pcie_msi_pic_init(pcie_port);
1753 + if (pcie_port == 0) {
1754 + MSI0_PMU_SETUP(IFX_PMU_ENABLE);
1755 + }
1756 + else {
1757 + MSI1_PMU_SETUP(IFX_PMU_ENABLE);
1758 + }
1759 +}
1760 +
1761 +static inline u32
1762 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
1763 +{
1764 + u32 tbus_number = bus_number;
1765 +
1766 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1767 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1768 + if (pcibios_host_nr() > 1) {
1769 + tbus_number -= pcibios_1st_host_bus_nr();
1770 + }
1771 + }
1772 +#endif /* CONFIG_IFX_PCI */
1773 + return tbus_number;
1774 +}
1775 +
1776 +static inline u32
1777 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
1778 +{
1779 + struct pci_dev *pdev;
1780 + u32 tvalue = value;
1781 +
1782 + /* Sanity check */
1783 + pdev = pci_get_slot(bus, devfn);
1784 + if (pdev == NULL) {
1785 + return tvalue;
1786 + }
1787 +
1788 + /* Only care about PCI bridge */
1789 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
1790 + return tvalue;
1791 + }
1792 +
1793 + if (read) { /* Read hack */
1794 + #ifdef CONFIG_IFX_PCIE_2ND_CORE
1795 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1796 + if (pcibios_host_nr() > 1) {
1797 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
1798 + }
1799 + }
1800 + #endif /* CONFIG_IFX_PCIE_2ND_CORE */
1801 + }
1802 + else { /* Write hack */
1803 + #ifdef CONFIG_IFX_PCIE_2ND_CORE
1804 + if (pcie_port == IFX_PCIE_PORT1) { /* Port 1 must check if there are two cores enabled */
1805 + if (pcibios_host_nr() > 1) {
1806 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
1807 + }
1808 + }
1809 + #endif
1810 + }
1811 + return tvalue;
1812 +}
1813 +
1814 +#endif /* IFXMIPS_PCIE_AR10_H */
1815 diff --git a/arch/mips/pci/ifxmips_pcie_msi.c b/arch/mips/pci/ifxmips_pcie_msi.c
1816 new file mode 100644
1817 index 0000000..bffd6fa
1818 --- /dev/null
1819 +++ b/arch/mips/pci/ifxmips_pcie_msi.c
1820 @@ -0,0 +1,392 @@
1821 +/******************************************************************************
1822 +**
1823 +** FILE NAME : ifxmips_pcie_msi.c
1824 +** PROJECT : IFX UEIP for VRX200
1825 +** MODULES : PCI MSI sub module
1826 +**
1827 +** DATE : 02 Mar 2009
1828 +** AUTHOR : Lei Chuanhua
1829 +** DESCRIPTION : PCIe MSI Driver
1830 +** COPYRIGHT : Copyright (c) 2009
1831 +** Infineon Technologies AG
1832 +** Am Campeon 1-12, 85579 Neubiberg, Germany
1833 +**
1834 +** This program is free software; you can redistribute it and/or modify
1835 +** it under the terms of the GNU General Public License as published by
1836 +** the Free Software Foundation; either version 2 of the License, or
1837 +** (at your option) any later version.
1838 +** HISTORY
1839 +** $Date $Author $Comment
1840 +** 02 Mar,2009 Lei Chuanhua Initial version
1841 +*******************************************************************************/
1842 +/*!
1843 + \defgroup IFX_PCIE_MSI MSI OS APIs
1844 + \ingroup IFX_PCIE
1845 + \brief PCIe bus driver OS interface functions
1846 +*/
1847 +
1848 +/*!
1849 + \file ifxmips_pcie_msi.c
1850 + \ingroup IFX_PCIE
1851 + \brief PCIe MSI OS interface file
1852 +*/
1853 +
1854 +#ifndef AUTOCONF_INCLUDED
1855 +#include <linux/config.h>
1856 +#endif /* AUTOCONF_INCLUDED */
1857 +#include <linux/init.h>
1858 +#include <linux/sched.h>
1859 +#include <linux/slab.h>
1860 +#include <linux/interrupt.h>
1861 +#include <linux/kernel_stat.h>
1862 +#include <linux/pci.h>
1863 +#include <linux/msi.h>
1864 +#include <linux/module.h>
1865 +#include <asm/bootinfo.h>
1866 +#include <asm/irq.h>
1867 +#include <asm/traps.h>
1868 +
1869 +#include <asm/ifx/ifx_types.h>
1870 +#include <asm/ifx/ifx_regs.h>
1871 +#include <asm/ifx/common_routines.h>
1872 +#include <asm/ifx/irq.h>
1873 +
1874 +#include "ifxmips_pcie_reg.h"
1875 +#include "ifxmips_pcie.h"
1876 +
1877 +#define IFX_MSI_IRQ_NUM 16
1878 +
1879 +enum {
1880 + IFX_PCIE_MSI_IDX0 = 0,
1881 + IFX_PCIE_MSI_IDX1,
1882 + IFX_PCIE_MSI_IDX2,
1883 + IFX_PCIE_MSI_IDX3,
1884 +};
1885 +
1886 +typedef struct ifx_msi_irq_idx {
1887 + const int irq;
1888 + const int idx;
1889 +}ifx_msi_irq_idx_t;
1890 +
1891 +struct ifx_msi_pic {
1892 + volatile u32 pic_table[IFX_MSI_IRQ_NUM];
1893 + volatile u32 pic_endian; /* 0x40 */
1894 +};
1895 +typedef struct ifx_msi_pic *ifx_msi_pic_t;
1896 +
1897 +typedef struct ifx_msi_irq {
1898 + const volatile ifx_msi_pic_t msi_pic_p;
1899 + const u32 msi_phy_base;
1900 + const ifx_msi_irq_idx_t msi_irq_idx[IFX_MSI_IRQ_NUM];
1901 + /*
1902 + * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is
1903 + * in use.
1904 + */
1905 + u16 msi_free_irq_bitmask;
1906 +
1907 + /*
1908 + * Each bit in msi_multiple_irq_bitmask tells that the device using
1909 + * this bit in msi_free_irq_bitmask is also using the next bit. This
1910 + * is used so we can disable all of the MSI interrupts when a device
1911 + * uses multiple.
1912 + */
1913 + u16 msi_multiple_irq_bitmask;
1914 +}ifx_msi_irq_t;
1915 +
1916 +static ifx_msi_irq_t msi_irqs[IFX_PCIE_CORE_NR] = {
1917 + {
1918 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI_PIC_REG_BASE,
1919 + .msi_phy_base = PCIE_MSI_PHY_BASE,
1920 + .msi_irq_idx = {
1921 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1922 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1923 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1924 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1925 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1926 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1927 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
1928 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
1929 + },
1930 + .msi_free_irq_bitmask = 0,
1931 + .msi_multiple_irq_bitmask= 0,
1932 + },
1933 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
1934 + {
1935 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI1_PIC_REG_BASE,
1936 + .msi_phy_base = PCIE1_MSI_PHY_BASE,
1937 + .msi_irq_idx = {
1938 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1939 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1940 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1941 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1942 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1943 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1944 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
1945 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
1946 + },
1947 + .msi_free_irq_bitmask = 0,
1948 + .msi_multiple_irq_bitmask= 0,
1949 +
1950 + },
1951 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
1952 +};
1953 +
1954 +/*
1955 + * This lock controls updates to msi_free_irq_bitmask,
1956 + * msi_multiple_irq_bitmask and pic register settting
1957 + */
1958 +static DEFINE_SPINLOCK(ifx_pcie_msi_lock);
1959 +
1960 +void pcie_msi_pic_init(int pcie_port)
1961 +{
1962 + spin_lock(&ifx_pcie_msi_lock);
1963 + msi_irqs[pcie_port].msi_pic_p->pic_endian = IFX_MSI_PIC_BIG_ENDIAN;
1964 + spin_unlock(&ifx_pcie_msi_lock);
1965 +}
1966 +
1967 +/**
1968 + * \fn int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1969 + * \brief Called when a driver request MSI interrupts instead of the
1970 + * legacy INT A-D. This routine will allocate multiple interrupts
1971 + * for MSI devices that support them. A device can override this by
1972 + * programming the MSI control bits [6:4] before calling
1973 + * pci_enable_msi().
1974 + *
1975 + * \param[in] pdev Device requesting MSI interrupts
1976 + * \param[in] desc MSI descriptor
1977 + *
1978 + * \return -EINVAL Invalid pcie root port or invalid msi bit
1979 + * \return 0 OK
1980 + * \ingroup IFX_PCIE_MSI
1981 + */
1982 +int
1983 +arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
1984 +{
1985 + int irq, pos;
1986 + u16 control;
1987 + int irq_idx;
1988 + int irq_step;
1989 + int configured_private_bits;
1990 + int request_private_bits;
1991 + struct msi_msg msg;
1992 + u16 search_mask;
1993 + struct ifx_pci_controller *ctrl = pdev->bus->sysdata;
1994 + int pcie_port = ctrl->port;
1995 +
1996 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s %s enter\n", __func__, pci_name(pdev));
1997 +
1998 + /* XXX, skip RC MSI itself */
1999 + if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
2000 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s RC itself doesn't use MSI interrupt\n", __func__);
2001 + return -EINVAL;
2002 + }
2003 +
2004 + /*
2005 + * Read the MSI config to figure out how many IRQs this device
2006 + * wants. Most devices only want 1, which will give
2007 + * configured_private_bits and request_private_bits equal 0.
2008 + */
2009 + pci_read_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, &control);
2010 +
2011 + /*
2012 + * If the number of private bits has been configured then use
2013 + * that value instead of the requested number. This gives the
2014 + * driver the chance to override the number of interrupts
2015 + * before calling pci_enable_msi().
2016 + */
2017 + configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4;
2018 + if (configured_private_bits == 0) {
2019 + /* Nothing is configured, so use the hardware requested size */
2020 + request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
2021 + }
2022 + else {
2023 + /*
2024 + * Use the number of configured bits, assuming the
2025 + * driver wanted to override the hardware request
2026 + * value.
2027 + */
2028 + request_private_bits = configured_private_bits;
2029 + }
2030 +
2031 + /*
2032 + * The PCI 2.3 spec mandates that there are at most 32
2033 + * interrupts. If this device asks for more, only give it one.
2034 + */
2035 + if (request_private_bits > 5) {
2036 + request_private_bits = 0;
2037 + }
2038 +again:
2039 + /*
2040 + * The IRQs have to be aligned on a power of two based on the
2041 + * number being requested.
2042 + */
2043 + irq_step = (1 << request_private_bits);
2044 +
2045 + /* Mask with one bit for each IRQ */
2046 + search_mask = (1 << irq_step) - 1;
2047 +
2048 + /*
2049 + * We're going to search msi_free_irq_bitmask_lock for zero
2050 + * bits. This represents an MSI interrupt number that isn't in
2051 + * use.
2052 + */
2053 + spin_lock(&ifx_pcie_msi_lock);
2054 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos += irq_step) {
2055 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & (search_mask << pos)) == 0) {
2056 + msi_irqs[pcie_port].msi_free_irq_bitmask |= search_mask << pos;
2057 + msi_irqs[pcie_port].msi_multiple_irq_bitmask |= (search_mask >> 1) << pos;
2058 + break;
2059 + }
2060 + }
2061 + spin_unlock(&ifx_pcie_msi_lock);
2062 +
2063 + /* Make sure the search for available interrupts didn't fail */
2064 + if (pos >= IFX_MSI_IRQ_NUM) {
2065 + if (request_private_bits) {
2066 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s: Unable to find %d free "
2067 + "interrupts, trying just one", __func__, 1 << request_private_bits);
2068 + request_private_bits = 0;
2069 + goto again;
2070 + }
2071 + else {
2072 + printk(KERN_ERR "%s: Unable to find a free MSI interrupt\n", __func__);
2073 + return -EINVAL;
2074 + }
2075 + }
2076 + irq = msi_irqs[pcie_port].msi_irq_idx[pos].irq;
2077 + irq_idx = msi_irqs[pcie_port].msi_irq_idx[pos].idx;
2078 +
2079 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pos %d, irq %d irq_idx %d\n", pos, irq, irq_idx);
2080 +
2081 + /*
2082 + * Initialize MSI. This has to match the memory-write endianess from the device
2083 + * Address bits [23:12]
2084 + */
2085 + spin_lock(&ifx_pcie_msi_lock);
2086 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] = SM(irq_idx, IFX_MSI_PIC_INT_LINE) |
2087 + SM((msi_irqs[pcie_port].msi_phy_base >> 12), IFX_MSI_PIC_MSG_ADDR) |
2088 + SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
2089 +
2090 + /* Enable this entry */
2091 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~IFX_MSI_PCI_INT_DISABLE;
2092 + spin_unlock(&ifx_pcie_msi_lock);
2093 +
2094 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pic_table[%d]: 0x%08x\n",
2095 + pos, msi_irqs[pcie_port].msi_pic_p->pic_table[pos]);
2096 +
2097 + /* Update the number of IRQs the device has available to it */
2098 + control &= ~PCI_MSI_FLAGS_QSIZE;
2099 + control |= (request_private_bits << 4);
2100 + pci_write_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, control);
2101 +
2102 + set_irq_msi(irq, desc);
2103 + msg.address_hi = 0x0;
2104 + msg.address_lo = msi_irqs[pcie_port].msi_phy_base;
2105 + msg.data = SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
2106 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "msi_data: pos %d 0x%08x\n", pos, msg.data);
2107 +
2108 + write_msi_msg(irq, &msg);
2109 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
2110 + return 0;
2111 +}
2112 +
2113 +static int
2114 +pcie_msi_irq_to_port(unsigned int irq, int *port)
2115 +{
2116 + int ret = 0;
2117 +
2118 + if (irq == IFX_PCIE_MSI_IR0 || irq == IFX_PCIE_MSI_IR1 ||
2119 + irq == IFX_PCIE_MSI_IR2 || irq == IFX_PCIE_MSI_IR3) {
2120 + *port = IFX_PCIE_PORT0;
2121 + }
2122 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
2123 + else if (irq == IFX_PCIE1_MSI_IR0 || irq == IFX_PCIE1_MSI_IR1 ||
2124 + irq == IFX_PCIE1_MSI_IR2 || irq == IFX_PCIE1_MSI_IR3) {
2125 + *port = IFX_PCIE_PORT1;
2126 + }
2127 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
2128 + else {
2129 + printk(KERN_ERR "%s: Attempted to teardown illegal "
2130 + "MSI interrupt (%d)\n", __func__, irq);
2131 + ret = -EINVAL;
2132 + }
2133 + return ret;
2134 +}
2135 +
2136 +/**
2137 + * \fn void arch_teardown_msi_irq(unsigned int irq)
2138 + * \brief Called when a device no longer needs its MSI interrupts. All
2139 + * MSI interrupts for the device are freed.
2140 + *
2141 + * \param irq The devices first irq number. There may be multple in sequence.
2142 + * \return none
2143 + * \ingroup IFX_PCIE_MSI
2144 + */
2145 +void
2146 +arch_teardown_msi_irq(unsigned int irq)
2147 +{
2148 + int pos;
2149 + int number_irqs;
2150 + u16 bitmask;
2151 + int pcie_port;
2152 +
2153 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s enter\n", __func__);
2154 +
2155 + BUG_ON(irq > INT_NUM_IM4_IRL31);
2156 +
2157 + if (pcie_msi_irq_to_port(irq, &pcie_port) != 0) {
2158 + return;
2159 + }
2160 +
2161 + /* Shift the mask to the correct bit location, not always correct
2162 + * Probally, the first match will be chosen.
2163 + */
2164 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos++) {
2165 + if ((msi_irqs[pcie_port].msi_irq_idx[pos].irq == irq)
2166 + && (msi_irqs[pcie_port].msi_free_irq_bitmask & ( 1 << pos))) {
2167 + break;
2168 + }
2169 + }
2170 + if (pos >= IFX_MSI_IRQ_NUM) {
2171 + printk(KERN_ERR "%s: Unable to find a matched MSI interrupt\n", __func__);
2172 + return;
2173 + }
2174 + spin_lock(&ifx_pcie_msi_lock);
2175 + /* Disable this entry */
2176 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] |= IFX_MSI_PCI_INT_DISABLE;
2177 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~(IFX_MSI_PIC_INT_LINE | IFX_MSI_PIC_MSG_ADDR | IFX_MSI_PIC_MSG_DATA);
2178 + spin_unlock(&ifx_pcie_msi_lock);
2179 + /*
2180 + * Count the number of IRQs we need to free by looking at the
2181 + * msi_multiple_irq_bitmask. Each bit set means that the next
2182 + * IRQ is also owned by this device.
2183 + */
2184 + number_irqs = 0;
2185 + while (((pos + number_irqs) < IFX_MSI_IRQ_NUM) &&
2186 + (msi_irqs[pcie_port].msi_multiple_irq_bitmask & (1 << (pos + number_irqs)))) {
2187 + number_irqs++;
2188 + }
2189 + number_irqs++;
2190 +
2191 + /* Mask with one bit for each IRQ */
2192 + bitmask = (1 << number_irqs) - 1;
2193 +
2194 + bitmask <<= pos;
2195 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & bitmask) != bitmask) {
2196 + printk(KERN_ERR "%s: Attempted to teardown MSI "
2197 + "interrupt (%d) not in use\n", __func__, irq);
2198 + return;
2199 + }
2200 + /* Checks are done, update the in use bitmask */
2201 + spin_lock(&ifx_pcie_msi_lock);
2202 + msi_irqs[pcie_port].msi_free_irq_bitmask &= ~bitmask;
2203 + msi_irqs[pcie_port].msi_multiple_irq_bitmask &= ~(bitmask >> 1);
2204 + spin_unlock(&ifx_pcie_msi_lock);
2205 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
2206 +}
2207 +
2208 +MODULE_LICENSE("GPL");
2209 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
2210 +MODULE_SUPPORTED_DEVICE("Infineon PCIe IP builtin MSI PIC module");
2211 +MODULE_DESCRIPTION("Infineon PCIe IP builtin MSI PIC driver");
2212 +
2213 diff --git a/arch/mips/pci/ifxmips_pcie_phy.c b/arch/mips/pci/ifxmips_pcie_phy.c
2214 new file mode 100644
2215 index 0000000..f5b0f13
2216 --- /dev/null
2217 +++ b/arch/mips/pci/ifxmips_pcie_phy.c
2218 @@ -0,0 +1,478 @@
2219 +/******************************************************************************
2220 +**
2221 +** FILE NAME : ifxmips_pcie_phy.c
2222 +** PROJECT : IFX UEIP for VRX200
2223 +** MODULES : PCIe PHY sub module
2224 +**
2225 +** DATE : 14 May 2009
2226 +** AUTHOR : Lei Chuanhua
2227 +** DESCRIPTION : PCIe Root Complex Driver
2228 +** COPYRIGHT : Copyright (c) 2009
2229 +** Infineon Technologies AG
2230 +** Am Campeon 1-12, 85579 Neubiberg, Germany
2231 +**
2232 +** This program is free software; you can redistribute it and/or modify
2233 +** it under the terms of the GNU General Public License as published by
2234 +** the Free Software Foundation; either version 2 of the License, or
2235 +** (at your option) any later version.
2236 +** HISTORY
2237 +** $Version $Date $Author $Comment
2238 +** 0.0.1 14 May,2009 Lei Chuanhua Initial version
2239 +*******************************************************************************/
2240 +/*!
2241 + \file ifxmips_pcie_phy.c
2242 + \ingroup IFX_PCIE
2243 + \brief PCIe PHY PLL register programming source file
2244 +*/
2245 +#include <linux/types.h>
2246 +#include <linux/kernel.h>
2247 +#include <asm/paccess.h>
2248 +#include <linux/delay.h>
2249 +
2250 +#include "ifxmips_pcie_reg.h"
2251 +#include "ifxmips_pcie.h"
2252 +
2253 +/* PCIe PDI only supports 16 bit operation */
2254 +
2255 +#define IFX_PCIE_PHY_REG_WRITE16(__addr, __data) \
2256 + ((*(volatile u16 *) (__addr)) = (__data))
2257 +
2258 +#define IFX_PCIE_PHY_REG_READ16(__addr) \
2259 + (*(volatile u16 *) (__addr))
2260 +
2261 +#define IFX_PCIE_PHY_REG16(__addr) \
2262 + (*(volatile u16 *) (__addr))
2263 +
2264 +#define IFX_PCIE_PHY_REG(__reg, __value, __mask) do { \
2265 + u16 read_data; \
2266 + u16 write_data; \
2267 + read_data = IFX_PCIE_PHY_REG_READ16((__reg)); \
2268 + write_data = (read_data & ((u16)~(__mask))) | (((u16)(__value)) & ((u16)(__mask)));\
2269 + IFX_PCIE_PHY_REG_WRITE16((__reg), write_data); \
2270 +} while (0)
2271 +
2272 +#define IFX_PCIE_PLL_TIMEOUT 1000 /* Tunnable */
2273 +
2274 +//#define IFX_PCI_PHY_REG_DUMP
2275 +
2276 +#ifdef IFX_PCI_PHY_REG_DUMP
2277 +static void
2278 +pcie_phy_reg_dump(int pcie_port)
2279 +{
2280 + printk("PLL REGFILE\n");
2281 + printk("PCIE_PHY_PLL_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL1(pcie_port)));
2282 + printk("PCIE_PHY_PLL_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL2(pcie_port)));
2283 + printk("PCIE_PHY_PLL_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL3(pcie_port)));
2284 + printk("PCIE_PHY_PLL_CTRL4 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL4(pcie_port)));
2285 + printk("PCIE_PHY_PLL_CTRL5 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL5(pcie_port)));
2286 + printk("PCIE_PHY_PLL_CTRL6 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL6(pcie_port)));
2287 + printk("PCIE_PHY_PLL_CTRL7 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_CTRL7(pcie_port)));
2288 + printk("PCIE_PHY_PLL_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL1(pcie_port)));
2289 + printk("PCIE_PHY_PLL_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL2(pcie_port)));
2290 + printk("PCIE_PHY_PLL_A_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_A_CTRL3(pcie_port)));
2291 + printk("PCIE_PHY_PLL_STATUS 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)));
2292 +
2293 + printk("TX1 REGFILE\n");
2294 + printk("PCIE_PHY_TX1_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL1(pcie_port)));
2295 + printk("PCIE_PHY_TX1_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL2(pcie_port)));
2296 + printk("PCIE_PHY_TX1_CTRL3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_CTRL3(pcie_port)));
2297 + printk("PCIE_PHY_TX1_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_A_CTRL1(pcie_port)));
2298 + printk("PCIE_PHY_TX1_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_A_CTRL2(pcie_port)));
2299 + printk("PCIE_PHY_TX1_MOD1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD1(pcie_port)));
2300 + printk("PCIE_PHY_TX1_MOD2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD2(pcie_port)));
2301 + printk("PCIE_PHY_TX1_MOD3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX1_MOD3(pcie_port)));
2302 +
2303 + printk("TX2 REGFILE\n");
2304 + printk("PCIE_PHY_TX2_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_CTRL1(pcie_port)));
2305 + printk("PCIE_PHY_TX2_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_CTRL2(pcie_port)));
2306 + printk("PCIE_PHY_TX2_A_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_A_CTRL1(pcie_port)));
2307 + printk("PCIE_PHY_TX2_A_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_A_CTRL2(pcie_port)));
2308 + printk("PCIE_PHY_TX2_MOD1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD1(pcie_port)));
2309 + printk("PCIE_PHY_TX2_MOD2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD2(pcie_port)));
2310 + printk("PCIE_PHY_TX2_MOD3 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_TX2_MOD3(pcie_port)));
2311 +
2312 + printk("RX1 REGFILE\n");
2313 + printk("PCIE_PHY_RX1_CTRL1 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CTRL1(pcie_port)));
2314 + printk("PCIE_PHY_RX1_CTRL2 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CTRL2(pcie_port)));
2315 + printk("PCIE_PHY_RX1_CDR 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_CDR(pcie_port)));
2316 + printk("PCIE_PHY_RX1_EI 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_EI(pcie_port)));
2317 + printk("PCIE_PHY_RX1_A_CTRL 0x%04x\n", IFX_PCIE_PHY_REG16(PCIE_PHY_RX1_A_CTRL(pcie_port)));
2318 +}
2319 +#endif /* IFX_PCI_PHY_REG_DUMP */
2320 +
2321 +static void
2322 +pcie_phy_comm_setup(int pcie_port)
2323 +{
2324 + /* PLL Setting */
2325 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
2326 +
2327 + /* increase the bias reference voltage */
2328 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
2329 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
2330 +
2331 + /* Endcnt */
2332 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
2333 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
2334 +
2335 + /* force */
2336 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
2337 +
2338 + /* predrv_ser_en */
2339 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
2340 +
2341 + /* ctrl_lim */
2342 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
2343 +
2344 + /* ctrl */
2345 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
2346 +
2347 + /* predrv_ser_en */
2348 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
2349 +
2350 + /* RTERM*/
2351 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
2352 +
2353 + /* Improved 100MHz clock output */
2354 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
2355 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
2356 +
2357 + /* Reduced CDR BW to avoid glitches */
2358 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
2359 +}
2360 +
2361 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
2362 +static void
2363 +pcie_phy_36mhz_mode_setup(int pcie_port)
2364 +{
2365 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2366 +#ifdef IFX_PCI_PHY_REG_DUMP
2367 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2368 + pcie_phy_reg_dump(pcie_port);
2369 +#endif
2370 +
2371 + /* en_ext_mmd_div_ratio */
2372 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2373 +
2374 + /* ext_mmd_div_ratio*/
2375 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2376 +
2377 + /* pll_ensdm */
2378 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2379 +
2380 + /* en_const_sdm */
2381 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2382 +
2383 + /* mmd */
2384 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2385 +
2386 + /* lf_mode */
2387 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2388 +
2389 + /* const_sdm */
2390 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2391 +
2392 + /* const sdm */
2393 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2394 +
2395 + /* pllmod */
2396 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2397 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2398 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2399 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
2400 +
2401 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2402 +}
2403 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
2404 +
2405 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE
2406 +static void
2407 +pcie_phy_36mhz_ssc_mode_setup(int pcie_port)
2408 +{
2409 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2410 +#ifdef IFX_PCI_PHY_REG_DUMP
2411 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2412 + pcie_phy_reg_dump(pcie_port);
2413 +#endif
2414 +
2415 + /* PLL Setting */
2416 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
2417 +
2418 + /* Increase the bias reference voltage */
2419 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
2420 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
2421 +
2422 + /* Endcnt */
2423 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
2424 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
2425 +
2426 + /* Force */
2427 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
2428 +
2429 + /* Predrv_ser_en */
2430 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
2431 +
2432 + /* ctrl_lim */
2433 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
2434 +
2435 + /* ctrl */
2436 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
2437 +
2438 + /* predrv_ser_en */
2439 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
2440 +
2441 + /* RTERM*/
2442 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
2443 +
2444 + /* en_ext_mmd_div_ratio */
2445 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2446 +
2447 + /* ext_mmd_div_ratio*/
2448 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2449 +
2450 + /* pll_ensdm */
2451 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0400, 0x0400);
2452 +
2453 + /* en_const_sdm */
2454 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2455 +
2456 + /* mmd */
2457 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2458 +
2459 + /* lf_mode */
2460 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2461 +
2462 + /* const_sdm */
2463 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2464 +
2465 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0100);
2466 + /* const sdm */
2467 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2468 +
2469 + /* pllmod */
2470 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2471 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2472 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2473 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1c72, 0xFFFF);
2474 +
2475 + /* improved 100MHz clock output */
2476 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
2477 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
2478 +
2479 + /* reduced CDR BW to avoid glitches */
2480 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
2481 +
2482 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2483 +}
2484 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE */
2485 +
2486 +#ifdef CONFIG_IFX_PCIE_PHY_25MHZ_MODE
2487 +static void
2488 +pcie_phy_25mhz_mode_setup(int pcie_port)
2489 +{
2490 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2491 +#ifdef IFX_PCI_PHY_REG_DUMP
2492 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2493 + pcie_phy_reg_dump(pcie_port);
2494 +#endif
2495 + /* en_const_sdm */
2496 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2497 +
2498 + /* pll_ensdm */
2499 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0200);
2500 +
2501 + /* en_ext_mmd_div_ratio*/
2502 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0002, 0x0002);
2503 +
2504 + /* ext_mmd_div_ratio*/
2505 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0040, 0x0070);
2506 +
2507 + /* mmd */
2508 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x6000, 0xe000);
2509 +
2510 + /* lf_mode */
2511 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x4000, 0x4000);
2512 +
2513 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2514 +}
2515 +#endif /* CONFIG_IFX_PCIE_PHY_25MHZ_MODE */
2516 +
2517 +#ifdef CONFIG_IFX_PCIE_PHY_100MHZ_MODE
2518 +static void
2519 +pcie_phy_100mhz_mode_setup(int pcie_port)
2520 +{
2521 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
2522 +#ifdef IFX_PCI_PHY_REG_DUMP
2523 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Initial PHY register dump\n");
2524 + pcie_phy_reg_dump(pcie_port);
2525 +#endif
2526 + /* en_ext_mmd_div_ratio */
2527 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
2528 +
2529 + /* ext_mmd_div_ratio*/
2530 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
2531 +
2532 + /* pll_ensdm */
2533 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
2534 +
2535 + /* en_const_sdm */
2536 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
2537 +
2538 + /* mmd */
2539 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
2540 +
2541 + /* lf_mode */
2542 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
2543 +
2544 + /* const_sdm */
2545 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
2546 +
2547 + /* const sdm */
2548 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
2549 +
2550 + /* pllmod */
2551 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
2552 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
2553 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
2554 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
2555 +
2556 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
2557 +}
2558 +#endif /* CONFIG_IFX_PCIE_PHY_100MHZ_MODE */
2559 +
2560 +static int
2561 +pcie_phy_wait_startup_ready(int pcie_port)
2562 +{
2563 + int i;
2564 +
2565 + for (i = 0; i < IFX_PCIE_PLL_TIMEOUT; i++) {
2566 + if ((IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)) & 0x0040) != 0) {
2567 + break;
2568 + }
2569 + udelay(10);
2570 + }
2571 + if (i >= IFX_PCIE_PLL_TIMEOUT) {
2572 + printk(KERN_ERR "%s PLL Link timeout\n", __func__);
2573 + return -1;
2574 + }
2575 + return 0;
2576 +}
2577 +
2578 +static void
2579 +pcie_phy_load_enable(int pcie_port, int slice)
2580 +{
2581 + /* Set the load_en of tx/rx slice to '1' */
2582 + switch (slice) {
2583 + case 1:
2584 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0010, 0x0010);
2585 + break;
2586 + case 2:
2587 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0010, 0x0010);
2588 + break;
2589 + case 3:
2590 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0002, 0x0002);
2591 + break;
2592 + }
2593 +}
2594 +
2595 +static void
2596 +pcie_phy_load_disable(int pcie_port, int slice)
2597 +{
2598 + /* set the load_en of tx/rx slice to '0' */
2599 + switch (slice) {
2600 + case 1:
2601 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0000, 0x0010);
2602 + break;
2603 + case 2:
2604 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0000, 0x0010);
2605 + break;
2606 + case 3:
2607 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0000, 0x0002);
2608 + break;
2609 + }
2610 +}
2611 +
2612 +static void
2613 +pcie_phy_load_war(int pcie_port)
2614 +{
2615 + int slice;
2616 +
2617 + for (slice = 1; slice < 4; slice++) {
2618 + pcie_phy_load_enable(pcie_port, slice);
2619 + udelay(1);
2620 + pcie_phy_load_disable(pcie_port, slice);
2621 + }
2622 +}
2623 +
2624 +static void
2625 +pcie_phy_tx2_modulation(int pcie_port)
2626 +{
2627 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD1(pcie_port), 0x1FFE, 0xFFFF);
2628 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD2(pcie_port), 0xFFFE, 0xFFFF);
2629 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0601, 0xFFFF);
2630 + mdelay(1);
2631 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0001, 0xFFFF);
2632 +}
2633 +
2634 +static void
2635 +pcie_phy_tx1_modulation(int pcie_port)
2636 +{
2637 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD1(pcie_port), 0x1FFE, 0xFFFF);
2638 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD2(pcie_port), 0xFFFE, 0xFFFF);
2639 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0601, 0xFFFF);
2640 + mdelay(1);
2641 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0001, 0xFFFF);
2642 +}
2643 +
2644 +static void
2645 +pcie_phy_tx_modulation_war(int pcie_port)
2646 +{
2647 + int i;
2648 +
2649 +#define PCIE_PHY_MODULATION_NUM 5
2650 + for (i = 0; i < PCIE_PHY_MODULATION_NUM; i++) {
2651 + pcie_phy_tx2_modulation(pcie_port);
2652 + pcie_phy_tx1_modulation(pcie_port);
2653 + }
2654 +#undef PCIE_PHY_MODULATION_NUM
2655 +}
2656 +
2657 +void
2658 +pcie_phy_clock_mode_setup(int pcie_port)
2659 +{
2660 + pcie_pdi_big_endian(pcie_port);
2661 +
2662 + /* Enable PDI to access PCIe PHY register */
2663 + pcie_pdi_pmu_enable(pcie_port);
2664 +
2665 + /* Configure PLL and PHY clock */
2666 + pcie_phy_comm_setup(pcie_port);
2667 +
2668 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
2669 + pcie_phy_36mhz_mode_setup(pcie_port);
2670 +#elif defined(CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE)
2671 + pcie_phy_36mhz_ssc_mode_setup(pcie_port);
2672 +#elif defined(CONFIG_IFX_PCIE_PHY_25MHZ_MODE)
2673 + pcie_phy_25mhz_mode_setup(pcie_port);
2674 +#elif defined (CONFIG_IFX_PCIE_PHY_100MHZ_MODE)
2675 + pcie_phy_100mhz_mode_setup(pcie_port);
2676 +#else
2677 + #error "PCIE PHY Clock Mode must be chosen first!!!!"
2678 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
2679 +
2680 + /* Enable PCIe PHY and make PLL setting take effect */
2681 + pcie_phy_pmu_enable(pcie_port);
2682 +
2683 + /* Check if we are in startup_ready status */
2684 + pcie_phy_wait_startup_ready(pcie_port);
2685 +
2686 + pcie_phy_load_war(pcie_port);
2687 +
2688 + /* Apply TX modulation workarounds */
2689 + pcie_phy_tx_modulation_war(pcie_port);
2690 +
2691 +#ifdef IFX_PCI_PHY_REG_DUMP
2692 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Modified PHY register dump\n");
2693 + pcie_phy_reg_dump(pcie_port);
2694 +#endif
2695 +}
2696 +
2697 diff --git a/arch/mips/pci/ifxmips_pcie_pm.c b/arch/mips/pci/ifxmips_pcie_pm.c
2698 new file mode 100644
2699 index 0000000..a10ecad
2700 --- /dev/null
2701 +++ b/arch/mips/pci/ifxmips_pcie_pm.c
2702 @@ -0,0 +1,176 @@
2703 +/******************************************************************************
2704 +**
2705 +** FILE NAME : ifxmips_pcie_pm.c
2706 +** PROJECT : IFX UEIP
2707 +** MODULES : PCIE Root Complex Driver
2708 +**
2709 +** DATE : 21 Dec 2009
2710 +** AUTHOR : Lei Chuanhua
2711 +** DESCRIPTION : PCIE Root Complex Driver Power Managment
2712 +** COPYRIGHT : Copyright (c) 2009
2713 +** Lantiq Deutschland GmbH
2714 +** Am Campeon 3, 85579 Neubiberg, Germany
2715 +**
2716 +** This program is free software; you can redistribute it and/or modify
2717 +** it under the terms of the GNU General Public License as published by
2718 +** the Free Software Foundation; either version 2 of the License, or
2719 +** (at your option) any later version.
2720 +**
2721 +** HISTORY
2722 +** $Date $Author $Comment
2723 +** 21 Dec,2009 Lei Chuanhua First UEIP release
2724 +*******************************************************************************/
2725 +/*!
2726 + \defgroup IFX_PCIE_PM Power Management functions
2727 + \ingroup IFX_PCIE
2728 + \brief IFX PCIE Root Complex Driver power management functions
2729 +*/
2730 +
2731 +/*!
2732 + \file ifxmips_pcie_pm.c
2733 + \ingroup IFX_PCIE
2734 + \brief source file for PCIE Root Complex Driver Power Management
2735 +*/
2736 +
2737 +#ifndef EXPORT_SYMTAB
2738 +#define EXPORT_SYMTAB
2739 +#endif
2740 +#ifndef AUTOCONF_INCLUDED
2741 +#include <linux/config.h>
2742 +#endif /* AUTOCONF_INCLUDED */
2743 +#include <linux/version.h>
2744 +#include <linux/module.h>
2745 +#include <linux/types.h>
2746 +#include <linux/kernel.h>
2747 +#include <asm/system.h>
2748 +
2749 +/* Project header */
2750 +#include <asm/ifx/ifx_types.h>
2751 +#include <asm/ifx/ifx_regs.h>
2752 +#include <asm/ifx/common_routines.h>
2753 +#include <asm/ifx/ifx_pmcu.h>
2754 +#include "ifxmips_pcie_pm.h"
2755 +
2756 +/**
2757 + * \fn static IFX_PMCU_RETURN_t ifx_pcie_pmcu_state_change(IFX_PMCU_STATE_t pmcuState)
2758 + * \brief the callback function to request pmcu state in the power management hardware-dependent module
2759 + *
2760 + * \param pmcuState This parameter is a PMCU state.
2761 + *
2762 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2763 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2764 + * \return IFX_PMCU_RETURN_DENIED Not allowed to operate power state
2765 + * \ingroup IFX_PCIE_PM
2766 + */
2767 +static IFX_PMCU_RETURN_t
2768 +ifx_pcie_pmcu_state_change(IFX_PMCU_STATE_t pmcuState)
2769 +{
2770 + switch(pmcuState)
2771 + {
2772 + case IFX_PMCU_STATE_D0:
2773 + return IFX_PMCU_RETURN_SUCCESS;
2774 + case IFX_PMCU_STATE_D1: // Not Applicable
2775 + return IFX_PMCU_RETURN_DENIED;
2776 + case IFX_PMCU_STATE_D2: // Not Applicable
2777 + return IFX_PMCU_RETURN_DENIED;
2778 + case IFX_PMCU_STATE_D3: // Module clock gating and Power gating
2779 + return IFX_PMCU_RETURN_SUCCESS;
2780 + default:
2781 + return IFX_PMCU_RETURN_DENIED;
2782 + }
2783 +}
2784 +
2785 +/**
2786 + * \fn static IFX_PMCU_RETURN_t ifx_pcie_pmcu_state_get(IFX_PMCU_STATE_t *pmcuState)
2787 + * \brief the callback function to get pmcu state in the power management hardware-dependent module
2788 +
2789 + * \param pmcuState Pointer to return power state.
2790 + *
2791 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2792 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2793 + * \return IFX_PMCU_RETURN_DENIED Not allowed to operate power state
2794 + * \ingroup IFX_PCIE_PM
2795 + */
2796 +static IFX_PMCU_RETURN_t
2797 +ifx_pcie_pmcu_state_get(IFX_PMCU_STATE_t *pmcuState)
2798 +{
2799 + return IFX_PMCU_RETURN_SUCCESS;
2800 +}
2801 +
2802 +/**
2803 + * \fn IFX_PMCU_RETURN_t ifx_pcie_pmcu_prechange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2804 + * \brief Apply all callbacks registered to be executed before a state change for pmcuModule
2805 + *
2806 + * \param pmcuModule Module
2807 + * \param newState New state
2808 + * \param oldState Old state
2809 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2810 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2811 + * \ingroup IFX_PCIE_PM
2812 + */
2813 +static IFX_PMCU_RETURN_t
2814 +ifx_pcie_pmcu_prechange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2815 +{
2816 + return IFX_PMCU_RETURN_SUCCESS;
2817 +}
2818 +
2819 +/**
2820 + * \fn IFX_PMCU_RETURN_t ifx_pcie_pmcu_postchange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2821 + * \brief Apply all callbacks registered to be executed before a state change for pmcuModule
2822 + *
2823 + * \param pmcuModule Module
2824 + * \param newState New state
2825 + * \param oldState Old state
2826 + * \return IFX_PMCU_RETURN_SUCCESS Set Power State successfully
2827 + * \return IFX_PMCU_RETURN_ERROR Failed to set power state.
2828 + * \ingroup IFX_PCIE_PM
2829 + */
2830 +static IFX_PMCU_RETURN_t
2831 +ifx_pcie_pmcu_postchange(IFX_PMCU_MODULE_t pmcuModule, IFX_PMCU_STATE_t newState, IFX_PMCU_STATE_t oldState)
2832 +{
2833 + return IFX_PMCU_RETURN_SUCCESS;
2834 +}
2835 +
2836 +/**
2837 + * \fn static void ifx_pcie_pmcu_init(void)
2838 + * \brief Register with central PMCU module
2839 + * \return none
2840 + * \ingroup IFX_PCIE_PM
2841 + */
2842 +void
2843 +ifx_pcie_pmcu_init(void)
2844 +{
2845 + IFX_PMCU_REGISTER_t pmcuRegister;
2846 +
2847 + /* XXX, hook driver context */
2848 +
2849 + /* State function register */
2850 + memset(&pmcuRegister, 0, sizeof(IFX_PMCU_REGISTER_t));
2851 + pmcuRegister.pmcuModule = IFX_PMCU_MODULE_PCIE;
2852 + pmcuRegister.pmcuModuleNr = 0;
2853 + pmcuRegister.ifx_pmcu_state_change = ifx_pcie_pmcu_state_change;
2854 + pmcuRegister.ifx_pmcu_state_get = ifx_pcie_pmcu_state_get;
2855 + pmcuRegister.pre = ifx_pcie_pmcu_prechange;
2856 + pmcuRegister.post= ifx_pcie_pmcu_postchange;
2857 + ifx_pmcu_register(&pmcuRegister);
2858 +}
2859 +
2860 +/**
2861 + * \fn static void ifx_pcie_pmcu_exit(void)
2862 + * \brief Unregister with central PMCU module
2863 + *
2864 + * \return none
2865 + * \ingroup IFX_PCIE_PM
2866 + */
2867 +void
2868 +ifx_pcie_pmcu_exit(void)
2869 +{
2870 + IFX_PMCU_REGISTER_t pmcuUnRegister;
2871 +
2872 + /* XXX, hook driver context */
2873 +
2874 + pmcuUnRegister.pmcuModule = IFX_PMCU_MODULE_PCIE;
2875 + pmcuUnRegister.pmcuModuleNr = 0;
2876 + ifx_pmcu_unregister(&pmcuUnRegister);
2877 +}
2878 +
2879 diff --git a/arch/mips/pci/ifxmips_pcie_pm.h b/arch/mips/pci/ifxmips_pcie_pm.h
2880 new file mode 100644
2881 index 0000000..6ece20d
2882 --- /dev/null
2883 +++ b/arch/mips/pci/ifxmips_pcie_pm.h
2884 @@ -0,0 +1,36 @@
2885 +/******************************************************************************
2886 +**
2887 +** FILE NAME : ifxmips_pcie_pm.h
2888 +** PROJECT : IFX UEIP
2889 +** MODULES : PCIe Root Complex Driver
2890 +**
2891 +** DATE : 21 Dec 2009
2892 +** AUTHOR : Lei Chuanhua
2893 +** DESCRIPTION : PCIe Root Complex Driver Power Managment
2894 +** COPYRIGHT : Copyright (c) 2009
2895 +** Lantiq Deutschland GmbH
2896 +** Am Campeon 3, 85579 Neubiberg, Germany
2897 +**
2898 +** This program is free software; you can redistribute it and/or modify
2899 +** it under the terms of the GNU General Public License as published by
2900 +** the Free Software Foundation; either version 2 of the License, or
2901 +** (at your option) any later version.
2902 +**
2903 +** HISTORY
2904 +** $Date $Author $Comment
2905 +** 21 Dec,2009 Lei Chuanhua First UEIP release
2906 +*******************************************************************************/
2907 +/*!
2908 + \file ifxmips_pcie_pm.h
2909 + \ingroup IFX_PCIE
2910 + \brief header file for PCIe Root Complex Driver Power Management
2911 +*/
2912 +
2913 +#ifndef IFXMIPS_PCIE_PM_H
2914 +#define IFXMIPS_PCIE_PM_H
2915 +
2916 +void ifx_pcie_pmcu_init(void);
2917 +void ifx_pcie_pmcu_exit(void);
2918 +
2919 +#endif /* IFXMIPS_PCIE_PM_H */
2920 +
2921 diff --git a/arch/mips/pci/ifxmips_pcie_reg.h b/arch/mips/pci/ifxmips_pcie_reg.h
2922 new file mode 100644
2923 index 0000000..e7e4b6c
2924 --- /dev/null
2925 +++ b/arch/mips/pci/ifxmips_pcie_reg.h
2926 @@ -0,0 +1,1001 @@
2927 +/******************************************************************************
2928 +**
2929 +** FILE NAME : ifxmips_pcie_reg.h
2930 +** PROJECT : IFX UEIP for VRX200
2931 +** MODULES : PCIe module
2932 +**
2933 +** DATE : 02 Mar 2009
2934 +** AUTHOR : Lei Chuanhua
2935 +** DESCRIPTION : PCIe Root Complex Driver
2936 +** COPYRIGHT : Copyright (c) 2009
2937 +** Infineon Technologies AG
2938 +** Am Campeon 1-12, 85579 Neubiberg, Germany
2939 +**
2940 +** This program is free software; you can redistribute it and/or modify
2941 +** it under the terms of the GNU General Public License as published by
2942 +** the Free Software Foundation; either version 2 of the License, or
2943 +** (at your option) any later version.
2944 +** HISTORY
2945 +** $Version $Date $Author $Comment
2946 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
2947 +*******************************************************************************/
2948 +#ifndef IFXMIPS_PCIE_REG_H
2949 +#define IFXMIPS_PCIE_REG_H
2950 +/*!
2951 + \file ifxmips_pcie_reg.h
2952 + \ingroup IFX_PCIE
2953 + \brief header file for PCIe module register definition
2954 +*/
2955 +/* PCIe Address Mapping Base */
2956 +#define PCIE_CFG_PHY_BASE 0x1D000000UL
2957 +#define PCIE_CFG_BASE (KSEG1 + PCIE_CFG_PHY_BASE)
2958 +#define PCIE_CFG_SIZE (8 * 1024 * 1024)
2959 +
2960 +#define PCIE_MEM_PHY_BASE 0x1C000000UL
2961 +#define PCIE_MEM_BASE (KSEG1 + PCIE_MEM_PHY_BASE)
2962 +#define PCIE_MEM_SIZE (16 * 1024 * 1024)
2963 +#define PCIE_MEM_PHY_END (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
2964 +
2965 +#define PCIE_IO_PHY_BASE 0x1D800000UL
2966 +#define PCIE_IO_BASE (KSEG1 + PCIE_IO_PHY_BASE)
2967 +#define PCIE_IO_SIZE (1 * 1024 * 1024)
2968 +#define PCIE_IO_PHY_END (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
2969 +
2970 +#define PCIE_RC_CFG_BASE (KSEG1 + 0x1D900000)
2971 +#define PCIE_APP_LOGIC_REG (KSEG1 + 0x1E100900)
2972 +#define PCIE_MSI_PHY_BASE 0x1F600000UL
2973 +
2974 +#define PCIE_PDI_PHY_BASE 0x1F106800UL
2975 +#define PCIE_PDI_BASE (KSEG1 + PCIE_PDI_PHY_BASE)
2976 +#define PCIE_PDI_SIZE 0x400
2977 +
2978 +#define PCIE1_CFG_PHY_BASE 0x19000000UL
2979 +#define PCIE1_CFG_BASE (KSEG1 + PCIE1_CFG_PHY_BASE)
2980 +#define PCIE1_CFG_SIZE (8 * 1024 * 1024)
2981 +
2982 +#define PCIE1_MEM_PHY_BASE 0x18000000UL
2983 +#define PCIE1_MEM_BASE (KSEG1 + PCIE1_MEM_PHY_BASE)
2984 +#define PCIE1_MEM_SIZE (16 * 1024 * 1024)
2985 +#define PCIE1_MEM_PHY_END (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
2986 +
2987 +#define PCIE1_IO_PHY_BASE 0x19800000UL
2988 +#define PCIE1_IO_BASE (KSEG1 + PCIE1_IO_PHY_BASE)
2989 +#define PCIE1_IO_SIZE (1 * 1024 * 1024)
2990 +#define PCIE1_IO_PHY_END (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
2991 +
2992 +#define PCIE1_RC_CFG_BASE (KSEG1 + 0x19900000)
2993 +#define PCIE1_APP_LOGIC_REG (KSEG1 + 0x1E100700)
2994 +#define PCIE1_MSI_PHY_BASE 0x1F400000UL
2995 +
2996 +#define PCIE1_PDI_PHY_BASE 0x1F700400UL
2997 +#define PCIE1_PDI_BASE (KSEG1 + PCIE1_PDI_PHY_BASE)
2998 +#define PCIE1_PDI_SIZE 0x400
2999 +
3000 +#define PCIE_CFG_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
3001 +#define PCIE_MEM_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
3002 +#define PCIE_IO_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
3003 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
3004 +#define PCIE_MEM_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
3005 +#define PCIE_IO_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
3006 +#define PCIE_IO_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
3007 +#define PCIE_APP_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
3008 +#define PCIE_RC_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
3009 +#define PCIE_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
3010 +
3011 +/* PCIe Application Logic Register */
3012 +/* RC Core Control Register */
3013 +#define PCIE_RC_CCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
3014 +/* This should be enabled after initializing configuratin registers
3015 + * Also should check link status retraining bit
3016 + */
3017 +#define PCIE_RC_CCR_LTSSM_ENABLE 0x00000001 /* Enable LTSSM to continue link establishment */
3018 +
3019 +/* RC Core Debug Register */
3020 +#define PCIE_RC_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
3021 +#define PCIE_RC_DR_DLL_UP 0x00000001 /* Data Link Layer Up */
3022 +#define PCIE_RC_DR_CURRENT_POWER_STATE 0x0000000E /* Current Power State */
3023 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S 1
3024 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE 0x000001F0 /* Current LTSSM State */
3025 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S 4
3026 +
3027 +#define PCIE_RC_DR_PM_DEV_STATE 0x00000E00 /* Power Management D-State */
3028 +#define PCIE_RC_DR_PM_DEV_STATE_S 9
3029 +
3030 +#define PCIE_RC_DR_PM_ENABLED 0x00001000 /* Power Management State from PMU */
3031 +#define PCIE_RC_DR_PME_EVENT_ENABLED 0x00002000 /* Power Management Event Enable State */
3032 +#define PCIE_RC_DR_AUX_POWER_ENABLED 0x00004000 /* Auxiliary Power Enable */
3033 +
3034 +/* Current Power State Definition */
3035 +enum {
3036 + PCIE_RC_DR_D0 = 0,
3037 + PCIE_RC_DR_D1, /* Not supported */
3038 + PCIE_RC_DR_D2, /* Not supported */
3039 + PCIE_RC_DR_D3,
3040 + PCIE_RC_DR_UN,
3041 +};
3042 +
3043 +/* PHY Link Status Register */
3044 +#define PCIE_PHY_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
3045 +#define PCIE_PHY_SR_PHY_LINK_UP 0x00000001 /* PHY Link Up/Down Indicator */
3046 +
3047 +/* Electromechanical Control Register */
3048 +#define PCIE_EM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
3049 +#define PCIE_EM_CR_CARD_IS_PRESENT 0x00000001 /* Card Presence Detect State */
3050 +#define PCIE_EM_CR_MRL_OPEN 0x00000002 /* MRL Sensor State */
3051 +#define PCIE_EM_CR_POWER_FAULT_SET 0x00000004 /* Power Fault Detected */
3052 +#define PCIE_EM_CR_MRL_SENSOR_SET 0x00000008 /* MRL Sensor Changed */
3053 +#define PCIE_EM_CR_PRESENT_DETECT_SET 0x00000010 /* Card Presense Detect Changed */
3054 +#define PCIE_EM_CR_CMD_CPL_INT_SET 0x00000020 /* Command Complete Interrupt */
3055 +#define PCIE_EM_CR_SYS_INTERLOCK_SET 0x00000040 /* System Electromechanical IterLock Engaged */
3056 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET 0x00000080 /* Attention Button Pressed */
3057 +
3058 +/* Interrupt Status Register */
3059 +#define PCIE_IR_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
3060 +#define PCIE_IR_SR_PME_CAUSE_MSI 0x00000002 /* MSI caused by PME */
3061 +#define PCIE_IR_SR_HP_PME_WAKE_GEN 0x00000004 /* Hotplug PME Wake Generation */
3062 +#define PCIE_IR_SR_HP_MSI 0x00000008 /* Hotplug MSI */
3063 +#define PCIE_IR_SR_AHB_LU_ERR 0x00000030 /* AHB Bridge Lookup Error Signals */
3064 +#define PCIE_IR_SR_AHB_LU_ERR_S 4
3065 +#define PCIE_IR_SR_INT_MSG_NUM 0x00003E00 /* Interrupt Message Number */
3066 +#define PCIE_IR_SR_INT_MSG_NUM_S 9
3067 +#define PCIE_IR_SR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
3068 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S 27
3069 +
3070 +/* Message Control Register */
3071 +#define PCIE_MSG_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
3072 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG 0x00000001 /* Generate PME Turn Off Message */
3073 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG 0x00000002 /* Generate Unlock Message */
3074 +
3075 +#define PCIE_VDM_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
3076 +
3077 +/* Vendor-Defined Message Requester ID Register */
3078 +#define PCIE_VDM_RID(X) (PCIE_APP_PORT_TO_BASE (X) + 0x38)
3079 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID 0x0000FFFF
3080 +#define PCIE_VDM_RID_VDMRID_S 0
3081 +
3082 +/* ASPM Control Register */
3083 +#define PCIE_ASPM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
3084 +#define PCIE_ASPM_CR_HOT_RST 0x00000001 /* Hot Reset Request to the downstream device */
3085 +#define PCIE_ASPM_CR_REQ_EXIT_L1 0x00000002 /* Request to Exit L1 */
3086 +#define PCIE_ASPM_CR_REQ_ENTER_L1 0x00000004 /* Request to Enter L1 */
3087 +
3088 +/* Vendor Message DW0 Register */
3089 +#define PCIE_VM_MSG_DW0(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
3090 +#define PCIE_VM_MSG_DW0_TYPE 0x0000001F /* Message type */
3091 +#define PCIE_VM_MSG_DW0_TYPE_S 0
3092 +#define PCIE_VM_MSG_DW0_FORMAT 0x00000060 /* Format */
3093 +#define PCIE_VM_MSG_DW0_FORMAT_S 5
3094 +#define PCIE_VM_MSG_DW0_TC 0x00007000 /* Traffic Class */
3095 +#define PCIE_VM_MSG_DW0_TC_S 12
3096 +#define PCIE_VM_MSG_DW0_ATTR 0x000C0000 /* Atrributes */
3097 +#define PCIE_VM_MSG_DW0_ATTR_S 18
3098 +#define PCIE_VM_MSG_DW0_EP_TLP 0x00100000 /* Poisoned TLP */
3099 +#define PCIE_VM_MSG_DW0_TD 0x00200000 /* TLP Digest */
3100 +#define PCIE_VM_MSG_DW0_LEN 0xFFC00000 /* Length */
3101 +#define PCIE_VM_MSG_DW0_LEN_S 22
3102 +
3103 +/* Format Definition */
3104 +enum {
3105 + PCIE_VM_MSG_FORMAT_00 = 0, /* 3DW Hdr, no data*/
3106 + PCIE_VM_MSG_FORMAT_01, /* 4DW Hdr, no data */
3107 + PCIE_VM_MSG_FORMAT_10, /* 3DW Hdr, with data */
3108 + PCIE_VM_MSG_FORMAT_11, /* 4DW Hdr, with data */
3109 +};
3110 +
3111 +/* Traffic Class Definition */
3112 +enum {
3113 + PCIE_VM_MSG_TC0 = 0,
3114 + PCIE_VM_MSG_TC1,
3115 + PCIE_VM_MSG_TC2,
3116 + PCIE_VM_MSG_TC3,
3117 + PCIE_VM_MSG_TC4,
3118 + PCIE_VM_MSG_TC5,
3119 + PCIE_VM_MSG_TC6,
3120 + PCIE_VM_MSG_TC7,
3121 +};
3122 +
3123 +/* Attributes Definition */
3124 +enum {
3125 + PCIE_VM_MSG_ATTR_00 = 0, /* RO and No Snoop cleared */
3126 + PCIE_VM_MSG_ATTR_01, /* RO cleared , No Snoop set */
3127 + PCIE_VM_MSG_ATTR_10, /* RO set, No Snoop cleared*/
3128 + PCIE_VM_MSG_ATTR_11, /* RO and No Snoop set */
3129 +};
3130 +
3131 +/* Payload Size Definition */
3132 +#define PCIE_VM_MSG_LEN_MIN 0
3133 +#define PCIE_VM_MSG_LEN_MAX 1024
3134 +
3135 +/* Vendor Message DW1 Register */
3136 +#define PCIE_VM_MSG_DW1(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
3137 +#define PCIE_VM_MSG_DW1_FUNC_NUM 0x00000070 /* Function Number */
3138 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S 8
3139 +#define PCIE_VM_MSG_DW1_CODE 0x00FF0000 /* Message Code */
3140 +#define PCIE_VM_MSG_DW1_CODE_S 16
3141 +#define PCIE_VM_MSG_DW1_TAG 0xFF000000 /* Tag */
3142 +#define PCIE_VM_MSG_DW1_TAG_S 24
3143 +
3144 +#define PCIE_VM_MSG_DW2(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
3145 +#define PCIE_VM_MSG_DW3(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
3146 +
3147 +/* Vendor Message Request Register */
3148 +#define PCIE_VM_MSG_REQR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
3149 +#define PCIE_VM_MSG_REQR_REQ 0x00000001 /* Vendor Message Request */
3150 +
3151 +
3152 +/* AHB Slave Side Band Control Register */
3153 +#define PCIE_AHB_SSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
3154 +#define PCIE_AHB_SSB_REQ_BCM 0x00000001 /* Slave Reques BCM filed */
3155 +#define PCIE_AHB_SSB_REQ_EP 0x00000002 /* Slave Reques EP filed */
3156 +#define PCIE_AHB_SSB_REQ_TD 0x00000004 /* Slave Reques TD filed */
3157 +#define PCIE_AHB_SSB_REQ_ATTR 0x00000018 /* Slave Reques Attribute number */
3158 +#define PCIE_AHB_SSB_REQ_ATTR_S 3
3159 +#define PCIE_AHB_SSB_REQ_TC 0x000000E0 /* Slave Request TC Field */
3160 +#define PCIE_AHB_SSB_REQ_TC_S 5
3161 +
3162 +/* AHB Master SideBand Ctrl Register */
3163 +#define PCIE_AHB_MSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
3164 +#define PCIE_AHB_MSB_RESP_ATTR 0x00000003 /* Master Response Attribute number */
3165 +#define PCIE_AHB_MSB_RESP_ATTR_S 0
3166 +#define PCIE_AHB_MSB_RESP_BAD_EOT 0x00000004 /* Master Response Badeot filed */
3167 +#define PCIE_AHB_MSB_RESP_BCM 0x00000008 /* Master Response BCM filed */
3168 +#define PCIE_AHB_MSB_RESP_EP 0x00000010 /* Master Response EP filed */
3169 +#define PCIE_AHB_MSB_RESP_TD 0x00000020 /* Master Response TD filed */
3170 +#define PCIE_AHB_MSB_RESP_FUN_NUM 0x000003C0 /* Master Response Function number */
3171 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S 6
3172 +
3173 +/* AHB Control Register, fixed bus enumeration exception */
3174 +#define PCIE_AHB_CTRL(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
3175 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS 0x00000001
3176 +
3177 +/* Interrupt Enalbe Register */
3178 +#define PCIE_IRNEN(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
3179 +#define PCIE_IRNCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
3180 +#define PCIE_IRNICR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
3181 +
3182 +/* PCIe interrupt enable/control/capture register definition */
3183 +#define PCIE_IRN_AER_REPORT 0x00000001 /* AER Interrupt */
3184 +#define PCIE_IRN_AER_MSIX 0x00000002 /* Advanced Error MSI-X Interrupt */
3185 +#define PCIE_IRN_PME 0x00000004 /* PME Interrupt */
3186 +#define PCIE_IRN_HOTPLUG 0x00000008 /* Hotplug Interrupt */
3187 +#define PCIE_IRN_RX_VDM_MSG 0x00000010 /* Vendor-Defined Message Interrupt */
3188 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG 0x00000020 /* Correctable Error Message Interrupt */
3189 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG 0x00000040 /* Non-fatal Error Message */
3190 +#define PCIE_IRN_RX_FATAL_ERR_MSG 0x00000080 /* Fatal Error Message */
3191 +#define PCIE_IRN_RX_PME_MSG 0x00000100 /* PME Message Interrupt */
3192 +#define PCIE_IRN_RX_PME_TURNOFF_ACK 0x00000200 /* PME Turnoff Ack Message Interrupt */
3193 +#define PCIE_IRN_AHB_BR_FATAL_ERR 0x00000400 /* AHB Fatal Error Interrupt */
3194 +#define PCIE_IRN_LINK_AUTO_BW_STATUS 0x00000800 /* Link Auto Bandwidth Status Interrupt */
3195 +#define PCIE_IRN_BW_MGT 0x00001000 /* Bandwidth Managment Interrupt */
3196 +#define PCIE_IRN_INTA 0x00002000 /* INTA */
3197 +#define PCIE_IRN_INTB 0x00004000 /* INTB */
3198 +#define PCIE_IRN_INTC 0x00008000 /* INTC */
3199 +#define PCIE_IRN_INTD 0x00010000 /* INTD */
3200 +#define PCIE_IRN_WAKEUP 0x00020000 /* Wake up Interrupt */
3201 +
3202 +#define PCIE_RC_CORE_COMBINED_INT (PCIE_IRN_AER_REPORT | PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
3203 + PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
3204 + PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
3205 + PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
3206 + PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
3207 +/* PCIe RC Configuration Register */
3208 +#define PCIE_VDID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
3209 +
3210 +/* Bit definition from pci_reg.h */
3211 +#define PCIE_PCICMDSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
3212 +#define PCIE_CCRID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
3213 +#define PCIE_CLSLTHTBR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
3214 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
3215 +#define PCIE_BAR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
3216 +#define PCIE_BAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
3217 +
3218 +#define PCIE_BNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
3219 +/* Bus Number Register bits */
3220 +#define PCIE_BNR_PRIMARY_BUS_NUM 0x000000FF
3221 +#define PCIE_BNR_PRIMARY_BUS_NUM_S 0
3222 +#define PCIE_PNR_SECONDARY_BUS_NUM 0x0000FF00
3223 +#define PCIE_PNR_SECONDARY_BUS_NUM_S 8
3224 +#define PCIE_PNR_SUB_BUS_NUM 0x00FF0000
3225 +#define PCIE_PNR_SUB_BUS_NUM_S 16
3226 +
3227 +/* IO Base/Limit Register bits */
3228 +#define PCIE_IOBLSECS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C) /* RC only */
3229 +#define PCIE_IOBLSECS_32BIT_IO_ADDR 0x00000001
3230 +#define PCIE_IOBLSECS_IO_BASE_ADDR 0x000000F0
3231 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S 4
3232 +#define PCIE_IOBLSECS_32BIT_IOLIMT 0x00000100
3233 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR 0x0000F000
3234 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S 12
3235 +
3236 +/* Non-prefetchable Memory Base/Limit Register bit */
3237 +#define PCIE_MBML(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20) /* RC only */
3238 +#define PCIE_MBML_MEM_BASE_ADDR 0x0000FFF0
3239 +#define PCIE_MBML_MEM_BASE_ADDR_S 4
3240 +#define PCIE_MBML_MEM_LIMIT_ADDR 0xFFF00000
3241 +#define PCIE_MBML_MEM_LIMIT_ADDR_S 20
3242 +
3243 +/* Prefetchable Memory Base/Limit Register bit */
3244 +#define PCIE_PMBL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24) /* RC only */
3245 +#define PCIE_PMBL_64BIT_ADDR 0x00000001
3246 +#define PCIE_PMBL_UPPER_12BIT 0x0000FFF0
3247 +#define PCIE_PMBL_UPPER_12BIT_S 4
3248 +#define PCIE_PMBL_E64MA 0x00010000
3249 +#define PCIE_PMBL_END_ADDR 0xFFF00000
3250 +#define PCIE_PMBL_END_ADDR_S 20
3251 +#define PCIE_PMBU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28) /* RC only */
3252 +#define PCIE_PMLU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C) /* RC only */
3253 +
3254 +/* I/O Base/Limit Upper 16 bits register */
3255 +#define PCIE_IO_BANDL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30) /* RC only */
3256 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE 0x0000FFFF
3257 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S 0
3258 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT 0xFFFF0000
3259 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S 16
3260 +
3261 +#define PCIE_CPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
3262 +#define PCIE_EBBAR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
3263 +
3264 +/* Interrupt and Secondary Bridge Control Register */
3265 +#define PCIE_INTRBCTRL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
3266 +
3267 +#define PCIE_INTRBCTRL_INT_LINE 0x000000FF
3268 +#define PCIE_INTRBCTRL_INT_LINE_S 0
3269 +#define PCIE_INTRBCTRL_INT_PIN 0x0000FF00
3270 +#define PCIE_INTRBCTRL_INT_PIN_S 8
3271 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE 0x00010000 /* #PERR */
3272 +#define PCIE_INTRBCTRL_SERR_ENABLE 0x00020000 /* #SERR */
3273 +#define PCIE_INTRBCTRL_ISA_ENABLE 0x00040000 /* ISA enable, IO 64KB only */
3274 +#define PCIE_INTRBCTRL_VGA_ENABLE 0x00080000 /* VGA enable */
3275 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE 0x00100000 /* VGA 16bit decode */
3276 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS 0x00400000 /* Secondary bus rest, hot rest, 1ms */
3277 +/* Others are read only */
3278 +enum {
3279 + PCIE_INTRBCTRL_INT_NON = 0,
3280 + PCIE_INTRBCTRL_INTA,
3281 + PCIE_INTRBCTRL_INTB,
3282 + PCIE_INTRBCTRL_INTC,
3283 + PCIE_INTRBCTRL_INTD,
3284 +};
3285 +
3286 +#define PCIE_PM_CAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
3287 +
3288 +/* Power Management Control and Status Register */
3289 +#define PCIE_PM_CSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
3290 +
3291 +#define PCIE_PM_CSR_POWER_STATE 0x00000003 /* Power State */
3292 +#define PCIE_PM_CSR_POWER_STATE_S 0
3293 +#define PCIE_PM_CSR_SW_RST 0x00000008 /* Soft Reset Enabled */
3294 +#define PCIE_PM_CSR_PME_ENABLE 0x00000100 /* PME Enable */
3295 +#define PCIE_PM_CSR_PME_STATUS 0x00008000 /* PME status */
3296 +
3297 +/* MSI Capability Register for EP */
3298 +#define PCIE_MCAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
3299 +
3300 +#define PCIE_MCAPR_MSI_CAP_ID 0x000000FF /* MSI Capability ID */
3301 +#define PCIE_MCAPR_MSI_CAP_ID_S 0
3302 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR 0x0000FF00 /* Next Capability Pointer */
3303 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S 8
3304 +#define PCIE_MCAPR_MSI_ENABLE 0x00010000 /* MSI Enable */
3305 +#define PCIE_MCAPR_MULTI_MSG_CAP 0x000E0000 /* Multiple Message Capable */
3306 +#define PCIE_MCAPR_MULTI_MSG_CAP_S 17
3307 +#define PCIE_MCAPR_MULTI_MSG_ENABLE 0x00700000 /* Multiple Message Enable */
3308 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S 20
3309 +#define PCIE_MCAPR_ADDR64_CAP 0X00800000 /* 64-bit Address Capable */
3310 +
3311 +/* MSI Message Address Register */
3312 +#define PCIE_MA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
3313 +
3314 +#define PCIE_MA_ADDR_MASK 0xFFFFFFFC /* Message Address */
3315 +
3316 +/* MSI Message Upper Address Register */
3317 +#define PCIE_MUA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
3318 +
3319 +/* MSI Message Data Register */
3320 +#define PCIE_MD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
3321 +
3322 +#define PCIE_MD_DATA 0x0000FFFF /* Message Data */
3323 +#define PCIE_MD_DATA_S 0
3324 +
3325 +/* PCI Express Capability Register */
3326 +#define PCIE_XCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
3327 +
3328 +#define PCIE_XCAP_ID 0x000000FF /* PCI Express Capability ID */
3329 +#define PCIE_XCAP_ID_S 0
3330 +#define PCIE_XCAP_NEXT_CAP 0x0000FF00 /* Next Capability Pointer */
3331 +#define PCIE_XCAP_NEXT_CAP_S 8
3332 +#define PCIE_XCAP_VER 0x000F0000 /* PCI Express Capability Version */
3333 +#define PCIE_XCAP_VER_S 16
3334 +#define PCIE_XCAP_DEV_PORT_TYPE 0x00F00000 /* Device Port Type */
3335 +#define PCIE_XCAP_DEV_PORT_TYPE_S 20
3336 +#define PCIE_XCAP_SLOT_IMPLEMENTED 0x01000000 /* Slot Implemented */
3337 +#define PCIE_XCAP_MSG_INT_NUM 0x3E000000 /* Interrupt Message Number */
3338 +#define PCIE_XCAP_MSG_INT_NUM_S 25
3339 +
3340 +/* Device Capability Register */
3341 +#define PCIE_DCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
3342 +
3343 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE 0x00000007 /* Max Payload size */
3344 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S 0
3345 +#define PCIE_DCAP_PHANTOM_FUNC 0x00000018 /* Phanton Function, not supported */
3346 +#define PCIE_DCAP_PHANTOM_FUNC_S 3
3347 +#define PCIE_DCAP_EXT_TAG 0x00000020 /* Extended Tag Field */
3348 +#define PCIE_DCAP_EP_L0S_LATENCY 0x000001C0 /* EP L0s latency only */
3349 +#define PCIE_DCAP_EP_L0S_LATENCY_S 6
3350 +#define PCIE_DCAP_EP_L1_LATENCY 0x00000E00 /* EP L1 latency only */
3351 +#define PCIE_DCAP_EP_L1_LATENCY_S 9
3352 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT 0x00008000 /* Role Based ERR */
3353 +
3354 +/* Maximum payload size supported */
3355 +enum {
3356 + PCIE_MAX_PAYLOAD_128 = 0,
3357 + PCIE_MAX_PAYLOAD_256,
3358 + PCIE_MAX_PAYLOAD_512,
3359 + PCIE_MAX_PAYLOAD_1024,
3360 + PCIE_MAX_PAYLOAD_2048,
3361 + PCIE_MAX_PAYLOAD_4096,
3362 +};
3363 +
3364 +/* Device Control and Status Register */
3365 +#define PCIE_DCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
3366 +
3367 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN 0x00000001 /* COR-ERR */
3368 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN 0x00000002 /* Non-fatal ERR */
3369 +#define PCIE_DCTLSTS_FATAL_ERR_EN 0x00000004 /* Fatal ERR */
3370 +#define PCIE_DCTLSYS_UR_REQ_EN 0x00000008 /* UR ERR */
3371 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN 0x00000010 /* Enable relaxing ordering */
3372 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE 0x000000E0 /* Max payload mask */
3373 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S 5
3374 +#define PCIE_DCTLSTS_EXT_TAG_EN 0x00000100 /* Extended tag field */
3375 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN 0x00000200 /* Phantom Function Enable */
3376 +#define PCIE_DCTLSTS_AUX_PM_EN 0x00000400 /* AUX Power PM Enable */
3377 +#define PCIE_DCTLSTS_NO_SNOOP_EN 0x00000800 /* Enable no snoop, except root port*/
3378 +#define PCIE_DCTLSTS_MAX_READ_SIZE 0x00007000 /* Max Read Request size*/
3379 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S 12
3380 +#define PCIE_DCTLSTS_CORRECTABLE_ERR 0x00010000 /* COR-ERR Detected */
3381 +#define PCIE_DCTLSTS_NONFATAL_ERR 0x00020000 /* Non-Fatal ERR Detected */
3382 +#define PCIE_DCTLSTS_FATAL_ER 0x00040000 /* Fatal ERR Detected */
3383 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ 0x00080000 /* UR Detected */
3384 +#define PCIE_DCTLSTS_AUX_POWER 0x00100000 /* Aux Power Detected */
3385 +#define PCIE_DCTLSTS_TRANSACT_PENDING 0x00200000 /* Transaction pending */
3386 +
3387 +#define PCIE_DCTLSTS_ERR_EN (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
3388 + PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
3389 + PCIE_DCTLSYS_UR_REQ_EN)
3390 +
3391 +/* Link Capability Register */
3392 +#define PCIE_LCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
3393 +#define PCIE_LCAP_MAX_LINK_SPEED 0x0000000F /* Max link speed, 0x1 by default */
3394 +#define PCIE_LCAP_MAX_LINK_SPEED_S 0
3395 +#define PCIE_LCAP_MAX_LENGTH_WIDTH 0x000003F0 /* Maxium Length Width */
3396 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S 4
3397 +#define PCIE_LCAP_ASPM_LEVEL 0x00000C00 /* Active State Link PM Support */
3398 +#define PCIE_LCAP_ASPM_LEVEL_S 10
3399 +#define PCIE_LCAP_L0S_EIXT_LATENCY 0x00007000 /* L0s Exit Latency */
3400 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S 12
3401 +#define PCIE_LCAP_L1_EXIT_LATENCY 0x00038000 /* L1 Exit Latency */
3402 +#define PCIE_LCAP_L1_EXIT_LATENCY_S 15
3403 +#define PCIE_LCAP_CLK_PM 0x00040000 /* Clock Power Management */
3404 +#define PCIE_LCAP_SDER 0x00080000 /* Surprise Down Error Reporting */
3405 +#define PCIE_LCAP_DLL_ACTIVE_REPROT 0x00100000 /* Data Link Layer Active Reporting Capable */
3406 +#define PCIE_LCAP_PORT_NUM 0xFF0000000 /* Port number */
3407 +#define PCIE_LCAP_PORT_NUM_S 24
3408 +
3409 +/* Maximum Length width definition */
3410 +#define PCIE_MAX_LENGTH_WIDTH_RES 0x00
3411 +#define PCIE_MAX_LENGTH_WIDTH_X1 0x01 /* Default */
3412 +#define PCIE_MAX_LENGTH_WIDTH_X2 0x02
3413 +#define PCIE_MAX_LENGTH_WIDTH_X4 0x04
3414 +#define PCIE_MAX_LENGTH_WIDTH_X8 0x08
3415 +#define PCIE_MAX_LENGTH_WIDTH_X12 0x0C
3416 +#define PCIE_MAX_LENGTH_WIDTH_X16 0x10
3417 +#define PCIE_MAX_LENGTH_WIDTH_X32 0x20
3418 +
3419 +/* Active State Link PM definition */
3420 +enum {
3421 + PCIE_ASPM_RES0 = 0,
3422 + PCIE_ASPM_L0S_ENTRY_SUPPORT, /* L0s */
3423 + PCIE_ASPM_RES1,
3424 + PCIE_ASPM_L0S_L1_ENTRY_SUPPORT, /* L0s and L1, default */
3425 +};
3426 +
3427 +/* L0s Exit Latency definition */
3428 +enum {
3429 + PCIE_L0S_EIXT_LATENCY_L64NS = 0, /* < 64 ns */
3430 + PCIE_L0S_EIXT_LATENCY_B64A128, /* > 64 ns < 128 ns */
3431 + PCIE_L0S_EIXT_LATENCY_B128A256, /* > 128 ns < 256 ns */
3432 + PCIE_L0S_EIXT_LATENCY_B256A512, /* > 256 ns < 512 ns */
3433 + PCIE_L0S_EIXT_LATENCY_B512TO1U, /* > 512 ns < 1 us */
3434 + PCIE_L0S_EIXT_LATENCY_B1A2U, /* > 1 us < 2 us */
3435 + PCIE_L0S_EIXT_LATENCY_B2A4U, /* > 2 us < 4 us */
3436 + PCIE_L0S_EIXT_LATENCY_M4US, /* > 4 us */
3437 +};
3438 +
3439 +/* L1 Exit Latency definition */
3440 +enum {
3441 + PCIE_L1_EXIT_LATENCY_L1US = 0, /* < 1 us */
3442 + PCIE_L1_EXIT_LATENCY_B1A2, /* > 1 us < 2 us */
3443 + PCIE_L1_EXIT_LATENCY_B2A4, /* > 2 us < 4 us */
3444 + PCIE_L1_EXIT_LATENCY_B4A8, /* > 4 us < 8 us */
3445 + PCIE_L1_EXIT_LATENCY_B8A16, /* > 8 us < 16 us */
3446 + PCIE_L1_EXIT_LATENCY_B16A32, /* > 16 us < 32 us */
3447 + PCIE_L1_EXIT_LATENCY_B32A64, /* > 32 us < 64 us */
3448 + PCIE_L1_EXIT_LATENCY_M64US, /* > 64 us */
3449 +};
3450 +
3451 +/* Link Control and Status Register */
3452 +#define PCIE_LCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
3453 +#define PCIE_LCTLSTS_ASPM_ENABLE 0x00000003 /* Active State Link PM Control */
3454 +#define PCIE_LCTLSTS_ASPM_ENABLE_S 0
3455 +#define PCIE_LCTLSTS_RCB128 0x00000008 /* Read Completion Boundary 128*/
3456 +#define PCIE_LCTLSTS_LINK_DISABLE 0x00000010 /* Link Disable */
3457 +#define PCIE_LCTLSTS_RETRIAN_LINK 0x00000020 /* Retrain Link */
3458 +#define PCIE_LCTLSTS_COM_CLK_CFG 0x00000040 /* Common Clock Configuration */
3459 +#define PCIE_LCTLSTS_EXT_SYNC 0x00000080 /* Extended Synch */
3460 +#define PCIE_LCTLSTS_CLK_PM_EN 0x00000100 /* Enable Clock Powerm Management */
3461 +#define PCIE_LCTLSTS_LINK_SPEED 0x000F0000 /* Link Speed */
3462 +#define PCIE_LCTLSTS_LINK_SPEED_S 16
3463 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH 0x03F00000 /* Negotiated Link Width */
3464 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
3465 +#define PCIE_LCTLSTS_RETRAIN_PENDING 0x08000000 /* Link training is ongoing */
3466 +#define PCIE_LCTLSTS_SLOT_CLK_CFG 0x10000000 /* Slot Clock Configuration */
3467 +#define PCIE_LCTLSTS_DLL_ACTIVE 0x20000000 /* Data Link Layer Active */
3468 +
3469 +/* Slot Capabilities Register */
3470 +#define PCIE_SLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
3471 +
3472 +/* Slot Capabilities */
3473 +#define PCIE_SLCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
3474 +
3475 +/* Root Control and Capability Register */
3476 +#define PCIE_RCTLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
3477 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR 0x00000001 /* #SERR on COR-ERR */
3478 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR 0x00000002 /* #SERR on Non-Fatal ERR */
3479 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR 0x00000004 /* #SERR on Fatal ERR */
3480 +#define PCIE_RCTLCAP_PME_INT_EN 0x00000008 /* PME Interrupt Enable */
3481 +#define PCIE_RCTLCAP_SERR_ENABLE (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
3482 + PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
3483 +/* Root Status Register */
3484 +#define PCIE_RSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
3485 +#define PCIE_RSTS_PME_REQ_ID 0x0000FFFF /* PME Request ID */
3486 +#define PCIE_RSTS_PME_REQ_ID_S 0
3487 +#define PCIE_RSTS_PME_STATUS 0x00010000 /* PME Status */
3488 +#define PCIE_RSTS_PME_PENDING 0x00020000 /* PME Pending */
3489 +
3490 +/* PCI Express Enhanced Capability Header */
3491 +#define PCIE_ENHANCED_CAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
3492 +#define PCIE_ENHANCED_CAP_ID 0x0000FFFF /* PCI Express Extended Capability ID */
3493 +#define PCIE_ENHANCED_CAP_ID_S 0
3494 +#define PCIE_ENHANCED_CAP_VER 0x000F0000 /* Capability Version */
3495 +#define PCIE_ENHANCED_CAP_VER_S 16
3496 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET 0xFFF00000 /* Next Capability Offset */
3497 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S 20
3498 +
3499 +/* Uncorrectable Error Status Register */
3500 +#define PCIE_UES_R(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
3501 +#define PCIE_DATA_LINK_PROTOCOL_ERR 0x00000010 /* Data Link Protocol Error Status */
3502 +#define PCIE_SURPRISE_DOWN_ERROR 0x00000020 /* Surprise Down Error Status */
3503 +#define PCIE_POISONED_TLP 0x00001000 /* Poisoned TLP Status */
3504 +#define PCIE_FC_PROTOCOL_ERR 0x00002000 /* Flow Control Protocol Error Status */
3505 +#define PCIE_COMPLETION_TIMEOUT 0x00004000 /* Completion Timeout Status */
3506 +#define PCIE_COMPLETOR_ABORT 0x00008000 /* Completer Abort Error */
3507 +#define PCIE_UNEXPECTED_COMPLETION 0x00010000 /* Unexpected Completion Status */
3508 +#define PCIE_RECEIVER_OVERFLOW 0x00020000 /* Receive Overflow Status */
3509 +#define PCIE_MALFORNED_TLP 0x00040000 /* Malformed TLP Stauts */
3510 +#define PCIE_ECRC_ERR 0x00080000 /* ECRC Error Stauts */
3511 +#define PCIE_UR_REQ 0x00100000 /* Unsupported Request Error Status */
3512 +#define PCIE_ALL_UNCORRECTABLE_ERR (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
3513 + PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT | \
3514 + PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
3515 + PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
3516 +
3517 +/* Uncorrectable Error Mask Register, Mask means no report */
3518 +#define PCIE_UEMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
3519 +
3520 +/* Uncorrectable Error Severity Register */
3521 +#define PCIE_UESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
3522 +
3523 +/* Correctable Error Status Register */
3524 +#define PCIE_CESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
3525 +#define PCIE_RX_ERR 0x00000001 /* Receive Error Status */
3526 +#define PCIE_BAD_TLP 0x00000040 /* Bad TLP Status */
3527 +#define PCIE_BAD_DLLP 0x00000080 /* Bad DLLP Status */
3528 +#define PCIE_REPLAY_NUM_ROLLOVER 0x00000100 /* Replay Number Rollover Status */
3529 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR 0x00001000 /* Reply Timer Timeout Status */
3530 +#define PCIE_ADVISORY_NONFTAL_ERR 0x00002000 /* Advisory Non-Fatal Error Status */
3531 +#define PCIE_CORRECTABLE_ERR (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
3532 + PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
3533 +
3534 +/* Correctable Error Mask Register */
3535 +#define PCIE_CEMR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
3536 +
3537 +/* Advanced Error Capabilities and Control Register */
3538 +#define PCIE_AECCR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
3539 +#define PCIE_AECCR_FIRST_ERR_PTR 0x0000001F /* First Error Pointer */
3540 +#define PCIE_AECCR_FIRST_ERR_PTR_S 0
3541 +#define PCIE_AECCR_ECRC_GEN_CAP 0x00000020 /* ECRC Generation Capable */
3542 +#define PCIE_AECCR_ECRC_GEN_EN 0x00000040 /* ECRC Generation Enable */
3543 +#define PCIE_AECCR_ECRC_CHECK_CAP 0x00000080 /* ECRC Check Capable */
3544 +#define PCIE_AECCR_ECRC_CHECK_EN 0x00000100 /* ECRC Check Enable */
3545 +
3546 +/* Header Log Register 1 */
3547 +#define PCIE_HLR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
3548 +
3549 +/* Header Log Register 2 */
3550 +#define PCIE_HLR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
3551 +
3552 +/* Header Log Register 3 */
3553 +#define PCIE_HLR3(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
3554 +
3555 +/* Header Log Register 4 */
3556 +#define PCIE_HLR4(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
3557 +
3558 +/* Root Error Command Register */
3559 +#define PCIE_RECR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
3560 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN 0x00000001 /* COR-ERR */
3561 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN 0x00000002 /* Non-Fatal ERR */
3562 +#define PCIE_RECR_FATAL_ERR_REPORT_EN 0x00000004 /* Fatal ERR */
3563 +#define PCIE_RECR_ERR_REPORT_EN (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
3564 + PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
3565 +
3566 +/* Root Error Status Register */
3567 +#define PCIE_RESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
3568 +#define PCIE_RESR_CORRECTABLE_ERR 0x00000001 /* COR-ERR Receveid */
3569 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR 0x00000002 /* Multiple COR-ERR Received */
3570 +#define PCIE_RESR_FATAL_NOFATAL_ERR 0x00000004 /* ERR Fatal/Non-Fatal Received */
3571 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR 0x00000008 /* Multiple ERR Fatal/Non-Fatal Received */
3572 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR 0x00000010 /* First UN-COR Fatal */
3573 +#define PCIR_RESR_NON_FATAL_ERR 0x00000020 /* Non-Fatal Error Message Received */
3574 +#define PCIE_RESR_FATAL_ERR 0x00000040 /* Fatal Message Received */
3575 +#define PCIE_RESR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
3576 +#define PCIE_RESR_AER_INT_MSG_NUM_S 27
3577 +
3578 +/* Error Source Indentification Register */
3579 +#define PCIE_ESIR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
3580 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID 0x0000FFFF
3581 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S 0
3582 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID 0xFFFF0000
3583 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S 16
3584 +
3585 +/* VC Enhanced Capability Header */
3586 +#define PCIE_VC_ECH(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
3587 +
3588 +/* Port VC Capability Register */
3589 +#define PCIE_PVC1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
3590 +#define PCIE_PVC1_EXT_VC_CNT 0x00000007 /* Extended VC Count */
3591 +#define PCIE_PVC1_EXT_VC_CNT_S 0
3592 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT 0x00000070 /* Low Priority Extended VC Count */
3593 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S 4
3594 +#define PCIE_PVC1_REF_CLK 0x00000300 /* Reference Clock */
3595 +#define PCIE_PVC1_REF_CLK_S 8
3596 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE 0x00000C00 /* Port Arbitration Table Entry Size */
3597 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S 10
3598 +
3599 +/* Extended Virtual Channel Count Defintion */
3600 +#define PCIE_EXT_VC_CNT_MIN 0
3601 +#define PCIE_EXT_VC_CNT_MAX 7
3602 +
3603 +/* Port Arbitration Table Entry Size Definition */
3604 +enum {
3605 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
3606 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
3607 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
3608 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
3609 +};
3610 +
3611 +/* Port VC Capability Register 2 */
3612 +#define PCIE_PVC2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
3613 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR 0x00000001 /* HW Fixed arbitration, 16 phase WRR */
3614 +#define PCIE_PVC2_VC_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
3615 +#define PCIE_PVC2_VC_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
3616 +#define PCIE_PVC2_VC_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
3617 +#define PCIE_PVC2_VC_ARB_WRR 0x0000000F
3618 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET 0xFF000000 /* VC arbitration table offset, not support */
3619 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S 24
3620 +
3621 +/* Port VC Control and Status Register */
3622 +#define PCIE_PVCCRSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
3623 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB 0x00000001 /* Load VC Arbitration Table */
3624 +#define PCIE_PVCCRSR_VC_ARB_SEL 0x0000000E /* VC Arbitration Select */
3625 +#define PCIE_PVCCRSR_VC_ARB_SEL_S 1
3626 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS 0x00010000 /* Arbitration Status */
3627 +
3628 +/* VC0 Resource Capability Register */
3629 +#define PCIE_VC0_RC(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
3630 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED 0x00000001 /* HW Fixed arbitration */
3631 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
3632 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
3633 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
3634 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR 0x00000010 /* Time-based 128 phase WRR */
3635 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR 0x00000020 /* Time-based 256 phase WRR */
3636 +#define PCIE_VC0_RC_PORT_ARB (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
3637 + PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
3638 + PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
3639 +
3640 +#define PCIE_VC0_RC_REJECT_SNOOP 0x00008000 /* Reject Snoop Transactioin */
3641 +#define PCIE_VC0_RC_MAX_TIMESLOTS 0x007F0000 /* Maximum time Slots */
3642 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S 16
3643 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET 0xFF000000 /* Port Arbitration Table Offset */
3644 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S 24
3645 +
3646 +/* VC0 Resource Control Register */
3647 +#define PCIE_VC0_RC0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
3648 +#define PCIE_VC0_RC0_TVM0 0x00000001 /* TC0 and VC0 */
3649 +#define PCIE_VC0_RC0_TVM1 0x00000002 /* TC1 and VC1 */
3650 +#define PCIE_VC0_RC0_TVM2 0x00000004 /* TC2 and VC2 */
3651 +#define PCIE_VC0_RC0_TVM3 0x00000008 /* TC3 and VC3 */
3652 +#define PCIE_VC0_RC0_TVM4 0x00000010 /* TC4 and VC4 */
3653 +#define PCIE_VC0_RC0_TVM5 0x00000020 /* TC5 and VC5 */
3654 +#define PCIE_VC0_RC0_TVM6 0x00000040 /* TC6 and VC6 */
3655 +#define PCIE_VC0_RC0_TVM7 0x00000080 /* TC7 and VC7 */
3656 +#define PCIE_VC0_RC0_TC_VC 0x000000FF /* TC/VC mask */
3657 +
3658 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB 0x00010000 /* Load Port Arbitration Table */
3659 +#define PCIE_VC0_RC0_PORT_ARB_SEL 0x000E0000 /* Port Arbitration Select */
3660 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S 17
3661 +#define PCIE_VC0_RC0_VC_ID 0x07000000 /* VC ID */
3662 +#define PCIE_VC0_RC0_VC_ID_S 24
3663 +#define PCIE_VC0_RC0_VC_EN 0x80000000 /* VC Enable */
3664 +
3665 +/* VC0 Resource Status Register */
3666 +#define PCIE_VC0_RSR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
3667 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS 0x00010000 /* Port Arbitration Table Status,not used */
3668 +#define PCIE_VC0_RSR0_VC_NEG_PENDING 0x00020000 /* VC Negotiation Pending */
3669 +
3670 +/* Ack Latency Timer and Replay Timer Register */
3671 +#define PCIE_ALTRT(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
3672 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT 0x0000FFFF /* Round Trip Latency Time Limit */
3673 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
3674 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT 0xFFFF0000 /* Replay Time Limit */
3675 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S 16
3676 +
3677 +/* Other Message Register */
3678 +#define PCIE_OMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
3679 +
3680 +/* Port Force Link Register */
3681 +#define PCIE_PFLR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
3682 +#define PCIE_PFLR_LINK_NUM 0x000000FF /* Link Number */
3683 +#define PCIE_PFLR_LINK_NUM_S 0
3684 +#define PCIE_PFLR_FORCE_LINK 0x00008000 /* Force link */
3685 +#define PCIE_PFLR_LINK_STATE 0x003F0000 /* Link State */
3686 +#define PCIE_PFLR_LINK_STATE_S 16
3687 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT 0xFF000000 /* Low Power Entrance Count, only for EP */
3688 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S 24
3689 +
3690 +/* Ack Frequency Register */
3691 +#define PCIE_AFR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
3692 +#define PCIE_AFR_AF 0x000000FF /* Ack Frequency */
3693 +#define PCIE_AFR_AF_S 0
3694 +#define PCIE_AFR_FTS_NUM 0x0000FF00 /* The number of Fast Training Sequence from L0S to L0 */
3695 +#define PCIE_AFR_FTS_NUM_S 8
3696 +#define PCIE_AFR_COM_FTS_NUM 0x00FF0000 /* N_FTS; when common clock is used*/
3697 +#define PCIE_AFR_COM_FTS_NUM_S 16
3698 +#define PCIE_AFR_L0S_ENTRY_LATENCY 0x07000000 /* L0s Entrance Latency */
3699 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S 24
3700 +#define PCIE_AFR_L1_ENTRY_LATENCY 0x38000000 /* L1 Entrance Latency */
3701 +#define PCIE_AFR_L1_ENTRY_LATENCY_S 27
3702 +#define PCIE_AFR_FTS_NUM_DEFAULT 32
3703 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT 7
3704 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT 5
3705 +
3706 +/* Port Link Control Register */
3707 +#define PCIE_PLCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
3708 +#define PCIE_PLCR_OTHER_MSG_REQ 0x00000001 /* Other Message Request */
3709 +#define PCIE_PLCR_SCRAMBLE_DISABLE 0x00000002 /* Scramble Disable */
3710 +#define PCIE_PLCR_LOOPBACK_EN 0x00000004 /* Loopback Enable */
3711 +#define PCIE_PLCR_LTSSM_HOT_RST 0x00000008 /* Force LTSSM to the hot reset */
3712 +#define PCIE_PLCR_DLL_LINK_EN 0x00000020 /* Enable Link initialization */
3713 +#define PCIE_PLCR_FAST_LINK_SIM_EN 0x00000080 /* Sets all internal timers to fast mode for simulation purposes */
3714 +#define PCIE_PLCR_LINK_MODE 0x003F0000 /* Link Mode Enable Mask */
3715 +#define PCIE_PLCR_LINK_MODE_S 16
3716 +#define PCIE_PLCR_CORRUPTED_CRC_EN 0x02000000 /* Enabled Corrupt CRC */
3717 +
3718 +/* Lane Skew Register */
3719 +#define PCIE_LSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
3720 +#define PCIE_LSR_LANE_SKEW_NUM 0x00FFFFFF /* Insert Lane Skew for Transmit, not applicable */
3721 +#define PCIE_LSR_LANE_SKEW_NUM_S 0
3722 +#define PCIE_LSR_FC_DISABLE 0x01000000 /* Disable of Flow Control */
3723 +#define PCIE_LSR_ACKNAK_DISABLE 0x02000000 /* Disable of Ack/Nak */
3724 +#define PCIE_LSR_LANE_DESKEW_DISABLE 0x80000000 /* Disable of Lane-to-Lane Skew */
3725 +
3726 +/* Symbol Number Register */
3727 +#define PCIE_SNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
3728 +#define PCIE_SNR_TS 0x0000000F /* Number of TS Symbol */
3729 +#define PCIE_SNR_TS_S 0
3730 +#define PCIE_SNR_SKP 0x00000700 /* Number of SKP Symbol */
3731 +#define PCIE_SNR_SKP_S 8
3732 +#define PCIE_SNR_REPLAY_TIMER 0x0007C000 /* Timer Modifier for Replay Timer */
3733 +#define PCIE_SNR_REPLAY_TIMER_S 14
3734 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER 0x00F80000 /* Timer Modifier for Ack/Nak Latency Timer */
3735 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S 19
3736 +#define PCIE_SNR_FC_TIMER 0x1F000000 /* Timer Modifier for Flow Control Watchdog Timer */
3737 +#define PCIE_SNR_FC_TIMER_S 28
3738 +
3739 +/* Symbol Timer Register and Filter Mask Register 1 */
3740 +#define PCIE_STRFMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
3741 +#define PCIE_STRFMR_SKP_INTERVAL 0x000007FF /* SKP lnterval Value */
3742 +#define PCIE_STRFMR_SKP_INTERVAL_S 0
3743 +#define PCIE_STRFMR_FC_WDT_DISABLE 0x00008000 /* Disable of FC Watchdog Timer */
3744 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK 0x00010000 /* Mask Function Mismatch Filtering for Incoming Requests */
3745 +#define PCIE_STRFMR_POISONED_TLP_OK 0x00020000 /* Mask Poisoned TLP Filtering */
3746 +#define PCIE_STRFMR_BAR_MATCH_OK 0x00040000 /* Mask BAR Match Filtering */
3747 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK 0x00080000 /* Mask Type 1 Configuration Request Filtering */
3748 +#define PCIE_STRFMR_LOCKED_REQ_OK 0x00100000 /* Mask Locked Request Filtering */
3749 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK 0x00200000 /* Mask Tag Error Rules for Received Completions */
3750 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000 /* Mask Requester ID Mismatch Error for Received Completions */
3751 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK 0x00800000 /* Mask Function Mismatch Error for Received Completions */
3752 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK 0x01000000 /* Mask Traffic Class Mismatch Error for Received Completions */
3753 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK 0x02000000 /* Mask Attribute Mismatch Error for Received Completions */
3754 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK 0x04000000 /* Mask Length Mismatch Error for Received Completions */
3755 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK 0x08000000 /* Mask ECRC Error Filtering */
3756 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK 0x10000000 /* Mask ECRC Error Filtering for Completions */
3757 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP 0x20000000 /* Send Message TLPs */
3758 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE 0x40000000 /* Mask Filtering of received I/O Requests */
3759 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE 0x80000000 /* Mask Filtering of Received Configuration Requests */
3760 +
3761 +#define PCIE_DEF_SKP_INTERVAL 700 /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
3762 +
3763 +/* Filter Masker Register 2 */
3764 +#define PCIE_FMR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
3765 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1 0x00000001 /* Mask RADM Filtering and Error Handling Rules */
3766 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 0x00000002 /* Mask RADM Filtering and Error Handling Rules */
3767 +
3768 +/* Debug Register 0 */
3769 +#define PCIE_DBR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
3770 +
3771 +/* Debug Register 1 */
3772 +#define PCIE_DBR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
3773 +
3774 +/* Transmit Posted FC Credit Status Register */
3775 +#define PCIE_TPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
3776 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS 0x00000FFF /* Transmit Posted Data FC Credits */
3777 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S 0
3778 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS 0x000FF000 /* Transmit Posted Header FC Credits */
3779 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S 12
3780 +
3781 +/* Transmit Non-Posted FC Credit Status */
3782 +#define PCIE_TNPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
3783 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS 0x00000FFF /* Transmit Non-Posted Data FC Credits */
3784 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S 0
3785 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS 0x000FF000 /* Transmit Non-Posted Header FC Credits */
3786 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S 12
3787 +
3788 +/* Transmit Complete FC Credit Status Register */
3789 +#define PCIE_TCFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
3790 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS 0x00000FFF /* Transmit Completion Data FC Credits */
3791 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S 0
3792 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS 0x000FF000 /* Transmit Completion Header FC Credits */
3793 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S 12
3794 +
3795 +/* Queue Status Register */
3796 +#define PCIE_QSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
3797 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL 0x00000001 /* Received TLP FC Credits Not Returned */
3798 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY 0x00000002 /* Transmit Retry Buffer Not Empty */
3799 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY 0x00000004 /* Received Queue Not Empty */
3800 +
3801 +/* VC Transmit Arbitration Register 1 */
3802 +#define PCIE_VCTAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
3803 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0 0x000000FF /* WRR Weight for VC0 */
3804 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1 0x0000FF00 /* WRR Weight for VC1 */
3805 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2 0x00FF0000 /* WRR Weight for VC2 */
3806 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3 0xFF000000 /* WRR Weight for VC3 */
3807 +
3808 +/* VC Transmit Arbitration Register 2 */
3809 +#define PCIE_VCTAR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
3810 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4 0x000000FF /* WRR Weight for VC4 */
3811 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5 0x0000FF00 /* WRR Weight for VC5 */
3812 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6 0x00FF0000 /* WRR Weight for VC6 */
3813 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7 0xFF000000 /* WRR Weight for VC7 */
3814 +
3815 +/* VC0 Posted Receive Queue Control Register */
3816 +#define PCIE_VC0_PRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
3817 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS 0x00000FFF /* VC0 Posted Data Credits */
3818 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S 0
3819 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS 0x000FF000 /* VC0 Posted Header Credits */
3820 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S 12
3821 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE 0x00E00000 /* VC0 Posted TLP Queue Mode */
3822 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S 20
3823 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER 0x40000000 /* TLP Type Ordering for VC0 */
3824 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER 0x80000000 /* VC0 Ordering for Receive Queues */
3825 +
3826 +/* VC0 Non-Posted Receive Queue Control */
3827 +#define PCIE_VC0_NPRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
3828 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS 0x00000FFF /* VC0 Non-Posted Data Credits */
3829 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S 0
3830 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS 0x000FF000 /* VC0 Non-Posted Header Credits */
3831 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S 12
3832 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE 0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
3833 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S 20
3834 +
3835 +/* VC0 Completion Receive Queue Control */
3836 +#define PCIE_VC0_CRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
3837 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS 0x00000FFF /* VC0 Completion TLP Queue Mode */
3838 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S 0
3839 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS 0x000FF000 /* VC0 Completion Header Credits */
3840 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S 12
3841 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE 0x00E00000 /* VC0 Completion Data Credits */
3842 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S 21
3843 +
3844 +/* Applicable to the above three registers */
3845 +enum {
3846 + PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
3847 + PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH = 2,
3848 + PCIE_VC0_TLP_QUEUE_MODE_BYPASS = 4,
3849 +};
3850 +
3851 +/* VC0 Posted Buffer Depth Register */
3852 +#define PCIE_VC0_PBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
3853 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Posted Data Queue Depth */
3854 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S 0
3855 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Posted Header Queue Depth */
3856 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S 16
3857 +
3858 +/* VC0 Non-Posted Buffer Depth Register */
3859 +#define PCIE_VC0_NPBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
3860 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Non-Posted Data Queue Depth */
3861 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S 0
3862 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
3863 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S 16
3864 +
3865 +/* VC0 Completion Buffer Depth Register */
3866 +#define PCIE_VC0_CBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
3867 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES 0x00003FFF /* C0 Completion Data Queue Depth */
3868 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S 0
3869 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Completion Header Queue Depth */
3870 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S 16
3871 +
3872 +/* PHY Status Register, all zeros in VR9 */
3873 +#define PCIE_PHYSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
3874 +
3875 +/* PHY Control Register, all zeros in VR9 */
3876 +#define PCIE_PHYCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
3877 +
3878 +/*
3879 + * PCIe PDI PHY register definition, suppose all the following
3880 + * stuff is confidential.
3881 + * XXX, detailed bit definition
3882 + */
3883 +#define PCIE_PHY_PLL_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
3884 +#define PCIE_PHY_PLL_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
3885 +#define PCIE_PHY_PLL_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
3886 +#define PCIE_PHY_PLL_CTRL4(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
3887 +#define PCIE_PHY_PLL_CTRL5(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
3888 +#define PCIE_PHY_PLL_CTRL6(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
3889 +#define PCIE_PHY_PLL_CTRL7(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
3890 +#define PCIE_PHY_PLL_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
3891 +#define PCIE_PHY_PLL_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
3892 +#define PCIE_PHY_PLL_A_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
3893 +#define PCIE_PHY_PLL_STATUS(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
3894 +
3895 +#define PCIE_PHY_TX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
3896 +#define PCIE_PHY_TX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
3897 +#define PCIE_PHY_TX1_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
3898 +#define PCIE_PHY_TX1_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
3899 +#define PCIE_PHY_TX1_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
3900 +#define PCIE_PHY_TX1_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
3901 +#define PCIE_PHY_TX1_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
3902 +#define PCIE_PHY_TX1_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
3903 +
3904 +#define PCIE_PHY_TX2_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
3905 +#define PCIE_PHY_TX2_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
3906 +#define PCIE_PHY_TX2_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
3907 +#define PCIE_PHY_TX2_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
3908 +#define PCIE_PHY_TX2_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
3909 +#define PCIE_PHY_TX2_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
3910 +#define PCIE_PHY_TX2_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
3911 +
3912 +#define PCIE_PHY_RX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
3913 +#define PCIE_PHY_RX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
3914 +#define PCIE_PHY_RX1_CDR(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
3915 +#define PCIE_PHY_RX1_EI(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
3916 +#define PCIE_PHY_RX1_A_CTRL(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
3917 +
3918 +/* Interrupt related stuff */
3919 +#define PCIE_LEGACY_DISABLE 0
3920 +#define PCIE_LEGACY_INTA 1
3921 +#define PCIE_LEGACY_INTB 2
3922 +#define PCIE_LEGACY_INTC 3
3923 +#define PCIE_LEGACY_INTD 4
3924 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
3925 +
3926 +#endif /* IFXMIPS_PCIE_REG_H */
3927 +
3928 diff --git a/arch/mips/pci/ifxmips_pcie_vr9.h b/arch/mips/pci/ifxmips_pcie_vr9.h
3929 new file mode 100644
3930 index 0000000..57d9368
3931 --- /dev/null
3932 +++ b/arch/mips/pci/ifxmips_pcie_vr9.h
3933 @@ -0,0 +1,271 @@
3934 +/****************************************************************************
3935 + Copyright (c) 2010
3936 + Lantiq Deutschland GmbH
3937 + Am Campeon 3; 85579 Neubiberg, Germany
3938 +
3939 + For licensing information, see the file 'LICENSE' in the root folder of
3940 + this software module.
3941 +
3942 + *****************************************************************************/
3943 +/*!
3944 + \file ifxmips_pcie_vr9.h
3945 + \ingroup IFX_PCIE
3946 + \brief PCIe RC driver vr9 specific file
3947 +*/
3948 +
3949 +#ifndef IFXMIPS_PCIE_VR9_H
3950 +#define IFXMIPS_PCIE_VR9_H
3951 +
3952 +#include <linux/types.h>
3953 +#include <linux/delay.h>
3954 +
3955 +#include <linux/gpio.h>
3956 +#include <lantiq_soc.h>
3957 +
3958 +#define IFX_PCIE_GPIO_RESET 238
3959 +
3960 +#define IFX_REG_R32 ltq_r32
3961 +#define IFX_REG_W32 ltq_w32
3962 +#define CONFIG_IFX_PCIE_HW_SWAP
3963 +#define IFX_RCU_AHB_ENDIAN ((volatile u32*)(IFX_RCU + 0x004C))
3964 +#define IFX_RCU_RST_REQ ((volatile u32*)(IFX_RCU + 0x0010))
3965 +#define IFX_RCU_AHB_BE_PCIE_PDI 0x00000080 /* Configure PCIE PDI module in big endian*/
3966 +
3967 +#define IFX_RCU (KSEG1 | 0x1F203000)
3968 +#define IFX_RCU_AHB_BE_PCIE_M 0x00000001 /* Configure AHB master port that connects to PCIe RC in big endian */
3969 +#define IFX_RCU_AHB_BE_PCIE_S 0x00000010 /* Configure AHB slave port that connects to PCIe RC in little endian */
3970 +#define IFX_RCU_AHB_BE_XBAR_M 0x00000002 /* Configure AHB master port that connects to XBAR in big endian */
3971 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
3972 +
3973 +#define IFX_PMU1_MODULE_PCIE_PHY (0)
3974 +#define IFX_PMU1_MODULE_PCIE_CTRL (1)
3975 +#define IFX_PMU1_MODULE_PDI (4)
3976 +#define IFX_PMU1_MODULE_MSI (5)
3977 +
3978 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
3979 +
3980 +
3981 +#define IFX_GPIO (KSEG1 | 0x1E100B00)
3982 +#define ALT0 ((volatile u32*)(IFX_GPIO + 0x007c))
3983 +#define ALT1 ((volatile u32*)(IFX_GPIO + 0x0080))
3984 +#define OD ((volatile u32*)(IFX_GPIO + 0x0084))
3985 +#define DIR ((volatile u32*)(IFX_GPIO + 0x0078))
3986 +#define OUT ((volatile u32*)(IFX_GPIO + 0x0070))
3987 +
3988 +
3989 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
3990 +{
3991 +
3992 + gpio_request(IFX_PCIE_GPIO_RESET, "pcie-reset");
3993 + gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
3994 + gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
3995 +
3996 +/* ifx_gpio_pin_reserve(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3997 + ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3998 + ifx_gpio_dir_out_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3999 + ifx_gpio_altsel0_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4000 + ifx_gpio_altsel1_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4001 + ifx_gpio_open_drain_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);*/
4002 +}
4003 +
4004 +static inline void pcie_ahb_pmu_setup(void)
4005 +{
4006 + /* Enable AHB bus master/slave */
4007 + struct clk *clk;
4008 + clk = clk_get_sys("1d900000.pcie", "ahb");
4009 + clk_enable(clk);
4010 +
4011 + //AHBM_PMU_SETUP(IFX_PMU_ENABLE);
4012 + //AHBS_PMU_SETUP(IFX_PMU_ENABLE);
4013 +}
4014 +
4015 +static inline void pcie_rcu_endian_setup(int pcie_port)
4016 +{
4017 + u32 reg;
4018 +
4019 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
4020 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
4021 + reg |= IFX_RCU_AHB_BE_PCIE_M;
4022 + reg |= IFX_RCU_AHB_BE_PCIE_S;
4023 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
4024 +#else
4025 + reg |= IFX_RCU_AHB_BE_PCIE_M;
4026 + reg &= ~IFX_RCU_AHB_BE_PCIE_S;
4027 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
4028 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
4029 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
4030 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
4031 +}
4032 +
4033 +static inline void pcie_phy_pmu_enable(int pcie_port)
4034 +{
4035 + struct clk *clk;
4036 + clk = clk_get_sys("1d900000.pcie", "phy");
4037 + clk_enable(clk);
4038 +
4039 + //PCIE_PHY_PMU_SETUP(IFX_PMU_ENABLE);
4040 +}
4041 +
4042 +static inline void pcie_phy_pmu_disable(int pcie_port)
4043 +{
4044 + struct clk *clk;
4045 + clk = clk_get_sys("1d900000.pcie", "phy");
4046 + clk_disable(clk);
4047 +
4048 +// PCIE_PHY_PMU_SETUP(IFX_PMU_DISABLE);
4049 +}
4050 +
4051 +static inline void pcie_pdi_big_endian(int pcie_port)
4052 +{
4053 + u32 reg;
4054 +
4055 + /* SRAM2PDI endianness control. */
4056 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
4057 + /* Config AHB->PCIe and PDI endianness */
4058 + reg |= IFX_RCU_AHB_BE_PCIE_PDI;
4059 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
4060 +}
4061 +
4062 +static inline void pcie_pdi_pmu_enable(int pcie_port)
4063 +{
4064 + /* Enable PDI to access PCIe PHY register */
4065 + struct clk *clk;
4066 + clk = clk_get_sys("1d900000.pcie", "pdi");
4067 + clk_enable(clk);
4068 + //PDI_PMU_SETUP(IFX_PMU_ENABLE);
4069 +}
4070 +
4071 +static inline void pcie_core_rst_assert(int pcie_port)
4072 +{
4073 + u32 reg;
4074 +
4075 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4076 +
4077 + /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
4078 + reg |= 0x00400000;
4079 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4080 +}
4081 +
4082 +static inline void pcie_core_rst_deassert(int pcie_port)
4083 +{
4084 + u32 reg;
4085 +
4086 + /* Make sure one micro-second delay */
4087 + udelay(1);
4088 +
4089 + /* Reset PCIe PHY & Core, bit 22 */
4090 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4091 + reg &= ~0x00400000;
4092 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4093 +}
4094 +
4095 +static inline void pcie_phy_rst_assert(int pcie_port)
4096 +{
4097 + u32 reg;
4098 +
4099 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4100 + reg |= 0x00001000; /* Bit 12 */
4101 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4102 +}
4103 +
4104 +static inline void pcie_phy_rst_deassert(int pcie_port)
4105 +{
4106 + u32 reg;
4107 +
4108 + /* Make sure one micro-second delay */
4109 + udelay(1);
4110 +
4111 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
4112 + reg &= ~0x00001000; /* Bit 12 */
4113 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
4114 +}
4115 +
4116 +static inline void pcie_device_rst_assert(int pcie_port)
4117 +{
4118 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
4119 + gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
4120 +// ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4121 +}
4122 +
4123 +static inline void pcie_device_rst_deassert(int pcie_port)
4124 +{
4125 + mdelay(100);
4126 + printk("%s:%s[%d]\n", __FILE__, __func__, __LINE__);
4127 + gpio_direction_output(IFX_PCIE_GPIO_RESET, 1);
4128 +// gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
4129 + //ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
4130 +}
4131 +
4132 +static inline void pcie_core_pmu_setup(int pcie_port)
4133 +{
4134 + struct clk *clk;
4135 + clk = clk_get_sys("1d900000.pcie", "ctl");
4136 + clk_enable(clk);
4137 + clk = clk_get_sys("1d900000.pcie", "bus");
4138 + clk_enable(clk);
4139 +
4140 + /* PCIe Core controller enabled */
4141 +// PCIE_CTRL_PMU_SETUP(IFX_PMU_ENABLE);
4142 +
4143 + /* Enable PCIe L0 Clock */
4144 +// PCIE_L0_CLK_PMU_SETUP(IFX_PMU_ENABLE);
4145 +}
4146 +
4147 +static inline void pcie_msi_init(int pcie_port)
4148 +{
4149 + struct clk *clk;
4150 + pcie_msi_pic_init(pcie_port);
4151 + clk = clk_get_sys("ltq_pcie", "msi");
4152 + clk_enable(clk);
4153 +// MSI_PMU_SETUP(IFX_PMU_ENABLE);
4154 +}
4155 +
4156 +static inline u32
4157 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
4158 +{
4159 + u32 tbus_number = bus_number;
4160 +
4161 +#ifdef CONFIG_IFX_PCI
4162 + if (pcibios_host_nr() > 1) {
4163 + tbus_number -= pcibios_1st_host_bus_nr();
4164 + }
4165 +#endif /* CONFIG_IFX_PCI */
4166 + return tbus_number;
4167 +}
4168 +
4169 +static inline u32
4170 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
4171 +{
4172 + struct pci_dev *pdev;
4173 + u32 tvalue = value;
4174 +
4175 + /* Sanity check */
4176 + pdev = pci_get_slot(bus, devfn);
4177 + if (pdev == NULL) {
4178 + return tvalue;
4179 + }
4180 +
4181 + /* Only care about PCI bridge */
4182 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
4183 + return tvalue;
4184 + }
4185 +
4186 + if (read) { /* Read hack */
4187 + #ifdef CONFIG_IFX_PCI
4188 + if (pcibios_host_nr() > 1) {
4189 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
4190 + }
4191 + #endif /* CONFIG_IFX_PCI */
4192 + }
4193 + else { /* Write hack */
4194 + #ifdef CONFIG_IFX_PCI
4195 + if (pcibios_host_nr() > 1) {
4196 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
4197 + }
4198 + #endif
4199 + }
4200 + return tvalue;
4201 +}
4202 +
4203 +#endif /* IFXMIPS_PCIE_VR9_H */
4204 +
4205 diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c
4206 index 594e60d..2e75400 100644
4207 --- a/arch/mips/pci/pci.c
4208 +++ b/arch/mips/pci/pci.c
4209 @@ -266,6 +266,31 @@ static int __init pcibios_init(void)
4210
4211 subsys_initcall(pcibios_init);
4212
4213 +int pcibios_host_nr(void)
4214 +{
4215 + int count;
4216 + struct pci_controller *hose;
4217 + for (count = 0, hose = hose_head; hose; hose = hose->next, count++) {
4218 + ;
4219 + }
4220 + return count;
4221 +}
4222 +EXPORT_SYMBOL(pcibios_host_nr);
4223 +
4224 +int pcibios_1st_host_bus_nr(void)
4225 +{
4226 + int bus_nr = 0;
4227 + struct pci_controller *hose = hose_head;
4228 +
4229 + if (hose != NULL) {
4230 + if (hose->bus != NULL) {
4231 + bus_nr = hose->bus->number + 1;
4232 + }
4233 + }
4234 + return bus_nr;
4235 +}
4236 +EXPORT_SYMBOL(pcibios_1st_host_bus_nr);
4237 +
4238 static int pcibios_enable_resources(struct pci_dev *dev, int mask)
4239 {
4240 u16 cmd, old_cmd;
4241 diff --git a/arch/mips/pci/pcie-lantiq.h b/arch/mips/pci/pcie-lantiq.h
4242 new file mode 100644
4243 index 0000000..d877c23
4244 --- /dev/null
4245 +++ b/arch/mips/pci/pcie-lantiq.h
4246 @@ -0,0 +1,1305 @@
4247 +/******************************************************************************
4248 +**
4249 +** FILE NAME : ifxmips_pcie_reg.h
4250 +** PROJECT : IFX UEIP for VRX200
4251 +** MODULES : PCIe module
4252 +**
4253 +** DATE : 02 Mar 2009
4254 +** AUTHOR : Lei Chuanhua
4255 +** DESCRIPTION : PCIe Root Complex Driver
4256 +** COPYRIGHT : Copyright (c) 2009
4257 +** Infineon Technologies AG
4258 +** Am Campeon 1-12, 85579 Neubiberg, Germany
4259 +**
4260 +** This program is free software; you can redistribute it and/or modify
4261 +** it under the terms of the GNU General Public License as published by
4262 +** the Free Software Foundation; either version 2 of the License, or
4263 +** (at your option) any later version.
4264 +** HISTORY
4265 +** $Version $Date $Author $Comment
4266 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
4267 +*******************************************************************************/
4268 +#ifndef IFXMIPS_PCIE_REG_H
4269 +#define IFXMIPS_PCIE_REG_H
4270 +#include <linux/version.h>
4271 +#include <linux/types.h>
4272 +#include <linux/pci.h>
4273 +#include <linux/interrupt.h>
4274 +/*!
4275 + \file ifxmips_pcie_reg.h
4276 + \ingroup IFX_PCIE
4277 + \brief header file for PCIe module register definition
4278 +*/
4279 +/* PCIe Address Mapping Base */
4280 +#define PCIE_CFG_PHY_BASE 0x1D000000UL
4281 +#define PCIE_CFG_BASE (KSEG1 + PCIE_CFG_PHY_BASE)
4282 +#define PCIE_CFG_SIZE (8 * 1024 * 1024)
4283 +
4284 +#define PCIE_MEM_PHY_BASE 0x1C000000UL
4285 +#define PCIE_MEM_BASE (KSEG1 + PCIE_MEM_PHY_BASE)
4286 +#define PCIE_MEM_SIZE (16 * 1024 * 1024)
4287 +#define PCIE_MEM_PHY_END (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
4288 +
4289 +#define PCIE_IO_PHY_BASE 0x1D800000UL
4290 +#define PCIE_IO_BASE (KSEG1 + PCIE_IO_PHY_BASE)
4291 +#define PCIE_IO_SIZE (1 * 1024 * 1024)
4292 +#define PCIE_IO_PHY_END (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
4293 +
4294 +#define PCIE_RC_CFG_BASE (KSEG1 + 0x1D900000)
4295 +#define PCIE_APP_LOGIC_REG (KSEG1 + 0x1E100900)
4296 +#define PCIE_MSI_PHY_BASE 0x1F600000UL
4297 +
4298 +#define PCIE_PDI_PHY_BASE 0x1F106800UL
4299 +#define PCIE_PDI_BASE (KSEG1 + PCIE_PDI_PHY_BASE)
4300 +#define PCIE_PDI_SIZE 0x400
4301 +
4302 +#define PCIE1_CFG_PHY_BASE 0x19000000UL
4303 +#define PCIE1_CFG_BASE (KSEG1 + PCIE1_CFG_PHY_BASE)
4304 +#define PCIE1_CFG_SIZE (8 * 1024 * 1024)
4305 +
4306 +#define PCIE1_MEM_PHY_BASE 0x18000000UL
4307 +#define PCIE1_MEM_BASE (KSEG1 + PCIE1_MEM_PHY_BASE)
4308 +#define PCIE1_MEM_SIZE (16 * 1024 * 1024)
4309 +#define PCIE1_MEM_PHY_END (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
4310 +
4311 +#define PCIE1_IO_PHY_BASE 0x19800000UL
4312 +#define PCIE1_IO_BASE (KSEG1 + PCIE1_IO_PHY_BASE)
4313 +#define PCIE1_IO_SIZE (1 * 1024 * 1024)
4314 +#define PCIE1_IO_PHY_END (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
4315 +
4316 +#define PCIE1_RC_CFG_BASE (KSEG1 + 0x19900000)
4317 +#define PCIE1_APP_LOGIC_REG (KSEG1 + 0x1E100700)
4318 +#define PCIE1_MSI_PHY_BASE 0x1F400000UL
4319 +
4320 +#define PCIE1_PDI_PHY_BASE 0x1F700400UL
4321 +#define PCIE1_PDI_BASE (KSEG1 + PCIE1_PDI_PHY_BASE)
4322 +#define PCIE1_PDI_SIZE 0x400
4323 +
4324 +#define PCIE_CFG_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
4325 +#define PCIE_MEM_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
4326 +#define PCIE_IO_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
4327 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
4328 +#define PCIE_MEM_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
4329 +#define PCIE_IO_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
4330 +#define PCIE_IO_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
4331 +#define PCIE_APP_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
4332 +#define PCIE_RC_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
4333 +#define PCIE_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
4334 +
4335 +/* PCIe Application Logic Register */
4336 +/* RC Core Control Register */
4337 +#define PCIE_RC_CCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
4338 +/* This should be enabled after initializing configuratin registers
4339 + * Also should check link status retraining bit
4340 + */
4341 +#define PCIE_RC_CCR_LTSSM_ENABLE 0x00000001 /* Enable LTSSM to continue link establishment */
4342 +
4343 +/* RC Core Debug Register */
4344 +#define PCIE_RC_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
4345 +#define PCIE_RC_DR_DLL_UP 0x00000001 /* Data Link Layer Up */
4346 +#define PCIE_RC_DR_CURRENT_POWER_STATE 0x0000000E /* Current Power State */
4347 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S 1
4348 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE 0x000001F0 /* Current LTSSM State */
4349 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S 4
4350 +
4351 +#define PCIE_RC_DR_PM_DEV_STATE 0x00000E00 /* Power Management D-State */
4352 +#define PCIE_RC_DR_PM_DEV_STATE_S 9
4353 +
4354 +#define PCIE_RC_DR_PM_ENABLED 0x00001000 /* Power Management State from PMU */
4355 +#define PCIE_RC_DR_PME_EVENT_ENABLED 0x00002000 /* Power Management Event Enable State */
4356 +#define PCIE_RC_DR_AUX_POWER_ENABLED 0x00004000 /* Auxiliary Power Enable */
4357 +
4358 +/* Current Power State Definition */
4359 +enum {
4360 + PCIE_RC_DR_D0 = 0,
4361 + PCIE_RC_DR_D1, /* Not supported */
4362 + PCIE_RC_DR_D2, /* Not supported */
4363 + PCIE_RC_DR_D3,
4364 + PCIE_RC_DR_UN,
4365 +};
4366 +
4367 +/* PHY Link Status Register */
4368 +#define PCIE_PHY_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
4369 +#define PCIE_PHY_SR_PHY_LINK_UP 0x00000001 /* PHY Link Up/Down Indicator */
4370 +
4371 +/* Electromechanical Control Register */
4372 +#define PCIE_EM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
4373 +#define PCIE_EM_CR_CARD_IS_PRESENT 0x00000001 /* Card Presence Detect State */
4374 +#define PCIE_EM_CR_MRL_OPEN 0x00000002 /* MRL Sensor State */
4375 +#define PCIE_EM_CR_POWER_FAULT_SET 0x00000004 /* Power Fault Detected */
4376 +#define PCIE_EM_CR_MRL_SENSOR_SET 0x00000008 /* MRL Sensor Changed */
4377 +#define PCIE_EM_CR_PRESENT_DETECT_SET 0x00000010 /* Card Presense Detect Changed */
4378 +#define PCIE_EM_CR_CMD_CPL_INT_SET 0x00000020 /* Command Complete Interrupt */
4379 +#define PCIE_EM_CR_SYS_INTERLOCK_SET 0x00000040 /* System Electromechanical IterLock Engaged */
4380 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET 0x00000080 /* Attention Button Pressed */
4381 +
4382 +/* Interrupt Status Register */
4383 +#define PCIE_IR_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
4384 +#define PCIE_IR_SR_PME_CAUSE_MSI 0x00000002 /* MSI caused by PME */
4385 +#define PCIE_IR_SR_HP_PME_WAKE_GEN 0x00000004 /* Hotplug PME Wake Generation */
4386 +#define PCIE_IR_SR_HP_MSI 0x00000008 /* Hotplug MSI */
4387 +#define PCIE_IR_SR_AHB_LU_ERR 0x00000030 /* AHB Bridge Lookup Error Signals */
4388 +#define PCIE_IR_SR_AHB_LU_ERR_S 4
4389 +#define PCIE_IR_SR_INT_MSG_NUM 0x00003E00 /* Interrupt Message Number */
4390 +#define PCIE_IR_SR_INT_MSG_NUM_S 9
4391 +#define PCIE_IR_SR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
4392 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S 27
4393 +
4394 +/* Message Control Register */
4395 +#define PCIE_MSG_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
4396 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG 0x00000001 /* Generate PME Turn Off Message */
4397 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG 0x00000002 /* Generate Unlock Message */
4398 +
4399 +#define PCIE_VDM_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
4400 +
4401 +/* Vendor-Defined Message Requester ID Register */
4402 +#define PCIE_VDM_RID(X) (PCIE_APP_PORT_TO_BASE (X) + 0x38)
4403 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID 0x0000FFFF
4404 +#define PCIE_VDM_RID_VDMRID_S 0
4405 +
4406 +/* ASPM Control Register */
4407 +#define PCIE_ASPM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
4408 +#define PCIE_ASPM_CR_HOT_RST 0x00000001 /* Hot Reset Request to the downstream device */
4409 +#define PCIE_ASPM_CR_REQ_EXIT_L1 0x00000002 /* Request to Exit L1 */
4410 +#define PCIE_ASPM_CR_REQ_ENTER_L1 0x00000004 /* Request to Enter L1 */
4411 +
4412 +/* Vendor Message DW0 Register */
4413 +#define PCIE_VM_MSG_DW0(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
4414 +#define PCIE_VM_MSG_DW0_TYPE 0x0000001F /* Message type */
4415 +#define PCIE_VM_MSG_DW0_TYPE_S 0
4416 +#define PCIE_VM_MSG_DW0_FORMAT 0x00000060 /* Format */
4417 +#define PCIE_VM_MSG_DW0_FORMAT_S 5
4418 +#define PCIE_VM_MSG_DW0_TC 0x00007000 /* Traffic Class */
4419 +#define PCIE_VM_MSG_DW0_TC_S 12
4420 +#define PCIE_VM_MSG_DW0_ATTR 0x000C0000 /* Atrributes */
4421 +#define PCIE_VM_MSG_DW0_ATTR_S 18
4422 +#define PCIE_VM_MSG_DW0_EP_TLP 0x00100000 /* Poisoned TLP */
4423 +#define PCIE_VM_MSG_DW0_TD 0x00200000 /* TLP Digest */
4424 +#define PCIE_VM_MSG_DW0_LEN 0xFFC00000 /* Length */
4425 +#define PCIE_VM_MSG_DW0_LEN_S 22
4426 +
4427 +/* Format Definition */
4428 +enum {
4429 + PCIE_VM_MSG_FORMAT_00 = 0, /* 3DW Hdr, no data*/
4430 + PCIE_VM_MSG_FORMAT_01, /* 4DW Hdr, no data */
4431 + PCIE_VM_MSG_FORMAT_10, /* 3DW Hdr, with data */
4432 + PCIE_VM_MSG_FORMAT_11, /* 4DW Hdr, with data */
4433 +};
4434 +
4435 +/* Traffic Class Definition */
4436 +enum {
4437 + PCIE_VM_MSG_TC0 = 0,
4438 + PCIE_VM_MSG_TC1,
4439 + PCIE_VM_MSG_TC2,
4440 + PCIE_VM_MSG_TC3,
4441 + PCIE_VM_MSG_TC4,
4442 + PCIE_VM_MSG_TC5,
4443 + PCIE_VM_MSG_TC6,
4444 + PCIE_VM_MSG_TC7,
4445 +};
4446 +
4447 +/* Attributes Definition */
4448 +enum {
4449 + PCIE_VM_MSG_ATTR_00 = 0, /* RO and No Snoop cleared */
4450 + PCIE_VM_MSG_ATTR_01, /* RO cleared , No Snoop set */
4451 + PCIE_VM_MSG_ATTR_10, /* RO set, No Snoop cleared*/
4452 + PCIE_VM_MSG_ATTR_11, /* RO and No Snoop set */
4453 +};
4454 +
4455 +/* Payload Size Definition */
4456 +#define PCIE_VM_MSG_LEN_MIN 0
4457 +#define PCIE_VM_MSG_LEN_MAX 1024
4458 +
4459 +/* Vendor Message DW1 Register */
4460 +#define PCIE_VM_MSG_DW1(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
4461 +#define PCIE_VM_MSG_DW1_FUNC_NUM 0x00000070 /* Function Number */
4462 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S 8
4463 +#define PCIE_VM_MSG_DW1_CODE 0x00FF0000 /* Message Code */
4464 +#define PCIE_VM_MSG_DW1_CODE_S 16
4465 +#define PCIE_VM_MSG_DW1_TAG 0xFF000000 /* Tag */
4466 +#define PCIE_VM_MSG_DW1_TAG_S 24
4467 +
4468 +#define PCIE_VM_MSG_DW2(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
4469 +#define PCIE_VM_MSG_DW3(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
4470 +
4471 +/* Vendor Message Request Register */
4472 +#define PCIE_VM_MSG_REQR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
4473 +#define PCIE_VM_MSG_REQR_REQ 0x00000001 /* Vendor Message Request */
4474 +
4475 +
4476 +/* AHB Slave Side Band Control Register */
4477 +#define PCIE_AHB_SSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
4478 +#define PCIE_AHB_SSB_REQ_BCM 0x00000001 /* Slave Reques BCM filed */
4479 +#define PCIE_AHB_SSB_REQ_EP 0x00000002 /* Slave Reques EP filed */
4480 +#define PCIE_AHB_SSB_REQ_TD 0x00000004 /* Slave Reques TD filed */
4481 +#define PCIE_AHB_SSB_REQ_ATTR 0x00000018 /* Slave Reques Attribute number */
4482 +#define PCIE_AHB_SSB_REQ_ATTR_S 3
4483 +#define PCIE_AHB_SSB_REQ_TC 0x000000E0 /* Slave Request TC Field */
4484 +#define PCIE_AHB_SSB_REQ_TC_S 5
4485 +
4486 +/* AHB Master SideBand Ctrl Register */
4487 +#define PCIE_AHB_MSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
4488 +#define PCIE_AHB_MSB_RESP_ATTR 0x00000003 /* Master Response Attribute number */
4489 +#define PCIE_AHB_MSB_RESP_ATTR_S 0
4490 +#define PCIE_AHB_MSB_RESP_BAD_EOT 0x00000004 /* Master Response Badeot filed */
4491 +#define PCIE_AHB_MSB_RESP_BCM 0x00000008 /* Master Response BCM filed */
4492 +#define PCIE_AHB_MSB_RESP_EP 0x00000010 /* Master Response EP filed */
4493 +#define PCIE_AHB_MSB_RESP_TD 0x00000020 /* Master Response TD filed */
4494 +#define PCIE_AHB_MSB_RESP_FUN_NUM 0x000003C0 /* Master Response Function number */
4495 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S 6
4496 +
4497 +/* AHB Control Register, fixed bus enumeration exception */
4498 +#define PCIE_AHB_CTRL(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
4499 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS 0x00000001
4500 +
4501 +/* Interrupt Enalbe Register */
4502 +#define PCIE_IRNEN(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
4503 +#define PCIE_IRNCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
4504 +#define PCIE_IRNICR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
4505 +
4506 +/* PCIe interrupt enable/control/capture register definition */
4507 +#define PCIE_IRN_AER_REPORT 0x00000001 /* AER Interrupt */
4508 +#define PCIE_IRN_AER_MSIX 0x00000002 /* Advanced Error MSI-X Interrupt */
4509 +#define PCIE_IRN_PME 0x00000004 /* PME Interrupt */
4510 +#define PCIE_IRN_HOTPLUG 0x00000008 /* Hotplug Interrupt */
4511 +#define PCIE_IRN_RX_VDM_MSG 0x00000010 /* Vendor-Defined Message Interrupt */
4512 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG 0x00000020 /* Correctable Error Message Interrupt */
4513 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG 0x00000040 /* Non-fatal Error Message */
4514 +#define PCIE_IRN_RX_FATAL_ERR_MSG 0x00000080 /* Fatal Error Message */
4515 +#define PCIE_IRN_RX_PME_MSG 0x00000100 /* PME Message Interrupt */
4516 +#define PCIE_IRN_RX_PME_TURNOFF_ACK 0x00000200 /* PME Turnoff Ack Message Interrupt */
4517 +#define PCIE_IRN_AHB_BR_FATAL_ERR 0x00000400 /* AHB Fatal Error Interrupt */
4518 +#define PCIE_IRN_LINK_AUTO_BW_STATUS 0x00000800 /* Link Auto Bandwidth Status Interrupt */
4519 +#define PCIE_IRN_BW_MGT 0x00001000 /* Bandwidth Managment Interrupt */
4520 +#define PCIE_IRN_INTA 0x00002000 /* INTA */
4521 +#define PCIE_IRN_INTB 0x00004000 /* INTB */
4522 +#define PCIE_IRN_INTC 0x00008000 /* INTC */
4523 +#define PCIE_IRN_INTD 0x00010000 /* INTD */
4524 +#define PCIE_IRN_WAKEUP 0x00020000 /* Wake up Interrupt */
4525 +
4526 +#define PCIE_RC_CORE_COMBINED_INT (PCIE_IRN_AER_REPORT | PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
4527 + PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
4528 + PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
4529 + PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
4530 + PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
4531 +/* PCIe RC Configuration Register */
4532 +#define PCIE_VDID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
4533 +
4534 +/* Bit definition from pci_reg.h */
4535 +#define PCIE_PCICMDSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
4536 +#define PCIE_CCRID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
4537 +#define PCIE_CLSLTHTBR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
4538 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
4539 +#define PCIE_BAR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
4540 +#define PCIE_BAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
4541 +
4542 +#define PCIE_BNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
4543 +/* Bus Number Register bits */
4544 +#define PCIE_BNR_PRIMARY_BUS_NUM 0x000000FF
4545 +#define PCIE_BNR_PRIMARY_BUS_NUM_S 0
4546 +#define PCIE_PNR_SECONDARY_BUS_NUM 0x0000FF00
4547 +#define PCIE_PNR_SECONDARY_BUS_NUM_S 8
4548 +#define PCIE_PNR_SUB_BUS_NUM 0x00FF0000
4549 +#define PCIE_PNR_SUB_BUS_NUM_S 16
4550 +
4551 +/* IO Base/Limit Register bits */
4552 +#define PCIE_IOBLSECS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C) /* RC only */
4553 +#define PCIE_IOBLSECS_32BIT_IO_ADDR 0x00000001
4554 +#define PCIE_IOBLSECS_IO_BASE_ADDR 0x000000F0
4555 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S 4
4556 +#define PCIE_IOBLSECS_32BIT_IOLIMT 0x00000100
4557 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR 0x0000F000
4558 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S 12
4559 +
4560 +/* Non-prefetchable Memory Base/Limit Register bit */
4561 +#define PCIE_MBML(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20) /* RC only */
4562 +#define PCIE_MBML_MEM_BASE_ADDR 0x0000FFF0
4563 +#define PCIE_MBML_MEM_BASE_ADDR_S 4
4564 +#define PCIE_MBML_MEM_LIMIT_ADDR 0xFFF00000
4565 +#define PCIE_MBML_MEM_LIMIT_ADDR_S 20
4566 +
4567 +/* Prefetchable Memory Base/Limit Register bit */
4568 +#define PCIE_PMBL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24) /* RC only */
4569 +#define PCIE_PMBL_64BIT_ADDR 0x00000001
4570 +#define PCIE_PMBL_UPPER_12BIT 0x0000FFF0
4571 +#define PCIE_PMBL_UPPER_12BIT_S 4
4572 +#define PCIE_PMBL_E64MA 0x00010000
4573 +#define PCIE_PMBL_END_ADDR 0xFFF00000
4574 +#define PCIE_PMBL_END_ADDR_S 20
4575 +#define PCIE_PMBU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28) /* RC only */
4576 +#define PCIE_PMLU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C) /* RC only */
4577 +
4578 +/* I/O Base/Limit Upper 16 bits register */
4579 +#define PCIE_IO_BANDL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30) /* RC only */
4580 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE 0x0000FFFF
4581 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S 0
4582 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT 0xFFFF0000
4583 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S 16
4584 +
4585 +#define PCIE_CPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
4586 +#define PCIE_EBBAR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
4587 +
4588 +/* Interrupt and Secondary Bridge Control Register */
4589 +#define PCIE_INTRBCTRL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
4590 +
4591 +#define PCIE_INTRBCTRL_INT_LINE 0x000000FF
4592 +#define PCIE_INTRBCTRL_INT_LINE_S 0
4593 +#define PCIE_INTRBCTRL_INT_PIN 0x0000FF00
4594 +#define PCIE_INTRBCTRL_INT_PIN_S 8
4595 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE 0x00010000 /* #PERR */
4596 +#define PCIE_INTRBCTRL_SERR_ENABLE 0x00020000 /* #SERR */
4597 +#define PCIE_INTRBCTRL_ISA_ENABLE 0x00040000 /* ISA enable, IO 64KB only */
4598 +#define PCIE_INTRBCTRL_VGA_ENABLE 0x00080000 /* VGA enable */
4599 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE 0x00100000 /* VGA 16bit decode */
4600 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS 0x00400000 /* Secondary bus rest, hot rest, 1ms */
4601 +/* Others are read only */
4602 +enum {
4603 + PCIE_INTRBCTRL_INT_NON = 0,
4604 + PCIE_INTRBCTRL_INTA,
4605 + PCIE_INTRBCTRL_INTB,
4606 + PCIE_INTRBCTRL_INTC,
4607 + PCIE_INTRBCTRL_INTD,
4608 +};
4609 +
4610 +#define PCIE_PM_CAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
4611 +
4612 +/* Power Management Control and Status Register */
4613 +#define PCIE_PM_CSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
4614 +
4615 +#define PCIE_PM_CSR_POWER_STATE 0x00000003 /* Power State */
4616 +#define PCIE_PM_CSR_POWER_STATE_S 0
4617 +#define PCIE_PM_CSR_SW_RST 0x00000008 /* Soft Reset Enabled */
4618 +#define PCIE_PM_CSR_PME_ENABLE 0x00000100 /* PME Enable */
4619 +#define PCIE_PM_CSR_PME_STATUS 0x00008000 /* PME status */
4620 +
4621 +/* MSI Capability Register for EP */
4622 +#define PCIE_MCAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
4623 +
4624 +#define PCIE_MCAPR_MSI_CAP_ID 0x000000FF /* MSI Capability ID */
4625 +#define PCIE_MCAPR_MSI_CAP_ID_S 0
4626 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR 0x0000FF00 /* Next Capability Pointer */
4627 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S 8
4628 +#define PCIE_MCAPR_MSI_ENABLE 0x00010000 /* MSI Enable */
4629 +#define PCIE_MCAPR_MULTI_MSG_CAP 0x000E0000 /* Multiple Message Capable */
4630 +#define PCIE_MCAPR_MULTI_MSG_CAP_S 17
4631 +#define PCIE_MCAPR_MULTI_MSG_ENABLE 0x00700000 /* Multiple Message Enable */
4632 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S 20
4633 +#define PCIE_MCAPR_ADDR64_CAP 0X00800000 /* 64-bit Address Capable */
4634 +
4635 +/* MSI Message Address Register */
4636 +#define PCIE_MA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
4637 +
4638 +#define PCIE_MA_ADDR_MASK 0xFFFFFFFC /* Message Address */
4639 +
4640 +/* MSI Message Upper Address Register */
4641 +#define PCIE_MUA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
4642 +
4643 +/* MSI Message Data Register */
4644 +#define PCIE_MD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
4645 +
4646 +#define PCIE_MD_DATA 0x0000FFFF /* Message Data */
4647 +#define PCIE_MD_DATA_S 0
4648 +
4649 +/* PCI Express Capability Register */
4650 +#define PCIE_XCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
4651 +
4652 +#define PCIE_XCAP_ID 0x000000FF /* PCI Express Capability ID */
4653 +#define PCIE_XCAP_ID_S 0
4654 +#define PCIE_XCAP_NEXT_CAP 0x0000FF00 /* Next Capability Pointer */
4655 +#define PCIE_XCAP_NEXT_CAP_S 8
4656 +#define PCIE_XCAP_VER 0x000F0000 /* PCI Express Capability Version */
4657 +#define PCIE_XCAP_VER_S 16
4658 +#define PCIE_XCAP_DEV_PORT_TYPE 0x00F00000 /* Device Port Type */
4659 +#define PCIE_XCAP_DEV_PORT_TYPE_S 20
4660 +#define PCIE_XCAP_SLOT_IMPLEMENTED 0x01000000 /* Slot Implemented */
4661 +#define PCIE_XCAP_MSG_INT_NUM 0x3E000000 /* Interrupt Message Number */
4662 +#define PCIE_XCAP_MSG_INT_NUM_S 25
4663 +
4664 +/* Device Capability Register */
4665 +#define PCIE_DCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
4666 +
4667 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE 0x00000007 /* Max Payload size */
4668 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S 0
4669 +#define PCIE_DCAP_PHANTOM_FUNC 0x00000018 /* Phanton Function, not supported */
4670 +#define PCIE_DCAP_PHANTOM_FUNC_S 3
4671 +#define PCIE_DCAP_EXT_TAG 0x00000020 /* Extended Tag Field */
4672 +#define PCIE_DCAP_EP_L0S_LATENCY 0x000001C0 /* EP L0s latency only */
4673 +#define PCIE_DCAP_EP_L0S_LATENCY_S 6
4674 +#define PCIE_DCAP_EP_L1_LATENCY 0x00000E00 /* EP L1 latency only */
4675 +#define PCIE_DCAP_EP_L1_LATENCY_S 9
4676 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT 0x00008000 /* Role Based ERR */
4677 +
4678 +/* Maximum payload size supported */
4679 +enum {
4680 + PCIE_MAX_PAYLOAD_128 = 0,
4681 + PCIE_MAX_PAYLOAD_256,
4682 + PCIE_MAX_PAYLOAD_512,
4683 + PCIE_MAX_PAYLOAD_1024,
4684 + PCIE_MAX_PAYLOAD_2048,
4685 + PCIE_MAX_PAYLOAD_4096,
4686 +};
4687 +
4688 +/* Device Control and Status Register */
4689 +#define PCIE_DCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
4690 +
4691 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN 0x00000001 /* COR-ERR */
4692 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN 0x00000002 /* Non-fatal ERR */
4693 +#define PCIE_DCTLSTS_FATAL_ERR_EN 0x00000004 /* Fatal ERR */
4694 +#define PCIE_DCTLSYS_UR_REQ_EN 0x00000008 /* UR ERR */
4695 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN 0x00000010 /* Enable relaxing ordering */
4696 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE 0x000000E0 /* Max payload mask */
4697 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S 5
4698 +#define PCIE_DCTLSTS_EXT_TAG_EN 0x00000100 /* Extended tag field */
4699 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN 0x00000200 /* Phantom Function Enable */
4700 +#define PCIE_DCTLSTS_AUX_PM_EN 0x00000400 /* AUX Power PM Enable */
4701 +#define PCIE_DCTLSTS_NO_SNOOP_EN 0x00000800 /* Enable no snoop, except root port*/
4702 +#define PCIE_DCTLSTS_MAX_READ_SIZE 0x00007000 /* Max Read Request size*/
4703 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S 12
4704 +#define PCIE_DCTLSTS_CORRECTABLE_ERR 0x00010000 /* COR-ERR Detected */
4705 +#define PCIE_DCTLSTS_NONFATAL_ERR 0x00020000 /* Non-Fatal ERR Detected */
4706 +#define PCIE_DCTLSTS_FATAL_ER 0x00040000 /* Fatal ERR Detected */
4707 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ 0x00080000 /* UR Detected */
4708 +#define PCIE_DCTLSTS_AUX_POWER 0x00100000 /* Aux Power Detected */
4709 +#define PCIE_DCTLSTS_TRANSACT_PENDING 0x00200000 /* Transaction pending */
4710 +
4711 +#define PCIE_DCTLSTS_ERR_EN (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
4712 + PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
4713 + PCIE_DCTLSYS_UR_REQ_EN)
4714 +
4715 +/* Link Capability Register */
4716 +#define PCIE_LCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
4717 +#define PCIE_LCAP_MAX_LINK_SPEED 0x0000000F /* Max link speed, 0x1 by default */
4718 +#define PCIE_LCAP_MAX_LINK_SPEED_S 0
4719 +#define PCIE_LCAP_MAX_LENGTH_WIDTH 0x000003F0 /* Maxium Length Width */
4720 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S 4
4721 +#define PCIE_LCAP_ASPM_LEVEL 0x00000C00 /* Active State Link PM Support */
4722 +#define PCIE_LCAP_ASPM_LEVEL_S 10
4723 +#define PCIE_LCAP_L0S_EIXT_LATENCY 0x00007000 /* L0s Exit Latency */
4724 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S 12
4725 +#define PCIE_LCAP_L1_EXIT_LATENCY 0x00038000 /* L1 Exit Latency */
4726 +#define PCIE_LCAP_L1_EXIT_LATENCY_S 15
4727 +#define PCIE_LCAP_CLK_PM 0x00040000 /* Clock Power Management */
4728 +#define PCIE_LCAP_SDER 0x00080000 /* Surprise Down Error Reporting */
4729 +#define PCIE_LCAP_DLL_ACTIVE_REPROT 0x00100000 /* Data Link Layer Active Reporting Capable */
4730 +#define PCIE_LCAP_PORT_NUM 0xFF0000000 /* Port number */
4731 +#define PCIE_LCAP_PORT_NUM_S 24
4732 +
4733 +/* Maximum Length width definition */
4734 +#define PCIE_MAX_LENGTH_WIDTH_RES 0x00
4735 +#define PCIE_MAX_LENGTH_WIDTH_X1 0x01 /* Default */
4736 +#define PCIE_MAX_LENGTH_WIDTH_X2 0x02
4737 +#define PCIE_MAX_LENGTH_WIDTH_X4 0x04
4738 +#define PCIE_MAX_LENGTH_WIDTH_X8 0x08
4739 +#define PCIE_MAX_LENGTH_WIDTH_X12 0x0C
4740 +#define PCIE_MAX_LENGTH_WIDTH_X16 0x10
4741 +#define PCIE_MAX_LENGTH_WIDTH_X32 0x20
4742 +
4743 +/* Active State Link PM definition */
4744 +enum {
4745 + PCIE_ASPM_RES0 = 0,
4746 + PCIE_ASPM_L0S_ENTRY_SUPPORT, /* L0s */
4747 + PCIE_ASPM_RES1,
4748 + PCIE_ASPM_L0S_L1_ENTRY_SUPPORT, /* L0s and L1, default */
4749 +};
4750 +
4751 +/* L0s Exit Latency definition */
4752 +enum {
4753 + PCIE_L0S_EIXT_LATENCY_L64NS = 0, /* < 64 ns */
4754 + PCIE_L0S_EIXT_LATENCY_B64A128, /* > 64 ns < 128 ns */
4755 + PCIE_L0S_EIXT_LATENCY_B128A256, /* > 128 ns < 256 ns */
4756 + PCIE_L0S_EIXT_LATENCY_B256A512, /* > 256 ns < 512 ns */
4757 + PCIE_L0S_EIXT_LATENCY_B512TO1U, /* > 512 ns < 1 us */
4758 + PCIE_L0S_EIXT_LATENCY_B1A2U, /* > 1 us < 2 us */
4759 + PCIE_L0S_EIXT_LATENCY_B2A4U, /* > 2 us < 4 us */
4760 + PCIE_L0S_EIXT_LATENCY_M4US, /* > 4 us */
4761 +};
4762 +
4763 +/* L1 Exit Latency definition */
4764 +enum {
4765 + PCIE_L1_EXIT_LATENCY_L1US = 0, /* < 1 us */
4766 + PCIE_L1_EXIT_LATENCY_B1A2, /* > 1 us < 2 us */
4767 + PCIE_L1_EXIT_LATENCY_B2A4, /* > 2 us < 4 us */
4768 + PCIE_L1_EXIT_LATENCY_B4A8, /* > 4 us < 8 us */
4769 + PCIE_L1_EXIT_LATENCY_B8A16, /* > 8 us < 16 us */
4770 + PCIE_L1_EXIT_LATENCY_B16A32, /* > 16 us < 32 us */
4771 + PCIE_L1_EXIT_LATENCY_B32A64, /* > 32 us < 64 us */
4772 + PCIE_L1_EXIT_LATENCY_M64US, /* > 64 us */
4773 +};
4774 +
4775 +/* Link Control and Status Register */
4776 +#define PCIE_LCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
4777 +#define PCIE_LCTLSTS_ASPM_ENABLE 0x00000003 /* Active State Link PM Control */
4778 +#define PCIE_LCTLSTS_ASPM_ENABLE_S 0
4779 +#define PCIE_LCTLSTS_RCB128 0x00000008 /* Read Completion Boundary 128*/
4780 +#define PCIE_LCTLSTS_LINK_DISABLE 0x00000010 /* Link Disable */
4781 +#define PCIE_LCTLSTS_RETRIAN_LINK 0x00000020 /* Retrain Link */
4782 +#define PCIE_LCTLSTS_COM_CLK_CFG 0x00000040 /* Common Clock Configuration */
4783 +#define PCIE_LCTLSTS_EXT_SYNC 0x00000080 /* Extended Synch */
4784 +#define PCIE_LCTLSTS_CLK_PM_EN 0x00000100 /* Enable Clock Powerm Management */
4785 +#define PCIE_LCTLSTS_LINK_SPEED 0x000F0000 /* Link Speed */
4786 +#define PCIE_LCTLSTS_LINK_SPEED_S 16
4787 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH 0x03F00000 /* Negotiated Link Width */
4788 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
4789 +#define PCIE_LCTLSTS_RETRAIN_PENDING 0x08000000 /* Link training is ongoing */
4790 +#define PCIE_LCTLSTS_SLOT_CLK_CFG 0x10000000 /* Slot Clock Configuration */
4791 +#define PCIE_LCTLSTS_DLL_ACTIVE 0x20000000 /* Data Link Layer Active */
4792 +
4793 +/* Slot Capabilities Register */
4794 +#define PCIE_SLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
4795 +
4796 +/* Slot Capabilities */
4797 +#define PCIE_SLCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
4798 +
4799 +/* Root Control and Capability Register */
4800 +#define PCIE_RCTLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
4801 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR 0x00000001 /* #SERR on COR-ERR */
4802 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR 0x00000002 /* #SERR on Non-Fatal ERR */
4803 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR 0x00000004 /* #SERR on Fatal ERR */
4804 +#define PCIE_RCTLCAP_PME_INT_EN 0x00000008 /* PME Interrupt Enable */
4805 +#define PCIE_RCTLCAP_SERR_ENABLE (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
4806 + PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
4807 +/* Root Status Register */
4808 +#define PCIE_RSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
4809 +#define PCIE_RSTS_PME_REQ_ID 0x0000FFFF /* PME Request ID */
4810 +#define PCIE_RSTS_PME_REQ_ID_S 0
4811 +#define PCIE_RSTS_PME_STATUS 0x00010000 /* PME Status */
4812 +#define PCIE_RSTS_PME_PENDING 0x00020000 /* PME Pending */
4813 +
4814 +/* PCI Express Enhanced Capability Header */
4815 +#define PCIE_ENHANCED_CAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
4816 +#define PCIE_ENHANCED_CAP_ID 0x0000FFFF /* PCI Express Extended Capability ID */
4817 +#define PCIE_ENHANCED_CAP_ID_S 0
4818 +#define PCIE_ENHANCED_CAP_VER 0x000F0000 /* Capability Version */
4819 +#define PCIE_ENHANCED_CAP_VER_S 16
4820 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET 0xFFF00000 /* Next Capability Offset */
4821 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S 20
4822 +
4823 +/* Uncorrectable Error Status Register */
4824 +#define PCIE_UES_R(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
4825 +#define PCIE_DATA_LINK_PROTOCOL_ERR 0x00000010 /* Data Link Protocol Error Status */
4826 +#define PCIE_SURPRISE_DOWN_ERROR 0x00000020 /* Surprise Down Error Status */
4827 +#define PCIE_POISONED_TLP 0x00001000 /* Poisoned TLP Status */
4828 +#define PCIE_FC_PROTOCOL_ERR 0x00002000 /* Flow Control Protocol Error Status */
4829 +#define PCIE_COMPLETION_TIMEOUT 0x00004000 /* Completion Timeout Status */
4830 +#define PCIE_COMPLETOR_ABORT 0x00008000 /* Completer Abort Error */
4831 +#define PCIE_UNEXPECTED_COMPLETION 0x00010000 /* Unexpected Completion Status */
4832 +#define PCIE_RECEIVER_OVERFLOW 0x00020000 /* Receive Overflow Status */
4833 +#define PCIE_MALFORNED_TLP 0x00040000 /* Malformed TLP Stauts */
4834 +#define PCIE_ECRC_ERR 0x00080000 /* ECRC Error Stauts */
4835 +#define PCIE_UR_REQ 0x00100000 /* Unsupported Request Error Status */
4836 +#define PCIE_ALL_UNCORRECTABLE_ERR (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
4837 + PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT | \
4838 + PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
4839 + PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
4840 +
4841 +/* Uncorrectable Error Mask Register, Mask means no report */
4842 +#define PCIE_UEMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
4843 +
4844 +/* Uncorrectable Error Severity Register */
4845 +#define PCIE_UESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
4846 +
4847 +/* Correctable Error Status Register */
4848 +#define PCIE_CESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
4849 +#define PCIE_RX_ERR 0x00000001 /* Receive Error Status */
4850 +#define PCIE_BAD_TLP 0x00000040 /* Bad TLP Status */
4851 +#define PCIE_BAD_DLLP 0x00000080 /* Bad DLLP Status */
4852 +#define PCIE_REPLAY_NUM_ROLLOVER 0x00000100 /* Replay Number Rollover Status */
4853 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR 0x00001000 /* Reply Timer Timeout Status */
4854 +#define PCIE_ADVISORY_NONFTAL_ERR 0x00002000 /* Advisory Non-Fatal Error Status */
4855 +#define PCIE_CORRECTABLE_ERR (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
4856 + PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
4857 +
4858 +/* Correctable Error Mask Register */
4859 +#define PCIE_CEMR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
4860 +
4861 +/* Advanced Error Capabilities and Control Register */
4862 +#define PCIE_AECCR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
4863 +#define PCIE_AECCR_FIRST_ERR_PTR 0x0000001F /* First Error Pointer */
4864 +#define PCIE_AECCR_FIRST_ERR_PTR_S 0
4865 +#define PCIE_AECCR_ECRC_GEN_CAP 0x00000020 /* ECRC Generation Capable */
4866 +#define PCIE_AECCR_ECRC_GEN_EN 0x00000040 /* ECRC Generation Enable */
4867 +#define PCIE_AECCR_ECRC_CHECK_CAP 0x00000080 /* ECRC Check Capable */
4868 +#define PCIE_AECCR_ECRC_CHECK_EN 0x00000100 /* ECRC Check Enable */
4869 +
4870 +/* Header Log Register 1 */
4871 +#define PCIE_HLR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
4872 +
4873 +/* Header Log Register 2 */
4874 +#define PCIE_HLR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
4875 +
4876 +/* Header Log Register 3 */
4877 +#define PCIE_HLR3(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
4878 +
4879 +/* Header Log Register 4 */
4880 +#define PCIE_HLR4(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
4881 +
4882 +/* Root Error Command Register */
4883 +#define PCIE_RECR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
4884 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN 0x00000001 /* COR-ERR */
4885 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN 0x00000002 /* Non-Fatal ERR */
4886 +#define PCIE_RECR_FATAL_ERR_REPORT_EN 0x00000004 /* Fatal ERR */
4887 +#define PCIE_RECR_ERR_REPORT_EN (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
4888 + PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
4889 +
4890 +/* Root Error Status Register */
4891 +#define PCIE_RESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
4892 +#define PCIE_RESR_CORRECTABLE_ERR 0x00000001 /* COR-ERR Receveid */
4893 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR 0x00000002 /* Multiple COR-ERR Received */
4894 +#define PCIE_RESR_FATAL_NOFATAL_ERR 0x00000004 /* ERR Fatal/Non-Fatal Received */
4895 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR 0x00000008 /* Multiple ERR Fatal/Non-Fatal Received */
4896 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR 0x00000010 /* First UN-COR Fatal */
4897 +#define PCIR_RESR_NON_FATAL_ERR 0x00000020 /* Non-Fatal Error Message Received */
4898 +#define PCIE_RESR_FATAL_ERR 0x00000040 /* Fatal Message Received */
4899 +#define PCIE_RESR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
4900 +#define PCIE_RESR_AER_INT_MSG_NUM_S 27
4901 +
4902 +/* Error Source Indentification Register */
4903 +#define PCIE_ESIR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
4904 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID 0x0000FFFF
4905 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S 0
4906 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID 0xFFFF0000
4907 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S 16
4908 +
4909 +/* VC Enhanced Capability Header */
4910 +#define PCIE_VC_ECH(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
4911 +
4912 +/* Port VC Capability Register */
4913 +#define PCIE_PVC1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
4914 +#define PCIE_PVC1_EXT_VC_CNT 0x00000007 /* Extended VC Count */
4915 +#define PCIE_PVC1_EXT_VC_CNT_S 0
4916 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT 0x00000070 /* Low Priority Extended VC Count */
4917 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S 4
4918 +#define PCIE_PVC1_REF_CLK 0x00000300 /* Reference Clock */
4919 +#define PCIE_PVC1_REF_CLK_S 8
4920 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE 0x00000C00 /* Port Arbitration Table Entry Size */
4921 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S 10
4922 +
4923 +/* Extended Virtual Channel Count Defintion */
4924 +#define PCIE_EXT_VC_CNT_MIN 0
4925 +#define PCIE_EXT_VC_CNT_MAX 7
4926 +
4927 +/* Port Arbitration Table Entry Size Definition */
4928 +enum {
4929 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
4930 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
4931 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
4932 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
4933 +};
4934 +
4935 +/* Port VC Capability Register 2 */
4936 +#define PCIE_PVC2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
4937 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR 0x00000001 /* HW Fixed arbitration, 16 phase WRR */
4938 +#define PCIE_PVC2_VC_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
4939 +#define PCIE_PVC2_VC_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
4940 +#define PCIE_PVC2_VC_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
4941 +#define PCIE_PVC2_VC_ARB_WRR 0x0000000F
4942 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET 0xFF000000 /* VC arbitration table offset, not support */
4943 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S 24
4944 +
4945 +/* Port VC Control and Status Register */
4946 +#define PCIE_PVCCRSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
4947 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB 0x00000001 /* Load VC Arbitration Table */
4948 +#define PCIE_PVCCRSR_VC_ARB_SEL 0x0000000E /* VC Arbitration Select */
4949 +#define PCIE_PVCCRSR_VC_ARB_SEL_S 1
4950 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS 0x00010000 /* Arbitration Status */
4951 +
4952 +/* VC0 Resource Capability Register */
4953 +#define PCIE_VC0_RC(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
4954 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED 0x00000001 /* HW Fixed arbitration */
4955 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
4956 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
4957 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
4958 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR 0x00000010 /* Time-based 128 phase WRR */
4959 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR 0x00000020 /* Time-based 256 phase WRR */
4960 +#define PCIE_VC0_RC_PORT_ARB (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
4961 + PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
4962 + PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
4963 +
4964 +#define PCIE_VC0_RC_REJECT_SNOOP 0x00008000 /* Reject Snoop Transactioin */
4965 +#define PCIE_VC0_RC_MAX_TIMESLOTS 0x007F0000 /* Maximum time Slots */
4966 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S 16
4967 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET 0xFF000000 /* Port Arbitration Table Offset */
4968 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S 24
4969 +
4970 +/* VC0 Resource Control Register */
4971 +#define PCIE_VC0_RC0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
4972 +#define PCIE_VC0_RC0_TVM0 0x00000001 /* TC0 and VC0 */
4973 +#define PCIE_VC0_RC0_TVM1 0x00000002 /* TC1 and VC1 */
4974 +#define PCIE_VC0_RC0_TVM2 0x00000004 /* TC2 and VC2 */
4975 +#define PCIE_VC0_RC0_TVM3 0x00000008 /* TC3 and VC3 */
4976 +#define PCIE_VC0_RC0_TVM4 0x00000010 /* TC4 and VC4 */
4977 +#define PCIE_VC0_RC0_TVM5 0x00000020 /* TC5 and VC5 */
4978 +#define PCIE_VC0_RC0_TVM6 0x00000040 /* TC6 and VC6 */
4979 +#define PCIE_VC0_RC0_TVM7 0x00000080 /* TC7 and VC7 */
4980 +#define PCIE_VC0_RC0_TC_VC 0x000000FF /* TC/VC mask */
4981 +
4982 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB 0x00010000 /* Load Port Arbitration Table */
4983 +#define PCIE_VC0_RC0_PORT_ARB_SEL 0x000E0000 /* Port Arbitration Select */
4984 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S 17
4985 +#define PCIE_VC0_RC0_VC_ID 0x07000000 /* VC ID */
4986 +#define PCIE_VC0_RC0_VC_ID_S 24
4987 +#define PCIE_VC0_RC0_VC_EN 0x80000000 /* VC Enable */
4988 +
4989 +/* VC0 Resource Status Register */
4990 +#define PCIE_VC0_RSR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
4991 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS 0x00010000 /* Port Arbitration Table Status,not used */
4992 +#define PCIE_VC0_RSR0_VC_NEG_PENDING 0x00020000 /* VC Negotiation Pending */
4993 +
4994 +/* Ack Latency Timer and Replay Timer Register */
4995 +#define PCIE_ALTRT(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
4996 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT 0x0000FFFF /* Round Trip Latency Time Limit */
4997 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
4998 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT 0xFFFF0000 /* Replay Time Limit */
4999 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S 16
5000 +
5001 +/* Other Message Register */
5002 +#define PCIE_OMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
5003 +
5004 +/* Port Force Link Register */
5005 +#define PCIE_PFLR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
5006 +#define PCIE_PFLR_LINK_NUM 0x000000FF /* Link Number */
5007 +#define PCIE_PFLR_LINK_NUM_S 0
5008 +#define PCIE_PFLR_FORCE_LINK 0x00008000 /* Force link */
5009 +#define PCIE_PFLR_LINK_STATE 0x003F0000 /* Link State */
5010 +#define PCIE_PFLR_LINK_STATE_S 16
5011 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT 0xFF000000 /* Low Power Entrance Count, only for EP */
5012 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S 24
5013 +
5014 +/* Ack Frequency Register */
5015 +#define PCIE_AFR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
5016 +#define PCIE_AFR_AF 0x000000FF /* Ack Frequency */
5017 +#define PCIE_AFR_AF_S 0
5018 +#define PCIE_AFR_FTS_NUM 0x0000FF00 /* The number of Fast Training Sequence from L0S to L0 */
5019 +#define PCIE_AFR_FTS_NUM_S 8
5020 +#define PCIE_AFR_COM_FTS_NUM 0x00FF0000 /* N_FTS; when common clock is used*/
5021 +#define PCIE_AFR_COM_FTS_NUM_S 16
5022 +#define PCIE_AFR_L0S_ENTRY_LATENCY 0x07000000 /* L0s Entrance Latency */
5023 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S 24
5024 +#define PCIE_AFR_L1_ENTRY_LATENCY 0x38000000 /* L1 Entrance Latency */
5025 +#define PCIE_AFR_L1_ENTRY_LATENCY_S 27
5026 +#define PCIE_AFR_FTS_NUM_DEFAULT 32
5027 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT 7
5028 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT 5
5029 +
5030 +/* Port Link Control Register */
5031 +#define PCIE_PLCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
5032 +#define PCIE_PLCR_OTHER_MSG_REQ 0x00000001 /* Other Message Request */
5033 +#define PCIE_PLCR_SCRAMBLE_DISABLE 0x00000002 /* Scramble Disable */
5034 +#define PCIE_PLCR_LOOPBACK_EN 0x00000004 /* Loopback Enable */
5035 +#define PCIE_PLCR_LTSSM_HOT_RST 0x00000008 /* Force LTSSM to the hot reset */
5036 +#define PCIE_PLCR_DLL_LINK_EN 0x00000020 /* Enable Link initialization */
5037 +#define PCIE_PLCR_FAST_LINK_SIM_EN 0x00000080 /* Sets all internal timers to fast mode for simulation purposes */
5038 +#define PCIE_PLCR_LINK_MODE 0x003F0000 /* Link Mode Enable Mask */
5039 +#define PCIE_PLCR_LINK_MODE_S 16
5040 +#define PCIE_PLCR_CORRUPTED_CRC_EN 0x02000000 /* Enabled Corrupt CRC */
5041 +
5042 +/* Lane Skew Register */
5043 +#define PCIE_LSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
5044 +#define PCIE_LSR_LANE_SKEW_NUM 0x00FFFFFF /* Insert Lane Skew for Transmit, not applicable */
5045 +#define PCIE_LSR_LANE_SKEW_NUM_S 0
5046 +#define PCIE_LSR_FC_DISABLE 0x01000000 /* Disable of Flow Control */
5047 +#define PCIE_LSR_ACKNAK_DISABLE 0x02000000 /* Disable of Ack/Nak */
5048 +#define PCIE_LSR_LANE_DESKEW_DISABLE 0x80000000 /* Disable of Lane-to-Lane Skew */
5049 +
5050 +/* Symbol Number Register */
5051 +#define PCIE_SNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
5052 +#define PCIE_SNR_TS 0x0000000F /* Number of TS Symbol */
5053 +#define PCIE_SNR_TS_S 0
5054 +#define PCIE_SNR_SKP 0x00000700 /* Number of SKP Symbol */
5055 +#define PCIE_SNR_SKP_S 8
5056 +#define PCIE_SNR_REPLAY_TIMER 0x0007C000 /* Timer Modifier for Replay Timer */
5057 +#define PCIE_SNR_REPLAY_TIMER_S 14
5058 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER 0x00F80000 /* Timer Modifier for Ack/Nak Latency Timer */
5059 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S 19
5060 +#define PCIE_SNR_FC_TIMER 0x1F000000 /* Timer Modifier for Flow Control Watchdog Timer */
5061 +#define PCIE_SNR_FC_TIMER_S 28
5062 +
5063 +/* Symbol Timer Register and Filter Mask Register 1 */
5064 +#define PCIE_STRFMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
5065 +#define PCIE_STRFMR_SKP_INTERVAL 0x000007FF /* SKP lnterval Value */
5066 +#define PCIE_STRFMR_SKP_INTERVAL_S 0
5067 +#define PCIE_STRFMR_FC_WDT_DISABLE 0x00008000 /* Disable of FC Watchdog Timer */
5068 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK 0x00010000 /* Mask Function Mismatch Filtering for Incoming Requests */
5069 +#define PCIE_STRFMR_POISONED_TLP_OK 0x00020000 /* Mask Poisoned TLP Filtering */
5070 +#define PCIE_STRFMR_BAR_MATCH_OK 0x00040000 /* Mask BAR Match Filtering */
5071 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK 0x00080000 /* Mask Type 1 Configuration Request Filtering */
5072 +#define PCIE_STRFMR_LOCKED_REQ_OK 0x00100000 /* Mask Locked Request Filtering */
5073 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK 0x00200000 /* Mask Tag Error Rules for Received Completions */
5074 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000 /* Mask Requester ID Mismatch Error for Received Completions */
5075 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK 0x00800000 /* Mask Function Mismatch Error for Received Completions */
5076 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK 0x01000000 /* Mask Traffic Class Mismatch Error for Received Completions */
5077 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK 0x02000000 /* Mask Attribute Mismatch Error for Received Completions */
5078 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK 0x04000000 /* Mask Length Mismatch Error for Received Completions */
5079 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK 0x08000000 /* Mask ECRC Error Filtering */
5080 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK 0x10000000 /* Mask ECRC Error Filtering for Completions */
5081 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP 0x20000000 /* Send Message TLPs */
5082 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE 0x40000000 /* Mask Filtering of received I/O Requests */
5083 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE 0x80000000 /* Mask Filtering of Received Configuration Requests */
5084 +
5085 +#define PCIE_DEF_SKP_INTERVAL 700 /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
5086 +
5087 +/* Filter Masker Register 2 */
5088 +#define PCIE_FMR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
5089 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1 0x00000001 /* Mask RADM Filtering and Error Handling Rules */
5090 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 0x00000002 /* Mask RADM Filtering and Error Handling Rules */
5091 +
5092 +/* Debug Register 0 */
5093 +#define PCIE_DBR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
5094 +
5095 +/* Debug Register 1 */
5096 +#define PCIE_DBR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
5097 +
5098 +/* Transmit Posted FC Credit Status Register */
5099 +#define PCIE_TPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
5100 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS 0x00000FFF /* Transmit Posted Data FC Credits */
5101 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S 0
5102 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS 0x000FF000 /* Transmit Posted Header FC Credits */
5103 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S 12
5104 +
5105 +/* Transmit Non-Posted FC Credit Status */
5106 +#define PCIE_TNPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
5107 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS 0x00000FFF /* Transmit Non-Posted Data FC Credits */
5108 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S 0
5109 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS 0x000FF000 /* Transmit Non-Posted Header FC Credits */
5110 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S 12
5111 +
5112 +/* Transmit Complete FC Credit Status Register */
5113 +#define PCIE_TCFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
5114 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS 0x00000FFF /* Transmit Completion Data FC Credits */
5115 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S 0
5116 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS 0x000FF000 /* Transmit Completion Header FC Credits */
5117 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S 12
5118 +
5119 +/* Queue Status Register */
5120 +#define PCIE_QSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
5121 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL 0x00000001 /* Received TLP FC Credits Not Returned */
5122 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY 0x00000002 /* Transmit Retry Buffer Not Empty */
5123 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY 0x00000004 /* Received Queue Not Empty */
5124 +
5125 +/* VC Transmit Arbitration Register 1 */
5126 +#define PCIE_VCTAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
5127 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0 0x000000FF /* WRR Weight for VC0 */
5128 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1 0x0000FF00 /* WRR Weight for VC1 */
5129 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2 0x00FF0000 /* WRR Weight for VC2 */
5130 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3 0xFF000000 /* WRR Weight for VC3 */
5131 +
5132 +/* VC Transmit Arbitration Register 2 */
5133 +#define PCIE_VCTAR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
5134 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4 0x000000FF /* WRR Weight for VC4 */
5135 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5 0x0000FF00 /* WRR Weight for VC5 */
5136 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6 0x00FF0000 /* WRR Weight for VC6 */
5137 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7 0xFF000000 /* WRR Weight for VC7 */
5138 +
5139 +/* VC0 Posted Receive Queue Control Register */
5140 +#define PCIE_VC0_PRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
5141 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS 0x00000FFF /* VC0 Posted Data Credits */
5142 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S 0
5143 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS 0x000FF000 /* VC0 Posted Header Credits */
5144 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S 12
5145 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE 0x00E00000 /* VC0 Posted TLP Queue Mode */
5146 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S 20
5147 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER 0x40000000 /* TLP Type Ordering for VC0 */
5148 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER 0x80000000 /* VC0 Ordering for Receive Queues */
5149 +
5150 +/* VC0 Non-Posted Receive Queue Control */
5151 +#define PCIE_VC0_NPRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
5152 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS 0x00000FFF /* VC0 Non-Posted Data Credits */
5153 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S 0
5154 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS 0x000FF000 /* VC0 Non-Posted Header Credits */
5155 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S 12
5156 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE 0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
5157 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S 20
5158 +
5159 +/* VC0 Completion Receive Queue Control */
5160 +#define PCIE_VC0_CRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
5161 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS 0x00000FFF /* VC0 Completion TLP Queue Mode */
5162 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S 0
5163 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS 0x000FF000 /* VC0 Completion Header Credits */
5164 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S 12
5165 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE 0x00E00000 /* VC0 Completion Data Credits */
5166 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S 21
5167 +
5168 +/* Applicable to the above three registers */
5169 +enum {
5170 + PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
5171 + PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH = 2,
5172 + PCIE_VC0_TLP_QUEUE_MODE_BYPASS = 4,
5173 +};
5174 +
5175 +/* VC0 Posted Buffer Depth Register */
5176 +#define PCIE_VC0_PBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
5177 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Posted Data Queue Depth */
5178 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S 0
5179 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Posted Header Queue Depth */
5180 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S 16
5181 +
5182 +/* VC0 Non-Posted Buffer Depth Register */
5183 +#define PCIE_VC0_NPBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
5184 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Non-Posted Data Queue Depth */
5185 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S 0
5186 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
5187 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S 16
5188 +
5189 +/* VC0 Completion Buffer Depth Register */
5190 +#define PCIE_VC0_CBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
5191 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES 0x00003FFF /* C0 Completion Data Queue Depth */
5192 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S 0
5193 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Completion Header Queue Depth */
5194 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S 16
5195 +
5196 +/* PHY Status Register, all zeros in VR9 */
5197 +#define PCIE_PHYSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
5198 +
5199 +/* PHY Control Register, all zeros in VR9 */
5200 +#define PCIE_PHYCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
5201 +
5202 +/*
5203 + * PCIe PDI PHY register definition, suppose all the following
5204 + * stuff is confidential.
5205 + * XXX, detailed bit definition
5206 + */
5207 +#define PCIE_PHY_PLL_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
5208 +#define PCIE_PHY_PLL_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
5209 +#define PCIE_PHY_PLL_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
5210 +#define PCIE_PHY_PLL_CTRL4(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
5211 +#define PCIE_PHY_PLL_CTRL5(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
5212 +#define PCIE_PHY_PLL_CTRL6(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
5213 +#define PCIE_PHY_PLL_CTRL7(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
5214 +#define PCIE_PHY_PLL_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
5215 +#define PCIE_PHY_PLL_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
5216 +#define PCIE_PHY_PLL_A_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
5217 +#define PCIE_PHY_PLL_STATUS(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
5218 +
5219 +#define PCIE_PHY_TX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
5220 +#define PCIE_PHY_TX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
5221 +#define PCIE_PHY_TX1_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
5222 +#define PCIE_PHY_TX1_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
5223 +#define PCIE_PHY_TX1_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
5224 +#define PCIE_PHY_TX1_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
5225 +#define PCIE_PHY_TX1_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
5226 +#define PCIE_PHY_TX1_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
5227 +
5228 +#define PCIE_PHY_TX2_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
5229 +#define PCIE_PHY_TX2_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
5230 +#define PCIE_PHY_TX2_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
5231 +#define PCIE_PHY_TX2_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
5232 +#define PCIE_PHY_TX2_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
5233 +#define PCIE_PHY_TX2_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
5234 +#define PCIE_PHY_TX2_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
5235 +
5236 +#define PCIE_PHY_RX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
5237 +#define PCIE_PHY_RX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
5238 +#define PCIE_PHY_RX1_CDR(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
5239 +#define PCIE_PHY_RX1_EI(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
5240 +#define PCIE_PHY_RX1_A_CTRL(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
5241 +
5242 +/* Interrupt related stuff */
5243 +#define PCIE_LEGACY_DISABLE 0
5244 +#define PCIE_LEGACY_INTA 1
5245 +#define PCIE_LEGACY_INTB 2
5246 +#define PCIE_LEGACY_INTC 3
5247 +#define PCIE_LEGACY_INTD 4
5248 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
5249 +
5250 +#define PCIE_IRQ_LOCK(lock) do { \
5251 + unsigned long flags; \
5252 + spin_lock_irqsave(&(lock), flags);
5253 +#define PCIE_IRQ_UNLOCK(lock) \
5254 + spin_unlock_irqrestore(&(lock), flags); \
5255 +} while (0)
5256 +
5257 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
5258 +#define IRQF_SHARED SA_SHIRQ
5259 +#endif
5260 +
5261 +#define PCIE_MSG_MSI 0x00000001
5262 +#define PCIE_MSG_ISR 0x00000002
5263 +#define PCIE_MSG_FIXUP 0x00000004
5264 +#define PCIE_MSG_READ_CFG 0x00000008
5265 +#define PCIE_MSG_WRITE_CFG 0x00000010
5266 +#define PCIE_MSG_CFG (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
5267 +#define PCIE_MSG_REG 0x00000020
5268 +#define PCIE_MSG_INIT 0x00000040
5269 +#define PCIE_MSG_ERR 0x00000080
5270 +#define PCIE_MSG_PHY 0x00000100
5271 +#define PCIE_MSG_ANY 0x000001ff
5272 +
5273 +#define IFX_PCIE_PORT0 0
5274 +#define IFX_PCIE_PORT1 1
5275 +
5276 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
5277 +#define IFX_PCIE_CORE_NR 2
5278 +#else
5279 +#define IFX_PCIE_CORE_NR 1
5280 +#endif
5281 +
5282 +//#define IFX_PCIE_ERROR_INT
5283 +
5284 +//#define IFX_PCIE_DBG
5285 +
5286 +#if defined(IFX_PCIE_DBG)
5287 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do { \
5288 + if (g_pcie_debug_flag & (_m)) { \
5289 + ifx_pcie_debug((_fmt), ##args); \
5290 + } \
5291 +} while (0)
5292 +
5293 +#define INLINE
5294 +#else
5295 +#define IFX_PCIE_PRINT(_m, _fmt, args...) \
5296 + do {} while(0)
5297 +#define INLINE inline
5298 +#endif
5299 +
5300 +struct ifx_pci_controller {
5301 + struct pci_controller pcic;
5302 +
5303 + /* RC specific, per host bus information */
5304 + u32 port; /* Port index, 0 -- 1st core, 1 -- 2nd core */
5305 +};
5306 +
5307 +typedef struct ifx_pcie_ir_irq {
5308 + const unsigned int irq;
5309 + const char name[16];
5310 +}ifx_pcie_ir_irq_t;
5311 +
5312 +typedef struct ifx_pcie_legacy_irq{
5313 + const u32 irq_bit;
5314 + const int irq;
5315 +}ifx_pcie_legacy_irq_t;
5316 +
5317 +typedef struct ifx_pcie_irq {
5318 + ifx_pcie_ir_irq_t ir_irq;
5319 + ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
5320 +}ifx_pcie_irq_t;
5321 +
5322 +extern u32 g_pcie_debug_flag;
5323 +extern void ifx_pcie_debug(const char *fmt, ...);
5324 +extern void pcie_phy_clock_mode_setup(int pcie_port);
5325 +extern void pcie_msi_pic_init(int pcie_port);
5326 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
5327 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
5328 +
5329 +
5330 +#include <linux/types.h>
5331 +#include <linux/delay.h>
5332 +#include <linux/gpio.h>
5333 +#include <linux/clk.h>
5334 +
5335 +#include <lantiq_soc.h>
5336 +
5337 +#define IFX_PCIE_GPIO_RESET 38
5338 +#define IFX_REG_R32 ltq_r32
5339 +#define IFX_REG_W32 ltq_w32
5340 +#define CONFIG_IFX_PCIE_HW_SWAP
5341 +#define IFX_RCU_AHB_ENDIAN ((volatile u32*)(IFX_RCU + 0x004C))
5342 +#define IFX_RCU_RST_REQ ((volatile u32*)(IFX_RCU + 0x0010))
5343 +#define IFX_RCU_AHB_BE_PCIE_PDI 0x00000080 /* Configure PCIE PDI module in big endian*/
5344 +
5345 +#define IFX_RCU (KSEG1 | 0x1F203000)
5346 +#define IFX_RCU_AHB_BE_PCIE_M 0x00000001 /* Configure AHB master port that connects to PCIe RC in big endian */
5347 +#define IFX_RCU_AHB_BE_PCIE_S 0x00000010 /* Configure AHB slave port that connects to PCIe RC in little endian */
5348 +#define IFX_RCU_AHB_BE_XBAR_M 0x00000002 /* Configure AHB master port that connects to XBAR in big endian */
5349 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
5350 +
5351 +#define IFX_PMU1_MODULE_PCIE_PHY (0)
5352 +#define IFX_PMU1_MODULE_PCIE_CTRL (1)
5353 +#define IFX_PMU1_MODULE_PDI (4)
5354 +#define IFX_PMU1_MODULE_MSI (5)
5355 +
5356 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
5357 +
5358 +
5359 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
5360 +{
5361 +}
5362 +
5363 +static inline void pcie_ahb_pmu_setup(void)
5364 +{
5365 + struct clk *clk;
5366 + clk = clk_get_sys("ltq_pcie", "ahb");
5367 + clk_enable(clk);
5368 + //ltq_pmu_enable(PMU_AHBM | PMU_AHBS);
5369 +}
5370 +
5371 +static inline void pcie_rcu_endian_setup(int pcie_port)
5372 +{
5373 + u32 reg;
5374 +
5375 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
5376 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
5377 + reg |= IFX_RCU_AHB_BE_PCIE_M;
5378 + reg |= IFX_RCU_AHB_BE_PCIE_S;
5379 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
5380 +#else
5381 + reg |= IFX_RCU_AHB_BE_PCIE_M;
5382 + reg &= ~IFX_RCU_AHB_BE_PCIE_S;
5383 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
5384 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
5385 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
5386 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
5387 +}
5388 +
5389 +static inline void pcie_phy_pmu_enable(int pcie_port)
5390 +{
5391 + struct clk *clk;
5392 + clk = clk_get_sys("ltq_pcie", "phy");
5393 + clk_enable(clk);
5394 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PCIE_PHY);
5395 +}
5396 +
5397 +static inline void pcie_phy_pmu_disable(int pcie_port)
5398 +{
5399 + struct clk *clk;
5400 + clk = clk_get_sys("ltq_pcie", "phy");
5401 + clk_disable(clk);
5402 + //ltq_pmu1_disable(1<<IFX_PMU1_MODULE_PCIE_PHY);
5403 +}
5404 +
5405 +static inline void pcie_pdi_big_endian(int pcie_port)
5406 +{
5407 + u32 reg;
5408 +
5409 + /* SRAM2PDI endianness control. */
5410 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
5411 + /* Config AHB->PCIe and PDI endianness */
5412 + reg |= IFX_RCU_AHB_BE_PCIE_PDI;
5413 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
5414 +}
5415 +
5416 +static inline void pcie_pdi_pmu_enable(int pcie_port)
5417 +{
5418 + struct clk *clk;
5419 + clk = clk_get_sys("ltq_pcie", "pdi");
5420 + clk_enable(clk);
5421 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PDI);
5422 +}
5423 +
5424 +static inline void pcie_core_rst_assert(int pcie_port)
5425 +{
5426 + u32 reg;
5427 +
5428 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5429 +
5430 + /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
5431 + reg |= 0x00400000;
5432 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5433 +}
5434 +
5435 +static inline void pcie_core_rst_deassert(int pcie_port)
5436 +{
5437 + u32 reg;
5438 +
5439 + /* Make sure one micro-second delay */
5440 + udelay(1);
5441 +
5442 + /* Reset PCIe PHY & Core, bit 22 */
5443 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5444 + reg &= ~0x00400000;
5445 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5446 +}
5447 +
5448 +static inline void pcie_phy_rst_assert(int pcie_port)
5449 +{
5450 + u32 reg;
5451 +
5452 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5453 + reg |= 0x00001000; /* Bit 12 */
5454 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5455 +}
5456 +
5457 +static inline void pcie_phy_rst_deassert(int pcie_port)
5458 +{
5459 + u32 reg;
5460 +
5461 + /* Make sure one micro-second delay */
5462 + udelay(1);
5463 +
5464 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
5465 + reg &= ~0x00001000; /* Bit 12 */
5466 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
5467 +}
5468 +
5469 +static inline void pcie_device_rst_assert(int pcie_port)
5470 +{
5471 + gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
5472 + // ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
5473 +}
5474 +
5475 +static inline void pcie_device_rst_deassert(int pcie_port)
5476 +{
5477 + mdelay(100);
5478 + gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
5479 +// ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
5480 +}
5481 +
5482 +static inline void pcie_core_pmu_setup(int pcie_port)
5483 +{
5484 + struct clk *clk;
5485 + clk = clk_get_sys("ltq_pcie", "ctl");
5486 + clk_enable(clk);
5487 + clk = clk_get_sys("ltq_pcie", "bus");
5488 + clk_enable(clk);
5489 +
5490 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_PCIE_CTRL);
5491 + //ltq_pmu_enable(1 << IFX_PMU_MODULE_PCIE_L0_CLK);
5492 +}
5493 +
5494 +static inline void pcie_msi_init(int pcie_port)
5495 +{
5496 + struct clk *clk;
5497 + pcie_msi_pic_init(pcie_port);
5498 + clk = clk_get_sys("ltq_pcie", "msi");
5499 + clk_enable(clk);
5500 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_MSI);
5501 +}
5502 +
5503 +static inline u32
5504 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
5505 +{
5506 + u32 tbus_number = bus_number;
5507 +
5508 +#ifdef CONFIG_IFX_PCI
5509 + if (pcibios_host_nr() > 1) {
5510 + tbus_number -= pcibios_1st_host_bus_nr();
5511 + }
5512 +#endif /* CONFIG_IFX_PCI */
5513 + return tbus_number;
5514 +}
5515 +
5516 +static inline u32
5517 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
5518 +{
5519 + struct pci_dev *pdev;
5520 + u32 tvalue = value;
5521 +
5522 + /* Sanity check */
5523 + pdev = pci_get_slot(bus, devfn);
5524 + if (pdev == NULL) {
5525 + return tvalue;
5526 + }
5527 +
5528 + /* Only care about PCI bridge */
5529 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
5530 + return tvalue;
5531 + }
5532 +
5533 + if (read) { /* Read hack */
5534 + #ifdef CONFIG_IFX_PCI
5535 + if (pcibios_host_nr() > 1) {
5536 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
5537 + }
5538 + #endif /* CONFIG_IFX_PCI */
5539 + }
5540 + else { /* Write hack */
5541 + #ifdef CONFIG_IFX_PCI
5542 + if (pcibios_host_nr() > 1) {
5543 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
5544 + }
5545 + #endif
5546 + }
5547 + return tvalue;
5548 +}
5549 +
5550 +#endif /* IFXMIPS_PCIE_VR9_H */
5551 +
5552 diff --git a/drivers/pci/pcie/aer/Kconfig b/drivers/pci/pcie/aer/Kconfig
5553 index 50e94e0..4bf848f 100644
5554 --- a/drivers/pci/pcie/aer/Kconfig
5555 +++ b/drivers/pci/pcie/aer/Kconfig
5556 @@ -5,7 +5,7 @@
5557 config PCIEAER
5558 boolean "Root Port Advanced Error Reporting support"
5559 depends on PCIEPORTBUS
5560 - default y
5561 + default n
5562 help
5563 This enables PCI Express Root Port Advanced Error Reporting
5564 (AER) driver support. Error reporting messages sent to Root
5565 diff --git a/include/linux/pci.h b/include/linux/pci.h
5566 index 3a24e4f..25b0349 100644
5567 --- a/include/linux/pci.h
5568 +++ b/include/linux/pci.h
5569 @@ -1082,6 +1082,8 @@ void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
5570 int pci_cfg_space_size_ext(struct pci_dev *dev);
5571 int pci_cfg_space_size(struct pci_dev *dev);
5572 unsigned char pci_bus_max_busnr(struct pci_bus *bus);
5573 +int pcibios_host_nr(void);
5574 +int pcibios_1st_host_bus_nr(void);
5575 void pci_setup_bridge(struct pci_bus *bus);
5576 resource_size_t pcibios_window_alignment(struct pci_bus *bus,
5577 unsigned long type);
5578 diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
5579 index c129162..c503ac9 100644
5580 --- a/include/linux/pci_ids.h
5581 +++ b/include/linux/pci_ids.h
5582 @@ -1042,6 +1042,12 @@
5583 #define PCI_DEVICE_ID_SGI_LITHIUM 0x1002
5584 #define PCI_DEVICE_ID_SGI_IOC4 0x100a
5585
5586 +#define PCI_VENDOR_ID_INFINEON 0x15D1
5587 +#define PCI_DEVICE_ID_INFINEON_DANUBE 0x000F
5588 +#define PCI_DEVICE_ID_INFINEON_PCIE 0x0011
5589 +#define PCI_VENDOR_ID_LANTIQ 0x1BEF
5590 +#define PCI_DEVICE_ID_LANTIQ_PCIE 0x00
5591 +
5592 #define PCI_VENDOR_ID_WINBOND 0x10ad
5593 #define PCI_DEVICE_ID_WINBOND_82C105 0x0105
5594 #define PCI_DEVICE_ID_WINBOND_83C553 0x0565
5595 --
5596 1.7.10.4
5597