Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / pci / host / pcie-iproc-bcma.c
blob603c83429cb305056ead23fcfb40fb9cdfc2ceed
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2015 Broadcom Corporation
4 * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de>
5 */
7 #include <linux/kernel.h>
8 #include <linux/pci.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include <linux/phy/phy.h>
12 #include <linux/bcma/bcma.h>
13 #include <linux/ioport.h>
15 #include "pcie-iproc.h"
18 /* NS: CLASS field is R/O, and set to wrong 0x200 value */
19 static void bcma_pcie2_fixup_class(struct pci_dev *dev)
21 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
23 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
24 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
26 static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
28 struct pci_sys_data *sys = dev->sysdata;
29 struct iproc_pcie *pcie = sys->private_data;
30 struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
32 return bcma_core_irq(bdev, 5);
35 static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
37 struct device *dev = &bdev->dev;
38 struct iproc_pcie *pcie;
39 LIST_HEAD(resources);
40 struct pci_host_bridge *bridge;
41 int ret;
43 bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
44 if (!bridge)
45 return -ENOMEM;
47 pcie = pci_host_bridge_priv(bridge);
49 pcie->dev = dev;
51 pcie->type = IPROC_PCIE_PAXB_BCMA;
52 pcie->base = bdev->io_addr;
53 if (!pcie->base) {
54 dev_err(dev, "no controller registers\n");
55 return -ENOMEM;
58 pcie->base_addr = bdev->addr;
60 pcie->mem.start = bdev->addr_s[0];
61 pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
62 pcie->mem.name = "PCIe MEM space";
63 pcie->mem.flags = IORESOURCE_MEM;
64 pci_add_resource(&resources, &pcie->mem);
66 pcie->map_irq = iproc_pcie_bcma_map_irq;
68 ret = iproc_pcie_setup(pcie, &resources);
69 if (ret) {
70 dev_err(dev, "PCIe controller setup failed\n");
71 pci_free_resource_list(&resources);
72 return ret;
75 bcma_set_drvdata(bdev, pcie);
76 return 0;
79 static void iproc_pcie_bcma_remove(struct bcma_device *bdev)
81 struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
83 iproc_pcie_remove(pcie);
86 static const struct bcma_device_id iproc_pcie_bcma_table[] = {
87 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
88 {},
90 MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table);
92 static struct bcma_driver iproc_pcie_bcma_driver = {
93 .name = KBUILD_MODNAME,
94 .id_table = iproc_pcie_bcma_table,
95 .probe = iproc_pcie_bcma_probe,
96 .remove = iproc_pcie_bcma_remove,
99 static int __init iproc_pcie_bcma_init(void)
101 return bcma_driver_register(&iproc_pcie_bcma_driver);
103 module_init(iproc_pcie_bcma_init);
105 static void __exit iproc_pcie_bcma_exit(void)
107 bcma_driver_unregister(&iproc_pcie_bcma_driver);
109 module_exit(iproc_pcie_bcma_exit);
111 MODULE_AUTHOR("Hauke Mehrtens");
112 MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
113 MODULE_LICENSE("GPL v2");