intel_dpll_mgr.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright © 2012-2016 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. */
  24. #ifndef _INTEL_DPLL_MGR_H_
  25. #define _INTEL_DPLL_MGR_H_
  26. /*FIXME: Move this to a more appropriate place. */
  27. #define abs_diff(a, b) ({ \
  28. typeof(a) __a = (a); \
  29. typeof(b) __b = (b); \
  30. (void) (&__a == &__b); \
  31. __a > __b ? (__a - __b) : (__b - __a); })
  32. struct drm_i915_private;
  33. struct intel_crtc;
  34. struct intel_crtc_state;
  35. struct intel_encoder;
  36. struct intel_shared_dpll;
  37. struct intel_dpll_mgr;
  38. enum intel_dpll_id {
  39. DPLL_ID_PRIVATE = -1, /* non-shared dpll in use */
  40. /* real shared dpll ids must be >= 0 */
  41. DPLL_ID_PCH_PLL_A = 0,
  42. DPLL_ID_PCH_PLL_B = 1,
  43. /* hsw/bdw */
  44. DPLL_ID_WRPLL1 = 0,
  45. DPLL_ID_WRPLL2 = 1,
  46. DPLL_ID_SPLL = 2,
  47. DPLL_ID_LCPLL_810 = 3,
  48. DPLL_ID_LCPLL_1350 = 4,
  49. DPLL_ID_LCPLL_2700 = 5,
  50. /* skl */
  51. DPLL_ID_SKL_DPLL0 = 0,
  52. DPLL_ID_SKL_DPLL1 = 1,
  53. DPLL_ID_SKL_DPLL2 = 2,
  54. DPLL_ID_SKL_DPLL3 = 3,
  55. };
  56. #define I915_NUM_PLLS 6
  57. /** Inform the state checker that the DPLL is kept enabled even if not
  58. * in use by any crtc.
  59. */
  60. #define INTEL_DPLL_ALWAYS_ON (1 << 0)
  61. struct intel_dpll_hw_state {
  62. /* i9xx, pch plls */
  63. uint32_t dpll;
  64. uint32_t dpll_md;
  65. uint32_t fp0;
  66. uint32_t fp1;
  67. /* hsw, bdw */
  68. uint32_t wrpll;
  69. uint32_t spll;
  70. /* skl */
  71. /*
  72. * DPLL_CTRL1 has 6 bits for each each this DPLL. We store those in
  73. * lower part of ctrl1 and they get shifted into position when writing
  74. * the register. This allows us to easily compare the state to share
  75. * the DPLL.
  76. */
  77. uint32_t ctrl1;
  78. /* HDMI only, 0 when used for DP */
  79. uint32_t cfgcr1, cfgcr2;
  80. /* bxt */
  81. uint32_t ebb0, ebb4, pll0, pll1, pll2, pll3, pll6, pll8, pll9, pll10,
  82. pcsdw12;
  83. };
  84. struct intel_shared_dpll_config {
  85. unsigned crtc_mask; /* mask of CRTCs sharing this PLL */
  86. struct intel_dpll_hw_state hw_state;
  87. };
  88. struct intel_shared_dpll_funcs {
  89. /* The mode_set hook is optional and should be used together with the
  90. * intel_prepare_shared_dpll function. */
  91. void (*mode_set)(struct drm_i915_private *dev_priv,
  92. struct intel_shared_dpll *pll);
  93. void (*enable)(struct drm_i915_private *dev_priv,
  94. struct intel_shared_dpll *pll);
  95. void (*disable)(struct drm_i915_private *dev_priv,
  96. struct intel_shared_dpll *pll);
  97. bool (*get_hw_state)(struct drm_i915_private *dev_priv,
  98. struct intel_shared_dpll *pll,
  99. struct intel_dpll_hw_state *hw_state);
  100. };
  101. struct intel_shared_dpll {
  102. struct intel_shared_dpll_config config;
  103. unsigned active_mask; /* mask of active CRTCs (i.e. DPMS on) */
  104. bool on; /* is the PLL actually active? Disabled during modeset */
  105. const char *name;
  106. /* should match the index in the dev_priv->shared_dplls array */
  107. enum intel_dpll_id id;
  108. struct intel_shared_dpll_funcs funcs;
  109. uint32_t flags;
  110. };
  111. #define SKL_DPLL0 0
  112. #define SKL_DPLL1 1
  113. #define SKL_DPLL2 2
  114. #define SKL_DPLL3 3
  115. /* shared dpll functions */
  116. struct intel_shared_dpll *
  117. intel_get_shared_dpll_by_id(struct drm_i915_private *dev_priv,
  118. enum intel_dpll_id id);
  119. enum intel_dpll_id
  120. intel_get_shared_dpll_id(struct drm_i915_private *dev_priv,
  121. struct intel_shared_dpll *pll);
  122. void
  123. intel_shared_dpll_config_get(struct intel_shared_dpll_config *config,
  124. struct intel_shared_dpll *pll,
  125. struct intel_crtc *crtc);
  126. void
  127. intel_shared_dpll_config_put(struct intel_shared_dpll_config *config,
  128. struct intel_shared_dpll *pll,
  129. struct intel_crtc *crtc);
  130. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  131. struct intel_shared_dpll *pll,
  132. bool state);
  133. #define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true)
  134. #define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false)
  135. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc,
  136. struct intel_crtc_state *state,
  137. struct intel_encoder *encoder);
  138. void intel_prepare_shared_dpll(struct intel_crtc *crtc);
  139. void intel_enable_shared_dpll(struct intel_crtc *crtc);
  140. void intel_disable_shared_dpll(struct intel_crtc *crtc);
  141. void intel_shared_dpll_commit(struct drm_atomic_state *state);
  142. void intel_shared_dpll_init(struct drm_device *dev);
  143. #endif /* _INTEL_DPLL_MGR_H_ */