60a96ca8e448aa77422e05cee6a3d9444232ceba
[openwrt/staging/jow.git] /
1 From b975642ea1ebaf66f6ed0ac403dfa82fa9d0e206 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 8 Apr 2020 16:12:02 +0100
4 Subject: [PATCH] drm/vc4_hdmi: Add Broadcast RGB property to allow
5 override of RGB range
6
7 Copy Intel's "Broadcast RGB" property semantics to add manual override
8 of the HDMI pixel range for monitors that don't abide by the content
9 of the AVI Infoframe.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 ---
13 drivers/gpu/drm/vc4/vc4_hdmi.c | 104 +++++++++++++++++++++++++++++++++
14 drivers/gpu/drm/vc4/vc4_hdmi.h | 15 +++++
15 2 files changed, 119 insertions(+)
16
17 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
18 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
19 @@ -57,6 +57,14 @@
20 #include "vc4_hdmi_regs.h"
21 #include "vc4_regs.h"
22
23 +/*
24 + * "Broadcast RGB" property.
25 + * Allows overriding of HDMI full or limited range RGB
26 + */
27 +#define VC4_BROADCAST_RGB_AUTO 0
28 +#define VC4_BROADCAST_RGB_FULL 1
29 +#define VC4_BROADCAST_RGB_LIMITED 2
30 +
31 #define VC5_HDMI_HORZA_HFP_SHIFT 16
32 #define VC5_HDMI_HORZA_HFP_MASK VC4_MASK(28, 16)
33 #define VC5_HDMI_HORZA_VPOS BIT(15)
34 @@ -155,6 +163,11 @@ static bool vc4_hdmi_is_full_range_rgb(s
35 {
36 struct drm_display_info *display = &vc4_hdmi->connector.display_info;
37
38 + if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_LIMITED)
39 + return false;
40 + else if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_FULL)
41 + return true;
42 +
43 return !display->is_hdmi ||
44 drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
45 }
46 @@ -544,6 +557,65 @@ static int vc4_hdmi_connector_atomic_che
47 return 0;
48 }
49
50 +/**
51 + * vc4_hdmi_connector_atomic_get_property - hook for
52 + * connector->atomic_get_property.
53 + * @connector: Connector to get the property for.
54 + * @state: Connector state to retrieve the property from.
55 + * @property: Property to retrieve.
56 + * @val: Return value for the property.
57 + *
58 + * Returns the atomic property value for a digital connector.
59 + */
60 +int vc4_hdmi_connector_get_property(struct drm_connector *connector,
61 + const struct drm_connector_state *state,
62 + struct drm_property *property,
63 + uint64_t *val)
64 +{
65 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
66 + const struct vc4_hdmi_connector_state *vc4_conn_state =
67 + const_conn_state_to_vc4_hdmi_conn_state(state);
68 +
69 + if (property == vc4_hdmi->broadcast_rgb_property) {
70 + *val = vc4_conn_state->broadcast_rgb;
71 + } else {
72 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
73 + property->base.id, property->name);
74 + return -EINVAL;
75 + }
76 +
77 + return 0;
78 +}
79 +
80 +/**
81 + * vc4_hdmi_connector_atomic_set_property - hook for
82 + * connector->atomic_set_property.
83 + * @connector: Connector to set the property for.
84 + * @state: Connector state to set the property on.
85 + * @property: Property to set.
86 + * @val: New value for the property.
87 + *
88 + * Sets the atomic property value for a digital connector.
89 + */
90 +int vc4_hdmi_connector_set_property(struct drm_connector *connector,
91 + struct drm_connector_state *state,
92 + struct drm_property *property,
93 + uint64_t val)
94 +{
95 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
96 + struct vc4_hdmi_connector_state *vc4_conn_state =
97 + conn_state_to_vc4_hdmi_conn_state(state);
98 +
99 + if (property == vc4_hdmi->broadcast_rgb_property) {
100 + vc4_conn_state->broadcast_rgb = val;
101 + return 0;
102 + }
103 +
104 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
105 + property->base.id, property->name);
106 + return -EINVAL;
107 +}
108 +
109 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
110 {
111 struct vc4_hdmi_connector_state *old_state =
112 @@ -580,6 +652,7 @@ vc4_hdmi_connector_duplicate_state(struc
113 new_state->tmds_char_rate = vc4_state->tmds_char_rate;
114 new_state->output_bpc = vc4_state->output_bpc;
115 new_state->output_format = vc4_state->output_format;
116 + new_state->broadcast_rgb = vc4_state->broadcast_rgb;
117 __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
118
119 return &new_state->base;
120 @@ -590,6 +663,8 @@ static const struct drm_connector_funcs
121 .reset = vc4_hdmi_connector_reset,
122 .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state,
123 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
124 + .atomic_get_property = vc4_hdmi_connector_get_property,
125 + .atomic_set_property = vc4_hdmi_connector_set_property,
126 };
127
128 static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = {
129 @@ -598,6 +673,32 @@ static const struct drm_connector_helper
130 .atomic_check = vc4_hdmi_connector_atomic_check,
131 };
132
133 +static const struct drm_prop_enum_list broadcast_rgb_names[] = {
134 + { VC4_BROADCAST_RGB_AUTO, "Automatic" },
135 + { VC4_BROADCAST_RGB_FULL, "Full" },
136 + { VC4_BROADCAST_RGB_LIMITED, "Limited 16:235" },
137 +};
138 +
139 +static void
140 +vc4_hdmi_attach_broadcast_rgb_property(struct drm_device *dev,
141 + struct vc4_hdmi *vc4_hdmi)
142 +{
143 + struct drm_property *prop = vc4_hdmi->broadcast_rgb_property;
144 +
145 + if (!prop) {
146 + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
147 + "Broadcast RGB",
148 + broadcast_rgb_names,
149 + ARRAY_SIZE(broadcast_rgb_names));
150 + if (!prop)
151 + return;
152 +
153 + vc4_hdmi->broadcast_rgb_property = prop;
154 + }
155 +
156 + drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
157 +}
158 +
159 static int vc4_hdmi_connector_init(struct drm_device *dev,
160 struct vc4_hdmi *vc4_hdmi)
161 {
162 @@ -644,6 +745,8 @@ static int vc4_hdmi_connector_init(struc
163 if (vc4_hdmi->variant->supports_hdr)
164 drm_connector_attach_hdr_output_metadata_property(connector);
165
166 + vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi);
167 +
168 drm_connector_attach_encoder(connector, encoder);
169
170 return 0;
171 @@ -1683,6 +1786,7 @@ static void vc4_hdmi_encoder_atomic_mode
172 mutex_lock(&vc4_hdmi->mutex);
173 drm_mode_copy(&vc4_hdmi->saved_adjusted_mode,
174 &crtc_state->adjusted_mode);
175 + vc4_hdmi->broadcast_rgb = vc4_state->broadcast_rgb;
176 vc4_hdmi->output_bpc = vc4_state->output_bpc;
177 vc4_hdmi->output_format = vc4_state->output_format;
178 mutex_unlock(&vc4_hdmi->mutex);
179 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
180 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
181 @@ -129,6 +129,8 @@ struct vc4_hdmi {
182
183 struct delayed_work scrambling_work;
184
185 + struct drm_property *broadcast_rgb_property;
186 +
187 struct i2c_adapter *ddc;
188 void __iomem *hdmicore_regs;
189 void __iomem *hd_regs;
190 @@ -229,6 +231,12 @@ struct vc4_hdmi {
191 * for use outside of KMS hooks. Protected by @mutex.
192 */
193 enum vc4_hdmi_output_format output_format;
194 +
195 + /**
196 + * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
197 + * for use outside of KMS hooks. Protected by @mutex.
198 + */
199 + int broadcast_rgb;
200 };
201
202 static inline struct vc4_hdmi *
203 @@ -249,6 +257,7 @@ struct vc4_hdmi_connector_state {
204 unsigned long long tmds_char_rate;
205 unsigned int output_bpc;
206 enum vc4_hdmi_output_format output_format;
207 + int broadcast_rgb;
208 };
209
210 static inline struct vc4_hdmi_connector_state *
211 @@ -256,6 +265,12 @@ conn_state_to_vc4_hdmi_conn_state(struct
212 {
213 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
214 }
215 +
216 +static inline const struct vc4_hdmi_connector_state *
217 +const_conn_state_to_vc4_hdmi_conn_state(const struct drm_connector_state *conn_state)
218 +{
219 + return container_of(conn_state, struct vc4_hdmi_connector_state, base);
220 +}
221
222 void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
223 struct vc4_hdmi_connector_state *vc4_conn_state);