2016-03-11 04:44:52 +08:00
|
|
|
/*
|
|
|
|
* PCIe RC driver for Synopsys DesignWare Core
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
|
|
|
|
*
|
2016-11-16 00:10:47 +08:00
|
|
|
* Authors: Joao Pinto <Joao.Pinto@synopsys.com>
|
2016-03-11 04:44:52 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/kernel.h>
|
2016-07-03 07:13:23 +08:00
|
|
|
#include <linux/init.h>
|
2016-03-11 04:44:52 +08:00
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/resource.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
|
|
|
|
#include "pcie-designware.h"
|
|
|
|
|
|
|
|
struct dw_plat_pcie {
|
2017-02-15 21:18:14 +08:00
|
|
|
struct dw_pcie *pci;
|
2016-03-11 04:44:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static irqreturn_t dw_plat_pcie_msi_irq_handler(int irq, void *arg)
|
|
|
|
{
|
|
|
|
struct pcie_port *pp = arg;
|
|
|
|
|
|
|
|
return dw_handle_msi_irq(pp);
|
|
|
|
}
|
|
|
|
|
2017-07-16 14:39:45 +08:00
|
|
|
static int dw_plat_pcie_host_init(struct pcie_port *pp)
|
2016-03-11 04:44:52 +08:00
|
|
|
{
|
2017-02-15 21:18:14 +08:00
|
|
|
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
|
|
|
|
|
2016-03-11 04:44:52 +08:00
|
|
|
dw_pcie_setup_rc(pp);
|
2017-02-15 21:18:14 +08:00
|
|
|
dw_pcie_wait_for_link(pci);
|
2016-03-11 04:44:52 +08:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_PCI_MSI))
|
|
|
|
dw_pcie_msi_init(pp);
|
2017-07-16 14:39:45 +08:00
|
|
|
|
|
|
|
return 0;
|
2016-03-11 04:44:52 +08:00
|
|
|
}
|
|
|
|
|
2017-06-05 16:53:46 +08:00
|
|
|
static const struct dw_pcie_host_ops dw_plat_pcie_host_ops = {
|
2016-03-11 04:44:52 +08:00
|
|
|
.host_init = dw_plat_pcie_host_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dw_plat_add_pcie_port(struct pcie_port *pp,
|
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
2017-02-15 21:18:14 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2016-03-11 04:44:52 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
pp->irq = platform_get_irq(pdev, 1);
|
|
|
|
if (pp->irq < 0)
|
|
|
|
return pp->irq;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_PCI_MSI)) {
|
|
|
|
pp->msi_irq = platform_get_irq(pdev, 0);
|
|
|
|
if (pp->msi_irq < 0)
|
|
|
|
return pp->msi_irq;
|
|
|
|
|
2016-10-07 02:32:15 +08:00
|
|
|
ret = devm_request_irq(dev, pp->msi_irq,
|
2016-03-11 04:44:52 +08:00
|
|
|
dw_plat_pcie_msi_irq_handler,
|
2017-04-20 18:27:18 +08:00
|
|
|
IRQF_SHARED | IRQF_NO_THREAD,
|
|
|
|
"dw-plat-pcie-msi", pp);
|
2016-03-11 04:44:52 +08:00
|
|
|
if (ret) {
|
2016-10-07 02:32:15 +08:00
|
|
|
dev_err(dev, "failed to request MSI IRQ\n");
|
2016-03-11 04:44:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pp->root_bus_nr = -1;
|
|
|
|
pp->ops = &dw_plat_pcie_host_ops;
|
|
|
|
|
|
|
|
ret = dw_pcie_host_init(pp);
|
|
|
|
if (ret) {
|
2016-10-07 02:32:15 +08:00
|
|
|
dev_err(dev, "failed to initialize host\n");
|
2016-03-11 04:44:52 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-04 06:35:12 +08:00
|
|
|
static const struct dw_pcie_ops dw_pcie_ops = {
|
|
|
|
};
|
|
|
|
|
2016-03-11 04:44:52 +08:00
|
|
|
static int dw_plat_pcie_probe(struct platform_device *pdev)
|
|
|
|
{
|
2016-10-07 02:32:15 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2016-03-11 04:44:52 +08:00
|
|
|
struct dw_plat_pcie *dw_plat_pcie;
|
2017-02-15 21:18:14 +08:00
|
|
|
struct dw_pcie *pci;
|
2016-03-11 04:44:52 +08:00
|
|
|
struct resource *res; /* Resource from DT */
|
|
|
|
int ret;
|
|
|
|
|
2016-10-07 02:32:15 +08:00
|
|
|
dw_plat_pcie = devm_kzalloc(dev, sizeof(*dw_plat_pcie), GFP_KERNEL);
|
2016-03-11 04:44:52 +08:00
|
|
|
if (!dw_plat_pcie)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
|
|
|
|
if (!pci)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
pci->dev = dev;
|
2017-04-04 06:35:12 +08:00
|
|
|
pci->ops = &dw_pcie_ops;
|
2016-03-11 04:44:52 +08:00
|
|
|
|
2017-02-25 18:08:12 +08:00
|
|
|
dw_plat_pcie->pci = pci;
|
|
|
|
|
2016-03-11 04:44:52 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2017-02-15 21:18:14 +08:00
|
|
|
pci->dbi_base = devm_ioremap_resource(dev, res);
|
|
|
|
if (IS_ERR(pci->dbi_base))
|
|
|
|
return PTR_ERR(pci->dbi_base);
|
2016-03-11 04:44:52 +08:00
|
|
|
|
2017-02-15 21:18:11 +08:00
|
|
|
platform_set_drvdata(pdev, dw_plat_pcie);
|
|
|
|
|
2017-02-15 21:18:14 +08:00
|
|
|
ret = dw_plat_add_pcie_port(&pci->pp, pdev);
|
2016-03-11 04:44:52 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id dw_plat_pcie_of_match[] = {
|
|
|
|
{ .compatible = "snps,dw-pcie", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver dw_plat_pcie_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "dw-pcie",
|
|
|
|
.of_match_table = dw_plat_pcie_of_match,
|
2017-04-21 04:36:25 +08:00
|
|
|
.suppress_bind_attrs = true,
|
2016-03-11 04:44:52 +08:00
|
|
|
},
|
|
|
|
.probe = dw_plat_pcie_probe,
|
|
|
|
};
|
2016-07-03 07:13:23 +08:00
|
|
|
builtin_platform_driver(dw_plat_pcie_driver);
|