pcie-iproc-platform.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. const struct of_device_id *of_id;
  47. struct iproc_pcie *pcie;
  48. struct device_node *np = dev->of_node;
  49. struct resource reg;
  50. resource_size_t iobase = 0;
  51. LIST_HEAD(res);
  52. int ret;
  53. of_id = of_match_device(iproc_pcie_of_match_table, dev);
  54. if (!of_id)
  55. return -EINVAL;
  56. pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
  57. if (!pcie)
  58. return -ENOMEM;
  59. pcie->dev = dev;
  60. pcie->type = (enum iproc_pcie_type)of_id->data;
  61. ret = of_address_to_resource(np, 0, &reg);
  62. if (ret < 0) {
  63. dev_err(dev, "unable to obtain controller resources\n");
  64. return ret;
  65. }
  66. pcie->base = devm_ioremap(dev, reg.start, resource_size(&reg));
  67. if (!pcie->base) {
  68. dev_err(dev, "unable to map controller registers\n");
  69. return -ENOMEM;
  70. }
  71. pcie->base_addr = reg.start;
  72. if (of_property_read_bool(np, "brcm,pcie-ob")) {
  73. u32 val;
  74. ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
  75. &val);
  76. if (ret) {
  77. dev_err(dev,
  78. "missing brcm,pcie-ob-axi-offset property\n");
  79. return ret;
  80. }
  81. pcie->ob.axi_offset = val;
  82. pcie->need_ob_cfg = true;
  83. }
  84. /* PHY use is optional */
  85. pcie->phy = devm_phy_get(dev, "pcie-phy");
  86. if (IS_ERR(pcie->phy)) {
  87. if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
  88. return -EPROBE_DEFER;
  89. pcie->phy = NULL;
  90. }
  91. ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
  92. if (ret) {
  93. dev_err(dev,
  94. "unable to get PCI host bridge resources\n");
  95. return ret;
  96. }
  97. /* PAXC doesn't support legacy IRQs, skip mapping */
  98. switch (pcie->type) {
  99. case IPROC_PCIE_PAXC:
  100. case IPROC_PCIE_PAXC_V2:
  101. break;
  102. default:
  103. pcie->map_irq = of_irq_parse_and_map_pci;
  104. }
  105. ret = iproc_pcie_setup(pcie, &res);
  106. if (ret)
  107. dev_err(dev, "PCIe controller setup failed\n");
  108. pci_free_resource_list(&res);
  109. platform_set_drvdata(pdev, pcie);
  110. return ret;
  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 struct platform_driver iproc_pcie_pltfm_driver = {
  118. .driver = {
  119. .name = "iproc-pcie",
  120. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  121. },
  122. .probe = iproc_pcie_pltfm_probe,
  123. .remove = iproc_pcie_pltfm_remove,
  124. };
  125. module_platform_driver(iproc_pcie_pltfm_driver);
  126. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  127. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  128. MODULE_LICENSE("GPL v2");