1 From b6cf78ca0773f54074da8dc3401b9f52aec2e27e 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 | 103 +++++++++++++++++++++++++++++++++
14 drivers/gpu/drm/vc4/vc4_hdmi.h | 15 +++++
15 2 files changed, 118 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 @@ -136,6 +144,10 @@ static bool vc4_hdmi_is_full_range_rgb(s
36 struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
38 + if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_LIMITED)
40 + else if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_FULL)
42 return !vc4_encoder->hdmi_monitor ||
43 drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
45 @@ -342,6 +354,65 @@ static int vc4_hdmi_connector_atomic_che
50 + * vc4_hdmi_connector_atomic_get_property - hook for
51 + * connector->atomic_get_property.
52 + * @connector: Connector to get the property for.
53 + * @state: Connector state to retrieve the property from.
54 + * @property: Property to retrieve.
55 + * @val: Return value for the property.
57 + * Returns the atomic property value for a digital connector.
59 +int vc4_hdmi_connector_get_property(struct drm_connector *connector,
60 + const struct drm_connector_state *state,
61 + struct drm_property *property,
64 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
65 + const struct vc4_hdmi_connector_state *vc4_conn_state =
66 + const_conn_state_to_vc4_hdmi_conn_state(state);
68 + if (property == vc4_hdmi->broadcast_rgb_property) {
69 + *val = vc4_conn_state->broadcast_rgb;
71 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
72 + property->base.id, property->name);
80 + * vc4_hdmi_connector_atomic_set_property - hook for
81 + * connector->atomic_set_property.
82 + * @connector: Connector to set the property for.
83 + * @state: Connector state to set the property on.
84 + * @property: Property to set.
85 + * @val: New value for the property.
87 + * Sets the atomic property value for a digital connector.
89 +int vc4_hdmi_connector_set_property(struct drm_connector *connector,
90 + struct drm_connector_state *state,
91 + struct drm_property *property,
94 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
95 + struct vc4_hdmi_connector_state *vc4_conn_state =
96 + conn_state_to_vc4_hdmi_conn_state(state);
98 + if (property == vc4_hdmi->broadcast_rgb_property) {
99 + vc4_conn_state->broadcast_rgb = val;
103 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
104 + property->base.id, property->name);
108 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
110 struct vc4_hdmi_connector_state *old_state =
111 @@ -378,6 +449,7 @@ vc4_hdmi_connector_duplicate_state(struc
112 new_state->pixel_rate = vc4_state->pixel_rate;
113 new_state->output_bpc = vc4_state->output_bpc;
114 new_state->output_format = vc4_state->output_format;
115 + new_state->broadcast_rgb = vc4_state->broadcast_rgb;
116 __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
118 return &new_state->base;
119 @@ -390,6 +462,8 @@ static const struct drm_connector_funcs
120 .reset = vc4_hdmi_connector_reset,
121 .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state,
122 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
123 + .atomic_get_property = vc4_hdmi_connector_get_property,
124 + .atomic_set_property = vc4_hdmi_connector_set_property,
127 static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = {
128 @@ -397,6 +471,32 @@ static const struct drm_connector_helper
129 .atomic_check = vc4_hdmi_connector_atomic_check,
132 +static const struct drm_prop_enum_list broadcast_rgb_names[] = {
133 + { VC4_BROADCAST_RGB_AUTO, "Automatic" },
134 + { VC4_BROADCAST_RGB_FULL, "Full" },
135 + { VC4_BROADCAST_RGB_LIMITED, "Limited 16:235" },
139 +vc4_hdmi_attach_broadcast_rgb_property(struct drm_device *dev,
140 + struct vc4_hdmi *vc4_hdmi)
142 + struct drm_property *prop = vc4_hdmi->broadcast_rgb_property;
145 + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
147 + broadcast_rgb_names,
148 + ARRAY_SIZE(broadcast_rgb_names));
152 + vc4_hdmi->broadcast_rgb_property = prop;
155 + drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
158 static int vc4_hdmi_connector_init(struct drm_device *dev,
159 struct vc4_hdmi *vc4_hdmi)
161 @@ -440,6 +540,8 @@ static int vc4_hdmi_connector_init(struc
162 if (vc4_hdmi->variant->supports_hdr)
163 drm_connector_attach_hdr_output_metadata_property(connector);
165 + vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi);
167 drm_connector_attach_encoder(connector, encoder);
170 @@ -1386,6 +1488,7 @@ static void vc4_hdmi_encoder_atomic_mode
171 mutex_lock(&vc4_hdmi->mutex);
172 vc4_hdmi->output_bpc = vc4_state->output_bpc;
173 vc4_hdmi->output_format = vc4_state->output_format;
174 + vc4_hdmi->broadcast_rgb = vc4_state->broadcast_rgb;
175 memcpy(&vc4_hdmi->saved_adjusted_mode,
176 &crtc_state->adjusted_mode,
177 sizeof(vc4_hdmi->saved_adjusted_mode));
178 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
179 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
180 @@ -140,6 +140,8 @@ struct vc4_hdmi {
182 struct delayed_work scrambling_work;
184 + struct drm_property *broadcast_rgb_property;
186 struct i2c_adapter *ddc;
187 void __iomem *hdmicore_regs;
188 void __iomem *hd_regs;
189 @@ -240,6 +242,12 @@ struct vc4_hdmi {
191 enum vc4_hdmi_output_format output_format;
194 + * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
195 + * for use outside of KMS hooks. Protected by @mutex.
199 /* VC5 debugfs regset */
200 struct debugfs_regset32 cec_regset;
201 struct debugfs_regset32 csc_regset;
202 @@ -268,6 +276,7 @@ struct vc4_hdmi_connector_state {
203 unsigned long long pixel_rate;
204 unsigned int output_bpc;
205 enum vc4_hdmi_output_format output_format;
209 static inline struct vc4_hdmi_connector_state *
210 @@ -275,6 +284,12 @@ conn_state_to_vc4_hdmi_conn_state(struct
212 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
215 +static inline const struct vc4_hdmi_connector_state *
216 +const_conn_state_to_vc4_hdmi_conn_state(const struct drm_connector_state *conn_state)
218 + return container_of(conn_state, struct vc4_hdmi_connector_state, base);
221 void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
222 struct vc4_hdmi_connector_state *vc4_conn_state);