0077-v6.0-PCI-qcom-Add-IPQ60xx-support.patch 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. From a7d96ca20847ade9f29cff4521f43b8ae968b3df Mon Sep 17 00:00:00 2001
  2. From: Selvam Sathappan Periakaruppan <[email protected]>
  3. Date: Tue, 21 Jun 2022 11:54:54 +0300
  4. Subject: [PATCH] PCI: qcom: Add IPQ60xx support
  5. IPQ60xx series of SoCs have one port of PCIe gen 3. Add support for that
  6. platform.
  7. The code is based on downstream[1] Codeaurora kernel v5.4 (branch
  8. win.linuxopenwrt.2.0).
  9. Split out the DBI registers access part from .init into .post_init. DBI
  10. registers are only accessible after phy_power_on().
  11. [1] https://source.codeaurora.org/quic/qsdk/oss/kernel/linux-ipq-5.4/
  12. Link: https://lore.kernel.org/r/f7f848653c99abbf9a0f877949a44e52329543ae.1655799816.git.baruch@tkos.co.il
  13. Tested-by: Robert Marko <[email protected]>
  14. Signed-off-by: Selvam Sathappan Periakaruppan <[email protected]>
  15. Signed-off-by: Baruch Siach <[email protected]>
  16. Signed-off-by: Bjorn Helgaas <[email protected]>
  17. Reviewed-by: Rob Herring <[email protected]>
  18. Reviewed-by: Johan Hovold <[email protected]>
  19. Acked-by: Stanimir Varbanov <[email protected]>
  20. ---
  21. drivers/pci/controller/dwc/pcie-designware.h | 1 +
  22. drivers/pci/controller/dwc/pcie-qcom.c | 130 +++++++++++++++++++
  23. 2 files changed, 131 insertions(+)
  24. --- a/drivers/pci/controller/dwc/pcie-designware.h
  25. +++ b/drivers/pci/controller/dwc/pcie-designware.h
  26. @@ -76,6 +76,7 @@
  27. #define GEN3_RELATED_OFF 0x890
  28. #define GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL BIT(0)
  29. +#define GEN3_RELATED_OFF_RXEQ_RGRDLESS_RXTS BIT(13)
  30. #define GEN3_RELATED_OFF_GEN3_EQ_DISABLE BIT(16)
  31. #define GEN3_RELATED_OFF_RATE_SHADOW_SEL_SHIFT 24
  32. #define GEN3_RELATED_OFF_RATE_SHADOW_SEL_MASK GENMASK(25, 24)
  33. --- a/drivers/pci/controller/dwc/pcie-qcom.c
  34. +++ b/drivers/pci/controller/dwc/pcie-qcom.c
  35. @@ -52,6 +52,10 @@
  36. #define PCIE20_PARF_DBI_BASE_ADDR 0x168
  37. #define PCIE20_PARF_SLV_ADDR_SPACE_SIZE 0x16C
  38. #define PCIE20_PARF_MHI_CLOCK_RESET_CTRL 0x174
  39. +#define AHB_CLK_EN BIT(0)
  40. +#define MSTR_AXI_CLK_EN BIT(1)
  41. +#define BYPASS BIT(4)
  42. +
  43. #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT 0x178
  44. #define PCIE20_PARF_AXI_MSTR_WR_ADDR_HALT_V2 0x1A8
  45. #define PCIE20_PARF_LTSSM 0x1B0
  46. @@ -181,6 +185,11 @@ struct qcom_pcie_resources_2_7_0 {
  47. struct clk *pipe_clk;
  48. };
  49. +struct qcom_pcie_resources_2_9_0 {
  50. + struct clk_bulk_data clks[5];
  51. + struct reset_control *rst;
  52. +};
  53. +
  54. union qcom_pcie_resources {
  55. struct qcom_pcie_resources_1_0_0 v1_0_0;
  56. struct qcom_pcie_resources_2_1_0 v2_1_0;
  57. @@ -188,6 +197,7 @@ union qcom_pcie_resources {
  58. struct qcom_pcie_resources_2_3_3 v2_3_3;
  59. struct qcom_pcie_resources_2_4_0 v2_4_0;
  60. struct qcom_pcie_resources_2_7_0 v2_7_0;
  61. + struct qcom_pcie_resources_2_9_0 v2_9_0;
  62. };
  63. struct qcom_pcie;
  64. @@ -1282,6 +1292,112 @@ static void qcom_pcie_post_deinit_2_7_0(
  65. clk_disable_unprepare(res->pipe_clk);
  66. }
  67. +static int qcom_pcie_get_resources_2_9_0(struct qcom_pcie *pcie)
  68. +{
  69. + struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0;
  70. + struct dw_pcie *pci = pcie->pci;
  71. + struct device *dev = pci->dev;
  72. + int ret;
  73. +
  74. + res->clks[0].id = "iface";
  75. + res->clks[1].id = "axi_m";
  76. + res->clks[2].id = "axi_s";
  77. + res->clks[3].id = "axi_bridge";
  78. + res->clks[4].id = "rchng";
  79. +
  80. + ret = devm_clk_bulk_get(dev, ARRAY_SIZE(res->clks), res->clks);
  81. + if (ret < 0)
  82. + return ret;
  83. +
  84. + res->rst = devm_reset_control_array_get_exclusive(dev);
  85. + if (IS_ERR(res->rst))
  86. + return PTR_ERR(res->rst);
  87. +
  88. + return 0;
  89. +}
  90. +
  91. +static void qcom_pcie_deinit_2_9_0(struct qcom_pcie *pcie)
  92. +{
  93. + struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0;
  94. +
  95. + clk_bulk_disable_unprepare(ARRAY_SIZE(res->clks), res->clks);
  96. +}
  97. +
  98. +static int qcom_pcie_init_2_9_0(struct qcom_pcie *pcie)
  99. +{
  100. + struct qcom_pcie_resources_2_9_0 *res = &pcie->res.v2_9_0;
  101. + struct device *dev = pcie->pci->dev;
  102. + int ret;
  103. +
  104. + ret = reset_control_assert(res->rst);
  105. + if (ret) {
  106. + dev_err(dev, "reset assert failed (%d)\n", ret);
  107. + return ret;
  108. + }
  109. +
  110. + /*
  111. + * Delay periods before and after reset deassert are working values
  112. + * from downstream Codeaurora kernel
  113. + */
  114. + usleep_range(2000, 2500);
  115. +
  116. + ret = reset_control_deassert(res->rst);
  117. + if (ret) {
  118. + dev_err(dev, "reset deassert failed (%d)\n", ret);
  119. + return ret;
  120. + }
  121. +
  122. + usleep_range(2000, 2500);
  123. +
  124. + return clk_bulk_prepare_enable(ARRAY_SIZE(res->clks), res->clks);
  125. +}
  126. +
  127. +static int qcom_pcie_post_init_2_9_0(struct qcom_pcie *pcie)
  128. +{
  129. + struct dw_pcie *pci = pcie->pci;
  130. + u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
  131. + u32 val;
  132. + int i;
  133. +
  134. + writel(SLV_ADDR_SPACE_SZ,
  135. + pcie->parf + PCIE20_v3_PARF_SLV_ADDR_SPACE_SIZE);
  136. +
  137. + val = readl(pcie->parf + PCIE20_PARF_PHY_CTRL);
  138. + val &= ~BIT(0);
  139. + writel(val, pcie->parf + PCIE20_PARF_PHY_CTRL);
  140. +
  141. + writel(0, pcie->parf + PCIE20_PARF_DBI_BASE_ADDR);
  142. +
  143. + writel(DEVICE_TYPE_RC, pcie->parf + PCIE20_PARF_DEVICE_TYPE);
  144. + writel(BYPASS | MSTR_AXI_CLK_EN | AHB_CLK_EN,
  145. + pcie->parf + PCIE20_PARF_MHI_CLOCK_RESET_CTRL);
  146. + writel(GEN3_RELATED_OFF_RXEQ_RGRDLESS_RXTS |
  147. + GEN3_RELATED_OFF_GEN3_ZRXDC_NONCOMPL,
  148. + pci->dbi_base + GEN3_RELATED_OFF);
  149. +
  150. + writel(MST_WAKEUP_EN | SLV_WAKEUP_EN | MSTR_ACLK_CGC_DIS |
  151. + SLV_ACLK_CGC_DIS | CORE_CLK_CGC_DIS |
  152. + AUX_PWR_DET | L23_CLK_RMV_DIS | L1_CLK_RMV_DIS,
  153. + pcie->parf + PCIE20_PARF_SYS_CTRL);
  154. +
  155. + writel(0, pcie->parf + PCIE20_PARF_Q2A_FLUSH);
  156. +
  157. + dw_pcie_dbi_ro_wr_en(pci);
  158. + writel(PCIE_CAP_SLOT_VAL, pci->dbi_base + offset + PCI_EXP_SLTCAP);
  159. +
  160. + val = readl(pci->dbi_base + offset + PCI_EXP_LNKCAP);
  161. + val &= ~PCI_EXP_LNKCAP_ASPMS;
  162. + writel(val, pci->dbi_base + offset + PCI_EXP_LNKCAP);
  163. +
  164. + writel(PCI_EXP_DEVCTL2_COMP_TMOUT_DIS, pci->dbi_base + offset +
  165. + PCI_EXP_DEVCTL2);
  166. +
  167. + for (i = 0; i < 256; i++)
  168. + writel(0, pcie->parf + PCIE20_PARF_BDF_TO_SID_TABLE_N + (4 * i));
  169. +
  170. + return 0;
  171. +}
  172. +
  173. static int qcom_pcie_link_up(struct dw_pcie *pci)
  174. {
  175. u16 offset = dw_pcie_find_capability(pci, PCI_CAP_ID_EXP);
  176. @@ -1473,6 +1589,15 @@ static const struct qcom_pcie_ops ops_1_
  177. .config_sid = qcom_pcie_config_sid_sm8250,
  178. };
  179. +/* Qcom IP rev.: 2.9.0 Synopsys IP rev.: 5.00a */
  180. +static const struct qcom_pcie_ops ops_2_9_0 = {
  181. + .get_resources = qcom_pcie_get_resources_2_9_0,
  182. + .init = qcom_pcie_init_2_9_0,
  183. + .post_init = qcom_pcie_post_init_2_9_0,
  184. + .deinit = qcom_pcie_deinit_2_9_0,
  185. + .ltssm_enable = qcom_pcie_2_3_2_ltssm_enable,
  186. +};
  187. +
  188. static const struct qcom_pcie_cfg apq8084_cfg = {
  189. .ops = &ops_1_0_0,
  190. };
  191. @@ -1505,6 +1630,10 @@ static const struct qcom_pcie_cfg sc7280
  192. .ops = &ops_1_9_0,
  193. };
  194. +static const struct qcom_pcie_cfg ipq6018_cfg = {
  195. + .ops = &ops_2_9_0,
  196. +};
  197. +
  198. static const struct dw_pcie_ops dw_pcie_ops = {
  199. .link_up = qcom_pcie_link_up,
  200. .start_link = qcom_pcie_start_link,
  201. @@ -1611,6 +1740,7 @@ static const struct of_device_id qcom_pc
  202. { .compatible = "qcom,pcie-sdm845", .data = &sdm845_cfg },
  203. { .compatible = "qcom,pcie-sm8250", .data = &sm8250_cfg },
  204. { .compatible = "qcom,pcie-sc7280", .data = &sc7280_cfg },
  205. + { .compatible = "qcom,pcie-ipq6018", .data = &ipq6018_cfg },
  206. { }
  207. };