pcie-iproc-bcma.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2015 Broadcom Corporation
  4. * Copyright (C) 2015 Hauke Mehrtens <[email protected]>
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/pci.h>
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <linux/phy/phy.h>
  11. #include <linux/bcma/bcma.h>
  12. #include <linux/ioport.h>
  13. #include "pcie-iproc.h"
  14. /* NS: CLASS field is R/O, and set to wrong 0x200 value */
  15. static void bcma_pcie2_fixup_class(struct pci_dev *dev)
  16. {
  17. dev->class = PCI_CLASS_BRIDGE_PCI_NORMAL;
  18. }
  19. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
  20. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
  21. static int iproc_bcma_pcie_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  22. {
  23. struct iproc_pcie *pcie = dev->sysdata;
  24. struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
  25. return bcma_core_irq(bdev, 5);
  26. }
  27. static int iproc_bcma_pcie_probe(struct bcma_device *bdev)
  28. {
  29. struct device *dev = &bdev->dev;
  30. struct iproc_pcie *pcie;
  31. struct pci_host_bridge *bridge;
  32. int ret;
  33. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  34. if (!bridge)
  35. return -ENOMEM;
  36. pcie = pci_host_bridge_priv(bridge);
  37. pcie->dev = dev;
  38. pcie->type = IPROC_PCIE_PAXB_BCMA;
  39. pcie->base = bdev->io_addr;
  40. if (!pcie->base) {
  41. dev_err(dev, "no controller registers\n");
  42. return -ENOMEM;
  43. }
  44. pcie->base_addr = bdev->addr;
  45. pcie->mem.start = bdev->addr_s[0];
  46. pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
  47. pcie->mem.name = "PCIe MEM space";
  48. pcie->mem.flags = IORESOURCE_MEM;
  49. pci_add_resource(&bridge->windows, &pcie->mem);
  50. ret = devm_request_pci_bus_resources(dev, &bridge->windows);
  51. if (ret)
  52. return ret;
  53. pcie->map_irq = iproc_bcma_pcie_map_irq;
  54. bcma_set_drvdata(bdev, pcie);
  55. return iproc_pcie_setup(pcie, &bridge->windows);
  56. }
  57. static void iproc_bcma_pcie_remove(struct bcma_device *bdev)
  58. {
  59. struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
  60. iproc_pcie_remove(pcie);
  61. }
  62. static const struct bcma_device_id iproc_bcma_pcie_table[] = {
  63. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
  64. {},
  65. };
  66. MODULE_DEVICE_TABLE(bcma, iproc_bcma_pcie_table);
  67. static struct bcma_driver iproc_bcma_pcie_driver = {
  68. .name = KBUILD_MODNAME,
  69. .id_table = iproc_bcma_pcie_table,
  70. .probe = iproc_bcma_pcie_probe,
  71. .remove = iproc_bcma_pcie_remove,
  72. };
  73. module_bcma_driver(iproc_bcma_pcie_driver);
  74. MODULE_AUTHOR("Hauke Mehrtens");
  75. MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
  76. MODULE_LICENSE("GPL v2");