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
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
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 drivers/gpu/drm/vc4/vc4_hdmi.c | 104 +++++++++++++++++++++++++++++++++
14 drivers/gpu/drm/vc4/vc4_hdmi.h | 15 +++++
15 2 files changed, 119 insertions(+)
17 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
18 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
20 #include "vc4_hdmi_regs.h"
24 + * "Broadcast RGB" property.
25 + * Allows overriding of HDMI full or limited range RGB
27 +#define VC4_BROADCAST_RGB_AUTO 0
28 +#define VC4_BROADCAST_RGB_FULL 1
29 +#define VC4_BROADCAST_RGB_LIMITED 2
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
36 struct drm_display_info *display = &vc4_hdmi->connector.display_info;
38 + if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_LIMITED)
40 + else if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_FULL)
43 return !display->is_hdmi ||
44 drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
46 @@ -544,6 +557,65 @@ static int vc4_hdmi_connector_atomic_che
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.
58 + * Returns the atomic property value for a digital connector.
60 +int vc4_hdmi_connector_get_property(struct drm_connector *connector,
61 + const struct drm_connector_state *state,
62 + struct drm_property *property,
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);
69 + if (property == vc4_hdmi->broadcast_rgb_property) {
70 + *val = vc4_conn_state->broadcast_rgb;
72 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
73 + property->base.id, property->name);
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.
88 + * Sets the atomic property value for a digital connector.
90 +int vc4_hdmi_connector_set_property(struct drm_connector *connector,
91 + struct drm_connector_state *state,
92 + struct drm_property *property,
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);
99 + if (property == vc4_hdmi->broadcast_rgb_property) {
100 + vc4_conn_state->broadcast_rgb = val;
104 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
105 + property->base.id, property->name);
109 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
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);
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,
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,
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" },
140 +vc4_hdmi_attach_broadcast_rgb_property(struct drm_device *dev,
141 + struct vc4_hdmi *vc4_hdmi)
143 + struct drm_property *prop = vc4_hdmi->broadcast_rgb_property;
146 + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
148 + broadcast_rgb_names,
149 + ARRAY_SIZE(broadcast_rgb_names));
153 + vc4_hdmi->broadcast_rgb_property = prop;
156 + drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
159 static int vc4_hdmi_connector_init(struct drm_device *dev,
160 struct vc4_hdmi *vc4_hdmi)
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);
166 + vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi);
168 drm_connector_attach_encoder(connector, encoder);
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 {
183 struct delayed_work scrambling_work;
185 + struct drm_property *broadcast_rgb_property;
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.
193 enum vc4_hdmi_output_format output_format;
196 + * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
197 + * for use outside of KMS hooks. Protected by @mutex.
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;
210 static inline struct vc4_hdmi_connector_state *
211 @@ -256,6 +265,12 @@ conn_state_to_vc4_hdmi_conn_state(struct
213 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
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)
219 + return container_of(conn_state, struct vc4_hdmi_connector_state, base);
222 void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
223 struct vc4_hdmi_connector_state *vc4_conn_state);