950-0634-drm-vc4-hdmi-Always-try-to-have-the-highest-bpc.patch 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. From 5194c69ca3e4af8c3a6ffc77e5eb1ee0a62a6bbe Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  3. Date: Fri, 10 Dec 2021 15:29:56 +0100
  4. Subject: [PATCH] drm/vc4: hdmi: Always try to have the highest bpc
  5. Currently we take the max_bpc property as the bpc value and do not try
  6. anything else.
  7. However, what the other drivers seem to be doing is that they would try
  8. with the highest bpc allowed by the max_bpc property and the hardware
  9. capabilities, test if it results in an acceptable configuration, and if
  10. not decrease the bpc and try again.
  11. Let's use the same logic.
  12. Signed-off-by: Maxime Ripard <[email protected]>
  13. ---
  14. drivers/gpu/drm/vc4/vc4_hdmi.c | 44 ++++++++++++++++++++++++++++++----
  15. drivers/gpu/drm/vc4/vc4_hdmi.h | 4 +++-
  16. 2 files changed, 43 insertions(+), 5 deletions(-)
  17. --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
  18. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
  19. @@ -357,6 +357,7 @@ vc4_hdmi_connector_duplicate_state(struc
  20. return NULL;
  21. new_state->pixel_rate = vc4_state->pixel_rate;
  22. + new_state->output_bpc = vc4_state->output_bpc;
  23. __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
  24. return &new_state->base;
  25. @@ -914,6 +915,8 @@ static void vc5_hdmi_set_timings(struct
  26. struct drm_connector_state *state,
  27. struct drm_display_mode *mode)
  28. {
  29. + const struct vc4_hdmi_connector_state *vc4_state =
  30. + conn_state_to_vc4_hdmi_conn_state(state);
  31. bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
  32. bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
  33. bool interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
  34. @@ -962,7 +965,7 @@ static void vc5_hdmi_set_timings(struct
  35. HDMI_WRITE(HDMI_VERTB0, vertb_even);
  36. HDMI_WRITE(HDMI_VERTB1, vertb);
  37. - switch (state->max_bpc) {
  38. + switch (vc4_state->output_bpc) {
  39. case 12:
  40. gcp = 6;
  41. gcp_en = true;
  42. @@ -1252,9 +1255,11 @@ static void vc4_hdmi_encoder_atomic_mode
  43. struct drm_connector_state *conn_state)
  44. {
  45. struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
  46. + struct vc4_hdmi_connector_state *vc4_state =
  47. + conn_state_to_vc4_hdmi_conn_state(conn_state);
  48. mutex_lock(&vc4_hdmi->mutex);
  49. - vc4_hdmi->output_bpc = conn_state->max_bpc;
  50. + vc4_hdmi->output_bpc = vc4_state->output_bpc;
  51. memcpy(&vc4_hdmi->saved_adjusted_mode,
  52. &crtc_state->adjusted_mode,
  53. sizeof(vc4_hdmi->saved_adjusted_mode));
  54. @@ -1309,6 +1314,38 @@ vc4_hdmi_encoder_compute_clock(const str
  55. return 0;
  56. }
  57. +static int
  58. +vc4_hdmi_encoder_compute_config(const struct vc4_hdmi *vc4_hdmi,
  59. + struct vc4_hdmi_connector_state *vc4_state,
  60. + const struct drm_display_mode *mode)
  61. +{
  62. + struct drm_connector_state *conn_state = &vc4_state->base;
  63. + unsigned int max_bpc = clamp_t(unsigned int, conn_state->max_bpc, 8, 12);
  64. + unsigned int bpc;
  65. + int ret;
  66. +
  67. + for (bpc = max_bpc; bpc >= 8; bpc -= 2) {
  68. + drm_dbg(dev, "Trying with a %d bpc output\n", bpc);
  69. +
  70. + ret = vc4_hdmi_encoder_compute_clock(vc4_hdmi, vc4_state,
  71. + mode, bpc);
  72. + if (ret)
  73. + continue;
  74. +
  75. + vc4_state->output_bpc = bpc;
  76. +
  77. + drm_dbg(dev,
  78. + "Mode %ux%u @ %uHz: Found configuration: bpc: %u, clock: %llu\n",
  79. + mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode),
  80. + vc4_state->output_bpc,
  81. + vc4_state->pixel_rate);
  82. +
  83. + break;
  84. + }
  85. +
  86. + return ret;
  87. +}
  88. +
  89. #define WIFI_2_4GHz_CH1_MIN_FREQ 2400000000ULL
  90. #define WIFI_2_4GHz_CH1_MAX_FREQ 2422000000ULL
  91. @@ -1343,8 +1380,7 @@ static int vc4_hdmi_encoder_atomic_check
  92. pixel_rate = mode->clock * 1000;
  93. }
  94. - ret = vc4_hdmi_encoder_compute_clock(vc4_hdmi, vc4_state, mode,
  95. - conn_state->max_bpc);
  96. + ret = vc4_hdmi_encoder_compute_config(vc4_hdmi, vc4_state, mode);
  97. if (ret)
  98. return ret;
  99. --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
  100. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
  101. @@ -222,7 +222,8 @@ struct vc4_hdmi {
  102. bool scdc_enabled;
  103. /**
  104. - * @output_bpc: BPC currently being used. Protected by @mutex.
  105. + * @output_bpc: Copy of @vc4_connector_state.output_bpc for use
  106. + * outside of KMS hooks. Protected by @mutex.
  107. */
  108. unsigned int output_bpc;
  109. @@ -252,6 +253,7 @@ encoder_to_vc4_hdmi(struct drm_encoder *
  110. struct vc4_hdmi_connector_state {
  111. struct drm_connector_state base;
  112. unsigned long long pixel_rate;
  113. + unsigned int output_bpc;
  114. };
  115. static inline struct vc4_hdmi_connector_state *