554fffc09e31d466cf86fb2ec94be0f0c467f88f
[openwrt/staging/noltari.git] /
1 From 82a5aa1df1b04efef46c7be82a7d71ea5300ce92 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 2 Dec 2020 18:36:24 +0000
4 Subject: [PATCH] drm/vc4: Add HDR metadata property to the VC5 HDMI
5 connectors
6
7 Now that we can export deeper colour depths, add in the signalling
8 for HDR metadata.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 drivers/gpu/drm/vc4/vc4_hdmi.c | 28 ++++++++++++++++++++++++++++
13 drivers/gpu/drm/vc4/vc4_hdmi.h | 3 +++
14 2 files changed, 31 insertions(+)
15
16 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
17 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
18 @@ -310,6 +310,10 @@ static int vc4_hdmi_connector_init(struc
19 connector->doublescan_allowed = 0;
20 connector->stereo_allowed = 1;
21
22 + if (vc4_hdmi->variant->supports_hdr)
23 + drm_object_attach_property(&connector->base,
24 + connector->dev->mode_config.hdr_output_metadata_property, 0);
25 +
26 drm_connector_attach_encoder(connector, encoder);
27
28 return 0;
29 @@ -449,6 +453,25 @@ static void vc4_hdmi_set_audio_infoframe
30 vc4_hdmi_write_infoframe(encoder, &frame);
31 }
32
33 +static void vc4_hdmi_set_hdr_infoframe(struct drm_encoder *encoder)
34 +{
35 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
36 + struct drm_connector *connector = &vc4_hdmi->connector;
37 + struct drm_connector_state *conn_state = connector->state;
38 + union hdmi_infoframe frame;
39 +
40 + if (!vc4_hdmi->variant->supports_hdr)
41 + return;
42 +
43 + if (!conn_state->hdr_output_metadata)
44 + return;
45 +
46 + if (drm_hdmi_infoframe_set_hdr_metadata(&frame.drm, conn_state))
47 + return;
48 +
49 + vc4_hdmi_write_infoframe(encoder, &frame);
50 +}
51 +
52 static void vc4_hdmi_set_infoframes(struct drm_encoder *encoder)
53 {
54 struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
55 @@ -461,6 +484,8 @@ static void vc4_hdmi_set_infoframes(stru
56 */
57 if (vc4_hdmi->audio.streaming)
58 vc4_hdmi_set_audio_infoframe(encoder);
59 +
60 + vc4_hdmi_set_hdr_infoframe(encoder);
61 }
62
63 static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
64 @@ -2298,6 +2323,7 @@ static const struct vc4_hdmi_variant bcm
65 .phy_rng_enable = vc4_hdmi_phy_rng_enable,
66 .phy_rng_disable = vc4_hdmi_phy_rng_disable,
67 .channel_map = vc4_hdmi_channel_map,
68 + .supports_hdr = false,
69 };
70
71 static const struct vc4_hdmi_variant bcm2711_hdmi0_variant = {
72 @@ -2325,6 +2351,7 @@ static const struct vc4_hdmi_variant bcm
73 .phy_rng_enable = vc5_hdmi_phy_rng_enable,
74 .phy_rng_disable = vc5_hdmi_phy_rng_disable,
75 .channel_map = vc5_hdmi_channel_map,
76 + .supports_hdr = true,
77 };
78
79 static const struct vc4_hdmi_variant bcm2711_hdmi1_variant = {
80 @@ -2352,6 +2379,7 @@ static const struct vc4_hdmi_variant bcm
81 .phy_rng_enable = vc5_hdmi_phy_rng_enable,
82 .phy_rng_disable = vc5_hdmi_phy_rng_disable,
83 .channel_map = vc5_hdmi_channel_map,
84 + .supports_hdr = true,
85 };
86
87 static const struct of_device_id vc4_hdmi_dt_match[] = {
88 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
89 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
90 @@ -99,6 +99,9 @@ struct vc4_hdmi_variant {
91
92 /* Callback to get channel map */
93 u32 (*channel_map)(struct vc4_hdmi *vc4_hdmi, u32 channel_mask);
94 +
95 + /* Enables HDR metadata */
96 + bool supports_hdr;
97 };
98
99 /* HDMI audio information */