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