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