kernel: bump 5.15 to 5.15.100
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0012-drm-vc4-hdmi-Introduce-a-scdc_enabled-flag.patch
1 From 4b98173449085326199e97a10d06cee4cce021a1 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Tue, 19 Oct 2021 19:13:46 +0200
4 Subject: [PATCH] drm/vc4: hdmi: Introduce a scdc_enabled flag
5
6 We currently rely on two functions, vc4_hdmi_supports_scrambling() and
7 vc4_hdmi_mode_needs_scrambling() to determine if we should enable and
8 disable the scrambler for any given mode.
9
10 Since we might need to disable the controller at boot, we also always
11 run vc4_hdmi_disable_scrambling() and thus call those functions without
12 a mode yet, which in turns need to make some special casing in order for
13 it to work.
14
15 Instead of duplicating the check for whether or not we need to take care
16 of the scrambler in both vc4_hdmi_enable_scrambling() and
17 vc4_hdmi_disable_scrambling(), we can do that check only when we enable
18 it and store whether or not it's been enabled in our private structure.
19
20 We also need to initialize that flag at true to make sure we disable the
21 scrambler at boot since we can't really know its state yet.
22
23 This allows to simplify a bit that part of the driver, and removes one
24 user of our copy of the CRTC adjusted mode outside of KMS (since
25 vc4_hdmi_disable_scrambling() might be called from the hotplug interrupt
26 handler).
27
28 It also removes our last user of the legacy encoder->crtc pointer.
29
30 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
31 ---
32 drivers/gpu/drm/vc4/vc4_hdmi.c | 22 ++++++++++++----------
33 drivers/gpu/drm/vc4/vc4_hdmi.h | 6 ++++++
34 2 files changed, 18 insertions(+), 10 deletions(-)
35
36 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
37 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
38 @@ -620,6 +620,8 @@ static void vc4_hdmi_enable_scrambling(s
39 VC5_HDMI_SCRAMBLER_CTL_ENABLE);
40 spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
41
42 + vc4_hdmi->scdc_enabled = true;
43 +
44 queue_delayed_work(system_wq, &vc4_hdmi->scrambling_work,
45 msecs_to_jiffies(SCRAMBLING_POLLING_DELAY_MS));
46 }
47 @@ -627,22 +629,14 @@ static void vc4_hdmi_enable_scrambling(s
48 static void vc4_hdmi_disable_scrambling(struct drm_encoder *encoder)
49 {
50 struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
51 - struct drm_display_mode *mode = &vc4_hdmi->saved_adjusted_mode;
52 - struct drm_crtc *crtc = encoder->crtc;
53 unsigned long flags;
54
55 lockdep_assert_held(&vc4_hdmi->mutex);
56
57 - /*
58 - * At boot, encoder->crtc will be NULL. Since we don't know the
59 - * state of the scrambler and in order to avoid any
60 - * inconsistency, let's disable it all the time.
61 - */
62 - if (crtc && !vc4_hdmi_supports_scrambling(encoder, mode))
63 + if (!vc4_hdmi->scdc_enabled)
64 return;
65
66 - if (crtc && !vc4_hdmi_mode_needs_scrambling(mode))
67 - return;
68 + vc4_hdmi->scdc_enabled = false;
69
70 if (delayed_work_pending(&vc4_hdmi->scrambling_work))
71 cancel_delayed_work_sync(&vc4_hdmi->scrambling_work);
72 @@ -2523,6 +2517,14 @@ static int vc4_hdmi_bind(struct device *
73 vc4_hdmi->pdev = pdev;
74 vc4_hdmi->variant = variant;
75
76 + /*
77 + * Since we don't know the state of the controller and its
78 + * display (if any), let's assume it's always enabled.
79 + * vc4_hdmi_disable_scrambling() will thus run at boot, make
80 + * sure it's disabled, and avoid any inconsistency.
81 + */
82 + vc4_hdmi->scdc_enabled = true;
83 +
84 ret = variant->init_resources(vc4_hdmi);
85 if (ret)
86 return ret;
87 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
88 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
89 @@ -210,6 +210,12 @@ struct vc4_hdmi {
90 * Protected by @mutex.
91 */
92 bool output_enabled;
93 +
94 + /**
95 + * @scdc_enabled: Is the HDMI controller currently running with
96 + * the scrambler on? Protected by @mutex.
97 + */
98 + bool scdc_enabled;
99 };
100
101 static inline struct vc4_hdmi *