dp_pll.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  4. * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  5. */
  6. #ifndef __DP_PLL_H
  7. #define __DP_PLL_H
  8. #include <linux/io.h>
  9. #include <linux/clk-provider.h>
  10. #include <linux/of_device.h>
  11. #include "dp_parser.h"
  12. #include "sde_dbg.h"
  13. #define DP_VCO_HSCLK_RATE_1620MHZDIV1000 1620000UL
  14. #define DP_VCO_HSCLK_RATE_2700MHZDIV1000 2700000UL
  15. #define DP_VCO_HSCLK_RATE_5400MHZDIV1000 5400000UL
  16. #define DP_VCO_HSCLK_RATE_8100MHZDIV1000 8100000UL
  17. #define DP_PHY_VCO_DIV 0x0070
  18. #define dp_pll_get_base(x) pll->io.x->io.base
  19. #define dp_pll_read(x, offset) ({ \
  20. readl_relaxed((dp_pll_get_base(x)) + (offset)); \
  21. })
  22. #define dp_pll_write(x, offset, data) ({ \
  23. DP_DEBUG(#offset", addr=0x%llx, val=0x%x\n", \
  24. ((u64)(dp_pll_get_base(x)) + (offset)), (data)); \
  25. SDE_EVT32_VERBOSE((dp_pll_get_base(x)) + (offset), (data)); \
  26. writel_relaxed((data), (dp_pll_get_base(x)) + (offset)); \
  27. })
  28. enum dp_pll_revision {
  29. DP_PLL_UNKNOWN,
  30. DP_PLL_5NM_V1,
  31. DP_PLL_5NM_V2,
  32. DP_PLL_4NM_V1,
  33. DP_PLL_4NM_V1_1,
  34. };
  35. enum hsclk_rate {
  36. HSCLK_RATE_1620MHZ,
  37. HSCLK_RATE_2700MHZ,
  38. HSCLK_RATE_5400MHZ,
  39. HSCLK_RATE_8100MHZ,
  40. HSCLK_RATE_MAX,
  41. };
  42. static inline const char *dp_pll_get_revision(enum dp_pll_revision rev)
  43. {
  44. switch (rev) {
  45. case DP_PLL_UNKNOWN: return "DP_PLL_UNKNOWN";
  46. case DP_PLL_5NM_V1: return "DP_PLL_5NM_V1";
  47. case DP_PLL_5NM_V2: return "DP_PLL_5NM_V2";
  48. case DP_PLL_4NM_V1: return "DP_PLL_4NM_V1";
  49. case DP_PLL_4NM_V1_1: return "DP_PLL_4NM_V1_1";
  50. default: return "???";
  51. }
  52. }
  53. struct dp_pll_io {
  54. struct dp_io_data *dp_phy;
  55. struct dp_io_data *dp_pll;
  56. struct dp_io_data *dp_ln_tx0;
  57. struct dp_io_data *dp_ln_tx1;
  58. struct dp_io_data *gdsc;
  59. };
  60. struct dp_pll_vco_clk {
  61. struct clk_hw hw;
  62. void *priv;
  63. };
  64. struct dp_pll {
  65. /* target pll revision information */
  66. u32 revision;
  67. /* save vco current rate */
  68. unsigned long vco_rate;
  69. /*
  70. * PLL index if multiple index are available. Eg. in case of
  71. * DSI we have 2 plls.
  72. */
  73. uint32_t index;
  74. bool ssc_en;
  75. bool bonding_en;
  76. void *priv;
  77. struct platform_device *pdev;
  78. struct dp_parser *parser;
  79. struct dp_power *power;
  80. struct dp_aux *aux;
  81. struct dp_pll_io io;
  82. struct clk_onecell_data *clk_data;
  83. u32 dp_core_revision;
  84. u32 clk_factor;
  85. int (*pll_cfg)(struct dp_pll *pll, unsigned long rate);
  86. int (*pll_prepare)(struct dp_pll *pll);
  87. int (*pll_unprepare)(struct dp_pll *pll);
  88. };
  89. struct dp_pll_params {
  90. /* COM PHY settings */
  91. u32 hsclk_sel;
  92. u32 integloop_gain0_mode0;
  93. u32 integloop_gain1_mode0;
  94. u32 lock_cmp_en;
  95. /* PHY vco divider */
  96. u32 phy_vco_div;
  97. u32 dec_start_mode0;
  98. u32 div_frac_start1_mode0;
  99. u32 div_frac_start2_mode0;
  100. u32 div_frac_start3_mode0;
  101. u32 lock_cmp1_mode0;
  102. u32 lock_cmp2_mode0;
  103. u32 ssc_step_size1_mode0;
  104. u32 ssc_step_size2_mode0;
  105. u32 ssc_per1;
  106. u32 ssc_per2;
  107. u32 cmp_code1_mode0;
  108. u32 cmp_code2_mode0;
  109. u32 pll_ivco;
  110. u32 bg_timer;
  111. u32 core_clk_en;
  112. u32 lane_offset_tx;
  113. u32 lane_offset_rx;
  114. };
  115. struct dp_pll_db {
  116. struct dp_pll *pll;
  117. /* lane and orientation settings */
  118. u8 lane_cnt;
  119. u8 orientation;
  120. u32 rate_idx;
  121. const struct dp_pll_params *pll_params;
  122. };
  123. static inline struct dp_pll_vco_clk *to_dp_vco_hw(struct clk_hw *hw)
  124. {
  125. return container_of(hw, struct dp_pll_vco_clk, hw);
  126. }
  127. static inline bool is_gdsc_disabled(struct dp_pll *pll)
  128. {
  129. return (dp_pll_read(gdsc, 0x0) & BIT(31)) ? false : true;
  130. }
  131. int dp_pll_clock_register_5nm(struct dp_pll *pll);
  132. void dp_pll_clock_unregister_5nm(struct dp_pll *pll);
  133. int dp_pll_clock_register_4nm(struct dp_pll *pll);
  134. void dp_pll_clock_unregister_4nm(struct dp_pll *pll);
  135. struct dp_pll_in {
  136. struct platform_device *pdev;
  137. struct dp_aux *aux;
  138. struct dp_parser *parser;
  139. u32 dp_core_revision;
  140. };
  141. int dp_pll_clock_register_helper(struct dp_pll *pll, struct dp_pll_vco_clk *clks, int num_clks);
  142. struct dp_pll *dp_pll_get(struct dp_pll_in *in);
  143. void dp_pll_put(struct dp_pll *pll);
  144. #endif /* __DP_PLL_H */