From patchwork Fri Dec 15 16:46:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10115521 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 358FA60231 for ; Fri, 15 Dec 2017 16:46:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271F129213 for ; Fri, 15 Dec 2017 16:46:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C06E29F4F; Fri, 15 Dec 2017 16:46:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56B5929213 for ; Fri, 15 Dec 2017 16:46:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E4AB46E853; Fri, 15 Dec 2017 16:46:23 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from lb2-smtp-cloud7.xs4all.net (lb2-smtp-cloud7.xs4all.net [194.109.24.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id B94326E853 for ; Fri, 15 Dec 2017 16:46:22 +0000 (UTC) Received: from [192.168.1.10] ([80.101.105.217]) by smtp-cloud7.xs4all.net with ESMTPA id Pt7reqFVcbYqmPt7seB2B5; Fri, 15 Dec 2017 17:46:20 +0100 To: "dri-devel@lists.freedesktop.org" , Maxime Ripard , Jose Abreu , Chen-Yu Tsai From: Hans Verkuil Subject: [PATCHv4] drm/sun4i: validate modes for HDMI Message-ID: <0fa230a8-d01d-561a-f74f-6b4fd421255b@xs4all.nl> Date: Fri, 15 Dec 2017 17:46:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfJ22N5PbBN9eaHvdkFapn8YdAT+hZLWxS3GZHAmABuiDmIezLsRvkSnsrz7B8Tu8jgFsvutf0UE6tG9EznHLp40Hf8+EmdVyw8BAE/FZ1OlxZuKCbivL a7cCDlOFt0CHiYIBBHxyAoW8JRqicEoYC+GteCf+9PZHWtsRBMqcitKxBx2cOcpcy0kXftjl/jR+y4MduxPYLsE1b278Vvgf8VGUW1OmeSmZABsf+t5KOgiw 7J8gf6H9586GX8fsO+2m5QLnDyghcd5AEzOLT+d2gvrObWGV0WMu3khR5Sk4astKFJvlqZjU7F2A9mp6/7sSgHbJQiz7gWhwc3I8pW2N+2Y= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP When I connected my cubieboard running 4.15-rc1 to my 4k display I got no picture. Some digging found that there is no check against the upper pixelclock limit of the HDMI output, so X selects a 4kp60 format at 594 MHz, which obviously won't work. The patch below adds a check for the upper bound of what this hardware can do, and it checks if the requested tmds clock can be obtained. It also allows for the ± 0.5% pixel clock variation that the HDMI spec permits. That code is based on commit 22d0be2a557e53a22feb484e8fce255fe09e6ad5 from Jose Abreu for drm/arc. Signed-off-by: Hans Verkuil Reviewed-by: Daniel Vetter --- Changes since v3: - Move the mode_valid callback to struct drm_encoder_helper_funcs. I'm assuming this is the correct struct, since this check is specific to the hdmi encoder. Changes since v2: - Allow for the 0.5% variation. --- drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c index dda904ec0534..500b6fb3e028 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c @@ -175,11 +175,31 @@ static void sun4i_hdmi_mode_set(struct drm_encoder *encoder, writel(val, hdmi->base + SUN4I_HDMI_VID_TIMING_POL_REG); } +static enum drm_mode_status sun4i_hdmi_mode_valid(struct drm_encoder *encoder, + const struct drm_display_mode *mode) +{ + struct sun4i_hdmi *hdmi = drm_encoder_to_sun4i_hdmi(encoder); + unsigned long rate = mode->clock * 1000; + unsigned long diff = rate / 200; /* +-0.5% allowed by HDMI spec */ + long rounded_rate; + + /* 165 MHz is the typical max pixelclock frequency for HDMI <= 1.2 */ + if (rate > 165000000) + return MODE_CLOCK_HIGH; + rounded_rate = clk_round_rate(hdmi->tmds_clk, rate); + if (rounded_rate > 0 && + max_t(unsigned long, rounded_rate, rate) - + min_t(unsigned long, rounded_rate, rate) < diff) + return MODE_OK; + return MODE_NOCLOCK; +} + static const struct drm_encoder_helper_funcs sun4i_hdmi_helper_funcs = { .atomic_check = sun4i_hdmi_atomic_check, .disable = sun4i_hdmi_disable, .enable = sun4i_hdmi_enable, .mode_set = sun4i_hdmi_mode_set, + .mode_valid = sun4i_hdmi_mode_valid, }; static const struct drm_encoder_funcs sun4i_hdmi_funcs = {