From patchwork Sat Feb 17 18:47:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ond=C5=99ej_Jirman?= X-Patchwork-Id: 202674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp462054dyc; Sat, 17 Feb 2024 10:47:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXy7VrFJmfcTyfF/3kYCjZFQk/gUFXUGNxl7dzXR1ybZmEBJMOBaopCUWzHSj5YgUwrfSBT99Kj08iYu2TPfZN/YJsINA== X-Google-Smtp-Source: AGHT+IEzAzLVOTYItL/b0cgN5rU1jetm795imaMc8g9dme0a7N9qHuOU0K9pjPHVl8olDgVxgTFo X-Received: by 2002:a81:91ce:0:b0:607:d62f:1a18 with SMTP id i197-20020a8191ce000000b00607d62f1a18mr2235372ywg.33.1708195661190; Sat, 17 Feb 2024 10:47:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708195661; cv=pass; d=google.com; s=arc-20160816; b=evJ43UoJMdlrCKmxpqmTelmxoIPTmAb4gF2buhJA8OIA3jNS5Fv8E7PKEZSatHg1dX +iK9iplBUluNL1YmO106WDku4MRHOXrbjr//qPfb/oeTVmlfC37zVbIwsbRpPj75BGw+ ToOl3Lv59sGUOICGasXscjZp0v87B7MY7w2lNmghEe8Pymu3fQOvAKESD6doeZF83oDu Xpox9EnvNc7Rhb8NGjcTKjZrCDcoX/Cfc+FmbjJQjNgM8KpJKIqeVcmkXT+8YV+2Sfa3 fFvHp62U3mrO0sGSlqBClG4vvFNPk65vt8pxqP9+Z40Xj+EfqmWnc/sN2cV9lV77AThn eRyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=mFjWwpyFtmH4nIccv65pJbjepSZ1pyS0Vu6K5pXsGGs=; fh=K/ZzRTF/PQ3C1bylR3z+17TS5qDhG8qPVnq0n479jhw=; b=C8S1NtUlYZIjX+hpyg5q+W6t3McSBN2cG1dgNH8rX92xT2tjX0Djurd5naZn91WpmS ddRU17s3O8pqC9cHH3pbEhAIA3GBbc4xjo6RCAgYag4+PxcUyGIt4SopZ8iMyqPiwt9x PTkB6AHCbNon+4yWIeJcVHQtOBzHNAsU8/HWQSw0BuA2cin5y+B8ob9YQ9Ehm2ILlXb3 rzkZwSODMdiFXVRYT6dGXYXFGUVjf+0715KkUQjuFK0lxyhsD9p+lsVCHxf4XJuS3NkY zWSgYpb4e2a2btPxkywvs+E3LUofbkCdqsu/yv3y5tjHdaZwtTUFIPPy7t+PONVnvIfN DTtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=nrGm2lL8; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-70019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id t6-20020ac85306000000b0042c41d8d797si2333888qtn.380.2024.02.17.10.47.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 17 Feb 2024 10:47:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-70019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=nrGm2lL8; arc=pass (i=1 spf=pass spfdomain=xff.cz dkim=pass dkdomain=xff.cz dmarc=pass fromdomain=xff.cz); spf=pass (google.com: domain of linux-kernel+bounces-70019-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-70019-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C04911C22090 for ; Sat, 17 Feb 2024 18:47:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0C31B7E566; Sat, 17 Feb 2024 18:47:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="nrGm2lL8" Received: from vps.xff.cz (vps.xff.cz [195.181.215.36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C1691C282 for ; Sat, 17 Feb 2024 18:47:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.181.215.36 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708195646; cv=none; b=g59HOFCx8vzJCQ/B49vpEhn3AX7f9t3TYdqF11UMqmJXBHMv2TVfbOBoKHir6yh/or8th2cQIgWCsz6R5gaGMmCsBnroq9l3vGOH0IboyTP1xtzk0tEqGTOzRsu20ZhKparRLckJQkTyWs40q0KDF+w7JHITHNn+IExcfmPKDng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708195646; c=relaxed/simple; bh=M7kFL6IVY5bC9B0FS4qqIwBemjDZhp54+jL5ahTfYbk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=iPd4NZyHydpu83K2x0UZ/92fTI76yFawSjfVRq3YpI2uFd2IHP19P+R3Apbtgs+22nu6tH/R1JSaYxsdMR2bC5/ysKqdTQ2PeAEQFKV2fLduuz7cfFmwX8nI45HJT3IUFCJJsfbdCB2yKh/XS5yUV1znWKLBzWVkE/+0XbJR4/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz; spf=pass smtp.mailfrom=xff.cz; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b=nrGm2lL8; arc=none smtp.client-ip=195.181.215.36 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=xff.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xff.cz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xff.cz; s=mail; t=1708195642; bh=M7kFL6IVY5bC9B0FS4qqIwBemjDZhp54+jL5ahTfYbk=; h=From:To:Cc:Subject:Date:From; b=nrGm2lL8aZW3rvmIDuLQAapt+SGeUWtVznCP3ghwOu7Ivq2TiYeE//Sl2NJGQIu3k ZL/fE1Yz0f26hI7bnNryID4CMZPzGSiqWpZm302C2g6hy9+mJchtxjYxFOv+JODHjd doD8ZpWYUZsWi2gR8r106LG4LB1oOiTX0iw5WMKk= From: =?utf-8?q?Ond=C5=99ej_Jirman?= To: linux-kernel@vger.kernel.org Cc: Ondrej Jirman , Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , Andy Yan , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org (open list:DRM DRIVERS FOR ROCKCHIP), linux-arm-kernel@lists.infradead.org (moderated list:ARM/Rockchip SoC support), linux-rockchip@lists.infradead.org (open list:ARM/Rockchip SoC support) Subject: [PATCH] drm: rockchip: dw-mipi-dsi: Fix hsclk calculation for non-burst video modes Date: Sat, 17 Feb 2024 19:47:15 +0100 Message-ID: <20240217184720.1753730-1-megi@xff.cz> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791172973282899225 X-GMAIL-MSGID: 1791172973282899225 From: Ondrej Jirman For panels that don't use video burst mode, hsclock should match the pixel clock * bpp / lane exactly. This fixes display image corruption on Pinephone Pro, which doesn't use video burst mode to drive the panel. To simplify the addition of exact fout calculation for non-burst modes, the code is re-organized in order to not redo the same calculation multiple times, and to use identical algorithm for per-lane bitrate for internal and external dphy use cases. Signed-off-by: Ondrej Jirman --- .../gpu/drm/rockchip/dw-mipi-dsi-rockchip.c | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c index 4cc8ed8f4fbd..7468324872ec 100644 --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi-rockchip.c @@ -548,8 +548,6 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, const struct drm_display_mode *mode, { struct dw_mipi_dsi_rockchip *dsi = priv_data; int bpp; - unsigned long mpclk, tmp; - unsigned int target_mbps = 1000; unsigned int max_mbps = dppa_map[ARRAY_SIZE(dppa_map) - 1].max_mbps; unsigned long best_freq = 0; unsigned long fvco_min, fvco_max, fin, fout; @@ -567,30 +565,28 @@ dw_mipi_dsi_get_lane_mbps(void *priv_data, const struct drm_display_mode *mode, return bpp; } - mpclk = DIV_ROUND_UP(mode->clock, MSEC_PER_SEC); - if (mpclk) { - /* take 1 / 0.8, since mbps must big than bandwidth of RGB */ - tmp = mpclk * (bpp / lanes) * 10 / 8; - if (tmp < max_mbps) - target_mbps = tmp; - else - DRM_DEV_ERROR(dsi->dev, - "DPHY clock frequency is out of range\n"); + fout = mode->clock * bpp / lanes; + if (mode_flags & MIPI_DSI_MODE_VIDEO_BURST) + fout = fout * 10 / 8; + fout *= MSEC_PER_SEC; + + if (fout > max_mbps * USEC_PER_SEC) { + DRM_DEV_ERROR(dsi->dev, + "DPHY clock frequency is out of range\n"); + return -EINVAL; } - /* for external phy only a the mipi_dphy_config is necessary */ + /* for external phy only the mipi_dphy_config is necessary */ if (dsi->phy) { - phy_mipi_dphy_get_default_config(mode->clock * 1000 * 10 / 8, - bpp, lanes, + phy_mipi_dphy_get_default_config_for_hsclk(fout, lanes, &dsi->phy_opts.mipi_dphy); - dsi->lane_mbps = target_mbps; + dsi->lane_mbps = DIV_ROUND_UP(fout, USEC_PER_SEC); *lane_mbps = dsi->lane_mbps; return 0; } fin = clk_get_rate(dsi->pllref_clk); - fout = target_mbps * USEC_PER_SEC; /* constraint: 5Mhz <= Fref / N <= 40MHz */ min_prediv = DIV_ROUND_UP(fin, 40 * USEC_PER_SEC);