e7c85ee1253f629d33009029d9be94d65378236c
[openwrt/staging/ldir.git] /
1 From c8a76985213abda828a2098c3d6ce8a49b5f9766 Mon Sep 17 00:00:00 2001
2 From: Dom Cobley <popcornmix@gmail.com>
3 Date: Fri, 5 Feb 2021 14:07:12 +0000
4 Subject: [PATCH] drm/vc4: Add connector check to trigger mode_change
5 when hdr metadata changes
6
7 Signed-off-by: Dom Cobley <popcornmix@gmail.com>
8 ---
9 drivers/gpu/drm/vc4/vc4_hdmi.c | 40 ++++++++++++++++++++++++++++++++++
10 1 file changed, 40 insertions(+)
11
12 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
13 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
14 @@ -224,6 +224,45 @@ static int vc4_hdmi_connector_get_modes(
15 return ret;
16 }
17
18 +static bool hdr_metadata_equal(const struct drm_connector_state *old_state,
19 + const struct drm_connector_state *new_state)
20 +{
21 + struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
22 + struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
23 +
24 + if (!old_blob || !new_blob)
25 + return old_blob == new_blob;
26 +
27 + if (old_blob->length != new_blob->length)
28 + return false;
29 +
30 + return !memcmp(old_blob->data, new_blob->data, old_blob->length);
31 +}
32 +
33 +static int vc4_hdmi_connector_atomic_check(struct drm_connector *connector,
34 + struct drm_atomic_state *state)
35 +{
36 + struct drm_connector_state *old_state =
37 + drm_atomic_get_old_connector_state(state, connector);
38 + struct drm_connector_state *new_state =
39 + drm_atomic_get_new_connector_state(state, connector);
40 + struct drm_crtc *crtc = new_state->crtc;
41 + struct drm_crtc_state *crtc_state;
42 +
43 + if (!crtc)
44 + return 0;
45 +
46 + if (!hdr_metadata_equal(old_state, new_state)) {
47 + crtc_state = drm_atomic_get_crtc_state(state, crtc);
48 + if (IS_ERR(crtc_state))
49 + return PTR_ERR(crtc_state);
50 +
51 + crtc_state->mode_changed = true;
52 + }
53 +
54 + return 0;
55 +}
56 +
57 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
58 {
59 struct vc4_hdmi_connector_state *old_state =
60 @@ -273,6 +312,7 @@ static const struct drm_connector_funcs
61
62 static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = {
63 .get_modes = vc4_hdmi_connector_get_modes,
64 + .atomic_check = vc4_hdmi_connector_atomic_check,
65 };
66
67 static int vc4_hdmi_connector_init(struct drm_device *dev,