From 8b3d3ec09bdd68de0fba67f0d0f50462f0183030 Mon Sep 17 00:00:00 2001 From: Dom Cobley Date: Tue, 17 May 2022 12:46:42 +0100 Subject: [PATCH] kms/vc4_hdmi: Refuse 4096x2160@60 hdmi modes These are no reliable without overclocking. See: https://github.com/raspberrypi/linux/issues/5034 Signed-off-by: Dom Cobley --- drivers/gpu/drm/vc4/vc4_drv.h | 6 ++++++ drivers/gpu/drm/vc4/vc4_hdmi.c | 14 ++++++++++++++ drivers/gpu/drm/vc4/vc4_hvs.c | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/gpu/drm/vc4/vc4_drv.h b/drivers/gpu/drm/vc4/vc4_drv.h index a3d058d3c7886e..7d5acc9ace0187 100644 --- a/drivers/gpu/drm/vc4/vc4_drv.h +++ b/drivers/gpu/drm/vc4/vc4_drv.h @@ -342,6 +342,12 @@ struct vc4_hvs { struct drm_mm_node mitchell_netravali_filter; struct debugfs_regset32 regset; + + /* + * 4096x2160@60 requires a core overclock to work, so register + * whether that is sufficient. + */ + bool vc5_hdmi_enable_4096by2160; }; struct vc4_plane { diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c index 11237d0801ba5c..032084d0bcfa1d 100644 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c @@ -2092,6 +2092,7 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder, struct drm_crtc_state *crtc_state, struct drm_connector_state *conn_state) { + struct vc4_dev *vc4 = to_vc4_dev(encoder->dev); struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); struct drm_connector *connector = &vc4_hdmi->connector; struct drm_connector_state *old_conn_state = @@ -2124,6 +2125,12 @@ static int vc4_hdmi_encoder_atomic_check(struct drm_encoder *encoder, return -EINVAL; } + /* 4096x2160@60 is not reliable without overclocking core */ + if (mode->hdisplay > 3840 && mode->vdisplay >= 2160 && + drm_mode_vrefresh(mode) >= 50 && + !vc4->hvs->vc5_hdmi_enable_4096by2160) + return -EINVAL; + /* * The 1440p@60 pixel rate is in the same range than the first * WiFi channel (between 2.4GHz and 2.422GHz with 22MHz @@ -2155,6 +2162,8 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder, const struct drm_display_mode *mode) { struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); + const struct drm_connector *connector = &vc4_hdmi->connector; + struct vc4_dev *vc4 = to_vc4_dev(connector->dev); if (vc4_hdmi->variant->unsupported_odd_h_timings && !(mode->flags & DRM_MODE_FLAG_DBLCLK) && @@ -2162,6 +2171,11 @@ vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder, (mode->hsync_end % 2) || (mode->htotal % 2))) return MODE_H_ILLEGAL; + if (mode->hdisplay > 3840 && mode->vdisplay >= 2160 && + drm_mode_vrefresh(mode) >= 50 && + !vc4->hvs->vc5_hdmi_enable_4096by2160) + return MODE_CLOCK_HIGH; + return vc4_hdmi_encoder_clock_valid(vc4_hdmi, mode->clock * 1000); } diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c index 78952a4e5f9630..a6aa8575fb41a8 100644 --- a/drivers/gpu/drm/vc4/vc4_hvs.c +++ b/drivers/gpu/drm/vc4/vc4_hvs.c @@ -1022,12 +1022,18 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data) hvs->regset.nregs = ARRAY_SIZE(hvs_regs); if (vc4->is_vc5) { + unsigned long min_rate; + hvs->core_clk = devm_clk_get(&pdev->dev, NULL); if (IS_ERR(hvs->core_clk)) { dev_err(&pdev->dev, "Couldn't get core clock\n"); return PTR_ERR(hvs->core_clk); } + min_rate = rpi_firmware_clk_get_min_rate(hvs->core_clk); + if (min_rate >= 600000000) + hvs->vc5_hdmi_enable_4096by2160 = true; + ret = clk_prepare_enable(hvs->core_clk); if (ret) { dev_err(&pdev->dev, "Couldn't enable the core clock\n");