950-0625-drm-vc4-hdmi-Use-full-range-helper-in-csc-functions.patch 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. From 183b128892a416e4c09b6379f964cb9620f2a7ea Mon Sep 17 00:00:00 2001
  2. From: Maxime Ripard <[email protected]>
  3. Date: Tue, 12 Jan 2021 15:57:50 +0100
  4. Subject: [PATCH] drm/vc4: hdmi: Use full range helper in csc functions
  5. The CSC callbacks takes a boolean as an argument to tell whether we're
  6. using the full range or limited range RGB.
  7. However, with the upcoming YUV support, the logic will be a bit more
  8. complex. In order to address this, let's make the callbacks take the
  9. entire mode, and call our new helper to tell whether the full or limited
  10. range RGB should be used.
  11. Acked-by: Thomas Zimmermann <[email protected]>
  12. Signed-off-by: Maxime Ripard <[email protected]>
  13. ---
  14. drivers/gpu/drm/vc4/vc4_hdmi.c | 31 +++++++++++--------------------
  15. drivers/gpu/drm/vc4/vc4_hdmi.h | 4 ++--
  16. 2 files changed, 13 insertions(+), 22 deletions(-)
  17. --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
  18. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
  19. @@ -505,7 +505,6 @@ static void vc4_hdmi_write_infoframe(str
  20. static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
  21. {
  22. struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
  23. - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
  24. struct drm_connector *connector = &vc4_hdmi->connector;
  25. struct drm_connector_state *cstate = connector->state;
  26. const struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
  27. @@ -523,9 +522,9 @@ static void vc4_hdmi_set_avi_infoframe(s
  28. drm_hdmi_avi_infoframe_quant_range(&frame.avi,
  29. connector, mode,
  30. - vc4_encoder->limited_rgb_range ?
  31. - HDMI_QUANTIZATION_RANGE_LIMITED :
  32. - HDMI_QUANTIZATION_RANGE_FULL);
  33. + vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode) ?
  34. + HDMI_QUANTIZATION_RANGE_FULL :
  35. + HDMI_QUANTIZATION_RANGE_LIMITED);
  36. drm_hdmi_avi_infoframe_colorimetry(&frame.avi, cstate);
  37. drm_hdmi_avi_infoframe_bars(&frame.avi, cstate);
  38. @@ -742,7 +741,8 @@ static void vc4_hdmi_encoder_post_crtc_p
  39. mutex_unlock(&vc4_hdmi->mutex);
  40. }
  41. -static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, bool enable)
  42. +static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
  43. + const struct drm_display_mode *mode)
  44. {
  45. unsigned long flags;
  46. u32 csc_ctl;
  47. @@ -752,7 +752,7 @@ static void vc4_hdmi_csc_setup(struct vc
  48. csc_ctl = VC4_SET_FIELD(VC4_HD_CSC_CTL_ORDER_BGR,
  49. VC4_HD_CSC_CTL_ORDER);
  50. - if (enable) {
  51. + if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) {
  52. /* CEA VICs other than #1 requre limited range RGB
  53. * output unless overridden by an AVI infoframe.
  54. * Apply a colorspace conversion to squash 0-255 down
  55. @@ -782,7 +782,8 @@ static void vc4_hdmi_csc_setup(struct vc
  56. spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
  57. }
  58. -static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, bool enable)
  59. +static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi,
  60. + const struct drm_display_mode *mode)
  61. {
  62. unsigned long flags;
  63. u32 csc_ctl;
  64. @@ -791,7 +792,7 @@ static void vc5_hdmi_csc_setup(struct vc
  65. spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
  66. - if (enable) {
  67. + if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) {
  68. /* CEA VICs other than #1 requre limited range RGB
  69. * output unless overridden by an AVI infoframe.
  70. * Apply a colorspace conversion to squash 0-255 down
  71. @@ -1121,22 +1122,12 @@ static void vc4_hdmi_encoder_pre_crtc_en
  72. {
  73. struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
  74. struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
  75. - struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
  76. unsigned long flags;
  77. mutex_lock(&vc4_hdmi->mutex);
  78. - if (!vc4_hdmi_is_full_range_rgb(vc4_hdmi, mode)) {
  79. - if (vc4_hdmi->variant->csc_setup)
  80. - vc4_hdmi->variant->csc_setup(vc4_hdmi, true);
  81. -
  82. - vc4_encoder->limited_rgb_range = true;
  83. - } else {
  84. - if (vc4_hdmi->variant->csc_setup)
  85. - vc4_hdmi->variant->csc_setup(vc4_hdmi, false);
  86. -
  87. - vc4_encoder->limited_rgb_range = false;
  88. - }
  89. + if (vc4_hdmi->variant->csc_setup)
  90. + vc4_hdmi->variant->csc_setup(vc4_hdmi, mode);
  91. spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
  92. HDMI_WRITE(HDMI_FIFO_CTL, VC4_HDMI_FIFO_CTL_MASTER_SLAVE_N);
  93. --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
  94. +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
  95. @@ -12,7 +12,6 @@
  96. struct vc4_hdmi_encoder {
  97. struct vc4_encoder base;
  98. bool hdmi_monitor;
  99. - bool limited_rgb_range;
  100. };
  101. static inline struct vc4_hdmi_encoder *
  102. @@ -77,7 +76,8 @@ struct vc4_hdmi_variant {
  103. void (*reset)(struct vc4_hdmi *vc4_hdmi);
  104. /* Callback to enable / disable the CSC */
  105. - void (*csc_setup)(struct vc4_hdmi *vc4_hdmi, bool enable);
  106. + void (*csc_setup)(struct vc4_hdmi *vc4_hdmi,
  107. + const struct drm_display_mode *mode);
  108. /* Callback to configure the video timings in the HDMI block */
  109. void (*set_timings)(struct vc4_hdmi *vc4_hdmi,