pll_drv.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __MDSS_PLL_H
  6. #define __MDSS_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. #if defined(CONFIG_DRM)
  16. #include <linux/sde_io_util.h>
  17. #else
  18. #include <linux/mdss_io_util.h>
  19. #endif
  20. #define MDSS_PLL_REG_W(base, offset, data) \
  21. writel_relaxed((data), (base) + (offset))
  22. #define MDSS_PLL_REG_R(base, offset) readl_relaxed((base) + (offset))
  23. #define PLL_CALC_DATA(addr0, addr1, data0, data1) \
  24. (((data1) << 24) | ((((addr1) / 4) & 0xFF) << 16) | \
  25. ((data0) << 8) | (((addr0) / 4) & 0xFF))
  26. #define MDSS_DYN_PLL_REG_W(base, offset, addr0, addr1, data0, data1) \
  27. writel_relaxed(PLL_CALC_DATA(addr0, addr1, data0, data1), \
  28. (base) + (offset))
  29. #define upper_8_bit(x) ((((x) >> 2) & 0x100) >> 8)
  30. enum {
  31. MDSS_DSI_PLL_10NM,
  32. MDSS_DP_PLL_10NM,
  33. MDSS_DSI_PLL_7NM,
  34. MDSS_DSI_PLL_7NM_V2,
  35. MDSS_DSI_PLL_7NM_V4_1,
  36. MDSS_DP_PLL_7NM,
  37. MDSS_DP_PLL_7NM_V2,
  38. MDSS_DSI_PLL_28LPM,
  39. MDSS_DSI_PLL_14NM,
  40. MDSS_DP_PLL_14NM,
  41. MDSS_HDMI_PLL_28LPM,
  42. MDSS_UNKNOWN_PLL,
  43. };
  44. enum {
  45. MDSS_PLL_TARGET_8996,
  46. };
  47. #define DFPS_MAX_NUM_OF_FRAME_RATES 16
  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 mdss_pll_resources {
  63. /* Pll specific resources like GPIO, power supply, clocks, etc*/
  64. struct dss_module_power mp;
  65. /*
  66. * dsi/edp/hmdi plls' base register, phy, gdsc and dynamic refresh
  67. * register mapping
  68. */
  69. void __iomem *pll_base;
  70. void __iomem *phy_base;
  71. void __iomem *ln_tx0_base;
  72. void __iomem *ln_tx0_tran_base;
  73. void __iomem *ln_tx0_vmode_base;
  74. void __iomem *ln_tx1_base;
  75. void __iomem *ln_tx1_tran_base;
  76. void __iomem *ln_tx1_vmode_base;
  77. void __iomem *gdsc_base;
  78. void __iomem *dyn_pll_base;
  79. bool is_init_locked;
  80. s64 vco_current_rate;
  81. s64 vco_locking_rate;
  82. s64 vco_ref_clk_rate;
  83. /*
  84. * Certain pll's needs to update the same vco rate after resume in
  85. * suspend/resume scenario. Cached the vco rate for such plls.
  86. */
  87. unsigned long vco_cached_rate;
  88. u32 cached_cfg0;
  89. u32 cached_cfg1;
  90. u32 cached_outdiv;
  91. u32 cached_postdiv1;
  92. u32 cached_postdiv3;
  93. u32 cached_vreg_cfg;
  94. /* dsi/edp/hmdi pll interface type */
  95. u32 pll_interface_type;
  96. /*
  97. * Target ID. Used in pll_register API for valid target check before
  98. * registering the PLL clocks.
  99. */
  100. u32 target_id;
  101. /* HW recommended delay during configuration of vco clock rate */
  102. u32 vco_delay;
  103. /* Ref-count of the PLL resources */
  104. u32 resource_ref_cnt;
  105. /*
  106. * Keep track to resource status to avoid updating same status for the
  107. * pll from different paths
  108. */
  109. bool resource_enable;
  110. /*
  111. * Certain plls' do not allow vco rate update if it is on. Keep track of
  112. * status for them to turn on/off after set rate success.
  113. */
  114. bool pll_on;
  115. /*
  116. * handoff_status is true of pll is already enabled by bootloader with
  117. * continuous splash enable case. Clock API will call the handoff API
  118. * to enable the status. It is disabled if continuous splash
  119. * feature is disabled.
  120. */
  121. bool handoff_resources;
  122. /*
  123. * caching the pll trim codes in the case of dynamic refresh
  124. */
  125. int cache_pll_trim_codes[3];
  126. /*
  127. * for maintaining the status of saving trim codes
  128. */
  129. bool reg_upd;
  130. /*
  131. * Notifier callback for MDSS gdsc regulator events
  132. */
  133. struct notifier_block gdsc_cb;
  134. /*
  135. * Worker function to call PLL off event
  136. */
  137. struct work_struct pll_off;
  138. /*
  139. * PLL index if multiple index are available. Eg. in case of
  140. * DSI we have 2 plls.
  141. */
  142. uint32_t index;
  143. bool ssc_en; /* share pll with master */
  144. bool ssc_center; /* default is down spread */
  145. u32 ssc_freq;
  146. u32 ssc_ppm;
  147. struct mdss_pll_resources *slave;
  148. /*
  149. * target pll revision information
  150. */
  151. int revision;
  152. void *priv;
  153. /*
  154. * dynamic refresh pll codes stored in this structure
  155. */
  156. struct dfps_info *dfps;
  157. /*
  158. * for cases where dfps trigger happens before first
  159. * suspend/resume and handoff is not finished.
  160. */
  161. bool dfps_trigger;
  162. };
  163. struct mdss_pll_vco_calc {
  164. s32 div_frac_start1;
  165. s32 div_frac_start2;
  166. s32 div_frac_start3;
  167. s64 dec_start1;
  168. s64 dec_start2;
  169. s64 pll_plllock_cmp1;
  170. s64 pll_plllock_cmp2;
  171. s64 pll_plllock_cmp3;
  172. };
  173. static inline bool is_gdsc_disabled(struct mdss_pll_resources *pll_res)
  174. {
  175. if (!pll_res->gdsc_base) {
  176. WARN(1, "gdsc_base register is not defined\n");
  177. return true;
  178. }
  179. return readl_relaxed(pll_res->gdsc_base) & BIT(31) ? false : true;
  180. }
  181. static inline int mdss_pll_div_prepare(struct clk_hw *hw)
  182. {
  183. struct clk_hw *parent_hw = clk_hw_get_parent(hw);
  184. /* Restore the divider's value */
  185. return hw->init->ops->set_rate(hw, clk_hw_get_rate(hw),
  186. clk_hw_get_rate(parent_hw));
  187. }
  188. static inline int mdss_set_mux_sel(void *context, unsigned int reg,
  189. unsigned int val)
  190. {
  191. return 0;
  192. }
  193. static inline int mdss_get_mux_sel(void *context, unsigned int reg,
  194. unsigned int *val)
  195. {
  196. *val = 0;
  197. return 0;
  198. }
  199. int mdss_pll_resource_enable(struct mdss_pll_resources *pll_res, bool enable);
  200. int mdss_pll_util_resource_enable(struct mdss_pll_resources *pll_res,
  201. bool enable);
  202. int mdss_pll_util_resource_parse(struct platform_device *pdev,
  203. struct mdss_pll_resources *pll_res);
  204. struct dss_vreg *mdss_pll_get_mp_by_reg_name(struct mdss_pll_resources *pll_res
  205. , char *name);
  206. #endif