539d62c3abffba7e9b81334f8922d63e365eb560
[openwrt/staging/blogic.git] /
1 From ca4627ecd3f93cd28ba3ae75af44e28224989b6a Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 2 Dec 2021 16:58:17 +0100
4 Subject: [PATCH] drm/vc4: hdmi: Move clock validation to its own
5 function
6
7 Our code is doing the same clock rate validation in multiple instances.
8 Let's create a helper to share the rate validation.
9
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
11 ---
12 drivers/gpu/drm/vc4/vc4_hdmi.c | 26 +++++++++++++++-----------
13 1 file changed, 15 insertions(+), 11 deletions(-)
14
15 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
16 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
17 @@ -1252,6 +1252,19 @@ static void vc4_hdmi_encoder_atomic_mode
18 mutex_unlock(&vc4_hdmi->mutex);
19 }
20
21 +static enum drm_mode_status
22 +vc4_hdmi_encoder_clock_valid(const struct vc4_hdmi *vc4_hdmi,
23 + unsigned long long clock)
24 +{
25 + if (clock > vc4_hdmi->variant->max_pixel_clock)
26 + return MODE_CLOCK_HIGH;
27 +
28 + if (vc4_hdmi->disable_4kp60 && clock > HDMI_14_MAX_TMDS_CLK)
29 + return MODE_CLOCK_HIGH;
30 +
31 + return MODE_OK;
32 +}
33 +
34 #define WIFI_2_4GHz_CH1_MIN_FREQ 2400000000ULL
35 #define WIFI_2_4GHz_CH1_MAX_FREQ 2422000000ULL
36
37 @@ -1296,10 +1309,7 @@ static int vc4_hdmi_encoder_atomic_check
38 if (mode->flags & DRM_MODE_FLAG_DBLCLK)
39 pixel_rate = pixel_rate * 2;
40
41 - if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
42 - return -EINVAL;
43 -
44 - if (vc4_hdmi->disable_4kp60 && (pixel_rate > HDMI_14_MAX_TMDS_CLK))
45 + if (vc4_hdmi_encoder_clock_valid(vc4_hdmi, pixel_rate) != MODE_OK)
46 return -EINVAL;
47
48 vc4_state->pixel_rate = pixel_rate;
49 @@ -1319,13 +1329,7 @@ vc4_hdmi_encoder_mode_valid(struct drm_e
50 (mode->hsync_end % 2) || (mode->htotal % 2)))
51 return MODE_H_ILLEGAL;
52
53 - if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
54 - return MODE_CLOCK_HIGH;
55 -
56 - if (vc4_hdmi->disable_4kp60 && vc4_hdmi_mode_needs_scrambling(mode))
57 - return MODE_CLOCK_HIGH;
58 -
59 - return MODE_OK;
60 + return vc4_hdmi_encoder_clock_valid(vc4_hdmi, mode->clock * 1000);
61 }
62
63 static const struct drm_encoder_helper_funcs vc4_hdmi_encoder_helper_funcs = {