1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright Altera Corporation (C) 2013-2015. All rights reserved
5 * Author: Ley Foon Tan <lftan@altera.com>
6 * Description: Altera PCIe host controller driver
9 #include <linux/delay.h>
10 #include <linux/interrupt.h>
11 #include <linux/irqchip/chained_irq.h>
12 #include <linux/init.h>
13 #include <linux/of_address.h>
14 #include <linux/of_device.h>
15 #include <linux/of_irq.h>
16 #include <linux/of_pci.h>
17 #include <linux/pci.h>
18 #include <linux/platform_device.h>
19 #include <linux/slab.h>
23 #define RP_TX_REG0 0x2000
24 #define RP_TX_REG1 0x2004
25 #define RP_TX_CNTRL 0x2008
28 #define RP_RXCPL_STATUS 0x2010
29 #define RP_RXCPL_EOP 0x2
30 #define RP_RXCPL_SOP 0x1
31 #define RP_RXCPL_REG0 0x2014
32 #define RP_RXCPL_REG1 0x2018
33 #define P2A_INT_STATUS 0x3060
34 #define P2A_INT_STS_ALL 0xf
35 #define P2A_INT_ENABLE 0x3070
36 #define P2A_INT_ENA_ALL 0xf
37 #define RP_LTSSM 0x3c64
38 #define RP_LTSSM_MASK 0x1f
41 #define S10_RP_TX_CNTRL 0x2004
42 #define S10_RP_RXCPL_REG 0x2008
43 #define S10_RP_RXCPL_STATUS 0x200C
44 #define S10_RP_CFG_ADDR(pcie, reg) \
45 (((pcie)->hip_base) + (reg) + (1 << 20))
47 /* TLP configuration type 0 and 1 */
48 #define TLP_FMTTYPE_CFGRD0 0x04 /* Configuration Read Type 0 */
49 #define TLP_FMTTYPE_CFGWR0 0x44 /* Configuration Write Type 0 */
50 #define TLP_FMTTYPE_CFGRD1 0x05 /* Configuration Read Type 1 */
51 #define TLP_FMTTYPE_CFGWR1 0x45 /* Configuration Write Type 1 */
52 #define TLP_PAYLOAD_SIZE 0x01
53 #define TLP_READ_TAG 0x1d
54 #define TLP_WRITE_TAG 0x10
56 #define TLP_REQ_ID(bus, devfn) (((bus) << 8) | (devfn))
57 #define TLP_CFGRD_DW0(pcie, bus) \
58 ((((bus == pcie->root_bus_nr) ? pcie->pcie_data->cfgrd0 \
59 : pcie->pcie_data->cfgrd1) << 24) | \
61 #define TLP_CFGWR_DW0(pcie, bus) \
62 ((((bus == pcie->root_bus_nr) ? pcie->pcie_data->cfgwr0 \
63 : pcie->pcie_data->cfgwr1) << 24) | \
65 #define TLP_CFG_DW1(pcie, tag, be) \
66 (((TLP_REQ_ID(pcie->root_bus_nr, RP_DEVFN)) << 16) | (tag << 8) | (be))
67 #define TLP_CFG_DW2(bus, devfn, offset) \
68 (((bus) << 24) | ((devfn) << 16) | (offset))
69 #define TLP_COMP_STATUS(s) (((s) >> 13) & 7)
70 #define TLP_BYTE_COUNT(s) (((s) >> 0) & 0xfff)
71 #define TLP_HDR_SIZE 3
74 #define LINK_UP_TIMEOUT HZ
75 #define LINK_RETRAIN_TIMEOUT HZ
79 #define S10_TLP_FMTTYPE_CFGRD0 0x05
80 #define S10_TLP_FMTTYPE_CFGRD1 0x04
81 #define S10_TLP_FMTTYPE_CFGWR0 0x45
82 #define S10_TLP_FMTTYPE_CFGWR1 0x44
84 enum altera_pcie_version {
90 struct platform_device *pdev;
91 void __iomem *cra_base;
92 void __iomem *hip_base;
95 struct irq_domain *irq_domain;
96 struct resource bus_range;
97 struct list_head resources;
98 const struct altera_pcie_data *pcie_data;
101 struct altera_pcie_ops {
102 int (*tlp_read_pkt)(struct altera_pcie *pcie, u32 *value);
103 void (*tlp_write_pkt)(struct altera_pcie *pcie, u32 *headers,
104 u32 data, bool align);
105 bool (*get_link_status)(struct altera_pcie *pcie);
106 int (*rp_read_cfg)(struct altera_pcie *pcie, int where,
107 int size, u32 *value);
108 int (*rp_write_cfg)(struct altera_pcie *pcie, u8 busno,
109 int where, int size, u32 value);
112 struct altera_pcie_data {
113 const struct altera_pcie_ops *ops;
114 enum altera_pcie_version version;
115 u32 cap_offset; /* PCIe capability structure register offset */
122 struct tlp_rp_regpair_t {
128 static inline void cra_writel(struct altera_pcie *pcie, const u32 value,
131 writel_relaxed(value, pcie->cra_base + reg);
134 static inline u32 cra_readl(struct altera_pcie *pcie, const u32 reg)
136 return readl_relaxed(pcie->cra_base + reg);
139 static bool altera_pcie_link_up(struct altera_pcie *pcie)
141 return !!((cra_readl(pcie, RP_LTSSM) & RP_LTSSM_MASK) == LTSSM_L0);
144 static bool s10_altera_pcie_link_up(struct altera_pcie *pcie)
146 void __iomem *addr = S10_RP_CFG_ADDR(pcie,
147 pcie->pcie_data->cap_offset +
150 return !!(readw(addr) & PCI_EXP_LNKSTA_DLLLA);
154 * Altera PCIe port uses BAR0 of RC's configuration space as the translation
155 * from PCI bus to native BUS. Entire DDR region is mapped into PCIe space
156 * using these registers, so it can be reached by DMA from EP devices.
157 * This BAR0 will also access to MSI vector when receiving MSI/MSIX interrupt
158 * from EP devices, eventually trigger interrupt to GIC. The BAR0 of bridge
159 * should be hidden during enumeration to avoid the sizing and resource
160 * allocation by PCIe core.
162 static bool altera_pcie_hide_rc_bar(struct pci_bus *bus, unsigned int devfn,
165 if (pci_is_root_bus(bus) && (devfn == 0) &&
166 (offset == PCI_BASE_ADDRESS_0))
172 static void tlp_write_tx(struct altera_pcie *pcie,
173 struct tlp_rp_regpair_t *tlp_rp_regdata)
175 cra_writel(pcie, tlp_rp_regdata->reg0, RP_TX_REG0);
176 cra_writel(pcie, tlp_rp_regdata->reg1, RP_TX_REG1);
177 cra_writel(pcie, tlp_rp_regdata->ctrl, RP_TX_CNTRL);
180 static void s10_tlp_write_tx(struct altera_pcie *pcie, u32 reg0, u32 ctrl)
182 cra_writel(pcie, reg0, RP_TX_REG0);
183 cra_writel(pcie, ctrl, S10_RP_TX_CNTRL);
186 static bool altera_pcie_valid_device(struct altera_pcie *pcie,
187 struct pci_bus *bus, int dev)
189 /* If there is no link, then there is no device */
190 if (bus->number != pcie->root_bus_nr) {
191 if (!pcie->pcie_data->ops->get_link_status(pcie))
195 /* access only one slot on each root port */
196 if (bus->number == pcie->root_bus_nr && dev > 0)
202 static int tlp_read_packet(struct altera_pcie *pcie, u32 *value)
211 * Minimum 2 loops to read TLP headers and 1 loop to read data
214 for (i = 0; i < TLP_LOOP; i++) {
215 ctrl = cra_readl(pcie, RP_RXCPL_STATUS);
216 if ((ctrl & RP_RXCPL_SOP) || (ctrl & RP_RXCPL_EOP) || sop) {
217 reg0 = cra_readl(pcie, RP_RXCPL_REG0);
218 reg1 = cra_readl(pcie, RP_RXCPL_REG1);
220 if (ctrl & RP_RXCPL_SOP) {
222 comp_status = TLP_COMP_STATUS(reg1);
225 if (ctrl & RP_RXCPL_EOP) {
227 return PCIBIOS_DEVICE_NOT_FOUND;
232 return PCIBIOS_SUCCESSFUL;
238 return PCIBIOS_DEVICE_NOT_FOUND;
241 static int s10_tlp_read_packet(struct altera_pcie *pcie, u32 *value)
247 struct device *dev = &pcie->pdev->dev;
249 for (count = 0; count < TLP_LOOP; count++) {
250 ctrl = cra_readl(pcie, S10_RP_RXCPL_STATUS);
251 if (ctrl & RP_RXCPL_SOP) {
253 dw[0] = cra_readl(pcie, S10_RP_RXCPL_REG);
260 /* SOP detection failed, return error */
261 if (count == TLP_LOOP)
262 return PCIBIOS_DEVICE_NOT_FOUND;
267 while (count < ARRAY_SIZE(dw)) {
268 ctrl = cra_readl(pcie, S10_RP_RXCPL_STATUS);
269 dw[count++] = cra_readl(pcie, S10_RP_RXCPL_REG);
270 if (ctrl & RP_RXCPL_EOP) {
271 comp_status = TLP_COMP_STATUS(dw[1]);
273 return PCIBIOS_DEVICE_NOT_FOUND;
275 if (value && TLP_BYTE_COUNT(dw[1]) == sizeof(u32) &&
279 return PCIBIOS_SUCCESSFUL;
283 dev_warn(dev, "Malformed TLP packet\n");
285 return PCIBIOS_DEVICE_NOT_FOUND;
288 static void tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
289 u32 data, bool align)
291 struct tlp_rp_regpair_t tlp_rp_regdata;
293 tlp_rp_regdata.reg0 = headers[0];
294 tlp_rp_regdata.reg1 = headers[1];
295 tlp_rp_regdata.ctrl = RP_TX_SOP;
296 tlp_write_tx(pcie, &tlp_rp_regdata);
299 tlp_rp_regdata.reg0 = headers[2];
300 tlp_rp_regdata.reg1 = 0;
301 tlp_rp_regdata.ctrl = 0;
302 tlp_write_tx(pcie, &tlp_rp_regdata);
304 tlp_rp_regdata.reg0 = data;
305 tlp_rp_regdata.reg1 = 0;
307 tlp_rp_regdata.reg0 = headers[2];
308 tlp_rp_regdata.reg1 = data;
311 tlp_rp_regdata.ctrl = RP_TX_EOP;
312 tlp_write_tx(pcie, &tlp_rp_regdata);
315 static void s10_tlp_write_packet(struct altera_pcie *pcie, u32 *headers,
316 u32 data, bool dummy)
318 s10_tlp_write_tx(pcie, headers[0], RP_TX_SOP);
319 s10_tlp_write_tx(pcie, headers[1], 0);
320 s10_tlp_write_tx(pcie, headers[2], 0);
321 s10_tlp_write_tx(pcie, data, RP_TX_EOP);
324 static int tlp_cfg_dword_read(struct altera_pcie *pcie, u8 bus, u32 devfn,
325 int where, u8 byte_en, u32 *value)
327 u32 headers[TLP_HDR_SIZE];
329 headers[0] = TLP_CFGRD_DW0(pcie, bus);
330 headers[1] = TLP_CFG_DW1(pcie, TLP_READ_TAG, byte_en);
331 headers[2] = TLP_CFG_DW2(bus, devfn, where);
333 pcie->pcie_data->ops->tlp_write_pkt(pcie, headers, 0, false);
335 return pcie->pcie_data->ops->tlp_read_pkt(pcie, value);
338 static int tlp_cfg_dword_write(struct altera_pcie *pcie, u8 bus, u32 devfn,
339 int where, u8 byte_en, u32 value)
341 u32 headers[TLP_HDR_SIZE];
344 headers[0] = TLP_CFGWR_DW0(pcie, bus);
345 headers[1] = TLP_CFG_DW1(pcie, TLP_WRITE_TAG, byte_en);
346 headers[2] = TLP_CFG_DW2(bus, devfn, where);
348 /* check alignment to Qword */
349 if ((where & 0x7) == 0)
350 pcie->pcie_data->ops->tlp_write_pkt(pcie, headers,
353 pcie->pcie_data->ops->tlp_write_pkt(pcie, headers,
356 ret = pcie->pcie_data->ops->tlp_read_pkt(pcie, NULL);
357 if (ret != PCIBIOS_SUCCESSFUL)
361 * Monitor changes to PCI_PRIMARY_BUS register on root port
362 * and update local copy of root bus number accordingly.
364 if ((bus == pcie->root_bus_nr) && (where == PCI_PRIMARY_BUS))
365 pcie->root_bus_nr = (u8)(value);
367 return PCIBIOS_SUCCESSFUL;
370 static int s10_rp_read_cfg(struct altera_pcie *pcie, int where,
371 int size, u32 *value)
373 void __iomem *addr = S10_RP_CFG_ADDR(pcie, where);
377 *value = readb(addr);
380 *value = readw(addr);
383 *value = readl(addr);
387 return PCIBIOS_SUCCESSFUL;
390 static int s10_rp_write_cfg(struct altera_pcie *pcie, u8 busno,
391 int where, int size, u32 value)
393 void __iomem *addr = S10_RP_CFG_ADDR(pcie, where);
408 * Monitor changes to PCI_PRIMARY_BUS register on root port
409 * and update local copy of root bus number accordingly.
411 if (busno == pcie->root_bus_nr && where == PCI_PRIMARY_BUS)
412 pcie->root_bus_nr = value & 0xff;
414 return PCIBIOS_SUCCESSFUL;
417 static int _altera_pcie_cfg_read(struct altera_pcie *pcie, u8 busno,
418 unsigned int devfn, int where, int size,
425 if (busno == pcie->root_bus_nr && pcie->pcie_data->ops->rp_read_cfg)
426 return pcie->pcie_data->ops->rp_read_cfg(pcie, where,
431 byte_en = 1 << (where & 3);
434 byte_en = 3 << (where & 3);
441 ret = tlp_cfg_dword_read(pcie, busno, devfn,
442 (where & ~DWORD_MASK), byte_en, &data);
443 if (ret != PCIBIOS_SUCCESSFUL)
448 *value = (data >> (8 * (where & 0x3))) & 0xff;
451 *value = (data >> (8 * (where & 0x2))) & 0xffff;
458 return PCIBIOS_SUCCESSFUL;
461 static int _altera_pcie_cfg_write(struct altera_pcie *pcie, u8 busno,
462 unsigned int devfn, int where, int size,
466 u32 shift = 8 * (where & 3);
469 if (busno == pcie->root_bus_nr && pcie->pcie_data->ops->rp_write_cfg)
470 return pcie->pcie_data->ops->rp_write_cfg(pcie, busno,
475 data32 = (value & 0xff) << shift;
476 byte_en = 1 << (where & 3);
479 data32 = (value & 0xffff) << shift;
480 byte_en = 3 << (where & 3);
488 return tlp_cfg_dword_write(pcie, busno, devfn, (where & ~DWORD_MASK),
492 static int altera_pcie_cfg_read(struct pci_bus *bus, unsigned int devfn,
493 int where, int size, u32 *value)
495 struct altera_pcie *pcie = bus->sysdata;
497 if (altera_pcie_hide_rc_bar(bus, devfn, where))
498 return PCIBIOS_BAD_REGISTER_NUMBER;
500 if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn))) {
502 return PCIBIOS_DEVICE_NOT_FOUND;
505 return _altera_pcie_cfg_read(pcie, bus->number, devfn, where, size,
509 static int altera_pcie_cfg_write(struct pci_bus *bus, unsigned int devfn,
510 int where, int size, u32 value)
512 struct altera_pcie *pcie = bus->sysdata;
514 if (altera_pcie_hide_rc_bar(bus, devfn, where))
515 return PCIBIOS_BAD_REGISTER_NUMBER;
517 if (!altera_pcie_valid_device(pcie, bus, PCI_SLOT(devfn)))
518 return PCIBIOS_DEVICE_NOT_FOUND;
520 return _altera_pcie_cfg_write(pcie, bus->number, devfn, where, size,
524 static struct pci_ops altera_pcie_ops = {
525 .read = altera_pcie_cfg_read,
526 .write = altera_pcie_cfg_write,
529 static int altera_read_cap_word(struct altera_pcie *pcie, u8 busno,
530 unsigned int devfn, int offset, u16 *value)
535 ret = _altera_pcie_cfg_read(pcie, busno, devfn,
536 pcie->pcie_data->cap_offset + offset,
543 static int altera_write_cap_word(struct altera_pcie *pcie, u8 busno,
544 unsigned int devfn, int offset, u16 value)
546 return _altera_pcie_cfg_write(pcie, busno, devfn,
547 pcie->pcie_data->cap_offset + offset,
552 static void altera_wait_link_retrain(struct altera_pcie *pcie)
554 struct device *dev = &pcie->pdev->dev;
556 unsigned long start_jiffies;
558 /* Wait for link training end. */
559 start_jiffies = jiffies;
561 altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
562 PCI_EXP_LNKSTA, ®16);
563 if (!(reg16 & PCI_EXP_LNKSTA_LT))
566 if (time_after(jiffies, start_jiffies + LINK_RETRAIN_TIMEOUT)) {
567 dev_err(dev, "link retrain timeout\n");
573 /* Wait for link is up */
574 start_jiffies = jiffies;
576 if (pcie->pcie_data->ops->get_link_status(pcie))
579 if (time_after(jiffies, start_jiffies + LINK_UP_TIMEOUT)) {
580 dev_err(dev, "link up timeout\n");
587 static void altera_pcie_retrain(struct altera_pcie *pcie)
589 u16 linkcap, linkstat, linkctl;
591 if (!pcie->pcie_data->ops->get_link_status(pcie))
595 * Set the retrain bit if the PCIe rootport support > 2.5GB/s, but
596 * current speed is 2.5 GB/s.
598 altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKCAP,
600 if ((linkcap & PCI_EXP_LNKCAP_SLS) <= PCI_EXP_LNKCAP_SLS_2_5GB)
603 altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN, PCI_EXP_LNKSTA,
605 if ((linkstat & PCI_EXP_LNKSTA_CLS) == PCI_EXP_LNKSTA_CLS_2_5GB) {
606 altera_read_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
607 PCI_EXP_LNKCTL, &linkctl);
608 linkctl |= PCI_EXP_LNKCTL_RL;
609 altera_write_cap_word(pcie, pcie->root_bus_nr, RP_DEVFN,
610 PCI_EXP_LNKCTL, linkctl);
612 altera_wait_link_retrain(pcie);
616 static int altera_pcie_intx_map(struct irq_domain *domain, unsigned int irq,
617 irq_hw_number_t hwirq)
619 irq_set_chip_and_handler(irq, &dummy_irq_chip, handle_simple_irq);
620 irq_set_chip_data(irq, domain->host_data);
624 static const struct irq_domain_ops intx_domain_ops = {
625 .map = altera_pcie_intx_map,
626 .xlate = pci_irqd_intx_xlate,
629 static void altera_pcie_isr(struct irq_desc *desc)
631 struct irq_chip *chip = irq_desc_get_chip(desc);
632 struct altera_pcie *pcie;
634 unsigned long status;
638 chained_irq_enter(chip, desc);
639 pcie = irq_desc_get_handler_data(desc);
640 dev = &pcie->pdev->dev;
642 while ((status = cra_readl(pcie, P2A_INT_STATUS)
643 & P2A_INT_STS_ALL) != 0) {
644 for_each_set_bit(bit, &status, PCI_NUM_INTX) {
645 /* clear interrupts */
646 cra_writel(pcie, 1 << bit, P2A_INT_STATUS);
648 virq = irq_find_mapping(pcie->irq_domain, bit);
650 generic_handle_irq(virq);
652 dev_err(dev, "unexpected IRQ, INT%d\n", bit);
656 chained_irq_exit(chip, desc);
659 static int altera_pcie_parse_request_of_pci_ranges(struct altera_pcie *pcie)
661 int err, res_valid = 0;
662 struct device *dev = &pcie->pdev->dev;
663 struct resource_entry *win;
665 err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff,
666 &pcie->resources, NULL);
670 err = devm_request_pci_bus_resources(dev, &pcie->resources);
672 goto out_release_res;
674 resource_list_for_each_entry(win, &pcie->resources) {
675 struct resource *res = win->res;
677 if (resource_type(res) == IORESOURCE_MEM)
678 res_valid |= !(res->flags & IORESOURCE_PREFETCH);
684 dev_err(dev, "non-prefetchable memory resource required\n");
688 pci_free_resource_list(&pcie->resources);
692 static int altera_pcie_init_irq_domain(struct altera_pcie *pcie)
694 struct device *dev = &pcie->pdev->dev;
695 struct device_node *node = dev->of_node;
698 pcie->irq_domain = irq_domain_add_linear(node, PCI_NUM_INTX,
699 &intx_domain_ops, pcie);
700 if (!pcie->irq_domain) {
701 dev_err(dev, "Failed to get a INTx IRQ domain\n");
708 static int altera_pcie_parse_dt(struct altera_pcie *pcie)
710 struct device *dev = &pcie->pdev->dev;
711 struct platform_device *pdev = pcie->pdev;
712 struct resource *cra;
713 struct resource *hip;
715 cra = platform_get_resource_byname(pdev, IORESOURCE_MEM, "Cra");
716 pcie->cra_base = devm_ioremap_resource(dev, cra);
717 if (IS_ERR(pcie->cra_base))
718 return PTR_ERR(pcie->cra_base);
720 if (pcie->pcie_data->version == ALTERA_PCIE_V2) {
721 hip = platform_get_resource_byname(pdev, IORESOURCE_MEM, "Hip");
722 pcie->hip_base = devm_ioremap_resource(&pdev->dev, hip);
723 if (IS_ERR(pcie->hip_base))
724 return PTR_ERR(pcie->hip_base);
728 pcie->irq = platform_get_irq(pdev, 0);
730 dev_err(dev, "failed to get IRQ: %d\n", pcie->irq);
734 irq_set_chained_handler_and_data(pcie->irq, altera_pcie_isr, pcie);
738 static void altera_pcie_host_init(struct altera_pcie *pcie)
740 altera_pcie_retrain(pcie);
743 static const struct altera_pcie_ops altera_pcie_ops_1_0 = {
744 .tlp_read_pkt = tlp_read_packet,
745 .tlp_write_pkt = tlp_write_packet,
746 .get_link_status = altera_pcie_link_up,
749 static const struct altera_pcie_ops altera_pcie_ops_2_0 = {
750 .tlp_read_pkt = s10_tlp_read_packet,
751 .tlp_write_pkt = s10_tlp_write_packet,
752 .get_link_status = s10_altera_pcie_link_up,
753 .rp_read_cfg = s10_rp_read_cfg,
754 .rp_write_cfg = s10_rp_write_cfg,
757 static const struct altera_pcie_data altera_pcie_1_0_data = {
758 .ops = &altera_pcie_ops_1_0,
760 .version = ALTERA_PCIE_V1,
761 .cfgrd0 = TLP_FMTTYPE_CFGRD0,
762 .cfgrd1 = TLP_FMTTYPE_CFGRD1,
763 .cfgwr0 = TLP_FMTTYPE_CFGWR0,
764 .cfgwr1 = TLP_FMTTYPE_CFGWR1,
767 static const struct altera_pcie_data altera_pcie_2_0_data = {
768 .ops = &altera_pcie_ops_2_0,
769 .version = ALTERA_PCIE_V2,
771 .cfgrd0 = S10_TLP_FMTTYPE_CFGRD0,
772 .cfgrd1 = S10_TLP_FMTTYPE_CFGRD1,
773 .cfgwr0 = S10_TLP_FMTTYPE_CFGWR0,
774 .cfgwr1 = S10_TLP_FMTTYPE_CFGWR1,
777 static const struct of_device_id altera_pcie_of_match[] = {
778 {.compatible = "altr,pcie-root-port-1.0",
779 .data = &altera_pcie_1_0_data },
780 {.compatible = "altr,pcie-root-port-2.0",
781 .data = &altera_pcie_2_0_data },
785 static int altera_pcie_probe(struct platform_device *pdev)
787 struct device *dev = &pdev->dev;
788 struct altera_pcie *pcie;
790 struct pci_bus *child;
791 struct pci_host_bridge *bridge;
793 const struct of_device_id *match;
795 bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
799 pcie = pci_host_bridge_priv(bridge);
802 match = of_match_device(altera_pcie_of_match, &pdev->dev);
806 pcie->pcie_data = match->data;
808 ret = altera_pcie_parse_dt(pcie);
810 dev_err(dev, "Parsing DT failed\n");
814 INIT_LIST_HEAD(&pcie->resources);
816 ret = altera_pcie_parse_request_of_pci_ranges(pcie);
818 dev_err(dev, "Failed add resources\n");
822 ret = altera_pcie_init_irq_domain(pcie);
824 dev_err(dev, "Failed creating IRQ Domain\n");
828 /* clear all interrupts */
829 cra_writel(pcie, P2A_INT_STS_ALL, P2A_INT_STATUS);
830 /* enable all interrupts */
831 cra_writel(pcie, P2A_INT_ENA_ALL, P2A_INT_ENABLE);
832 altera_pcie_host_init(pcie);
834 list_splice_init(&pcie->resources, &bridge->windows);
835 bridge->dev.parent = dev;
836 bridge->sysdata = pcie;
837 bridge->busnr = pcie->root_bus_nr;
838 bridge->ops = &altera_pcie_ops;
839 bridge->map_irq = of_irq_parse_and_map_pci;
840 bridge->swizzle_irq = pci_common_swizzle;
842 ret = pci_scan_root_bus_bridge(bridge);
848 pci_assign_unassigned_bus_resources(bus);
850 /* Configure PCI Express setting. */
851 list_for_each_entry(child, &bus->children, node)
852 pcie_bus_configure_settings(child);
854 pci_bus_add_devices(bus);
858 static struct platform_driver altera_pcie_driver = {
859 .probe = altera_pcie_probe,
861 .name = "altera-pcie",
862 .of_match_table = altera_pcie_of_match,
863 .suppress_bind_attrs = true,
867 builtin_platform_driver(altera_pcie_driver);