phy-exynos-pcie.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Samsung Exynos SoC series PCIe PHY driver
  4. *
  5. * Phy provider for PCIe controller on Exynos SoC series
  6. *
  7. * Copyright (C) 2017-2020 Samsung Electronics Co., Ltd.
  8. * Jaehoon Chung <[email protected]>
  9. */
  10. #include <linux/io.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/of_platform.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/phy/phy.h>
  15. #include <linux/regmap.h>
  16. #define PCIE_PHY_OFFSET(x) ((x) * 0x4)
  17. /* Sysreg FSYS register offsets and bits for Exynos5433 */
  18. #define PCIE_EXYNOS5433_PHY_MAC_RESET 0x0208
  19. #define PCIE_MAC_RESET_MASK 0xFF
  20. #define PCIE_MAC_RESET BIT(4)
  21. #define PCIE_EXYNOS5433_PHY_L1SUB_CM_CON 0x1010
  22. #define PCIE_REFCLK_GATING_EN BIT(0)
  23. #define PCIE_EXYNOS5433_PHY_COMMON_RESET 0x1020
  24. #define PCIE_PHY_RESET BIT(0)
  25. #define PCIE_EXYNOS5433_PHY_GLOBAL_RESET 0x1040
  26. #define PCIE_GLOBAL_RESET BIT(0)
  27. #define PCIE_REFCLK BIT(1)
  28. #define PCIE_REFCLK_MASK 0x16
  29. #define PCIE_APP_REQ_EXIT_L1_MODE BIT(5)
  30. /* PMU PCIE PHY isolation control */
  31. #define EXYNOS5433_PMU_PCIE_PHY_OFFSET 0x730
  32. /* For Exynos pcie phy */
  33. struct exynos_pcie_phy {
  34. void __iomem *base;
  35. struct regmap *pmureg;
  36. struct regmap *fsysreg;
  37. };
  38. static void exynos_pcie_phy_writel(void __iomem *base, u32 val, u32 offset)
  39. {
  40. writel(val, base + offset);
  41. }
  42. /* Exynos5433 specific functions */
  43. static int exynos5433_pcie_phy_init(struct phy *phy)
  44. {
  45. struct exynos_pcie_phy *ep = phy_get_drvdata(phy);
  46. regmap_update_bits(ep->pmureg, EXYNOS5433_PMU_PCIE_PHY_OFFSET,
  47. BIT(0), 1);
  48. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
  49. PCIE_APP_REQ_EXIT_L1_MODE, 0);
  50. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_L1SUB_CM_CON,
  51. PCIE_REFCLK_GATING_EN, 0);
  52. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_COMMON_RESET,
  53. PCIE_PHY_RESET, 1);
  54. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_MAC_RESET,
  55. PCIE_MAC_RESET, 0);
  56. /* PHY refclk 24MHz */
  57. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
  58. PCIE_REFCLK_MASK, PCIE_REFCLK);
  59. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_GLOBAL_RESET,
  60. PCIE_GLOBAL_RESET, 0);
  61. exynos_pcie_phy_writel(ep->base, 0x11, PCIE_PHY_OFFSET(0x3));
  62. /* band gap reference on */
  63. exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x20));
  64. exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x4b));
  65. /* jitter tuning */
  66. exynos_pcie_phy_writel(ep->base, 0x34, PCIE_PHY_OFFSET(0x4));
  67. exynos_pcie_phy_writel(ep->base, 0x02, PCIE_PHY_OFFSET(0x7));
  68. exynos_pcie_phy_writel(ep->base, 0x41, PCIE_PHY_OFFSET(0x21));
  69. exynos_pcie_phy_writel(ep->base, 0x7F, PCIE_PHY_OFFSET(0x14));
  70. exynos_pcie_phy_writel(ep->base, 0xC0, PCIE_PHY_OFFSET(0x15));
  71. exynos_pcie_phy_writel(ep->base, 0x61, PCIE_PHY_OFFSET(0x36));
  72. /* D0 uninit.. */
  73. exynos_pcie_phy_writel(ep->base, 0x44, PCIE_PHY_OFFSET(0x3D));
  74. /* 24MHz */
  75. exynos_pcie_phy_writel(ep->base, 0x94, PCIE_PHY_OFFSET(0x8));
  76. exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x9));
  77. exynos_pcie_phy_writel(ep->base, 0x93, PCIE_PHY_OFFSET(0xA));
  78. exynos_pcie_phy_writel(ep->base, 0x6B, PCIE_PHY_OFFSET(0xC));
  79. exynos_pcie_phy_writel(ep->base, 0xA5, PCIE_PHY_OFFSET(0xF));
  80. exynos_pcie_phy_writel(ep->base, 0x34, PCIE_PHY_OFFSET(0x16));
  81. exynos_pcie_phy_writel(ep->base, 0xA3, PCIE_PHY_OFFSET(0x17));
  82. exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x1A));
  83. exynos_pcie_phy_writel(ep->base, 0x71, PCIE_PHY_OFFSET(0x23));
  84. exynos_pcie_phy_writel(ep->base, 0x4C, PCIE_PHY_OFFSET(0x24));
  85. exynos_pcie_phy_writel(ep->base, 0x0E, PCIE_PHY_OFFSET(0x26));
  86. exynos_pcie_phy_writel(ep->base, 0x14, PCIE_PHY_OFFSET(0x7));
  87. exynos_pcie_phy_writel(ep->base, 0x48, PCIE_PHY_OFFSET(0x43));
  88. exynos_pcie_phy_writel(ep->base, 0x44, PCIE_PHY_OFFSET(0x44));
  89. exynos_pcie_phy_writel(ep->base, 0x03, PCIE_PHY_OFFSET(0x45));
  90. exynos_pcie_phy_writel(ep->base, 0xA7, PCIE_PHY_OFFSET(0x48));
  91. exynos_pcie_phy_writel(ep->base, 0x13, PCIE_PHY_OFFSET(0x54));
  92. exynos_pcie_phy_writel(ep->base, 0x04, PCIE_PHY_OFFSET(0x31));
  93. exynos_pcie_phy_writel(ep->base, 0, PCIE_PHY_OFFSET(0x32));
  94. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_COMMON_RESET,
  95. PCIE_PHY_RESET, 0);
  96. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_MAC_RESET,
  97. PCIE_MAC_RESET_MASK, PCIE_MAC_RESET);
  98. return 0;
  99. }
  100. static int exynos5433_pcie_phy_exit(struct phy *phy)
  101. {
  102. struct exynos_pcie_phy *ep = phy_get_drvdata(phy);
  103. regmap_update_bits(ep->fsysreg, PCIE_EXYNOS5433_PHY_L1SUB_CM_CON,
  104. PCIE_REFCLK_GATING_EN, PCIE_REFCLK_GATING_EN);
  105. regmap_update_bits(ep->pmureg, EXYNOS5433_PMU_PCIE_PHY_OFFSET,
  106. BIT(0), 0);
  107. return 0;
  108. }
  109. static const struct phy_ops exynos5433_phy_ops = {
  110. .init = exynos5433_pcie_phy_init,
  111. .exit = exynos5433_pcie_phy_exit,
  112. .owner = THIS_MODULE,
  113. };
  114. static const struct of_device_id exynos_pcie_phy_match[] = {
  115. {
  116. .compatible = "samsung,exynos5433-pcie-phy",
  117. },
  118. {},
  119. };
  120. static int exynos_pcie_phy_probe(struct platform_device *pdev)
  121. {
  122. struct device *dev = &pdev->dev;
  123. struct exynos_pcie_phy *exynos_phy;
  124. struct phy *generic_phy;
  125. struct phy_provider *phy_provider;
  126. exynos_phy = devm_kzalloc(dev, sizeof(*exynos_phy), GFP_KERNEL);
  127. if (!exynos_phy)
  128. return -ENOMEM;
  129. exynos_phy->base = devm_platform_ioremap_resource(pdev, 0);
  130. if (IS_ERR(exynos_phy->base))
  131. return PTR_ERR(exynos_phy->base);
  132. exynos_phy->pmureg = syscon_regmap_lookup_by_phandle(dev->of_node,
  133. "samsung,pmu-syscon");
  134. if (IS_ERR(exynos_phy->pmureg)) {
  135. dev_err(&pdev->dev, "PMU regmap lookup failed.\n");
  136. return PTR_ERR(exynos_phy->pmureg);
  137. }
  138. exynos_phy->fsysreg = syscon_regmap_lookup_by_phandle(dev->of_node,
  139. "samsung,fsys-sysreg");
  140. if (IS_ERR(exynos_phy->fsysreg)) {
  141. dev_err(&pdev->dev, "FSYS sysreg regmap lookup failed.\n");
  142. return PTR_ERR(exynos_phy->fsysreg);
  143. }
  144. generic_phy = devm_phy_create(dev, dev->of_node, &exynos5433_phy_ops);
  145. if (IS_ERR(generic_phy)) {
  146. dev_err(dev, "failed to create PHY\n");
  147. return PTR_ERR(generic_phy);
  148. }
  149. phy_set_drvdata(generic_phy, exynos_phy);
  150. phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
  151. return PTR_ERR_OR_ZERO(phy_provider);
  152. }
  153. static struct platform_driver exynos_pcie_phy_driver = {
  154. .probe = exynos_pcie_phy_probe,
  155. .driver = {
  156. .of_match_table = exynos_pcie_phy_match,
  157. .name = "exynos_pcie_phy",
  158. .suppress_bind_attrs = true,
  159. }
  160. };
  161. builtin_platform_driver(exynos_pcie_phy_driver);