dsi_pll.h 4.8 KB

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