pcie-iproc-bcma.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. #include <linux/kernel.h>
  15. #include <linux/pci.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/phy/phy.h>
  19. #include <linux/bcma/bcma.h>
  20. #include <linux/ioport.h>
  21. #include "pcie-iproc.h"
  22. /* NS: CLASS field is R/O, and set to wrong 0x200 value */
  23. static void bcma_pcie2_fixup_class(struct pci_dev *dev)
  24. {
  25. dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  26. }
  27. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
  28. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
  29. static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  30. {
  31. struct pci_sys_data *sys = dev->sysdata;
  32. struct iproc_pcie *pcie = sys->private_data;
  33. struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
  34. return bcma_core_irq(bdev, 5);
  35. }
  36. static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
  37. {
  38. struct device *dev = &bdev->dev;
  39. struct iproc_pcie *pcie;
  40. LIST_HEAD(resources);
  41. struct pci_host_bridge *bridge;
  42. int ret;
  43. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  44. if (!bridge)
  45. return -ENOMEM;
  46. pcie = pci_host_bridge_priv(bridge);
  47. pcie->dev = dev;
  48. pcie->type = IPROC_PCIE_PAXB_BCMA;
  49. pcie->base = bdev->io_addr;
  50. if (!pcie->base) {
  51. dev_err(dev, "no controller registers\n");
  52. return -ENOMEM;
  53. }
  54. pcie->base_addr = bdev->addr;
  55. pcie->mem.start = bdev->addr_s[0];
  56. pcie->mem.end = bdev->addr_s[0] + SZ_128M - 1;
  57. pcie->mem.name = "PCIe MEM space";
  58. pcie->mem.flags = IORESOURCE_MEM;
  59. pci_add_resource(&resources, &pcie->mem);
  60. pcie->map_irq = iproc_pcie_bcma_map_irq;
  61. ret = iproc_pcie_setup(pcie, &resources);
  62. if (ret) {
  63. dev_err(dev, "PCIe controller setup failed\n");
  64. pci_free_resource_list(&resources);
  65. return ret;
  66. }
  67. bcma_set_drvdata(bdev, pcie);
  68. return 0;
  69. }
  70. static void iproc_pcie_bcma_remove(struct bcma_device *bdev)
  71. {
  72. struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
  73. iproc_pcie_remove(pcie);
  74. }
  75. static const struct bcma_device_id iproc_pcie_bcma_table[] = {
  76. BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
  77. {},
  78. };
  79. MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table);
  80. static struct bcma_driver iproc_pcie_bcma_driver = {
  81. .name = KBUILD_MODNAME,
  82. .id_table = iproc_pcie_bcma_table,
  83. .probe = iproc_pcie_bcma_probe,
  84. .remove = iproc_pcie_bcma_remove,
  85. };
  86. static int __init iproc_pcie_bcma_init(void)
  87. {
  88. return bcma_driver_register(&iproc_pcie_bcma_driver);
  89. }
  90. module_init(iproc_pcie_bcma_init);
  91. static void __exit iproc_pcie_bcma_exit(void)
  92. {
  93. bcma_driver_unregister(&iproc_pcie_bcma_driver);
  94. }
  95. module_exit(iproc_pcie_bcma_exit);
  96. MODULE_AUTHOR("Hauke Mehrtens");
  97. MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
  98. MODULE_LICENSE("GPL v2");