pcie-iproc-platform.c 3.9 KB

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