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