Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2103794rdb; Sun, 11 Feb 2024 11:26:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVJ/f1NbS1XkHk9FZSr6vya22aZwQiceBfwfQFIDrFf7mOXhhJxyvQJNccgam373eid4VxQaZcPao/e8CWbVIFJfy99AvnbepSf4pGXpQ== X-Google-Smtp-Source: AGHT+IG5D+Ep3y2HqB6+Am6iB0/lOnIkFwyoGGR9o0r2L2UMuR5XRG3Z1aCmXZiaIp1Xr6y38PHr X-Received: by 2002:a50:fb95:0:b0:55f:8c5d:e55e with SMTP id e21-20020a50fb95000000b0055f8c5de55emr3060960edq.26.1707679569232; Sun, 11 Feb 2024 11:26:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707679569; cv=pass; d=google.com; s=arc-20160816; b=Hy9rc4vL13sm3Jgx0+OfXSEYw/lyXR+FO+9uoawoYVFbgXu0IbU2NTzIy5olDx3tGj aB6jPrJMEmFoQf3OP8NE8DLoGMeh0ngjXxNq3ChoicmSaROMt1QjOKQhKu5NqrbhMQNv Ark/xWeZzJPTHJw1lnN3A1h345sHTcmdMg6K9FX6q2bJgErXdpCS4Q6JFFPn4ml14vgN 2ZtZg/ufXoGM5aJXbg5xx7xUn3vlpDtGHwhlU5RW2k9BfxJd4m4JNeVVMWo0L9LvUKPe TxGoPc5pDGKnNYXvTbgi70I/maLVww9Wg/57xQVkW0EHWHffU2iEOsUpLL87bc1/kZjL cPUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=1f32tzu/y4Gfgku7lI73fww2+tjCv5NJWfW1eAe7igo=; fh=Vh+LlirkmU2ooCkDuc1GgwCgSF0KOMGHO8gASAmjtlE=; b=tw+LQPol+JP56628gLZpJYbauio7+xbfB2Yv7QhubQAkSDyA0MY+00rl9w5JHQsfbU D+0mriHH2evjlwH2F04NtIyQdj+73SJcV71GPrZLrozB9XidPaWtZlAl8R8AgUqDi6Rl 1kfgsL4NpEaklmS1H672H34iFKEj/5CcFPnoYY8TCP6rfCQJwJyKJmnmmJzRWhppr8eZ c0S950Mo3mg8Jn14pTS+dIFRNxgK+heTDATYlnUR5rYm1wJcSrbgbG/xMquAbhaWClzi TwveeJcmgx2rP9ah2tzrbYA2T41MXh6sEC8omLxbiqH2iQm5sYDZzLuzpKUy4e64bkqh Rhcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=sWJbAR6O; 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-60927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60927-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=xff.cz X-Forwarded-Encrypted: i=2; AJvYcCWXtteORX2ps/KVZ70+uNyuYJB6Dz6c3tV26q2IDgWYpJtrLIPZ7HOERfCt3d5xgtTujiEJ2cXTcbGBTr2uXTbIo9TNmFhCcOvO7gDjRA== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v11-20020a056402348b00b005617a85905dsi1516441edc.491.2024.02.11.11.26.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 11:26:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@xff.cz header.s=mail header.b=sWJbAR6O; 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-60927-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60927-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id C3E3C1F23633 for ; Sun, 11 Feb 2024 19:26:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 141BB5DF35; Sun, 11 Feb 2024 19:25:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xff.cz header.i=@xff.cz header.b="sWJbAR6O" 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 8B1D55DF1E; Sun, 11 Feb 2024 19:25:37 +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=1707679540; cv=none; b=I9D9TrNNtmt4+hNbc/PX7fska4efn1jfUiR7m/8icauh4+xtoQE7eP/6Rcx+XAbtDHya+JAz31OFx6Tdu5ZQ8s942/Zq0sEaZCDvaftNRf2Sof7fzfplyS5qUxkE16ygnSVEs5joxfZJCctqtqAgmHSew564ID3tmLLMj/dTodU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707679540; c=relaxed/simple; bh=Z25xX+bia1okSsqB7nry5Ae+hz9tSpeaIvW4gUl9Nvk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=tY5eE/wYMLkwbcWgnZ18fx9k18BPwoAPxFP2W85S+jbERuoYhu8xwEYNpOwDuiA8QEcwlh9yzqVK4ZlrbuWJh2JD+ZUOGJf39Bl2GnQUnchKrsIx2AJS8L8rOrmvzv94R0DNbobkpdA90WDqjdNrJJIl3Thv8wTmLbIbGTEUGuo= 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=sWJbAR6O; 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=1707679529; bh=Z25xX+bia1okSsqB7nry5Ae+hz9tSpeaIvW4gUl9Nvk=; h=Date:From:To:Cc:Subject:X-My-GPG-KeyId:References:From; b=sWJbAR6OOaa2c8K/IhfYfHLR//CTYGvBOg2nHOeuBAGccuAKi+qMKGIC+vOuxFTml 4N6LAxX7rt5h0tCtN1PtHKZgSaft/hCB6K38T1lXJj03Z2uB3GDnpJet3eodCdfLnV QVaK/RQqsgePuQcFmuB5IKOYAbiDrHJugcqnxkWQ= Date: Sun, 11 Feb 2024 20:25:29 +0100 From: =?utf-8?Q?Ond=C5=99ej?= Jirman To: Frank Oltmanns Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Guido =?utf-8?Q?G=C3=BCnther?= , Purism Kernel Team , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: Re: [PATCH v2 0/6] Pinephone video out fixes (flipping between two frames) Message-ID: Mail-Followup-To: =?utf-8?Q?Ond=C5=99ej?= Jirman , Frank Oltmanns , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Guido =?utf-8?Q?G=C3=BCnther?= , Purism Kernel Team , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org X-My-GPG-KeyId: EBFBDDE11FB918D44D1F56C1F9F0A873BE9777ED References: <20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev> <87wmrbxckj.fsf@oltmanns.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87wmrbxckj.fsf@oltmanns.dev> Hi Frank, On Sun, Feb 11, 2024 at 04:09:16PM +0100, Frank Oltmanns wrote: > Hi Ondřej, > > On 2024-02-05 at 17:02:00 +0100, Ondřej Jirman wrote: > > On Mon, Feb 05, 2024 at 04:54:07PM +0100, Ondřej Jirman wrote: > >> On Mon, Feb 05, 2024 at 04:22:23PM +0100, Frank Oltmanns wrote: > >> > >> [...] > >> > >> Also sunxi-ng clk driver does apply NM factors at once to PLL_GPU clock, > >> which can cause sudden frequency increase beyond intended output frequency, > >> because division is applied immediately while multiplication is reflected > >> slowly. > >> > >> Eg. if you're changing divider from 7 to 1, you can get a sudden 7x output > >> frequency spike, before PLL VCO manages to lower the frequency through N clk > >> divider feedback loop and lock on again. This can mess up whatever's connected > >> to the output quite badly. > >> > >> You'd have to put logging on kernel writes to PLL_GPU register to see what > >> is written in there and if divider is lowered significantly on some GPU > >> devfreq frequency transitions. > > By looking at the clocks in clk_summary in debugfs, the rate of PLL-GPU > always matches the rate of the GPU (at least at 120, 312, and 432 MHz). > This is further underlined by the fact, that none of the rates can be > achieved by integer dividing one of the other rates. sunxi-ng would > only favor a different rate for pll-gpu than the one that is requested > for the gpu, if pll-gpu is already running at a rate such that there > exists an M ∈ {1, 2, 3, 4, 5, 6, 7, 8}, where > rate of pll-gpu / M = requested gpu rate > or if the requested rate could not be reached directly by pll-gpu. Both > is not the case for the rates in question (120, 192, 312, and 432 MHz). > > This means that the following divisor/multipliers are used by sunxi-ng's > ccu_nm: > N = 5, M = 1 for 120 MHz (min value without PATCH 6) > N = 8, M = 1 for 192 MHz (min value after applying PATCH 6) > N = 13, M = 1 for 312 MHz > N = 18, M = 1 for 432 MHz > > So, with or without PATCH 6, the divider stays constant and it's only > the multiplier that changes. This means, there should be no unexpected > frequency spikes, right? Maybe. Thanks for giving it a try. There may still be other kinds of glitches even if the divisor stays the same. It all depends how the register update is implemented in the PLL block. It's hard to say. I guess, unless Allwinner guarantees glitchless output from a given PLL when changing its parameters, you can't rely on the output being clean during changes. > >> It's also unclear what happens when FRAC_CLK_OUT or PLL_MODE_SEL changes. > > Those are not changed once the clock is initialized. The bug however > occurs hours or days after booting. IMO, this makes it unlikely that this > could be the culprit. > > >> Maybe not much because M is supposed to be set to 1, but you still need to > >> care when enabling fractional mode, and setting M to 1 because that's exactly > >> the bad scenario if M was previously higher than 1. > >> > >> It's tricky. > >> > >> Having GPU module clock gated during PLL config changes may help! You can > >> do that without locking yourself out, unlike with the CPU PLL. > >> > >> There's a gate enable bit for it at GPU_CLK_REG.SCLK_GATING. (page 122) > > The GPU should already be properly gated: > https://elixir.bootlin.com/linux/v6.7.4/source/drivers/clk/sunxi-ng/ccu-sun50i-a64.c#L599 How so? That's just clock declaration. How does it guarantee the clock to the module is gated during parent PLL configuration changes? CLK_SET_RATE_PARENT only gates output on re-parenting, not on parent rate changes, according to the header: https://elixir.bootlin.com/linux/v6.7.4/source/include/linux/clk-provider.h#L19 You'd need perhaps CLK_SET_RATE_GATE *and* still verify that it actually works as expected via some tracing of gpu clock enable/disable/set_rate and pll-gpu set_rate. CLK_SET_RATE_GATE seems confusingly docummented: https://elixir.bootlin.com/linux/v6.7.4/source/drivers/clk/clk.c#L1034 so I don't particularly trust it does exaclty what the header claims and what would be needed to test the theory that gating gpu clock during rate change might help. kind regards, o. > Thank you for your detailed proposal! It was insightful to read. But > while those were all great ideas, they have all already been taken care > of. I'm fresh out of ideas again (except for pinning the GPU rate). > > Again, thank you so much, > Frank > > >> > >> Kind regards, > >> o. > >> > >> > I very much appreciate your feedback! > >> > > >> > [1] https://gitlab.com/postmarketOS/pmaports/-/issues/805 > >> > > >> > Signed-off-by: Frank Oltmanns > >> > --- > >> > Changes in v2: > >> > - dts: Increase minimum GPU frequency to 192 MHz. > >> > - nkm and a64: Add minimum and maximum rate for PLL-MIPI. > >> > - nkm: Use the same approach for skipping invalid rates in > >> > ccu_nkm_find_best() as in ccu_nkm_find_best_with_parent_adj(). > >> > - nkm: Improve names for ratio struct members and hence get rid of > >> > describing comments. > >> > - nkm and a64: Correct description in the commit messages: M/N <= 3 > >> > - Remove patches for nm as they were not needed. > >> > - st7703: Rework the commit message to cover more background for the > >> > change. > >> > - Link to v1: https://lore.kernel.org/r/20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev > >> > > >> > --- > >> > Frank Oltmanns (6): > >> > clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate > >> > clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m ratio and parent rate > >> > clk: sunxi-ng: nkm: Support minimum and maximum rate > >> > clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI > >> > drm/panel: st7703: Drive XBD599 panel at higher clock rate > >> > arm64: dts: allwinner: a64: Fix minimum GPU OPP rate > >> > > >> > arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi | 4 ++-- > >> > drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 14 +++++++---- > >> > drivers/clk/sunxi-ng/ccu_nkm.c | 34 +++++++++++++++++++++++++++ > >> > drivers/clk/sunxi-ng/ccu_nkm.h | 4 ++++ > >> > drivers/gpu/drm/panel/panel-sitronix-st7703.c | 14 +++++------ > >> > 5 files changed, 56 insertions(+), 14 deletions(-) > >> > --- > >> > base-commit: 059c53e877ca6e723e10490c27c1487a63e66efe > >> > change-id: 20231218-pinephone-pll-fixes-0ccdfde273e4 > >> > > >> > Best regards, > >> > -- > >> > Frank Oltmanns > >> >