From patchwork Mon Aug 7 12:43:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344123 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 E8EDEC001DF for ; Mon, 7 Aug 2023 12:44:40 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=x/eUDDv0b+BEJDAzw8aO4rXPK0yX/JcT2V1Z6P/iMsY=; b=aHAG6fz6YnifYC RbUXDNxwl1PMB6QHzZPKbqqOFCCKnFLWJ0AxvrAS8gMzvgCLGQ9zZffXrVPuL7mthRpV5eboE6Tg2 oHTiGQ/2f9ZGNtC29NzNpAuKsH1Vx00SA2pr0oZ9SyTsTFEoXDq9B4GlpJ0oTZ00jSVRT3/ghNIEa Ru5E2XuODaJXFBjj4PS/jcMl/mGhI12PMvfpF5nhbJUVi8LWUA2ckAvFVOCItH7yLAjX/7ks3CRcE EqM2gt0Rp6h9hqV0TMcCHfMNqF9tc6XDr8ZKnf1Nbz5RWptdGVLcjxcScgZWZwfAlcw02f/X5anKi rwOxneMaWBSEORNSVS5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzas-00HFlq-1b; Mon, 07 Aug 2023 12:44:18 +0000 Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzaj-00HFh4-26 for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:11 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGV62y8z9snG; Mon, 7 Aug 2023 14:44:02 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412242; 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=J7xunkH+eplPFJS6xmeOR6PfO5HXKdfmXSQre18tglE=; b=wksyKUBg7az1g+U5XnvWYd/eML/uU8VmHklspVcTEltUDIeq9HSnw7quA62rgsLdwt15dt DLN/PpVQwxW1xhIMjkMIS4onN2JHloIm23efIV+30CTSPZY9HJzl7E6udVdOAU5BkEcEGj FxKTO6H74F2f3hT5l3VRzuKFa8Sw4wCUfTyvzLgHxvMuDJDiVSdVHNO1QKqodY7k7J9WG7 m2FN4u7zH9hD0P0YPG1gt6tcx4wGRZe2QQJrUiFgMTFWBTmFYxl/zocoFDuxJkF05bvIBo s7UqIkgQjXJKRhqR/9ODtpeaneuexzkYwQ7pCA3/bz7xp7ipa2pQd40NGMuWOA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:34 +0200 Subject: [PATCH v6 01/11] clk: sunxi-ng: nkm: Use correct parameter name for parent HW MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-1-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=993; i=frank@oltmanns.dev; h=from:subject:message-id; bh=J6lNhQH93AkSfayEFm5nQRn8x5rZvQ+scqDM/7cL81I=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcJeltk/PivTlSiWRcBOFYm7PZOWIMRYMGjM RWzMMDnn26JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCQAKCRCaaaIIlErT x+VUC/47WWLIjW3u247is9gP9SM58/c6axgqxtcxPeRvU6HtetXfdf6vRMLsKUzAkEvqwnD4p8a oHqCeKZAG0m1Syd6sXkNnV6liB0ALRuc82DS7a4MP/5VkNTniHW9TyoD3beDkmQbc7/HIRToCge AP6m+y50vdArcvbYs0CeS7mjxQROtzSX0UhWivJtnEFn14MExhRD8abYLg6/CAxT6AqLxEGcShe ngmQKu5RWj87VuoYmK7QSZJeP9kTVkJ/s+H9cl5W65yZ7RDpRKPxTfWeU0/JiJIPFOdqzZQlYX5 WVC7cTUN7ATNCxSDdiWplPATSYTlTtm6cKWnqsRQRzCk/gCnBSmxgei1ZqEfz+25JO6lnYe5z18 kMe5vc1b0frBSgjTChttKcVc+4eZA0Zcgy57DNjDtyBBDSgGb1mIgN697L8zMhNLAvKuiPgk0JR 7+jymkS2o/CWeWeJvLyvNCFQpBFRq/ClWTo42eqgWkSH5LqMo2El29jstnLZlVkB+Tjco= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGV62y8z9snG X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054409_832586_71606CC0 X-CRM114-Status: GOOD ( 11.36 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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, } 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) From patchwork Mon Aug 7 12:43:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344121 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 1906BC001DF for ; Mon, 7 Aug 2023 12:44:37 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QPCdDcr0xMxQQQBbUfp1qiApqeilLzG+XHIvigY/cIc=; b=yQtEpQ+xtQYiz6 zHQU5/xMlCdaSC4MkzTvfNfOKOjO6F1vt4vAvcMjKFQHNWCeiCEqzem6kCTcOfaRK4I0nBh/qgaDD aM39btYyr60yFLvZMNPIsI4E0kRkkZSyimXYPkF0U2Jv46hLRtPXXtrLQrESAGdqFIKkYUS8qrlUS +J2gKUZinkeZLC7GMk1AGDcMpNDtw7zyzXwpPUSYPVqvyLCgyONDjvC81GkqJ93UhWkrUeEi2Qf6S rpfGCKHo40RTn5VdVIplQqPrD64sCEeJKuqKL3M9h3ZkYtRVCN+OgexCunj+kKJsnanOLBcqhbBIp o+28KNLzrZC6zGYicBFQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzal-00HFiV-2I; Mon, 07 Aug 2023 12:44:11 +0000 Received: from mout-p-101.mailbox.org ([80.241.56.151]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzai-00HFh9-1J for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:10 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGY36Knz9snc; Mon, 7 Aug 2023 14:44:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412245; 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=Y8ktluX8ISdNot5DVuNsCYEDtddUgFalgfYdbHRzW38=; b=v9QFVAcdrssP/cI8ELuc6Z9v/BvV7PtjZd6Ez6Xoe2FsJp1HgM5kqJ+BNOk9pawmzlkZfx xyz/nSkybAeOCu5kqRCsbNiO7imkOn5x0TnhYvWJEv7uuzLAsx4IJG2o3Rr9qRHMmcrKdx qfeXivqU5SiLf/ar2bdZkeFGxtoILavkp1N06z6eFAHJbvIl0LrcgECAW4umz4a+LRhqQQ JNfZKVxTWKs84n7jr3PppwO/nTRau6p7rjxUej9UL/nrX9rw+9Ybc4RJ1Q5SLXwgvODGsl leH83vQ4fupPbmCeDSLIDG7Pf+H6dNmBTGfZsXifmAXxbx1pBBga4CqncEKdeA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:35 +0200 Subject: [PATCH v6 02/11] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-2-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=2705; i=frank@oltmanns.dev; h=from:subject:message-id; bh=DhVDNfWw7/1aAXsxGZ2ImXUGfXIvkdSMT1LB/wIRtvw=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcKB1QCOVuSnP9f40U1kYo4xgG5KUuRdnVW5 mC6MFJDoRSJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT xxYtC/92g6+CgrTGASkH/Ott8VxrMH8bycREhYf/t2+xQMjCk5E5e00rCo1JGKBcXlvQZC3UNDF Ppu1Divft8lTU+QR+x4rs4ycACV4EQ2SiKLi4AJlGDLBSk276R8Z6hUyqG1h+51+oV1Bv5rRg3V MsLmLpePWNmAFuNtPNkzv44Mnjsja7mFRcFLb9l1PD79McUTmXbmretcnW+aEh9HYuuXGpf+yhV h4zWqNcuwQUNwYMdYCkSxZ7ZpEUfCYe1bXpVGVEwqcJf+Xh5Y/yx4070guw7W4KIf++comIoVdj qp8toYdJ2vF05VZGqq62A1TQvJzoIAYxtCrBD8ow6RbsY7CxdX2A2Y5XBxa2BK35Jrpn1ZdLGHm 2VfpeVuqghgdngI4kYk/1OCvU1+m9Cp4lumlgWYMPqwcVchCcj1eAmUNS8WjWnxPj+ikHVK8lYf e54ZbpL8ulSGHiHtgAZMVHAZ+oFukEWp9lycZoyzkryjnDWNUK9/8WOPOkTDTSoCQMUIY= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGY36Knz9snc X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054408_647255_919E1CA4 X-CRM114-Status: GOOD ( 14.83 ) 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 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 Reviewed-by: Chen-Yu Tsai --- drivers/clk/sunxi-ng/ccu_nkm.c | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index f267142e58b3..2f60f3c33e30 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -16,6 +16,45 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; +static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw, + unsigned long *parent, unsigned long rate, + struct _ccu_nkm *nkm) +{ + unsigned long best_rate = 0, best_parent_rate = *parent, tmp_parent = *parent; + unsigned long best_n = 0, best_k = 0, best_m = 0; + unsigned long _n, _k, _m; + + for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { + for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { + for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { + unsigned long tmp_rate; + + tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); + + tmp_rate = tmp_parent * _n * _k / _m; + if (tmp_rate > rate) + continue; + + if ((rate - tmp_rate) < (rate - best_rate)) { + best_rate = tmp_rate; + best_parent_rate = tmp_parent; + best_n = _n; + best_k = _k; + best_m = _m; + } + } + } + } + + nkm->n = best_n; + nkm->k = best_k; + nkm->m = best_m; + + *parent = 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 +163,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate *= nkm->fixed_post_div; - rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) + rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + else + rate = ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate, &_nkm); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; From patchwork Mon Aug 7 12:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344124 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 192E2C04A6A for ; Mon, 7 Aug 2023 12:44:43 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+TGOJBSAqYRypFjB/+jY/GMLAUhDRGOcq9CAX+5w7+E=; b=TR2YnIpjK81dLK sZgjbEbAy1TgygZwtx0X9jBtvL7/pJnfbY8pya9FNkxuS/PsKXTDwD/oQYnWUAEbb0I3KgLW3wSJq V5bUvn07UPUpgVFYBXKfns/kReVoLt+73lITwCJd3qhaFReSjV9Ch8Cz19KCD/rGuAkSsazzb+vsE CfaMdAetunQfFkJvxnE2jIcblNcREbZLTfhq37rRCefS2pGWqi2ZSBINKgAfg9v8zi003BPY2lptW 9pVnv4HRjEsPbdSj5kv/+JSFY0mB4eUqQfbBwsyvRlIn3cwINe7J4hO8gEP9fUUESfN3xi9E1e4mJ ewOsOoyce5eK8Yo+B1HA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzas-00HFmE-37; Mon, 07 Aug 2023 12:44:18 +0000 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzan-00HFhm-0O for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:14 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4RKGGb2b9kz9sls; Mon, 7 Aug 2023 14:44:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412247; 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=xI2XtQy9/8BiyYedLMS7iqa0KU9c36EUPArQdRGOxBQ=; b=JPaOJk3E74uICdzWH7geM/TOdGTORdg12KZXne32kB5hQ5Eaq8jmqtC0s8Gxy8LqwNbiJj uQN8RaVKsFjhHlT9kVYCr+nmnnNzMMae9wNvEWyhbVg4OzXTFynoJCCh2HT0W1goaF7fjx GGbbmA8tSuCHz2/BcC7A2Do2uQJybT/xvMrza+5jbxYZ+fTJhxkoI4burqpadXiT7Umghq vLVGrgOmHUn0aVwbPQil57J+CrVYCKX1cjNDjNYG/iq0CXxaN799K2K1xNvAgLcuGBbpaD YpKz/zcgLMBYG9xzxMHDNXDSiUfvi7YGL3NrB6a4PFpE6ijt33Jx/yS55+skBQ== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:36 +0200 Subject: [PATCH v6 03/11] clk: sunxi-ng: a64: allow pll-mipi to set parent's rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-3-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=908; i=frank@oltmanns.dev; h=from:subject:message-id; bh=Lc6iH3J9lp5ZKkHkcprA7ejcVK33NT1XKW3ZK3AQRuk=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcKIr3rPts+hD8qdYeRNcF3WRTLwZuXLt2NP DF8xXpxA+OJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT x+tUDACOB7FWM73UvXVMgv8OeS0ZdBA1ZDO4RjI83we3tZwKMMzerbVQtuMM75inhl738Tcydqo 0j1nVF0NO1Fryc8WSJS3qjKyAKBx+JzcslVc4NZuEYB4BNX5erpU9/RIoDEA7mf6GqpAt10KzEm rwuMfPXhxeCXA7Q8oyZUWg6LFxG2Wd42RFWADvglYRmUIbuE+795I9CMcyJH4O1gJpnf71HM3ua vxD7Gkuf5TnUWljt/VcWbIfwTP5hU1X+49SN4hJfxZ7+VJMPQfyE2tWiLMqcUQX6OTjZsdII2C7 T1C1L03yAPaYmd8kcHaFwTE8UqEX4YS6QqtAVCeH6iVmJcV37jaU3J+JERTOJmOMxMznqPSMhD4 oZYC3doPebidFJ66o+ERQhoPeCB97EO4akFxt70cZJzlMYPt7cUTxYdOwQXBOZPbcL2xYtEj3MD XrlatJykUOi/f/QH02GEyVme5CX/z9JGKEMjmEmuRc72EZMeX5ambV6pT711vHgsXLPmI= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054413_308096_D137AEDE X-CRM114-Status: UNSURE ( 9.47 ) X-CRM114-Notice: Please train this message. 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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/ccu-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 = { .common = { .reg = 0x040, .hw.init = 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), }, }; From patchwork Mon Aug 7 12:43:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344126 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 B5EF2C001DF for ; Mon, 7 Aug 2023 12:44:43 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kxb3j8Uq9jAD+WSZ7j7pJomC6y4qGH0ZducqBhaPzdM=; b=QuOVxdhhqLNgkt sUULDz1z8GrZQ+XF6MoaUvOEwBHoh80Wgo9XEW76RPma5GCXBr59LDKxchxno4Ve5ZFwtw04Ylq2D JHbGyJiO0xnl+JX/jaTpTUUXASVl41aI9VjuQYbBS3I1QXccCfAc0zgGilsVddLG7RKUVXjZBFT31 wvpDQ9LXwFodY8KrIgOBGoRzPImEDu5wUTLnTYdx3D6gUr9rrPRK7ZDPHe5fGR8zDpnLySO6AiTNt r8aPJ+nj6zFpRRDY5KOR0jE+zXaLkHGpaVOEisSin4xEi4Ae5WvktLTozeKsuG7MF8+ES5c8N4kQr 0B06Sfckne1dSwj3Av3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzau-00HFnU-0G; Mon, 07 Aug 2023 12:44:20 +0000 Received: from mout-p-201.mailbox.org ([2001:67c:2050:0:465::201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzao-00HFiT-3D for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:16 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4RKGGd3KWYz9sRH; Mon, 7 Aug 2023 14:44:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412249; 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=SpKQU05wR+7Zs/sksGtxQdVy5+eUWQjc5g03Nzug4Xk=; b=YSzCGQ4Syz7bR8eF3HMeo7fnHKJqIXHblM1V0ex+odQM0ldLRERyL0GToUrZPgUhQEaET1 d1y9ac2Th+j9oafzR8g17440CeO6j6MDw9+2RcSY+XDO+9LtNGjo3Ieu78bhpc+8KIELs9 PTAtBvWf0WzLrEdAJCVeRpVT1O3IQbchvHWGcPxs836PZ3fdF2M1VavWz4KkTS/FyZKdfL o6nCa+z3smSb9oMWZFVjG1duesNeB16t1S/TDRCgHT5G+gaCwRtDp0aevvTEkCcRp8QzEg 6dpBDQ+yphhyppEABFYblL8G8fLUzpDpLJjbprpXqc/gq4R1K6l+GDEWmDBQTg== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:37 +0200 Subject: [PATCH v6 04/11] clk: sunxi-ng: Add feature to find closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-4-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=978; i=frank@oltmanns.dev; h=from:subject:message-id; bh=3x31nxdweRqT+uRnszwgErzuZSGTLRFbE2HuT6iJDYM=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcKptx+VTRV8LM09n7IP+MlgokpAXqh7GyWV 5NLMCG+I3+JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT x+Q8C/0QUESt8er0xSXZGFj4gSeR1/gStfxEEXlYQGN6XDpSOeG/O8gAyTweu7NP+voR/gfaa/S 3Ip4qKq2GDZV99P7TjqA9CUtrMFeFtDZnyNEsxkqy8rISoO3s6iprYVI9G2jzbs1ddErXO/4me3 SvCA3gzUjz5QYotvaayiDk0zRGg4dmOUUr0Co+uUzSzPgH5lp10nfrlyQQbf0Z6N2ujq+sBukqo dH1Jp9iHh4jMAyHLc441fK7/mYQDONILylxZIU11FsZr7iQobrO/H9WwDx8zSCVV2Jwp+lEONgi EeD9SiF3VRhj9XWgVFcKaK/A/zaHgmcnMag2WTOqBSlDAuIDBcBVdHZ88w6krU+nzOClJzVM/s0 6JuDghuKA20IJUizfim/ibV+OCAEDmSgqQ6neCqaM0zh7RKT9HMjV9eG5AggDva0w4/YDnDQFUx cXGojKJ187asYObueRA+LEQcwr1BjkHF7IxpumWxGqttAA7L8icuF4f3c1q6EsW1a3leo= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054415_173185_E9195BBF X-CRM114-Status: UNSURE ( 9.39 ) X-CRM114-Notice: Please train this message. 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 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 Acked-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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_common.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) /* MMC timing mode switch bit */ #define CCU_MMC_NEW_TIMING_MODE BIT(30) From patchwork Mon Aug 7 12:43:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344125 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 46ED6C001B0 for ; Mon, 7 Aug 2023 12:44:43 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=f+U1EUANYDIBplhvABYFc0wy/aS1AFmbfzoASkZoDLg=; b=QPUQ8BUqEJ7L8n HS48TXIKuBnlBh0b2U5N8PqLd1k9RetlKopp54rc+ghhzjkds0PXVgbwWwv+FOwa3QlRqoB5fOpv5 FryuVLWM3IEIXZ92928pHvRHITsJyk4RxacVFQJgeOolNW5qdIp7W3YGBP744PHggWKhf/ecO234S IYWQyZZz3vqNGpPsQSOP8Os4cSDHPBV4hxDdko6TQaqTe7xgT+0eVVT3mGZL/g53s0zw246lYr9N0 gdq+P4Ve+w5HvX+IsnKs+6koS56suy6AZTsjt5gF32jQC0/dzsfpbNM96EbmK56JFvXHQb+7sR8HL qwoOzb16XTJRx6dv8uyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzat-00HFmb-1U; Mon, 07 Aug 2023 12:44:19 +0000 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzao-00HFjb-0i for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:15 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGg2jgtz9sbF; Mon, 7 Aug 2023 14:44:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412251; 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=7S6C5RiSumrJfz42U1M/i1EZIbkB/8kA+J3OWBudPh0=; b=mxX90osoghfcoNAkh7pt+Q3K/V5cbYvVVLIGr/gPOalFU5UlXbbSVazySe0pVlKhrtVpLB XDSoLhFTVctlrfLfFtzvbuj7lXhuXyZbIlwaLN9NDlcDBQFAVXV6QdnrDG5fUzYW5WZe08 xhwZXIZlD4asy+Sz1c1O/YFTyufY5vkGhHY8ryRFYQrG2qoLtCAZgYr0ZFZZFTeQmnx5fa 2PCtdO2gg1UB4qAt7MTFFOUcBs3f0W8Vi40Q+n3jOTL8y1Xdp/KXL3RlRIEuknuNLKKb3z f8oMiA4ukYn+6iTos7KcsYbpOkVZaanBCRYJMzfpFazI8dgEsin+yiq22eiKTA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:38 +0200 Subject: [PATCH v6 05/11] clk: sunxi-ng: Add helper function to find closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-5-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=2110; i=frank@oltmanns.dev; h=from:subject:message-id; bh=GNz6YFitptd/iU8xYw3UneQLsMtDUEwC7Tg8y73qcgg=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcKJH/KZtB8NiUE9YPrjmIq0Yfi4KAlgUVWK vYSXi6ILbyJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT x+czDACS1qQUFTkA+fXSqlWeYYcYXJMNNT+MBRXjQX4wyMvsNUoPl94gTdVpG085tWfFhY2uWY/ 92iw9E++jfBc5ru8JUJ8iG5AKEUB9YMMpebC+R4YFYuIaowcTPficLov3ysOwJ75qeGJMIhemIp ZpoCvzVV2RtLsljO0yxdYRcacOQOALMkfh+k1fQ3Wwf5bx6hcwZd8Wc1ON9ggNmjTxaj9oXthXG pLF3awM7aiC/fcxsMDDM9VOwflw2mIJG7ZzYq352t9KGKQGCyxJB0pnxot5Ul1mXnUTT6Gpm6Le TZNdTYtcVYFOT+9j1L8ACGa0vU23/CcKyoNKSnT7iJXLbRqMnv0/wOWzOjohrit2eJoxxes88vo A/c39ja4ItA+VQMFGddj+G7Nc6jnqpug9fsx0nj7vmasd5mqaij6e06jkFkH5LFphq0PG3zlChR jORG2gX8aoYc/6BwWdy3O3uigqLj7sqTCoAMp75uPLCZC4YPClf+6OJAJmFEMeOpqIc88= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGg2jgtz9sbF X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054414_402910_585502C2 X-CRM114-Status: GOOD ( 11.88 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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_common.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); +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 <= 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_common.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 { void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock); +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; From patchwork Mon Aug 7 12:43:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344130 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 EEC13C001DF for ; Mon, 7 Aug 2023 12:44:54 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=3vMtWnursk8kIbTdJ9rhFmAQVvhU4v7j5llmhU1dowo=; b=nF0Q3s9slV+ypk NWU0vj6NPBpsp0QDCcKKEPtx63iJtUJkqPljYefhMIaw5G/5+PwnGYNkZ2mrBn1Q8TGoTmHl/ZCv+ JAhVs/wiowngoXYHMvDJY4pJVMeS2tZLyrtXo6proGWwt0WCfnGGGjx2IhDID0WlLiiEvtku+PMeB 4DwqnX66y4tcFooyRfncm78rycmZSMfrwTMD/Qsy9GxRWQMaYZhFiGQkZx0x1fe3msYr6018HlquF UQpVjP523W8Te23o7tDNhcCnjM8goqp20q/BMMANldkKqNc1cvEey3xBF4eh7H0xZOTANEoiQQ8kQ Ur5F1KN59Hk5jppywxBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb2-00HFsY-1l; Mon, 07 Aug 2023 12:44:28 +0000 Received: from mout-p-201.mailbox.org ([80.241.56.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzat-00HFkW-1o for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:21 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGj2PVHz9sTb; Mon, 7 Aug 2023 14:44:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412253; 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=Q1hrv579TMrIns6VyI7h5LRNKnE8k+K9y8V4QVTxqKo=; b=EScqRDa/FX+iNy8efPa9LHX3iigi4m364VD1X0rIilV93JpjogCeIx7aH+zY/8fsgyCBpv tb+PcuLqzoCC4nQrnrFYAq7wIDoyHJ3Wf1B8v4Ma/vsw1lXqZiog2YHv73ixhaHJSrtHzJ 0j6pe5HYI4iMMHTfoNMe6/13VhQRbEhSk2SlD59NiwdNPERGnjPc2c4xyT0wwlRXOplxRt MmTO7JcnbnYDWF90GDnIIVpAXpDixraTekzX2fWiNSHAqAARUS31RHI0/S28b7S7z72gcs Yof4PwyMDbaBbL8N1GUvRb8NohpGqwHGMN4IVpgeFaVrlbsvbivLngD5zpmzdw== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:39 +0200 Subject: [PATCH v6 06/11] clk: sunxi-ng: nm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-6-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=5291; i=frank@oltmanns.dev; h=from:subject:message-id; bh=D2rwnNX+V6lMP/8Ad0tO2HsymDVBSU9g3vAxu119xBA=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcK0Gida+NqPbhInVZHi/8DtHjaHWKRjosYW 1J+4Jp0rTCJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT x5v0C/9yRgGhhlo8G1bh38YgqDkf5uYLV9VbwaH/8t8jc0XtpYNtQUmrHuHbdhHYdLukRlbsceL bsAq7jsANE9Lqkgl+b/ROoOcphJXxUNDt4dZlQUbC5D1t76FTZEIB//+gq2zjyrgg9Aiv7WZpRG ScD3pcUAcATZZhPOvB5sHdUnCZ7GuAzTLaInGoO/rM+qXQllQ5oEh28TXFctZwaYupVEc6llP/U 1boZmoBQwEHa3HQg3ZUbGpdgheyNc8z8Yl1Qr/NUcdBk0ppTUbPDogRSa2F3pY/3OKgkLyIfCUz 4c2GLfE6VBMbnSrQWv6GGnex3W+6uFSw4tNTlQ2/PyrFNV0tw0D4+G0nGSODwDUFxsKa3oTO806 oxz5xo4O+WRMov0fcpL9YxLb5nL5YTdqxZWj4t2RxaEhG99zdyDcRhEDSsHncA5fZx2zrS2w2By t0or084GLw0YvtxDd7e+6B8V/V/6GIKXLzBtJOT+HJlVyQAo7d2tD1JNRvmMiGyKezTG8= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGj2PVHz9sTb X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054419_892186_ED2714F6 X-CRM114-Status: GOOD ( 13.79 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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 parent, return rate; } -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 = 0; unsigned long best_n = 0, best_m = 0; @@ -39,10 +39,7 @@ static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate, unsigned long tmp_rate = ccu_nm_calc_rate(parent, _n, _m); - 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 = tmp_rate; best_n = _n; best_m = _m; @@ -159,7 +156,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsigned long rate, _nm.min_m = 1; _nm.max_m = nm->m.max ?: 1 << nm->m.width; - rate = ccu_nm_find_best(*parent_rate, rate, &_nm); + rate = ccu_nm_find_best(&nm->common, *parent_rate, rate, &_nm); if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= 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); } 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 { }, \ } -#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 = { \ .enable = _gate, \ .lock = _lock, \ @@ -129,7 +130,7 @@ struct ccu_nm { .max_rate = _max_rate, \ .common = { \ .reg = _reg, \ - .features = CCU_FEATURE_FRACTIONAL, \ + .features = _features, \ .hw.init = CLK_HW_INIT(_name, \ _parent, \ &ccu_nm_ops, \ @@ -137,6 +138,47 @@ struct ccu_nm { }, \ } +#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, \ From patchwork Mon Aug 7 12:43:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344132 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 A3799C001B0 for ; Mon, 7 Aug 2023 12:44:55 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ytjzhsTjSUAjpooQhMDJ442DTk1x+0TLBSalTrvUDho=; b=Hc7tJItGwIOt8s j4fjQd0UeWagcpm+vzskQn485+FTX7GhP4WpjPr1zDZ/K2wDjWFwV+2RZr+AAIi89JPWg8hssywcd zJO26rVLR4y8YL0c58mC72CLkSJ13FcqTyeXcsWh0HUupLL3M9NmJW+Zwf1E7b9K9sEt6PtiOR3wu Y2YzOTg+TYunbkgg90u8WAUNLTIGSEDr2v//LHDDuq9DFPC1uPpio++STWpHW9e1KLO0a5ZfUjAXN 1bQ0ik2CXyMft8eykHTj1WOA5sVpS07LQbPCmPq/eMOpTxAlWPDSEg6gmWdWjihTrwYhbZaLipHha 19oSfpd2rr+g62pi/TUA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb3-00HFt5-0U; Mon, 07 Aug 2023 12:44:29 +0000 Received: from mout-p-102.mailbox.org ([2001:67c:2050:0:465::102]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzau-00HFlH-23 for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:22 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4RKGGl17cVz9smd; Mon, 7 Aug 2023 14:44:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412255; 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=K5tQ98OlbFoBALCdfAJcGFpmCSr1McUfseOzgGp0PTY=; b=ccCHRN6NY3DW1K48ImhsJu9yD4i0iw5UynxoEb4uGbitKIkzMhxmFNiFYaGsRS1kBZ0TDM Qq84MFPBYAq3B4RdqYBvXk+8uMv4bGRhBtwWQT33B0aqnCEzoycue64+NrlOD0ot+xG75e teZxokiHfCvL4BR7rOGaRvsdi6NqnuD3rGrEK0Rd3erLRO2oHi3gliEQVznArO4y1ESjnA 8JwxaqNu/R2YzPXq4Yd3t508ZMk6UkEpDBTPfRYJTPTLnlNyFxAjGKIRLcfaPViL5dvqUP FRVhqMrWGXhceOAFhNqDolU0YjPYeCVB1m206oUz/Rrls3TXMjn86b1IO0TqZA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:40 +0200 Subject: [PATCH v6 07/11] clk: sunxi-ng: nkm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-7-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=3842; i=frank@oltmanns.dev; h=from:subject:message-id; bh=MhP71vaxDH8c5zg0TT+00Y3yrnB4gc5lIl4iI9sXSDE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcKJJBxSyYB7ebgHRDX5I5tMU1E8xNdRViiN vlu0LhdnnWJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCgAKCRCaaaIIlErT xzlZC/96ZiL2HTDvGuJrlUqavcGvc2d4pjQIpvTIsN11xzr0Ecjt0bYRIuyCpEcwFHZgQoVBlSu M1X/OcyGV2UAY05JteHix0yFbcQG2D+ceWrzqsn0MEsDgLWyi7Gd9bz6Jn3rrnYQPFvhAOmWy5W C4E2PQ3qX8d/nnZxkGOcbqeoq0D5MwGq0sI9CDaD9P03GCrLj+BTvAcAH3L3hpzlHzV5qsiWsYC 2gpAirT6a8wxAABvkxWbIt4Onjm6qkhdIPBfvUKieZlP7RB1iGXZeu3+7CYoX27yBHbBTKeK9HQ CElaKhgW5AeZJjU56aemimv3r0ZBFI9oleMY9mMLapD4rEPMZSKHfCZhR2/YCehKh+xR3IV5MSA WUfB5nQG20yL0oLBQj4ikmG0qQ+GYsqs3ANqdx2SI3u1zVjMOSXvPFBh7GnSrW8pkHE4DDjPYK1 NZY0Z80wWSky3SQ6bqlEvIXtdPzGBGIDFUCddKmgqC+jami7QdQlSLFfhLw9UqDNyKOhc= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054420_822425_7EB9B043 X-CRM114-Status: GOOD ( 12.59 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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 *common, goto out; } - if ((req->rate - tmp_rate) < (req->rate - best_rate)) { + if (ccu_is_better_rate(common, req->rate, tmp_rate, best_rate)) { best_rate = tmp_rate; best_parent_rate = parent_rate; best_parent = parent; diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index 2f60f3c33e30..a714dcf0dfc1 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -16,7 +16,8 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; -static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_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) { @@ -32,10 +33,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw, tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); tmp_rate = tmp_parent * _n * _k / _m; - 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 = tmp_rate; best_parent_rate = tmp_parent; best_n = _n; @@ -56,7 +55,7 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw, } 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 = 0; unsigned long best_n = 0, best_k = 0, best_m = 0; @@ -69,9 +68,7 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, tmp_rate = parent * _n * _k / _m; - 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 = tmp_rate; best_n = _n; best_k = _k; @@ -164,9 +161,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, rate *= nkm->fixed_post_div; if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) - rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common); else - rate = ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate, &_nkm); + rate = ccu_nkm_find_best_with_parent_adj(&nkm->common, parent_hw, parent_rate, rate, + &_nkm); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; @@ -201,7 +199,7 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned long rate, _nkm.min_m = 1; _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; - ccu_nkm_find_best(parent_rate, rate, &_nkm); + ccu_nkm_find_best(parent_rate, rate, &_nkm, &nkm->common); spin_lock_irqsave(nkm->common.lock, flags); From patchwork Mon Aug 7 12:43:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344127 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 E3649C001B0 for ; Mon, 7 Aug 2023 12:44:52 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+aMco3ILjOGzG4e1lxTAQCbaLDG/Ka3B0u+hlKxkSkM=; b=Tqv+5Zic4MzTsm bOxRDrCz7xKVBq5+WH3ET3WCzxWrj8tXClbOdsFS4/Lrjt6ea2n3J8qezige4IbH3j4hcOBUE04kd Ae600cpKfU1KrHPZNZ3aQnu+1OJc8qZ4aYNBcFvXjlw6C27JUUxpuTOPY4KqbCFl7GXQ4Si0OiPQ8 04DGH3W+Xayaetfkiw7Z5msN6vxdHRU222L1gw/MLWt7TLrkjW3Vx7hGUjCxTdf2PCoplrKEvQTSp ZQH/r2vi1x/AnPirf2+Es/RuWupY0SE+qe1oudhz0IkMivYRfvMRw9ehUEPOqH4CflAgVldkVGnuM H2bPOT6hS4NCdqAeERmQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb1-00HFs7-34; Mon, 07 Aug 2023 12:44:27 +0000 Received: from mout-p-201.mailbox.org ([80.241.56.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzat-00HFm8-27 for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:21 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4RKGGm5dS2z9sWQ; Mon, 7 Aug 2023 14:44:16 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412256; 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=v0+pPKgWXMRtQfEcq7Lwac7P0rHRUc81juXc47wwEhw=; b=2GYm8z6Uftu4xkYbu0pLp9ZvmPh2ymuBckFacYhOXdpNfxZTrVcTYgi8SUolK/mMkxMfgZ 6U8KiKUUvoDLDJlXkVHSsA0uUFgJVRzGWnfVCwAtQ5ScoeJJEGgnYNlfhTs7W5eRnO7EOM qAXMFlbDMweivfZ4c86KlyVwnmARAmXgYLoWNMSqpcRo9AABrmBv3EMMvcceVEE2DDi4p8 T7YWkDFJZ0c6aR8Kx+28vYC2OawGRiq8lsSTg3CwYFhUIR6Rr0rvXrDBeFB7hPEqQ94t0R BKtv0sAhGu9lSaSBRhzFvafS8n1mGWwQTxgpbduF+z0QmdppUB18AQ/IZ8C6BA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:41 +0200 Subject: [PATCH v6 08/11] clk: sunxi-ng: mux: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-8-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=3496; i=frank@oltmanns.dev; h=from:subject:message-id; bh=89fqPS+TY+dHyrz3Q+lbonRwaAXXziauHi+C8rJELvg=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcLb4CblL6ckG0P5i4esDuUHY+FbF3NAFjZy JTCGN7PWFyJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCwAKCRCaaaIIlErT x2oyC/4isk1uDQVoFJy3vdcYBc2xIE9Dcm12BWDGx5QVDGMu3aa7IKQ6ESBpJytPtqDTuQ1T2uy nqBzXUbo3+UK0SNrR8xx/6jPzYtf7Zemgp4Nd10nD0dxDsw3oeb4P2Xbv4Lm9Mus7AWgBlHULeh 26KEJQpzoEw9G7YE9mpAR6M6Kg4vWGOlGDs0ON7yN0zpxiZsXwrvOrsMtUjVaSP0qljm4lwhKVW OHB9D5nU9D2ZLg9EZbBVtKosIzD7JYaocotBpddtyamD6AhcRgbAdS7NdznKlf/lA1rQzp+6vf4 onL1InUYOmSHOlAUWrtbbd3C/mNZwhzk/0qqZJclsUw1k5EG9L/Q2Qm4ZZ6BglzEL0EJvaLqRQz 7sJRiQQ+dspmyWEW+k4wyVYlttXoi5MK8Kfpi6IuV3TNL4pFAVAMyRxEaWl9XOIlZRfFjUaz7Zh YyPSI0WCOKyNJLmz7ryy3qqUoDslu8tXgCbVn8pSDbNWsehaGG4qzK/GFFVeHo3JpryJM= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054419_836251_00057ADB X-CRM114-Status: GOOD ( 12.56 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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 index) return ccu_mux_helper_set_parent(&cm->common, &cm->mux, index); } +static int ccu_mux_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct ccu_mux *cm = 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 = { .get_parent = ccu_mux_get_parent, .set_parent = ccu_mux_set_parent, - .determine_rate = __clk_mux_determine_rate, + .determine_rate = ccu_mux_determine_rate, .recalc_rate = 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; }; +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, _table, \ + _reg, _shift, _width, _gate, \ + _flags, _features) \ + struct ccu_mux _struct = { \ + .enable = _gate, \ + .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_mux_ops, \ + _flags), \ + .features = _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 = { \ - .enable = _gate, \ - .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ - .common = { \ - .reg = _reg, \ - .hw.init = 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) #define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \ _shift, _width, _gate, _flags) \ From patchwork Mon Aug 7 12:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344129 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 2B36FC04A94 for ; Mon, 7 Aug 2023 12:44:54 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/0OOSMptXVIPjwQz3OQaZHRukp3met5txm9ytGnM10s=; b=EJQPgmvgU1q40v YC0XU0WX1WwnxC3+ZmkIYuU08ohLpYM/Z4mV4SiFhML7Q+tZgzdLHZ9su9nNbP45L/hqiT0G1ruGC rH8QNJbu4+ZDIf4DHysiBB+i938w9F6Xe3hTpNcD11lvdtSe694AdIbtMJ3O2My/bJITbOZIP2KFP r3eZIataXEeh/pDbfzwCSUxS87DkOzJkik2fOhCqwHlOoCRfipnXgRmu1xWE6HCv4EaPJce/PGNt0 yirr395XKgpchYusQdULfq+WrC0SFCEXnN9/9igy1b5gWLwXfOQOTyR8cCoKgSvAPgVPSuyAeKhv4 oA3pCUJhqdgr37+cre1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb3-00HFtb-2E; Mon, 07 Aug 2023 12:44:29 +0000 Received: from mout-p-101.mailbox.org ([2001:67c:2050:0:465::101]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzav-00HFoY-30 for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:23 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [10.196.197.1]) (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 4RKGGq0HCKz9snG; Mon, 7 Aug 2023 14:44:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412259; 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=5lFYFCdN0sdgDJqab568y4FkGp83iqOD14+wLiTmK/k=; b=X+esrlXFZ/MEzzW7OH4/kL8xjhT4yVMKWsJ5rwQ2pis+OhbiLwOrAzmFdeCjIF4xBvzfq1 h5pEqnjdul3/J+w59+Ai4b4d60AXkZk9TD9b+hW/utWoHSTc/4a14hq1RNfcOzkXHCvChk FIASFa1vjfsMgnBmlOuMV6BpTxuMW4plr4gEnU28BrAuVbgW7guqj7jjso/sucAeH9zyie aFfV/ZI8g0tRq6Qbk3dsCRHkyil6Vtucf/GsRJAVBKdrPMUGeP3I/h0Dq6C2w+ypJCUI6C vnJB7BP6ZzJvzJgYaYSSxlkRwBkDv/h/YX+v3uBj5+S66cN5fr5ElGCVJiA2VA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:42 +0200 Subject: [PATCH v6 09/11] clk: sunxi-ng: div: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-9-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=2176; i=frank@oltmanns.dev; h=from:subject:message-id; bh=lF1bB9W1an2uvrdtnkgXzTklsJAiLLQesxIoCOqHDY4=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcLKCUZ4KFM13LA61e9BOpBla9sUzPL6WeP6 Hn7EqWG2ZiJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCwAKCRCaaaIIlErT x2z+C/9qavB0kYFaXXtRGKJopVSzHgKC9VKmG3SqdHxyG8n9a4h66qSaL47rv0CEngYPlJ6PVVs 8FxzFcBqT+1Xzy6/0ZMhCLo2ADnhUgsqVJX7FyR0iO6LeGzNB2chyZUzQP5dBlGozfSYu4bMiek 5ZkXSV8g7fOMDim28WQ8uOMVa4Pv8XQVqjm4sichhiSZpy4V2wBTFuBPAq5v1eGZohKn3GmuWAm VaN5fugkDoRbzrEOX/IpcV0NTk0O2XCUX4Q8NiCobERNlqRMLwqX8FgGy83AB1tu2Bumbj/adpz gFPPK/iSP3FEr4F7Kn32YzaSDD9BqtWXmcbvP8fYxLgMBM2RcBaTcXr4cVHSrTDLmbbJNIF4yy/ SGRAUOIMUxSQt5SVtfEcAYeKS83+a6/HCXFtTHsVu4ONnM23d+ssYfnA8XX+PbT325r695Tgdv2 fXuIqA0vfT8TaqbTafAcyDmzN8+XE1UtThaNmhy8Sc4zptakKYaFsE1lIH4Sq7GUmXXQY= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054422_110787_76271F48 X-CRM114-Status: UNSURE ( 9.30 ) X-CRM114-Notice: Please train this message. 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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 { }, \ } +#define SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(_struct, _name, \ + _parents, _table, \ + _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_div _struct = { \ + .enable = _gate, \ + .div = _SUNXI_CCU_DIV_FLAGS(_mshift, _mwidth, CLK_DIVIDER_ROUND_CLOSEST), \ + .mux = _SUNXI_CCU_MUX_TABLE(_muxshift, _muxwidth, _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_div_ops, \ + _flags), \ + .features = 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) +#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) \ From patchwork Mon Aug 7 12:43:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344131 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 4630BC04FE1 for ; Mon, 7 Aug 2023 12:44:56 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=NrZr23bKCCYWEewfyqB7zvmlTWoZFSNmgmifBckIpEs=; b=To9Iz9zxhkq7Ao 3MbCzPhb7EdDkPN0ttejih7EKD7lz9gOiG03tP6i7ns3twVix73qu45h0GdAJrUoHBEAO9gnWRLoO 0JUNDIeiWa2tSl+AHkAflqpeusGnYrBVMHlhg7GpzsvGkgwEuewFU5B1gIgKuRjCW9WrcGJcBoSCL JgTu5HYS0x+m4drNOFx82ZbcLBNuipb3OjRYD/wU7yVDeqGUDsdDo/jQIOWM1ec+9NImijLo+e1c3 9F6eG4trkC/tj1XaMc7x+IMfqzlu30Xs7hZCCQEHLnn6p6UKnVjmyQ1+/r5D5F/YD77x/k+kFFXNi AL1pBTHCA9B6dfNldoLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb5-00HFvH-0I; Mon, 07 Aug 2023 12:44:31 +0000 Received: from mout-p-102.mailbox.org ([80.241.56.152]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb0-00HFpp-2K for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:28 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGs2MTgz9smM; Mon, 7 Aug 2023 14:44:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412261; 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=cYk/WjPilwdLT52oKsxs9DmCkmmfG9/lP+c2FzWjlKk=; b=FHbighWE48Frl3XkbgJmVqHWexNbUvFGnUCoXE3lDZlDAjabq5/Hw0Tkh6gOQQpbD8LVb9 F1JW+vVdMkdr3oIgeXlIns8QGuRbpVH9pOTgPbRx+7Cu7eXZgHSxVgNaoSj2H5Dj9orzvH JNMTcuctKALQazCbFI6B6NgxBUnOHkFsHBcgIbCquueuxOGxQvw4ifPIs/GWTKY2hgvXKJ zNTE5BUE3bSzogTg4UZ52MtjovWK35baTfC6dnAIoJzavWR7SrX6+avfwu7h1MRCeY6G18 dluln5n/eAhXjWsPfnY4Jbr3QGv4jy0PzFlDsVWhLREeevQE0fPZEcFKfg0TpA== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:43 +0200 Subject: [PATCH v6 10/11] clk: sunxi-ng: a64: select closest rate for pll-video0 MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-10-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=4401; i=frank@oltmanns.dev; h=from:subject:message-id; bh=024G5xyTznyRt4YpHJTxtDNLL91JqC/nakX5h3KPrX8=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcL6DaE1Q8WGp0HTbu3O/gaBmeyMGAX77e6E 1F0hBfzsB+JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCwAKCRCaaaIIlErT xzH8C/9vIlMTBZyle7xjv50JXMjdzs14tLgCPL5hgnrtl47p+7qMzufVdnUcxA2ITWgiY2KmWh/ kw7R5b/M9dUaX7qpX18K0j0rqZ7TSIdLbMtLAiajh0V9HSvidrSuNRUsnvTzJ2p80x01HfSMiXc BEiE0j13UnEyYCVjt2OCTZSYCkLJifV3YgNj9NfCvz8AortqoanYu53ERX1wxGtyA+EEUmOp9Sp fc2HalbCtPCZBaHhofbuzTbdewkmnCSF3IDX/+tYjwtGTeZOFJJCbhXintg2WOy99gR/bZHzx1A zBs4Cp6iYaEerxEdSb5LQUrr3w2FR7xG5gxN/3jGeZNTura690WsC4ke7ba+4u6+leKV1tPxRzd WVisJLEGemQnU0eII/Ar5/3OrRYpfOgWmJRqcvA1B1AucJaPqU/1Dep+7OTUMiZFZ2rAwsfI2eH BznEt9O2WoufKq1Wy+6hvc8CKE9O9gLW9xUzo2H/WkmpT5onR+Br4C9viyoSERrrnWFws= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGs2MTgz9smM X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054426_901750_D58A077B X-CRM114-Status: GOOD ( 10.99 ) 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 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 Reviewed-by: Jernej Skrabec Signed-off-by: Frank Oltmanns --- 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/ccu-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); -static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0", +static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "pll-video0", "osc24M", 0x010, 192000000, /* Minimum rate */ 1008000000, /* Maximum rate */ @@ -181,6 +181,7 @@ static struct ccu_nkm pll_mipi_clk = { .hw.init = CLK_HW_INIT("pll-mipi", "pll-video0", &ccu_nkm_ops, CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT), + .features = CCU_FEATURE_CLOSEST_RATE, }, }; @@ -531,24 +532,18 @@ static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents, static const char * const tcon0_parents[] = { "pll-mipi", "pll-video0-2x" }; static const u8 tcon0_table[] = { 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_parents, tcon0_table, 0x118, 24, 3, BIT(31), CLK_SET_RATE_PARENT); static const char * const tcon1_parents[] = { "pll-video0", "pll-video1" }; static const u8 tcon1_table[] = { 0, 2, }; -static struct ccu_div tcon1_clk = { - .enable = BIT(31), - .div = _SUNXI_CCU_DIV(0, 4), - .mux = _SUNXI_CCU_MUX_TABLE(24, 2, tcon1_table), - .common = { - .reg = 0x11c, - .hw.init = 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_parents, + tcon1_table, 0x11c, + 0, 4, /* M */ + 24, 2, /* mux */ + BIT(31), /* gate */ + CLK_SET_RATE_PARENT); static const char * const deinterlace_parents[] = { "pll-periph0", "pll-periph1" }; static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterlace_parents, @@ -578,8 +573,8 @@ static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x144, BIT(31), 0); static const char * const hdmi_parents[] = { "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); 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, static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-periph0" }; static const u8 dsi_dphy_table[] = { 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); static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu", 0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT); From patchwork Mon Aug 7 12:43:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13344128 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 87D20C04A6A for ; Mon, 7 Aug 2023 12:44:53 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/Npag+hAvgpInXU1CqXjz9h/CfmMwfhQFvf4LiyDuzs=; b=fM7ZgIWk66nRVl oDoUT+Mt4Pew+eMVQYvqF8L5KVPpjX+upnlGVijSuDKt9QFs/Rj1h45Gcq80vkl3Z3BzmJ8lPQV24 xCeQ9/dIz4v+bO6lKZILioGcbiyAj9eGFVUi7AB+YeatOqGTGRXw0STq8kIzm/QFe68fRuRd1uq3s vFbRh49xxFRQ55CKsToLL4QAtrDWM9EAbaZV1m0oATAq36n6UwTgSJNO8WB/bkovYou+VpebFO/+l vQN9dTPW6Xigrjh+YDOA1w1PxDWUUcus1LJmzfGBSnL4rKapnnF4hspv+6Rr/XJXacL5WzGSkFNQG tlcalf0+sAGAfmUhYRtQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb4-00HFuK-10; Mon, 07 Aug 2023 12:44:30 +0000 Received: from mout-p-202.mailbox.org ([2001:67c:2050:0:465::202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSzb0-00HFqb-13 for linux-arm-kernel@lists.infradead.org; Mon, 07 Aug 2023 12:44:27 +0000 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (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 4RKGGv3BnLz9sW7; Mon, 7 Aug 2023 14:44:23 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1691412263; 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=eujE6oPZv+zmJCFxuwNd5VPBn5IlE6vd2cc/1IpSkXc=; b=Y1z6Z9dbD+y1cpjLhNyi5Zd1auL26Zaea26L4auYxOnb7gY/t1T63Qn1SspKzzzaWFymKv K/bqQXnYbTDFmS9MHm38d14vse6oAdAWh/UxdZthEgZVkCuI25ovn+rQdU9Z+kjuQz2RoD pbohH+fLmF7Td9avv8QkGczZJOsGczso5j6KWRfr35yVS38LfgyI5ROYLZRoIdl0zjGsvx xsCAiwrsQV0cbPY2imTw9jpLz0oZUWqhhZAmVeoGZpb2CiLyTZ9HwTddNEFTRP4A6LaftN dSiqazAAqdEzi55CxIDcX/9jaSWqM/LYHvvaMiNDOrx0zEp5Uz0I23arZ+fUpg== From: Frank Oltmanns Date: Mon, 07 Aug 2023 14:43:44 +0200 Subject: [PATCH v6 11/11] clk: sunxi-ng: nkm: Prefer current parent rate MIME-Version: 1.0 Message-Id: <20230807-pll-mipi_set_rate_parent-v6-11-f173239a4b59@oltmanns.dev> References: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev> In-Reply-To: <20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@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=975; i=frank@oltmanns.dev; h=from:subject:message-id; bh=nX7O6HIGcIL6L1G1S3ONo9eulQgwHWxaNoxqcrZCmdE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBk0OcLfaRyp447JpXrEZFmI4EHjbwF9UWfiLNWq QOaFHIRNpmJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZNDnCwAKCRCaaaIIlErT x60gC/9o+RMltX9ZY6ftQCMuJXLFJlqfRCHw9zBPZWmougN1+w6ltG1Tp0m/y2ITx6pTgi25D6+ KD9Ipv4gUg0pfpZxgUbIibzgzLktFCj8nsWuwP6RoczbZf2cz5EC6uJPCppRY8n8VoCYJ3MQXCj AkFvx/V/K+DxWpCdqbaBhBXC04tGPbx/UehIXdK/1dgtg17uq4t3lM+2tCN9i413FTp9mbpR/1X a2Yb9ESG+SVVTmTUy1VkBBofGvCCN0Mymk/vGv2ofXjuAuo2xZ5Wy47wkKIvy+XV9VG+u6IY3Bi ltLW6QAHXbhdtcCFk4YCSakotisQcD7kTSmJc31x0LZq0LwzbJ3bfWVyLWkEwlNDxkA9SPQPOEE IXQ56SwHsSRbtoC5ovgn13hmyRv0o9W6nerBobz1bNYtciMCLURFL74OfvCueBeHym+XjUYp5fS KPWPeR89A3oydQ4e4zuHAgXaEELjn8CvW2H96XYViGCxkQZuBFiSMCAQWS1Y/BA+/ZY/Q= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4RKGGv3BnLz9sW7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230807_054426_506613_A00893EA X-CRM114-Status: GOOD ( 10.06 ) 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 Similar to ccu_mp, if the current parent rate allows getting the ideal rate, prefer to not change the parent clock's rate. Reviewed-by: Jernej Skrabec 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 a714dcf0dfc1..eed64547ad42 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -34,7 +34,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common tmp_rate = tmp_parent * _n * _k / _m; - if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || + (tmp_parent == *parent && tmp_rate == best_rate)) { best_rate = tmp_rate; best_parent_rate = tmp_parent; best_n = _n;