1 From ab91bdfb7d8dbeebe4594b96cf81721f97012d24 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 8 Mar 2012 15:57:33 +0100
4 Subject: [PATCH 54/73] MIPS: lantiq: pcie: add pcie driver
7 arch/mips/Kconfig | 1 +
8 arch/mips/lantiq/Kconfig | 4 -
9 arch/mips/lantiq/xway/Kconfig | 21 +
10 arch/mips/pci/Makefile | 2 +
11 arch/mips/pci/fixup-lantiq-pcie.c | 81 +++
12 arch/mips/pci/pci.c | 25 +
13 arch/mips/pci/pcie-lantiq-msi.c | 399 +++++++++++
14 arch/mips/pci/pcie-lantiq-phy.c | 408 ++++++++++++
15 arch/mips/pci/pcie-lantiq.c | 1146 ++++++++++++++++++++++++++++++++
16 arch/mips/pci/pcie-lantiq.h | 1305 +++++++++++++++++++++++++++++++++++++
17 10 files changed, 3388 insertions(+), 4 deletions(-)
18 create mode 100644 arch/mips/pci/fixup-lantiq-pcie.c
19 create mode 100644 arch/mips/pci/pcie-lantiq-msi.c
20 create mode 100644 arch/mips/pci/pcie-lantiq-phy.c
21 create mode 100644 arch/mips/pci/pcie-lantiq.c
22 create mode 100644 arch/mips/pci/pcie-lantiq.h
24 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
25 index 1b78cd7..bbaff9b 100644
26 --- a/arch/mips/Kconfig
27 +++ b/arch/mips/Kconfig
28 @@ -2329,6 +2329,7 @@ config PCI_DOMAINS
31 source "drivers/pci/Kconfig"
32 +source "drivers/pci/pcie/Kconfig"
35 # ISA support is now enabled via select. Too many systems still have the one
36 diff --git a/arch/mips/lantiq/Kconfig b/arch/mips/lantiq/Kconfig
37 index dde9fc6..d21d9d4 100644
38 --- a/arch/mips/lantiq/Kconfig
39 +++ b/arch/mips/lantiq/Kconfig
40 @@ -22,10 +22,6 @@ config SOC_FALCON
46 - depends on SOC_XWAY && PCI
48 source "arch/mips/lantiq/xway/Kconfig"
49 source "arch/mips/lantiq/falcon/Kconfig"
51 diff --git a/arch/mips/lantiq/xway/Kconfig b/arch/mips/lantiq/xway/Kconfig
52 index 2b857de..54a51ff 100644
53 --- a/arch/mips/lantiq/xway/Kconfig
54 +++ b/arch/mips/lantiq/xway/Kconfig
55 @@ -8,6 +8,27 @@ config LANTIQ_MACH_EASY50712
61 + default PCI_LANTIQ_NONE
63 +config PCI_LANTIQ_NONE
72 + select ARCH_SUPPORTS_MSI
76 +config PCIE_LANTIQ_MSI
78 + depends on PCIE_LANTIQ && PCI_MSI
83 diff --git a/arch/mips/pci/Makefile b/arch/mips/pci/Makefile
84 index 3ca5f75..3386888 100644
85 --- a/arch/mips/pci/Makefile
86 +++ b/arch/mips/pci/Makefile
87 @@ -42,6 +42,8 @@ obj-$(CONFIG_SIBYTE_BCM1x80) += pci-bcm1480.o pci-bcm1480ht.o
88 obj-$(CONFIG_SNI_RM) += fixup-sni.o ops-sni.o
89 obj-$(CONFIG_LANTIQ) += fixup-lantiq.o
90 obj-$(CONFIG_PCI_LANTIQ) += pci-lantiq.o ops-lantiq.o
91 +obj-$(CONFIG_PCIE_LANTIQ) += pcie-lantiq-phy.o pcie-lantiq.o fixup-lantiq-pcie.o
92 +obj-$(CONFIG_PCIE_LANTIQ_MSI) += pcie-lantiq-msi.o
93 obj-$(CONFIG_TANBAC_TB0219) += fixup-tb0219.o
94 obj-$(CONFIG_TANBAC_TB0226) += fixup-tb0226.o
95 obj-$(CONFIG_TANBAC_TB0287) += fixup-tb0287.o
96 diff --git a/arch/mips/pci/fixup-lantiq-pcie.c b/arch/mips/pci/fixup-lantiq-pcie.c
98 index 0000000..84517df
100 +++ b/arch/mips/pci/fixup-lantiq-pcie.c
102 +/******************************************************************************
104 +** FILE NAME : ifxmips_fixup_pcie.c
105 +** PROJECT : IFX UEIP for VRX200
108 +** DATE : 02 Mar 2009
109 +** AUTHOR : Lei Chuanhua
110 +** DESCRIPTION : PCIe Root Complex Driver
111 +** COPYRIGHT : Copyright (c) 2009
112 +** Infineon Technologies AG
113 +** Am Campeon 1-12, 85579 Neubiberg, Germany
115 +** This program is free software; you can redistribute it and/or modify
116 +** it under the terms of the GNU General Public License as published by
117 +** the Free Software Foundation; either version 2 of the License, or
118 +** (at your option) any later version.
120 +** $Version $Date $Author $Comment
121 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
122 +*******************************************************************************/
124 + \file ifxmips_fixup_pcie.c
126 + \brief PCIe Fixup functions source file
128 +#include <linux/pci.h>
129 +#include <linux/pci_regs.h>
130 +#include <linux/pci_ids.h>
132 +#include <lantiq_soc.h>
134 +#include "pcie-lantiq.h"
136 +#define PCI_VENDOR_ID_INFINEON 0x15D1
137 +#define PCI_DEVICE_ID_INFINEON_DANUBE 0x000F
138 +#define PCI_DEVICE_ID_INFINEON_PCIE 0x0011
139 +#define PCI_VENDOR_ID_LANTIQ 0x1BEF
140 +#define PCI_DEVICE_ID_LANTIQ_PCIE 0x0011
144 +static void __devinit
145 +ifx_pcie_fixup_resource(struct pci_dev *dev)
149 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
151 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s: fixup host controller %s (%04x:%04x)\n",
152 + __func__, pci_name(dev), dev->vendor, dev->device);
154 + /* Setup COMMAND register */
155 + reg = PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER /* |
156 + PCI_COMMAND_INTX_DISABLE */| PCI_COMMAND_SERR;
157 + pci_write_config_word(dev, PCI_COMMAND, reg);
158 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
160 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE, ifx_pcie_fixup_resource);
161 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_VENDOR_ID_LANTIQ, ifx_pcie_fixup_resource);
163 +static void __devinit
164 +ifx_pcie_rc_class_early_fixup(struct pci_dev *dev)
166 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: enter\n", __func__, pci_name(dev));
168 + if (dev->devfn == PCI_DEVFN(0, 0) &&
169 + (dev->class >> 8) == PCI_CLASS_BRIDGE_HOST) {
171 + dev->class = (PCI_CLASS_BRIDGE_PCI << 8) | (dev->class & 0xff);
173 + printk(KERN_INFO "%s: fixed pcie host bridge to pci-pci bridge\n", __func__);
175 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s: exit\n", __func__, pci_name(dev));
178 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INFINEON, PCI_DEVICE_ID_INFINEON_PCIE,
179 + ifx_pcie_rc_class_early_fixup);
181 +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_LANTIQ, PCI_DEVICE_ID_LANTIQ_PCIE,
182 + ifx_pcie_rc_class_early_fixup);
183 diff --git a/arch/mips/pci/pci.c b/arch/mips/pci/pci.c
184 index 41af7fa..2239cda 100644
185 --- a/arch/mips/pci/pci.c
186 +++ b/arch/mips/pci/pci.c
187 @@ -167,6 +167,31 @@ static int __init pcibios_init(void)
189 subsys_initcall(pcibios_init);
191 +int pcibios_host_nr(void)
194 + struct pci_controller *hose;
195 + for (count = 0, hose = hose_head; hose; hose = hose->next, count++) {
200 +EXPORT_SYMBOL(pcibios_host_nr);
202 +int pcibios_1st_host_bus_nr(void)
205 + struct pci_controller *hose = hose_head;
207 + if (hose != NULL) {
208 + if (hose->bus != NULL) {
209 + bus_nr = hose->bus->subordinate + 1;
214 +EXPORT_SYMBOL(pcibios_1st_host_bus_nr);
216 static int pcibios_enable_resources(struct pci_dev *dev, int mask)
219 diff --git a/arch/mips/pci/pcie-lantiq-msi.c b/arch/mips/pci/pcie-lantiq-msi.c
221 index 0000000..9cbf639
223 +++ b/arch/mips/pci/pcie-lantiq-msi.c
225 +/******************************************************************************
227 +** FILE NAME : ifxmips_pcie_msi.c
228 +** PROJECT : IFX UEIP for VRX200
229 +** MODULES : PCI MSI sub module
231 +** DATE : 02 Mar 2009
232 +** AUTHOR : Lei Chuanhua
233 +** DESCRIPTION : PCIe MSI Driver
234 +** COPYRIGHT : Copyright (c) 2009
235 +** Infineon Technologies AG
236 +** Am Campeon 1-12, 85579 Neubiberg, Germany
238 +** This program is free software; you can redistribute it and/or modify
239 +** it under the terms of the GNU General Public License as published by
240 +** the Free Software Foundation; either version 2 of the License, or
241 +** (at your option) any later version.
243 +** $Date $Author $Comment
244 +** 02 Mar,2009 Lei Chuanhua Initial version
245 +*******************************************************************************/
247 + \defgroup IFX_PCIE_MSI MSI OS APIs
249 + \brief PCIe bus driver OS interface functions
253 + \file ifxmips_pcie_msi.c
255 + \brief PCIe MSI OS interface file
258 +#include <linux/init.h>
259 +#include <linux/sched.h>
260 +#include <linux/slab.h>
261 +#include <linux/interrupt.h>
262 +#include <linux/kernel_stat.h>
263 +#include <linux/pci.h>
264 +#include <linux/msi.h>
265 +#include <linux/module.h>
266 +#include <asm/bootinfo.h>
267 +#include <asm/irq.h>
268 +#include <asm/traps.h>
270 +#include "pcie-lantiq.h"
272 +#define IFX_MSI_IRQ_NUM 16
273 +#define SM(_v, _f) (((_v) << _f##_S) & (_f))
275 +#define IFX_MSI_PIC_REG_BASE (KSEG1 | 0x1F700000)
276 +#define IFX_PCIE_MSI_IR0 (INT_NUM_IM4_IRL0 + 27)
277 +#define IFX_PCIE_MSI_IR1 (INT_NUM_IM4_IRL0 + 28)
278 +#define IFX_PCIE_MSI_IR2 (INT_NUM_IM4_IRL0 + 29)
279 +#define IFX_PCIE_MSI_IR3 (INT_NUM_IM0_IRL0 + 30)
281 +#define IFX_MSI_PCI_INT_DISABLE 0x80000000
282 +#define IFX_MSI_PIC_INT_LINE 0x30000000
283 +#define IFX_MSI_PIC_MSG_ADDR 0x0FFF0000
284 +#define IFX_MSI_PIC_MSG_DATA 0x0000FFFF
285 +#define IFX_MSI_PIC_BIG_ENDIAN 1
286 +#define IFX_MSI_PIC_INT_LINE_S 28
287 +#define IFX_MSI_PIC_MSG_ADDR_S 16
288 +#define IFX_MSI_PIC_MSG_DATA_S 0x0
291 + IFX_PCIE_MSI_IDX0 = 0,
297 +typedef struct ifx_msi_irq_idx {
302 +struct ifx_msi_pic {
303 + volatile u32 pic_table[IFX_MSI_IRQ_NUM];
304 + volatile u32 pic_endian; /* 0x40 */
306 +typedef struct ifx_msi_pic *ifx_msi_pic_t;
308 +typedef struct ifx_msi_irq {
309 + const volatile ifx_msi_pic_t msi_pic_p;
310 + const u32 msi_phy_base;
311 + const ifx_msi_irq_idx_t msi_irq_idx[IFX_MSI_IRQ_NUM];
313 + * Each bit in msi_free_irq_bitmask represents a MSI interrupt that is
316 + u16 msi_free_irq_bitmask;
319 + * Each bit in msi_multiple_irq_bitmask tells that the device using
320 + * this bit in msi_free_irq_bitmask is also using the next bit. This
321 + * is used so we can disable all of the MSI interrupts when a device
324 + u16 msi_multiple_irq_bitmask;
327 +static ifx_msi_irq_t msi_irqs[IFX_PCIE_CORE_NR] = {
329 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI_PIC_REG_BASE,
330 + .msi_phy_base = PCIE_MSI_PHY_BASE,
332 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
333 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
334 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
335 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
336 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
337 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
338 + {IFX_PCIE_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE_MSI_IR1, IFX_PCIE_MSI_IDX1},
339 + {IFX_PCIE_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE_MSI_IR3, IFX_PCIE_MSI_IDX3},
341 + .msi_free_irq_bitmask = 0,
342 + .msi_multiple_irq_bitmask= 0,
344 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
346 + .msi_pic_p = (const volatile ifx_msi_pic_t)IFX_MSI1_PIC_REG_BASE,
347 + .msi_phy_base = PCIE1_MSI_PHY_BASE,
349 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
350 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
351 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
352 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
353 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
354 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
355 + {IFX_PCIE1_MSI_IR0, IFX_PCIE_MSI_IDX0}, {IFX_PCIE1_MSI_IR1, IFX_PCIE_MSI_IDX1},
356 + {IFX_PCIE1_MSI_IR2, IFX_PCIE_MSI_IDX2}, {IFX_PCIE1_MSI_IR3, IFX_PCIE_MSI_IDX3},
358 + .msi_free_irq_bitmask = 0,
359 + .msi_multiple_irq_bitmask= 0,
362 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
366 + * This lock controls updates to msi_free_irq_bitmask,
367 + * msi_multiple_irq_bitmask and pic register settting
369 +static DEFINE_SPINLOCK(ifx_pcie_msi_lock);
371 +void pcie_msi_pic_init(int pcie_port)
373 + spin_lock(&ifx_pcie_msi_lock);
374 + msi_irqs[pcie_port].msi_pic_p->pic_endian = IFX_MSI_PIC_BIG_ENDIAN;
375 + spin_unlock(&ifx_pcie_msi_lock);
379 + * \fn int arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
380 + * \brief Called when a driver request MSI interrupts instead of the
381 + * legacy INT A-D. This routine will allocate multiple interrupts
382 + * for MSI devices that support them. A device can override this by
383 + * programming the MSI control bits [6:4] before calling
384 + * pci_enable_msi().
386 + * \param[in] pdev Device requesting MSI interrupts
387 + * \param[in] desc MSI descriptor
389 + * \return -EINVAL Invalid pcie root port or invalid msi bit
391 + * \ingroup IFX_PCIE_MSI
394 +arch_setup_msi_irq(struct pci_dev *pdev, struct msi_desc *desc)
400 + int configured_private_bits;
401 + int request_private_bits;
402 + struct msi_msg msg;
404 + struct ifx_pci_controller *ctrl = pdev->bus->sysdata;
405 + int pcie_port = ctrl->port;
407 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s %s enter\n", __func__, pci_name(pdev));
409 + /* XXX, skip RC MSI itself */
410 + if (pdev->pcie_type == PCI_EXP_TYPE_ROOT_PORT) {
411 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s RC itself doesn't use MSI interrupt\n", __func__);
416 + * Read the MSI config to figure out how many IRQs this device
417 + * wants. Most devices only want 1, which will give
418 + * configured_private_bits and request_private_bits equal 0.
420 + pci_read_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, &control);
423 + * If the number of private bits has been configured then use
424 + * that value instead of the requested number. This gives the
425 + * driver the chance to override the number of interrupts
426 + * before calling pci_enable_msi().
428 + configured_private_bits = (control & PCI_MSI_FLAGS_QSIZE) >> 4;
429 + if (configured_private_bits == 0) {
430 + /* Nothing is configured, so use the hardware requested size */
431 + request_private_bits = (control & PCI_MSI_FLAGS_QMASK) >> 1;
435 + * Use the number of configured bits, assuming the
436 + * driver wanted to override the hardware request
439 + request_private_bits = configured_private_bits;
443 + * The PCI 2.3 spec mandates that there are at most 32
444 + * interrupts. If this device asks for more, only give it one.
446 + if (request_private_bits > 5) {
447 + request_private_bits = 0;
451 + * The IRQs have to be aligned on a power of two based on the
452 + * number being requested.
454 + irq_step = (1 << request_private_bits);
456 + /* Mask with one bit for each IRQ */
457 + search_mask = (1 << irq_step) - 1;
460 + * We're going to search msi_free_irq_bitmask_lock for zero
461 + * bits. This represents an MSI interrupt number that isn't in
464 + spin_lock(&ifx_pcie_msi_lock);
465 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos += irq_step) {
466 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & (search_mask << pos)) == 0) {
467 + msi_irqs[pcie_port].msi_free_irq_bitmask |= search_mask << pos;
468 + msi_irqs[pcie_port].msi_multiple_irq_bitmask |= (search_mask >> 1) << pos;
472 + spin_unlock(&ifx_pcie_msi_lock);
474 + /* Make sure the search for available interrupts didn't fail */
475 + if (pos >= IFX_MSI_IRQ_NUM) {
476 + if (request_private_bits) {
477 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s: Unable to find %d free "
478 + "interrupts, trying just one", __func__, 1 << request_private_bits);
479 + request_private_bits = 0;
483 + printk(KERN_ERR "%s: Unable to find a free MSI interrupt\n", __func__);
487 + irq = msi_irqs[pcie_port].msi_irq_idx[pos].irq;
488 + irq_idx = msi_irqs[pcie_port].msi_irq_idx[pos].idx;
490 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pos %d, irq %d irq_idx %d\n", pos, irq, irq_idx);
493 + * Initialize MSI. This has to match the memory-write endianess from the device
494 + * Address bits [23:12]
496 + spin_lock(&ifx_pcie_msi_lock);
497 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] = SM(irq_idx, IFX_MSI_PIC_INT_LINE) |
498 + SM((msi_irqs[pcie_port].msi_phy_base >> 12), IFX_MSI_PIC_MSG_ADDR) |
499 + SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
501 + /* Enable this entry */
502 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] &= ~IFX_MSI_PCI_INT_DISABLE;
503 + spin_unlock(&ifx_pcie_msi_lock);
505 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "pic_table[%d]: 0x%08x\n",
506 + pos, msi_irqs[pcie_port].msi_pic_p->pic_table[pos]);
508 + /* Update the number of IRQs the device has available to it */
509 + control &= ~PCI_MSI_FLAGS_QSIZE;
510 + control |= (request_private_bits << 4);
511 + pci_write_config_word(pdev, desc->msi_attrib.pos + PCI_MSI_FLAGS, control);
513 + irq_set_msi_desc(irq, desc);
514 + msg.address_hi = 0x0;
515 + msg.address_lo = msi_irqs[pcie_port].msi_phy_base;
516 + msg.data = SM((1 << pos), IFX_MSI_PIC_MSG_DATA);
517 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "msi_data: pos %d 0x%08x\n", pos, msg.data);
519 + write_msi_msg(irq, &msg);
520 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
525 +pcie_msi_irq_to_port(unsigned int irq, int *port)
529 + if (irq == IFX_PCIE_MSI_IR0 || irq == IFX_PCIE_MSI_IR1 ||
530 + irq == IFX_PCIE_MSI_IR2 || irq == IFX_PCIE_MSI_IR3) {
531 + *port = IFX_PCIE_PORT0;
533 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
534 + else if (irq == IFX_PCIE1_MSI_IR0 || irq == IFX_PCIE1_MSI_IR1 ||
535 + irq == IFX_PCIE1_MSI_IR2 || irq == IFX_PCIE1_MSI_IR3) {
536 + *port = IFX_PCIE_PORT1;
538 +#endif /* CONFIG_IFX_PCIE_2ND_CORE */
540 + printk(KERN_ERR "%s: Attempted to teardown illegal "
541 + "MSI interrupt (%d)\n", __func__, irq);
548 + * \fn void arch_teardown_msi_irq(unsigned int irq)
549 + * \brief Called when a device no longer needs its MSI interrupts. All
550 + * MSI interrupts for the device are freed.
552 + * \param irq The devices first irq number. There may be multple in sequence.
554 + * \ingroup IFX_PCIE_MSI
557 +arch_teardown_msi_irq(unsigned int irq)
564 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s enter\n", __func__);
566 + BUG_ON(irq > (INT_NUM_IM4_IRL0 + 31));
568 + if (pcie_msi_irq_to_port(irq, &pcie_port) != 0) {
572 + /* Shift the mask to the correct bit location, not always correct
573 + * Probally, the first match will be chosen.
575 + for (pos = 0; pos < IFX_MSI_IRQ_NUM; pos++) {
576 + if ((msi_irqs[pcie_port].msi_irq_idx[pos].irq == irq)
577 + && (msi_irqs[pcie_port].msi_free_irq_bitmask & ( 1 << pos))) {
581 + if (pos >= IFX_MSI_IRQ_NUM) {
582 + printk(KERN_ERR "%s: Unable to find a matched MSI interrupt\n", __func__);
585 + spin_lock(&ifx_pcie_msi_lock);
586 + /* Disable this entry */
587 + msi_irqs[pcie_port].msi_pic_p->pic_table[pos] |= IFX_MSI_PCI_INT_DISABLE;
588 + 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);
589 + spin_unlock(&ifx_pcie_msi_lock);
591 + * Count the number of IRQs we need to free by looking at the
592 + * msi_multiple_irq_bitmask. Each bit set means that the next
593 + * IRQ is also owned by this device.
596 + while (((pos + number_irqs) < IFX_MSI_IRQ_NUM) &&
597 + (msi_irqs[pcie_port].msi_multiple_irq_bitmask & (1 << (pos + number_irqs)))) {
602 + /* Mask with one bit for each IRQ */
603 + bitmask = (1 << number_irqs) - 1;
606 + if ((msi_irqs[pcie_port].msi_free_irq_bitmask & bitmask) != bitmask) {
607 + printk(KERN_ERR "%s: Attempted to teardown MSI "
608 + "interrupt (%d) not in use\n", __func__, irq);
611 + /* Checks are done, update the in use bitmask */
612 + spin_lock(&ifx_pcie_msi_lock);
613 + msi_irqs[pcie_port].msi_free_irq_bitmask &= ~bitmask;
614 + msi_irqs[pcie_port].msi_multiple_irq_bitmask &= ~(bitmask >> 1);
615 + spin_unlock(&ifx_pcie_msi_lock);
616 + IFX_PCIE_PRINT(PCIE_MSG_MSI, "%s exit\n", __func__);
619 +MODULE_LICENSE("GPL");
620 +MODULE_AUTHOR("Chuanhua.Lei@infineon.com");
621 +MODULE_SUPPORTED_DEVICE("Infineon PCIe IP builtin MSI PIC module");
622 +MODULE_DESCRIPTION("Infineon PCIe IP builtin MSI PIC driver");
624 diff --git a/arch/mips/pci/pcie-lantiq-phy.c b/arch/mips/pci/pcie-lantiq-phy.c
626 index 0000000..9f5027d
628 +++ b/arch/mips/pci/pcie-lantiq-phy.c
630 +/******************************************************************************
632 +** FILE NAME : ifxmips_pcie_phy.c
633 +** PROJECT : IFX UEIP for VRX200
634 +** MODULES : PCIe PHY sub module
636 +** DATE : 14 May 2009
637 +** AUTHOR : Lei Chuanhua
638 +** DESCRIPTION : PCIe Root Complex Driver
639 +** COPYRIGHT : Copyright (c) 2009
640 +** Infineon Technologies AG
641 +** Am Campeon 1-12, 85579 Neubiberg, Germany
643 +** This program is free software; you can redistribute it and/or modify
644 +** it under the terms of the GNU General Public License as published by
645 +** the Free Software Foundation; either version 2 of the License, or
646 +** (at your option) any later version.
648 +** $Version $Date $Author $Comment
649 +** 0.0.1 14 May,2009 Lei Chuanhua Initial version
650 +*******************************************************************************/
652 + \file ifxmips_pcie_phy.c
654 + \brief PCIe PHY PLL register programming source file
656 +#include <linux/types.h>
657 +#include <linux/kernel.h>
658 +#include <asm/paccess.h>
659 +#include <linux/delay.h>
661 +#include "pcie-lantiq.h"
663 +/* PCIe PDI only supports 16 bit operation */
665 +#define IFX_PCIE_PHY_REG_WRITE16(__addr, __data) \
666 + ((*(volatile u16 *) (__addr)) = (__data))
668 +#define IFX_PCIE_PHY_REG_READ16(__addr) \
669 + (*(volatile u16 *) (__addr))
671 +#define IFX_PCIE_PHY_REG16(__addr) \
672 + (*(volatile u16 *) (__addr))
674 +#define IFX_PCIE_PHY_REG(__reg, __value, __mask) do { \
677 + read_data = IFX_PCIE_PHY_REG_READ16((__reg)); \
678 + write_data = (read_data & ((u16)~(__mask))) | (((u16)(__value)) & ((u16)(__mask)));\
679 + IFX_PCIE_PHY_REG_WRITE16((__reg), write_data); \
682 +#define IFX_PCIE_PLL_TIMEOUT 1000 /* Tunnable */
685 +pcie_phy_comm_setup(int pcie_port)
688 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
690 + /* increase the bias reference voltage */
691 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
692 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
695 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
696 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
699 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
701 + /* predrv_ser_en */
702 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
705 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
708 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
710 + /* predrv_ser_en */
711 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
714 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
716 + /* Improved 100MHz clock output */
717 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
718 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
720 + /* Reduced CDR BW to avoid glitches */
721 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
724 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
726 +pcie_phy_36mhz_mode_setup(int pcie_port)
728 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
730 + /* en_ext_mmd_div_ratio */
731 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
733 + /* ext_mmd_div_ratio*/
734 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
737 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
740 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
743 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
746 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
749 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
752 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
755 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
756 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
757 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
758 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
760 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
762 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
764 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE
766 +pcie_phy_36mhz_ssc_mode_setup(int pcie_port)
768 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
771 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL1(pcie_port), 0x120e, 0xFFFF);
773 + /* Increase the bias reference voltage */
774 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x39D7, 0xFFFF);
775 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x0900, 0xFFFF);
778 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_EI(pcie_port), 0x0004, 0xFFFF);
779 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_A_CTRL(pcie_port), 0x6803, 0xFFFF);
782 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0008, 0x0008);
784 + /* Predrv_ser_en */
785 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL2(pcie_port), 0x0706, 0xFFFF);
788 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL3(pcie_port), 0x1FFF, 0xFFFF);
791 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_A_CTRL1(pcie_port), 0x0800, 0xFF00);
793 + /* predrv_ser_en */
794 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4702, 0x7F00);
797 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL2(pcie_port), 0x2e00, 0xFFFF);
799 + /* en_ext_mmd_div_ratio */
800 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
802 + /* ext_mmd_div_ratio*/
803 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
806 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0400, 0x0400);
809 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
812 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
815 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
818 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
820 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0100);
822 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
825 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
826 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
827 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
828 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1c72, 0xFFFF);
830 + /* improved 100MHz clock output */
831 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL2(pcie_port), 0x3096, 0xFFFF);
832 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_A_CTRL2(pcie_port), 0x4707, 0xFFFF);
834 + /* reduced CDR BW to avoid glitches */
835 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CDR(pcie_port), 0x0235, 0xFFFF);
837 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
839 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE */
841 +#ifdef CONFIG_IFX_PCIE_PHY_25MHZ_MODE
843 +pcie_phy_25mhz_mode_setup(int pcie_port)
845 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
847 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
850 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0000, 0x0200);
852 + /* en_ext_mmd_div_ratio*/
853 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0002, 0x0002);
855 + /* ext_mmd_div_ratio*/
856 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0040, 0x0070);
859 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x6000, 0xe000);
862 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x4000, 0x4000);
864 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
866 +#endif /* CONFIG_IFX_PCIE_PHY_25MHZ_MODE */
868 +#ifdef CONFIG_IFX_PCIE_PHY_100MHZ_MODE
870 +pcie_phy_100mhz_mode_setup(int pcie_port)
872 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d enter\n", __func__, pcie_port);
873 + /* en_ext_mmd_div_ratio */
874 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0002);
876 + /* ext_mmd_div_ratio*/
877 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL3(pcie_port), 0x0000, 0x0070);
880 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0200, 0x0200);
883 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x0100, 0x0100);
886 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL3(pcie_port), 0x2000, 0xe000);
889 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_A_CTRL2(pcie_port), 0x0000, 0x4000);
892 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL1(pcie_port), 0x38e4, 0xFFFF);
895 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL2(pcie_port), 0x00ee, 0x00FF);
898 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL7(pcie_port), 0x0002, 0xFFFF);
899 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL6(pcie_port), 0x3a04, 0xFFFF);
900 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL5(pcie_port), 0xfae3, 0xFFFF);
901 + IFX_PCIE_PHY_REG(PCIE_PHY_PLL_CTRL4(pcie_port), 0x1b72, 0xFFFF);
903 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "%s pcie_port %d exit\n", __func__, pcie_port);
905 +#endif /* CONFIG_IFX_PCIE_PHY_100MHZ_MODE */
908 +pcie_phy_wait_startup_ready(int pcie_port)
912 + for (i = 0; i < IFX_PCIE_PLL_TIMEOUT; i++) {
913 + if ((IFX_PCIE_PHY_REG16(PCIE_PHY_PLL_STATUS(pcie_port)) & 0x0040) != 0) {
918 + if (i >= IFX_PCIE_PLL_TIMEOUT) {
919 + printk(KERN_ERR "%s PLL Link timeout\n", __func__);
926 +pcie_phy_load_enable(int pcie_port, int slice)
928 + /* Set the load_en of tx/rx slice to '1' */
931 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0010, 0x0010);
934 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0010, 0x0010);
937 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0002, 0x0002);
943 +pcie_phy_load_disable(int pcie_port, int slice)
945 + /* set the load_en of tx/rx slice to '0' */
948 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_CTRL1(pcie_port), 0x0000, 0x0010);
951 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_CTRL1(pcie_port), 0x0000, 0x0010);
954 + IFX_PCIE_PHY_REG(PCIE_PHY_RX1_CTRL1(pcie_port), 0x0000, 0x0002);
959 +static void pcie_phy_load_war(int pcie_port)
963 + for (slice = 1; slice < 4; slice++) {
964 + pcie_phy_load_enable(pcie_port, slice);
966 + pcie_phy_load_disable(pcie_port, slice);
970 +static void pcie_phy_tx2_modulation(int pcie_port)
972 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD1(pcie_port), 0x1FFE, 0xFFFF);
973 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD2(pcie_port), 0xFFFE, 0xFFFF);
974 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0601, 0xFFFF);
976 + IFX_PCIE_PHY_REG(PCIE_PHY_TX2_MOD3(pcie_port), 0x0001, 0xFFFF);
979 +static void pcie_phy_tx1_modulation(int pcie_port)
981 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD1(pcie_port), 0x1FFE, 0xFFFF);
982 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD2(pcie_port), 0xFFFE, 0xFFFF);
983 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0601, 0xFFFF);
985 + IFX_PCIE_PHY_REG(PCIE_PHY_TX1_MOD3(pcie_port), 0x0001, 0xFFFF);
988 +static void pcie_phy_tx_modulation_war(int pcie_port)
991 +#define PCIE_PHY_MODULATION_NUM 5
992 + for (i = 0; i < PCIE_PHY_MODULATION_NUM; i++) {
993 + pcie_phy_tx2_modulation(pcie_port);
994 + pcie_phy_tx1_modulation(pcie_port);
996 +#undef PCIE_PHY_MODULATION_NUM
999 +void pcie_phy_clock_mode_setup(int pcie_port)
1001 + pcie_pdi_big_endian(pcie_port);
1003 + /* Enable PDI to access PCIe PHY register */
1004 + pcie_pdi_pmu_enable(pcie_port);
1006 + /* Configure PLL and PHY clock */
1007 + pcie_phy_comm_setup(pcie_port);
1009 +#ifdef CONFIG_IFX_PCIE_PHY_36MHZ_MODE
1010 + pcie_phy_36mhz_mode_setup(pcie_port);
1011 +#elif defined(CONFIG_IFX_PCIE_PHY_36MHZ_SSC_MODE)
1012 + pcie_phy_36mhz_ssc_mode_setup(pcie_port);
1013 +#elif defined(CONFIG_IFX_PCIE_PHY_25MHZ_MODE)
1014 + pcie_phy_25mhz_mode_setup(pcie_port);
1015 +#elif defined (CONFIG_IFX_PCIE_PHY_100MHZ_MODE)
1016 + pcie_phy_100mhz_mode_setup(pcie_port);
1018 + #error "PCIE PHY Clock Mode must be chosen first!!!!"
1019 +#endif /* CONFIG_IFX_PCIE_PHY_36MHZ_MODE */
1021 + /* Enable PCIe PHY and make PLL setting take effect */
1022 + pcie_phy_pmu_enable(pcie_port);
1024 + /* Check if we are in startup_ready status */
1025 + pcie_phy_wait_startup_ready(pcie_port);
1027 + pcie_phy_load_war(pcie_port);
1029 + /* Apply TX modulation workarounds */
1030 + pcie_phy_tx_modulation_war(pcie_port);
1032 +#ifdef IFX_PCI_PHY_REG_DUMP
1033 + IFX_PCIE_PRINT(PCIE_MSG_PHY, "Modified PHY register dump\n");
1034 + pcie_phy_reg_dump(pcie_port);
1038 diff --git a/arch/mips/pci/pcie-lantiq.c b/arch/mips/pci/pcie-lantiq.c
1039 new file mode 100644
1040 index 0000000..1df55b5
1042 +++ b/arch/mips/pci/pcie-lantiq.c
1044 +#include <linux/types.h>
1045 +#include <linux/module.h>
1046 +#include <linux/pci.h>
1047 +#include <linux/kernel.h>
1048 +#include <linux/init.h>
1049 +#include <linux/delay.h>
1050 +#include <linux/mm.h>
1051 +#include <asm/paccess.h>
1052 +#include <linux/pci.h>
1053 +#include <linux/pci_regs.h>
1054 +#include <linux/platform_device.h>
1056 +#define CONFIG_IFX_PCIE_1ST_CORE
1058 +#include "pcie-lantiq.h"
1060 +#define IFX_PCIE_IR (INT_NUM_IM4_IRL0 + 25)
1061 +#define IFX_PCIE_INTA (INT_NUM_IM4_IRL0 + 8)
1062 +#define IFX_PCIE_INTB (INT_NUM_IM4_IRL0 + 9)
1063 +#define IFX_PCIE_INTC (INT_NUM_IM4_IRL0 + 10)
1064 +#define IFX_PCIE_INTD (INT_NUM_IM4_IRL0 + 11)
1065 +#define MS(_v, _f) (((_v) & (_f)) >> _f##_S)
1066 +#define SM(_v, _f) (((_v) << _f##_S) & (_f))
1067 +#define IFX_REG_SET_BIT(_f, _r) \
1068 + IFX_REG_W32((IFX_REG_R32((_r)) &~ (_f)) | (_f), (_r))
1069 +#define IFX_PCIE_LTSSM_ENABLE_TIMEOUT 10
1070 +#define IFX_PCIE_PHY_LINK_UP_TIMEOUT 1000
1071 +#define IFX_PCIE_PHY_LOOP_CNT 5
1073 +static DEFINE_SPINLOCK(ifx_pcie_lock);
1075 +int pcibios_1st_host_bus_nr(void);
1077 +unsigned int g_pcie_debug_flag = PCIE_MSG_ANY & (~PCIE_MSG_CFG);
1079 +static ifx_pcie_irq_t pcie_irqs[IFX_PCIE_CORE_NR] = {
1082 + .irq = IFX_PCIE_IR,
1083 + .name = "ifx_pcie_rc0",
1088 + .irq_bit = PCIE_IRN_INTA,
1089 + .irq = IFX_PCIE_INTA,
1092 + .irq_bit = PCIE_IRN_INTB,
1093 + .irq = IFX_PCIE_INTB,
1096 + .irq_bit = PCIE_IRN_INTC,
1097 + .irq = IFX_PCIE_INTC,
1100 + .irq_bit = PCIE_IRN_INTD,
1101 + .irq = IFX_PCIE_INTD,
1107 +static inline int pcie_ltssm_enable(int pcie_port)
1111 + IFX_REG_W32(PCIE_RC_CCR_LTSSM_ENABLE, PCIE_RC_CCR(pcie_port)); /* Enable LTSSM */
1113 + /* Wait for the link to come up */
1114 + for (i = 0; i < IFX_PCIE_LTSSM_ENABLE_TIMEOUT; i++) {
1115 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_RETRAIN_PENDING)) {
1120 + if (i >= IFX_PCIE_LTSSM_ENABLE_TIMEOUT) {
1121 + IFX_PCIE_PRINT(PCIE_MSG_INIT, "%s link timeout!!!!!\n", __func__);
1127 +static inline void pcie_status_register_clear(int pcie_port)
1129 + IFX_REG_W32(0, PCIE_RC_DR(pcie_port));
1130 + IFX_REG_W32(0, PCIE_PCICMDSTS(pcie_port));
1131 + IFX_REG_W32(0, PCIE_DCTLSTS(pcie_port));
1132 + IFX_REG_W32(0, PCIE_LCTLSTS(pcie_port));
1133 + IFX_REG_W32(0, PCIE_SLCTLSTS(pcie_port));
1134 + IFX_REG_W32(0, PCIE_RSTS(pcie_port));
1135 + IFX_REG_W32(0, PCIE_UES_R(pcie_port));
1136 + IFX_REG_W32(0, PCIE_UEMR(pcie_port));
1137 + IFX_REG_W32(0, PCIE_UESR(pcie_port));
1138 + IFX_REG_W32(0, PCIE_CESR(pcie_port));
1139 + IFX_REG_W32(0, PCIE_CEMR(pcie_port));
1140 + IFX_REG_W32(0, PCIE_RESR(pcie_port));
1141 + IFX_REG_W32(0, PCIE_PVCCRSR(pcie_port));
1142 + IFX_REG_W32(0, PCIE_VC0_RSR0(pcie_port));
1143 + IFX_REG_W32(0, PCIE_TPFCS(pcie_port));
1144 + IFX_REG_W32(0, PCIE_TNPFCS(pcie_port));
1145 + IFX_REG_W32(0, PCIE_TCFCS(pcie_port));
1146 + IFX_REG_W32(0, PCIE_QSR(pcie_port));
1147 + IFX_REG_W32(0, PCIE_IOBLSECS(pcie_port));
1150 +static inline int ifx_pcie_link_up(int pcie_port)
1152 + return (IFX_REG_R32(PCIE_PHY_SR(pcie_port)) & PCIE_PHY_SR_PHY_LINK_UP) ? 1 : 0;
1155 +static inline void pcie_mem_io_setup(int pcie_port)
1159 + * BAR[0:1] readonly register
1160 + * RC contains only minimal BARs for packets mapped to this device
1161 + * Mem/IO filters defines a range of memory occupied by memory mapped IO devices that
1162 + * reside on the downstream side fo the bridge.
1164 + reg = SM((PCIE_MEM_PHY_PORT_TO_END(pcie_port) >> 20), PCIE_MBML_MEM_LIMIT_ADDR)
1165 + | SM((PCIE_MEM_PHY_PORT_TO_BASE(pcie_port) >> 20), PCIE_MBML_MEM_BASE_ADDR);
1166 + IFX_REG_W32(reg, PCIE_MBML(pcie_port));
1168 + /* PCIe_PBML, same as MBML */
1169 + IFX_REG_W32(IFX_REG_R32(PCIE_MBML(pcie_port)), PCIE_PMBL(pcie_port));
1171 + /* IO Address Range */
1172 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 12), PCIE_IOBLSECS_IO_LIMIT_ADDR)
1173 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 12), PCIE_IOBLSECS_IO_BASE_ADDR);
1174 + reg |= PCIE_IOBLSECS_32BIT_IO_ADDR;
1175 + IFX_REG_W32(reg, PCIE_IOBLSECS(pcie_port));
1177 + reg = SM((PCIE_IO_PHY_PORT_TO_END(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT)
1178 + | SM((PCIE_IO_PHY_PORT_TO_BASE(pcie_port) >> 16), PCIE_IO_BANDL_UPPER_16BIT_IO_BASE);
1179 + IFX_REG_W32(reg, PCIE_IO_BANDL(pcie_port));
1182 +static inline void pcie_msi_setup(int pcie_port)
1186 + /* XXX, MSI stuff should only apply to EP */
1187 + /* MSI Capability: Only enable 32-bit addresses */
1188 + reg = IFX_REG_R32(PCIE_MCAPR(pcie_port));
1189 + reg &= ~PCIE_MCAPR_ADDR64_CAP;
1190 + reg |= PCIE_MCAPR_MSI_ENABLE;
1192 + /* Disable multiple message */
1193 + reg &= ~(PCIE_MCAPR_MULTI_MSG_CAP | PCIE_MCAPR_MULTI_MSG_ENABLE);
1194 + IFX_REG_W32(reg, PCIE_MCAPR(pcie_port));
1197 +static inline void pcie_pm_setup(int pcie_port)
1201 + /* Enable PME, Soft reset enabled */
1202 + reg = IFX_REG_R32(PCIE_PM_CSR(pcie_port));
1203 + reg |= PCIE_PM_CSR_PME_ENABLE | PCIE_PM_CSR_SW_RST;
1204 + IFX_REG_W32(reg, PCIE_PM_CSR(pcie_port));
1207 +static inline void pcie_bus_setup(int pcie_port)
1211 + reg = SM(0, PCIE_BNR_PRIMARY_BUS_NUM) | SM(1, PCIE_PNR_SECONDARY_BUS_NUM) | SM(0xFF, PCIE_PNR_SUB_BUS_NUM);
1212 + IFX_REG_W32(reg, PCIE_BNR(pcie_port));
1215 +static inline void pcie_device_setup(int pcie_port)
1219 + /* Device capability register, set up Maximum payload size */
1220 + reg = IFX_REG_R32(PCIE_DCAP(pcie_port));
1221 + reg |= PCIE_DCAP_ROLE_BASE_ERR_REPORT;
1222 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCAP_MAX_PAYLOAD_SIZE);
1224 + /* Only available for EP */
1225 + reg &= ~(PCIE_DCAP_EP_L0S_LATENCY | PCIE_DCAP_EP_L1_LATENCY);
1226 + IFX_REG_W32(reg, PCIE_DCAP(pcie_port));
1228 + /* Device control and status register */
1229 + /* Set Maximum Read Request size for the device as a Requestor */
1230 + reg = IFX_REG_R32(PCIE_DCTLSTS(pcie_port));
1233 + * Request size can be larger than the MPS used, but the completions returned
1234 + * for the read will be bounded by the MPS size.
1235 + * In our system, Max request size depends on AHB burst size. It is 64 bytes.
1236 + * but we set it as 128 as minimum one.
1238 + reg |= SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_READ_SIZE)
1239 + | SM(PCIE_MAX_PAYLOAD_128, PCIE_DCTLSTS_MAX_PAYLOAD_SIZE);
1241 + /* Enable relaxed ordering, no snoop, and all kinds of errors */
1242 + reg |= PCIE_DCTLSTS_RELAXED_ORDERING_EN | PCIE_DCTLSTS_ERR_EN | PCIE_DCTLSTS_NO_SNOOP_EN;
1244 + IFX_REG_W32(reg, PCIE_DCTLSTS(pcie_port));
1247 +static inline void pcie_link_setup(int pcie_port)
1252 + * XXX, Link capability register, bit 18 for EP CLKREQ# dynamic clock management for L1, L2/3 CPM
1253 + * L0s is reported during link training via TS1 order set by N_FTS
1255 + reg = IFX_REG_R32(PCIE_LCAP(pcie_port));
1256 + reg &= ~PCIE_LCAP_L0S_EIXT_LATENCY;
1257 + reg |= SM(3, PCIE_LCAP_L0S_EIXT_LATENCY);
1258 + IFX_REG_W32(reg, PCIE_LCAP(pcie_port));
1260 + /* Link control and status register */
1261 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
1263 + /* Link Enable, ASPM enabled */
1264 + reg &= ~PCIE_LCTLSTS_LINK_DISABLE;
1266 +#ifdef CONFIG_PCIEASPM
1268 + * We use the same physical reference clock that the platform provides on the connector
1269 + * It paved the way for ASPM to calculate the new exit Latency
1271 + reg |= PCIE_LCTLSTS_SLOT_CLK_CFG;
1272 + reg |= PCIE_LCTLSTS_COM_CLK_CFG;
1274 + * We should disable ASPM by default except that we have dedicated power management support
1275 + * Enable ASPM will cause the system hangup/instability, performance degration
1277 + reg |= PCIE_LCTLSTS_ASPM_ENABLE;
1279 + reg &= ~PCIE_LCTLSTS_ASPM_ENABLE;
1280 +#endif /* CONFIG_PCIEASPM */
1283 + * The maximum size of any completion with data packet is bounded by the MPS setting
1284 + * in device control register
1286 + /* RCB may cause multiple split transactions, two options available, we use 64 byte RCB */
1287 + reg &= ~ PCIE_LCTLSTS_RCB128;
1288 + IFX_REG_W32(reg, PCIE_LCTLSTS(pcie_port));
1291 +static inline void pcie_error_setup(int pcie_port)
1296 + * Forward ERR_COR, ERR_NONFATAL, ERR_FATAL to the backbone
1297 + * Poisoned write TLPs and completions indicating poisoned TLPs will set the PCIe_PCICMDSTS.MDPE
1299 + reg = IFX_REG_R32(PCIE_INTRBCTRL(pcie_port));
1300 + reg |= PCIE_INTRBCTRL_SERR_ENABLE | PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE;
1302 + IFX_REG_W32(reg, PCIE_INTRBCTRL(pcie_port));
1304 + /* Uncorrectable Error Mask Register, Unmask <enable> all bits in PCIE_UESR */
1305 + reg = IFX_REG_R32(PCIE_UEMR(pcie_port));
1306 + reg &= ~PCIE_ALL_UNCORRECTABLE_ERR;
1307 + IFX_REG_W32(reg, PCIE_UEMR(pcie_port));
1309 + /* Uncorrectable Error Severity Register, ALL errors are FATAL */
1310 + IFX_REG_W32(PCIE_ALL_UNCORRECTABLE_ERR, PCIE_UESR(pcie_port));
1312 + /* Correctable Error Mask Register, unmask <enable> all bits */
1313 + reg = IFX_REG_R32(PCIE_CEMR(pcie_port));
1314 + reg &= ~PCIE_CORRECTABLE_ERR;
1315 + IFX_REG_W32(reg, PCIE_CEMR(pcie_port));
1317 + /* Advanced Error Capabilities and Control Registr */
1318 + reg = IFX_REG_R32(PCIE_AECCR(pcie_port));
1319 + reg |= PCIE_AECCR_ECRC_CHECK_EN | PCIE_AECCR_ECRC_GEN_EN;
1320 + IFX_REG_W32(reg, PCIE_AECCR(pcie_port));
1322 + /* Root Error Command Register, Report all types of errors */
1323 + reg = IFX_REG_R32(PCIE_RECR(pcie_port));
1324 + reg |= PCIE_RECR_ERR_REPORT_EN;
1325 + IFX_REG_W32(reg, PCIE_RECR(pcie_port));
1327 + /* Clear the Root status register */
1328 + reg = IFX_REG_R32(PCIE_RESR(pcie_port));
1329 + IFX_REG_W32(reg, PCIE_RESR(pcie_port));
1332 +static inline void pcie_root_setup(int pcie_port)
1336 + /* Root control and capabilities register */
1337 + reg = IFX_REG_R32(PCIE_RCTLCAP(pcie_port));
1338 + reg |= PCIE_RCTLCAP_SERR_ENABLE | PCIE_RCTLCAP_PME_INT_EN;
1339 + IFX_REG_W32(reg, PCIE_RCTLCAP(pcie_port));
1342 +static inline void pcie_vc_setup(int pcie_port)
1346 + /* Port VC Capability Register 2 */
1347 + reg = IFX_REG_R32(PCIE_PVC2(pcie_port));
1348 + reg &= ~PCIE_PVC2_VC_ARB_WRR;
1349 + reg |= PCIE_PVC2_VC_ARB_16P_FIXED_WRR;
1350 + IFX_REG_W32(reg, PCIE_PVC2(pcie_port));
1352 + /* VC0 Resource Capability Register */
1353 + reg = IFX_REG_R32(PCIE_VC0_RC(pcie_port));
1354 + reg &= ~PCIE_VC0_RC_REJECT_SNOOP;
1355 + IFX_REG_W32(reg, PCIE_VC0_RC(pcie_port));
1358 +static inline void pcie_port_logic_setup(int pcie_port)
1362 + /* FTS number, default 12, increase to 63, may increase time from/to L0s to L0 */
1363 + reg = IFX_REG_R32(PCIE_AFR(pcie_port));
1364 + reg &= ~(PCIE_AFR_FTS_NUM | PCIE_AFR_COM_FTS_NUM);
1365 + reg |= SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_FTS_NUM)
1366 + | SM(PCIE_AFR_FTS_NUM_DEFAULT, PCIE_AFR_COM_FTS_NUM);
1367 + /* L0s and L1 entry latency */
1368 + reg &= ~(PCIE_AFR_L0S_ENTRY_LATENCY | PCIE_AFR_L1_ENTRY_LATENCY);
1369 + reg |= SM(PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L0S_ENTRY_LATENCY)
1370 + | SM(PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT, PCIE_AFR_L1_ENTRY_LATENCY);
1371 + IFX_REG_W32(reg, PCIE_AFR(pcie_port));
1373 + /* Port Link Control Register */
1374 + reg = IFX_REG_R32(PCIE_PLCR(pcie_port));
1375 + reg |= PCIE_PLCR_DLL_LINK_EN; /* Enable the DLL link */
1376 + IFX_REG_W32(reg, PCIE_PLCR(pcie_port));
1378 + /* Lane Skew Register */
1379 + reg = IFX_REG_R32(PCIE_LSR(pcie_port));
1380 + /* Enable ACK/NACK and FC */
1381 + reg &= ~(PCIE_LSR_ACKNAK_DISABLE | PCIE_LSR_FC_DISABLE);
1382 + IFX_REG_W32(reg, PCIE_LSR(pcie_port));
1384 + /* Symbol Timer Register and Filter Mask Register 1 */
1385 + reg = IFX_REG_R32(PCIE_STRFMR(pcie_port));
1387 + /* Default SKP interval is very accurate already, 5us */
1388 + /* Enable IO/CFG transaction */
1389 + reg |= PCIE_STRFMR_RX_CFG_TRANS_ENABLE | PCIE_STRFMR_RX_IO_TRANS_ENABLE;
1390 + /* Disable FC WDT */
1391 + reg &= ~PCIE_STRFMR_FC_WDT_DISABLE;
1392 + IFX_REG_W32(reg, PCIE_STRFMR(pcie_port));
1394 + /* Filter Masker Register 2 */
1395 + reg = IFX_REG_R32(PCIE_FMR2(pcie_port));
1396 + reg |= PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 | PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1;
1397 + IFX_REG_W32(reg, PCIE_FMR2(pcie_port));
1399 + /* VC0 Completion Receive Queue Control Register */
1400 + reg = IFX_REG_R32(PCIE_VC0_CRQCR(pcie_port));
1401 + reg &= ~PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE;
1402 + reg |= SM(PCIE_VC0_TLP_QUEUE_MODE_BYPASS, PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE);
1403 + IFX_REG_W32(reg, PCIE_VC0_CRQCR(pcie_port));
1406 +static inline void pcie_rc_cfg_reg_setup(int pcie_port)
1408 + /* diable ltssm */
1409 + IFX_REG_W32(0, PCIE_RC_CCR(pcie_port));
1411 + pcie_mem_io_setup(pcie_port);
1412 + pcie_msi_setup(pcie_port);
1413 + pcie_pm_setup(pcie_port);
1414 + pcie_bus_setup(pcie_port);
1415 + pcie_device_setup(pcie_port);
1416 + pcie_link_setup(pcie_port);
1417 + pcie_error_setup(pcie_port);
1418 + pcie_root_setup(pcie_port);
1419 + pcie_vc_setup(pcie_port);
1420 + pcie_port_logic_setup(pcie_port);
1423 +static int ifx_pcie_wait_phy_link_up(int pcie_port)
1427 + /* Wait for PHY link is up */
1428 + for (i = 0; i < IFX_PCIE_PHY_LINK_UP_TIMEOUT; i++) {
1429 + if (ifx_pcie_link_up(pcie_port)) {
1434 + if (i >= IFX_PCIE_PHY_LINK_UP_TIMEOUT) {
1435 + printk(KERN_ERR "%s timeout\n", __func__);
1439 + /* Check data link up or not */
1440 + if (!(IFX_REG_R32(PCIE_RC_DR(pcie_port)) & PCIE_RC_DR_DLL_UP)) {
1441 + printk(KERN_ERR "%s DLL link is still down\n", __func__);
1445 + /* Check Data link active or not */
1446 + if (!(IFX_REG_R32(PCIE_LCTLSTS(pcie_port)) & PCIE_LCTLSTS_DLL_ACTIVE)) {
1447 + printk(KERN_ERR "%s DLL is not active\n", __func__);
1453 +static inline int pcie_app_loigc_setup(int pcie_port)
1455 + IFX_REG_W32(PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS, PCIE_AHB_CTRL(pcie_port));
1457 + /* Pull PCIe EP out of reset */
1458 + pcie_device_rst_deassert(pcie_port);
1460 + /* Start LTSSM training between RC and EP */
1461 + pcie_ltssm_enable(pcie_port);
1463 + /* Check PHY status after enabling LTSSM */
1464 + if (ifx_pcie_wait_phy_link_up(pcie_port) != 0) {
1471 + * Must be done after ltssm due to based on negotiated link
1472 + * width and payload size
1473 + * Update the Replay Time Limit. Empirically, some PCIe
1474 + * devices take a little longer to respond than expected under
1475 + * load. As a workaround for this we configure the Replay Time
1476 + * Limit to the value expected for a 512 byte MPS instead of
1477 + * our actual 128 byte MPS. The numbers below are directly
1478 + * from the PCIe spec table 3-4/5.
1480 +static inline void pcie_replay_time_update(int pcie_port)
1486 + reg = IFX_REG_R32(PCIE_LCTLSTS(pcie_port));
1488 + nlw = MS(reg, PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH);
1490 + case PCIE_MAX_LENGTH_WIDTH_X1:
1493 + case PCIE_MAX_LENGTH_WIDTH_X2:
1496 + case PCIE_MAX_LENGTH_WIDTH_X4:
1499 + case PCIE_MAX_LENGTH_WIDTH_X8:
1506 + reg = IFX_REG_R32(PCIE_ALTRT(pcie_port));
1507 + reg &= ~PCIE_ALTRT_REPLAY_TIME_LIMIT;
1508 + reg |= SM(rtl, PCIE_ALTRT_REPLAY_TIME_LIMIT);
1509 + IFX_REG_W32(reg, PCIE_ALTRT(pcie_port));
1511 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s PCIE_ALTRT 0x%08x\n",
1512 + __func__, IFX_REG_R32(PCIE_ALTRT(pcie_port)));
1516 + * Table 359 Enhanced Configuration Address Mapping1)
1517 + * 1) This table is defined in Table 7-1, page 341, PCI Express Base Specification v1.1
1518 + * Memory Address PCI Express Configuration Space
1519 + * A[(20+n-1):20] Bus Number 1 < n < 8
1520 + * A[19:15] Device Number
1521 + * A[14:12] Function Number
1522 + * A[11:8] Extended Register Number
1523 + * A[7:2] Register Number
1524 + * A[1:0] Along with size of the access, used to generate Byte Enables
1525 + * For VR9, only the address bits [22:0] are mapped to the configuration space:
1526 + * . Address bits [22:20] select the target bus (1-of-8)1)
1527 + * . Address bits [19:15] select the target device (1-of-32) on the bus
1528 + * . Address bits [14:12] select the target function (1-of-8) within the device.
1529 + * . Address bits [11:2] selects the target dword (1-of-1024) within the selected function.s configuration space
1530 + * . Address bits [1:0] define the start byte location within the selected dword.
1532 +static inline unsigned int pcie_bus_addr(u8 bus_num, u16 devfn, int where)
1534 + unsigned int addr;
1539 + addr = ((PCI_SLOT(devfn) & 0x1F) << 15) | ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF)& ~3);
1542 + /* type 1, only support 8 buses */
1543 + addr = ((bus & 0x7) << 20) | ((PCI_SLOT(devfn) & 0x1F) << 15) |
1544 + ((PCI_FUNC(devfn) & 0x7) << 12) | ((where & 0xFFF) & ~3);
1546 + IFX_PCIE_PRINT(PCIE_MSG_CFG, "%s: bus addr : %02x:%02x.%01x/%02x, addr=%08x\n",
1547 + __func__, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn), where, addr);
1551 +static int pcie_valid_config(int pcie_port, int bus, int dev)
1554 + if ((bus == 0) && (dev == 0))
1557 + /* No physical link */
1558 + if (!ifx_pcie_link_up(pcie_port))
1561 + /* Bus zero only has RC itself
1562 + * XXX, check if EP will be integrated
1564 + if ((bus == 0) && (dev != 0))
1567 + /* Maximum 8 buses supported for VRX */
1572 + * PCIe is PtP link, one bus only supports only one device
1573 + * except bus zero and PCIe switch which is virtual bus device
1574 + * The following two conditions really depends on the system design
1575 + * and attached the device.
1576 + * XXX, how about more new switch
1578 + if ((bus == 1) && (dev != 0))
1581 + if ((bus >= 3) && (dev != 0))
1586 +static inline unsigned int ifx_pcie_cfg_rd(int pcie_port, unsigned int reg)
1588 + return IFX_REG_R32((volatile unsigned int *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
1591 +static inline void ifx_pcie_cfg_wr(int pcie_port, unsigned int reg, unsigned int val)
1593 + IFX_REG_W32( val, (volatile unsigned int *)(PCIE_CFG_PORT_TO_BASE(pcie_port) + reg));
1596 +static inline unsigned int ifx_pcie_rc_cfg_rd(int pcie_port, unsigned int reg)
1598 + return IFX_REG_R32((volatile unsigned int *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
1601 +static inline void ifx_pcie_rc_cfg_wr(int pcie_port, unsigned int reg, unsigned int val)
1603 + IFX_REG_W32(val, (volatile unsigned int *)(PCIE_RC_PORT_TO_BASE(pcie_port) + reg));
1606 +unsigned int ifx_pcie_bus_enum_read_hack(int where, unsigned int value)
1608 + unsigned int tvalue = value;
1610 + if (where == PCI_PRIMARY_BUS) {
1611 + u8 primary, secondary, subordinate;
1613 + primary = tvalue & 0xFF;
1614 + secondary = (tvalue >> 8) & 0xFF;
1615 + subordinate = (tvalue >> 16) & 0xFF;
1616 + primary += pcibios_1st_host_bus_nr();
1617 + secondary += pcibios_1st_host_bus_nr();
1618 + subordinate += pcibios_1st_host_bus_nr();
1619 + tvalue = (tvalue & 0xFF000000) | (unsigned int)primary | (unsigned int)(secondary << 8) | (unsigned int)(subordinate << 16);
1624 +unsigned int ifx_pcie_bus_enum_write_hack(int where, unsigned int value)
1626 + unsigned int tvalue = value;
1628 + if (where == PCI_PRIMARY_BUS) {
1629 + u8 primary, secondary, subordinate;
1631 + primary = tvalue & 0xFF;
1632 + secondary = (tvalue >> 8) & 0xFF;
1633 + subordinate = (tvalue >> 16) & 0xFF;
1634 + if (primary > 0 && primary != 0xFF)
1635 + primary -= pcibios_1st_host_bus_nr();
1636 + if (secondary > 0 && secondary != 0xFF)
1637 + secondary -= pcibios_1st_host_bus_nr();
1638 + if (subordinate > 0 && subordinate != 0xFF)
1639 + subordinate -= pcibios_1st_host_bus_nr();
1640 + tvalue = (tvalue & 0xFF000000) | (unsigned int)primary | (unsigned int)(secondary << 8) | (unsigned int)(subordinate << 16);
1641 + } else if (where == PCI_SUBORDINATE_BUS) {
1642 + u8 subordinate = tvalue & 0xFF;
1643 + subordinate = subordinate > 0 ? subordinate - pcibios_1st_host_bus_nr() : 0;
1644 + tvalue = subordinate;
1650 + * \fn static int ifx_pcie_read_config(struct pci_bus *bus, unsigned int devfn,
1651 + * int where, int size, unsigned int *value)
1652 + * \brief Read a value from configuration space
1654 + * \param[in] bus Pointer to pci bus
1655 + * \param[in] devfn PCI device function number
1656 + * \param[in] where PCI register number
1657 + * \param[in] size Register read size
1658 + * \param[out] value Pointer to return value
1659 + * \return PCIBIOS_BAD_REGISTER_NUMBER Invalid register number
1660 + * \return PCIBIOS_FUNC_NOT_SUPPORTED PCI function not supported
1661 + * \return PCIBIOS_DEVICE_NOT_FOUND PCI device not found
1662 + * \return PCIBIOS_SUCCESSFUL OK
1663 + * \ingroup IFX_PCIE_OS
1665 +static int ifx_pcie_read_config(struct pci_bus *bus, unsigned int devfn, int where, int size, unsigned int *value)
1667 + unsigned int data = 0;
1668 + int bus_number = bus->number;
1669 + static const unsigned int mask[8] = {0, 0xff, 0xffff, 0, 0xffffffff, 0, 0, 0};
1670 + int ret = PCIBIOS_SUCCESSFUL;
1671 + struct ifx_pci_controller *ctrl = bus->sysdata;
1672 + int pcie_port = ctrl->port;
1674 + if (unlikely(size != 1 && size != 2 && size != 4)){
1675 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
1679 + /* Make sure the address is aligned to natural boundary */
1680 + if (unlikely(((size - 1) & where))) {
1681 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
1686 + * If we are second controller, we have to cheat OS so that it assume
1687 + * its bus number starts from 0 in host controller
1689 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
1692 + * We need to force the bus number to be zero on the root
1693 + * bus. Linux numbers the 2nd root bus to start after all
1694 + * busses on root 0.
1696 + if (bus->parent == NULL)
1700 + * PCIe only has a single device connected to it. It is
1701 + * always device ID 0. Don't bother doing reads for other
1702 + * device IDs on the first segment.
1704 + if ((bus_number == 0) && (PCI_SLOT(devfn) != 0)) {
1705 + ret = PCIBIOS_FUNC_NOT_SUPPORTED;
1709 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1710 + *value = 0xffffffff;
1711 + ret = PCIBIOS_DEVICE_NOT_FOUND;
1715 + IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: %02x:%02x.%01x/%02x:%01d\n", __func__, bus_number,
1716 + PCI_SLOT(devfn), PCI_FUNC(devfn), where, size);
1718 + PCIE_IRQ_LOCK(ifx_pcie_lock);
1719 + if (bus_number == 0) { /* RC itself */
1723 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1724 + IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: rd local cfg, offset:%08x, data:%08x\n",
1725 + __func__, t, data);
1727 + unsigned int addr = pcie_bus_addr(bus_number, devfn, where);
1729 + data = ifx_pcie_cfg_rd(pcie_port, addr);
1730 + if (pcie_port == IFX_PCIE_PORT0) {
1731 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1732 + data = le32_to_cpu(data);
1733 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1735 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1736 + data = le32_to_cpu(data);
1737 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1740 + /* To get a correct PCI topology, we have to restore the bus number to OS */
1741 + data = ifx_pcie_bus_enum_hack(bus, devfn, where, data, pcie_port, 1);
1743 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1744 + IFX_PCIE_PRINT(PCIE_MSG_READ_CFG, "%s: read config: data=%08x raw=%08x\n",
1745 + __func__, (data >> (8 * (where & 3))) & mask[size & 7], data);
1747 + *value = (data >> (8 * (where & 3))) & mask[size & 7];
1752 +static unsigned int ifx_pcie_size_to_value(int where, int size, unsigned int data, unsigned int value)
1754 + unsigned int shift;
1755 + unsigned int tdata = data;
1759 + shift = (where & 0x3) << 3;
1760 + tdata &= ~(0xffU << shift);
1761 + tdata |= ((value & 0xffU) << shift);
1764 + shift = (where & 3) << 3;
1765 + tdata &= ~(0xffffU << shift);
1766 + tdata |= ((value & 0xffffU) << shift);
1776 + * \fn static static int ifx_pcie_write_config(struct pci_bus *bus, unsigned int devfn,
1777 + * int where, int size, unsigned int value)
1778 + * \brief Write a value to PCI configuration space
1780 + * \param[in] bus Pointer to pci bus
1781 + * \param[in] devfn PCI device function number
1782 + * \param[in] where PCI register number
1783 + * \param[in] size The register size to be written
1784 + * \param[in] value The valule to be written
1785 + * \return PCIBIOS_BAD_REGISTER_NUMBER Invalid register number
1786 + * \return PCIBIOS_DEVICE_NOT_FOUND PCI device not found
1787 + * \return PCIBIOS_SUCCESSFUL OK
1788 + * \ingroup IFX_PCIE_OS
1790 +static int ifx_pcie_write_config(struct pci_bus *bus, unsigned int devfn, int where, int size, unsigned int value)
1792 + int bus_number = bus->number;
1793 + int ret = PCIBIOS_SUCCESSFUL;
1794 + struct ifx_pci_controller *ctrl = bus->sysdata;
1795 + int pcie_port = ctrl->port;
1796 + unsigned int tvalue = value;
1797 + unsigned int data;
1799 + /* Make sure the address is aligned to natural boundary */
1800 + if (unlikely(((size - 1) & where))) {
1801 + ret = PCIBIOS_BAD_REGISTER_NUMBER;
1805 + * If we are second controller, we have to cheat OS so that it assume
1806 + * its bus number starts from 0 in host controller
1808 + bus_number = ifx_pcie_bus_nr_deduct(bus_number, pcie_port);
1811 + * We need to force the bus number to be zero on the root
1812 + * bus. Linux numbers the 2nd root bus to start after all
1813 + * busses on root 0.
1815 + if (bus->parent == NULL)
1818 + if (pcie_valid_config(pcie_port, bus_number, PCI_SLOT(devfn)) == 0) {
1819 + ret = PCIBIOS_DEVICE_NOT_FOUND;
1823 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: %02x:%02x.%01x/%02x:%01d value=%08x\n", __func__,
1824 + bus_number, PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, value);
1826 + /* XXX, some PCIe device may need some delay */
1827 + PCIE_IRQ_LOCK(ifx_pcie_lock);
1830 + * To configure the correct bus topology using native way, we have to cheat Os so that
1831 + * it can configure the PCIe hardware correctly.
1833 + tvalue = ifx_pcie_bus_enum_hack(bus, devfn, where, value, pcie_port, 0);
1835 + if (bus_number == 0) { /* RC itself */
1839 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr local cfg, offset:%08x, fill:%08x\n", __func__, t, value);
1840 + data = ifx_pcie_rc_cfg_rd(pcie_port, t);
1841 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd local cfg, offset:%08x, data:%08x\n", __func__, t, data);
1843 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1845 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr local cfg, offset:%08x, value:%08x\n", __func__, t, data);
1846 + ifx_pcie_rc_cfg_wr(pcie_port, t, data);
1847 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd local cfg, offset:%08x, value:%08x\n",
1848 + __func__, t, ifx_pcie_rc_cfg_rd(pcie_port, t));
1850 + unsigned int addr = pcie_bus_addr(bus_number, devfn, where);
1852 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: wr cfg, offset:%08x, fill:%08x\n", __func__, addr, value);
1853 + data = ifx_pcie_cfg_rd(pcie_port, addr);
1854 + if (pcie_port == IFX_PCIE_PORT0) {
1855 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1856 + data = le32_to_cpu(data);
1857 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1859 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1860 + data = le32_to_cpu(data);
1861 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1863 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG,"%s: rd cfg, offset:%08x, data:%08x\n", __func__, addr, data);
1865 + data = ifx_pcie_size_to_value(where, size, data, tvalue);
1866 + if (pcie_port == IFX_PCIE_PORT0) {
1867 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
1868 + data = cpu_to_le32(data);
1869 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1871 +#ifdef CONFIG_IFX_PCIE1_HW_SWAP
1872 + data = cpu_to_le32(data);
1873 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
1875 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: wr cfg, offset:%08x, value:%08x\n", __func__, addr, data);
1876 + ifx_pcie_cfg_wr(pcie_port, addr, data);
1877 + IFX_PCIE_PRINT(PCIE_MSG_WRITE_CFG, "%s: rd cfg, offset:%08x, value:%08x\n",
1878 + __func__, addr, ifx_pcie_cfg_rd(pcie_port, addr));
1880 + PCIE_IRQ_UNLOCK(ifx_pcie_lock);
1885 +static struct resource ifx_pcie_io_resource = {
1886 + .name = "PCIe0 I/O space",
1887 + .start = PCIE_IO_PHY_BASE,
1888 + .end = PCIE_IO_PHY_END,
1889 + .flags = IORESOURCE_IO,
1892 +static struct resource ifx_pcie_mem_resource = {
1893 + .name = "PCIe0 Memory space",
1894 + .start = PCIE_MEM_PHY_BASE,
1895 + .end = PCIE_MEM_PHY_END,
1896 + .flags = IORESOURCE_MEM,
1899 +static struct pci_ops ifx_pcie_ops = {
1900 + .read = ifx_pcie_read_config,
1901 + .write = ifx_pcie_write_config,
1904 +static struct ifx_pci_controller ifx_pcie_controller[IFX_PCIE_CORE_NR] = {
1907 + .pci_ops = &ifx_pcie_ops,
1908 + .mem_resource = &ifx_pcie_mem_resource,
1909 + .io_resource = &ifx_pcie_io_resource,
1911 + .port = IFX_PCIE_PORT0,
1915 +static inline void pcie_core_int_clear_all(int pcie_port)
1918 + reg = IFX_REG_R32(PCIE_IRNCR(pcie_port));
1919 + reg &= PCIE_RC_CORE_COMBINED_INT;
1920 + IFX_REG_W32(reg, PCIE_IRNCR(pcie_port));
1923 +static irqreturn_t pcie_rc_core_isr(int irq, void *dev_id)
1925 + struct ifx_pci_controller *ctrl = (struct ifx_pci_controller *)dev_id;
1926 + int pcie_port = ctrl->port;
1928 + IFX_PCIE_PRINT(PCIE_MSG_ISR, "PCIe RC error intr %d\n", irq);
1929 + pcie_core_int_clear_all(pcie_port);
1930 + return IRQ_HANDLED;
1933 +static int pcie_rc_core_int_init(int pcie_port)
1937 + /* Enable core interrupt */
1938 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNEN(pcie_port));
1940 + /* Clear it first */
1941 + IFX_REG_SET_BIT(PCIE_RC_CORE_COMBINED_INT, PCIE_IRNCR(pcie_port));
1942 + ret = request_irq(pcie_irqs[pcie_port].ir_irq.irq, pcie_rc_core_isr, IRQF_DISABLED,
1943 + pcie_irqs[pcie_port].ir_irq.name, &ifx_pcie_controller[pcie_port]);
1945 + printk(KERN_ERR "%s request irq %d failed\n", __func__, IFX_PCIE_IR);
1950 +int ifx_pcie_bios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
1952 + unsigned int irq_bit = 0;
1954 + struct ifx_pci_controller *ctrl = dev->bus->sysdata;
1955 + int pcie_port = ctrl->port;
1957 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s port %d dev %s slot %d pin %d \n", __func__, pcie_port, pci_name(dev), slot, pin);
1959 + if ((pin == PCIE_LEGACY_DISABLE) || (pin > PCIE_LEGACY_INT_MAX)) {
1960 + printk(KERN_WARNING "WARNING: dev %s: invalid interrupt pin %d\n", pci_name(dev), pin);
1963 + /* Pin index so minus one */
1964 + irq_bit = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq_bit;
1965 + irq = pcie_irqs[pcie_port].legacy_irq[pin - 1].irq;
1966 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNEN(pcie_port));
1967 + IFX_REG_SET_BIT(irq_bit, PCIE_IRNCR(pcie_port));
1968 + IFX_PCIE_PRINT(PCIE_MSG_FIXUP, "%s dev %s irq %d assigned\n", __func__, pci_name(dev), irq);
1973 + * \fn int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1974 + * \brief Called to perform platform specific PCI setup
1976 + * \param[in] dev The Linux PCI device structure for the device to map
1978 + * \ingroup IFX_PCIE_OS
1980 +int ifx_pcie_bios_plat_dev_init(struct pci_dev *dev)
1983 + unsigned int dconfig;
1985 + /* Enable reporting System errors and parity errors on all devices */
1986 + /* Enable parity checking and error reporting */
1987 + pci_read_config_word(dev, PCI_COMMAND, &config);
1988 + config |= PCI_COMMAND_PARITY | PCI_COMMAND_SERR /*| PCI_COMMAND_INVALIDATE |
1989 + PCI_COMMAND_FAST_BACK*/;
1990 + pci_write_config_word(dev, PCI_COMMAND, config);
1992 + if (dev->subordinate) {
1993 + /* Set latency timers on sub bridges */
1994 + pci_write_config_byte(dev, PCI_SEC_LATENCY_TIMER, 0x40); /* XXX, */
1995 + /* More bridge error detection */
1996 + pci_read_config_word(dev, PCI_BRIDGE_CONTROL, &config);
1997 + config |= PCI_BRIDGE_CTL_PARITY | PCI_BRIDGE_CTL_SERR;
1998 + pci_write_config_word(dev, PCI_BRIDGE_CONTROL, config);
2000 + /* Enable the PCIe normal error reporting */
2001 + pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
2003 + /* Disable system error generation in response to error messages */
2004 + pci_read_config_word(dev, pos + PCI_EXP_RTCTL, &config);
2005 + config &= ~(PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE | PCI_EXP_RTCTL_SEFEE);
2006 + pci_write_config_word(dev, pos + PCI_EXP_RTCTL, config);
2008 + /* Clear PCIE Capability's Device Status */
2009 + pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &config);
2010 + pci_write_config_word(dev, pos + PCI_EXP_DEVSTA, config);
2012 + /* Update Device Control */
2013 + pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &config);
2014 + /* Correctable Error Reporting */
2015 + config |= PCI_EXP_DEVCTL_CERE;
2016 + /* Non-Fatal Error Reporting */
2017 + config |= PCI_EXP_DEVCTL_NFERE;
2018 + /* Fatal Error Reporting */
2019 + config |= PCI_EXP_DEVCTL_FERE;
2020 + /* Unsupported Request */
2021 + config |= PCI_EXP_DEVCTL_URRE;
2022 + pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, config);
2025 + /* Find the Advanced Error Reporting capability */
2026 + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ERR);
2028 + /* Clear Uncorrectable Error Status */
2029 + pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &dconfig);
2030 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, dconfig);
2031 + /* Enable reporting of all uncorrectable errors */
2032 + /* Uncorrectable Error Mask - turned on bits disable errors */
2033 + pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_MASK, 0);
2035 + * Leave severity at HW default. This only controls if
2036 + * errors are reported as uncorrectable or
2037 + * correctable, not if the error is reported.
2039 + /* PCI_ERR_UNCOR_SEVER - Uncorrectable Error Severity */
2040 + /* Clear Correctable Error Status */
2041 + pci_read_config_dword(dev, pos + PCI_ERR_COR_STATUS, &dconfig);
2042 + pci_write_config_dword(dev, pos + PCI_ERR_COR_STATUS, dconfig);
2043 + /* Enable reporting of all correctable errors */
2044 + /* Correctable Error Mask - turned on bits disable errors */
2045 + pci_write_config_dword(dev, pos + PCI_ERR_COR_MASK, 0);
2046 + /* Advanced Error Capabilities */
2047 + pci_read_config_dword(dev, pos + PCI_ERR_CAP, &dconfig);
2048 + /* ECRC Generation Enable */
2049 + if (dconfig & PCI_ERR_CAP_ECRC_GENC)
2050 + dconfig |= PCI_ERR_CAP_ECRC_GENE;
2051 + /* ECRC Check Enable */
2052 + if (dconfig & PCI_ERR_CAP_ECRC_CHKC)
2053 + dconfig |= PCI_ERR_CAP_ECRC_CHKE;
2054 + pci_write_config_dword(dev, pos + PCI_ERR_CAP, dconfig);
2056 + /* PCI_ERR_HEADER_LOG - Header Log Register (16 bytes) */
2057 + /* Enable Root Port's interrupt in response to error messages */
2058 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_COMMAND,
2059 + PCI_ERR_ROOT_CMD_COR_EN |
2060 + PCI_ERR_ROOT_CMD_NONFATAL_EN |
2061 + PCI_ERR_ROOT_CMD_FATAL_EN);
2062 + /* Clear the Root status register */
2063 + pci_read_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, &dconfig);
2064 + pci_write_config_dword(dev, pos + PCI_ERR_ROOT_STATUS, dconfig);
2066 + /* WAR, only 128 MRRS is supported, force all EPs to support this value */
2067 + pcie_set_readrq(dev, 128);
2071 +static void pcie_phy_rst(int pcie_port)
2073 + pcie_phy_rst_assert(pcie_port);
2074 + pcie_phy_rst_deassert(pcie_port);
2075 + /* Make sure PHY PLL is stable */
2079 +static int pcie_rc_initialize(int pcie_port)
2083 + pcie_rcu_endian_setup(pcie_port);
2085 + pcie_ep_gpio_rst_init(pcie_port);
2088 + * XXX, PCIe elastic buffer bug will cause not to be detected. One more
2089 + * reset PCIe PHY will solve this issue
2091 + for (i = 0; i < IFX_PCIE_PHY_LOOP_CNT; i++) {
2092 + /* Disable PCIe PHY Analog part for sanity check */
2093 + pcie_phy_pmu_disable(pcie_port);
2094 + pcie_phy_rst(pcie_port);
2095 + /* PCIe Core reset enabled, low active, sw programmed */
2096 + pcie_core_rst_assert(pcie_port);
2097 + /* Put PCIe EP in reset status */
2098 + pcie_device_rst_assert(pcie_port);
2099 + /* PCI PHY & Core reset disabled, high active, sw programmed */
2100 + pcie_core_rst_deassert(pcie_port);
2101 + /* Already in a quiet state, program PLL, enable PHY, check ready bit */
2102 + pcie_phy_clock_mode_setup(pcie_port);
2103 + /* Enable PCIe PHY and Clock */
2104 + pcie_core_pmu_setup(pcie_port);
2105 + /* Clear status registers */
2106 + pcie_status_register_clear(pcie_port);
2107 +#ifdef CONFIG_PCI_MSI
2108 + pcie_msi_init(pcie_port);
2109 +#endif /* CONFIG_PCI_MSI */
2110 + pcie_rc_cfg_reg_setup(pcie_port);
2112 + /* Once link is up, break out */
2113 + if (pcie_app_loigc_setup(pcie_port) == 0)
2116 + if (i >= IFX_PCIE_PHY_LOOP_CNT) {
2117 + printk(KERN_ERR "%s link up failed!!!!!\n", __func__);
2120 + /* NB, don't increase ACK/NACK timer timeout value, which will cause a lot of COR errors */
2121 + pcie_replay_time_update(pcie_port);
2125 +static int inline ifx_pcie_startup_port_nr(void)
2127 + int pcie_port = IFX_PCIE_PORT0;
2129 + pcie_port = IFX_PCIE_PORT0;
2134 + * \fn static int __init ifx_pcie_bios_init(void)
2135 + * \brief Initialize the IFX PCIe controllers
2137 + * \return -EIO PCIe PHY link is not up
2138 + * \return -ENOMEM Configuration/IO space failed to map
2140 + * \ingroup IFX_PCIE_OS
2142 +extern int (*ltqpci_plat_arch_init)(struct pci_dev *dev);
2143 +extern int (*ltqpci_map_irq)(const struct pci_dev *dev, u8 slot, u8 pin);
2144 +static int __devinit ltq_pcie_probe(struct platform_device *pdev)
2146 + char ver_str[128] = {0};
2147 + void __iomem *io_map_base;
2150 + ltqpci_map_irq = ifx_pcie_bios_map_irq;
2151 + ltqpci_plat_arch_init = ifx_pcie_bios_plat_dev_init;
2152 + /* Enable AHB Master/ Slave */
2153 + pcie_ahb_pmu_setup();
2155 + startup_port = ifx_pcie_startup_port_nr();
2157 + ltq_gpio_request(&pdev->dev, IFX_PCIE_GPIO_RESET, 0, 1, "pcie-reset");
2159 + for (pcie_port = startup_port; pcie_port < IFX_PCIE_CORE_NR; pcie_port++){
2160 + if (pcie_rc_initialize(pcie_port) == 0) {
2161 + /* Otherwise, warning will pop up */
2162 + io_map_base = ioremap(PCIE_IO_PHY_PORT_TO_BASE(pcie_port), PCIE_IO_SIZE);
2163 + if (io_map_base == NULL)
2165 + ifx_pcie_controller[pcie_port].pcic.io_map_base = (unsigned long)io_map_base;
2166 + register_pci_controller(&ifx_pcie_controller[pcie_port].pcic);
2167 + /* XXX, clear error status */
2168 + pcie_rc_core_int_init(pcie_port);
2172 + printk(KERN_INFO "%s", ver_str);
2176 +static struct platform_driver ltq_pcie_driver = {
2177 + .probe = ltq_pcie_probe,
2179 + .name = "pcie-xway",
2180 + .owner = THIS_MODULE,
2184 +int __init pciebios_init(void)
2186 + return platform_driver_register(<q_pcie_driver);
2189 +arch_initcall(pciebios_init);
2190 diff --git a/arch/mips/pci/pcie-lantiq.h b/arch/mips/pci/pcie-lantiq.h
2191 new file mode 100644
2192 index 0000000..d877c23
2194 +++ b/arch/mips/pci/pcie-lantiq.h
2196 +/******************************************************************************
2198 +** FILE NAME : ifxmips_pcie_reg.h
2199 +** PROJECT : IFX UEIP for VRX200
2200 +** MODULES : PCIe module
2202 +** DATE : 02 Mar 2009
2203 +** AUTHOR : Lei Chuanhua
2204 +** DESCRIPTION : PCIe Root Complex Driver
2205 +** COPYRIGHT : Copyright (c) 2009
2206 +** Infineon Technologies AG
2207 +** Am Campeon 1-12, 85579 Neubiberg, Germany
2209 +** This program is free software; you can redistribute it and/or modify
2210 +** it under the terms of the GNU General Public License as published by
2211 +** the Free Software Foundation; either version 2 of the License, or
2212 +** (at your option) any later version.
2214 +** $Version $Date $Author $Comment
2215 +** 0.0.1 17 Mar,2009 Lei Chuanhua Initial version
2216 +*******************************************************************************/
2217 +#ifndef IFXMIPS_PCIE_REG_H
2218 +#define IFXMIPS_PCIE_REG_H
2219 +#include <linux/version.h>
2220 +#include <linux/types.h>
2221 +#include <linux/pci.h>
2222 +#include <linux/interrupt.h>
2224 + \file ifxmips_pcie_reg.h
2226 + \brief header file for PCIe module register definition
2228 +/* PCIe Address Mapping Base */
2229 +#define PCIE_CFG_PHY_BASE 0x1D000000UL
2230 +#define PCIE_CFG_BASE (KSEG1 + PCIE_CFG_PHY_BASE)
2231 +#define PCIE_CFG_SIZE (8 * 1024 * 1024)
2233 +#define PCIE_MEM_PHY_BASE 0x1C000000UL
2234 +#define PCIE_MEM_BASE (KSEG1 + PCIE_MEM_PHY_BASE)
2235 +#define PCIE_MEM_SIZE (16 * 1024 * 1024)
2236 +#define PCIE_MEM_PHY_END (PCIE_MEM_PHY_BASE + PCIE_MEM_SIZE - 1)
2238 +#define PCIE_IO_PHY_BASE 0x1D800000UL
2239 +#define PCIE_IO_BASE (KSEG1 + PCIE_IO_PHY_BASE)
2240 +#define PCIE_IO_SIZE (1 * 1024 * 1024)
2241 +#define PCIE_IO_PHY_END (PCIE_IO_PHY_BASE + PCIE_IO_SIZE - 1)
2243 +#define PCIE_RC_CFG_BASE (KSEG1 + 0x1D900000)
2244 +#define PCIE_APP_LOGIC_REG (KSEG1 + 0x1E100900)
2245 +#define PCIE_MSI_PHY_BASE 0x1F600000UL
2247 +#define PCIE_PDI_PHY_BASE 0x1F106800UL
2248 +#define PCIE_PDI_BASE (KSEG1 + PCIE_PDI_PHY_BASE)
2249 +#define PCIE_PDI_SIZE 0x400
2251 +#define PCIE1_CFG_PHY_BASE 0x19000000UL
2252 +#define PCIE1_CFG_BASE (KSEG1 + PCIE1_CFG_PHY_BASE)
2253 +#define PCIE1_CFG_SIZE (8 * 1024 * 1024)
2255 +#define PCIE1_MEM_PHY_BASE 0x18000000UL
2256 +#define PCIE1_MEM_BASE (KSEG1 + PCIE1_MEM_PHY_BASE)
2257 +#define PCIE1_MEM_SIZE (16 * 1024 * 1024)
2258 +#define PCIE1_MEM_PHY_END (PCIE1_MEM_PHY_BASE + PCIE1_MEM_SIZE - 1)
2260 +#define PCIE1_IO_PHY_BASE 0x19800000UL
2261 +#define PCIE1_IO_BASE (KSEG1 + PCIE1_IO_PHY_BASE)
2262 +#define PCIE1_IO_SIZE (1 * 1024 * 1024)
2263 +#define PCIE1_IO_PHY_END (PCIE1_IO_PHY_BASE + PCIE1_IO_SIZE - 1)
2265 +#define PCIE1_RC_CFG_BASE (KSEG1 + 0x19900000)
2266 +#define PCIE1_APP_LOGIC_REG (KSEG1 + 0x1E100700)
2267 +#define PCIE1_MSI_PHY_BASE 0x1F400000UL
2269 +#define PCIE1_PDI_PHY_BASE 0x1F700400UL
2270 +#define PCIE1_PDI_BASE (KSEG1 + PCIE1_PDI_PHY_BASE)
2271 +#define PCIE1_PDI_SIZE 0x400
2273 +#define PCIE_CFG_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_CFG_BASE) : (PCIE_CFG_BASE))
2274 +#define PCIE_MEM_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_BASE) : (PCIE_MEM_BASE))
2275 +#define PCIE_IO_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_BASE) : (PCIE_IO_BASE))
2276 +#define PCIE_MEM_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_MEM_PHY_BASE) : (PCIE_MEM_PHY_BASE))
2277 +#define PCIE_MEM_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_MEM_PHY_END) : (PCIE_MEM_PHY_END))
2278 +#define PCIE_IO_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_IO_PHY_BASE) : (PCIE_IO_PHY_BASE))
2279 +#define PCIE_IO_PHY_PORT_TO_END(X) ((X) > 0 ? (PCIE1_IO_PHY_END) : (PCIE_IO_PHY_END))
2280 +#define PCIE_APP_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_APP_LOGIC_REG) : (PCIE_APP_LOGIC_REG))
2281 +#define PCIE_RC_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_RC_CFG_BASE) : (PCIE_RC_CFG_BASE))
2282 +#define PCIE_PHY_PORT_TO_BASE(X) ((X) > 0 ? (PCIE1_PDI_BASE) : (PCIE_PDI_BASE))
2284 +/* PCIe Application Logic Register */
2285 +/* RC Core Control Register */
2286 +#define PCIE_RC_CCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x10)
2287 +/* This should be enabled after initializing configuratin registers
2288 + * Also should check link status retraining bit
2290 +#define PCIE_RC_CCR_LTSSM_ENABLE 0x00000001 /* Enable LTSSM to continue link establishment */
2292 +/* RC Core Debug Register */
2293 +#define PCIE_RC_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x14)
2294 +#define PCIE_RC_DR_DLL_UP 0x00000001 /* Data Link Layer Up */
2295 +#define PCIE_RC_DR_CURRENT_POWER_STATE 0x0000000E /* Current Power State */
2296 +#define PCIE_RC_DR_CURRENT_POWER_STATE_S 1
2297 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE 0x000001F0 /* Current LTSSM State */
2298 +#define PCIE_RC_DR_CURRENT_LTSSM_STATE_S 4
2300 +#define PCIE_RC_DR_PM_DEV_STATE 0x00000E00 /* Power Management D-State */
2301 +#define PCIE_RC_DR_PM_DEV_STATE_S 9
2303 +#define PCIE_RC_DR_PM_ENABLED 0x00001000 /* Power Management State from PMU */
2304 +#define PCIE_RC_DR_PME_EVENT_ENABLED 0x00002000 /* Power Management Event Enable State */
2305 +#define PCIE_RC_DR_AUX_POWER_ENABLED 0x00004000 /* Auxiliary Power Enable */
2307 +/* Current Power State Definition */
2309 + PCIE_RC_DR_D0 = 0,
2310 + PCIE_RC_DR_D1, /* Not supported */
2311 + PCIE_RC_DR_D2, /* Not supported */
2316 +/* PHY Link Status Register */
2317 +#define PCIE_PHY_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x18)
2318 +#define PCIE_PHY_SR_PHY_LINK_UP 0x00000001 /* PHY Link Up/Down Indicator */
2320 +/* Electromechanical Control Register */
2321 +#define PCIE_EM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x1C)
2322 +#define PCIE_EM_CR_CARD_IS_PRESENT 0x00000001 /* Card Presence Detect State */
2323 +#define PCIE_EM_CR_MRL_OPEN 0x00000002 /* MRL Sensor State */
2324 +#define PCIE_EM_CR_POWER_FAULT_SET 0x00000004 /* Power Fault Detected */
2325 +#define PCIE_EM_CR_MRL_SENSOR_SET 0x00000008 /* MRL Sensor Changed */
2326 +#define PCIE_EM_CR_PRESENT_DETECT_SET 0x00000010 /* Card Presense Detect Changed */
2327 +#define PCIE_EM_CR_CMD_CPL_INT_SET 0x00000020 /* Command Complete Interrupt */
2328 +#define PCIE_EM_CR_SYS_INTERLOCK_SET 0x00000040 /* System Electromechanical IterLock Engaged */
2329 +#define PCIE_EM_CR_ATTENTION_BUTTON_SET 0x00000080 /* Attention Button Pressed */
2331 +/* Interrupt Status Register */
2332 +#define PCIE_IR_SR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x20)
2333 +#define PCIE_IR_SR_PME_CAUSE_MSI 0x00000002 /* MSI caused by PME */
2334 +#define PCIE_IR_SR_HP_PME_WAKE_GEN 0x00000004 /* Hotplug PME Wake Generation */
2335 +#define PCIE_IR_SR_HP_MSI 0x00000008 /* Hotplug MSI */
2336 +#define PCIE_IR_SR_AHB_LU_ERR 0x00000030 /* AHB Bridge Lookup Error Signals */
2337 +#define PCIE_IR_SR_AHB_LU_ERR_S 4
2338 +#define PCIE_IR_SR_INT_MSG_NUM 0x00003E00 /* Interrupt Message Number */
2339 +#define PCIE_IR_SR_INT_MSG_NUM_S 9
2340 +#define PCIE_IR_SR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
2341 +#define PCIE_IR_SR_AER_INT_MSG_NUM_S 27
2343 +/* Message Control Register */
2344 +#define PCIE_MSG_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x30)
2345 +#define PCIE_MSG_CR_GEN_PME_TURN_OFF_MSG 0x00000001 /* Generate PME Turn Off Message */
2346 +#define PCIE_MSG_CR_GEN_UNLOCK_MSG 0x00000002 /* Generate Unlock Message */
2348 +#define PCIE_VDM_DR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x34)
2350 +/* Vendor-Defined Message Requester ID Register */
2351 +#define PCIE_VDM_RID(X) (PCIE_APP_PORT_TO_BASE (X) + 0x38)
2352 +#define PCIE_VDM_RID_VENROR_MSG_REQ_ID 0x0000FFFF
2353 +#define PCIE_VDM_RID_VDMRID_S 0
2355 +/* ASPM Control Register */
2356 +#define PCIE_ASPM_CR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x40)
2357 +#define PCIE_ASPM_CR_HOT_RST 0x00000001 /* Hot Reset Request to the downstream device */
2358 +#define PCIE_ASPM_CR_REQ_EXIT_L1 0x00000002 /* Request to Exit L1 */
2359 +#define PCIE_ASPM_CR_REQ_ENTER_L1 0x00000004 /* Request to Enter L1 */
2361 +/* Vendor Message DW0 Register */
2362 +#define PCIE_VM_MSG_DW0(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x50)
2363 +#define PCIE_VM_MSG_DW0_TYPE 0x0000001F /* Message type */
2364 +#define PCIE_VM_MSG_DW0_TYPE_S 0
2365 +#define PCIE_VM_MSG_DW0_FORMAT 0x00000060 /* Format */
2366 +#define PCIE_VM_MSG_DW0_FORMAT_S 5
2367 +#define PCIE_VM_MSG_DW0_TC 0x00007000 /* Traffic Class */
2368 +#define PCIE_VM_MSG_DW0_TC_S 12
2369 +#define PCIE_VM_MSG_DW0_ATTR 0x000C0000 /* Atrributes */
2370 +#define PCIE_VM_MSG_DW0_ATTR_S 18
2371 +#define PCIE_VM_MSG_DW0_EP_TLP 0x00100000 /* Poisoned TLP */
2372 +#define PCIE_VM_MSG_DW0_TD 0x00200000 /* TLP Digest */
2373 +#define PCIE_VM_MSG_DW0_LEN 0xFFC00000 /* Length */
2374 +#define PCIE_VM_MSG_DW0_LEN_S 22
2376 +/* Format Definition */
2378 + PCIE_VM_MSG_FORMAT_00 = 0, /* 3DW Hdr, no data*/
2379 + PCIE_VM_MSG_FORMAT_01, /* 4DW Hdr, no data */
2380 + PCIE_VM_MSG_FORMAT_10, /* 3DW Hdr, with data */
2381 + PCIE_VM_MSG_FORMAT_11, /* 4DW Hdr, with data */
2384 +/* Traffic Class Definition */
2386 + PCIE_VM_MSG_TC0 = 0,
2396 +/* Attributes Definition */
2398 + PCIE_VM_MSG_ATTR_00 = 0, /* RO and No Snoop cleared */
2399 + PCIE_VM_MSG_ATTR_01, /* RO cleared , No Snoop set */
2400 + PCIE_VM_MSG_ATTR_10, /* RO set, No Snoop cleared*/
2401 + PCIE_VM_MSG_ATTR_11, /* RO and No Snoop set */
2404 +/* Payload Size Definition */
2405 +#define PCIE_VM_MSG_LEN_MIN 0
2406 +#define PCIE_VM_MSG_LEN_MAX 1024
2408 +/* Vendor Message DW1 Register */
2409 +#define PCIE_VM_MSG_DW1(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x54)
2410 +#define PCIE_VM_MSG_DW1_FUNC_NUM 0x00000070 /* Function Number */
2411 +#define PCIE_VM_MSG_DW1_FUNC_NUM_S 8
2412 +#define PCIE_VM_MSG_DW1_CODE 0x00FF0000 /* Message Code */
2413 +#define PCIE_VM_MSG_DW1_CODE_S 16
2414 +#define PCIE_VM_MSG_DW1_TAG 0xFF000000 /* Tag */
2415 +#define PCIE_VM_MSG_DW1_TAG_S 24
2417 +#define PCIE_VM_MSG_DW2(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x58)
2418 +#define PCIE_VM_MSG_DW3(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x5C)
2420 +/* Vendor Message Request Register */
2421 +#define PCIE_VM_MSG_REQR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x60)
2422 +#define PCIE_VM_MSG_REQR_REQ 0x00000001 /* Vendor Message Request */
2425 +/* AHB Slave Side Band Control Register */
2426 +#define PCIE_AHB_SSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x70)
2427 +#define PCIE_AHB_SSB_REQ_BCM 0x00000001 /* Slave Reques BCM filed */
2428 +#define PCIE_AHB_SSB_REQ_EP 0x00000002 /* Slave Reques EP filed */
2429 +#define PCIE_AHB_SSB_REQ_TD 0x00000004 /* Slave Reques TD filed */
2430 +#define PCIE_AHB_SSB_REQ_ATTR 0x00000018 /* Slave Reques Attribute number */
2431 +#define PCIE_AHB_SSB_REQ_ATTR_S 3
2432 +#define PCIE_AHB_SSB_REQ_TC 0x000000E0 /* Slave Request TC Field */
2433 +#define PCIE_AHB_SSB_REQ_TC_S 5
2435 +/* AHB Master SideBand Ctrl Register */
2436 +#define PCIE_AHB_MSB(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x74)
2437 +#define PCIE_AHB_MSB_RESP_ATTR 0x00000003 /* Master Response Attribute number */
2438 +#define PCIE_AHB_MSB_RESP_ATTR_S 0
2439 +#define PCIE_AHB_MSB_RESP_BAD_EOT 0x00000004 /* Master Response Badeot filed */
2440 +#define PCIE_AHB_MSB_RESP_BCM 0x00000008 /* Master Response BCM filed */
2441 +#define PCIE_AHB_MSB_RESP_EP 0x00000010 /* Master Response EP filed */
2442 +#define PCIE_AHB_MSB_RESP_TD 0x00000020 /* Master Response TD filed */
2443 +#define PCIE_AHB_MSB_RESP_FUN_NUM 0x000003C0 /* Master Response Function number */
2444 +#define PCIE_AHB_MSB_RESP_FUN_NUM_S 6
2446 +/* AHB Control Register, fixed bus enumeration exception */
2447 +#define PCIE_AHB_CTRL(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0x78)
2448 +#define PCIE_AHB_CTRL_BUS_ERROR_SUPPRESS 0x00000001
2450 +/* Interrupt Enalbe Register */
2451 +#define PCIE_IRNEN(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF4)
2452 +#define PCIE_IRNCR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xF8)
2453 +#define PCIE_IRNICR(X) (volatile u32*)(PCIE_APP_PORT_TO_BASE(X) + 0xFC)
2455 +/* PCIe interrupt enable/control/capture register definition */
2456 +#define PCIE_IRN_AER_REPORT 0x00000001 /* AER Interrupt */
2457 +#define PCIE_IRN_AER_MSIX 0x00000002 /* Advanced Error MSI-X Interrupt */
2458 +#define PCIE_IRN_PME 0x00000004 /* PME Interrupt */
2459 +#define PCIE_IRN_HOTPLUG 0x00000008 /* Hotplug Interrupt */
2460 +#define PCIE_IRN_RX_VDM_MSG 0x00000010 /* Vendor-Defined Message Interrupt */
2461 +#define PCIE_IRN_RX_CORRECTABLE_ERR_MSG 0x00000020 /* Correctable Error Message Interrupt */
2462 +#define PCIE_IRN_RX_NON_FATAL_ERR_MSG 0x00000040 /* Non-fatal Error Message */
2463 +#define PCIE_IRN_RX_FATAL_ERR_MSG 0x00000080 /* Fatal Error Message */
2464 +#define PCIE_IRN_RX_PME_MSG 0x00000100 /* PME Message Interrupt */
2465 +#define PCIE_IRN_RX_PME_TURNOFF_ACK 0x00000200 /* PME Turnoff Ack Message Interrupt */
2466 +#define PCIE_IRN_AHB_BR_FATAL_ERR 0x00000400 /* AHB Fatal Error Interrupt */
2467 +#define PCIE_IRN_LINK_AUTO_BW_STATUS 0x00000800 /* Link Auto Bandwidth Status Interrupt */
2468 +#define PCIE_IRN_BW_MGT 0x00001000 /* Bandwidth Managment Interrupt */
2469 +#define PCIE_IRN_INTA 0x00002000 /* INTA */
2470 +#define PCIE_IRN_INTB 0x00004000 /* INTB */
2471 +#define PCIE_IRN_INTC 0x00008000 /* INTC */
2472 +#define PCIE_IRN_INTD 0x00010000 /* INTD */
2473 +#define PCIE_IRN_WAKEUP 0x00020000 /* Wake up Interrupt */
2475 +#define PCIE_RC_CORE_COMBINED_INT (PCIE_IRN_AER_REPORT | PCIE_IRN_AER_MSIX | PCIE_IRN_PME | \
2476 + PCIE_IRN_HOTPLUG | PCIE_IRN_RX_VDM_MSG | PCIE_IRN_RX_CORRECTABLE_ERR_MSG |\
2477 + PCIE_IRN_RX_NON_FATAL_ERR_MSG | PCIE_IRN_RX_FATAL_ERR_MSG | \
2478 + PCIE_IRN_RX_PME_MSG | PCIE_IRN_RX_PME_TURNOFF_ACK | PCIE_IRN_AHB_BR_FATAL_ERR | \
2479 + PCIE_IRN_LINK_AUTO_BW_STATUS | PCIE_IRN_BW_MGT)
2480 +/* PCIe RC Configuration Register */
2481 +#define PCIE_VDID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x00)
2483 +/* Bit definition from pci_reg.h */
2484 +#define PCIE_PCICMDSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x04)
2485 +#define PCIE_CCRID(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x08)
2486 +#define PCIE_CLSLTHTBR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x0C) /* EP only */
2487 +/* BAR0, BAR1,Only necessary if the bridges implements a device-specific register set or memory buffer */
2488 +#define PCIE_BAR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10) /* Not used*/
2489 +#define PCIE_BAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14) /* Not used */
2491 +#define PCIE_BNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x18) /* Mandatory */
2492 +/* Bus Number Register bits */
2493 +#define PCIE_BNR_PRIMARY_BUS_NUM 0x000000FF
2494 +#define PCIE_BNR_PRIMARY_BUS_NUM_S 0
2495 +#define PCIE_PNR_SECONDARY_BUS_NUM 0x0000FF00
2496 +#define PCIE_PNR_SECONDARY_BUS_NUM_S 8
2497 +#define PCIE_PNR_SUB_BUS_NUM 0x00FF0000
2498 +#define PCIE_PNR_SUB_BUS_NUM_S 16
2500 +/* IO Base/Limit Register bits */
2501 +#define PCIE_IOBLSECS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x1C) /* RC only */
2502 +#define PCIE_IOBLSECS_32BIT_IO_ADDR 0x00000001
2503 +#define PCIE_IOBLSECS_IO_BASE_ADDR 0x000000F0
2504 +#define PCIE_IOBLSECS_IO_BASE_ADDR_S 4
2505 +#define PCIE_IOBLSECS_32BIT_IOLIMT 0x00000100
2506 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR 0x0000F000
2507 +#define PCIE_IOBLSECS_IO_LIMIT_ADDR_S 12
2509 +/* Non-prefetchable Memory Base/Limit Register bit */
2510 +#define PCIE_MBML(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x20) /* RC only */
2511 +#define PCIE_MBML_MEM_BASE_ADDR 0x0000FFF0
2512 +#define PCIE_MBML_MEM_BASE_ADDR_S 4
2513 +#define PCIE_MBML_MEM_LIMIT_ADDR 0xFFF00000
2514 +#define PCIE_MBML_MEM_LIMIT_ADDR_S 20
2516 +/* Prefetchable Memory Base/Limit Register bit */
2517 +#define PCIE_PMBL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x24) /* RC only */
2518 +#define PCIE_PMBL_64BIT_ADDR 0x00000001
2519 +#define PCIE_PMBL_UPPER_12BIT 0x0000FFF0
2520 +#define PCIE_PMBL_UPPER_12BIT_S 4
2521 +#define PCIE_PMBL_E64MA 0x00010000
2522 +#define PCIE_PMBL_END_ADDR 0xFFF00000
2523 +#define PCIE_PMBL_END_ADDR_S 20
2524 +#define PCIE_PMBU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x28) /* RC only */
2525 +#define PCIE_PMLU32(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x2C) /* RC only */
2527 +/* I/O Base/Limit Upper 16 bits register */
2528 +#define PCIE_IO_BANDL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x30) /* RC only */
2529 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE 0x0000FFFF
2530 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_BASE_S 0
2531 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT 0xFFFF0000
2532 +#define PCIE_IO_BANDL_UPPER_16BIT_IO_LIMIT_S 16
2534 +#define PCIE_CPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x34)
2535 +#define PCIE_EBBAR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x38)
2537 +/* Interrupt and Secondary Bridge Control Register */
2538 +#define PCIE_INTRBCTRL(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x3C)
2540 +#define PCIE_INTRBCTRL_INT_LINE 0x000000FF
2541 +#define PCIE_INTRBCTRL_INT_LINE_S 0
2542 +#define PCIE_INTRBCTRL_INT_PIN 0x0000FF00
2543 +#define PCIE_INTRBCTRL_INT_PIN_S 8
2544 +#define PCIE_INTRBCTRL_PARITY_ERR_RESP_ENABLE 0x00010000 /* #PERR */
2545 +#define PCIE_INTRBCTRL_SERR_ENABLE 0x00020000 /* #SERR */
2546 +#define PCIE_INTRBCTRL_ISA_ENABLE 0x00040000 /* ISA enable, IO 64KB only */
2547 +#define PCIE_INTRBCTRL_VGA_ENABLE 0x00080000 /* VGA enable */
2548 +#define PCIE_INTRBCTRL_VGA_16BIT_DECODE 0x00100000 /* VGA 16bit decode */
2549 +#define PCIE_INTRBCTRL_RST_SECONDARY_BUS 0x00400000 /* Secondary bus rest, hot rest, 1ms */
2550 +/* Others are read only */
2552 + PCIE_INTRBCTRL_INT_NON = 0,
2553 + PCIE_INTRBCTRL_INTA,
2554 + PCIE_INTRBCTRL_INTB,
2555 + PCIE_INTRBCTRL_INTC,
2556 + PCIE_INTRBCTRL_INTD,
2559 +#define PCIE_PM_CAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x40)
2561 +/* Power Management Control and Status Register */
2562 +#define PCIE_PM_CSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x44)
2564 +#define PCIE_PM_CSR_POWER_STATE 0x00000003 /* Power State */
2565 +#define PCIE_PM_CSR_POWER_STATE_S 0
2566 +#define PCIE_PM_CSR_SW_RST 0x00000008 /* Soft Reset Enabled */
2567 +#define PCIE_PM_CSR_PME_ENABLE 0x00000100 /* PME Enable */
2568 +#define PCIE_PM_CSR_PME_STATUS 0x00008000 /* PME status */
2570 +/* MSI Capability Register for EP */
2571 +#define PCIE_MCAPR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x50)
2573 +#define PCIE_MCAPR_MSI_CAP_ID 0x000000FF /* MSI Capability ID */
2574 +#define PCIE_MCAPR_MSI_CAP_ID_S 0
2575 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR 0x0000FF00 /* Next Capability Pointer */
2576 +#define PCIE_MCAPR_MSI_NEXT_CAP_PTR_S 8
2577 +#define PCIE_MCAPR_MSI_ENABLE 0x00010000 /* MSI Enable */
2578 +#define PCIE_MCAPR_MULTI_MSG_CAP 0x000E0000 /* Multiple Message Capable */
2579 +#define PCIE_MCAPR_MULTI_MSG_CAP_S 17
2580 +#define PCIE_MCAPR_MULTI_MSG_ENABLE 0x00700000 /* Multiple Message Enable */
2581 +#define PCIE_MCAPR_MULTI_MSG_ENABLE_S 20
2582 +#define PCIE_MCAPR_ADDR64_CAP 0X00800000 /* 64-bit Address Capable */
2584 +/* MSI Message Address Register */
2585 +#define PCIE_MA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x54)
2587 +#define PCIE_MA_ADDR_MASK 0xFFFFFFFC /* Message Address */
2589 +/* MSI Message Upper Address Register */
2590 +#define PCIE_MUA(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x58)
2592 +/* MSI Message Data Register */
2593 +#define PCIE_MD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x5C)
2595 +#define PCIE_MD_DATA 0x0000FFFF /* Message Data */
2596 +#define PCIE_MD_DATA_S 0
2598 +/* PCI Express Capability Register */
2599 +#define PCIE_XCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70)
2601 +#define PCIE_XCAP_ID 0x000000FF /* PCI Express Capability ID */
2602 +#define PCIE_XCAP_ID_S 0
2603 +#define PCIE_XCAP_NEXT_CAP 0x0000FF00 /* Next Capability Pointer */
2604 +#define PCIE_XCAP_NEXT_CAP_S 8
2605 +#define PCIE_XCAP_VER 0x000F0000 /* PCI Express Capability Version */
2606 +#define PCIE_XCAP_VER_S 16
2607 +#define PCIE_XCAP_DEV_PORT_TYPE 0x00F00000 /* Device Port Type */
2608 +#define PCIE_XCAP_DEV_PORT_TYPE_S 20
2609 +#define PCIE_XCAP_SLOT_IMPLEMENTED 0x01000000 /* Slot Implemented */
2610 +#define PCIE_XCAP_MSG_INT_NUM 0x3E000000 /* Interrupt Message Number */
2611 +#define PCIE_XCAP_MSG_INT_NUM_S 25
2613 +/* Device Capability Register */
2614 +#define PCIE_DCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74)
2616 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE 0x00000007 /* Max Payload size */
2617 +#define PCIE_DCAP_MAX_PAYLOAD_SIZE_S 0
2618 +#define PCIE_DCAP_PHANTOM_FUNC 0x00000018 /* Phanton Function, not supported */
2619 +#define PCIE_DCAP_PHANTOM_FUNC_S 3
2620 +#define PCIE_DCAP_EXT_TAG 0x00000020 /* Extended Tag Field */
2621 +#define PCIE_DCAP_EP_L0S_LATENCY 0x000001C0 /* EP L0s latency only */
2622 +#define PCIE_DCAP_EP_L0S_LATENCY_S 6
2623 +#define PCIE_DCAP_EP_L1_LATENCY 0x00000E00 /* EP L1 latency only */
2624 +#define PCIE_DCAP_EP_L1_LATENCY_S 9
2625 +#define PCIE_DCAP_ROLE_BASE_ERR_REPORT 0x00008000 /* Role Based ERR */
2627 +/* Maximum payload size supported */
2629 + PCIE_MAX_PAYLOAD_128 = 0,
2630 + PCIE_MAX_PAYLOAD_256,
2631 + PCIE_MAX_PAYLOAD_512,
2632 + PCIE_MAX_PAYLOAD_1024,
2633 + PCIE_MAX_PAYLOAD_2048,
2634 + PCIE_MAX_PAYLOAD_4096,
2637 +/* Device Control and Status Register */
2638 +#define PCIE_DCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x78)
2640 +#define PCIE_DCTLSTS_CORRECTABLE_ERR_EN 0x00000001 /* COR-ERR */
2641 +#define PCIE_DCTLSTS_NONFATAL_ERR_EN 0x00000002 /* Non-fatal ERR */
2642 +#define PCIE_DCTLSTS_FATAL_ERR_EN 0x00000004 /* Fatal ERR */
2643 +#define PCIE_DCTLSYS_UR_REQ_EN 0x00000008 /* UR ERR */
2644 +#define PCIE_DCTLSTS_RELAXED_ORDERING_EN 0x00000010 /* Enable relaxing ordering */
2645 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE 0x000000E0 /* Max payload mask */
2646 +#define PCIE_DCTLSTS_MAX_PAYLOAD_SIZE_S 5
2647 +#define PCIE_DCTLSTS_EXT_TAG_EN 0x00000100 /* Extended tag field */
2648 +#define PCIE_DCTLSTS_PHANTOM_FUNC_EN 0x00000200 /* Phantom Function Enable */
2649 +#define PCIE_DCTLSTS_AUX_PM_EN 0x00000400 /* AUX Power PM Enable */
2650 +#define PCIE_DCTLSTS_NO_SNOOP_EN 0x00000800 /* Enable no snoop, except root port*/
2651 +#define PCIE_DCTLSTS_MAX_READ_SIZE 0x00007000 /* Max Read Request size*/
2652 +#define PCIE_DCTLSTS_MAX_READ_SIZE_S 12
2653 +#define PCIE_DCTLSTS_CORRECTABLE_ERR 0x00010000 /* COR-ERR Detected */
2654 +#define PCIE_DCTLSTS_NONFATAL_ERR 0x00020000 /* Non-Fatal ERR Detected */
2655 +#define PCIE_DCTLSTS_FATAL_ER 0x00040000 /* Fatal ERR Detected */
2656 +#define PCIE_DCTLSTS_UNSUPPORTED_REQ 0x00080000 /* UR Detected */
2657 +#define PCIE_DCTLSTS_AUX_POWER 0x00100000 /* Aux Power Detected */
2658 +#define PCIE_DCTLSTS_TRANSACT_PENDING 0x00200000 /* Transaction pending */
2660 +#define PCIE_DCTLSTS_ERR_EN (PCIE_DCTLSTS_CORRECTABLE_ERR_EN | \
2661 + PCIE_DCTLSTS_NONFATAL_ERR_EN | PCIE_DCTLSTS_FATAL_ERR_EN | \
2662 + PCIE_DCTLSYS_UR_REQ_EN)
2664 +/* Link Capability Register */
2665 +#define PCIE_LCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7C)
2666 +#define PCIE_LCAP_MAX_LINK_SPEED 0x0000000F /* Max link speed, 0x1 by default */
2667 +#define PCIE_LCAP_MAX_LINK_SPEED_S 0
2668 +#define PCIE_LCAP_MAX_LENGTH_WIDTH 0x000003F0 /* Maxium Length Width */
2669 +#define PCIE_LCAP_MAX_LENGTH_WIDTH_S 4
2670 +#define PCIE_LCAP_ASPM_LEVEL 0x00000C00 /* Active State Link PM Support */
2671 +#define PCIE_LCAP_ASPM_LEVEL_S 10
2672 +#define PCIE_LCAP_L0S_EIXT_LATENCY 0x00007000 /* L0s Exit Latency */
2673 +#define PCIE_LCAP_L0S_EIXT_LATENCY_S 12
2674 +#define PCIE_LCAP_L1_EXIT_LATENCY 0x00038000 /* L1 Exit Latency */
2675 +#define PCIE_LCAP_L1_EXIT_LATENCY_S 15
2676 +#define PCIE_LCAP_CLK_PM 0x00040000 /* Clock Power Management */
2677 +#define PCIE_LCAP_SDER 0x00080000 /* Surprise Down Error Reporting */
2678 +#define PCIE_LCAP_DLL_ACTIVE_REPROT 0x00100000 /* Data Link Layer Active Reporting Capable */
2679 +#define PCIE_LCAP_PORT_NUM 0xFF0000000 /* Port number */
2680 +#define PCIE_LCAP_PORT_NUM_S 24
2682 +/* Maximum Length width definition */
2683 +#define PCIE_MAX_LENGTH_WIDTH_RES 0x00
2684 +#define PCIE_MAX_LENGTH_WIDTH_X1 0x01 /* Default */
2685 +#define PCIE_MAX_LENGTH_WIDTH_X2 0x02
2686 +#define PCIE_MAX_LENGTH_WIDTH_X4 0x04
2687 +#define PCIE_MAX_LENGTH_WIDTH_X8 0x08
2688 +#define PCIE_MAX_LENGTH_WIDTH_X12 0x0C
2689 +#define PCIE_MAX_LENGTH_WIDTH_X16 0x10
2690 +#define PCIE_MAX_LENGTH_WIDTH_X32 0x20
2692 +/* Active State Link PM definition */
2694 + PCIE_ASPM_RES0 = 0,
2695 + PCIE_ASPM_L0S_ENTRY_SUPPORT, /* L0s */
2697 + PCIE_ASPM_L0S_L1_ENTRY_SUPPORT, /* L0s and L1, default */
2700 +/* L0s Exit Latency definition */
2702 + PCIE_L0S_EIXT_LATENCY_L64NS = 0, /* < 64 ns */
2703 + PCIE_L0S_EIXT_LATENCY_B64A128, /* > 64 ns < 128 ns */
2704 + PCIE_L0S_EIXT_LATENCY_B128A256, /* > 128 ns < 256 ns */
2705 + PCIE_L0S_EIXT_LATENCY_B256A512, /* > 256 ns < 512 ns */
2706 + PCIE_L0S_EIXT_LATENCY_B512TO1U, /* > 512 ns < 1 us */
2707 + PCIE_L0S_EIXT_LATENCY_B1A2U, /* > 1 us < 2 us */
2708 + PCIE_L0S_EIXT_LATENCY_B2A4U, /* > 2 us < 4 us */
2709 + PCIE_L0S_EIXT_LATENCY_M4US, /* > 4 us */
2712 +/* L1 Exit Latency definition */
2714 + PCIE_L1_EXIT_LATENCY_L1US = 0, /* < 1 us */
2715 + PCIE_L1_EXIT_LATENCY_B1A2, /* > 1 us < 2 us */
2716 + PCIE_L1_EXIT_LATENCY_B2A4, /* > 2 us < 4 us */
2717 + PCIE_L1_EXIT_LATENCY_B4A8, /* > 4 us < 8 us */
2718 + PCIE_L1_EXIT_LATENCY_B8A16, /* > 8 us < 16 us */
2719 + PCIE_L1_EXIT_LATENCY_B16A32, /* > 16 us < 32 us */
2720 + PCIE_L1_EXIT_LATENCY_B32A64, /* > 32 us < 64 us */
2721 + PCIE_L1_EXIT_LATENCY_M64US, /* > 64 us */
2724 +/* Link Control and Status Register */
2725 +#define PCIE_LCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x80)
2726 +#define PCIE_LCTLSTS_ASPM_ENABLE 0x00000003 /* Active State Link PM Control */
2727 +#define PCIE_LCTLSTS_ASPM_ENABLE_S 0
2728 +#define PCIE_LCTLSTS_RCB128 0x00000008 /* Read Completion Boundary 128*/
2729 +#define PCIE_LCTLSTS_LINK_DISABLE 0x00000010 /* Link Disable */
2730 +#define PCIE_LCTLSTS_RETRIAN_LINK 0x00000020 /* Retrain Link */
2731 +#define PCIE_LCTLSTS_COM_CLK_CFG 0x00000040 /* Common Clock Configuration */
2732 +#define PCIE_LCTLSTS_EXT_SYNC 0x00000080 /* Extended Synch */
2733 +#define PCIE_LCTLSTS_CLK_PM_EN 0x00000100 /* Enable Clock Powerm Management */
2734 +#define PCIE_LCTLSTS_LINK_SPEED 0x000F0000 /* Link Speed */
2735 +#define PCIE_LCTLSTS_LINK_SPEED_S 16
2736 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH 0x03F00000 /* Negotiated Link Width */
2737 +#define PCIE_LCTLSTS_NEGOTIATED_LINK_WIDTH_S 20
2738 +#define PCIE_LCTLSTS_RETRAIN_PENDING 0x08000000 /* Link training is ongoing */
2739 +#define PCIE_LCTLSTS_SLOT_CLK_CFG 0x10000000 /* Slot Clock Configuration */
2740 +#define PCIE_LCTLSTS_DLL_ACTIVE 0x20000000 /* Data Link Layer Active */
2742 +/* Slot Capabilities Register */
2743 +#define PCIE_SLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x84)
2745 +/* Slot Capabilities */
2746 +#define PCIE_SLCTLSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x88)
2748 +/* Root Control and Capability Register */
2749 +#define PCIE_RCTLCAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x8C)
2750 +#define PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR 0x00000001 /* #SERR on COR-ERR */
2751 +#define PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR 0x00000002 /* #SERR on Non-Fatal ERR */
2752 +#define PCIE_RCTLCAP_SERR_ON_FATAL_ERR 0x00000004 /* #SERR on Fatal ERR */
2753 +#define PCIE_RCTLCAP_PME_INT_EN 0x00000008 /* PME Interrupt Enable */
2754 +#define PCIE_RCTLCAP_SERR_ENABLE (PCIE_RCTLCAP_SERR_ON_CORRECTABLE_ERR | \
2755 + PCIE_RCTLCAP_SERR_ON_NONFATAL_ERR | PCIE_RCTLCAP_SERR_ON_FATAL_ERR)
2756 +/* Root Status Register */
2757 +#define PCIE_RSTS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x90)
2758 +#define PCIE_RSTS_PME_REQ_ID 0x0000FFFF /* PME Request ID */
2759 +#define PCIE_RSTS_PME_REQ_ID_S 0
2760 +#define PCIE_RSTS_PME_STATUS 0x00010000 /* PME Status */
2761 +#define PCIE_RSTS_PME_PENDING 0x00020000 /* PME Pending */
2763 +/* PCI Express Enhanced Capability Header */
2764 +#define PCIE_ENHANCED_CAP(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x100)
2765 +#define PCIE_ENHANCED_CAP_ID 0x0000FFFF /* PCI Express Extended Capability ID */
2766 +#define PCIE_ENHANCED_CAP_ID_S 0
2767 +#define PCIE_ENHANCED_CAP_VER 0x000F0000 /* Capability Version */
2768 +#define PCIE_ENHANCED_CAP_VER_S 16
2769 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET 0xFFF00000 /* Next Capability Offset */
2770 +#define PCIE_ENHANCED_CAP_NEXT_OFFSET_S 20
2772 +/* Uncorrectable Error Status Register */
2773 +#define PCIE_UES_R(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x104)
2774 +#define PCIE_DATA_LINK_PROTOCOL_ERR 0x00000010 /* Data Link Protocol Error Status */
2775 +#define PCIE_SURPRISE_DOWN_ERROR 0x00000020 /* Surprise Down Error Status */
2776 +#define PCIE_POISONED_TLP 0x00001000 /* Poisoned TLP Status */
2777 +#define PCIE_FC_PROTOCOL_ERR 0x00002000 /* Flow Control Protocol Error Status */
2778 +#define PCIE_COMPLETION_TIMEOUT 0x00004000 /* Completion Timeout Status */
2779 +#define PCIE_COMPLETOR_ABORT 0x00008000 /* Completer Abort Error */
2780 +#define PCIE_UNEXPECTED_COMPLETION 0x00010000 /* Unexpected Completion Status */
2781 +#define PCIE_RECEIVER_OVERFLOW 0x00020000 /* Receive Overflow Status */
2782 +#define PCIE_MALFORNED_TLP 0x00040000 /* Malformed TLP Stauts */
2783 +#define PCIE_ECRC_ERR 0x00080000 /* ECRC Error Stauts */
2784 +#define PCIE_UR_REQ 0x00100000 /* Unsupported Request Error Status */
2785 +#define PCIE_ALL_UNCORRECTABLE_ERR (PCIE_DATA_LINK_PROTOCOL_ERR | PCIE_SURPRISE_DOWN_ERROR | \
2786 + PCIE_POISONED_TLP | PCIE_FC_PROTOCOL_ERR | PCIE_COMPLETION_TIMEOUT | \
2787 + PCIE_COMPLETOR_ABORT | PCIE_UNEXPECTED_COMPLETION | PCIE_RECEIVER_OVERFLOW |\
2788 + PCIE_MALFORNED_TLP | PCIE_ECRC_ERR | PCIE_UR_REQ)
2790 +/* Uncorrectable Error Mask Register, Mask means no report */
2791 +#define PCIE_UEMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x108)
2793 +/* Uncorrectable Error Severity Register */
2794 +#define PCIE_UESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x10C)
2796 +/* Correctable Error Status Register */
2797 +#define PCIE_CESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x110)
2798 +#define PCIE_RX_ERR 0x00000001 /* Receive Error Status */
2799 +#define PCIE_BAD_TLP 0x00000040 /* Bad TLP Status */
2800 +#define PCIE_BAD_DLLP 0x00000080 /* Bad DLLP Status */
2801 +#define PCIE_REPLAY_NUM_ROLLOVER 0x00000100 /* Replay Number Rollover Status */
2802 +#define PCIE_REPLAY_TIMER_TIMEOUT_ERR 0x00001000 /* Reply Timer Timeout Status */
2803 +#define PCIE_ADVISORY_NONFTAL_ERR 0x00002000 /* Advisory Non-Fatal Error Status */
2804 +#define PCIE_CORRECTABLE_ERR (PCIE_RX_ERR | PCIE_BAD_TLP | PCIE_BAD_DLLP | PCIE_REPLAY_NUM_ROLLOVER |\
2805 + PCIE_REPLAY_TIMER_TIMEOUT_ERR | PCIE_ADVISORY_NONFTAL_ERR)
2807 +/* Correctable Error Mask Register */
2808 +#define PCIE_CEMR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x114)
2810 +/* Advanced Error Capabilities and Control Register */
2811 +#define PCIE_AECCR(X) (volatile u32*)(PCIE_RC_CFG_BASE + 0x118)
2812 +#define PCIE_AECCR_FIRST_ERR_PTR 0x0000001F /* First Error Pointer */
2813 +#define PCIE_AECCR_FIRST_ERR_PTR_S 0
2814 +#define PCIE_AECCR_ECRC_GEN_CAP 0x00000020 /* ECRC Generation Capable */
2815 +#define PCIE_AECCR_ECRC_GEN_EN 0x00000040 /* ECRC Generation Enable */
2816 +#define PCIE_AECCR_ECRC_CHECK_CAP 0x00000080 /* ECRC Check Capable */
2817 +#define PCIE_AECCR_ECRC_CHECK_EN 0x00000100 /* ECRC Check Enable */
2819 +/* Header Log Register 1 */
2820 +#define PCIE_HLR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x11C)
2822 +/* Header Log Register 2 */
2823 +#define PCIE_HLR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x120)
2825 +/* Header Log Register 3 */
2826 +#define PCIE_HLR3(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x124)
2828 +/* Header Log Register 4 */
2829 +#define PCIE_HLR4(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x128)
2831 +/* Root Error Command Register */
2832 +#define PCIE_RECR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x12C)
2833 +#define PCIE_RECR_CORRECTABLE_ERR_REPORT_EN 0x00000001 /* COR-ERR */
2834 +#define PCIE_RECR_NONFATAL_ERR_REPORT_EN 0x00000002 /* Non-Fatal ERR */
2835 +#define PCIE_RECR_FATAL_ERR_REPORT_EN 0x00000004 /* Fatal ERR */
2836 +#define PCIE_RECR_ERR_REPORT_EN (PCIE_RECR_CORRECTABLE_ERR_REPORT_EN | \
2837 + PCIE_RECR_NONFATAL_ERR_REPORT_EN | PCIE_RECR_FATAL_ERR_REPORT_EN)
2839 +/* Root Error Status Register */
2840 +#define PCIE_RESR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x130)
2841 +#define PCIE_RESR_CORRECTABLE_ERR 0x00000001 /* COR-ERR Receveid */
2842 +#define PCIE_RESR_MULTI_CORRECTABLE_ERR 0x00000002 /* Multiple COR-ERR Received */
2843 +#define PCIE_RESR_FATAL_NOFATAL_ERR 0x00000004 /* ERR Fatal/Non-Fatal Received */
2844 +#define PCIE_RESR_MULTI_FATAL_NOFATAL_ERR 0x00000008 /* Multiple ERR Fatal/Non-Fatal Received */
2845 +#define PCIE_RESR_FIRST_UNCORRECTABLE_FATAL_ERR 0x00000010 /* First UN-COR Fatal */
2846 +#define PCIR_RESR_NON_FATAL_ERR 0x00000020 /* Non-Fatal Error Message Received */
2847 +#define PCIE_RESR_FATAL_ERR 0x00000040 /* Fatal Message Received */
2848 +#define PCIE_RESR_AER_INT_MSG_NUM 0xF8000000 /* Advanced Error Interrupt Message Number */
2849 +#define PCIE_RESR_AER_INT_MSG_NUM_S 27
2851 +/* Error Source Indentification Register */
2852 +#define PCIE_ESIR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x134)
2853 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID 0x0000FFFF
2854 +#define PCIE_ESIR_CORRECTABLE_ERR_SRC_ID_S 0
2855 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID 0xFFFF0000
2856 +#define PCIE_ESIR_FATAL_NON_FATAL_SRC_ID_S 16
2858 +/* VC Enhanced Capability Header */
2859 +#define PCIE_VC_ECH(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x140)
2861 +/* Port VC Capability Register */
2862 +#define PCIE_PVC1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x144)
2863 +#define PCIE_PVC1_EXT_VC_CNT 0x00000007 /* Extended VC Count */
2864 +#define PCIE_PVC1_EXT_VC_CNT_S 0
2865 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT 0x00000070 /* Low Priority Extended VC Count */
2866 +#define PCIE_PVC1_LOW_PRI_EXT_VC_CNT_S 4
2867 +#define PCIE_PVC1_REF_CLK 0x00000300 /* Reference Clock */
2868 +#define PCIE_PVC1_REF_CLK_S 8
2869 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE 0x00000C00 /* Port Arbitration Table Entry Size */
2870 +#define PCIE_PVC1_PORT_ARB_TAB_ENTRY_SIZE_S 10
2872 +/* Extended Virtual Channel Count Defintion */
2873 +#define PCIE_EXT_VC_CNT_MIN 0
2874 +#define PCIE_EXT_VC_CNT_MAX 7
2876 +/* Port Arbitration Table Entry Size Definition */
2878 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S1BIT = 0,
2879 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S2BIT,
2880 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S4BIT,
2881 + PCIE_PORT_ARB_TAB_ENTRY_SIZE_S8BIT,
2884 +/* Port VC Capability Register 2 */
2885 +#define PCIE_PVC2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x148)
2886 +#define PCIE_PVC2_VC_ARB_16P_FIXED_WRR 0x00000001 /* HW Fixed arbitration, 16 phase WRR */
2887 +#define PCIE_PVC2_VC_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
2888 +#define PCIE_PVC2_VC_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
2889 +#define PCIE_PVC2_VC_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
2890 +#define PCIE_PVC2_VC_ARB_WRR 0x0000000F
2891 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET 0xFF000000 /* VC arbitration table offset, not support */
2892 +#define PCIE_PVC2_VC_ARB_TAB_OFFSET_S 24
2894 +/* Port VC Control and Status Register */
2895 +#define PCIE_PVCCRSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x14C)
2896 +#define PCIE_PVCCRSR_LOAD_VC_ARB_TAB 0x00000001 /* Load VC Arbitration Table */
2897 +#define PCIE_PVCCRSR_VC_ARB_SEL 0x0000000E /* VC Arbitration Select */
2898 +#define PCIE_PVCCRSR_VC_ARB_SEL_S 1
2899 +#define PCIE_PVCCRSR_VC_ARB_TAB_STATUS 0x00010000 /* Arbitration Status */
2901 +/* VC0 Resource Capability Register */
2902 +#define PCIE_VC0_RC(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x150)
2903 +#define PCIE_VC0_RC_PORT_ARB_HW_FIXED 0x00000001 /* HW Fixed arbitration */
2904 +#define PCIE_VC0_RC_PORT_ARB_32P_WRR 0x00000002 /* 32 phase WRR */
2905 +#define PCIE_VC0_RC_PORT_ARB_64P_WRR 0x00000004 /* 64 phase WRR */
2906 +#define PCIE_VC0_RC_PORT_ARB_128P_WRR 0x00000008 /* 128 phase WRR */
2907 +#define PCIE_VC0_RC_PORT_ARB_TM_128P_WRR 0x00000010 /* Time-based 128 phase WRR */
2908 +#define PCIE_VC0_RC_PORT_ARB_TM_256P_WRR 0x00000020 /* Time-based 256 phase WRR */
2909 +#define PCIE_VC0_RC_PORT_ARB (PCIE_VC0_RC_PORT_ARB_HW_FIXED | PCIE_VC0_RC_PORT_ARB_32P_WRR |\
2910 + PCIE_VC0_RC_PORT_ARB_64P_WRR | PCIE_VC0_RC_PORT_ARB_128P_WRR | \
2911 + PCIE_VC0_RC_PORT_ARB_TM_128P_WRR | PCIE_VC0_RC_PORT_ARB_TM_256P_WRR)
2913 +#define PCIE_VC0_RC_REJECT_SNOOP 0x00008000 /* Reject Snoop Transactioin */
2914 +#define PCIE_VC0_RC_MAX_TIMESLOTS 0x007F0000 /* Maximum time Slots */
2915 +#define PCIE_VC0_RC_MAX_TIMESLOTS_S 16
2916 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET 0xFF000000 /* Port Arbitration Table Offset */
2917 +#define PCIE_VC0_RC_PORT_ARB_TAB_OFFSET_S 24
2919 +/* VC0 Resource Control Register */
2920 +#define PCIE_VC0_RC0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x154)
2921 +#define PCIE_VC0_RC0_TVM0 0x00000001 /* TC0 and VC0 */
2922 +#define PCIE_VC0_RC0_TVM1 0x00000002 /* TC1 and VC1 */
2923 +#define PCIE_VC0_RC0_TVM2 0x00000004 /* TC2 and VC2 */
2924 +#define PCIE_VC0_RC0_TVM3 0x00000008 /* TC3 and VC3 */
2925 +#define PCIE_VC0_RC0_TVM4 0x00000010 /* TC4 and VC4 */
2926 +#define PCIE_VC0_RC0_TVM5 0x00000020 /* TC5 and VC5 */
2927 +#define PCIE_VC0_RC0_TVM6 0x00000040 /* TC6 and VC6 */
2928 +#define PCIE_VC0_RC0_TVM7 0x00000080 /* TC7 and VC7 */
2929 +#define PCIE_VC0_RC0_TC_VC 0x000000FF /* TC/VC mask */
2931 +#define PCIE_VC0_RC0_LOAD_PORT_ARB_TAB 0x00010000 /* Load Port Arbitration Table */
2932 +#define PCIE_VC0_RC0_PORT_ARB_SEL 0x000E0000 /* Port Arbitration Select */
2933 +#define PCIE_VC0_RC0_PORT_ARB_SEL_S 17
2934 +#define PCIE_VC0_RC0_VC_ID 0x07000000 /* VC ID */
2935 +#define PCIE_VC0_RC0_VC_ID_S 24
2936 +#define PCIE_VC0_RC0_VC_EN 0x80000000 /* VC Enable */
2938 +/* VC0 Resource Status Register */
2939 +#define PCIE_VC0_RSR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x158)
2940 +#define PCIE_VC0_RSR0_PORT_ARB_TAB_STATUS 0x00010000 /* Port Arbitration Table Status,not used */
2941 +#define PCIE_VC0_RSR0_VC_NEG_PENDING 0x00020000 /* VC Negotiation Pending */
2943 +/* Ack Latency Timer and Replay Timer Register */
2944 +#define PCIE_ALTRT(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x700)
2945 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT 0x0000FFFF /* Round Trip Latency Time Limit */
2946 +#define PCIE_ALTRT_ROUND_TRIP_LATENCY_LIMIT_S 0
2947 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT 0xFFFF0000 /* Replay Time Limit */
2948 +#define PCIE_ALTRT_REPLAY_TIME_LIMIT_S 16
2950 +/* Other Message Register */
2951 +#define PCIE_OMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x704)
2953 +/* Port Force Link Register */
2954 +#define PCIE_PFLR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x708)
2955 +#define PCIE_PFLR_LINK_NUM 0x000000FF /* Link Number */
2956 +#define PCIE_PFLR_LINK_NUM_S 0
2957 +#define PCIE_PFLR_FORCE_LINK 0x00008000 /* Force link */
2958 +#define PCIE_PFLR_LINK_STATE 0x003F0000 /* Link State */
2959 +#define PCIE_PFLR_LINK_STATE_S 16
2960 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT 0xFF000000 /* Low Power Entrance Count, only for EP */
2961 +#define PCIE_PFLR_LOW_POWER_ENTRY_CNT_S 24
2963 +/* Ack Frequency Register */
2964 +#define PCIE_AFR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x70C)
2965 +#define PCIE_AFR_AF 0x000000FF /* Ack Frequency */
2966 +#define PCIE_AFR_AF_S 0
2967 +#define PCIE_AFR_FTS_NUM 0x0000FF00 /* The number of Fast Training Sequence from L0S to L0 */
2968 +#define PCIE_AFR_FTS_NUM_S 8
2969 +#define PCIE_AFR_COM_FTS_NUM 0x00FF0000 /* N_FTS; when common clock is used*/
2970 +#define PCIE_AFR_COM_FTS_NUM_S 16
2971 +#define PCIE_AFR_L0S_ENTRY_LATENCY 0x07000000 /* L0s Entrance Latency */
2972 +#define PCIE_AFR_L0S_ENTRY_LATENCY_S 24
2973 +#define PCIE_AFR_L1_ENTRY_LATENCY 0x38000000 /* L1 Entrance Latency */
2974 +#define PCIE_AFR_L1_ENTRY_LATENCY_S 27
2975 +#define PCIE_AFR_FTS_NUM_DEFAULT 32
2976 +#define PCIE_AFR_L0S_ENTRY_LATENCY_DEFAULT 7
2977 +#define PCIE_AFR_L1_ENTRY_LATENCY_DEFAULT 5
2979 +/* Port Link Control Register */
2980 +#define PCIE_PLCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x710)
2981 +#define PCIE_PLCR_OTHER_MSG_REQ 0x00000001 /* Other Message Request */
2982 +#define PCIE_PLCR_SCRAMBLE_DISABLE 0x00000002 /* Scramble Disable */
2983 +#define PCIE_PLCR_LOOPBACK_EN 0x00000004 /* Loopback Enable */
2984 +#define PCIE_PLCR_LTSSM_HOT_RST 0x00000008 /* Force LTSSM to the hot reset */
2985 +#define PCIE_PLCR_DLL_LINK_EN 0x00000020 /* Enable Link initialization */
2986 +#define PCIE_PLCR_FAST_LINK_SIM_EN 0x00000080 /* Sets all internal timers to fast mode for simulation purposes */
2987 +#define PCIE_PLCR_LINK_MODE 0x003F0000 /* Link Mode Enable Mask */
2988 +#define PCIE_PLCR_LINK_MODE_S 16
2989 +#define PCIE_PLCR_CORRUPTED_CRC_EN 0x02000000 /* Enabled Corrupt CRC */
2991 +/* Lane Skew Register */
2992 +#define PCIE_LSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x714)
2993 +#define PCIE_LSR_LANE_SKEW_NUM 0x00FFFFFF /* Insert Lane Skew for Transmit, not applicable */
2994 +#define PCIE_LSR_LANE_SKEW_NUM_S 0
2995 +#define PCIE_LSR_FC_DISABLE 0x01000000 /* Disable of Flow Control */
2996 +#define PCIE_LSR_ACKNAK_DISABLE 0x02000000 /* Disable of Ack/Nak */
2997 +#define PCIE_LSR_LANE_DESKEW_DISABLE 0x80000000 /* Disable of Lane-to-Lane Skew */
2999 +/* Symbol Number Register */
3000 +#define PCIE_SNR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x718)
3001 +#define PCIE_SNR_TS 0x0000000F /* Number of TS Symbol */
3002 +#define PCIE_SNR_TS_S 0
3003 +#define PCIE_SNR_SKP 0x00000700 /* Number of SKP Symbol */
3004 +#define PCIE_SNR_SKP_S 8
3005 +#define PCIE_SNR_REPLAY_TIMER 0x0007C000 /* Timer Modifier for Replay Timer */
3006 +#define PCIE_SNR_REPLAY_TIMER_S 14
3007 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER 0x00F80000 /* Timer Modifier for Ack/Nak Latency Timer */
3008 +#define PCIE_SNR_ACKNAK_LATENCY_TIMER_S 19
3009 +#define PCIE_SNR_FC_TIMER 0x1F000000 /* Timer Modifier for Flow Control Watchdog Timer */
3010 +#define PCIE_SNR_FC_TIMER_S 28
3012 +/* Symbol Timer Register and Filter Mask Register 1 */
3013 +#define PCIE_STRFMR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x71C)
3014 +#define PCIE_STRFMR_SKP_INTERVAL 0x000007FF /* SKP lnterval Value */
3015 +#define PCIE_STRFMR_SKP_INTERVAL_S 0
3016 +#define PCIE_STRFMR_FC_WDT_DISABLE 0x00008000 /* Disable of FC Watchdog Timer */
3017 +#define PCIE_STRFMR_TLP_FUNC_MISMATCH_OK 0x00010000 /* Mask Function Mismatch Filtering for Incoming Requests */
3018 +#define PCIE_STRFMR_POISONED_TLP_OK 0x00020000 /* Mask Poisoned TLP Filtering */
3019 +#define PCIE_STRFMR_BAR_MATCH_OK 0x00040000 /* Mask BAR Match Filtering */
3020 +#define PCIE_STRFMR_TYPE1_CFG_REQ_OK 0x00080000 /* Mask Type 1 Configuration Request Filtering */
3021 +#define PCIE_STRFMR_LOCKED_REQ_OK 0x00100000 /* Mask Locked Request Filtering */
3022 +#define PCIE_STRFMR_CPL_TAG_ERR_RULES_OK 0x00200000 /* Mask Tag Error Rules for Received Completions */
3023 +#define PCIE_STRFMR_CPL_REQUESTOR_ID_MISMATCH_OK 0x00400000 /* Mask Requester ID Mismatch Error for Received Completions */
3024 +#define PCIE_STRFMR_CPL_FUNC_MISMATCH_OK 0x00800000 /* Mask Function Mismatch Error for Received Completions */
3025 +#define PCIE_STRFMR_CPL_TC_MISMATCH_OK 0x01000000 /* Mask Traffic Class Mismatch Error for Received Completions */
3026 +#define PCIE_STRFMR_CPL_ATTR_MISMATCH_OK 0x02000000 /* Mask Attribute Mismatch Error for Received Completions */
3027 +#define PCIE_STRFMR_CPL_LENGTH_MISMATCH_OK 0x04000000 /* Mask Length Mismatch Error for Received Completions */
3028 +#define PCIE_STRFMR_TLP_ECRC_ERR_OK 0x08000000 /* Mask ECRC Error Filtering */
3029 +#define PCIE_STRFMR_CPL_TLP_ECRC_OK 0x10000000 /* Mask ECRC Error Filtering for Completions */
3030 +#define PCIE_STRFMR_RX_TLP_MSG_NO_DROP 0x20000000 /* Send Message TLPs */
3031 +#define PCIE_STRFMR_RX_IO_TRANS_ENABLE 0x40000000 /* Mask Filtering of received I/O Requests */
3032 +#define PCIE_STRFMR_RX_CFG_TRANS_ENABLE 0x80000000 /* Mask Filtering of Received Configuration Requests */
3034 +#define PCIE_DEF_SKP_INTERVAL 700 /* 1180 ~1538 , 125MHz * 2, 250MHz * 1 */
3036 +/* Filter Masker Register 2 */
3037 +#define PCIE_FMR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x720)
3038 +#define PCIE_FMR2_VENDOR_MSG0_PASSED_TO_TRGT1 0x00000001 /* Mask RADM Filtering and Error Handling Rules */
3039 +#define PCIE_FMR2_VENDOR_MSG1_PASSED_TO_TRGT1 0x00000002 /* Mask RADM Filtering and Error Handling Rules */
3041 +/* Debug Register 0 */
3042 +#define PCIE_DBR0(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x728)
3044 +/* Debug Register 1 */
3045 +#define PCIE_DBR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x72C)
3047 +/* Transmit Posted FC Credit Status Register */
3048 +#define PCIE_TPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x730)
3049 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS 0x00000FFF /* Transmit Posted Data FC Credits */
3050 +#define PCIE_TPFCS_TX_P_DATA_FC_CREDITS_S 0
3051 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS 0x000FF000 /* Transmit Posted Header FC Credits */
3052 +#define PCIE_TPFCS_TX_P_HDR_FC_CREDITS_S 12
3054 +/* Transmit Non-Posted FC Credit Status */
3055 +#define PCIE_TNPFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x734)
3056 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS 0x00000FFF /* Transmit Non-Posted Data FC Credits */
3057 +#define PCIE_TNPFCS_TX_NP_DATA_FC_CREDITS_S 0
3058 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS 0x000FF000 /* Transmit Non-Posted Header FC Credits */
3059 +#define PCIE_TNPFCS_TX_NP_HDR_FC_CREDITS_S 12
3061 +/* Transmit Complete FC Credit Status Register */
3062 +#define PCIE_TCFCS(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x738)
3063 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS 0x00000FFF /* Transmit Completion Data FC Credits */
3064 +#define PCIE_TCFCS_TX_CPL_DATA_FC_CREDITS_S 0
3065 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS 0x000FF000 /* Transmit Completion Header FC Credits */
3066 +#define PCIE_TCFCS_TX_CPL_HDR_FC_CREDITS_S 12
3068 +/* Queue Status Register */
3069 +#define PCIE_QSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x73C)
3070 +#define PCIE_QSR_WAIT_UPDATE_FC_DLL 0x00000001 /* Received TLP FC Credits Not Returned */
3071 +#define PCIE_QSR_TX_RETRY_BUF_NOT_EMPTY 0x00000002 /* Transmit Retry Buffer Not Empty */
3072 +#define PCIE_QSR_RX_QUEUE_NOT_EMPTY 0x00000004 /* Received Queue Not Empty */
3074 +/* VC Transmit Arbitration Register 1 */
3075 +#define PCIE_VCTAR1(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x740)
3076 +#define PCIE_VCTAR1_WRR_WEIGHT_VC0 0x000000FF /* WRR Weight for VC0 */
3077 +#define PCIE_VCTAR1_WRR_WEIGHT_VC1 0x0000FF00 /* WRR Weight for VC1 */
3078 +#define PCIE_VCTAR1_WRR_WEIGHT_VC2 0x00FF0000 /* WRR Weight for VC2 */
3079 +#define PCIE_VCTAR1_WRR_WEIGHT_VC3 0xFF000000 /* WRR Weight for VC3 */
3081 +/* VC Transmit Arbitration Register 2 */
3082 +#define PCIE_VCTAR2(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x744)
3083 +#define PCIE_VCTAR2_WRR_WEIGHT_VC4 0x000000FF /* WRR Weight for VC4 */
3084 +#define PCIE_VCTAR2_WRR_WEIGHT_VC5 0x0000FF00 /* WRR Weight for VC5 */
3085 +#define PCIE_VCTAR2_WRR_WEIGHT_VC6 0x00FF0000 /* WRR Weight for VC6 */
3086 +#define PCIE_VCTAR2_WRR_WEIGHT_VC7 0xFF000000 /* WRR Weight for VC7 */
3088 +/* VC0 Posted Receive Queue Control Register */
3089 +#define PCIE_VC0_PRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x748)
3090 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS 0x00000FFF /* VC0 Posted Data Credits */
3091 +#define PCIE_VC0_PRQCR_P_DATA_CREDITS_S 0
3092 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS 0x000FF000 /* VC0 Posted Header Credits */
3093 +#define PCIE_VC0_PRQCR_P_HDR_CREDITS_S 12
3094 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE 0x00E00000 /* VC0 Posted TLP Queue Mode */
3095 +#define PCIE_VC0_PRQCR_P_TLP_QUEUE_MODE_S 20
3096 +#define PCIE_VC0_PRQCR_TLP_RELAX_ORDER 0x40000000 /* TLP Type Ordering for VC0 */
3097 +#define PCIE_VC0_PRQCR_VC_STRICT_ORDER 0x80000000 /* VC0 Ordering for Receive Queues */
3099 +/* VC0 Non-Posted Receive Queue Control */
3100 +#define PCIE_VC0_NPRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x74C)
3101 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS 0x00000FFF /* VC0 Non-Posted Data Credits */
3102 +#define PCIE_VC0_NPRQCR_NP_DATA_CREDITS_S 0
3103 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS 0x000FF000 /* VC0 Non-Posted Header Credits */
3104 +#define PCIE_VC0_NPRQCR_NP_HDR_CREDITS_S 12
3105 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE 0x00E00000 /* VC0 Non-Posted TLP Queue Mode */
3106 +#define PCIE_VC0_NPRQCR_NP_TLP_QUEUE_MODE_S 20
3108 +/* VC0 Completion Receive Queue Control */
3109 +#define PCIE_VC0_CRQCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x750)
3110 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS 0x00000FFF /* VC0 Completion TLP Queue Mode */
3111 +#define PCIE_VC0_CRQCR_CPL_DATA_CREDITS_S 0
3112 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS 0x000FF000 /* VC0 Completion Header Credits */
3113 +#define PCIE_VC0_CRQCR_CPL_HDR_CREDITS_S 12
3114 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE 0x00E00000 /* VC0 Completion Data Credits */
3115 +#define PCIE_VC0_CRQCR_CPL_TLP_QUEUE_MODE_S 21
3117 +/* Applicable to the above three registers */
3119 + PCIE_VC0_TLP_QUEUE_MODE_STORE_FORWARD = 1,
3120 + PCIE_VC0_TLP_QUEUE_MODE_CUT_THROUGH = 2,
3121 + PCIE_VC0_TLP_QUEUE_MODE_BYPASS = 4,
3124 +/* VC0 Posted Buffer Depth Register */
3125 +#define PCIE_VC0_PBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7A8)
3126 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Posted Data Queue Depth */
3127 +#define PCIE_VC0_PBD_P_DATA_QUEUE_ENTRIES_S 0
3128 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Posted Header Queue Depth */
3129 +#define PCIE_VC0_PBD_P_HDR_QUEUE_ENTRIES_S 16
3131 +/* VC0 Non-Posted Buffer Depth Register */
3132 +#define PCIE_VC0_NPBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7AC)
3133 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES 0x00003FFF /* VC0 Non-Posted Data Queue Depth */
3134 +#define PCIE_VC0_NPBD_NP_DATA_QUEUE_ENTRIES_S 0
3135 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Non-Posted Header Queue Depth */
3136 +#define PCIE_VC0_NPBD_NP_HDR_QUEUE_ENTRIES_S 16
3138 +/* VC0 Completion Buffer Depth Register */
3139 +#define PCIE_VC0_CBD(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x7B0)
3140 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES 0x00003FFF /* C0 Completion Data Queue Depth */
3141 +#define PCIE_VC0_CBD_CPL_DATA_QUEUE_ENTRIES_S 0
3142 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES 0x03FF0000 /* VC0 Completion Header Queue Depth */
3143 +#define PCIE_VC0_CBD_CPL_HDR_QUEUE_ENTRIES_S 16
3145 +/* PHY Status Register, all zeros in VR9 */
3146 +#define PCIE_PHYSR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x810)
3148 +/* PHY Control Register, all zeros in VR9 */
3149 +#define PCIE_PHYCR(X) (volatile u32*)(PCIE_RC_PORT_TO_BASE(X) + 0x814)
3152 + * PCIe PDI PHY register definition, suppose all the following
3153 + * stuff is confidential.
3154 + * XXX, detailed bit definition
3156 +#define PCIE_PHY_PLL_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x22 << 1))
3157 +#define PCIE_PHY_PLL_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x23 << 1))
3158 +#define PCIE_PHY_PLL_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x24 << 1))
3159 +#define PCIE_PHY_PLL_CTRL4(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x25 << 1))
3160 +#define PCIE_PHY_PLL_CTRL5(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x26 << 1))
3161 +#define PCIE_PHY_PLL_CTRL6(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x27 << 1))
3162 +#define PCIE_PHY_PLL_CTRL7(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x28 << 1))
3163 +#define PCIE_PHY_PLL_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x29 << 1))
3164 +#define PCIE_PHY_PLL_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2A << 1))
3165 +#define PCIE_PHY_PLL_A_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2B << 1))
3166 +#define PCIE_PHY_PLL_STATUS(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x2C << 1))
3168 +#define PCIE_PHY_TX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x30 << 1))
3169 +#define PCIE_PHY_TX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x31 << 1))
3170 +#define PCIE_PHY_TX1_CTRL3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x32 << 1))
3171 +#define PCIE_PHY_TX1_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x33 << 1))
3172 +#define PCIE_PHY_TX1_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x34 << 1))
3173 +#define PCIE_PHY_TX1_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x35 << 1))
3174 +#define PCIE_PHY_TX1_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x36 << 1))
3175 +#define PCIE_PHY_TX1_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x37 << 1))
3177 +#define PCIE_PHY_TX2_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x38 << 1))
3178 +#define PCIE_PHY_TX2_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x39 << 1))
3179 +#define PCIE_PHY_TX2_A_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3B << 1))
3180 +#define PCIE_PHY_TX2_A_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3C << 1))
3181 +#define PCIE_PHY_TX2_MOD1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3D << 1))
3182 +#define PCIE_PHY_TX2_MOD2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3E << 1))
3183 +#define PCIE_PHY_TX2_MOD3(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x3F << 1))
3185 +#define PCIE_PHY_RX1_CTRL1(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x50 << 1))
3186 +#define PCIE_PHY_RX1_CTRL2(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x51 << 1))
3187 +#define PCIE_PHY_RX1_CDR(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x52 << 1))
3188 +#define PCIE_PHY_RX1_EI(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x53 << 1))
3189 +#define PCIE_PHY_RX1_A_CTRL(X) (PCIE_PHY_PORT_TO_BASE(X) + (0x55 << 1))
3191 +/* Interrupt related stuff */
3192 +#define PCIE_LEGACY_DISABLE 0
3193 +#define PCIE_LEGACY_INTA 1
3194 +#define PCIE_LEGACY_INTB 2
3195 +#define PCIE_LEGACY_INTC 3
3196 +#define PCIE_LEGACY_INTD 4
3197 +#define PCIE_LEGACY_INT_MAX PCIE_LEGACY_INTD
3199 +#define PCIE_IRQ_LOCK(lock) do { \
3200 + unsigned long flags; \
3201 + spin_lock_irqsave(&(lock), flags);
3202 +#define PCIE_IRQ_UNLOCK(lock) \
3203 + spin_unlock_irqrestore(&(lock), flags); \
3206 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
3207 +#define IRQF_SHARED SA_SHIRQ
3210 +#define PCIE_MSG_MSI 0x00000001
3211 +#define PCIE_MSG_ISR 0x00000002
3212 +#define PCIE_MSG_FIXUP 0x00000004
3213 +#define PCIE_MSG_READ_CFG 0x00000008
3214 +#define PCIE_MSG_WRITE_CFG 0x00000010
3215 +#define PCIE_MSG_CFG (PCIE_MSG_READ_CFG | PCIE_MSG_WRITE_CFG)
3216 +#define PCIE_MSG_REG 0x00000020
3217 +#define PCIE_MSG_INIT 0x00000040
3218 +#define PCIE_MSG_ERR 0x00000080
3219 +#define PCIE_MSG_PHY 0x00000100
3220 +#define PCIE_MSG_ANY 0x000001ff
3222 +#define IFX_PCIE_PORT0 0
3223 +#define IFX_PCIE_PORT1 1
3225 +#ifdef CONFIG_IFX_PCIE_2ND_CORE
3226 +#define IFX_PCIE_CORE_NR 2
3228 +#define IFX_PCIE_CORE_NR 1
3231 +//#define IFX_PCIE_ERROR_INT
3233 +//#define IFX_PCIE_DBG
3235 +#if defined(IFX_PCIE_DBG)
3236 +#define IFX_PCIE_PRINT(_m, _fmt, args...) do { \
3237 + if (g_pcie_debug_flag & (_m)) { \
3238 + ifx_pcie_debug((_fmt), ##args); \
3244 +#define IFX_PCIE_PRINT(_m, _fmt, args...) \
3246 +#define INLINE inline
3249 +struct ifx_pci_controller {
3250 + struct pci_controller pcic;
3252 + /* RC specific, per host bus information */
3253 + u32 port; /* Port index, 0 -- 1st core, 1 -- 2nd core */
3256 +typedef struct ifx_pcie_ir_irq {
3257 + const unsigned int irq;
3258 + const char name[16];
3259 +}ifx_pcie_ir_irq_t;
3261 +typedef struct ifx_pcie_legacy_irq{
3262 + const u32 irq_bit;
3264 +}ifx_pcie_legacy_irq_t;
3266 +typedef struct ifx_pcie_irq {
3267 + ifx_pcie_ir_irq_t ir_irq;
3268 + ifx_pcie_legacy_irq_t legacy_irq[PCIE_LEGACY_INT_MAX];
3271 +extern u32 g_pcie_debug_flag;
3272 +extern void ifx_pcie_debug(const char *fmt, ...);
3273 +extern void pcie_phy_clock_mode_setup(int pcie_port);
3274 +extern void pcie_msi_pic_init(int pcie_port);
3275 +extern u32 ifx_pcie_bus_enum_read_hack(int where, u32 value);
3276 +extern u32 ifx_pcie_bus_enum_write_hack(int where, u32 value);
3279 +#include <linux/types.h>
3280 +#include <linux/delay.h>
3281 +#include <linux/gpio.h>
3282 +#include <linux/clk.h>
3284 +#include <lantiq_soc.h>
3286 +#define IFX_PCIE_GPIO_RESET 38
3287 +#define IFX_REG_R32 ltq_r32
3288 +#define IFX_REG_W32 ltq_w32
3289 +#define CONFIG_IFX_PCIE_HW_SWAP
3290 +#define IFX_RCU_AHB_ENDIAN ((volatile u32*)(IFX_RCU + 0x004C))
3291 +#define IFX_RCU_RST_REQ ((volatile u32*)(IFX_RCU + 0x0010))
3292 +#define IFX_RCU_AHB_BE_PCIE_PDI 0x00000080 /* Configure PCIE PDI module in big endian*/
3294 +#define IFX_RCU (KSEG1 | 0x1F203000)
3295 +#define IFX_RCU_AHB_BE_PCIE_M 0x00000001 /* Configure AHB master port that connects to PCIe RC in big endian */
3296 +#define IFX_RCU_AHB_BE_PCIE_S 0x00000010 /* Configure AHB slave port that connects to PCIe RC in little endian */
3297 +#define IFX_RCU_AHB_BE_XBAR_M 0x00000002 /* Configure AHB master port that connects to XBAR in big endian */
3298 +#define CONFIG_IFX_PCIE_PHY_36MHZ_MODE
3300 +#define IFX_PMU1_MODULE_PCIE_PHY (0)
3301 +#define IFX_PMU1_MODULE_PCIE_CTRL (1)
3302 +#define IFX_PMU1_MODULE_PDI (4)
3303 +#define IFX_PMU1_MODULE_MSI (5)
3305 +#define IFX_PMU_MODULE_PCIE_L0_CLK (31)
3308 +static inline void pcie_ep_gpio_rst_init(int pcie_port)
3312 +static inline void pcie_ahb_pmu_setup(void)
3315 + clk = clk_get_sys("ltq_pcie", "ahb");
3317 + //ltq_pmu_enable(PMU_AHBM | PMU_AHBS);
3320 +static inline void pcie_rcu_endian_setup(int pcie_port)
3324 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3325 +#ifdef CONFIG_IFX_PCIE_HW_SWAP
3326 + reg |= IFX_RCU_AHB_BE_PCIE_M;
3327 + reg |= IFX_RCU_AHB_BE_PCIE_S;
3328 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3330 + reg |= IFX_RCU_AHB_BE_PCIE_M;
3331 + reg &= ~IFX_RCU_AHB_BE_PCIE_S;
3332 + reg &= ~IFX_RCU_AHB_BE_XBAR_M;
3333 +#endif /* CONFIG_IFX_PCIE_HW_SWAP */
3334 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3335 + IFX_PCIE_PRINT(PCIE_MSG_REG, "%s IFX_RCU_AHB_ENDIAN: 0x%08x\n", __func__, IFX_REG_R32(IFX_RCU_AHB_ENDIAN));
3338 +static inline void pcie_phy_pmu_enable(int pcie_port)
3341 + clk = clk_get_sys("ltq_pcie", "phy");
3343 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PCIE_PHY);
3346 +static inline void pcie_phy_pmu_disable(int pcie_port)
3349 + clk = clk_get_sys("ltq_pcie", "phy");
3351 + //ltq_pmu1_disable(1<<IFX_PMU1_MODULE_PCIE_PHY);
3354 +static inline void pcie_pdi_big_endian(int pcie_port)
3358 + /* SRAM2PDI endianness control. */
3359 + reg = IFX_REG_R32(IFX_RCU_AHB_ENDIAN);
3360 + /* Config AHB->PCIe and PDI endianness */
3361 + reg |= IFX_RCU_AHB_BE_PCIE_PDI;
3362 + IFX_REG_W32(reg, IFX_RCU_AHB_ENDIAN);
3365 +static inline void pcie_pdi_pmu_enable(int pcie_port)
3368 + clk = clk_get_sys("ltq_pcie", "pdi");
3370 + //ltq_pmu1_enable(1<<IFX_PMU1_MODULE_PDI);
3373 +static inline void pcie_core_rst_assert(int pcie_port)
3377 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3379 + /* Reset PCIe PHY & Core, bit 22, bit 26 may be affected if write it directly */
3380 + reg |= 0x00400000;
3381 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3384 +static inline void pcie_core_rst_deassert(int pcie_port)
3388 + /* Make sure one micro-second delay */
3391 + /* Reset PCIe PHY & Core, bit 22 */
3392 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3393 + reg &= ~0x00400000;
3394 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3397 +static inline void pcie_phy_rst_assert(int pcie_port)
3401 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3402 + reg |= 0x00001000; /* Bit 12 */
3403 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3406 +static inline void pcie_phy_rst_deassert(int pcie_port)
3410 + /* Make sure one micro-second delay */
3413 + reg = IFX_REG_R32(IFX_RCU_RST_REQ);
3414 + reg &= ~0x00001000; /* Bit 12 */
3415 + IFX_REG_W32(reg, IFX_RCU_RST_REQ);
3418 +static inline void pcie_device_rst_assert(int pcie_port)
3420 + gpio_set_value(IFX_PCIE_GPIO_RESET, 0);
3421 + // ifx_gpio_output_clear(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3424 +static inline void pcie_device_rst_deassert(int pcie_port)
3427 + gpio_set_value(IFX_PCIE_GPIO_RESET, 1);
3428 +// ifx_gpio_output_set(IFX_PCIE_GPIO_RESET, ifx_pcie_gpio_module_id);
3431 +static inline void pcie_core_pmu_setup(int pcie_port)
3434 + clk = clk_get_sys("ltq_pcie", "ctl");
3436 + clk = clk_get_sys("ltq_pcie", "bus");
3439 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_PCIE_CTRL);
3440 + //ltq_pmu_enable(1 << IFX_PMU_MODULE_PCIE_L0_CLK);
3443 +static inline void pcie_msi_init(int pcie_port)
3446 + pcie_msi_pic_init(pcie_port);
3447 + clk = clk_get_sys("ltq_pcie", "msi");
3449 + //ltq_pmu1_enable(1 << IFX_PMU1_MODULE_MSI);
3453 +ifx_pcie_bus_nr_deduct(u32 bus_number, int pcie_port)
3455 + u32 tbus_number = bus_number;
3457 +#ifdef CONFIG_IFX_PCI
3458 + if (pcibios_host_nr() > 1) {
3459 + tbus_number -= pcibios_1st_host_bus_nr();
3461 +#endif /* CONFIG_IFX_PCI */
3462 + return tbus_number;
3466 +ifx_pcie_bus_enum_hack(struct pci_bus *bus, u32 devfn, int where, u32 value, int pcie_port, int read)
3468 + struct pci_dev *pdev;
3469 + u32 tvalue = value;
3471 + /* Sanity check */
3472 + pdev = pci_get_slot(bus, devfn);
3473 + if (pdev == NULL) {
3477 + /* Only care about PCI bridge */
3478 + if (pdev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
3482 + if (read) { /* Read hack */
3483 + #ifdef CONFIG_IFX_PCI
3484 + if (pcibios_host_nr() > 1) {
3485 + tvalue = ifx_pcie_bus_enum_read_hack(where, tvalue);
3487 + #endif /* CONFIG_IFX_PCI */
3489 + else { /* Write hack */
3490 + #ifdef CONFIG_IFX_PCI
3491 + if (pcibios_host_nr() > 1) {
3492 + tvalue = ifx_pcie_bus_enum_write_hack(where, tvalue);
3499 +#endif /* IFXMIPS_PCIE_VR9_H */