pcie-iproc-platform.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2015 Broadcom Corporation
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/pci.h>
  7. #include <linux/clk.h>
  8. #include <linux/module.h>
  9. #include <linux/slab.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/of_address.h>
  13. #include <linux/of_pci.h>
  14. #include <linux/of_irq.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/phy/phy.h>
  17. #include "../pci.h"
  18. #include "pcie-iproc.h"
  19. static const struct of_device_id iproc_pcie_of_match_table[] = {
  20. {
  21. .compatible = "brcm,iproc-pcie",
  22. .data = (int *)IPROC_PCIE_PAXB,
  23. }, {
  24. .compatible = "brcm,iproc-pcie-paxb-v2",
  25. .data = (int *)IPROC_PCIE_PAXB_V2,
  26. }, {
  27. .compatible = "brcm,iproc-pcie-paxc",
  28. .data = (int *)IPROC_PCIE_PAXC,
  29. }, {
  30. .compatible = "brcm,iproc-pcie-paxc-v2",
  31. .data = (int *)IPROC_PCIE_PAXC_V2,
  32. },
  33. { /* sentinel */ }
  34. };
  35. MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
  36. static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
  37. {
  38. struct device *dev = &pdev->dev;
  39. struct iproc_pcie *pcie;
  40. struct device_node *np = dev->of_node;
  41. struct resource reg;
  42. resource_size_t iobase = 0;
  43. LIST_HEAD(resources);
  44. struct pci_host_bridge *bridge;
  45. int ret;
  46. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  47. if (!bridge)
  48. return -ENOMEM;
  49. pcie = pci_host_bridge_priv(bridge);
  50. pcie->dev = dev;
  51. pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
  52. ret = of_address_to_resource(np, 0, &reg);
  53. if (ret < 0) {
  54. dev_err(dev, "unable to obtain controller resources\n");
  55. return ret;
  56. }
  57. pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
  58. resource_size(&reg));
  59. if (!pcie->base) {
  60. dev_err(dev, "unable to map controller registers\n");
  61. return -ENOMEM;
  62. }
  63. pcie->base_addr = reg.start;
  64. if (of_property_read_bool(np, "brcm,pcie-ob")) {
  65. u32 val;
  66. ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
  67. &val);
  68. if (ret) {
  69. dev_err(dev,
  70. "missing brcm,pcie-ob-axi-offset property\n");
  71. return ret;
  72. }
  73. pcie->ob.axi_offset = val;
  74. pcie->need_ob_cfg = true;
  75. }
  76. /*
  77. * DT nodes are not used by all platforms that use the iProc PCIe
  78. * core driver. For platforms that require explict inbound mapping
  79. * configuration, "dma-ranges" would have been present in DT
  80. */
  81. pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges");
  82. /* PHY use is optional */
  83. pcie->phy = devm_phy_get(dev, "pcie-phy");
  84. if (IS_ERR(pcie->phy)) {
  85. if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
  86. return -EPROBE_DEFER;
  87. pcie->phy = NULL;
  88. }
  89. ret = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &resources,
  90. &iobase);
  91. if (ret) {
  92. dev_err(dev, "unable to get PCI host bridge resources\n");
  93. return ret;
  94. }
  95. /* PAXC doesn't support legacy IRQs, skip mapping */
  96. switch (pcie->type) {
  97. case IPROC_PCIE_PAXC:
  98. case IPROC_PCIE_PAXC_V2:
  99. break;
  100. default:
  101. pcie->map_irq = of_irq_parse_and_map_pci;
  102. }
  103. ret = iproc_pcie_setup(pcie, &resources);
  104. if (ret) {
  105. dev_err(dev, "PCIe controller setup failed\n");
  106. pci_free_resource_list(&resources);
  107. return ret;
  108. }
  109. platform_set_drvdata(pdev, pcie);
  110. return 0;
  111. }
  112. static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
  113. {
  114. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  115. return iproc_pcie_remove(pcie);
  116. }
  117. static void iproc_pcie_pltfm_shutdown(struct platform_device *pdev)
  118. {
  119. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  120. iproc_pcie_shutdown(pcie);
  121. }
  122. static struct platform_driver iproc_pcie_pltfm_driver = {
  123. .driver = {
  124. .name = "iproc-pcie",
  125. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  126. },
  127. .probe = iproc_pcie_pltfm_probe,
  128. .remove = iproc_pcie_pltfm_remove,
  129. .shutdown = iproc_pcie_pltfm_shutdown,
  130. };
  131. module_platform_driver(iproc_pcie_pltfm_driver);
  132. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  133. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  134. MODULE_LICENSE("GPL v2");