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
7 Our code is doing the same clock rate validation in multiple instances.
8 Let's create a helper to share the rate validation.
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
12 drivers/gpu/drm/vc4/vc4_hdmi.c | 26 +++++++++++++++-----------
13 1 file changed, 15 insertions(+), 11 deletions(-)
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);
21 +static enum drm_mode_status
22 +vc4_hdmi_encoder_clock_valid(const struct vc4_hdmi *vc4_hdmi,
23 + unsigned long long clock)
25 + if (clock > vc4_hdmi->variant->max_pixel_clock)
26 + return MODE_CLOCK_HIGH;
28 + if (vc4_hdmi->disable_4kp60 && clock > HDMI_14_MAX_TMDS_CLK)
29 + return MODE_CLOCK_HIGH;
34 #define WIFI_2_4GHz_CH1_MIN_FREQ 2400000000ULL
35 #define WIFI_2_4GHz_CH1_MAX_FREQ 2422000000ULL
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;
41 - if (pixel_rate > vc4_hdmi->variant->max_pixel_clock)
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)
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;
53 - if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
54 - return MODE_CLOCK_HIGH;
56 - if (vc4_hdmi->disable_4kp60 && vc4_hdmi_mode_needs_scrambling(mode))
57 - return MODE_CLOCK_HIGH;
60 + return vc4_hdmi_encoder_clock_valid(vc4_hdmi, mode->clock * 1000);
63 static const struct drm_encoder_helper_funcs vc4_hdmi_encoder_helper_funcs = {