Bjorn Helgaas | 8cfab3c | 2018-01-26 12:50:27 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 2 | /* |
| 3 | * PCIe host controller driver for Freescale Layerscape SoCs |
| 4 | * |
| 5 | * Copyright (C) 2014 Freescale Semiconductor. |
Hou Zhiqiang | d23f0c1 | 2021-12-24 17:40:00 +0800 | [diff] [blame] | 6 | * Copyright 2021 NXP |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 7 | * |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 8 | * Author: Minghuan Lian <Minghuan.Lian@freescale.com> |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <linux/kernel.h> |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 12 | #include <linux/interrupt.h> |
Paul Gortmaker | 154fb60 | 2016-07-02 19:13:27 -0400 | [diff] [blame] | 13 | #include <linux/init.h> |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 14 | #include <linux/of_pci.h> |
| 15 | #include <linux/of_platform.h> |
| 16 | #include <linux/of_irq.h> |
| 17 | #include <linux/of_address.h> |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/resource.h> |
| 21 | #include <linux/mfd/syscon.h> |
| 22 | #include <linux/regmap.h> |
| 23 | |
| 24 | #include "pcie-designware.h" |
| 25 | |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 26 | /* PEX Internal Configuration Registers */ |
| 27 | #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */ |
Minghuan Lian | 84d897d | 2017-10-12 17:44:48 +0800 | [diff] [blame] | 28 | #define PCIE_ABSERR 0x8d0 /* Bridge Slave Error Response Register */ |
| 29 | #define PCIE_ABSERR_SETTING 0x9401 /* Forward error of non-posted request */ |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 30 | |
Hou Zhiqiang | 4a2745d | 2017-08-28 18:52:58 +0800 | [diff] [blame] | 31 | #define PCIE_IATU_NUM 6 |
| 32 | |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 33 | struct ls_pcie { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 34 | struct dw_pcie *pci; |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 35 | }; |
| 36 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 37 | #define to_ls_pcie(x) dev_get_drvdata((x)->dev) |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 38 | |
Minghuan Lian | 7af4ce3 | 2015-10-16 15:19:16 +0800 | [diff] [blame] | 39 | static bool ls_pcie_is_bridge(struct ls_pcie *pcie) |
| 40 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 41 | struct dw_pcie *pci = pcie->pci; |
Minghuan Lian | 7af4ce3 | 2015-10-16 15:19:16 +0800 | [diff] [blame] | 42 | u32 header_type; |
| 43 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 44 | header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE); |
Minghuan Lian | 7af4ce3 | 2015-10-16 15:19:16 +0800 | [diff] [blame] | 45 | header_type &= 0x7f; |
| 46 | |
| 47 | return header_type == PCI_HEADER_TYPE_BRIDGE; |
| 48 | } |
| 49 | |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 50 | /* Clear multi-function bit */ |
| 51 | static void ls_pcie_clear_multifunction(struct ls_pcie *pcie) |
| 52 | { |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 53 | struct dw_pcie *pci = pcie->pci; |
| 54 | |
| 55 | iowrite8(PCI_HEADER_TYPE_BRIDGE, pci->dbi_base + PCI_HEADER_TYPE); |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 56 | } |
| 57 | |
Minghuan Lian | 1195c103 | 2016-02-29 17:24:15 -0600 | [diff] [blame] | 58 | /* Drop MSG TLP except for Vendor MSG */ |
| 59 | static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie) |
| 60 | { |
| 61 | u32 val; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 62 | struct dw_pcie *pci = pcie->pci; |
Minghuan Lian | 1195c103 | 2016-02-29 17:24:15 -0600 | [diff] [blame] | 63 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 64 | val = ioread32(pci->dbi_base + PCIE_STRFMR1); |
Minghuan Lian | 1195c103 | 2016-02-29 17:24:15 -0600 | [diff] [blame] | 65 | val &= 0xDFFFFFFF; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 66 | iowrite32(val, pci->dbi_base + PCIE_STRFMR1); |
Minghuan Lian | 1195c103 | 2016-02-29 17:24:15 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Minghuan Lian | 84d897d | 2017-10-12 17:44:48 +0800 | [diff] [blame] | 69 | /* Forward error response of outbound non-posted requests */ |
| 70 | static void ls_pcie_fix_error_response(struct ls_pcie *pcie) |
| 71 | { |
| 72 | struct dw_pcie *pci = pcie->pci; |
| 73 | |
| 74 | iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR); |
| 75 | } |
| 76 | |
Hou Zhiqiang | ba95a82 | 2017-08-28 18:52:56 +0800 | [diff] [blame] | 77 | static int ls_pcie_host_init(struct pcie_port *pp) |
| 78 | { |
| 79 | struct dw_pcie *pci = to_dw_pcie_from_pp(pp); |
| 80 | struct ls_pcie *pcie = to_ls_pcie(pci); |
| 81 | |
Minghuan Lian | 84d897d | 2017-10-12 17:44:48 +0800 | [diff] [blame] | 82 | ls_pcie_fix_error_response(pcie); |
Hou Zhiqiang | 4a2745d | 2017-08-28 18:52:58 +0800 | [diff] [blame] | 83 | |
Hou Zhiqiang | e44abfe | 2017-08-28 18:52:59 +0800 | [diff] [blame] | 84 | dw_pcie_dbi_ro_wr_en(pci); |
Hou Zhiqiang | ba95a82 | 2017-08-28 18:52:56 +0800 | [diff] [blame] | 85 | ls_pcie_clear_multifunction(pcie); |
Hou Zhiqiang | e44abfe | 2017-08-28 18:52:59 +0800 | [diff] [blame] | 86 | dw_pcie_dbi_ro_wr_dis(pci); |
Hou Zhiqiang | ba95a82 | 2017-08-28 18:52:56 +0800 | [diff] [blame] | 87 | |
| 88 | ls_pcie_drop_msg_tlp(pcie); |
| 89 | |
Hou Zhiqiang | ba95a82 | 2017-08-28 18:52:56 +0800 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
Jisheng Zhang | 4ab2e7c | 2017-06-05 16:53:46 +0800 | [diff] [blame] | 93 | static const struct dw_pcie_host_ops ls_pcie_host_ops = { |
Minghuan Lian | 5192ec7 | 2015-10-16 15:19:19 +0800 | [diff] [blame] | 94 | .host_init = ls_pcie_host_init, |
| 95 | }; |
| 96 | |
Minghuan Lian | d646334 | 2015-10-16 15:19:17 +0800 | [diff] [blame] | 97 | static const struct of_device_id ls_pcie_of_match[] = { |
Hou Zhiqiang | d23f0c1 | 2021-12-24 17:40:00 +0800 | [diff] [blame] | 98 | { .compatible = "fsl,ls1012a-pcie", }, |
| 99 | { .compatible = "fsl,ls1021a-pcie", }, |
| 100 | { .compatible = "fsl,ls1028a-pcie", }, |
| 101 | { .compatible = "fsl,ls1043a-pcie", }, |
| 102 | { .compatible = "fsl,ls1046a-pcie", }, |
| 103 | { .compatible = "fsl,ls2080a-pcie", }, |
| 104 | { .compatible = "fsl,ls2085a-pcie", }, |
| 105 | { .compatible = "fsl,ls2088a-pcie", }, |
| 106 | { .compatible = "fsl,ls1088a-pcie", }, |
Minghuan Lian | d646334 | 2015-10-16 15:19:17 +0800 | [diff] [blame] | 107 | { }, |
| 108 | }; |
Minghuan Lian | d646334 | 2015-10-16 15:19:17 +0800 | [diff] [blame] | 109 | |
Michael Walle | 7007b74 | 2021-01-20 11:52:46 +0100 | [diff] [blame] | 110 | static int ls_pcie_probe(struct platform_device *pdev) |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 111 | { |
Bjorn Helgaas | c11125e | 2016-10-06 13:38:05 -0500 | [diff] [blame] | 112 | struct device *dev = &pdev->dev; |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 113 | struct dw_pcie *pci; |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 114 | struct ls_pcie *pcie; |
| 115 | struct resource *dbi_base; |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 116 | |
Bjorn Helgaas | c11125e | 2016-10-06 13:38:05 -0500 | [diff] [blame] | 117 | pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL); |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 118 | if (!pcie) |
| 119 | return -ENOMEM; |
| 120 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 121 | pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL); |
| 122 | if (!pci) |
| 123 | return -ENOMEM; |
| 124 | |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 125 | pci->dev = dev; |
Hou Zhiqiang | d23f0c1 | 2021-12-24 17:40:00 +0800 | [diff] [blame] | 126 | pci->pp.ops = &ls_pcie_host_ops; |
Bjorn Helgaas | fefe673 | 2016-10-06 13:38:06 -0500 | [diff] [blame] | 127 | |
Guenter Roeck | c046406 | 2017-02-25 02:08:12 -0800 | [diff] [blame] | 128 | pcie->pci = pci; |
| 129 | |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 130 | dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs"); |
Lorenzo Pieralisi | 01bd489 | 2017-04-19 17:49:08 +0100 | [diff] [blame] | 131 | pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base); |
Kishon Vijay Abraham I | 442ec4c | 2017-02-15 18:48:14 +0530 | [diff] [blame] | 132 | if (IS_ERR(pci->dbi_base)) |
| 133 | return PTR_ERR(pci->dbi_base); |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 134 | |
Minghuan Lian | 7af4ce3 | 2015-10-16 15:19:16 +0800 | [diff] [blame] | 135 | if (!ls_pcie_is_bridge(pcie)) |
| 136 | return -ENODEV; |
| 137 | |
Kishon Vijay Abraham I | 9bcf0a6 | 2017-02-15 18:48:11 +0530 | [diff] [blame] | 138 | platform_set_drvdata(pdev, pcie); |
| 139 | |
Rob Herring | 60f5b73 | 2020-11-05 15:11:56 -0600 | [diff] [blame] | 140 | return dw_pcie_host_init(&pci->pp); |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 141 | } |
| 142 | |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 143 | static struct platform_driver ls_pcie_driver = { |
Michael Walle | 7007b74 | 2021-01-20 11:52:46 +0100 | [diff] [blame] | 144 | .probe = ls_pcie_probe, |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 145 | .driver = { |
| 146 | .name = "layerscape-pcie", |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 147 | .of_match_table = ls_pcie_of_match, |
Brian Norris | a5f40e8 | 2017-04-20 15:36:25 -0500 | [diff] [blame] | 148 | .suppress_bind_attrs = true, |
Minghuan Lian | 62d0ff83 | 2014-11-05 16:45:11 +0800 | [diff] [blame] | 149 | }, |
| 150 | }; |
Michael Walle | 7007b74 | 2021-01-20 11:52:46 +0100 | [diff] [blame] | 151 | builtin_platform_driver(ls_pcie_driver); |