From patchwork Sat Dec 16 16:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Bee X-Patchwork-Id: 13495687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F058BC46CCD for ; Sat, 16 Dec 2023 16:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Omr5yEGir3aWd7p6AAJBpb3/uJ5pU7SXurjOU52FpK4=; b=rAnKMh6vcL0HwE 8TWYdg3oxBjVvVXGXVN7rh7cDyptwyreb3OgIzDAcysKBdjDJ7OB41HIWZZpG6x13XQU0vw6vL5yG UjW9gP+E/Po0OHWs/gzaLjcnw5LlwXOv8l7SnuyZJTN5c3dFM882sSeWOV7JQbhCpGk9ninN7eKi/ 2ncEHNbl3AmX3SGYYGLp5/5DUs6Bh3sEENMBzcV+FliScQBb4YL991HYAXwUFZS5z2t8w64LDpQuL m4XtR1iTPY8Kaw0622qBGjtyUecC+m9nm5K3lfeZc5u2Q/mVwhEE5cmrj0AW5x5hlfEfTMIkDm4go DsAii6bxStBlnFGUmeJg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rEXXk-006M73-2e; Sat, 16 Dec 2023 16:29:36 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rEXVf-006K0p-0L; Sat, 16 Dec 2023 16:27:30 +0000 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-50be24167efso1826363e87.3; Sat, 16 Dec 2023 08:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702744042; x=1703348842; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E8OEv0l6dNVJqHF1ONziiRRjeg+pBs39OamlQeNnAzk=; b=ah+NS0akpDQivM/VNoB0ewnfKlMZ2ncwRzYas/4OMtLdi7bIAP6UBPn/k6sjwHGaqM sXnEn4mWrYDZmqG6OHnWbtA+wB/2GDlDWQilApZPfurffYl6trKREXVsjBXhqvkeOFWc 2fgmJWekD95wgNrD3IowUPbLoXdRIbh3L91NJuWDYh5Gv8+oN0W5RS8N01fz7O8Un5Fl TPVIIN3HflE7jVMZFJzO8hv/M6kijJeM7IrYEpH10o+VWAMLpA14+GL8fKjaTM6ZxIoJ lwqanbUf/ZTjk4cyW6LoeWeHddzPucFXEsnAiMuEacKeMckvYUUsrL1evPwM7/x91fDc Q0zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702744042; x=1703348842; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E8OEv0l6dNVJqHF1ONziiRRjeg+pBs39OamlQeNnAzk=; b=ojPYJtMq1TzyrDZnwry1LEJ0uPV/SiGrMM9EYwET/9tRSdNXa9q2N+NJ2FpL0tsPTX 1ZxLqXeJoXvGggb/66CYwTNEJARG2J8gIuh24hQE5I/MSNmvU/23c7wBIAkKsbaXbBZf HCZ/E21pmHcUR4lX5sx0BGQ7IJdVqFwnsHpnHw3HeG6UCUglgy+4J+pVggFG7P0fUs/C knzw7QmmAAU0SIKnGMKkLYH2g1sLcws+bYcFwuFhgat1tKlY865KHG5rRANSMsPVSt5M XS2UdYuIVU8WudaXyeNePgkrwztznTJbYzNI70MHQHYCXRly9PvpHxP0HarzW25e0/H1 2yng== X-Gm-Message-State: AOJu0YwkyFLu3IL/0gWqutiZ0+SHAt4Gz7GLhEVdxkZM5sThGMXmqV8V BAeQmsw+RNJO4hE4E9QNGA== X-Google-Smtp-Source: AGHT+IFEHvRQbTKnZvTIoMFV/ssuD2uNon+ejyGS9XyVQHiyLyghPQz2Vh5IUyEFL7l0qFs8Pgr0pg== X-Received: by 2002:a05:6512:1327:b0:50d:6249:17cc with SMTP id x39-20020a056512132700b0050d624917ccmr3309272lfu.245.1702744042393; Sat, 16 Dec 2023 08:27:22 -0800 (PST) Received: from U4.lan ([2a02:810b:f40:4300:e807:d345:6f47:1db9]) by smtp.gmail.com with ESMTPSA id st10-20020a170907c08a00b00a1cd0794696sm11990362ejc.53.2023.12.16.08.27.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 08:27:22 -0800 (PST) From: Alex Bee To: Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann Cc: David Airlie , Daniel Vetter , devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Alex Bee Subject: [PATCH v2 23/27] drm/rockchip: inno_hdmi: Add basic mode validation Date: Sat, 16 Dec 2023 17:26:34 +0100 Message-ID: <20231216162639.125215-24-knaerzche@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231216162639.125215-1-knaerzche@gmail.com> References: <20231216162639.125215-1-knaerzche@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231216_082727_147807_56EB2063 X-CRM114-Status: GOOD ( 17.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 the variant has a phy reference clock we can additionally validate against VESA DMT'srecommendations. Signed-off-by: Alex Bee Reviewed-by: Maxime Ripard --- changes in v2: - rename inno_mode_valid -> inno_hdmi_display_mode_valid - fixed max_tolerance calculation - use abs_diff() instead of abs() - call in inno_hdmi_display_mode_valid in atomic_check drivers/gpu/drm/rockchip/inno_hdmi.c | 42 ++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/rockchip/inno_hdmi.c b/drivers/gpu/drm/rockchip/inno_hdmi.c index 792e5fad09bf..14473ca96e0f 100644 --- a/drivers/gpu/drm/rockchip/inno_hdmi.c +++ b/drivers/gpu/drm/rockchip/inno_hdmi.c @@ -26,6 +26,8 @@ #include "inno_hdmi.h" +#define INNO_HDMI_MIN_TMDS_CLOCK 25000000U + struct inno_hdmi_phy_config { unsigned long pixelclock; u8 pre_emphasis; @@ -548,6 +550,38 @@ static int inno_hdmi_setup(struct inno_hdmi *hdmi, return 0; } +static enum drm_mode_status inno_hdmi_display_mode_valid(struct inno_hdmi *hdmi, + struct drm_display_mode *mode) +{ + unsigned long mpixelclk, max_tolerance; + long rounded_refclk; + + /* No support for double-clock modes */ + if (mode->flags & DRM_MODE_FLAG_DBLCLK) + return MODE_BAD; + + mpixelclk = mode->clock * 1000; + + if (mpixelclk < INNO_HDMI_MIN_TMDS_CLOCK) + return MODE_CLOCK_LOW; + + if (inno_hdmi_find_phy_config(hdmi, mpixelclk) < 0) + return MODE_CLOCK_HIGH; + + if (hdmi->refclk) { + rounded_refclk = clk_round_rate(hdmi->refclk, mpixelclk); + if (rounded_refclk < 0) + return MODE_BAD; + + /* Vesa DMT standard mentions +/- 0.5% max tolerance */ + max_tolerance = mpixelclk / 200; + if (abs_diff((unsigned long)rounded_refclk, mpixelclk) > max_tolerance) + return MODE_NOCLOCK; + } + + return MODE_OK; +} + static void inno_hdmi_encoder_enable(struct drm_encoder *encoder, struct drm_atomic_state *state) { @@ -581,11 +615,13 @@ inno_hdmi_encoder_atomic_check(struct drm_encoder *encoder, struct drm_connector_state *conn_state) { struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); + struct inno_hdmi *hdmi = encoder_to_inno_hdmi(encoder); s->output_mode = ROCKCHIP_OUT_MODE_P888; s->output_type = DRM_MODE_CONNECTOR_HDMIA; - return 0; + return inno_hdmi_display_mode_valid(hdmi, + &crtc_state->adjusted_mode) == MODE_OK ? 0 : -EINVAL; } static struct drm_encoder_helper_funcs inno_hdmi_encoder_helper_funcs = { @@ -626,7 +662,9 @@ static enum drm_mode_status inno_hdmi_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { - return MODE_OK; + struct inno_hdmi *hdmi = connector_to_inno_hdmi(connector); + + return inno_hdmi_display_mode_valid(hdmi, mode); } static int