bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0451-drm-vc4-Refactor-mode-checking-logic.patch
1 From cf8fe4bd58be368fc600fab4ea5aed2dd5dba138 Mon Sep 17 00:00:00 2001
2 From: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
3 Date: Thu, 15 Jul 2021 01:08:05 +0200
4 Subject: [PATCH] drm/vc4: Refactor mode checking logic
5
6 Replace drm_encoder_helper_funcs::atomic_check with
7 drm_connector_helper_funcs::atomic_check - the former is not called
8 during drm_mode_obj_set_property_ioctl(). Set crtc_state->mode_changed
9 if TV norm changes even without explicit mode change. This makes things
10 like "xrandr --output Composite-1 --set mode PAL-M" work properly.
11
12 Signed-off-by: Mateusz Kwiatkowski <kfyatek+publicgit@gmail.com>
13 ---
14 drivers/gpu/drm/vc4/vc4_vec.c | 42 ++++++++++++++++++++++-------------
15 1 file changed, 26 insertions(+), 16 deletions(-)
16
17 --- a/drivers/gpu/drm/vc4/vc4_vec.c
18 +++ b/drivers/gpu/drm/vc4/vc4_vec.c
19 @@ -415,6 +415,31 @@ static void vc4_vec_connector_reset(stru
20 connector->state->tv.mode = vc4_vec_get_default_mode(connector);
21 }
22
23 +static int vc4_vec_connector_atomic_check(struct drm_connector *conn,
24 + struct drm_atomic_state *state)
25 +{
26 + struct drm_connector_state *old_state =
27 + drm_atomic_get_old_connector_state(state, conn);
28 + struct drm_connector_state *new_state =
29 + drm_atomic_get_new_connector_state(state, conn);
30 +
31 + const struct vc4_vec_tv_mode *vec_mode =
32 + &vc4_vec_tv_modes[new_state->tv.mode];
33 +
34 + if (new_state->crtc) {
35 + struct drm_crtc_state *crtc_state =
36 + drm_atomic_get_new_crtc_state(state, new_state->crtc);
37 +
38 + if (!drm_mode_equal(vec_mode->mode, &crtc_state->mode))
39 + return -EINVAL;
40 +
41 + if (old_state->tv.mode != new_state->tv.mode)
42 + crtc_state->mode_changed = true;
43 + }
44 +
45 + return 0;
46 +}
47 +
48 static const struct drm_connector_funcs vc4_vec_connector_funcs = {
49 .detect = vc4_vec_connector_detect,
50 .fill_modes = drm_helper_probe_single_connector_modes,
51 @@ -426,6 +451,7 @@ static const struct drm_connector_funcs
52
53 static const struct drm_connector_helper_funcs vc4_vec_connector_helper_funcs = {
54 .get_modes = vc4_vec_connector_get_modes,
55 + .atomic_check = vc4_vec_connector_atomic_check,
56 };
57
58 static struct drm_connector *vc4_vec_connector_init(struct drm_device *dev,
59 @@ -563,26 +589,10 @@ static bool vc4_vec_encoder_mode_fixup(s
60 return true;
61 }
62
63 -static int vc4_vec_encoder_atomic_check(struct drm_encoder *encoder,
64 - struct drm_crtc_state *crtc_state,
65 - struct drm_connector_state *conn_state)
66 -{
67 - const struct vc4_vec_tv_mode *vec_mode;
68 -
69 - vec_mode = &vc4_vec_tv_modes[conn_state->tv.mode];
70 -
71 - if (conn_state->crtc &&
72 - !drm_mode_equal(vec_mode->mode, &crtc_state->adjusted_mode))
73 - return -EINVAL;
74 -
75 - return 0;
76 -}
77 -
78 static const struct drm_encoder_helper_funcs vc4_vec_encoder_helper_funcs = {
79 .disable = vc4_vec_encoder_disable,
80 .enable = vc4_vec_encoder_enable,
81 .mode_fixup = vc4_vec_encoder_mode_fixup,
82 - .atomic_check = vc4_vec_encoder_atomic_check,
83 };
84
85 static const struct vc4_vec_variant bcm2835_vec_variant = {