40927805cf591e6f21b01d8c840f6a2f38ebfff3
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0011-drm-vc4-hdmi-Introduce-an-output_enabled-flag.patch
1 From 02631cb4e30d7bc46f2b30657a84ddeb65831798 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Tue, 19 Oct 2021 17:31:58 +0200
4 Subject: [PATCH] drm/vc4: hdmi: Introduce an output_enabled flag
5
6 We currently poke at encoder->crtc in the ALSA code path to determine
7 whether the HDMI output is enabled or not, and thus whether we should
8 allow the audio output.
9
10 However, that pointer is deprecated and shouldn't really be used by
11 atomic drivers anymore. Since we have the infrastructure in place now,
12 let's just create a flag that we toggle to report whether the controller
13 is currently enabled and use that instead of encoder->crtc in ALSA.
14
15 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
16 ---
17 drivers/gpu/drm/vc4/vc4_hdmi.c | 16 ++++++++++++----
18 drivers/gpu/drm/vc4/vc4_hdmi.h | 6 ++++++
19 2 files changed, 18 insertions(+), 4 deletions(-)
20
21 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
22 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
23 @@ -729,6 +729,11 @@ static void vc4_hdmi_encoder_post_crtc_p
24
25 static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder)
26 {
27 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
28 +
29 + mutex_lock(&vc4_hdmi->mutex);
30 + vc4_hdmi->output_enabled = false;
31 + mutex_unlock(&vc4_hdmi->mutex);
32 }
33
34 static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, bool enable)
35 @@ -1227,6 +1232,11 @@ static void vc4_hdmi_encoder_post_crtc_e
36
37 static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
38 {
39 + struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
40 +
41 + mutex_lock(&vc4_hdmi->mutex);
42 + vc4_hdmi->output_enabled = true;
43 + mutex_unlock(&vc4_hdmi->mutex);
44 }
45
46 static void vc4_hdmi_encoder_atomic_mode_set(struct drm_encoder *encoder,
47 @@ -1408,14 +1418,12 @@ static inline struct vc4_hdmi *dai_to_hd
48
49 static bool vc4_hdmi_audio_can_stream(struct vc4_hdmi *vc4_hdmi)
50 {
51 - struct drm_encoder *encoder = &vc4_hdmi->encoder.base.base;
52 -
53 lockdep_assert_held(&vc4_hdmi->mutex);
54
55 /*
56 - * The encoder doesn't have a CRTC until the first modeset.
57 + * If the controller is disabled, prevent any ALSA output.
58 */
59 - if (!encoder->crtc)
60 + if (!vc4_hdmi->output_enabled)
61 return false;
62
63 /*
64 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
65 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
66 @@ -204,6 +204,12 @@ struct vc4_hdmi {
67 * for use by ALSA hooks and interrupt handlers. Protected by @mutex.
68 */
69 struct drm_display_mode saved_adjusted_mode;
70 +
71 + /**
72 + * @output_enabled: Is the HDMI controller currently active?
73 + * Protected by @mutex.
74 + */
75 + bool output_enabled;
76 };
77
78 static inline struct vc4_hdmi *