pcie-iproc-platform.c 3.8 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * 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>

#include "pcie-iproc.h"

R
Ray Jui 已提交
21 22 23 24
static const struct of_device_id iproc_pcie_of_match_table[] = {
	{
		.compatible = "brcm,iproc-pcie",
		.data = (int *)IPROC_PCIE_PAXB,
25 26 27
	}, {
		.compatible = "brcm,iproc-pcie-paxb-v2",
		.data = (int *)IPROC_PCIE_PAXB_V2,
R
Ray Jui 已提交
28 29 30
	}, {
		.compatible = "brcm,iproc-pcie-paxc",
		.data = (int *)IPROC_PCIE_PAXC,
R
Ray Jui 已提交
31 32 33
	}, {
		.compatible = "brcm,iproc-pcie-paxc-v2",
		.data = (int *)IPROC_PCIE_PAXC_V2,
R
Ray Jui 已提交
34 35 36 37 38
	},
	{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);

39 40
static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
{
41
	struct device *dev = &pdev->dev;
42
	struct iproc_pcie *pcie;
43
	struct device_node *np = dev->of_node;
44 45
	struct resource reg;
	resource_size_t iobase = 0;
46
	LIST_HEAD(resources);
47
	struct pci_host_bridge *bridge;
48 49
	int ret;

50 51
	bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
	if (!bridge)
52 53
		return -ENOMEM;

54 55
	pcie = pci_host_bridge_priv(bridge);

56
	pcie->dev = dev;
57
	pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
58 59 60

	ret = of_address_to_resource(np, 0, &reg);
	if (ret < 0) {
61
		dev_err(dev, "unable to obtain controller resources\n");
62 63 64
		return ret;
	}

65 66
	pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
					     resource_size(&reg));
67
	if (!pcie->base) {
68
		dev_err(dev, "unable to map controller registers\n");
69 70
		return -ENOMEM;
	}
R
Ray Jui 已提交
71
	pcie->base_addr = reg.start;
72

R
Ray Jui 已提交
73 74 75 76 77 78
	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) {
79
			dev_err(dev,
R
Ray Jui 已提交
80 81 82 83 84 85 86
				"missing brcm,pcie-ob-axi-offset property\n");
			return ret;
		}
		pcie->ob.axi_offset = val;
		pcie->need_ob_cfg = true;
	}

87 88 89 90 91 92 93
	/*
	 * DT nodes are not used by all platforms that use the iProc PCIe
	 * core driver. For platforms that require explict inbound mapping
	 * configuration, "dma-ranges" would have been present in DT
	 */
	pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges");

94
	/* PHY use is optional */
95
	pcie->phy = devm_phy_get(dev, "pcie-phy");
96 97 98 99 100 101
	if (IS_ERR(pcie->phy)) {
		if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
			return -EPROBE_DEFER;
		pcie->phy = NULL;
	}

102
	ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
103
						    &iobase);
104
	if (ret) {
105
		dev_err(dev, "unable to get PCI host bridge resources\n");
106 107 108
		return ret;
	}

109 110 111 112 113 114 115 116
	/* 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;
	}
117

118 119
	ret = iproc_pcie_setup(pcie, &resources);
	if (ret) {
120
		dev_err(dev, "PCIe controller setup failed\n");
121 122 123
		pci_free_resource_list(&resources);
		return ret;
	}
124

125
	platform_set_drvdata(pdev, pcie);
126
	return 0;
127 128 129 130 131 132 133 134 135
}

static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
{
	struct iproc_pcie *pcie = platform_get_drvdata(pdev);

	return iproc_pcie_remove(pcie);
}

136 137 138 139 140 141 142
static void iproc_pcie_pltfm_shutdown(struct platform_device *pdev)
{
	struct iproc_pcie *pcie = platform_get_drvdata(pdev);

	iproc_pcie_shutdown(pcie);
}

143 144 145 146 147 148 149
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,
150
	.shutdown = iproc_pcie_pltfm_shutdown,
151 152 153 154 155 156
};
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");