dp_pll.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, 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%llx, val=0x%x\n", \
  22. ((u64)(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. void *priv;
  50. };
  51. struct dp_pll {
  52. /* target pll revision information */
  53. u32 revision;
  54. /* save vco current rate */
  55. unsigned long vco_rate;
  56. /*
  57. * PLL index if multiple index are available. Eg. in case of
  58. * DSI we have 2 plls.
  59. */
  60. uint32_t index;
  61. bool ssc_en;
  62. bool bonding_en;
  63. void *priv;
  64. struct platform_device *pdev;
  65. struct dp_parser *parser;
  66. struct dp_power *power;
  67. struct dp_aux *aux;
  68. struct dp_pll_io io;
  69. struct clk_onecell_data *clk_data;
  70. u32 dp_core_revision;
  71. int (*pll_cfg)(struct dp_pll *pll, unsigned long rate);
  72. int (*pll_prepare)(struct dp_pll *pll);
  73. int (*pll_unprepare)(struct dp_pll *pll);
  74. };
  75. struct dp_pll_db {
  76. struct dp_pll *pll;
  77. /* lane and orientation settings */
  78. u8 lane_cnt;
  79. u8 orientation;
  80. /* COM PHY settings */
  81. u32 hsclk_sel;
  82. u32 dec_start_mode0;
  83. u32 div_frac_start1_mode0;
  84. u32 div_frac_start2_mode0;
  85. u32 div_frac_start3_mode0;
  86. u32 integloop_gain0_mode0;
  87. u32 integloop_gain1_mode0;
  88. u32 lock_cmp1_mode0;
  89. u32 lock_cmp2_mode0;
  90. u32 lock_cmp_en;
  91. u32 ssc_step_size1_mode0;
  92. u32 ssc_step_size2_mode0;
  93. /* PHY vco divider */
  94. u32 phy_vco_div;
  95. };
  96. static inline struct dp_pll_vco_clk *to_dp_vco_hw(struct clk_hw *hw)
  97. {
  98. return container_of(hw, struct dp_pll_vco_clk, hw);
  99. }
  100. static inline bool is_gdsc_disabled(struct dp_pll *pll)
  101. {
  102. return (dp_pll_read(gdsc, 0x0) & BIT(31)) ? false : true;
  103. }
  104. int dp_pll_clock_register_5nm(struct dp_pll *pll);
  105. void dp_pll_clock_unregister_5nm(struct dp_pll *pll);
  106. struct dp_pll_in {
  107. struct platform_device *pdev;
  108. struct dp_aux *aux;
  109. struct dp_parser *parser;
  110. u32 dp_core_revision;
  111. };
  112. int dp_pll_clock_register_helper(struct dp_pll *pll, struct dp_pll_vco_clk *clks, int num_clks);
  113. struct dp_pll *dp_pll_get(struct dp_pll_in *in);
  114. void dp_pll_put(struct dp_pll *pll);
  115. #endif /* __DP_PLL_H */