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