pcie-iproc-platform.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. /* PHY use is optional */
  50. pcie->phy = devm_phy_get(&pdev->dev, "pcie-phy");
  51. if (IS_ERR(pcie->phy)) {
  52. if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
  53. return -EPROBE_DEFER;
  54. pcie->phy = NULL;
  55. }
  56. ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
  57. if (ret) {
  58. dev_err(pcie->dev,
  59. "unable to get PCI host bridge resources\n");
  60. return ret;
  61. }
  62. pcie->map_irq = of_irq_parse_and_map_pci;
  63. ret = iproc_pcie_setup(pcie, &res);
  64. if (ret)
  65. dev_err(pcie->dev, "PCIe controller setup failed\n");
  66. pci_free_resource_list(&res);
  67. return ret;
  68. }
  69. static int iproc_pcie_pltfm_remove(struct platform_device *pdev)
  70. {
  71. struct iproc_pcie *pcie = platform_get_drvdata(pdev);
  72. return iproc_pcie_remove(pcie);
  73. }
  74. static const struct of_device_id iproc_pcie_of_match_table[] = {
  75. { .compatible = "brcm,iproc-pcie", },
  76. { /* sentinel */ }
  77. };
  78. MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
  79. static struct platform_driver iproc_pcie_pltfm_driver = {
  80. .driver = {
  81. .name = "iproc-pcie",
  82. .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
  83. },
  84. .probe = iproc_pcie_pltfm_probe,
  85. .remove = iproc_pcie_pltfm_remove,
  86. };
  87. module_platform_driver(iproc_pcie_pltfm_driver);
  88. MODULE_AUTHOR("Ray Jui <rjui@broadcom.com>");
  89. MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
  90. MODULE_LICENSE("GPL v2");