pci-layerscape.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * PCIe host controller driver for Freescale Layerscape SoCs
  4. *
  5. * Copyright (C) 2014 Freescale Semiconductor.
  6. * Copyright 2021 NXP
  7. *
  8. * Author: Minghuan Lian <[email protected]>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/of_pci.h>
  14. #include <linux/of_platform.h>
  15. #include <linux/of_irq.h>
  16. #include <linux/of_address.h>
  17. #include <linux/pci.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/resource.h>
  20. #include <linux/mfd/syscon.h>
  21. #include <linux/regmap.h>
  22. #include "pcie-designware.h"
  23. /* PEX Internal Configuration Registers */
  24. #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */
  25. #define PCIE_ABSERR 0x8d0 /* Bridge Slave Error Response Register */
  26. #define PCIE_ABSERR_SETTING 0x9401 /* Forward error of non-posted request */
  27. #define PCIE_IATU_NUM 6
  28. struct ls_pcie {
  29. struct dw_pcie *pci;
  30. };
  31. #define to_ls_pcie(x) dev_get_drvdata((x)->dev)
  32. static bool ls_pcie_is_bridge(struct ls_pcie *pcie)
  33. {
  34. struct dw_pcie *pci = pcie->pci;
  35. u32 header_type;
  36. header_type = ioread8(pci->dbi_base + PCI_HEADER_TYPE);
  37. header_type &= 0x7f;
  38. return header_type == PCI_HEADER_TYPE_BRIDGE;
  39. }
  40. /* Clear multi-function bit */
  41. static void ls_pcie_clear_multifunction(struct ls_pcie *pcie)
  42. {
  43. struct dw_pcie *pci = pcie->pci;
  44. iowrite8(PCI_HEADER_TYPE_BRIDGE, pci->dbi_base + PCI_HEADER_TYPE);
  45. }
  46. /* Drop MSG TLP except for Vendor MSG */
  47. static void ls_pcie_drop_msg_tlp(struct ls_pcie *pcie)
  48. {
  49. u32 val;
  50. struct dw_pcie *pci = pcie->pci;
  51. val = ioread32(pci->dbi_base + PCIE_STRFMR1);
  52. val &= 0xDFFFFFFF;
  53. iowrite32(val, pci->dbi_base + PCIE_STRFMR1);
  54. }
  55. /* Forward error response of outbound non-posted requests */
  56. static void ls_pcie_fix_error_response(struct ls_pcie *pcie)
  57. {
  58. struct dw_pcie *pci = pcie->pci;
  59. iowrite32(PCIE_ABSERR_SETTING, pci->dbi_base + PCIE_ABSERR);
  60. }
  61. static int ls_pcie_host_init(struct dw_pcie_rp *pp)
  62. {
  63. struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
  64. struct ls_pcie *pcie = to_ls_pcie(pci);
  65. ls_pcie_fix_error_response(pcie);
  66. dw_pcie_dbi_ro_wr_en(pci);
  67. ls_pcie_clear_multifunction(pcie);
  68. dw_pcie_dbi_ro_wr_dis(pci);
  69. ls_pcie_drop_msg_tlp(pcie);
  70. return 0;
  71. }
  72. static const struct dw_pcie_host_ops ls_pcie_host_ops = {
  73. .host_init = ls_pcie_host_init,
  74. };
  75. static const struct of_device_id ls_pcie_of_match[] = {
  76. { .compatible = "fsl,ls1012a-pcie", },
  77. { .compatible = "fsl,ls1021a-pcie", },
  78. { .compatible = "fsl,ls1028a-pcie", },
  79. { .compatible = "fsl,ls1043a-pcie", },
  80. { .compatible = "fsl,ls1046a-pcie", },
  81. { .compatible = "fsl,ls2080a-pcie", },
  82. { .compatible = "fsl,ls2085a-pcie", },
  83. { .compatible = "fsl,ls2088a-pcie", },
  84. { .compatible = "fsl,ls1088a-pcie", },
  85. { },
  86. };
  87. static int ls_pcie_probe(struct platform_device *pdev)
  88. {
  89. struct device *dev = &pdev->dev;
  90. struct dw_pcie *pci;
  91. struct ls_pcie *pcie;
  92. struct resource *dbi_base;
  93. pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
  94. if (!pcie)
  95. return -ENOMEM;
  96. pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
  97. if (!pci)
  98. return -ENOMEM;
  99. pci->dev = dev;
  100. pci->pp.ops = &ls_pcie_host_ops;
  101. pcie->pci = pci;
  102. dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
  103. pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
  104. if (IS_ERR(pci->dbi_base))
  105. return PTR_ERR(pci->dbi_base);
  106. if (!ls_pcie_is_bridge(pcie))
  107. return -ENODEV;
  108. platform_set_drvdata(pdev, pcie);
  109. return dw_pcie_host_init(&pci->pp);
  110. }
  111. static struct platform_driver ls_pcie_driver = {
  112. .probe = ls_pcie_probe,
  113. .driver = {
  114. .name = "layerscape-pcie",
  115. .of_match_table = ls_pcie_of_match,
  116. .suppress_bind_attrs = true,
  117. },
  118. };
  119. builtin_platform_driver(ls_pcie_driver);