pcie-iproc-platform.c 3.8 KB

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