pcie-iproc-platform.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 int iproc_pcie_pltfm_probe(struct platform_device *pdev)
  27. {
  28. struct iproc_pcie *pcie;
  29. struct device_node *np = pdev->dev.of_node;
  30. struct resource reg;
  31. resource_size_t iobase = 0;
  32. LIST_HEAD(res);
  33. int ret;
  34. pcie = devm_kzalloc(&pdev->dev, sizeof(struct iproc_pcie), GFP_KERNEL);
  35. if (!pcie)
  36. return -ENOMEM;
  37. pcie->dev = &pdev->dev;
  38. platform_set_drvdata(pdev, pcie);
  39. ret = of_address_to_resource(np, 0, &reg);
  40. if (ret < 0) {
  41. dev_err(pcie->dev, "unable to obtain controller resources\n");
  42. return ret;
  43. }
  44. pcie->base = devm_ioremap(pcie->dev, reg.start, resource_size(&reg));
  45. if (!pcie->base) {
  46. dev_err(pcie->dev, "unable to map controller registers\n");
  47. return -ENOMEM;
  48. }
  49. if (of_property_read_bool(np, "brcm,pcie-ob")) {
  50. u32 val;
  51. ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
  52. &val);
  53. if (ret) {
  54. dev_err(pcie->dev,
  55. "missing brcm,pcie-ob-axi-offset property\n");
  56. return ret;
  57. }
  58. pcie->ob.axi_offset = val;
  59. ret = of_property_read_u32(np, "brcm,pcie-ob-window-size",
  60. &val);
  61. if (ret) {
  62. dev_err(pcie->dev,
  63. "missing brcm,pcie-ob-window-size property\n");
  64. return ret;
  65. }
  66. pcie->ob.window_size = (resource_size_t)val * SZ_1M;
  67. if (of_property_read_bool(np, "brcm,pcie-ob-oarr-size"))
  68. pcie->ob.set_oarr_size = true;
  69. pcie->need_ob_cfg = true;
  70. }
  71. /* PHY use is optional */
  72. pcie->phy = devm_phy_get(&pdev->dev, "pcie-phy");
  73. if (IS_ERR(pcie->phy)) {
  74. if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
  75. return -EPROBE_DEFER;
  76. pcie->phy = NULL;
  77. }
  78. ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
  79. if (ret) {
  80. dev_err(pcie->dev,
  81. "unable to get PCI host bridge resources\n");
  82. return ret;
  83. }
  84. pcie->map_irq = of_irq_parse_and_map_pci;
  85. ret = iproc_pcie_setup(pcie, &res);
  86. if (ret)
  87. dev_err(pcie->dev, "PCIe controller setup failed\n");
  88. pci_free_resource_list(&res);
  89. return ret;
  90. }
  91. static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
  92. {
  93. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  94. return iproc_pcie_remove(pcie);
  95. }
  96. static const struct of_device_id iproc_pcie_of_match_table[] = {
  97. { .compatible = "brcm,iproc-pcie", },
  98. { /* sentinel */ }
  99. };
  100. MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
  101. static struct platform_driver iproc_pcie_pltfm_driver = {
  102. .driver = {
  103. .name = "iproc-pcie",
  104. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  105. },
  106. .probe = iproc_pcie_pltfm_probe,
  107. .remove = iproc_pcie_pltfm_remove,
  108. };
  109. module_platform_driver(iproc_pcie_pltfm_driver);
  110. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  111. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  112. MODULE_LICENSE("GPL v2");