dsi_pll.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __DSI_PLL_H
  6. #define __DSI_PLL_H
  7. #include <linux/clk-provider.h>
  8. #include <linux/io.h>
  9. #include <linux/clk.h>
  10. #include <linux/clkdev.h>
  11. #include <linux/regmap.h>
  12. #include "clk-regmap.h"
  13. #include "clk-regmap-divider.h"
  14. #include "clk-regmap-mux.h"
  15. #include "dsi_defs.h"
  16. #define DSI_PLL_DBG(p, fmt, ...) DRM_DEV_DEBUG(NULL, "[msm-dsi-debug]: DSI_PLL_%d: "\
  17. fmt, p ? p->index : -1, ##__VA_ARGS__)
  18. #define DSI_PLL_ERR(p, fmt, ...) DRM_DEV_ERROR(NULL, "[msm-dsi-error]: DSI_PLL_%d: "\
  19. fmt, p ? p->index : -1, ##__VA_ARGS__)
  20. #define DSI_PLL_INFO(p, fmt, ...) DRM_DEV_INFO(NULL, "[msm-dsi-info]: DSI_PLL_%d: "\
  21. fmt, p ? p->index : -1, ##__VA_ARGS__)
  22. #define DSI_PLL_WARN(p, fmt, ...) DRM_WARN("[msm-dsi-warn]: DSI_PLL_%d: "\
  23. fmt, p ? p->index : -1, ##__VA_ARGS__)
  24. #define DSI_PLL_REG_W(base, offset, data) \
  25. writel_relaxed((data), (base) + (offset))
  26. #define DSI_PLL_REG_R(base, offset) readl_relaxed((base) + (offset))
  27. #define PLL_CALC_DATA(addr0, addr1, data0, data1) \
  28. (((data1) << 24) | ((((addr1) / 4) & 0xFF) << 16) | \
  29. ((data0) << 8) | (((addr0) / 4) & 0xFF))
  30. #define DSI_DYN_PLL_REG_W(base, offset, addr0, addr1, data0, data1) \
  31. writel_relaxed(PLL_CALC_DATA(addr0, addr1, data0, data1), \
  32. (base) + (offset))
  33. #define upper_8_bit(x) ((((x) >> 2) & 0x100) >> 8)
  34. #define DFPS_MAX_NUM_OF_FRAME_RATES 16
  35. #define MAX_DSI_PLL_EN_SEQS 10
  36. /* Register offsets for 5nm PHY PLL */
  37. #define MMSS_DSI_PHY_PLL_PLL_CNTRL (0x0014)
  38. #define MMSS_DSI_PHY_PLL_PLL_BKG_KVCO_CAL_EN (0x002C)
  39. #define MMSS_DSI_PHY_PLL_PLLLOCK_CMP_EN (0x009C)
  40. struct lpfr_cfg {
  41. unsigned long vco_rate;
  42. u32 r;
  43. };
  44. enum {
  45. DSI_PLL_5NM,
  46. DSI_PLL_10NM,
  47. DSI_UNKNOWN_PLL,
  48. };
  49. struct dfps_pll_codes {
  50. uint32_t pll_codes_1;
  51. uint32_t pll_codes_2;
  52. uint32_t pll_codes_3;
  53. };
  54. struct dfps_codes_info {
  55. uint32_t is_valid;
  56. uint32_t clk_rate; /* hz */
  57. struct dfps_pll_codes pll_codes;
  58. };
  59. struct dfps_info {
  60. uint32_t vco_rate_cnt;
  61. struct dfps_codes_info codes_dfps[DFPS_MAX_NUM_OF_FRAME_RATES];
  62. };
  63. struct dsi_pll_resource {
  64. /*
  65. * dsi base register, phy, gdsc and dynamic refresh
  66. * register mapping
  67. */
  68. void __iomem *pll_base;
  69. void __iomem *phy_base;
  70. void __iomem *gdsc_base;
  71. void __iomem *dyn_pll_base;
  72. s64 vco_current_rate;
  73. s64 vco_ref_clk_rate;
  74. s64 vco_min_rate;
  75. s64 vco_rate;
  76. s64 byteclk_rate;
  77. s64 pclk_rate;
  78. u32 pll_revision;
  79. /* HW recommended delay during configuration of vco clock rate */
  80. u32 vco_delay;
  81. /*
  82. * Certain plls' do not allow vco rate update if it is on. Keep track of
  83. * status for them to turn on/off after set rate success.
  84. */
  85. bool pll_on;
  86. /*
  87. * caching the pll trim codes in the case of dynamic refresh
  88. */
  89. int cache_pll_trim_codes[3];
  90. /*
  91. * PLL index if multiple index are available. Eg. in case of
  92. * DSI we have 2 plls.
  93. */
  94. uint32_t index;
  95. bool ssc_en; /* share pll with master */
  96. bool ssc_center; /* default is down spread */
  97. u32 ssc_freq;
  98. u32 ssc_ppm;
  99. struct dsi_pll_resource *slave;
  100. void *priv;
  101. /*
  102. * dynamic refresh pll codes stored in this structure
  103. */
  104. struct dfps_info *dfps;
  105. /*
  106. * DSI pixel depth and lane information
  107. */
  108. int bpp;
  109. int lanes;
  110. /*
  111. * DSI PHY type DPHY/CPHY
  112. */
  113. enum dsi_phy_type type;
  114. };
  115. struct dsi_pll_clk {
  116. struct clk_hw hw;
  117. void *priv;
  118. };
  119. struct dsi_pll_vco_calc {
  120. s32 div_frac_start1;
  121. s32 div_frac_start2;
  122. s32 div_frac_start3;
  123. s64 dec_start1;
  124. s64 dec_start2;
  125. s64 pll_plllock_cmp1;
  126. s64 pll_plllock_cmp2;
  127. s64 pll_plllock_cmp3;
  128. };
  129. struct dsi_pll_div_table {
  130. u32 min_hz;
  131. u32 max_hz;
  132. int pll_div;
  133. int phy_div;
  134. };
  135. static inline struct dsi_pll_clk *to_pll_clk_hw(struct clk_hw *hw)
  136. {
  137. return container_of(hw, struct dsi_pll_clk, hw);
  138. }
  139. int dsi_pll_clock_register_5nm(struct platform_device *pdev,
  140. struct dsi_pll_resource *pll_res);
  141. int dsi_pll_init(struct platform_device *pdev,
  142. struct dsi_pll_resource **pll_res);
  143. #endif