1 // SPDX-License-Identifier: GPL-2.0
3 * PCIe host controller driver for Freescale Layerscape SoCs
5 * Copyright (C) 2014 Freescale Semiconductor.
11 #include <linux/kernel.h>
12 #include <linux/interrupt.h>
13 #include <linux/init.h>
14 #include <linux/of_pci.h>
15 #include <linux/of_platform.h>
16 #include <linux/of_address.h>
17 #include <linux/pci.h>
18 #include <linux/platform_device.h>
19 #include <linux/resource.h>
20 #include <linux/mfd/syscon.h>
21 #include <linux/regmap.h>
23 #include "pcie-designware.h"
25 /* PEX Internal Configuration Registers */
26 #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */
27 #define PCIE_ABSERR 0x8d0 /* Bridge Slave Error Response Register */
28 #define PCIE_ABSERR_SETTING 0x9401 /* Forward error of non-posted request */
30 #define PCIE_IATU_NUM 6
36 #define to_ls_pcie(x) dev_get_drvdata((x)->dev)
38 static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
40 struct dw_pcie *pci = pcie->pci;
43 header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
46 return header_type == PCI_HEADER_TYPE_BRIDGE;
49 /* Clear multi-function bit */
50 static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
52 struct dw_pcie *pci = pcie->pci;
54 iowrite8(PCI_HEADER_TYPE_BRIDGE, pci->dbi_base + PCI_HEADER_TYPE);
57 /* Drop MSG TLP except for Vendor MSG */
58 static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
61 struct dw_pcie *pci = pcie->pci;
63 val = ioread32(pci->dbi_base + PCIE_STRFMR1);
65 iowrite32(val, pci->dbi_base + PCIE_STRFMR1);
68 /* Forward error response of outbound non-posted requests */
69 static void ls_pcie_fix_error_response(struct ls_pcie *pcie)
71 struct dw_pcie *pci = pcie->pci;
73 iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR);
76 static int ls_pcie_host_init(struct dw_pcie_rp *pp)
78 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
79 struct ls_pcie *pcie = to_ls_pcie(pci);
81 ls_pcie_fix_error_response(pcie);
83 dw_pcie_dbi_ro_wr_en(pci);
84 ls_pcie_clear_multifunction(pcie);
85 dw_pcie_dbi_ro_wr_dis(pci);
87 ls_pcie_drop_msg_tlp(pcie);
92 static const struct dw_pcie_host_ops ls_pcie_host_ops = {
93 .host_init = ls_pcie_host_init,
96 static const struct of_device_id ls_pcie_of_match[] = {
97 { .compatible = "fsl,ls1012a-pcie", },
98 { .compatible = "fsl,ls1021a-pcie", },
99 { .compatible = "fsl,ls1028a-pcie", },
100 { .compatible = "fsl,ls1043a-pcie", },
101 { .compatible = "fsl,ls1046a-pcie", },
102 { .compatible = "fsl,ls2080a-pcie", },
103 { .compatible = "fsl,ls2085a-pcie", },
104 { .compatible = "fsl,ls2088a-pcie", },
105 { .compatible = "fsl,ls1088a-pcie", },
109 static int ls_pcie_probe(struct platform_device *pdev)
111 struct device *dev = &pdev->dev;
113 struct ls_pcie *pcie;
114 struct resource *dbi_base;
116 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
120 pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
125 pci->pp.ops = &ls_pcie_host_ops;
129 dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
130 pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
131 if (IS_ERR(pci->dbi_base))
132 return PTR_ERR(pci->dbi_base);
134 if (!ls_pcie_is_bridge(pcie))
137 platform_set_drvdata(pdev, pcie);
139 return dw_pcie_host_init(&pci->pp);
142 static struct platform_driver ls_pcie_driver = {
143 .probe = ls_pcie_probe,
145 .name = "layerscape-pcie",
146 .of_match_table = ls_pcie_of_match,
147 .suppress_bind_attrs = true,
150 builtin_platform_driver(ls_pcie_driver);