pcie-iproc-platform.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. int ret;
  52. pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
  53. if (!pcie)
  54. return -ENOMEM;
  55. pcie->dev = dev;
  56. pcie->type = (enum iproc_pcie_type) of_device_get_match_data(dev);
  57. ret = of_address_to_resource(np, 0, &reg);
  58. if (ret < 0) {
  59. dev_err(dev, "unable to obtain controller resources\n");
  60. return ret;
  61. }
  62. pcie->base = devm_pci_remap_cfgspace(dev, reg.start,
  63. resource_size(&reg));
  64. if (!pcie->base) {
  65. dev_err(dev, "unable to map controller registers\n");
  66. return -ENOMEM;
  67. }
  68. pcie->base_addr = reg.start;
  69. if (of_property_read_bool(np, "brcm,pcie-ob")) {
  70. u32 val;
  71. ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
  72. &val);
  73. if (ret) {
  74. dev_err(dev,
  75. "missing brcm,pcie-ob-axi-offset property\n");
  76. return ret;
  77. }
  78. pcie->ob.axi_offset = val;
  79. pcie->need_ob_cfg = true;
  80. }
  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 struct platform_driver iproc_pcie_pltfm_driver = {
  117. .driver = {
  118. .name = "iproc-pcie",
  119. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  120. },
  121. .probe = iproc_pcie_pltfm_probe,
  122. .remove = iproc_pcie_pltfm_remove,
  123. };
  124. module_platform_driver(iproc_pcie_pltfm_driver);
  125. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  126. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  127. MODULE_LICENSE("GPL v2");