dsi_pll.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020, 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_UNKNOWN_PLL,
  47. };
  48. struct dfps_pll_codes {
  49. uint32_t pll_codes_1;
  50. uint32_t pll_codes_2;
  51. uint32_t pll_codes_3;
  52. };
  53. struct dfps_codes_info {
  54. uint32_t is_valid;
  55. uint32_t clk_rate; /* hz */
  56. struct dfps_pll_codes pll_codes;
  57. };
  58. struct dfps_info {
  59. uint32_t vco_rate_cnt;
  60. struct dfps_codes_info codes_dfps[DFPS_MAX_NUM_OF_FRAME_RATES];
  61. };
  62. struct dsi_pll_resource {
  63. /*
  64. * dsi base register, phy, gdsc and dynamic refresh
  65. * register mapping
  66. */
  67. void __iomem *pll_base;
  68. void __iomem *phy_base;
  69. void __iomem *gdsc_base;
  70. void __iomem *dyn_pll_base;
  71. s64 vco_current_rate;
  72. s64 vco_locking_rate;
  73. s64 vco_ref_clk_rate;
  74. /*
  75. * Certain pll's needs to update the same vco rate after resume in
  76. * suspend/resume scenario. Cached the vco rate for such plls.
  77. */
  78. unsigned long vco_cached_rate;
  79. u32 cached_cfg0;
  80. u32 cached_cfg1;
  81. u32 cached_outdiv;
  82. u32 cached_postdiv1;
  83. u32 cached_postdiv3;
  84. u32 pll_revision;
  85. /* HW recommended delay during configuration of vco clock rate */
  86. u32 vco_delay;
  87. /*
  88. * Certain plls' do not allow vco rate update if it is on. Keep track of
  89. * status for them to turn on/off after set rate success.
  90. */
  91. bool pll_on;
  92. /*
  93. * handoff_status is true of pll is already enabled by bootloader with
  94. * continuous splash enable case. Clock API will call the handoff API
  95. * to enable the status. It is disabled if continuous splash
  96. * feature is disabled.
  97. */
  98. bool handoff_resources;
  99. /*
  100. * caching the pll trim codes in the case of dynamic refresh
  101. */
  102. int cache_pll_trim_codes[3];
  103. /*
  104. * for maintaining the status of saving trim codes
  105. */
  106. bool reg_upd;
  107. /*
  108. * PLL index if multiple index are available. Eg. in case of
  109. * DSI we have 2 plls.
  110. */
  111. uint32_t index;
  112. bool ssc_en; /* share pll with master */
  113. bool ssc_center; /* default is down spread */
  114. u32 ssc_freq;
  115. u32 ssc_ppm;
  116. struct dsi_pll_resource *slave;
  117. /*
  118. * target pll revision information
  119. */
  120. int revision;
  121. void *priv;
  122. /*
  123. * dynamic refresh pll codes stored in this structure
  124. */
  125. struct dfps_info *dfps;
  126. /*
  127. * for cases where dfps trigger happens before first
  128. * suspend/resume and handoff is not finished.
  129. */
  130. bool dfps_trigger;
  131. };
  132. struct dsi_pll_vco_clk {
  133. struct clk_hw hw;
  134. unsigned long ref_clk_rate;
  135. u64 min_rate;
  136. u64 max_rate;
  137. u32 pll_en_seq_cnt;
  138. struct lpfr_cfg *lpfr_lut;
  139. u32 lpfr_lut_size;
  140. void *priv;
  141. int (*pll_enable_seqs[MAX_DSI_PLL_EN_SEQS])
  142. (struct dsi_pll_resource *pll_res);
  143. };
  144. struct dsi_pll_vco_calc {
  145. s32 div_frac_start1;
  146. s32 div_frac_start2;
  147. s32 div_frac_start3;
  148. s64 dec_start1;
  149. s64 dec_start2;
  150. s64 pll_plllock_cmp1;
  151. s64 pll_plllock_cmp2;
  152. s64 pll_plllock_cmp3;
  153. };
  154. static inline bool is_gdsc_disabled(struct dsi_pll_resource *pll_res)
  155. {
  156. if (!pll_res->gdsc_base) {
  157. WARN(1, "gdsc_base register is not defined\n");
  158. return true;
  159. }
  160. return readl_relaxed(pll_res->gdsc_base) & BIT(31) ? false : true;
  161. }
  162. static inline int dsi_pll_div_prepare(struct clk_hw *hw)
  163. {
  164. struct clk_hw *parent_hw = clk_hw_get_parent(hw);
  165. /* Restore the divider's value */
  166. return hw->init->ops->set_rate(hw, clk_hw_get_rate(hw),
  167. clk_hw_get_rate(parent_hw));
  168. }
  169. static inline int dsi_set_mux_sel(void *context, unsigned int reg,
  170. unsigned int val)
  171. {
  172. return 0;
  173. }
  174. static inline int dsi_get_mux_sel(void *context, unsigned int reg,
  175. unsigned int *val)
  176. {
  177. *val = 0;
  178. return 0;
  179. }
  180. static inline struct dsi_pll_vco_clk *to_vco_clk_hw(struct clk_hw *hw)
  181. {
  182. return container_of(hw, struct dsi_pll_vco_clk, hw);
  183. }
  184. int dsi_pll_clock_register_5nm(struct platform_device *pdev,
  185. struct dsi_pll_resource *pll_res);
  186. int dsi_pll_init(struct platform_device *pdev,
  187. struct dsi_pll_resource **pll_res);
  188. #endif