From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0EA8C0015E for ; Sun, 6 Aug 2023 13:07:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229591AbjHFNHf (ORCPT ); Sun, 6 Aug 2023 09:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjHFNHb (ORCPT ); Sun, 6 Aug 2023 09:07:31 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B958319A6; Sun, 6 Aug 2023 06:07:29 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4RJfqy5M5Mz9stK; Sun, 6 Aug 2023 15:07:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QjIv1HLGr8M+5FVCd5ineasqD/tSHOm93SA0NvSqrHk=; b=Gx+OkUETVuPsXIdpsbBbcj+fKzKlvOQ1uCKGlZt3DD2iUcxI2XAZ2AmywPWG6mFXVcj0W1 0Eifu1Adxz7wRdY0jwOlOKnR22JcE7H111YjCwhoGO5SehKd943GUavid6A2Dfe1FmVEKr eHy72HIgKnGeswSJZ7GwcFWUA4um+OtofeCUFPHv6eS8aINvUtTKcpzKlokn6s58s/IgfP fsxMfztWXyiwczO+PXAQ/MCcqcyV/DwL7WY+m2IpyVopPOnvKRq8QSRJl41Y1bYeatQCZh GyqmRrAz0NeiMGPcnb8Kmif3+awGeryx020i/x+XLKMTjQgMwcEmJmXRkD27Pw== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:46 +0200 Subject: [PATCH v5 01/11] clk: sunxi-ng: nkm: Use correct parameter name for parent HW MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-1-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=937; i=frank@oltmanns.dev; h=from:subject:message-id; bh=Sswnw4bRuM7bW6xD6gAVjI9f1VtIg89IqRRpy5EZ2+s=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sGou+voxb/S82pNeivjmNnup8GMti5l+ah3 DMm2uRpC96JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBgAKCRCaaaIIlErT x1pVC/9zkO8bLiH9IvDUTmhwUR5N261doqXodIn1o08jSfjRjGsGa41iNBtr9QEanG2aMXh+WD8 xHVWs5uHdS/sD5mKKI0yohq7m+WOb6H90x0YOZB0vZ0vyysBK1TiwutPEfUY+JBAHAWdR+L1V+/ vhMBRdx8RarjeN/RsyF4Sh5Hpgei+uLeqEGsgLoVDzOtRj2I6S72I2ME1VKlksDKbQPhr2oTreN iTCOPy7mgWBfqnAXVPlQ9MharQBXYr1eSK+E6jeXKekx4lCLRKPzukMqYWIt5WIFK4tbr9cKMGq H3burQ/LIWxmspQQZ+wszhA5mCGV5dmd5Rnp39LO24mrigB3/1MH7eVI0T6NdaDsSzMrcEV7umi 2iY5BnN5QbZFM6gOEytR2wivhhrYgclMhAlt7lZ37mnJnrLx6FsmqbrvjXVXqXPvMmEln2s1A15 nyDkWz6TtbV6qrd49bMexw7dWCM0MaO26Hn+tEoJw35GaZwmKnwq8I7CStQbgupSPHxPY= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfqy5M5Mz9stK Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ccu_nkm_round_rate() takes a clk_hw as parameter "hw". Since "hw" is the nkm clock's parent clk_hw, not the clk_hw of the nkm clock itself, change the parameter name to "parent_hw" to make it more clear what we're dealing with. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_nkm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index a0978a50edae..f267142e58b3 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -106,7 +106,7 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw = *hw, } =20 static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, - struct clk_hw *hw, + struct clk_hw *parent_hw, unsigned long *parent_rate, unsigned long rate, void *data) --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB12AC0015E for ; Sun, 6 Aug 2023 13:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229695AbjHFNHm (ORCPT ); Sun, 6 Aug 2023 09:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjHFNHf (ORCPT ); Sun, 6 Aug 2023 09:07:35 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 167BC19A6; Sun, 6 Aug 2023 06:07:33 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RJfr114Plz9sNb; Sun, 6 Aug 2023 15:07:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=g6sEdVa7J+6lcy1g1QB7y/EzCKzoUvGk1CHP/7ocrU8=; b=Wiw7MvMYMFpo64BhUYjRXXiFQY7BbMiKAK8oQHskLaKKEfFbyzF6YTkiGparTeS70oDGGk +OUWh+ahcoVKTzcPQ2UA24VUFCQCtkYRIY9gFPpJZYZ8CQ2d5IPx1DAE0t7Aqqa+DibTnY FM9NBaHuk8Crxq2eyz8WRSGwtNk8L9edCxWtNEyZzyHnDezsYvutjfZRrBAeqRURYkr1rs w6oJxeCbws/vWAiXJ4lkOqNVqxwn7JQHWXgPgUeIPUWwy2I+50mVwFOiagqNA+kyv2Bn4h bkxB9cbbNgYNeGn7U1bU8jpsh53rdiTvCSiGz1z45L8/kF1ewx+1j6NFvTJMDw== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:47 +0200 Subject: [PATCH v5 02/11] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-2-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=2859; i=frank@oltmanns.dev; h=from:subject:message-id; bh=BoixBk50el6YgCVc74Xk+M8fXWIcHSM+fM1Ls01062E=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sGvdjnx51+hIuZm7FBfXFWWJyiHnTdCyQ8u EoqWN2aEpiJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBgAKCRCaaaIIlErT xyyeC/0TF5kq/cc5XjwGXaNyO/SfJIIx/CEhiUrULFaTag9VAHiv1IvGZf4nyy9GyjNsrYVn/cG MovwMh2oyIUPItgCvk6tQE79NQTzxVMLFLRFSf1oe/sTF7DUUQcPp8L7BQ/zUsFv7NEauvgm/bY SyFguUozojqc+l6jZ6fB3EmzVNSg7sERADhJ61qHgiw2/rqi4iOS+uOxoAONEssXFgEoseus4Ig LZX+AQXTv0H0/cR4amA5Npgn1rCqUQcFANX7sYgfhRgWrt/dGfrib9+3jiWjs0f+iFf6GaAUUkd 7eLkrIULHKNjczJ2jLNDH/qZ0qZqR9+mZ8BFg9TsFU26Vokm0NX3XfVAjUPdQygmyKfEG1f3OGw B4q1KlylxV19RB20Occ5K+7AbeNPR20rKXPXCk7hsrkROJiKWMlkyirni7GICkSyxdaLs/X8TJu 17vk0aediTaMz2k+monA8ZViqBbKTekuNlfgqddCngsqrnqhA3Ctr7iAaH46IXBh9gt54= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case the CLK_SET_RATE_PARENT flag is set, consider using a different parent rate when determining a new rate. To find the best match for the requested rate, perform the following steps for each NKM combination: - calculate the optimal parent rate, - find the best parent rate that the parent clock actually supports - use that parent rate to calculate the effective rate. In case the clk does not support setting the parent rate, use the same algorithm as before. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_nkm.c | 45 ++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index f267142e58b3..ea1b77e9b57f 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -6,6 +6,7 @@ =20 #include #include +#include =20 #include "ccu_gate.h" #include "ccu_nkm.h" @@ -16,6 +17,45 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; =20 +static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *pare= nt_hw, + unsigned long *parent, unsigned long rate, + struct _ccu_nkm *nkm) +{ + unsigned long best_rate =3D 0, best_parent_rate =3D *parent, tmp_parent = =3D *parent; + unsigned long best_n =3D 0, best_k =3D 0, best_m =3D 0; + unsigned long _n, _k, _m; + + for (_k =3D nkm->min_k; _k <=3D nkm->max_k; _k++) { + for (_n =3D nkm->min_n; _n <=3D nkm->max_n; _n++) { + for (_m =3D nkm->min_m; _m <=3D nkm->max_m; _m++) { + unsigned long tmp_rate; + + tmp_parent =3D clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); + + tmp_rate =3D tmp_parent * _n * _k / _m; + if (tmp_rate > rate) + continue; + + if ((rate - tmp_rate) < (rate - best_rate)) { + best_rate =3D tmp_rate; + best_parent_rate =3D tmp_parent; + best_n =3D _n; + best_k =3D _k; + best_m =3D _m; + } + } + } + } + + nkm->n =3D best_n; + nkm->k =3D best_k; + nkm->m =3D best_m; + + *parent =3D best_parent_rate; + + return best_rate; +} + static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long= rate, struct _ccu_nkm *nkm) { @@ -124,7 +164,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux= _internal *mux, if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate *=3D nkm->fixed_post_div; =20 - rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm); + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) + rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm); + else + rate =3D ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate,= &_nkm); =20 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /=3D nkm->fixed_post_div; --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C544CC04E69 for ; Sun, 6 Aug 2023 13:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbjHFNHk (ORCPT ); Sun, 6 Aug 2023 09:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229573AbjHFNHf (ORCPT ); Sun, 6 Aug 2023 09:07:35 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A861F19A7; Sun, 6 Aug 2023 06:07:33 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RJfr24qVTz9sZT; Sun, 6 Aug 2023 15:07:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327250; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9/AP7UiU8qhdUXkhdNLxJOtFL/gExqBQUGjN0bV4ALI=; b=NENAiv+rv+bGTCS8/iJADXEEDcGEYw/IlD0GwW2bCoGqHzmz1qSJiHWBr8KhCcZ8inb7Nv gOB8O2gVpkgjP4veo/0trrRA55n7iJRBMGFZTQNJSo+LiC7RXOY3Y7el9aaJ2Q5K9ueCAZ GlrZ3Il5klGJBaiAazti/UA1eriTMslZdUkgFmBKnkLwo1eMTCNWqC4Mrh6vmztXuFrSDV y+jq0Nxoum0xEJ8hwe4ukEev0x8nmMtrRsjZRalyrY89K5C5PTS9m0+afUvJtp0FOiatUf P2LrbTbDVZJ4DKkOQUeyjmhmrfds3BzZYeRt/56nYhSMg1vDrpiA7mX4Fjh47Q== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:48 +0200 Subject: [PATCH v5 03/11] clk: sunxi-ng: a64: allow pll-mipi to set parent's rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-3-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=852; i=frank@oltmanns.dev; h=from:subject:message-id; bh=MYgMUXDylKq1ueF0/z4NSPOcrbzoRllAat6F65tgrPA=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sHnloZRzJuGt3lvpsh+p8RC+xhWEURHdKBN Cyakv5yFkeJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT xx9TC/9IjZMxKzcUHZQpldwWSgz3YyRgiJUWBEb4yLsRg+uH495gGDtLLPm/VDHU4YJXV2cfNjj PtC0D3pvGs0GKCzkRdCAWkHGDd//slD27POHpv4LAl1b8veUjfYpClFR21LVRLFGsQsY7OVPjQc PpRBNX1MQK2zAOO0bOSAfnL9sYxmq7IyKzuDHgtlhZAitFa1aZGQ6k2gMYPfVNlb/Y5zNSBIUCe IJic5jNPoJriaJJ5UkHS/UFOPiLWSwH+5H16zSppXD/SlF5rCkDw9nPPTQyVSHp0MyTGZsgHd6a N5BRZ2pTtJFt1fxgpks5ngy0TX/NH9UHsVD9d59ao3oX74MYw7eMs2cmHE6ghFIY1OG807OriXn u+vY/ktseClX4tsg00Iu1yCow9wjLlTjYpRa140TQHhH88mGGEKz7BN9BdPVjnkG2ToetPdhaSI Lt9zP3qfirhiJAw4CeBRmbP9PzgAgbQv1WZDycyfT509/ElaLMrwSvm9E5I8l+VbukN6g= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The nkm clock now supports setting the parent's rate. Utilize this option to find the optimal rate for pll-mipi. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/c= cu-sun50i-a64.c index 41519185600a..a139a5c438d4 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -179,7 +179,8 @@ static struct ccu_nkm pll_mipi_clk =3D { .common =3D { .reg =3D 0x040, .hw.init =3D CLK_HW_INIT("pll-mipi", "pll-video0", - &ccu_nkm_ops, CLK_SET_RATE_UNGATE), + &ccu_nkm_ops, + CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT), }, }; =20 --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62F25C04A94 for ; Sun, 6 Aug 2023 13:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjHFNHp (ORCPT ); Sun, 6 Aug 2023 09:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjHFNHh (ORCPT ); Sun, 6 Aug 2023 09:07:37 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FFC119A9; Sun, 6 Aug 2023 06:07:35 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RJfr41dY4z9sWC; Sun, 6 Aug 2023 15:07:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327252; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9mBnj/sxnS9zwU8wD2TdC9KZuObHfj2Iut9ShLW7rE4=; b=wHuAxDd5BgHWIy6qClaImBiXiz/M/Zjisvencs4WrxtVHowJY7QMuX1AMU+ecZ6RXbfulk 8hTzWQ6ad7Ggmczrn7uj9rN/7Bf6TMf5iqDGuLrkoi3BbJTLPDE0dYFZ+vpARcN2jW3Ixq 9B10OAvjJwTRlakt27SFudJEyqhaDWn34pRokALYu2g3cihTnbLomOS20bdS1OybtyF2jG 017Zgfc8AiebXjBRyOKLlJTOIfAjvcTwjuyq/oYP6Q9OW5nZN0QaUFUVaiSgWw3+6Vz4+s wK81Bvcr/X525oadT+CJnNL8wPSYuL67pAhsJIYJ1b8dTF5mi4LLwX3UhxVB9A== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:49 +0200 Subject: [PATCH v5 04/11] clk: sunxi-ng: Add feature to find closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-4-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=925; i=frank@oltmanns.dev; h=from:subject:message-id; bh=gnSO2u9KSds+yso2ENUmK1fTBfjNRGShsPD5HpXqe+0=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sHEM2bFxC57sgboTsWggrljhrWXTJ1sKB8/ d6pVtHgP3uJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT x7EzC/45nGmbcJ73KqZZrpd0scAqn1wgPmLY7YmnJRLCFRL0DyJoyefI5555Tu7iOPHyDmTu8+P DyqrPk7HwfcRBIBpyUtqataoEnbSZxbx74lOU0MRqaLAkXdwSM7L9PTgvCF2Elg8/T+Mv8i+VB4 ksXbh9Vn7mE4XAZULzw+A9msFsYJtZjbNI2nSX04jnWAFhJXk8ptnXbnh1LVxoejuQvFPgwxWHa CoWz02j7Idxjk7O9qYGP+o/ds4gSrARi+YbhWFmgQoFVbKs9nK86FgNhuiWNM3CfAfDt1jpMm5F h9wEhgYB9huYKxaEXMNVkVOvwp/5EsTHB/aiZiK24CDXhQl/BN1N1RBdMmpnaqq487fJdhQFquj poQjvpBgLT5b6M/xX7x+OcaX1JAN6hcNJ9bgnFErVqqAUNVOMKNTY1B85yQbHHGb+zsVGy3/+xJ Eja11qHPeLfmVbwGwxEkceJf4M5m/gY7BFG4G4myBa16v0GSXW0/W/1tSQEP+ZxVR4hdU= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfr41dY4z9sWC Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The default behaviour of clocks in the sunxi-ng driver is to select a clock rate that is closest to but less than the requested rate. Add the CCU_FEATURE_CLOSEST_RATE flag, which can be used to allow clocks to find the closest rate instead. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Acked-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_c= ommon.h index fbf16c6b896d..5ad219f041d5 100644 --- a/drivers/clk/sunxi-ng/ccu_common.h +++ b/drivers/clk/sunxi-ng/ccu_common.h @@ -18,6 +18,7 @@ #define CCU_FEATURE_MMC_TIMING_SWITCH BIT(6) #define CCU_FEATURE_SIGMA_DELTA_MOD BIT(7) #define CCU_FEATURE_KEY_FIELD BIT(8) +#define CCU_FEATURE_CLOSEST_RATE BIT(9) =20 /* MMC timing mode switch bit */ #define CCU_MMC_NEW_TIMING_MODE BIT(30) --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 167CDC001DF for ; Sun, 6 Aug 2023 13:07:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230011AbjHFNHu (ORCPT ); Sun, 6 Aug 2023 09:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229595AbjHFNHj (ORCPT ); Sun, 6 Aug 2023 09:07:39 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA6D619B0; Sun, 6 Aug 2023 06:07:36 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4RJfr54g3Qz9sb4; Sun, 6 Aug 2023 15:07:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gyHR6cW2QR6OnAUrfo88G/ExONveB495BGT7pOTWnE0=; b=l3KOqfbgTmCZkmEXjDTQuModwoc6v57f3zYbDbSaHQTCj524Oy/FgH0/1T1rWEx8tFW90Y YD6g1XSjJczHkzEW4CClVas++io+rH61uZ71nbgy2XVxANoVIEHoYWzzbIMPj5ajlqu5Kk 4ilKdhqGpvYd/wjZd6+ujQCp71pAL9wBL+ImjV0C28z6wPQPMfzvJJK+K3jNvOQ21e5vBO oGCg+OQyZsMLO1MwW1Dh2JQLGfDGhRYH5kPDHCN/fvTc77CqA5ZrvUnM2uNCAF2Lvtf6yZ jWLybfN11ugOBBB+GgHgMlmI5dDutOLwVpPj2cmWb1eVhxd9dcjTvYu+D77+lg== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:50 +0200 Subject: [PATCH v5 05/11] clk: sunxi-ng: Add helper function to find closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-5-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=2054; i=frank@oltmanns.dev; h=from:subject:message-id; bh=G9TxumF2IGfxEJiLa7uWr7K3JxoemmvIjofrmdkSxSk=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sHqkjDz9bsW7VEf79eXkQGEmgFt2dyGd0Hw Cekysc4/WKJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT xwGhDACR9HIIL1q5cZAhnOzYErN7FS23jf5MPGkEw/xKvP1TWnnrJtw5YdwVJnlQSisFMHil2sG CqeLtCIUBHvO8kHwYpoINOFwpAuBLsO/xNlfXvWlTvtlG0CcJJo5lkf1RV5JJiWF83wptxGUzNA uDBACJU66Fu7Q28jFD6kMD70bfAGJ2ALPbZc8Mif8Kqy3l4Vq8ZVR8t1c1ueICA9i8/bjhuty9E 4G1rwU0UDKJ8k0FnIpAlV4GidMI+Mc8xi8D6ZZkld4F5xD0WFtJrnvYZxr1RlL+ioWoGRJzI6HB S+jGAxHMOp3IYA4fbTACXDx8adSKEgJXBjeWewjdPsluDZ4tMzlHHB8luc7GxC8We+++AvIVj4o wR3D0EFs7VJpkctOqg4AlT5kmStPttAxxB4IB4aE2XSUHvYdFjhjMqINbV2OyUC7p+OXioMBoxu 1toI56pd5lRNpdL/+EHRpUONkPO2+SIYQFEjqi0r/PSLWLa/GHuXheuAIxrpWHC9QGM9E= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfr54g3Qz9sb4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The default behaviour of clocks in the sunxi-ng driver is to select a clock rate that is closest to but less than the requested rate. Add the ccu_is_better_rate() helper function that - depending on the fact if thc CCU_FEATURE_CLOSEST_RATE flag is set - decides if a rate is closer than another rate. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_common.c | 12 ++++++++++++ drivers/clk/sunxi-ng/ccu_common.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_c= ommon.c index 8d28a7a079d0..8babce55302f 100644 --- a/drivers/clk/sunxi-ng/ccu_common.c +++ b/drivers/clk/sunxi-ng/ccu_common.c @@ -39,6 +39,18 @@ void ccu_helper_wait_for_lock(struct ccu_common *common,= u32 lock) } EXPORT_SYMBOL_NS_GPL(ccu_helper_wait_for_lock, SUNXI_CCU); =20 +bool ccu_is_better_rate(struct ccu_common *common, + unsigned long target_rate, + unsigned long current_rate, + unsigned long best_rate) +{ + if (common->features & CCU_FEATURE_CLOSEST_RATE) + return abs(current_rate - target_rate) < abs(best_rate - target_rate); + + return current_rate <=3D target_rate && current_rate > best_rate; +} +EXPORT_SYMBOL_NS_GPL(ccu_is_better_rate, SUNXI_CCU); + /* * This clock notifier is called when the frequency of a PLL clock is * changed. In common PLL designs, changes to the dividers take effect diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_c= ommon.h index 5ad219f041d5..942a72c09437 100644 --- a/drivers/clk/sunxi-ng/ccu_common.h +++ b/drivers/clk/sunxi-ng/ccu_common.h @@ -53,6 +53,11 @@ struct sunxi_ccu_desc { =20 void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock); =20 +bool ccu_is_better_rate(struct ccu_common *common, + unsigned long target_rate, + unsigned long current_rate, + unsigned long best_rate); + struct ccu_pll_nb { struct notifier_block clk_nb; struct ccu_common *common; --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54EADC04E69 for ; Sun, 6 Aug 2023 13:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229628AbjHFNHx (ORCPT ); Sun, 6 Aug 2023 09:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229656AbjHFNHj (ORCPT ); Sun, 6 Aug 2023 09:07:39 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BE219A6; Sun, 6 Aug 2023 06:07:38 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4RJfr70V79z9scB; Sun, 6 Aug 2023 15:07:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327255; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ulpryhyL1fmeYsGJ/YbYMV/lxBA4ghi1gWFL1YwCRLA=; b=KsXWslPsWmf9NXndeQm54LZV4BcpuJ6wHnsIP/f/GlTaE1Mgo+jE4KlLvddkd8vg6tAP84 01zIaaxSGLIQo2tDkHSJB4YUP9kfNwmZdkdd0DjcQ2GL2qFsTtOJY6kMiNdw0+jrwUlyrV AEHVl51tGoKTfLdobt0lmrG5mMVY2ex6qMlaciwTK/AmHuibxIqhCKTl9NLRcRcTzeynuV bIqC8LV0QHDSU7RTPA8mQNO2AM9FVFkQnKB3ZUE3DrL1CYwGZuQiCrRAsdFtajLWzTRPzF t1M+3g1sj9qj+w67sXYSDjCrl0bhYCsZTiCFBL+DvCbCSvEMDYOxF5aFlsM26Q== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:51 +0200 Subject: [PATCH v5 06/11] clk: sunxi-ng: nm: Support finding closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-6-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=5235; i=frank@oltmanns.dev; h=from:subject:message-id; bh=eW6KkKaJ9BQvJtir1IykKZIae/DH/+72MOsKsB7WpzM=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sHaCe4x63fqDVI2fzQrrTVMflGiKCkwMDd2 uHSSYPnV/aJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT x+wCC/4/kr9Lq69CJmJGUjpmSqRJ4YQouLR0zby+65slLsTDPXnS/S1Mh8su03yaIX+OPwkMEo8 Riyo7dzalkvoL/7xe64MeBvDMzOipw77vLWb8mY4bh66hiYE6LwyF+qpkdyKdY1ac613l+kPBBP YAC/gxRlDyDYoELTswccVFpOP+2j1kg5qMHrqdrx2HYI2hzYtwuAkWRnQS1t0qmNAEIGPxXX6M5 7/a7z/CcSMbnfAoH6layOojzAbeVjzw3lL6vyRggcYBMq5b+E0LrO9DUb+WneTBLdCebL9zEiaS E91yqmZVafz9wevFW3jaQ/T60kfRSxmW3Zw3p2rUtqy9Vp8+ZOoET6Tz4zo+CDCSUSDX8cTrRts bTKZbzgBKnWusFuf6Wz7xkDUhztgyqROgkj2J5e5Bkp0WgnL+DtUBTWKXHnbq8by6rzE7USGPBQ 9OSI9dXNRzpgJIBuFIdmsVXj8Vj3d1RglOpSf9fjIqhgMwKn4+xc4tvrN03TvItfEP+2A= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfr70V79z9scB Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the helper function ccu_is_better_rate() to determine the rate that is closest to the requested rate, thereby supporting rates that are higher than the requested rate if the clock uses the CCU_FEATURE_CLOSEST_RATE. Add the macro SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST which sets CCU_FEATURE_CLOSEST_RATE. To avoid code duplication, add the macros SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT that allows selecting arbitrary features and use it in the original SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX as well as the newly introduced SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST macros. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_nm.c | 13 +++++------- drivers/clk/sunxi-ng/ccu_nm.h | 48 +++++++++++++++++++++++++++++++++++++++= +--- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c index c1fd11542c45..ffac3deb89d6 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -27,8 +27,8 @@ static unsigned long ccu_nm_calc_rate(unsigned long paren= t, return rate; } =20 -static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long = rate, - struct _ccu_nm *nm) +static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned = long parent, + unsigned long rate, struct _ccu_nm *nm) { unsigned long best_rate =3D 0; unsigned long best_n =3D 0, best_m =3D 0; @@ -39,10 +39,7 @@ static unsigned long ccu_nm_find_best(unsigned long pare= nt, unsigned long rate, unsigned long tmp_rate =3D ccu_nm_calc_rate(parent, _n, _m); =20 - if (tmp_rate > rate) - continue; - - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate =3D tmp_rate; best_n =3D _n; best_m =3D _m; @@ -159,7 +156,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsign= ed long rate, _nm.min_m =3D 1; _nm.max_m =3D nm->m.max ?: 1 << nm->m.width; =20 - rate =3D ccu_nm_find_best(*parent_rate, rate, &_nm); + rate =3D ccu_nm_find_best(&nm->common, *parent_rate, rate, &_nm); =20 if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /=3D nm->fixed_post_div; @@ -210,7 +207,7 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned = long rate, &_nm.m, &_nm.n); } else { ccu_sdm_helper_disable(&nm->common, &nm->sdm); - ccu_nm_find_best(parent_rate, rate, &_nm); + ccu_nm_find_best(&nm->common, parent_rate, rate, &_nm); } =20 spin_lock_irqsave(nm->common.lock, flags); diff --git a/drivers/clk/sunxi-ng/ccu_nm.h b/drivers/clk/sunxi-ng/ccu_nm.h index 2904e67f05a8..93c11693574f 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.h +++ b/drivers/clk/sunxi-ng/ccu_nm.h @@ -108,7 +108,7 @@ struct ccu_nm { }, \ } =20 -#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ _parent, _reg, \ _min_rate, _max_rate, \ _nshift, _nwidth, \ @@ -116,7 +116,8 @@ struct ccu_nm { _frac_en, _frac_sel, \ _frac_rate_0, \ _frac_rate_1, \ - _gate, _lock, _flags) \ + _gate, _lock, _flags, \ + _features) \ struct ccu_nm _struct =3D { \ .enable =3D _gate, \ .lock =3D _lock, \ @@ -129,7 +130,7 @@ struct ccu_nm { .max_rate =3D _max_rate, \ .common =3D { \ .reg =3D _reg, \ - .features =3D CCU_FEATURE_FRACTIONAL, \ + .features =3D _features, \ .hw.init =3D CLK_HW_INIT(_name, \ _parent, \ &ccu_nm_ops, \ @@ -137,6 +138,47 @@ struct ccu_nm { }, \ } =20 +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags) \ + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags, \ + CCU_FEATURE_FRACTIONAL) + +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags) \ + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags, \ + CCU_FEATURE_FRACTIONAL |\ + CCU_FEATURE_CLOSEST_RATE) + #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \ _nshift, _nwidth, \ _mshift, _mwidth, \ --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFA65C001DF for ; Sun, 6 Aug 2023 13:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjHFNHz (ORCPT ); Sun, 6 Aug 2023 09:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbjHFNHl (ORCPT ); Sun, 6 Aug 2023 09:07:41 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6D7E19B1; Sun, 6 Aug 2023 06:07:39 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4RJfr84fGkz9ssc; Sun, 6 Aug 2023 15:07:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jP7azlWe913nN4pLhChAwYmOVnXxCr1K6ASPbVey0qI=; b=hg8A0IP+6qI1I3ktOHf4Yv0W+VaGmw8irBaJlfFOw6SlWKBUV2sw6igr3WxgrvYYd0mt7h p7kBREL0g6/ZDD1ZiPdpQI3dW0j1UGkp5k54b/wnBDl2qgA8n29mxEDdYswI/P4s4a1cU3 CN/BZB3bN+jiEutDfJ853kH9ifsQuYyYdkvFtgzXKQhBc3qRMvWDU/IEwcERtKA3Lsi72v 8R6K4nHjmG+oxvcMFxGPHOJtj6tr5Xd+DHvUz/zGTFid7CqvQyePz1COXohdinS1rzb34U DnMqqFLYM9V5JkXwVway+ugYd9/SM3O6bS2A3OBqG6ang+Wqt3+IFywC+kbxQg== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:52 +0200 Subject: [PATCH v5 07/11] clk: sunxi-ng: nkm: Support finding closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-7-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=3786; i=frank@oltmanns.dev; h=from:subject:message-id; bh=88DH4FmkecM+BvpS+IIc+feAri98ehm0OPoAyhARAxs=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sHMDzT02nFpWO+c/LmS60zlKqDNPcMKxq5N qLTTlHlqyKJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT x6SpC/sEiAeZYXhqG1P5D/E5rBVyUb9hwzWLZBvlpwDOoNGCrTtALN1bKllGg6oLlKJIi9ikNiH hvAMyvwyukEHs1II+4yjcBnfYs/Yb49/taalpPqjKEzf/5qWncIxzQp/qe3/je9enP8K66AI7Cr YMAEZn2GSceKIIV/mg/CySf69G3NVIt6RT0b5cT06+Od0XGvtmZy4lpxjJnmtvMKRg2Xs2TygU7 +tr261aGVg2OEaGgwyCcHJYsIvSA5ExZ8yLJcZM+haR7l9HClnIDokRgNoGZ7WbWmuyEOL+oCk3 CT+Qy12ceYOY+ZVRmpZxoY4qq6FpcaAt0tl3sYdGPkyrekUsHMIGuBqRndF+/BnejgFPjCWKOQf GH+4v+BuKA48ES3wVv2Yeb5XIRTuiavatR6gAdE4sMMhojvbGkGDUvmWIn1GdSSa/85+Li+f/ic OnDcM7xyv7DsT2leB/B7TT/ynEUsB3l4LqetGJ2MZPx4ycLIe7ecBQbOiF1zPtDTKdZko= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfr84fGkz9ssc Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When finding the best rate for a NKM clock, consider rates that are higher than the requested rate, if the CCU_FEATURE_CLOSEST_RATE flag is set by using the helper function ccu_is_better_rate(). Accommodate ccu_mux_helper_determine_rate to this change. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_mux.c | 2 +- drivers/clk/sunxi-ng/ccu_nkm.c | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 1d557e323169..3ca695439620 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -139,7 +139,7 @@ int ccu_mux_helper_determine_rate(struct ccu_common *co= mmon, goto out; } =20 - if ((req->rate - tmp_rate) < (req->rate - best_rate)) { + if (ccu_is_better_rate(common, req->rate, tmp_rate, best_rate)) { best_rate =3D tmp_rate; best_parent_rate =3D parent_rate; best_parent =3D parent; diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index ea1b77e9b57f..896bb1ef8642 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -17,7 +17,8 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; =20 -static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *pare= nt_hw, +static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *= common, + struct clk_hw *parent_hw, unsigned long *parent, unsigned long rate, struct _ccu_nkm *nkm) { @@ -33,10 +34,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(s= truct clk_hw *parent_hw, tmp_parent =3D clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); =20 tmp_rate =3D tmp_parent * _n * _k / _m; - if (tmp_rate > rate) - continue; =20 - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate =3D tmp_rate; best_parent_rate =3D tmp_parent; best_n =3D _n; @@ -57,7 +56,7 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(st= ruct clk_hw *parent_hw, } =20 static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long= rate, - struct _ccu_nkm *nkm) + struct _ccu_nkm *nkm, struct ccu_common *common) { unsigned long best_rate =3D 0; unsigned long best_n =3D 0, best_k =3D 0, best_m =3D 0; @@ -70,9 +69,7 @@ static unsigned long ccu_nkm_find_best(unsigned long pare= nt, unsigned long rate, =20 tmp_rate =3D parent * _n * _k / _m; =20 - if (tmp_rate > rate) - continue; - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate =3D tmp_rate; best_n =3D _n; best_k =3D _k; @@ -165,9 +162,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux= _internal *mux, rate *=3D nkm->fixed_post_div; =20 if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) - rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm); + rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common); else - rate =3D ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate,= &_nkm); + rate =3D ccu_nkm_find_best_with_parent_adj(&nkm->common, parent_hw, pare= nt_rate, rate, + &_nkm); =20 if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /=3D nkm->fixed_post_div; @@ -202,7 +200,7 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned= long rate, _nkm.min_m =3D 1; _nkm.max_m =3D nkm->m.max ?: 1 << nkm->m.width; =20 - ccu_nkm_find_best(parent_rate, rate, &_nkm); + ccu_nkm_find_best(parent_rate, rate, &_nkm, &nkm->common); =20 spin_lock_irqsave(nkm->common.lock, flags); =20 --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F34C3C0015E for ; Sun, 6 Aug 2023 13:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbjHFNH5 (ORCPT ); Sun, 6 Aug 2023 09:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbjHFNHo (ORCPT ); Sun, 6 Aug 2023 09:07:44 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3345319A6; Sun, 6 Aug 2023 06:07:41 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4RJfrB21Yxz9smF; Sun, 6 Aug 2023 15:07:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327258; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TjD5RUuDvuJH5h092AsaV1mTvvtxTHcezWL7uVLhzVw=; b=WCIkSL59yRzbxO7Cd+5CXfhrgRYJ/GOmpNs51kMCd5Bu7oVwa9XhpUsS5bX32JmZEfdrUT wYb0CVU2wPmreomP1pEOvXC5p/pwsTIlQvJVdS+aqY1SxmhYRDk8B/0daapvaFsdFV2eD1 Zqki1CdcY/gsArMj30ul0jFvLWIE7nwNxj3FNzX0ISkswUKJCs7CRYJFQLG2EmdFzplg22 AhtzSWPG/pCXTE3BWfgPA2+avtkupHPuNgEwitIlOOmTUE805Vb0u4YCbjqGxTeGmp+QvX JgOEhNrs7NAHUglyt2LNbOU6xBoseWpcydZIJdBRkgRYq+NkT+ccNQG3haNPJw== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:53 +0200 Subject: [PATCH v5 08/11] clk: sunxi-ng: mux: Support finding closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-8-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=3440; i=frank@oltmanns.dev; h=from:subject:message-id; bh=OvKXg4vQ+wbmZqDkAPDAPHykvEpUGR9vUTxoWn/TvUI=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sH2rQD7N/pKO3IK5DJNPbc4o7hwgupuHQYO TDQwMj2j4iJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bBwAKCRCaaaIIlErT x5riC/wJLP4De2988WYJxP7YFoz01YlNlZ5JrrNcLp6JQXF9WgmXZLSszca6hxejUI4Ls+oy2yr mwh3tHNoWMxP0S/heYro7SWGvsMfnKJrjT/N4zP4qPBbraqeMHT9VcNRO5o8llNXopH5d+zxYkn uk4XNFB0beUcnesz+4YUirpwxBwvlvpvrF5B1BMltbjrVkJNuQQobsDnxXAYQGcL2MLuddks0SQ zwK1rRBuTKs2gGysrmWd3bc/ZBQyo+ta8bPc6JlpkPwA7Iw10yO1OhpgkA97ZttwUw6K0o443dj U6rvciUazUIk4tW+MREXoCnOJ5U5PrRtiFxSqfVP8Af+AUj4T0M7gyk0giiYZ9alYK+kwHlV+GP /SSudMzjQMFGtTYsR3LuY0ju2+1PWpqg748JPGMB0SjTbpuiku+7UGED5fEHYepVdB8QWhqeJTS F9104esWTQYC5u8VZWq/rPGVyialabn9GLuNlkvYPJNEb93Ws9s62FyQy9sRx7GZeI0uI= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfrB21Yxz9smF Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When finding the best rate for a mux clock, consider rates that are higher than the requested rate when CCU_FEATURE_ROUND_CLOSEST is used. Furthermore, introduce an initialization macro that sets this flag. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_mux.c | 13 ++++++++++++- drivers/clk/sunxi-ng/ccu_mux.h | 38 +++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 3ca695439620..5edc63b46651 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -242,6 +242,17 @@ static int ccu_mux_set_parent(struct clk_hw *hw, u8 in= dex) return ccu_mux_helper_set_parent(&cm->common, &cm->mux, index); } =20 +static int ccu_mux_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct ccu_mux *cm =3D hw_to_ccu_mux(hw); + + if (cm->common.features & CCU_FEATURE_CLOSEST_RATE) + return clk_mux_determine_rate_flags(hw, req, CLK_MUX_ROUND_CLOSEST); + + return clk_mux_determine_rate_flags(hw, req, 0); +} + static unsigned long ccu_mux_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -259,7 +270,7 @@ const struct clk_ops ccu_mux_ops =3D { .get_parent =3D ccu_mux_get_parent, .set_parent =3D ccu_mux_set_parent, =20 - .determine_rate =3D __clk_mux_determine_rate, + .determine_rate =3D ccu_mux_determine_rate, .recalc_rate =3D ccu_mux_recalc_rate, }; EXPORT_SYMBOL_NS_GPL(ccu_mux_ops, SUNXI_CCU); diff --git a/drivers/clk/sunxi-ng/ccu_mux.h b/drivers/clk/sunxi-ng/ccu_mux.h index 2c1811a445b0..eb1172ebbd94 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.h +++ b/drivers/clk/sunxi-ng/ccu_mux.h @@ -46,20 +46,36 @@ struct ccu_mux { struct ccu_common common; }; =20 +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, _tabl= e, \ + _reg, _shift, _width, _gate, \ + _flags, _features) \ + struct ccu_mux _struct =3D { \ + .enable =3D _gate, \ + .mux =3D _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ + .common =3D { \ + .reg =3D _reg, \ + .hw.init =3D CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_mux_ops, \ + _flags), \ + .features =3D _features, \ + } \ + } + +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags) \ + SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags, \ + CCU_FEATURE_CLOSEST_RATE) + #define SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, _table, \ _reg, _shift, _width, _gate, \ _flags) \ - struct ccu_mux _struct =3D { \ - .enable =3D _gate, \ - .mux =3D _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ - .common =3D { \ - .reg =3D _reg, \ - .hw.init =3D CLK_HW_INIT_PARENTS(_name, \ - _parents, \ - &ccu_mux_ops, \ - _flags), \ - } \ - } + SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags, 0) =20 #define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \ _shift, _width, _gate, _flags) \ --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EB3BC001DF for ; Sun, 6 Aug 2023 13:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230207AbjHFNIA (ORCPT ); Sun, 6 Aug 2023 09:08:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230004AbjHFNHu (ORCPT ); Sun, 6 Aug 2023 09:07:50 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D860797; Sun, 6 Aug 2023 06:07:43 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4RJfrD33wsz9sW4; Sun, 6 Aug 2023 15:07:40 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/3jUW02TnjdYtDtyTpuIK2UaIeAHqfX2p8U1BU0MxI=; b=gE7Qe3FRFfS94coh3aDOD8vptroCe3bBW+0OxrKURdeA3qO5Ju1i3fiatm7ld2i9Cb4pih ZSLBYQsXzfxcKogOwUvKKMk6r73PE0iW+vK1bIUTk7Xq9pivsMGGtRQJxyAigKI4qunryr hz6vbUGlnzBwyD+/hy7jlGkYxhTixrljqUcddK5rANl281G8UlXGSLEMYwjS9c+iWAI+cA lnFJCxZmIrpoSw1kHGw3Eb59hArMs20dh8jea63dNOlMtiFJUmPIuw69VRQYR7hXUGHvaY MP2ywuLMlrJYqfhWvWIb0caXFfxntEqLuJWRuj/lwZLnd6i0zKXe5MNpMxNvFg== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:54 +0200 Subject: [PATCH v5 09/11] clk: sunxi-ng: div: Support finding closest rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-9-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=2120; i=frank@oltmanns.dev; h=from:subject:message-id; bh=BCjq/TvLd7Vyg2yzlkEqCcyLfH3Gamqs91hzh7NVMYE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sIf22ZiEzq9muhL+X98DikF0J5zWcMcfZ/X JEogB868vCJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bCAAKCRCaaaIIlErT x0KHC/9K9WzyLIVvorKsrsgQ0ioaRIfo7CZj7TNN8U43TMKhkP3w8KNLB06KXAc44ncAaVr2VTq rbJjUSPcSOR7JOAl1n4ViT4rTmULgcBXJXuHSHz2uvU1+6JonUqsZQn5i1ug2ikBDXFQXUFuPf5 VK3opMLlzgsVK06LrxsvkznBDULFAyWLfN4SAMnz7IuRsKaXR1lgwrMFiQ+t5kmcI8vwZagiiuC hq0XZNza6EZBAfkGO2RwfCd6116bcbXGs7BtNe1mDKivmc6dov4ePoR58MQb1y977nPJPRpYzR9 zm7PTQFjx9HIyV1ILniEC5xu1/8UWKyOkdZqyeTvPr6HHxUoEmS6TKPOfEJd4c7DnGaioTgzVZj 4/2eOvlbnbfBARSo/vcEXMF/xGwd2BGYNYQxgh8p/v9V0inCm5KPzmGpuka4KloQYjRA/Ak0Hup MfeV1lUJlxgVnek3hus37oxUyXowYFfRfJVIOPhR4Inf+P0K/2nr7CbJR+11cgC/W5kxM= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RJfrD33wsz9sW4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add initalization macros for divisor clocks with mux (SUNXI_CCU_M_WITH_MUX) to support finding the closest rate. This clock type requires the appropriate flags to be set in the .common structure (for the mux part of the clock) and the .div part. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu_div.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu_div.h b/drivers/clk/sunxi-ng/ccu_div.h index 948e2b0c0c3b..90d49ee8e0cc 100644 --- a/drivers/clk/sunxi-ng/ccu_div.h +++ b/drivers/clk/sunxi-ng/ccu_div.h @@ -143,6 +143,26 @@ struct ccu_div { }, \ } =20 +#define SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(_struct, _name, \ + _parents, _table, \ + _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_div _struct =3D { \ + .enable =3D _gate, \ + .div =3D _SUNXI_CCU_DIV_FLAGS(_mshift, _mwidth, CLK_DIVIDER_ROUND_CLOSES= T), \ + .mux =3D _SUNXI_CCU_MUX_TABLE(_muxshift, _muxwidth, _table), \ + .common =3D { \ + .reg =3D _reg, \ + .hw.init =3D CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_div_ops, \ + _flags), \ + .features =3D CCU_FEATURE_CLOSEST_RATE, \ + }, \ + } + #define SUNXI_CCU_M_WITH_MUX_GATE(_struct, _name, _parents, _reg, \ _mshift, _mwidth, _muxshift, _muxwidth, \ _gate, _flags) \ @@ -152,6 +172,16 @@ struct ccu_div { _muxshift, _muxwidth, \ _gate, _flags) =20 +#define SUNXI_CCU_M_WITH_MUX_GATE_CLOSEST(_struct, _name, _parents, \ + _reg, _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(_struct, _name, \ + _parents, NULL, \ + _reg, _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) + #define SUNXI_CCU_M_WITH_MUX(_struct, _name, _parents, _reg, \ _mshift, _mwidth, _muxshift, _muxwidth, \ _flags) \ --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2ED1DC04A94 for ; Sun, 6 Aug 2023 13:08:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230004AbjHFNIP (ORCPT ); Sun, 6 Aug 2023 09:08:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230199AbjHFNIA (ORCPT ); Sun, 6 Aug 2023 09:08:00 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C0613E; Sun, 6 Aug 2023 06:07:45 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RJfrG08w3z9sNX; Sun, 6 Aug 2023 15:07:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327262; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EgnnlUl7wAsOZuNby/ZOzIkp3rYwogNkugsRmSM4dN4=; b=Oamc0eUc+caJbT3llSZ/q6b+lWvtssblgMESdXbBqF+aDwaRcE43PwpdliTubte0OM/mpr RbaqPgMmpDMyPoXcQ5Wh7gJ5BsS3qwMvj/dA1R0qAbYR1rgWGmp6Vfxk/bjO3z48xmZf6l kgeRq3u3cQKCVV5g/70bM5FGSQjwo+rngM+GrdcYRdOsBgK3TcAeDvOfbqZnYJMaEtJsAD e8paPNb/t5u5u6F9Y4RbgkV7BGC1uc4YyhzF41tthWjS+rzHeRPwqLrrHcUxT7Xxmz8GkF 8ELsGNroP1p0nfHmvkCfHofrd7O3O8wtyMSH8KK5Cv0b7M18KPkHPhcLPicong== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:55 +0200 Subject: [PATCH v5 10/11] clk: sunxi-ng: a64: select closest rate for pll-video0 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-10-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=4345; i=frank@oltmanns.dev; h=from:subject:message-id; bh=Gs6RR7GAGvt8jNifuVDTyJFgyhezVvB3N0uotsIXiYE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sI2W3KVoFsEpyhNZufEpHKsMDFj2N3dECmG IZH7swpYoSJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bCAAKCRCaaaIIlErT x/GkC/0Uvn309wWj85qTwxXJHBkGmcPgf4dl2G/5cczIUB2bwI5DSBy5ia2SgsqNAn0S+ShjyJJ agTwcjYGOBXe0CHhf21Td5DISs+c/5VlVCEOTFJsMe50dv4Xt5QWh8o5vPvKwgtPNZD7gQuzi4o c7oKYEH+0RoMrE+7L1pjvoFdkhj2pdf2Z5b4fgqxa1zENKCWNb26PFtKVKBKGgIgRyKdcNiJkYe xJnwVFTXAEx8QhNdddzhy/Mg6UMXwqWsVOfk7egYsnfwcS0BLEWkimt8yJl7Ebh+aq1XasrNyr9 B5Sse+Pk36DYsNT8T/KQhnwLYt7jvvIM6SCYFTZfabhuHz1WuKgpeKx1iXPURDfYzoNL+IvPrdm yHc8mjvTyBV4auuuWeI0PMAv/HyaLtopaKbRqMbRbN8vc5JO01HmtmJcWm2qaQHqa73I2avoir4 F7IkVC76qStDcgYlHPMBMItgai5GVsNBAyWJvwDv9zEgTYo9ixoUZ4zaBmH6xBPE/y9KU= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Selecting the closest rate for pll-video0 instead of the closest rate that is less than the requested rate has no downside for this clock, while allowing for selecting a more suitable rate, e.g. for the connected panels. Furthermore, the algorithm that sets an NKM clock's parent benefits from the closest rate. Without it, the NKM clock's rate might drift away from the requested rate in the multiple successive calls to ccu_nkm_determine_rate that the clk framework performs when setting a clock rate. Therefore, configure pll-video0 and, in consequence, all of its descendents to select the closest rate. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 33 ++++++++++++++-----------------= -- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/c= cu-sun50i-a64.c index a139a5c438d4..73c84d20f3ee 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -68,7 +68,7 @@ static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk= , "pll-audio-base", BIT(28), /* lock */ CLK_SET_RATE_UNGATE); =20 -static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video= 0", +static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "p= ll-video0", "osc24M", 0x010, 192000000, /* Minimum rate */ 1008000000, /* Maximum rate */ @@ -181,6 +181,7 @@ static struct ccu_nkm pll_mipi_clk =3D { .hw.init =3D CLK_HW_INIT("pll-mipi", "pll-video0", &ccu_nkm_ops, CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT), + .features =3D CCU_FEATURE_CLOSEST_RATE, }, }; =20 @@ -531,24 +532,18 @@ static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_par= ents, =20 static const char * const tcon0_parents[] =3D { "pll-mipi", "pll-video0-2x= " }; static const u8 tcon0_table[] =3D { 0, 2, }; -static SUNXI_CCU_MUX_TABLE_WITH_GATE(tcon0_clk, "tcon0", tcon0_parents, +static SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(tcon0_clk, "tcon0", tcon0_par= ents, tcon0_table, 0x118, 24, 3, BIT(31), CLK_SET_RATE_PARENT); =20 static const char * const tcon1_parents[] =3D { "pll-video0", "pll-video1"= }; static const u8 tcon1_table[] =3D { 0, 2, }; -static struct ccu_div tcon1_clk =3D { - .enable =3D BIT(31), - .div =3D _SUNXI_CCU_DIV(0, 4), - .mux =3D _SUNXI_CCU_MUX_TABLE(24, 2, tcon1_table), - .common =3D { - .reg =3D 0x11c, - .hw.init =3D CLK_HW_INIT_PARENTS("tcon1", - tcon1_parents, - &ccu_div_ops, - CLK_SET_RATE_PARENT), - }, -}; +static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(tcon1_clk, "tcon1", tcon1_p= arents, + tcon1_table, 0x11c, + 0, 4, /* M */ + 24, 2, /* mux */ + BIT(31), /* gate */ + CLK_SET_RATE_PARENT); =20 static const char * const deinterlace_parents[] =3D { "pll-periph0", "pll-= periph1" }; static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterla= ce_parents, @@ -578,8 +573,8 @@ static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x144, BIT(31), 0); =20 static const char * const hdmi_parents[] =3D { "pll-video0", "pll-video1" = }; -static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents, - 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT); +static SUNXI_CCU_M_WITH_MUX_GATE_CLOSEST(hdmi_clk, "hdmi", hdmi_parents, + 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT); =20 static SUNXI_CCU_GATE(hdmi_ddc_clk, "hdmi-ddc", "osc24M", 0x154, BIT(31), 0); @@ -591,9 +586,9 @@ static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus= _parents, =20 static const char * const dsi_dphy_parents[] =3D { "pll-video0", "pll-peri= ph0" }; static const u8 dsi_dphy_table[] =3D { 0, 2, }; -static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_dphy_clk, "dsi-dphy", - dsi_dphy_parents, dsi_dphy_table, - 0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT); +static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(dsi_dphy_clk, "dsi-dphy", + dsi_dphy_parents, dsi_dphy_table, + 0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT); =20 static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu", 0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT); --=20 2.41.0 From nobody Thu Sep 11 17:08:10 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F9F8C04A94 for ; Sun, 6 Aug 2023 13:08:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230273AbjHFNIW (ORCPT ); Sun, 6 Aug 2023 09:08:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230035AbjHFNIM (ORCPT ); Sun, 6 Aug 2023 09:08:12 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF4D1B5; Sun, 6 Aug 2023 06:07:47 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4RJfrH3Y00z9sTx; Sun, 6 Aug 2023 15:07:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691327263; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yRoPYzAKTnTbgFFEG+eJ+hkJL/BPQBe79b1oVFxR0W8=; b=QUA4bR2SmJicg6oPqu7yncuFitFk0JVnNHMBYjSA5nbjoKR7ztUOV0cV9xXnJuzMireE69 ei3m8kvqNugiGqs5u9Iakuyp9+H6KE7Fi+ZiuPQ8dkhHmMXlTWVb3XZ/QVIj7F3cAtWQcP NY84/08Lay3Eks5ue6PvTzYWv7K0GYQHfVtLRkf35kcsrDB/Z+bkBZ2IHcihmo0ueaGSS9 +NOiiSZOc6/S9ixY1ofb45GJ/cLWDyH0vxzmF/MtQ0GKBGHt+Raq+l+3qTde/exHDGTbdd g6gFblhVtaLWjyYtrUwZWYiqqyQeKTOw+WdON75DoT1Ib8eRfoUAv6EFhNXuwA== From: Frank Oltmanns Date: Sun, 06 Aug 2023 15:06:56 +0200 Subject: [PATCH v5 11/11] clk: sunxi-ng: nkm: Prefer current parent rate MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230806-pll-mipi_set_rate_parent-v5-11-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=919; i=frank@oltmanns.dev; h=from:subject:message-id; bh=Z/IH5d/kFzjrhI6vdMr/b3JFwWV3Wz0iaYZ2ZX+Fbvo=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkz5sIPL+PUvFsAmdO56tAomWjb3FWkFagHuQca 4MIo8ZEvU6JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZM+bCAAKCRCaaaIIlErT x1CvC/9YsuJAfvcqyq17ZqNaRnt+r0NHAFSbCgN641KlVeFiKf6fgYVeMNFRLXK8C60AFWWoimY cXcg7iQAuMvhVHVRpZgt+qbdcQ5zmVgNvdp6+Nm2uoZEpiHHNkoDsZRklOB7K6FKEfsjeIkAAjc hoM8DuI1KiFSxkwJs1dhiFgPqzXxmphFbXRgg9X7JnzRW5oOIe8SJRCQSMqZMvhgiKXrnx/iCqA zkKoCvM0sqWWJceQMEVwD3+cC1Ah2y/HUZeZNl85bOdER+Yt99/DgRxVZL9JjXwaKym+QkkL+VQ rf7L+yhxzhjHGA+L7eIT695hC3y18ePMsX3MGz3O5H65L58ZKoDbQgorMPqO5excXIQovH+kRYn rdnPCE3ijB8JConJfFrlhh0/W6z40K0s36OoqOUWW+uu48nGsqPrcVQotKGgu4NdlyaV8TJt0Z1 Xz+tpHrX/GXoAns3GFAT8CIX5CV6AX33CB7TxPy6Hvu6O/VzorAWvFyFdBQ8EM6C5DMss= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Similar to ccu_mp, if the current parent rate allows getting the ideal rate, prefer to not change the parent clock's rate. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_nkm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index 896bb1ef8642..1e49444817cf 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -35,7 +35,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(st= ruct ccu_common *common =20 tmp_rate =3D tmp_parent * _n * _k / _m; =20 - if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || + (tmp_parent =3D=3D *parent && tmp_rate =3D=3D best_rate)) { best_rate =3D tmp_rate; best_parent_rate =3D tmp_parent; best_n =3D _n; --=20 2.41.0