Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2015 Broadcom Corporation
0004  * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de>
0005  */
0006 
0007 #include <linux/kernel.h>
0008 #include <linux/pci.h>
0009 #include <linux/module.h>
0010 #include <linux/slab.h>
0011 #include <linux/phy/phy.h>
0012 #include <linux/bcma/bcma.h>
0013 #include <linux/ioport.h>
0014 
0015 #include "pcie-iproc.h"
0016 
0017 
0018 /* NS: CLASS field is R/O, and set to wrong 0x200 value */
0019 static void bcma_pcie2_fixup_class(struct pci_dev *dev)
0020 {
0021     dev->class = PCI_CLASS_BRIDGE_PCI_NORMAL;
0022 }
0023 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
0024 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
0025 
0026 static int iproc_bcma_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
0027 {
0028     struct iproc_pcie *pcie = dev->sysdata;
0029     struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
0030 
0031     return bcma_core_irq(bdev, 5);
0032 }
0033 
0034 static int iproc_bcma_pcie_probe(struct bcma_device *bdev)
0035 {
0036     struct device *dev = &bdev->dev;
0037     struct iproc_pcie *pcie;
0038     struct pci_host_bridge *bridge;
0039     int ret;
0040 
0041     bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
0042     if (!bridge)
0043         return -ENOMEM;
0044 
0045     pcie = pci_host_bridge_priv(bridge);
0046 
0047     pcie->dev = dev;
0048 
0049     pcie->type = IPROC_PCIE_PAXB_BCMA;
0050     pcie->base = bdev->io_addr;
0051     if (!pcie->base) {
0052         dev_err(dev, "no controller registers\n");
0053         return -ENOMEM;
0054     }
0055 
0056     pcie->base_addr = bdev->addr;
0057 
0058     pcie->mem.start = bdev->addr_s[0];
0059     pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
0060     pcie->mem.name = "PCIe MEM space";
0061     pcie->mem.flags = IORESOURCE_MEM;
0062     pci_add_resource(&bridge->windows, &pcie->mem);
0063     ret = devm_request_pci_bus_resources(dev, &bridge->windows);
0064     if (ret)
0065         return ret;
0066 
0067     pcie->map_irq = iproc_bcma_pcie_map_irq;
0068 
0069     bcma_set_drvdata(bdev, pcie);
0070 
0071     return iproc_pcie_setup(pcie, &bridge->windows);
0072 }
0073 
0074 static void iproc_bcma_pcie_remove(struct bcma_device *bdev)
0075 {
0076     struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
0077 
0078     iproc_pcie_remove(pcie);
0079 }
0080 
0081 static const struct bcma_device_id iproc_bcma_pcie_table[] = {
0082     BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
0083     {},
0084 };
0085 MODULE_DEVICE_TABLE(bcma, iproc_bcma_pcie_table);
0086 
0087 static struct bcma_driver iproc_bcma_pcie_driver = {
0088     .name       = KBUILD_MODNAME,
0089     .id_table   = iproc_bcma_pcie_table,
0090     .probe      = iproc_bcma_pcie_probe,
0091     .remove     = iproc_bcma_pcie_remove,
0092 };
0093 module_bcma_driver(iproc_bcma_pcie_driver);
0094 
0095 MODULE_AUTHOR("Hauke Mehrtens");
0096 MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
0097 MODULE_LICENSE("GPL v2");