2015-04-09 02:21:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation version 2.
|
|
|
|
*
|
|
|
|
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
|
|
|
|
* kind, whether express or implied; without even the implied warranty
|
|
|
|
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
|
|
|
|
|
|
|
#include "pcie-iproc.h"
|
|
|
|
|
2015-12-05 01:34:59 +08:00
|
|
|
static const struct of_device_id iproc_pcie_of_match_table[] = {
|
|
|
|
{
|
|
|
|
.compatible = "brcm,iproc-pcie",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXB,
|
2016-11-01 08:38:41 +08:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxb-v2",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXB_V2,
|
2015-12-05 01:34:59 +08:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxc",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXC,
|
2016-11-01 08:38:35 +08:00
|
|
|
}, {
|
|
|
|
.compatible = "brcm,iproc-pcie-paxc-v2",
|
|
|
|
.data = (int *)IPROC_PCIE_PAXC_V2,
|
2015-12-05 01:34:59 +08:00
|
|
|
},
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
|
|
|
|
|
2015-04-09 02:21:35 +08:00
|
|
|
static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
|
|
|
|
{
|
2016-10-07 02:36:08 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2015-04-09 02:21:35 +08:00
|
|
|
struct iproc_pcie *pcie;
|
2016-10-07 02:36:08 +08:00
|
|
|
struct device_node *np = dev->of_node;
|
2015-04-09 02:21:35 +08:00
|
|
|
struct resource reg;
|
|
|
|
resource_size_t iobase = 0;
|
2017-03-10 01:27:07 +08:00
|
|
|
LIST_HEAD(resources);
|
2017-06-29 04:13:57 +08:00
|
|
|
struct pci_host_bridge *bridge;
|
2015-04-09 02:21:35 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-06-29 04:13:57 +08:00
|
|
|
bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
|
|
|
|
if (!bridge)
|
2015-04-09 02:21:35 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-06-29 04:13:57 +08:00
|
|
|
pcie = pci_host_bridge_priv(bridge);
|
|
|
|
|
2016-10-07 02:36:08 +08:00
|
|
|
pcie->dev = dev;
|
2017-02-01 06:36:32 +08:00
|
|
|
pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
|
2015-04-09 02:21:35 +08:00
|
|
|
|
|
|
|
ret = of_address_to_resource(np, 0, ®);
|
|
|
|
if (ret < 0) {
|
2016-10-07 02:36:08 +08:00
|
|
|
dev_err(dev, "unable to obtain controller resources\n");
|
2015-04-09 02:21:35 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-20 00:49:02 +08:00
|
|
|
pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
|
|
|
|
resource_size(®));
|
2015-04-09 02:21:35 +08:00
|
|
|
if (!pcie->base) {
|
2016-10-07 02:36:08 +08:00
|
|
|
dev_err(dev, "unable to map controller registers\n");
|
2015-04-09 02:21:35 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2016-01-07 08:04:35 +08:00
|
|
|
pcie->base_addr = reg.start;
|
2015-04-09 02:21:35 +08:00
|
|
|
|
2015-10-16 21:18:24 +08: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-07 02:36:08 +08:00
|
|
|
dev_err(dev,
|
2015-10-16 21:18:24 +08:00
|
|
|
"missing brcm,pcie-ob-axi-offset property\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
pcie->ob.axi_offset = val;
|
|
|
|
pcie->need_ob_cfg = true;
|
|
|
|
}
|
|
|
|
|
2015-04-09 02:21:35 +08:00
|
|
|
/* PHY use is optional */
|
2016-10-07 02:36:08 +08:00
|
|
|
pcie->phy = devm_phy_get(dev, "pcie-phy");
|
2015-04-09 02:21:35 +08:00
|
|
|
if (IS_ERR(pcie->phy)) {
|
|
|
|
if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
|
|
|
|
return -EPROBE_DEFER;
|
|
|
|
pcie->phy = NULL;
|
|
|
|
}
|
|
|
|
|
2017-03-10 01:27:07 +08:00
|
|
|
ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &resources,
|
|
|
|
&iobase);
|
2015-04-09 02:21:35 +08:00
|
|
|
if (ret) {
|
2017-03-10 01:27:07 +08:00
|
|
|
dev_err(dev, "unable to get PCI host bridge resources\n");
|
2015-04-09 02:21:35 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-02 04:34:52 +08:00
|
|
|
/* PAXC doesn't support legacy IRQs, skip mapping */
|
|
|
|
switch (pcie->type) {
|
|
|
|
case IPROC_PCIE_PAXC:
|
|
|
|
case IPROC_PCIE_PAXC_V2:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
pcie->map_irq = of_irq_parse_and_map_pci;
|
|
|
|
}
|
2015-05-13 05:23:00 +08:00
|
|
|
|
2017-03-10 01:27:07 +08:00
|
|
|
ret = iproc_pcie_setup(pcie, &resources);
|
|
|
|
if (ret) {
|
2016-10-07 02:36:08 +08:00
|
|
|
dev_err(dev, "PCIe controller setup failed\n");
|
2017-03-10 01:27:07 +08:00
|
|
|
pci_free_resource_list(&resources);
|
|
|
|
return ret;
|
|
|
|
}
|
2015-05-25 04:37:03 +08:00
|
|
|
|
2016-10-07 02:36:08 +08:00
|
|
|
platform_set_drvdata(pdev, pcie);
|
2017-03-10 01:27:07 +08:00
|
|
|
return 0;
|
2015-04-09 02:21:35 +08: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 05:43:35 +08: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-09 02:21:35 +08: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 05:43:35 +08:00
|
|
|
.shutdown = iproc_pcie_pltfm_shutdown,
|
2015-04-09 02:21:35 +08: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");
|