dsi_pll.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __DSI_PLL_H
  7. #define __DSI_PLL_H
  8. #include <linux/clk-provider.h>
  9. #include <linux/io.h>
  10. #include <linux/clk.h>
  11. #include <linux/clkdev.h>
  12. #include <linux/regmap.h>
  13. #include "clk-regmap.h"
  14. #include "clk-regmap-divider.h"
  15. #include "clk-regmap-mux.h"
  16. #include "dsi_defs.h"
  17. #include "dsi_hw.h"
  18. #define DSI_PLL_DBG(p, fmt, ...) DRM_DEV_DEBUG(NULL, "[msm-dsi-debug]: DSI_PLL_%d: "\
  19. fmt, p ? p->index : -1, ##__VA_ARGS__)
  20. #define DSI_PLL_ERR(p, fmt, ...) DRM_DEV_ERROR(NULL, "[msm-dsi-error]: DSI_PLL_%d: "\
  21. fmt, p ? p->index : -1, ##__VA_ARGS__)
  22. #define DSI_PLL_INFO(p, fmt, ...) DRM_DEV_INFO(NULL, "[msm-dsi-info]: DSI_PLL_%d: "\
  23. fmt, p ? p->index : -1, ##__VA_ARGS__)
  24. #define DSI_PLL_WARN(p, fmt, ...) DRM_WARN("[msm-dsi-warn]: DSI_PLL_%d: "\
  25. fmt, p ? p->index : -1, ##__VA_ARGS__)
  26. #define DSI_PLL_REG_W(base, offset, data) \
  27. do {\
  28. pr_debug("[DSI_PLL][%s] - [0x%08x]\n", #offset, (uint32_t)(data)); \
  29. DSI_GEN_W32(base, offset, data); \
  30. } while (0)
  31. #define DSI_PLL_REG_R(base, offset) DSI_GEN_R32(base, offset)
  32. #define DSI_DYN_PLL_REG_W(base, offset, addr0, addr1, data0, data1) \
  33. DSI_DYN_REF_REG_W(base, offset, addr0, addr1, data0, data1)
  34. #define upper_8_bit(x) ((((x) >> 2) & 0x100) >> 8)
  35. #define DFPS_MAX_NUM_OF_FRAME_RATES 16
  36. #define MAX_DSI_PLL_EN_SEQS 10
  37. /* Register offsets for 5nm PHY PLL */
  38. #define MMSS_DSI_PHY_PLL_PLL_CNTRL (0x0014)
  39. #define MMSS_DSI_PHY_PLL_PLL_BKG_KVCO_CAL_EN (0x002C)
  40. #define MMSS_DSI_PHY_PLL_PLLLOCK_CMP_EN (0x009C)
  41. /* PLL codes magic id in header */
  42. #define DSI_PLL_TRIM_CODES_MAGIC_ID (0x5643)
  43. /* PLL codes support version*/
  44. #define DSI_PLL_TRIM_CODES_VERSION (0x1)
  45. struct lpfr_cfg {
  46. unsigned long vco_rate;
  47. u32 r;
  48. };
  49. enum {
  50. DSI_PLL_4NM,
  51. DSI_PLL_5NM,
  52. DSI_PLL_10NM,
  53. DSI_UNKNOWN_PLL,
  54. };
  55. enum {
  56. DISPLAY_PLL_CODEID_DSI0 = 0,
  57. DISPLAY_PLL_CODEID_DSI1 = 1,
  58. DISPLAY_PLL_CODEID_MAX
  59. };
  60. #pragma pack(push)
  61. #pragma pack(1)
  62. struct pll_codes_header {
  63. u16 magic_id; /* Magic identifier */
  64. u8 version; /* Version ID, starting with 1 */
  65. u8 num_entries; /* Number of VCO rates in this structure */
  66. u16 size; /* Size of the entrie data structure, including header */
  67. u8 reserved[4]; /* Reserved for future use */
  68. };
  69. struct pll_codes_entry {
  70. u8 device_id; /* The PLL ID for this entry, refer to DISPLAY_PLL_CODEID */
  71. u32 vco_rate; /* VCO rate of this entry in Hz */
  72. u8 num_codes; /* Number of codes stored for this entry */
  73. u8 pll_codes[8]; /* List of PLL codes */
  74. };
  75. struct pll_codes_info {
  76. struct pll_codes_header header; /* PLL code data header */
  77. struct pll_codes_entry *pll_code_data; /* PLL code data */
  78. };
  79. #pragma pack(pop) // Restore the default packing
  80. struct dfps_pll_codes {
  81. uint32_t pll_codes_1;
  82. uint32_t pll_codes_2;
  83. uint32_t pll_codes_3;
  84. };
  85. struct dfps_codes_info {
  86. uint32_t is_valid;
  87. uint32_t clk_rate; /* hz */
  88. struct dfps_pll_codes pll_codes;
  89. };
  90. struct dfps_info {
  91. uint32_t vco_rate_cnt;
  92. struct dfps_codes_info codes_dfps[DFPS_MAX_NUM_OF_FRAME_RATES];
  93. };
  94. struct dsi_pll_resource {
  95. /*
  96. * dsi base register, phy, gdsc and dynamic refresh
  97. * register mapping
  98. */
  99. void __iomem *pll_base;
  100. void __iomem *phy_base;
  101. void __iomem *gdsc_base;
  102. void __iomem *dyn_pll_base;
  103. s64 vco_current_rate;
  104. s64 vco_ref_clk_rate;
  105. s64 vco_min_rate;
  106. s64 vco_rate;
  107. s64 byteclk_rate;
  108. s64 pclk_rate;
  109. u32 pll_revision;
  110. /* HW recommended delay during configuration of vco clock rate */
  111. u32 vco_delay;
  112. /*
  113. * caching the pll trim codes in the case of dynamic refresh
  114. */
  115. int cache_pll_trim_codes[3];
  116. /*
  117. * PLL index if multiple index are available. Eg. in case of
  118. * DSI we have 2 plls.
  119. */
  120. uint32_t index;
  121. bool ssc_en; /* share pll with master */
  122. bool ssc_center; /* default is down spread */
  123. u32 ssc_freq;
  124. u32 ssc_ppm;
  125. struct dsi_pll_resource *slave;
  126. void *priv;
  127. /*
  128. * dynamic refresh pll codes stored in this structure
  129. */
  130. struct dfps_info *dfps;
  131. /*
  132. * DSI pixel depth and lane information
  133. */
  134. int bpp;
  135. int lanes;
  136. bool phy_pll_bypass;
  137. /*
  138. * DSI PHY type DPHY/CPHY
  139. */
  140. enum dsi_phy_type type;
  141. bool in_trusted_vm;
  142. };
  143. struct dsi_pll_clk {
  144. struct clk_hw hw;
  145. void *priv;
  146. };
  147. struct dsi_pll_vco_calc {
  148. s32 div_frac_start1;
  149. s32 div_frac_start2;
  150. s32 div_frac_start3;
  151. s64 dec_start1;
  152. s64 dec_start2;
  153. s64 pll_plllock_cmp1;
  154. s64 pll_plllock_cmp2;
  155. s64 pll_plllock_cmp3;
  156. };
  157. struct dsi_pll_div_table {
  158. u64 min_hz;
  159. u64 max_hz;
  160. int pll_div;
  161. int phy_div;
  162. };
  163. static inline struct dsi_pll_clk *to_pll_clk_hw(struct clk_hw *hw)
  164. {
  165. return container_of(hw, struct dsi_pll_clk, hw);
  166. }
  167. int dsi_pll_clock_register_5nm(struct platform_device *pdev,
  168. struct dsi_pll_resource *pll_res);
  169. int dsi_pll_clock_register_4nm(struct platform_device *pdev, struct dsi_pll_resource *pll_res);
  170. int dsi_pll_init(struct platform_device *pdev,
  171. struct dsi_pll_resource **pll_res);
  172. void dsi_pll_parse_dfps_data(struct platform_device *pdev, struct dsi_pll_resource *pll_res);
  173. #endif