From patchwork Thu Dec 7 15:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 175260 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4876904vqy; Thu, 7 Dec 2023 07:54:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGKCiBg3P2oLyGgFk/y57HRDHPXLPECcx1yifHy/2hE+EjCbW7qDVNNGYT/WmUV66CmKi8j X-Received: by 2002:a17:90a:41:b0:286:6cc1:3efe with SMTP id 1-20020a17090a004100b002866cc13efemr2609667pjb.53.1701964484798; Thu, 07 Dec 2023 07:54:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701964484; cv=none; d=google.com; s=arc-20160816; b=hBDrvyrsmfmym+qfcoqtdBFMSwM7zTWItqAE/3mWwIAkzFK+tTrrRp2ehDTFK5xhkr UPtjOSfl1wRcWsVMM7btB05uSci+ytWK2UwJ2NM8BvREM5K9rvvzA/UcWf1e1hofpWBZ cY5I5cCdGCEy3mvXWFYa6IA8McOq4zlKbpgo5hywkWEkYv2JjEhLJyMp8pZ8Tzamtr/P +4vC/OLFuQSlybPbEGxuPge3U9/TttaOPLymdwBUaBy3Uzamay3LUeRkz2A4iqCO84ti m7hZc0CtvOsZ3Cp1IjjwnkZeuY8S0273Wzh6iPfOaEGatSBeV29XE1i6PbJdzCBWhjrj keHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=0fGlquuzFkbp9QFqWkbGO+dZMS2pnck+G2+//AkRHhc=; fh=e6/uyeFf2k7v8JUtB6fPyaAS5iN3eSA1hjtg35V2Rzw=; b=S8PVArkWlcHJPwhZq0hZGRtpsxq9WHnniWoyFqwazgibvRzXd+xML513pz1B2qO/pc gMBtDD7H3ZnL0n5iNdYYKTKLQ0Z2xieWBc1SouTRVvDqwizLyBc6hWVzv1UdNHbeTbjs SJM/1dqtEyxsPGKMPIwlU+QV4T42gC4ixYCjBOhrIOLhJXgVX0rnH6Meg+A6rewtoFTY /V1SeagkW4Vc8/atx8pBLx4epme+YAdx6oLGmeOH73YK2uSjCgc2uLKZ8pCQXTzQhUWX iyyuTKuuG6sjm4491VsAJKAZ13i8B915goI/QcfIDxqkuCsvIgXBN7r150Z5B92nqrQA Fcnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PYzuZmZr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id t16-20020a170902e85000b001cfc9894958si1393928plg.379.2023.12.07.07.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 07:54:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PYzuZmZr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CACB2826E37E; Thu, 7 Dec 2023 07:54:41 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443673AbjLGPy0 (ORCPT + 99 others); Thu, 7 Dec 2023 10:54:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1443719AbjLGPyD (ORCPT ); Thu, 7 Dec 2023 10:54:03 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C41630CD for ; Thu, 7 Dec 2023 07:51:34 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23894C4166B; Thu, 7 Dec 2023 15:51:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701964293; bh=LVnlQNCazjkGTqLwXxcrcuFECpSDdb3l2iMVIaIxEkM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PYzuZmZrQnHEvZyGXoFA8IpJAm9Cfip0jHXkFMHfNQnNZ+MGG/j1LkUlafkoxfJdb 8FBE2ZNsveTQc1DK2pZAZl3DEhg6L5T3Rn7WQKHReIwcec/e9LngMM6rmsAqvtA/Ik xjCU3xFd4tfLkquRwhftxRjcPRxH2AV9LM7JP35RC8UIjrelPc5lKe1MRw/30FhqVk Xhm3V9CIkB3aonQEOqPKxvQoNhvrFzUxpl9MR5s0gVnRSqRczP3jzgV5p/U5H4dLG3 N74gs34upRQxtM+Bpg0DBhf/a2uF9ib6YUDNX9mmboy/DgiX4qgJDKwfN/LgnUnobb E7lC92uLHUCeA== From: Maxime Ripard Date: Thu, 07 Dec 2023 16:50:06 +0100 Subject: [PATCH v5 43/44] drm/sun4i: hdmi: Consolidate atomic_check and mode_valid MIME-Version: 1.0 Message-Id: <20231207-kms-hdmi-connector-state-v5-43-6538e19d634d@kernel.org> References: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> In-Reply-To: <20231207-kms-hdmi-connector-state-v5-0-6538e19d634d@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Emma Anholt , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-sunxi@lists.linux.dev, Maxime Ripard X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4258; i=mripard@kernel.org; h=from:subject:message-id; bh=LVnlQNCazjkGTqLwXxcrcuFECpSDdb3l2iMVIaIxEkM=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKmFL9sn7fxh69z5/b2C3HFlidk209Utr59RmFJRmpEqJ W58Siupo5SFQYyLQVZMkSVG2HxJ3KlZrzvZ+ObBzGFlAhnCwMUpABNZ6M/wm/3Py93ikS+218Uc 9D1tduMPn7GC/sZiO3NVljtym9822zP8082eICTEYym7a77eyefJG61WdikYKzvOZxX0X3+nwuA dNwA= X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D 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 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 07:54:42 -0800 (PST) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784639111818168673 X-GMAIL-MSGID: 1784639111818168673 atomic_check and mode_valid do not check for the same things which can lead to surprising result if the userspace commits a mode that didn't go through mode_valid. Let's merge the two implementations into a function called by both. Signed-off-by: Maxime Ripard Acked-by: Sui Jingfeng --- drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c | 74 +++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c index c276d984da6b..b7cf369b1906 100644 --- a/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c +++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_enc.c @@ -62,18 +62,6 @@ static int sun4i_hdmi_setup_avi_infoframes(struct sun4i_hdmi *hdmi, return 0; } -static int sun4i_hdmi_atomic_check(struct drm_encoder *encoder, - struct drm_crtc_state *crtc_state, - struct drm_connector_state *conn_state) -{ - struct drm_display_mode *mode = &crtc_state->mode; - - if (mode->flags & DRM_MODE_FLAG_DBLCLK) - return -EINVAL; - - return 0; -} - static void sun4i_hdmi_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) { @@ -166,31 +154,61 @@ static void sun4i_hdmi_enable(struct drm_encoder *encoder, writel(val, hdmi->base + SUN4I_HDMI_VID_CTRL_REG); } -static enum drm_mode_status sun4i_hdmi_mode_valid(struct drm_encoder *encoder, - const struct drm_display_mode *mode) +static const struct drm_encoder_helper_funcs sun4i_hdmi_helper_funcs = { + .atomic_disable = sun4i_hdmi_disable, + .atomic_enable = sun4i_hdmi_enable, +}; + +static enum drm_mode_status +sun4i_hdmi_connector_clock_valid(const struct drm_connector *connector, + const struct drm_display_mode *mode, + unsigned long long clock) { - 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 */ + const struct sun4i_hdmi *hdmi = drm_connector_to_sun4i_hdmi(connector); + unsigned long diff = clock / 200; /* +-0.5% allowed by HDMI spec */ long rounded_rate; + if (mode->flags & DRM_MODE_FLAG_DBLCLK) + return MODE_BAD; + /* 165 MHz is the typical max pixelclock frequency for HDMI <= 1.2 */ - if (rate > 165000000) + if (clock > 165000000) return MODE_CLOCK_HIGH; - rounded_rate = clk_round_rate(hdmi->tmds_clk, rate); + + rounded_rate = clk_round_rate(hdmi->tmds_clk, clock); if (rounded_rate > 0 && - max_t(unsigned long, rounded_rate, rate) - - min_t(unsigned long, rounded_rate, rate) < diff) + max_t(unsigned long, rounded_rate, clock) - + min_t(unsigned long, rounded_rate, clock) < diff) return MODE_OK; + return MODE_NOCLOCK; } -static const struct drm_encoder_helper_funcs sun4i_hdmi_helper_funcs = { - .atomic_check = sun4i_hdmi_atomic_check, - .atomic_disable = sun4i_hdmi_disable, - .atomic_enable = sun4i_hdmi_enable, - .mode_valid = sun4i_hdmi_mode_valid, -}; +static int sun4i_hdmi_connector_atomic_check(struct drm_connector *connector, + struct drm_atomic_state *state) +{ + struct drm_connector_state *conn_state = + drm_atomic_get_new_connector_state(state, connector); + struct drm_crtc *crtc = conn_state->crtc; + struct drm_crtc_state *crtc_state = crtc->state; + struct drm_display_mode *mode = &crtc_state->adjusted_mode; + enum drm_mode_status status; + + status = sun4i_hdmi_connector_clock_valid(connector, mode, + mode->clock * 1000); + if (status != MODE_OK) + return -EINVAL; + + return 0; +} + +static enum drm_mode_status +sun4i_hdmi_connector_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) +{ + return sun4i_hdmi_connector_clock_valid(connector, mode, + mode->clock * 1000); +} static int sun4i_hdmi_get_modes(struct drm_connector *connector) { @@ -236,6 +254,8 @@ static struct i2c_adapter *sun4i_hdmi_get_ddc(struct device *dev) } static const struct drm_connector_helper_funcs sun4i_hdmi_connector_helper_funcs = { + .atomic_check = sun4i_hdmi_connector_atomic_check, + .mode_valid = sun4i_hdmi_connector_mode_valid, .get_modes = sun4i_hdmi_get_modes, };