2018-01-26 21:50:27 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-04-08 21:21:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Broadcom Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_pci.h>
|
|
|
|
#include <linux/of_irq.h>
|
|
|
|
#include <linux/of_platform.h>
|
|
|
|
#include <linux/phy/phy.h>
|
|
|
|
|
2018-05-11 20:15:30 +03:00
|
|
|
#include "../pci.h"
|
2015-04-08 21:21:35 +03:00
|
|
|
#include "pcie-iproc.h"
|
|
|
|
|
2015-12-04 20:34:59 +03:00
|
|
|
static const struct of_device_id iproc_pcie_of_match_table[] = {
|
|
|
|
{
|
|
|
|
.compatible = "brcm,iproc-pcie",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXB,
|
2016-11-01 03:38:41 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxb-v2",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXB_V2,
|
2015-12-04 20:34:59 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxc",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXC,
|
2016-11-01 03:38:35 +03:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxc-v2",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXC_V2,
|
2015-12-04 20:34:59 +03:00
|
|
|
},
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
|
|
|
|
|
2015-04-08 21:21:35 +03:00
|
|
|
static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
|
|
|
|
{
|
2016-10-06 21:36:08 +03:00
|
|
|
struct device *dev = &pdev->dev;
|
2015-04-08 21:21:35 +03:00
|
|
|
struct iproc_pcie *pcie;
|
2016-10-06 21:36:08 +03:00
|
|
|
struct device_node *np = dev->of_node;
|
2015-04-08 21:21:35 +03:00
|
|
|
struct resource reg;
|
2017-06-28 23:13:57 +03:00
|
|
|
struct pci_host_bridge *bridge;
|
2015-04-08 21:21:35 +03:00
|
|
|
int ret;
|
|
|
|
|
2017-06-28 23:13:57 +03:00
|
|
|
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
|
|
|
|
if (!bridge)
|
2015-04-08 21:21:35 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-06-28 23:13:57 +03:00
|
|
|
pcie = pci_host_bridge_priv(bridge);
|
|
|
|
|
2016-10-06 21:36:08 +03:00
|
|
|
pcie->dev = dev;
|
2017-02-01 01:36:32 +03:00
|
|
|
pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
|
2015-04-08 21:21:35 +03:00
|
|
|
|
|
|
|
ret = of_address_to_resource(np, 0, ®);
|
|
|
|
if (ret < 0) {
|
2016-10-06 21:36:08 +03:00
|
|
|
dev_err(dev, "unable to obtain controller resources\n");
|
2015-04-08 21:21:35 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-19 19:49:02 +03:00
|
|
|
pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
|
|
|
|
resource_size(®));
|
2015-04-08 21:21:35 +03:00
|
|
|
if (!pcie->base) {
|
2016-10-06 21:36:08 +03:00
|
|
|
dev_err(dev, "unable to map controller registers\n");
|
2015-04-08 21:21:35 +03:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2016-01-07 03:04:35 +03:00
|
|
|
pcie->base_addr = reg.start;
|
2015-04-08 21:21:35 +03:00
|
|
|
|
2015-10-16 16:18:24 +03:00
|
|
|
if (of_property_read_bool(np, "brcm,pcie-ob")) {
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
|
|
|
|
&val);
|
|
|
|
if (ret) {
|
2016-10-06 21:36:08 +03:00
|
|
|
dev_err(dev,
|
2015-10-16 16:18:24 +03:00
|
|
|
"missing brcm,pcie-ob-axi-offset property\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
pcie->ob.axi_offset = val;
|
|
|
|
pcie->need_ob_cfg = true;
|
|
|
|
}
|
|
|
|
|
2018-01-11 23:36:16 +03:00
|
|
|
/*
|
|
|
|
* DT nodes are not used by all platforms that use the iProc PCIe
|
2019-05-30 16:05:58 +03:00
|
|
|
* core driver. For platforms that require explicit inbound mapping
|
2018-01-11 23:36:16 +03:00
|
|
|
* configuration, "dma-ranges" would have been present in DT
|
|
|
|
*/
|
|
|
|
pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges");
|
|
|
|
|
2015-04-08 21:21:35 +03:00
|
|
|
/* PHY use is optional */
|
2019-08-29 13:53:19 +03:00
|
|
|
pcie->phy = devm_phy_optional_get(dev, "pcie-phy");
|
|
|
|
if (IS_ERR(pcie->phy))
|
|
|
|
return PTR_ERR(pcie->phy);
|
2015-04-08 21:21:35 +03:00
|
|
|
|
2016-12-01 23:34:52 +03:00
|
|
|
/* PAXC doesn't support legacy IRQs, skip mapping */
|
|
|
|
switch (pcie->type) {
|
|
|
|
case IPROC_PCIE_PAXC:
|
|
|
|
case IPROC_PCIE_PAXC_V2:
|
2020-09-22 22:49:32 +03:00
|
|
|
pcie->map_irq = NULL;
|
2016-12-01 23:34:52 +03:00
|
|
|
break;
|
|
|
|
default:
|
2020-07-22 05:25:14 +03:00
|
|
|
break;
|
2016-12-01 23:34:52 +03:00
|
|
|
}
|
2015-05-13 00:23:00 +03:00
|
|
|
|
2019-10-28 19:32:38 +03:00
|
|
|
ret = iproc_pcie_setup(pcie, &bridge->windows);
|
2017-03-09 20:27:07 +03:00
|
|
|
if (ret) {
|
2016-10-06 21:36:08 +03:00
|
|
|
dev_err(dev, "PCIe controller setup failed\n");
|
2017-03-09 20:27:07 +03:00
|
|
|
return ret;
|
|
|
|
}
|
2015-05-24 23:37:03 +03:00
|
|
|
|
2016-10-06 21:36:08 +03:00
|
|
|
platform_set_drvdata(pdev, pcie);
|
2017-03-09 20:27:07 +03:00
|
|
|
return 0;
|
2015-04-08 21:21:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct iproc_pcie *pcie = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
return iproc_pcie_remove(pcie);
|
|
|
|
}
|
|
|
|
|
PCI: iproc: Add 500ms delay during device shutdown
During soft reset (e.g., "reboot" from Linux) on some iProc-based SOCs, the
LCPLL clock and PERST both go off simultaneously. This seems in accordance
with the PCIe Card Electromechanical spec, r2.0, sec 2.2.3, which says the
clock goes inactive after PERST# goes active, but doesn't specify how long
the clock should be valid after PERST#.
However, we have observed that with the iProc Stingray, some Intel NVMe
endpoints, e.g., the P3700 400GB series, are not detected correctly upon
the next boot sequence unless the clock remains valid for some time after
PERST# is asserted.
Delay 500ms after asserting PERST# before performing a reboot. The 500ms
is experimentally determined.
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
[bhelgaas: changelog, add spec reference, fold in iproc_pcie_shutdown()
export from Arnd Bergmann <arnd@arndb.de>]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>
Reviewed-by: Scott Branden <scott.branden@broadcom.com>
2017-08-29 00:43:35 +03:00
|
|
|
static void iproc_pcie_pltfm_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct iproc_pcie *pcie = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
iproc_pcie_shutdown(pcie);
|
|
|
|
}
|
|
|
|
|
2015-04-08 21:21:35 +03:00
|
|
|
static struct platform_driver iproc_pcie_pltfm_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "iproc-pcie",
|
|
|
|
.of_match_table = of_match_ptr(iproc_pcie_of_match_table),
|
|
|
|
},
|
|
|
|
.probe = iproc_pcie_pltfm_probe,
|
|
|
|
.remove = iproc_pcie_pltfm_remove,
|
PCI: iproc: Add 500ms delay during device shutdown
During soft reset (e.g., "reboot" from Linux) on some iProc-based SOCs, the
LCPLL clock and PERST both go off simultaneously. This seems in accordance
with the PCIe Card Electromechanical spec, r2.0, sec 2.2.3, which says the
clock goes inactive after PERST# goes active, but doesn't specify how long
the clock should be valid after PERST#.
However, we have observed that with the iProc Stingray, some Intel NVMe
endpoints, e.g., the P3700 400GB series, are not detected correctly upon
the next boot sequence unless the clock remains valid for some time after
PERST# is asserted.
Delay 500ms after asserting PERST# before performing a reboot. The 500ms
is experimentally determined.
Signed-off-by: Oza Pawandeep <oza.oza@broadcom.com>
[bhelgaas: changelog, add spec reference, fold in iproc_pcie_shutdown()
export from Arnd Bergmann <arnd@arndb.de>]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ray Jui <ray.jui@broadcom.com>
Reviewed-by: Scott Branden <scott.branden@broadcom.com>
2017-08-29 00:43:35 +03:00
|
|
|
.shutdown = iproc_pcie_pltfm_shutdown,
|
2015-04-08 21:21:35 +03:00
|
|
|
};
|
|
|
|
module_platform_driver(iproc_pcie_pltfm_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
|
|
|
|
MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|