f6d45b1c33a59cf76e520e9332a31c3d55e2c9f2
[openwrt/staging/aparcar.git] /
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
5
6 The CSC callbacks takes a boolean as an argument to tell whether we're
7 using the full range or limited range RGB.
8
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.
13
14 Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
15 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
16 ---
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(-)
20
21 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
22 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
23 @@ -504,7 +504,6 @@ static void vc4_hdmi_write_infoframe(str
24 static void vc4_hdmi_set_avi_infoframe(struct drm_encoder *encoder)
25 {
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 @@ -522,9 +521,9 @@ static void vc4_hdmi_set_avi_infoframe(s
32
33 drm_hdmi_avi_infoframe_quant_range(&frame.avi,
34 connector, mode,
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);
43
44 @@ -741,7 +740,8 @@ static void vc4_hdmi_encoder_post_crtc_p
45 mutex_unlock(&vc4_hdmi->mutex);
46 }
47
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)
51 {
52 unsigned long flags;
53 u32 csc_ctl;
54 @@ -751,7 +751,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);
57
58 - if (enable) {
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 @@ -781,7 +781,8 @@ static void vc4_hdmi_csc_setup(struct vc
64 spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
65 }
66
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)
70 {
71 unsigned long flags;
72 u32 csc_ctl;
73 @@ -790,7 +791,7 @@ static void vc5_hdmi_csc_setup(struct vc
74
75 spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
76
77 - if (enable) {
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 @@ -1119,22 +1120,12 @@ static void vc4_hdmi_encoder_pre_crtc_en
83 {
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);
87 unsigned long flags;
88
89 mutex_lock(&vc4_hdmi->mutex);
90
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);
94 -
95 - vc4_encoder->limited_rgb_range = true;
96 - } else {
97 - if (vc4_hdmi->variant->csc_setup)
98 - vc4_hdmi->variant->csc_setup(vc4_hdmi, false);
99 -
100 - vc4_encoder->limited_rgb_range = false;
101 - }
102 + if (vc4_hdmi->variant->csc_setup)
103 + vc4_hdmi->variant->csc_setup(vc4_hdmi, mode);
104
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
109 @@ -12,7 +12,6 @@
110 struct vc4_hdmi_encoder {
111 struct vc4_encoder base;
112 bool hdmi_monitor;
113 - bool limited_rgb_range;
114 };
115
116 static inline struct vc4_hdmi_encoder *
117 @@ -77,7 +76,8 @@ struct vc4_hdmi_variant {
118 void (*reset)(struct vc4_hdmi *vc4_hdmi);
119
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);
124
125 /* Callback to configure the video timings in the HDMI block */
126 void (*set_timings)(struct vc4_hdmi *vc4_hdmi,