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