pcie-iproc-platform.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. struct pci_host_bridge *bridge;
  43. int ret;
  44. bridge = devm_pci_alloc_host_bridge(dev, sizeof(*pcie));
  45. if (!bridge)
  46. return -ENOMEM;
  47. pcie = pci_host_bridge_priv(bridge);
  48. pcie->dev = dev;
  49. pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
  50. ret = of_address_to_resource(np, 0, &reg);
  51. if (ret < 0) {
  52. dev_err(dev, "unable to obtain controller resources\n");
  53. return ret;
  54. }
  55. pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
  56. resource_size(&reg));
  57. if (!pcie->base) {
  58. dev_err(dev, "unable to map controller registers\n");
  59. return -ENOMEM;
  60. }
  61. pcie->base_addr = reg.start;
  62. if (of_property_read_bool(np, "brcm,pcie-ob")) {
  63. u32 val;
  64. ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
  65. &val);
  66. if (ret) {
  67. dev_err(dev,
  68. "missing brcm,pcie-ob-axi-offset property\n");
  69. return ret;
  70. }
  71. pcie->ob.axi_offset = val;
  72. pcie->need_ob_cfg = true;
  73. }
  74. /*
  75. * DT nodes are not used by all platforms that use the iProc PCIe
  76. * core driver. For platforms that require explicit inbound mapping
  77. * configuration, "dma-ranges" would have been present in DT
  78. */
  79. pcie->need_ib_cfg = of_property_read_bool(np, "dma-ranges");
  80. /* PHY use is optional */
  81. pcie->phy = devm_phy_optional_get(dev, "pcie-phy");
  82. if (IS_ERR(pcie->phy))
  83. return PTR_ERR(pcie->phy);
  84. /* PAXC doesn't support legacy IRQs, skip mapping */
  85. switch (pcie->type) {
  86. case IPROC_PCIE_PAXC:
  87. case IPROC_PCIE_PAXC_V2:
  88. pcie->map_irq = NULL;
  89. break;
  90. default:
  91. break;
  92. }
  93. ret = iproc_pcie_setup(pcie, &bridge->windows);
  94. if (ret) {
  95. dev_err(dev, "PCIe controller setup failed\n");
  96. return ret;
  97. }
  98. platform_set_drvdata(pdev, pcie);
  99. return 0;
  100. }
  101. static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
  102. {
  103. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  104. return iproc_pcie_remove(pcie);
  105. }
  106. static void iproc_pcie_pltfm_shutdown(struct platform_device *pdev)
  107. {
  108. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  109. iproc_pcie_shutdown(pcie);
  110. }
  111. static struct platform_driver iproc_pcie_pltfm_driver = {
  112. .driver = {
  113. .name = "iproc-pcie",
  114. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  115. },
  116. .probe = iproc_pcie_pltfm_probe,
  117. .remove = iproc_pcie_pltfm_remove,
  118. .shutdown = iproc_pcie_pltfm_shutdown,
  119. };
  120. module_platform_driver(iproc_pcie_pltfm_driver);
  121. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  122. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  123. MODULE_LICENSE("GPL v2");