icl_dsi.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright © 2018 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
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Madhav Chauhan <madhav.chauhan@intel.com>
  25. * Jani Nikula <jani.nikula@intel.com>
  26. */
  27. #include "intel_dsi.h"
  28. static void gen11_dsi_program_esc_clk_div(struct intel_encoder *encoder)
  29. {
  30. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  31. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  32. enum port port;
  33. u32 bpp = mipi_dsi_pixel_format_to_bpp(intel_dsi->pixel_format);
  34. u32 afe_clk_khz; /* 8X Clock */
  35. u32 esc_clk_div_m;
  36. afe_clk_khz = DIV_ROUND_CLOSEST(intel_dsi->pclk * bpp,
  37. intel_dsi->lane_count);
  38. esc_clk_div_m = DIV_ROUND_UP(afe_clk_khz, DSI_MAX_ESC_CLK);
  39. for_each_dsi_port(port, intel_dsi->ports) {
  40. I915_WRITE(ICL_DSI_ESC_CLK_DIV(port),
  41. esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
  42. POSTING_READ(ICL_DSI_ESC_CLK_DIV(port));
  43. }
  44. for_each_dsi_port(port, intel_dsi->ports) {
  45. I915_WRITE(ICL_DPHY_ESC_CLK_DIV(port),
  46. esc_clk_div_m & ICL_ESC_CLK_DIV_MASK);
  47. POSTING_READ(ICL_DPHY_ESC_CLK_DIV(port));
  48. }
  49. }
  50. static void gen11_dsi_enable_io_power(struct intel_encoder *encoder)
  51. {
  52. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  53. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  54. enum port port;
  55. u32 tmp;
  56. for_each_dsi_port(port, intel_dsi->ports) {
  57. tmp = I915_READ(ICL_DSI_IO_MODECTL(port));
  58. tmp |= COMBO_PHY_MODE_DSI;
  59. I915_WRITE(ICL_DSI_IO_MODECTL(port), tmp);
  60. }
  61. for_each_dsi_port(port, intel_dsi->ports) {
  62. intel_display_power_get(dev_priv, port == PORT_A ?
  63. POWER_DOMAIN_PORT_DDI_A_IO :
  64. POWER_DOMAIN_PORT_DDI_B_IO);
  65. }
  66. }
  67. static void gen11_dsi_power_up_lanes(struct intel_encoder *encoder)
  68. {
  69. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  70. struct intel_dsi *intel_dsi = enc_to_intel_dsi(&encoder->base);
  71. enum port port;
  72. u32 tmp;
  73. u32 lane_mask;
  74. switch (intel_dsi->lane_count) {
  75. case 1:
  76. lane_mask = PWR_DOWN_LN_3_1_0;
  77. break;
  78. case 2:
  79. lane_mask = PWR_DOWN_LN_3_1;
  80. break;
  81. case 3:
  82. lane_mask = PWR_DOWN_LN_3;
  83. break;
  84. case 4:
  85. default:
  86. lane_mask = PWR_UP_ALL_LANES;
  87. break;
  88. }
  89. for_each_dsi_port(port, intel_dsi->ports) {
  90. tmp = I915_READ(ICL_PORT_CL_DW10(port));
  91. tmp &= ~PWR_DOWN_LN_MASK;
  92. I915_WRITE(ICL_PORT_CL_DW10(port), tmp | lane_mask);
  93. }
  94. }
  95. static void gen11_dsi_enable_port_and_phy(struct intel_encoder *encoder)
  96. {
  97. /* step 4a: power up all lanes of the DDI used by DSI */
  98. gen11_dsi_power_up_lanes(encoder);
  99. }
  100. static void __attribute__((unused))
  101. gen11_dsi_pre_enable(struct intel_encoder *encoder,
  102. const struct intel_crtc_state *pipe_config,
  103. const struct drm_connector_state *conn_state)
  104. {
  105. /* step2: enable IO power */
  106. gen11_dsi_enable_io_power(encoder);
  107. /* step3: enable DSI PLL */
  108. gen11_dsi_program_esc_clk_div(encoder);
  109. /* step4: enable DSI port and DPHY */
  110. gen11_dsi_enable_port_and_phy(encoder);
  111. }