Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Broadcom Corporation |
| 3 | * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation version 2. |
| 8 | * |
| 9 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any |
| 10 | * kind, whether express or implied; without even the implied warranty |
| 11 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/pci.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/phy/phy.h> |
| 20 | #include <linux/bcma/bcma.h> |
| 21 | #include <linux/ioport.h> |
| 22 | |
| 23 | #include "pcie-iproc.h" |
| 24 | |
| 25 | |
| 26 | /* NS: CLASS field is R/O, and set to wrong 0x200 value */ |
| 27 | static void bcma_pcie2_fixup_class(struct pci_dev *dev) |
| 28 | { |
| 29 | dev->class = PCI_CLASS_BRIDGE_PCI << 8; |
| 30 | } |
| 31 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class); |
| 32 | DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class); |
| 33 | |
| 34 | static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin) |
| 35 | { |
| 36 | struct pci_sys_data *sys = dev->sysdata; |
| 37 | struct iproc_pcie *pcie = sys->private_data; |
| 38 | struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev); |
| 39 | |
| 40 | return bcma_core_irq(bdev, 5); |
| 41 | } |
| 42 | |
| 43 | static int iproc_pcie_bcma_probe(struct bcma_device *bdev) |
| 44 | { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 45 | struct device *dev = &bdev->dev; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 46 | struct iproc_pcie *pcie; |
Bjorn Helgaas | 6e347b5 | 2017-03-09 11:27:07 -0600 | [diff] [blame] | 47 | LIST_HEAD(resources); |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 48 | struct pci_host_bridge *bridge; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 49 | int ret; |
| 50 | |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 51 | bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie)); |
| 52 | if (!bridge) |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 53 | return -ENOMEM; |
| 54 | |
Lorenzo Pieralisi | 5277407 | 2017-06-28 15:13:57 -0500 | [diff] [blame] | 55 | pcie = pci_host_bridge_priv(bridge); |
| 56 | |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 57 | pcie->dev = dev; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 58 | |
Ray Jui | 404349c | 2016-10-31 17:38:32 -0700 | [diff] [blame] | 59 | pcie->type = IPROC_PCIE_PAXB_BCMA; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 60 | pcie->base = bdev->io_addr; |
Bjorn Helgaas | f66e5b2 | 2016-10-06 13:36:07 -0500 | [diff] [blame] | 61 | if (!pcie->base) { |
| 62 | dev_err(dev, "no controller registers\n"); |
| 63 | return -ENOMEM; |
| 64 | } |
| 65 | |
Ray Jui | 3bc2b23 | 2016-01-06 18:04:35 -0600 | [diff] [blame] | 66 | pcie->base_addr = bdev->addr; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 67 | |
Bjorn Helgaas | 6e347b5 | 2017-03-09 11:27:07 -0600 | [diff] [blame] | 68 | pcie->mem.start = bdev->addr_s[0]; |
| 69 | pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1; |
| 70 | pcie->mem.name = "PCIe MEM space"; |
| 71 | pcie->mem.flags = IORESOURCE_MEM; |
| 72 | pci_add_resource(&resources, &pcie->mem); |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 73 | |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 74 | pcie->map_irq = iproc_pcie_bcma_map_irq; |
| 75 | |
Bjorn Helgaas | 6e347b5 | 2017-03-09 11:27:07 -0600 | [diff] [blame] | 76 | ret = iproc_pcie_setup(pcie, &resources); |
| 77 | if (ret) { |
Bjorn Helgaas | 786aecc | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 78 | dev_err(dev, "PCIe controller setup failed\n"); |
Bjorn Helgaas | 6e347b5 | 2017-03-09 11:27:07 -0600 | [diff] [blame] | 79 | pci_free_resource_list(&resources); |
| 80 | return ret; |
| 81 | } |
Hauke Mehrtens | ef07991 | 2015-05-24 22:37:03 +0200 | [diff] [blame] | 82 | |
Bjorn Helgaas | 556c7bb | 2016-10-06 13:36:08 -0500 | [diff] [blame] | 83 | bcma_set_drvdata(bdev, pcie); |
Bjorn Helgaas | 6e347b5 | 2017-03-09 11:27:07 -0600 | [diff] [blame] | 84 | return 0; |
Hauke Mehrtens | 4785ffb | 2015-05-12 23:23:01 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static void iproc_pcie_bcma_remove(struct bcma_device *bdev) |
| 88 | { |
| 89 | struct iproc_pcie *pcie = bcma_get_drvdata(bdev); |
| 90 | |
| 91 | iproc_pcie_remove(pcie); |
| 92 | } |
| 93 | |
| 94 | static const struct bcma_device_id iproc_pcie_bcma_table[] = { |
| 95 | BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS), |
| 96 | {}, |
| 97 | }; |
| 98 | MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table); |
| 99 | |
| 100 | static struct bcma_driver iproc_pcie_bcma_driver = { |
| 101 | .name = KBUILD_MODNAME, |
| 102 | .id_table = iproc_pcie_bcma_table, |
| 103 | .probe = iproc_pcie_bcma_probe, |
| 104 | .remove = iproc_pcie_bcma_remove, |
| 105 | }; |
| 106 | |
| 107 | static int __init iproc_pcie_bcma_init(void) |
| 108 | { |
| 109 | return bcma_driver_register(&iproc_pcie_bcma_driver); |
| 110 | } |
| 111 | module_init(iproc_pcie_bcma_init); |
| 112 | |
| 113 | static void __exit iproc_pcie_bcma_exit(void) |
| 114 | { |
| 115 | bcma_driver_unregister(&iproc_pcie_bcma_driver); |
| 116 | } |
| 117 | module_exit(iproc_pcie_bcma_exit); |
| 118 | |
| 119 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 120 | MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver"); |
| 121 | MODULE_LICENSE("GPL v2"); |