pcie-iproc-bcma.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. */
  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 << 8;
  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_pcie_bcma_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_pcie_bcma_probe(struct bcma_device *bdev)
  28. {
  29. struct device *dev = &bdev->dev;
  30. struct iproc_pcie *pcie;
  31. LIST_HEAD(resources);
  32. struct pci_host_bridge *bridge;
  33. int ret;
  34. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  35. if (!bridge)
  36. return -ENOMEM;
  37. pcie = pci_host_bridge_priv(bridge);
  38. pcie->dev = dev;
  39. pcie->type = IPROC_PCIE_PAXB_BCMA;
  40. pcie->base = bdev->io_addr;
  41. if (!pcie->base) {
  42. dev_err(dev, "no controller registers\n");
  43. return -ENOMEM;
  44. }
  45. pcie->base_addr = bdev->addr;
  46. pcie->mem.start = bdev->addr_s[0];
  47. pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
  48. pcie->mem.name = "PCIe MEM space";
  49. pcie->mem.flags = IORESOURCE_MEM;
  50. pci_add_resource(&resources, &pcie->mem);
  51. pcie->map_irq = iproc_pcie_bcma_map_irq;
  52. ret = iproc_pcie_setup(pcie, &resources);
  53. if (ret) {
  54. dev_err(dev, "PCIe controller setup failed\n");
  55. pci_free_resource_list(&resources);
  56. return ret;
  57. }
  58. bcma_set_drvdata(bdev, pcie);
  59. return 0;
  60. }
  61. static void iproc_pcie_bcma_remove(struct bcma_device *bdev)
  62. {
  63. struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
  64. iproc_pcie_remove(pcie);
  65. }
  66. static const struct bcma_device_id iproc_pcie_bcma_table[] = {
  67. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
  68. {},
  69. };
  70. MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table);
  71. static struct bcma_driver iproc_pcie_bcma_driver = {
  72. .name = KBUILD_MODNAME,
  73. .id_table = iproc_pcie_bcma_table,
  74. .probe = iproc_pcie_bcma_probe,
  75. .remove = iproc_pcie_bcma_remove,
  76. };
  77. static int __init iproc_pcie_bcma_init(void)
  78. {
  79. return bcma_driver_register(&iproc_pcie_bcma_driver);
  80. }
  81. module_init(iproc_pcie_bcma_init);
  82. static void __exit iproc_pcie_bcma_exit(void)
  83. {
  84. bcma_driver_unregister(&iproc_pcie_bcma_driver);
  85. }
  86. module_exit(iproc_pcie_bcma_exit);
  87. MODULE_AUTHOR("Hauke Mehrtens");
  88. MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
  89. MODULE_LICENSE("GPL v2");