From patchwork Thu Feb 22 18:14:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 204982 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp131239dyb; Thu, 22 Feb 2024 10:31:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVo1Pc1L8XQTWSx89PUEJ6MdCY39zHvcbpNb/gzqAImmnuC5+Dwgs4QqNT7ymrD1AZSSMKHW+HO3Z1ElIN1V0uX9QFdbQ== X-Google-Smtp-Source: AGHT+IE0FADmYdn+xs8pc/II5/Klq6Q7xGgB9O73rcnm380LvDSMou23tpeXi3g0lSbvkK0KQKYO X-Received: by 2002:a05:6358:5e85:b0:17b:5c4c:7895 with SMTP id z5-20020a0563585e8500b0017b5c4c7895mr6682510rwn.22.1708626706415; Thu, 22 Feb 2024 10:31:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708626706; cv=pass; d=google.com; s=arc-20160816; b=xZi9HZrItbTsVWepOBh5u+Ko1ZJhVsyDDrvzsJ2MJ830Gt8OpluYgR6Bsxqd7H5P9O bSWtiQhrXqkDMTh+IeYAEJrgQ/vwa1iSIhRGrDyj8PmoiNwNl/10CnVzkqoyZ4gWRauy RvP/1EZK/iSWxjidnhXSbJqlNOW14K8eaywb3+j7ZPzTMnnrRSn3i8rbf36OjB+FVKXD nhkvn5MlQwHGoHlCp0TCXmUttutTVcBc7X4GoKpLiyLk9KJtSvZVvkR/ku3pSvSOQplu iVMXjK1BQ5DYtzYSPuuxt81Wamwm4KG1aTYswk8u89oycoaniGPM2t601JTswhpZ6p9J B8Sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=59bBfPtSUCGvNMcSTdpjSCDzJRpQrgjnv9vA94G1rY0=; fh=jHlABrYnApVt5KJlrthitgyo0hqpWWrdlN0oFT+yLLg=; b=vOnrZmYIWGmqHfuXnE6x6EJY2bRU+31DEUKAtvbaX5DmHtEReKkhRX1acZvSQk1R8V 3Yz3PHLeRCZjhajgJBOT0X6yN9pHkm6Y1TA4B2xhTjMR9/luEW1ovG+qchioA1v2YMu7 UzSe4S5B4K2073pTZYFmb/9GGxxWopF6AbPzhjYwuaPhHNEmpYmfkSi5CI0Q4iyVx1l5 DfXHdRvDwTJmn9jqH1iqNzWLv9/vfHgSHylaSSG62udq+unWNtlDqtjoyM1kGlDjthbZ NIL1jtaQqWnwq1eeYmPdKDChBuBKz6xJ6yvemzpyceLegB6mM5GA2JqlSV9JMWHxzjbT 0lTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e0NBs1SQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77115-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77115-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e15-20020a63744f000000b005dc8834047esi10448291pgn.422.2024.02.22.10.31.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 10:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-77115-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e0NBs1SQ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-77115-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-77115-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3552A283953 for ; Thu, 22 Feb 2024 18:31:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73A4F14F96E; Thu, 22 Feb 2024 18:16:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="e0NBs1SQ" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FC8A14EFFB; Thu, 22 Feb 2024 18:16:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625766; cv=none; b=bSCVsfet0q7g0Iw951aK7FM9f8Na5uAbyZTSPHei9VrCIFatuv3zMTZUlkzMTsTx0twEs3C2paSUMEL9gp9FyFRULu9Pjl2+hHfBQxm+nSl/ijDPApv5FcIOZmfmwfQGL5AeTgjIt7wMmltjKQVAh+xVoPNWf7D/5CGKVvN5zNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708625766; c=relaxed/simple; bh=T+Mwu+EH8KKp7SKPsP5xhhewnkamDcEqVw1vxC33JeM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GNosw6wEF/5Qc9Biob+O65u0vosXRFo0CEtRAFWTdnxbSXm7UKiEnj9OXcHKU+7EAGYd0KLeOeGPHRvwPzNxLyiYbS7hP/K6ltNzRIzSFHbazIuEstbcMliQvZFYWO8VIz7KVE/x/uVLAEIW4cCwxvKvjMiIsJNzPO50+siFQAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=e0NBs1SQ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 047AEC433F1; Thu, 22 Feb 2024 18:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708625766; bh=T+Mwu+EH8KKp7SKPsP5xhhewnkamDcEqVw1vxC33JeM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=e0NBs1SQK24/CJ6wPapKpX3i/K65QEnaHjdddDM0lnaMo1WqBIMwjvYDgghLy069h DcxpGwEHv90/ZDwYP3EJw3ze23GA5Jd4gOvDS4c/NnDIdQDIAmfJ5HcyfTWXHSYyj/ 34ZFrNj9fIdaxy/EpGuLsJnJDgk9zYP+i0sDF7HM5idpNHN96r2lxa4hWYCttdNStY HbfgSKORdKnYqk7tMLEtle3fQTK65+D+CWaZgBdVsC0gu7CNgejddL6JqCqUNfDkxT qtu+X236s+8/mPmg5HfBrYUOcyWJrX26xgtf2MxpI71w4T/6GsUTQQZLWX5V6g+pvi JFJ+VvIQwX7ig== From: Maxime Ripard Date: Thu, 22 Feb 2024 19:14:21 +0100 Subject: [PATCH v7 35/36] drm/sun4i: hdmi: Consolidate atomic_check and mode_valid Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240222-kms-hdmi-connector-state-v7-35-8f4af575fce2@kernel.org> References: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> In-Reply-To: <20240222-kms-hdmi-connector-state-v7-0-8f4af575fce2@kernel.org> To: Maarten Lankhorst , Thomas Zimmermann , David Airlie , Daniel Vetter , Jonathan Corbet , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Hans Verkuil , Sebastian Wick , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , 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 , Sui Jingfeng X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4307; i=mripard@kernel.org; h=from:subject:message-id; bh=T+Mwu+EH8KKp7SKPsP5xhhewnkamDcEqVw1vxC33JeM=; b=owGbwMvMwCX2+D1vfrpE4FHG02pJDKnX+/4nvJn7iXPDwx83j1tOMPO3WD27Lad3PdePqgrfX pN7D/9Wd5SyMIhxMciKKbLECJsviTs163UnG988mDmsTCBDGLg4BWAiM9kZGa6+uHcz8iajdM+n 1yz3q1f/DbtRuWVe7AnNc4t2GKss5ddh+F+lLhZy3mS2SOB7m2e7S+5qqb6olti+7PUck9BnMyU WmzMAAA== X-Developer-Key: i=mripard@kernel.org; a=openpgp; fpr=BE5675C37E818C8B5764241C254BCFC56BF6CE8D X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791624956995894336 X-GMAIL-MSGID: 1791624956995894336 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. Acked-by: Sui Jingfeng Signed-off-by: Maxime Ripard Reviewed-by: Jernej Skrabec --- 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, };