Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5909493rdb; Thu, 14 Dec 2023 03:17:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVY6A6J2YFONYP2jtd4ZbzUVUWPy2/i799g9+Ev6rOn9X0Fugywz6t4WUauxgLw/1HXPq+ X-Received: by 2002:a05:6a00:170a:b0:6cd:faa6:fc4b with SMTP id h10-20020a056a00170a00b006cdfaa6fc4bmr11733781pfc.33.1702552674356; Thu, 14 Dec 2023 03:17:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702552674; cv=none; d=google.com; s=arc-20160816; b=K1/0IXvqNw0ZRQs1k1rCQMPp3xqncWMQU+EAbap6UVo9cE/YAyuWBfZJqNXOU4V/Kq qPvyml28/s87r8nThgLLJqUSqOaKQI7vgh6vF4LHywRCjSx9PlSHoH1qUmbH6Sjv69uN OBmbCMLd8GyiwjVd8AR0E18RahkuLHT49+umki+pFpm7dYIFoU1aWqo76wcfXS0pDTbj Ye7Q/1FGiHTpBB0hPZLd656EFLiM7gZRDMOXrEtSq4StZHsD5JtGt5Cw96SPctOpHxs/ T265f2MmQVz27Xv6ruzmFQ7Nzen47Ayn7NbjthfwcgzT2I29n8eUAEFz0Ig+EscB9rGs drXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=C6K0WZ0aorShhSqsnEfIUTq66rUOD4bR1wUC+mAh/Go=; fh=pug+WK5cgVvlw/GSkU4VcKwsW/1wdN8AJU//kbaZW8Y=; b=kwzf6v5SNWxNhAAGu84TVzzz6sOLBTG0Pv00U8U1wxDTnDFFWRbkjZLArDX7BlYozG 9xj/YCYnZ5FUwcANqG9TXMn0J++JH/S/GM3dqcBcSENBClhgI8oFwnqWUHwg1+vI9GZB OldkBdla9WLihjIyc5owP+qSevWfxYamraVRyPor0+vG5kqPL54vVxkv4Zm3R3YXvjv7 s58tp2YeRWivRTt8IsDEtV6NJOL/MO7ASzx62csW3XGwDavuJHdjRT5/ng/fc/uXRZ/y f70+8i8UBNtpsvBMUf+HDNoZLwg366qNzcrkuSKKI27CfSXLPGHNrDCnpnIhHrHb7971 g8WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D5IW65v9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id z4-20020a056a00240400b006cbb7e5e06fsi11222933pfh.125.2023.12.14.03.17.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 03:17:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=D5IW65v9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6FE318026902; Thu, 14 Dec 2023 03:17:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443730AbjLNLRh (ORCPT + 99 others); Thu, 14 Dec 2023 06:17:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443635AbjLNLRg (ORCPT ); Thu, 14 Dec 2023 06:17:36 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76D6A93; Thu, 14 Dec 2023 03:17:42 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3333074512bso266610f8f.1; Thu, 14 Dec 2023 03:17:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702552661; x=1703157461; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=C6K0WZ0aorShhSqsnEfIUTq66rUOD4bR1wUC+mAh/Go=; b=D5IW65v9Gn6+NSZRXfak6kcVOSzdwNMFznmoJQhY+OzEJKzv3ltF1pAjcmKbQlDdxu pu1u9ea11j6cmbIh3BnMp5Jq437B7WOGj5PEyE95Cx/C+N3nDx6FoXB01QA7sGg4CzYh 5HtxVfSZhWWNE4Qfq18jdoxWSGvARN0Y0P487r7WpjMnUG/46q/BRZvTUT1oBynHjpAK 2mH5IpVQTK/9GLH4arR79iD4/2sdNvZxGbE2wUQlcDEZLuddfouJvuGtBDVP1yD2ZrUp 5T79nX+c+V8ADd9eSdvjaB21X1acibg/vixY7p6eNLcpCo2CZ+IOz2L7NiG/uzSWUS8f +d6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702552661; x=1703157461; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C6K0WZ0aorShhSqsnEfIUTq66rUOD4bR1wUC+mAh/Go=; b=PkrAyrbQHZlhh4YLLWk9oda4SOpgGnZorQn+gARueISNsUlItAjeC7M4kgvUfNWNIX /SJr/m0PJjTfKXhsk82whc4+u/ZPcyEjkhmMViuDN6MPMJ7t8dQeK5vem8ytUunhsVeF RmC/Ch0epO2QexaAv/TcnEwdRjNl+0pfe8OVjyfBo5r1vl67tba1N92NHkDoH4iczlDS wiFolAh+Mr4PqICb8iU5firywc57OF8In52g6sSYuqjVBu8pUCoqnn6aA5JpKt884YNe Ldq34GpfuWL9bgfU9kufteqLCsjzrohei82WzqhAr70U4zr78kIerUjwRZHunT83MaUg Hw0w== X-Gm-Message-State: AOJu0YyaCk4pbVa8yKatAQYoXA/aYfc2wDwk9Plk4WNlZ3RLK1GWJBDY N1IsqJPfD6J1gQwOVC2RBA== X-Received: by 2002:a05:600c:3d91:b0:40b:5e56:7b4c with SMTP id bi17-20020a05600c3d9100b0040b5e567b4cmr4959384wmb.149.1702552660830; Thu, 14 Dec 2023 03:17:40 -0800 (PST) Received: from ?IPV6:2a02:810b:f40:4300:bca3:dfc6:dafa:abb2? ([2a02:810b:f40:4300:bca3:dfc6:dafa:abb2]) by smtp.gmail.com with ESMTPSA id e12-20020a05600c4e4c00b0040b398f0585sm24766579wmq.9.2023.12.14.03.17.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 03:17:40 -0800 (PST) Message-ID: <1b7402b2-ec03-420b-a81b-3e6ea46e402a@gmail.com> Date: Thu, 14 Dec 2023 12:17:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 07/11] drm/rockchip: inno_hdmi: Add basic mode validation Content-Language: en-US, de-DE To: Maxime Ripard Cc: Sandy Huang , =?UTF-8?Q?Heiko_St=C3=BCbner?= , Andy Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org References: <20231213195125.212923-1-knaerzche@gmail.com> <20231213195125.212923-8-knaerzche@gmail.com> From: Alex Bee In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Dec 2023 03:17:51 -0800 (PST) Hi Maxime, Am 14.12.23 um 09:05 schrieb Maxime Ripard: > Hi, > > On Wed, Dec 13, 2023 at 08:51:21PM +0100, Alex Bee wrote: >> As per TRM this controller supports pixelclocks starting from 25 MHz. The >> maximum supported pixelclocks are defined by the phy configurations we >> have. Also it can't support modes that require doubled clocks. >> If there is a phy reference clock we can additionally validate against >> VESA DMT's recommendations. >> Those checks are added to the mode_valid hook of the connector and >> encoder's mode_fixup hook. >> >> Signed-off-by: Alex Bee >> --- >> drivers/gpu/drm/rockchip/inno_hdmi.c | 38 ++++++++++++++++++++++++++-- >> 1 file changed, 36 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockchip/inno_hdmi.c >> index f7f0bec725f9..2f839ff31c1c 100644 >> --- a/drivers/gpu/drm/rockchip/inno_hdmi.c >> +++ b/drivers/gpu/drm/rockchip/inno_hdmi.c >> @@ -38,6 +38,8 @@ struct inno_hdmi_variant { >> struct inno_hdmi_phy_config *default_phy_config; >> }; >> >> +#define INNO_HDMI_MIN_TMDS_CLOCK 25000000U >> + >> struct hdmi_data_info { >> int vic; >> bool sink_has_audio; >> @@ -572,6 +574,34 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi, >> return 0; >> } >> >> +static enum drm_mode_status inno_hdmi_mode_valid(struct inno_hdmi *hdmi, >> + struct drm_display_mode *mode) >> +{ > So, mode_valid is only called to filter out the modes retrieved by > get_modes, but it won't be called when userspace programs a mode. That's > atomic_check's job. > > So you probably want to create a shared function between atomic_check > and mode_valid, and call it from both places (or call mode_valid from > atomic_check). This actually _is_ a shared function called in inno_hdmi_connector_mode_valid and inno_hdmi_encoder_mode_fixup. Yes, I  probably should use it in atomic_check _also_. > >> + /* No support for double-clock modes */ >> + if (mode->flags & DRM_MODE_FLAG_DBLCLK) >> + return MODE_BAD; >> + >> + unsigned int mpixelclk = mode->clock * 1000; > Variables should be declared at the top of the function. Oookay ... can move them. >> + if (mpixelclk < INNO_HDMI_MIN_TMDS_CLOCK) >> + return MODE_CLOCK_LOW; > You probably want to check the max TMDS clock too? Not sure what you mean here. For the currently supported formats of this driver (rgb only) tmds clock and pixel clock are always the same. > >> + if (inno_hdmi_find_phy_config(hdmi, mpixelclk) < 0) >> + return MODE_CLOCK_HIGH; >> + >> + if (hdmi->refclk) { >> + long refclk = clk_round_rate(hdmi->refclk, mpixelclk); >> + unsigned int max_tolerance = mpixelclk / 5000; >> + >> + /* Vesa DMT standard mentions +/- 0.5% max tolerance */ >> + if (abs(refclk - mpixelclk) > max_tolerance || >> + mpixelclk - refclk > max_tolerance; >> + return MODE_NOCLOCK; > You should use abs_diff here. abs() will get confused by the unsigned vs > signed comparison. Ack. > >> + } >> + >> + return MODE_OK; >> +} >> + >> static void inno_hdmi_encoder_mode_set(struct drm_encoder *encoder, >> struct drm_display_mode *mode, >> struct drm_display_mode *adj_mode) >> @@ -602,7 +632,9 @@ static bool inno_hdmi_encoder_mode_fixup(struct drm_encoder *encoder, >> const struct drm_display_mode *mode, >> struct drm_display_mode *adj_mode) >> { >> - return true; >> + struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder); >> + >> + return inno_hdmi_mode_valid(hdmi, adj_mode) == MODE_OK; >> } > Why do you call mode_valid in mode_fixup? I'm calling the shared function you asked me to introduce (inno_hdmi_connector_mode_valid != inno_mode_valid) Alex > > Maxime