1 From 8bac9bb3f865b262e009faffb31d0d0b844faa5f Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 14 Nov 2022 19:32:10 +0000
4 Subject: [PATCH] drm/vc4: hdmi: Add property to allow manual config of
7 Add a custom property "Output format" that allows the overriding
8 of the default colourspace choice in the way that the old
9 firmware hdmi_pixel_encoding property did. If the chosen format is not
10 supported, then it will still drop back to the older behaviour.
12 This won't be acceptable to upstream, but it adds back the missing
13 functionality of hdmi_pixel_encoding.
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
17 drivers/gpu/drm/vc4/vc4_hdmi.c | 60 ++++++++++++++++++++++++++++++++++
18 drivers/gpu/drm/vc4/vc4_hdmi.h | 8 +++++
19 2 files changed, 68 insertions(+)
21 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
22 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
23 @@ -556,6 +556,7 @@ static int vc4_hdmi_connector_atomic_che
25 if (old_state->colorspace != new_state->colorspace ||
26 old_vc4_state->broadcast_rgb != new_vc4_state->broadcast_rgb ||
27 + old_vc4_state->requested_output_format != new_vc4_state->requested_output_format ||
28 !drm_connector_atomic_hdr_metadata_equal(old_state, new_state)) {
29 struct drm_crtc_state *crtc_state;
31 @@ -590,6 +591,8 @@ int vc4_hdmi_connector_get_property(stru
33 if (property == vc4_hdmi->broadcast_rgb_property) {
34 *val = vc4_conn_state->broadcast_rgb;
35 + } else if (property == vc4_hdmi->output_format_property) {
36 + *val = vc4_conn_state->requested_output_format;
38 DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
39 property->base.id, property->name);
40 @@ -621,6 +624,9 @@ int vc4_hdmi_connector_set_property(stru
41 if (property == vc4_hdmi->broadcast_rgb_property) {
42 vc4_conn_state->broadcast_rgb = val;
44 + } else if (property == vc4_hdmi->output_format_property) {
45 + vc4_conn_state->requested_output_format = val;
49 DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
50 @@ -664,6 +670,7 @@ vc4_hdmi_connector_duplicate_state(struc
51 new_state->tmds_char_rate = vc4_state->tmds_char_rate;
52 new_state->output_bpc = vc4_state->output_bpc;
53 new_state->output_format = vc4_state->output_format;
54 + new_state->requested_output_format = vc4_state->requested_output_format;
55 new_state->broadcast_rgb = vc4_state->broadcast_rgb;
56 __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
58 @@ -711,6 +718,33 @@ vc4_hdmi_attach_broadcast_rgb_property(s
59 drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
62 +static const struct drm_prop_enum_list output_format_names[] = {
63 + { VC4_HDMI_OUTPUT_AUTO, "Automatic" },
64 + { VC4_HDMI_OUTPUT_RGB, "RGB" },
65 + { VC4_HDMI_OUTPUT_YUV422, "YCbCr 4:2:2" },
66 + { VC4_HDMI_OUTPUT_YUV444, "YCbCr 4:4:4" },
70 +vc4_hdmi_attach_output_format_property(struct drm_device *dev,
71 + struct vc4_hdmi *vc4_hdmi)
73 + struct drm_property *prop = vc4_hdmi->output_format_property;
76 + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
78 + output_format_names,
79 + ARRAY_SIZE(output_format_names));
83 + vc4_hdmi->output_format_property = prop;
86 + drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
89 static int vc4_hdmi_connector_init(struct drm_device *dev,
90 struct vc4_hdmi *vc4_hdmi)
92 @@ -758,6 +792,7 @@ static int vc4_hdmi_connector_init(struc
93 drm_connector_attach_hdr_output_metadata_property(connector);
95 vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi);
96 + vc4_hdmi_attach_output_format_property(dev, vc4_hdmi);
98 drm_connector_attach_encoder(connector, encoder);
100 @@ -1895,6 +1930,11 @@ static void vc4_hdmi_encoder_atomic_mode
101 vc4_hdmi->broadcast_rgb = vc4_state->broadcast_rgb;
102 vc4_hdmi->output_bpc = vc4_state->output_bpc;
103 vc4_hdmi->output_format = vc4_state->output_format;
104 + vc4_hdmi->requested_output_format = vc4_state->requested_output_format;
105 + vc4_hdmi->broadcast_rgb = vc4_state->broadcast_rgb;
106 + memcpy(&vc4_hdmi->saved_adjusted_mode,
107 + &crtc_state->adjusted_mode,
108 + sizeof(vc4_hdmi->saved_adjusted_mode));
109 mutex_unlock(&vc4_hdmi->mutex);
112 @@ -2056,6 +2096,26 @@ vc4_hdmi_encoder_compute_format(const st
113 const struct drm_display_info *info = &connector->display_info;
116 + if (vc4_state->requested_output_format != VC4_HDMI_OUTPUT_AUTO) {
117 + drm_dbg(dev, "Trying with user requested output %u\n",
118 + vc4_state->requested_output_format);
120 + format = vc4_state->requested_output_format;
121 + if (vc4_hdmi_sink_supports_format_bpc(vc4_hdmi, info, mode,
125 + ret = vc4_hdmi_encoder_compute_clock(vc4_hdmi, vc4_state,
126 + mode, bpc, format);
128 + vc4_state->output_format = format;
136 drm_dbg(dev, "Trying with an RGB output\n");
138 format = VC4_HDMI_OUTPUT_RGB;
139 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
140 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
141 @@ -111,6 +111,7 @@ struct vc4_hdmi_audio {
144 enum vc4_hdmi_output_format {
145 + VC4_HDMI_OUTPUT_AUTO,
147 VC4_HDMI_OUTPUT_YUV422,
148 VC4_HDMI_OUTPUT_YUV444,
149 @@ -130,6 +131,7 @@ struct vc4_hdmi {
150 struct delayed_work scrambling_work;
152 struct drm_property *broadcast_rgb_property;
153 + struct drm_property *output_format_property;
155 struct i2c_adapter *ddc;
156 void __iomem *hdmicore_regs;
157 @@ -223,6 +225,11 @@ struct vc4_hdmi {
158 * for use outside of KMS hooks. Protected by @mutex.
160 enum vc4_hdmi_output_format output_format;
162 + * @requested_output_format: Copy of @vc4_connector_state.requested_output_format
163 + * for use outside of KMS hooks. Protected by @mutex.
165 + enum vc4_hdmi_output_format requested_output_format;
168 * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
169 @@ -249,6 +256,7 @@ struct vc4_hdmi_connector_state {
170 unsigned long long tmds_char_rate;
171 unsigned int output_bpc;
172 enum vc4_hdmi_output_format output_format;
173 + enum vc4_hdmi_output_format requested_output_format;