dp_pll.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __DP_PLL_H
  6. #define __DP_PLL_H
  7. #include <linux/io.h>
  8. #include <linux/clk-provider.h>
  9. #include <linux/of_device.h>
  10. #include "dp_parser.h"
  11. #include "sde_dbg.h"
  12. #define DP_VCO_HSCLK_RATE_1620MHZDIV1000 1620000UL
  13. #define DP_VCO_HSCLK_RATE_2700MHZDIV1000 2700000UL
  14. #define DP_VCO_HSCLK_RATE_5400MHZDIV1000 5400000UL
  15. #define DP_VCO_HSCLK_RATE_8100MHZDIV1000 8100000UL
  16. #define dp_pll_get_base(x) pll->io.x->io.base
  17. #define dp_pll_read(x, offset) ({ \
  18. readl_relaxed((dp_pll_get_base(x)) + (offset)); \
  19. })
  20. #define dp_pll_write(x, offset, data) ({ \
  21. DP_DEBUG(#offset", addr=0x%x, val=0x%x\n", \
  22. (dp_pll_get_base(x)) + (offset), (data)); \
  23. SDE_EVT32_VERBOSE((dp_pll_get_base(x)) + (offset), (data)); \
  24. writel_relaxed((data), (dp_pll_get_base(x)) + (offset)); \
  25. })
  26. enum dp_pll_revision {
  27. DP_PLL_UNKNOWN,
  28. DP_PLL_5NM_V1,
  29. DP_PLL_5NM_V2,
  30. };
  31. static inline const char *dp_pll_get_revision(enum dp_pll_revision rev)
  32. {
  33. switch (rev) {
  34. case DP_PLL_UNKNOWN: return "DP_PLL_UNKNOWN";
  35. case DP_PLL_5NM_V1: return "DP_PLL_5NM_V1";
  36. case DP_PLL_5NM_V2: return "DP_PLL_5NM_V2";
  37. default: return "???";
  38. }
  39. }
  40. struct dp_pll_io {
  41. struct dp_io_data *dp_phy;
  42. struct dp_io_data *dp_pll;
  43. struct dp_io_data *dp_ln_tx0;
  44. struct dp_io_data *dp_ln_tx1;
  45. struct dp_io_data *gdsc;
  46. };
  47. struct dp_pll_vco_clk {
  48. struct clk_hw hw;
  49. unsigned long rate; /* current vco rate */
  50. u64 min_rate; /* min vco rate */
  51. u64 max_rate; /* max vco rate */
  52. void *priv;
  53. };
  54. struct dp_pll {
  55. /*
  56. * target pll revision information
  57. */
  58. u32 revision;
  59. /*
  60. * Certain plls needs to update the same vco rate after resume in
  61. * suspend/resume scenario. Cached the vco rate for such plls.
  62. */
  63. unsigned long vco_cached_rate;
  64. /*
  65. * PLL index if multiple index are available. Eg. in case of
  66. * DSI we have 2 plls.
  67. */
  68. uint32_t index;
  69. bool ssc_en;
  70. bool bonding_en;
  71. void *priv;
  72. struct platform_device *pdev;
  73. struct dp_parser *parser;
  74. struct dp_power *power;
  75. struct dp_aux *aux;
  76. struct dp_pll_io io;
  77. struct clk_onecell_data *clk_data;
  78. };
  79. struct dp_pll_db {
  80. struct dp_pll *pll;
  81. /* lane and orientation settings */
  82. u8 lane_cnt;
  83. u8 orientation;
  84. /* COM PHY settings */
  85. u32 hsclk_sel;
  86. u32 dec_start_mode0;
  87. u32 div_frac_start1_mode0;
  88. u32 div_frac_start2_mode0;
  89. u32 div_frac_start3_mode0;
  90. u32 integloop_gain0_mode0;
  91. u32 integloop_gain1_mode0;
  92. u32 lock_cmp1_mode0;
  93. u32 lock_cmp2_mode0;
  94. u32 lock_cmp_en;
  95. u32 ssc_step_size1_mode0;
  96. u32 ssc_step_size2_mode0;
  97. /* PHY vco divider */
  98. u32 phy_vco_div;
  99. };
  100. static inline struct dp_pll_vco_clk *to_dp_vco_hw(struct clk_hw *hw)
  101. {
  102. return container_of(hw, struct dp_pll_vco_clk, hw);
  103. }
  104. static inline bool is_gdsc_disabled(struct dp_pll *pll)
  105. {
  106. return (dp_pll_read(gdsc, 0x0) & BIT(31)) ? false : true;
  107. }
  108. int dp_pll_clock_register_5nm(struct dp_pll *pll);
  109. void dp_pll_clock_unregister_5nm(struct dp_pll *pll);
  110. struct dp_pll_in {
  111. struct platform_device *pdev;
  112. struct dp_aux *aux;
  113. struct dp_parser *parser;
  114. };
  115. struct dp_pll *dp_pll_get(struct dp_pll_in *in);
  116. void dp_pll_put(struct dp_pll *pll);
  117. #endif /* __DP_PLL_H */