From patchwork Sun Jul 2 17:55:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299392 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 90322C001DD for ; Sun, 2 Jul 2023 17:56:23 +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=OqrTm1Jc6Tw9buPKk8HOzz6/2lZPy4rjZW/rxNpAh4I=; b=IZ/KE7LeW6P1kI nVIveLhT7JM29IKsVM8FLDolWlfmN8d7HQzoiGQJH+E5KUkH9UTuxxdf9p7ypQnzzxs6AZbdZ7kLu pa4rdYqdE+ObkNsloOAKwkUaCJMfwMqPlYB0Kqx/ejJAP3lWuHbQ1zn2I1MzPh5h+yviZPKOuurEy cj+eqfj6xSUCtRYiC+cQSG90ie3TzDS64W9ZWc08tku3yJSVuZX1FhQ2QKXnn13VY/DFQvw6sJPyv QWB4qqajQ5NPEreIqPTghp7hBPY34abdcqnYRurYf+VTZ1FdQcIt2a+0VXISnxOiCYaKtH3TKzhyL G51ZzPPCuu4RB+jImbsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Ig-008F7c-32; Sun, 02 Jul 2023 17:55:54 +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 1qG1Id-008F56-1s for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:54 +0000 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 4QvGtp5jn5z9sWl; Sun, 2 Jul 2023 19:55:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320546; 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=x9fmM0fT8uj3/mQjTtgGNj5UoFoMoqnDLGSIr5/oXTs=; b=SdiVR4MaEnrn4e0/1imGtdk3j96t4YqmDLtnEiKreTm9t9nW9wTtLAWgB4thPn4V4JasHy 9Fl+GZdP/qJ569jahiW8JknXFSmuShk1mepjZk1c0Ll7t9lPAteyRE6+z3lRi+SyV1BBvX QJgwvV2EPK7nKW4Q83/zEJ+8a67eWbr1wjAKojZJIe336Oh3CM26whugevkZ01NUGmKIn5 3BQt70mxv2bBDP3kav/PMzxptjGmCz5T3yeMUR3iZANJ6I93kbiz1MRPcOnYLCv+yno409 ddVtXdPlbBuz2pRBhVJwrAqqMhSX5CshXfS8uPe1MCkJ2Z5bnbP+svkIj2B08w== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:20 +0200 Subject: [PATCH v3 1/8] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-1-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=3396; i=frank@oltmanns.dev; h=from:subject:message-id; bh=HVQ5eb3Px+mMKJ3qzsFpElQcZwMVX6kra1Fj/PYKI+o=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobobH6sAdwPDpCnBt7BVKXWjmOzHtCN5tQzCd jGIoubVUyqJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6GwAKCRCaaaIIlErT x1eYDACPfjAKC+7Gsc70ClrDjNtQWbTy/MzHDJHYfwaPbG56Q4xfN9pNwZE9amuRcJPke0LF6Lc jANjHUPkOOSGHWDIda+BopPu28R48OdFZNuUdLtL3fyzA0AgodLkcKZkVUzz08uMxJQIEGxb05q fD0/8WnY0GgkxNhIVDByiE8mZCAt/syOzNvYMdERMJ/Q/XEPTcQGs9BBa2Vibo0C/RJ/R76kEXh w4y54LeEst5NL/AKNp5c0GgS6jEpYsFJMMT1DQcLiigWTP84++MuPuKH5Pzyi18d9TlCtfLIVou UXR5fJ/EAcGqleurg+PUaLQJARw8k9aAX1uqgE2jClgy5V7tdymilCOpmXSo0SmsUO1V7e0SWyM E5bLdYwWOkseHRnelpLGbzBXUhlIsbbV/uSfgg3v9fyTkx7QBl4lrg1s49sjqUJ0C2LuarpFuwM KpWmBrC+LgPBHklEAQZ/edq0sfeQFMsNOlCqRY8Wx1om8/AFe0cKQZuYooQg7BN/fHd7Y= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGtp5jn5z9sWl X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105551_793069_D039576F X-CRM114-Status: GOOD ( 16.66 ) 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. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_nkm.c | 48 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index a0978a50edae..d83843e69c25 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -6,6 +6,7 @@ #include #include +#include #include "ccu_gate.h" #include "ccu_nkm.h" @@ -16,6 +17,44 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; +static unsigned long ccu_nkm_find_best_with_parent_adj(unsigned long *parent, unsigned long rate, + struct _ccu_nkm *nkm, struct clk_hw *phw) +{ + 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(phw, 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) { @@ -106,7 +145,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) @@ -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_rate, rate, &_nkm, parent_hw); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; @@ -159,7 +201,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); spin_lock_irqsave(nkm->common.lock, flags); From patchwork Sun Jul 2 17:55:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299389 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 986B1EB64DA for ; Sun, 2 Jul 2023 17:56:21 +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=ljr9PrfNsvUMD2cP9kecHx1Eab8Z1B7UtVFU09OmF2g=; b=wme9IrQipu88y1 P/GYc3GtBsjenWc6+5NUwjkoHxN82nv1wA0+8/t5VJ+Tt/xUFtWZ77JfAU0BnntFdNAVDCt1Q0QHa Tvt8SnuEsmtg4jzE9Ypi4/S43N2/Hz8oDJRaTlK5EiD/Ig6l97MmvEUDV7BLd0aTjOINZthrHSgks XeTAKIOxFGWN4x4YGaR+GP19FL+IUKsG9W5Le/XwhcCqoRbxg5S3V8YgOzYH5foGD2L/SL8sIyWVl EjmI5i+rZ4NB9IBr2pqPnUg2S5fyBxyTmrO01/8lUZJfLHAMV764SarG4F0lqeWYbg61lAL1hom/Y +8KhRL6MBSMZxWl5dcnw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Ih-008F8A-1i; Sun, 02 Jul 2023 17:55:55 +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 1qG1Ie-008F5M-1M for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:53 +0000 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 4QvGts2SHHz9sbv; Sun, 2 Jul 2023 19:55:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320549; 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=+F9Qzm6IdvX+YdAxJq37HDn1fqo5BDQOBMr0dvLlSyw=; b=kY6yKlEzhagJ9p+DAc9ZPZDEkC5M+2MaRy9XAhQy8JfO8vk17IuZvkHmDWDFIfpuTdfArn xA0XeUYlDCCHJY7uZbCABfEfE0lC8Uyn2OtWHZuftxqVlAEqZRrHFMPGKa40aMoPAiU5GK kpHYeVzuYgU8/VwZrnsCpFxEQkaM2qQwuHJtA+FKeFS/4yAAC9cqLgoVkJBPCOGD2zAVK6 KLKBEDRcU/CZOmsUWsJnd2wb0jRIwcoOqw4H2UlR/06pGoTBpoZrNqeJm4duYzvnEQ3gz1 VTLQctSrCeKsVpPxDADfs4ZVrj20qGgfNjwdx5Zqsa2MHF/SXXEHRTXEmMOaoQ== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:21 +0200 Subject: [PATCH v3 2/8] clk: sunxi-ng: a64: allow pll-mipi to set parent's rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-2-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=806; i=frank@oltmanns.dev; h=from:subject:message-id; bh=6KqjBLS1Ov/nYPswsTAdcoLKG7a0XW4Ac8QXs1cSwVw=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobobka0bAipDKc0Ze1hPtisyY07V9gb2U08jO +hyzuXZYXiJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6GwAKCRCaaaIIlErT x12uC/9Ae6iMuCUPFpbZhqbKawdVnd6iFNqSqi/GCBjcMh2wXjRh0Du7zQZb7G5dt8d4AoCVdgM E1uD3Pf/FEtfKS1x1GMSN7UDx8gvDrI6b7cO/aMqvjInHWsuFHYVctDs+5Vxg+tMbODzLNF5mwv ZFy5Ytup/8Lw0cOtFcr4x3nief+pu6PmuRdl6lMHjXqqpV81nGrai/KxjY6OygCe/nSNG/jZ5wk GYpgO8+eIrtxDj1SnLIeHT/9C8loZ61RY9AfzKrX8bkc1FH0IfXKq+smvrEtGkVWOq/swT27tOA OwWLJqeyRwVgyeOSYafi4gFH1UplHB9k3cyuvN2sxqOFeqR1tj/b6yZcdoCPn69a5L6PElAwFyB QhLKejkhqq20rsae+CiDd7HmZCuQjMraBkv1knNdATdPbvAw0CpB1CKAszC1h0VS7f/+wSssRMH //RwPC3wEg1bGdQRfMM2/EG8+sAfGB+WwKpVc0Pq02k1lV/OQzPbBanP0TtlQUK6XPmyg= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGts2SHHz9sbv X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105552_616282_97D81B14 X-CRM114-Status: UNSURE ( 9.95 ) 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. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- 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 Sun Jul 2 17:55:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299390 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 986E1EB64DD for ; Sun, 2 Jul 2023 17:56:21 +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=5rJQ2rtipPRQfpEKV0dIqTTBbtb6RgD99+R1+j4ihqw=; b=wyiLoGYi6JTLeq 06LP1D78k4ZYtpPUVnzqmnzqo5r0cIRgKaKox4YFDo0Qtnw7yZBDfmXbteqTXGz4A7SY4UcgebGFY 54lHgcvlnd1DlFC2blTJfNA4DqK4ULnuyZIXntI2PMLvYFp1iabqF4JMc5VYHdePXa8/I3EiXtUZB k3V+fz24V6Wehil1Mj6Vq8dpm8lBqeNMFVsraNkzvfGDNCWWzn/S3A3ndt1BXaE5MdoNHRPcqOMYz DKEnCfPKmfVPN16AVU2QXLwwRdDBbCqhlvkT8FzrvDPeRfsoxUpwwiVzhjELNUdJf3kYl0918FpTh p0qGN6fCS0bkYD132BJQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Ij-008F9R-2N; Sun, 02 Jul 2023 17:55:57 +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 1qG1Ie-008F5k-2a for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:54 +0000 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 4QvGtt6CD6z9sTH; Sun, 2 Jul 2023 19:55:50 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320550; 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=UYJXelK6HIvlm3HnYGcGVVQzmR308v13RIhh/o3PQBg=; b=wRnKIno8Zl+53XIRjFS/8DvIMFh/37nriSsfDYkfGAlw21nTdvJibyZt4RnMnZR1e9tHYF 7RMMtijVm50jTOmFB6PEe3/ub0M+hcZ4k631WaO1xGrVo+JoPF4zguI2fRs1/JCe52ouZm DKraCXnpZ5aRTKrMUHhoMGtl+yRxPz+v8tOd+UbVD8AOolKtk37+icYAiK0LFTOtFJswDo B8J3BybMON/yOnjd8eEknhxYazb96n5d7oxERavE96v1qGNRidH0zoqBu93j/+a33RFfK9 jiRVtflKB9bi6Foq3a4iwZcwYtUH+3RmC8cFM2qs7TnfQUPEPlnF/JXPQq4HWg== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:22 +0200 Subject: [PATCH v3 3/8] clk: sunxi-ng: Add feature to find closest rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-3-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=879; i=frank@oltmanns.dev; h=from:subject:message-id; bh=nq4as25RxVF9/y/5G9YYRABH8Ort2KDG2xy+iJVw8Qw=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkoboba3wAEwXiJymkTQCoONbsAf4+BrEkd06OO xBG/cEzMmKJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6GwAKCRCaaaIIlErT x9SuC/9IAekMRGvkUFyioDP+R5cgyY2CuyinjuaOp0VgYfQ2L+COWJOmDq9LIovGIVqXAOQ5L7v DrS2cT4q70H59JbgSrrZeEBfBheXAJ3QNS/akazcMZcm7ulkWFzVP0ilQuBE6+wrnakWecHFhJ9 ZH1edZU3VQjYxxwGIv92yGgrIL35slkPSUKmKCI9T37rEWfcF6JPdj9uNwJqcPY0xA6WwC6aGp2 ikVcRryVFPL6nRz/kOZi44V/vAvY3iq1E2uBvocLkS2oxkgIj/tCQhwaYUVcV8mwUlbME/mIrBB MsoBRhtI2TbZHbwbkaYIi9cn9XupxSO5a1f6VzW5h6pQ4gYMA4W/uHFKhcRI/7UKhkgYNGU/Llz VxKUCr7JPGfK1QreusM1xbgovRYi5t4XYoidsU3pxDYqnHqOwhhUp9imprHKxbqXOJyQuD0GTrS JZE5pMquaDSg8rj5OQKZGErmrLjSV5V2YwJ4BbvA++WgfAEWCKR28Q4x9nvYr/cbuuBYw= 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-20230702_105553_061807_EACF0C46 X-CRM114-Status: UNSURE ( 9.78 ) 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. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- 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 Sun Jul 2 17:55:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299391 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 06087C001B0 for ; Sun, 2 Jul 2023 17:56:21 +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=hnER/bTYJdW1P7X+3tvUTkv/J58nVQtRW3L0I665wE0=; b=vGOeXAzQQps2g2 DzPGfBrTdjFIa/rF05vrjQvp33QDK4/LAhxQaH5kGl25K1B7hODHkBMF7QDCmVby2vqxc5pwJOVPW vajMM94haIGlgwa2gZxz1p7fpDDzuozbFqiai4dwGTtTFFxyQ8O2z9YqNTPx8J6KfWiAQMf6R4zir r7TbrSOVUZ7Is+z0+qlys4qTi4YI+nJ29hGRqlNRI85sS30nu4v6ntFB+Re7gRloCJsLE7mrrAVxe +3ne6XmTO8ii5ydSdQCXfMx8xoImYGLu9QDcOGRrDI9cn4uZaL1+/r8k2xf8VOvCaMe/c+xEYuMmn Jnse256kgykborOzsELA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Ik-008F9j-18; Sun, 02 Jul 2023 17:55:58 +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 1qG1Ih-008F71-0X for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:56 +0000 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-102.mailbox.org (Postfix) with ESMTPS id 4QvGtw65Pwz9sbm; Sun, 2 Jul 2023 19:55:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320552; 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=fFSE4aJXFFiLcg46myKzbINBS8Qh8rFz5Co1KmVIz9c=; b=NxjLsHxmcDG+O4jv6nkpiaLmfTc5Rti/kGk7qPjQ+szKNf2CJB+T36Qn39RKMwMM6YKwQh QTRZhlPJf0HOEdT5OPVZk2eTLWlrKh0zg8Zeb85+yKjB3bUAMxEZOY06e3TW93YebdLrRb pC6KiIEMuh2H4sNtdP/k2QxVA3dxd37fs0MmJZOVr284oHSzKzI+XJQ84Q/xjRTqut4PA+ NE3IU4sA6Gwg4TyN1q6dgQx0PVTpBFFaRld1b71ecUQGd2KHSLdYg20U5oYK7yqgD+au4L fOvmTXkjEk1qzc7ecvO8BXoKD9x6pTcZUinvfVlxUxy7+xKfBC5LLlSPsTvkFA== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:23 +0200 Subject: [PATCH v3 4/8] clk: sunxi-ng: nm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-4-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=6190; i=frank@oltmanns.dev; h=from:subject:message-id; bh=5Cd03N4wCNx9JuiFbCYwulRT4Tt8W9Fv6aFmgI2nQA0=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobobzLxhZc/Ur48ZGOAn+H+uJYSqXhqjjM0Py RUV9MIN6cuJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6GwAKCRCaaaIIlErT x53GC/9lHsOibQro7hT4RiGVeZ8l2DsILXW5s9Q6CWufBDacRWxz6H73PI2jo3tvJGpQL+6MRiH A1uN5YRAtSvqQ0FqNGl6GEsIA9sTJQr7vfZGh4nelI7e0jW3Sg6f2+G+Msp7E1aEvi/DJgTSsxm lJ2jBOM/FxALfrKKzhOZThjPs9PbTKzuBvJw2F65KAbgMyK1usOJVEIgRPqQxthXLcfrX1rq1al GciCpuFrmI+n/1Ag7vGt8Jd+PpCvB6HpSWuAMz/i6zSgco1w3EiZ9MsnZLZLaawAdKFkdHtuUn0 KMQQu6NkVzyfrk48ugtDIuJUbO9GLzzp/OI8da0McEDa24QQBd8zRm+/pjS+5/8gQC/3YgJdpK5 e22vixHylxMVtQBm92TenOOsZWp2ubv+7j6faTgeaozCwbMLulBFMVM2Ds28aJ4T0/aDSGvqD8z voDdxm05UoHnz2XIp4xl1RVRiog8DfIzq5sy4AZLAQHqQFwVlCntykRayuV/I77rgvqIM= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGtw65Pwz9sbm X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105555_350481_24DF7B41 X-CRM114-Status: GOOD ( 15.51 ) 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 Incorporate a new function, ccu_nm_find_best_closest, that selects the closest possible rate instead of the closest rate that is less than the requested rate. Utilizing rational_best_approximation has the additional effect of boosting performance in clock rate selection. In cases where the CCU_FEATURE_CLOSEST_RATE flag is set, use ccu_nm_find_best_closest instead of the original ccu_nm_find_best function. Extend the macro SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX to allow selecting additional features and update all usages of the macro with no additional flags set. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 6 ++++-- drivers/clk/sunxi-ng/ccu-sun8i-h3.c | 3 ++- drivers/clk/sunxi-ng/ccu-sun8i-r40.c | 6 ++++-- drivers/clk/sunxi-ng/ccu_nm.c | 23 +++++++++++++++++++++-- drivers/clk/sunxi-ng/ccu_nm.h | 6 ++++-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index a139a5c438d4..ebfab1fdbb96 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -80,7 +80,8 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0", 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + 0); /* features */ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", "osc24M", 0x018, @@ -143,7 +144,8 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video1_clk, "pll-video1", 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + 0); /* features */ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu", "osc24M", 0x038, diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-h3.c b/drivers/clk/sunxi-ng/ccu-sun8i-h3.c index bfebe8dbbe65..1e2669648a24 100644 --- a/drivers/clk/sunxi-ng/ccu-sun8i-h3.c +++ b/drivers/clk/sunxi-ng/ccu-sun8i-h3.c @@ -76,7 +76,8 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video_clk, "pll-video", 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + 0); /* features */ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", "osc24M", 0x0018, diff --git a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c index 31eca0d3bc1e..63907b86ce06 100644 --- a/drivers/clk/sunxi-ng/ccu-sun8i-r40.c +++ b/drivers/clk/sunxi-ng/ccu-sun8i-r40.c @@ -82,7 +82,8 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0", 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + 0); /* features */ /* TODO: The result of N/M is required to be in [8, 25] range. */ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", @@ -169,7 +170,8 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video1_clk, "pll-video1", 297000000, /* frac rate 1 */ BIT(31), /* gate */ BIT(28), /* lock */ - CLK_SET_RATE_UNGATE); + CLK_SET_RATE_UNGATE, + 0); /* features */ static struct ccu_nkm pll_sata_clk = { .enable = BIT(31), diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c index c1fd11542c45..97d8d9e3255c 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -6,6 +6,7 @@ #include #include +#include #include "ccu_frac.h" #include "ccu_gate.h" @@ -56,6 +57,18 @@ static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate, return best_rate; } +static unsigned long ccu_nm_find_best_closest(unsigned long parent, unsigned long rate, + struct _ccu_nm *nm) +{ + unsigned long best_rate = 0; + + rational_best_approximation(rate, parent, nm->max_n, nm->max_m, &nm->n, &nm->m); + + best_rate = ccu_nm_calc_rate(parent, nm->n, nm->m); + + return best_rate; +} + static void ccu_nm_disable(struct clk_hw *hw) { struct ccu_nm *nm = hw_to_ccu_nm(hw); @@ -159,7 +172,10 @@ 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); + if (nm->common.features & CCU_FEATURE_CLOSEST_RATE) + rate = ccu_nm_find_best_closest(*parent_rate, rate, &_nm); + else + rate = ccu_nm_find_best(*parent_rate, rate, &_nm); if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nm->fixed_post_div; @@ -210,7 +226,10 @@ 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); + if (nm->common.features & CCU_FEATURE_CLOSEST_RATE) + ccu_nm_find_best_closest(parent_rate, rate, &_nm); + else + ccu_nm_find_best(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..a3825c4e8d42 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.h +++ b/drivers/clk/sunxi-ng/ccu_nm.h @@ -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,8 @@ struct ccu_nm { .max_rate = _max_rate, \ .common = { \ .reg = _reg, \ - .features = CCU_FEATURE_FRACTIONAL, \ + .features = CCU_FEATURE_FRACTIONAL | \ + _features, \ .hw.init = CLK_HW_INIT(_name, \ _parent, \ &ccu_nm_ops, \ From patchwork Sun Jul 2 17:55:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299393 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 CCA2AEB64D9 for ; Sun, 2 Jul 2023 17:56:24 +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=v0CDIbsQfVGjmNT2KEKcKh+Fj16SQUydAKMwbBspWOY=; b=fSrVMuNEMI/IOT LrmBTpFN6RujlfpUYBJ7Ucx0SNhU6+NadZIBxeopcOBtYmsTUuv/zy3ngvEbTWTshv+i0Hibau997 zQgfaXssg3mLTRegLIo4RAzaAKyCSuAuKrUx2Gdsg88tz41QdZ6/i0Z9L57kARuit1klfxTY56jsV NXwEASq8VPdSYBiG+4PZU5++p8C5Fs1/FpcgArJ/40Yze6HwbIz5XGeUhukw6tdQ+eELNAMQn8zOg Xx9QAC7lSn728I9/DVluyIXHstnB/aBTeEkbtaj8q6qVpuTLscGIHK/KNniaGN1kSEKnT98nuXAAD 27Yhiq4OMny4OqJScvpg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1In-008FBM-2J; Sun, 02 Jul 2023 17:56:01 +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 1qG1Ii-008F7b-1e for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:58 +0000 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 4QvGty2ygmz9sjH; Sun, 2 Jul 2023 19:55:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320554; 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=aq590HVBEwg50wkxos7ahgh1JLWFQV+J8aVVvHi0a4Y=; b=sp5J/ikkFc4sG/tZVmx7vim/b4tes2DMOeGREJ0+Am3L/iIpglGd451ODGeccWD/oSayT2 KIghBJLi6i4mEH5MnomDsDC4kMHhZiwAIBfNp25zrxRy9AwKCnNbtCNCkWpaPfbdf3p/YN J+Vxj18uxXlEzKUNOmKn6Xo4hQCdjBSo78WUm8OjNzbgbn0cA4NU8obdpMyYy1ASPygTqM L04KLs/3m3Y04whldj3CEi+idzvlflpbDMTdOgS+HPhnghtVl88iP563MAf0MSu17BX8Tj sX0vWVd/YrVs9xHIczgD26PHK3fySe1QFOURUAbLsL/t7YvbJ0oFDJ/GnGlwBA== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:24 +0200 Subject: [PATCH v3 5/8] clk: sunxi-ng: nkm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-5-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=5689; i=frank@oltmanns.dev; h=from:subject:message-id; bh=01TYbYHSpWpEljajLcjLJtavTtPY0wbp20arNVgfXdk=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobocbibhLaXOZS9QFPeBBunCc7/+EdaOJX2Bx Kw/P870HFKJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6HAAKCRCaaaIIlErT x5LsDACBuood8TCghOul1h0Z0uWTsL+qOFEbf5SrDXrAA8Gh3TxAAkDJNuwr+P3qiTYHJTl4V81 1f1IJ5VDj+osn/SZfCADWNn0ii+hXFJekCxeykaZaJmFtudM8USZskZ2z1bowms9Kcm4+jRC53g JYg0iDOO7Mnj8DH8S/ip+Di2+ugxWwzi95t9lf7kxL9vhVhTP8J7S4tQYSjBNSlOvKaKvTzHO53 4nbF4wnU5zwncRPP9KCIlmito4mOSArUyZQAml1/M4y8YwyGgR6fMnavq9swFAd3uS3SmEP48xU 6NQFWBnpBZrWXcySWmPOdATDfw80yeTzUVSqZtVQeSLx9bpl+DGxtMI6WTljKDUxEptUFn/kmzs SAAg1mHka5vwnou+4rd0zXw8gWu1bp6h5mstTNU4kq3nTNz4G2hQrT73YsYNzuTdMk7jaOHJmvq zUojXNqeOdFFHN9HUnZVQGtK9EeoeCuGYSWtiaYXVUeebtwKgAUC5oFYzfxaWIWgjF+Bs= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGty2ygmz9sjH X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105556_774309_E38CEABD X-CRM114-Status: GOOD ( 14.89 ) 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. Accommodate ccu_mux_helper_determine_rate to this change. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_mux.c | 23 +++++++++++++++----- drivers/clk/sunxi-ng/ccu_nkm.c | 48 +++++++++++++++++++++++++++++++----------- 2 files changed, 54 insertions(+), 17 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 1d557e323169..8594d6a4addd 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -113,7 +113,7 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common, } for (i = 0; i < clk_hw_get_num_parents(hw); i++) { - unsigned long tmp_rate, parent_rate; + unsigned long tmp_rate, parent_rate, best_diff = ULONG_MAX; struct clk_hw *parent; parent = clk_hw_get_parent_by_index(hw, i); @@ -139,10 +139,23 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common, goto out; } - if ((req->rate - tmp_rate) < (req->rate - best_rate)) { - best_rate = tmp_rate; - best_parent_rate = parent_rate; - best_parent = parent; + if (common->features & CCU_FEATURE_CLOSEST_RATE) { + unsigned long tmp_diff = req->rate > tmp_rate ? + req->rate - tmp_rate : + tmp_rate - req->rate; + + if (tmp_diff < best_diff) { + best_rate = tmp_rate; + best_parent_rate = parent_rate; + best_parent = parent; + best_diff = tmp_diff; + } + } else { + if ((req->rate - tmp_rate) < (req->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 d83843e69c25..36d9e987e4d8 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -18,9 +18,11 @@ struct _ccu_nkm { }; static unsigned long ccu_nkm_find_best_with_parent_adj(unsigned long *parent, unsigned long rate, - struct _ccu_nkm *nkm, struct clk_hw *phw) + struct _ccu_nkm *nkm, struct clk_hw *phw, + unsigned long features) { - unsigned long best_rate = 0, best_parent_rate = *parent, tmp_parent = *parent; + unsigned long best_rate = 0, best_parent_rate = 0, tmp_parent = *parent; + unsigned long best_diff = ULONG_MAX; unsigned long best_n = 0, best_k = 0, best_m = 0; unsigned long _n, _k, _m; @@ -28,16 +30,26 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(unsigned long *parent, un for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { unsigned long tmp_rate; + unsigned long tmp_diff; tmp_parent = clk_hw_round_rate(phw, rate * _m / (_n * _k)); tmp_rate = tmp_parent * _n * _k / _m; - if (tmp_rate > rate) - continue; - if ((rate - tmp_rate) < (rate - best_rate)) { + if (features & CCU_FEATURE_CLOSEST_RATE) { + tmp_diff = rate > tmp_rate ? + rate - tmp_rate : + tmp_rate - rate; + } else { + if (tmp_rate > rate) + continue; + tmp_diff = rate - tmp_diff; + } + + if (tmp_diff < best_diff) { best_rate = tmp_rate; best_parent_rate = tmp_parent; + best_diff = tmp_diff; best_n = _n; best_k = _k; best_m = _m; @@ -56,9 +68,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(unsigned long *parent, un } static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, - struct _ccu_nkm *nkm) + struct _ccu_nkm *nkm, unsigned long features) { unsigned long best_rate = 0; + unsigned long best_diff = ULONG_MAX; unsigned long best_n = 0, best_k = 0, best_m = 0; unsigned long _n, _k, _m; @@ -66,13 +79,23 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { unsigned long tmp_rate; + unsigned long tmp_diff; tmp_rate = parent * _n * _k / _m; - if (tmp_rate > rate) - continue; - if ((rate - tmp_rate) < (rate - best_rate)) { + if (features & CCU_FEATURE_CLOSEST_RATE) { + tmp_diff = rate > tmp_rate ? + rate - tmp_rate : + tmp_rate - rate; + } else { + if (tmp_rate > rate) + continue; + tmp_diff = rate - tmp_diff; + } + + if (tmp_diff < best_diff) { best_rate = tmp_rate; + best_diff = tmp_diff; best_n = _n; best_k = _k; best_m = _m; @@ -164,9 +187,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.features); else - rate = ccu_nkm_find_best_with_parent_adj(parent_rate, rate, &_nkm, parent_hw); + rate = ccu_nkm_find_best_with_parent_adj(parent_rate, rate, &_nkm, parent_hw, + nkm->common.features); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; @@ -201,7 +225,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.features); spin_lock_irqsave(nkm->common.lock, flags); From patchwork Sun Jul 2 17:55:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299396 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 5A221C001B0 for ; Sun, 2 Jul 2023 17:56:27 +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=+WkULyt7Yc/UnHcDZm/BzFGqaztmtqOdAOwev+QtLe0=; b=NGBgXL1pGzzM5Q dy9x/SWPVdrqB5SuiKhRIYbzCYof0P315tbd77k2l87ia2bK71RRWL4m05OsCP/cJjTNkwE0dsoA5 +Ig24KnuLxMmYjjgZEsTObLRp/X8oIxoPyn3pVXE5C903AZ3LVTQhlnKwArPttJlv6lxnz/Vxc3h/ lTnF2rki/VmnHQDWXgKdZNUXFRm1ptYO+KYCiExgwisqbVmh5bOD9drCrtKmrfPfKxfbwqReGxQXn 8OkVAuO/fFH+zGE/6tvVhf+UjdHEh+SsOoOEZ8aHfwqBl/I2bRubcejVou1ojItq5aBFVTjJSge4u 01YNSNbYuuwDdjO5oftA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Io-008FBt-13; Sun, 02 Jul 2023 17:56:02 +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 1qG1Ii-008F8O-3C for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:55:58 +0000 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 4QvGtz5c4Qz9sZZ; Sun, 2 Jul 2023 19:55:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320555; 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=IZMNOAHPDl9b4RN7sUq38ZIUetqHmkZGYvLFzUrfFmY=; b=ZP3C25mm/2Mr1zTr4yzpNcFJDvHsxZPCxmErBcBbREuaK+PhUOEcJ0k6gxarSx+cc8iG6g qRxxK8qFy2mIHUkvhUVm3a4N7d4NJEho08eWIVK2srGxF9XKADVUhu9LrMBAxNBbBhvVoW qwYjPsLX43vZMc2HLnybyy/WZ+nBIjDmqot+Oz3vLDSFEiEQS7m7r4a3GtP86o7ArUb7YT +jS4thVX/N9A02xbhYw6gvwlht2Ah3KPL+6sipVfChTHok/BvXB8iQLrtfIHWerNKdY6aX DAo7jPBJhUdaH+5bAwomVTgzglUIg1haCabBfJE7qGy5K7vLtqfuCJ2NCs9AaA== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:25 +0200 Subject: [PATCH v3 6/8] clk: sunxi-ng: mux: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-6-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=2527; i=frank@oltmanns.dev; h=from:subject:message-id; bh=HsHfxFRs7DqOrFQiRdG6ZrjV1WoqnP7I3+QzdUYxcq4=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobocaAucRSds8Zel2B2AZiCmG1Rk5mjq8PIH7 ek5IE04aoWJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6HAAKCRCaaaIIlErT x4U6C/0XkZefhQVUaII1v3aP3hDxww/N4F+dog+qiEvBVe/dTsFsOc9yPS85sDiiWVJHJ+Yvppy ZwCrAv5ZYb1QX0oyb/CZ0qAb5EtDU2Uix0urFYZPj2XWGZgXxZtYu6zO2p9fDmF00u9daMtcfI1 oH8/qofO//Uzu0dGAbom6cIcJDAnkN884yKtknWrNlH0GQXzCgUiKVlNWre3AZkhaHVgIWmYSxF dDwOe5jOO0dyIA4oXRAIIyl25ZOctIPyln4yX8EtEXuXkwQh07x6d5T8J3eCUSwCEoN3xEVzvIs iH86hDfMS+2A06TZa2x08l+N8zaqS+M3IQDheh7pdPueA07sobAPhP13dMbfNrEVYSqLzohmI4c fPgbTUanW2ky8qUnuGpkYmnRFnV1IiCOkwy7rhbXZ2KXpwbFnozFWKBp3qf/jr9UnuRpQk8580F p6x+H8VwStv2Juvpv7crMUF44JdDWKgUOK42lwZg9BcY+1Cns6/llnbaEwblDaSqObhvU= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGtz5c4Qz9sZZ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105557_171564_BE20DC71 X-CRM114-Status: GOOD ( 10.84 ) 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 by introducing a new clk_ops structure that uses the existing __clk_mux_determine_rate_closest function. Furthermore introduce an initialization macro that uses this new structure. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_mux.c | 13 +++++++++++++ drivers/clk/sunxi-ng/ccu_mux.h | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 8594d6a4addd..49a592bdeacf 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -264,6 +264,19 @@ static unsigned long ccu_mux_recalc_rate(struct clk_hw *hw, parent_rate); } +const struct clk_ops ccu_mux_closest_ops = { + .disable = ccu_mux_disable, + .enable = ccu_mux_enable, + .is_enabled = ccu_mux_is_enabled, + + .get_parent = ccu_mux_get_parent, + .set_parent = ccu_mux_set_parent, + + .determine_rate = __clk_mux_determine_rate_closest, + .recalc_rate = ccu_mux_recalc_rate, +}; +EXPORT_SYMBOL_NS_GPL(ccu_mux_closest_ops, SUNXI_CCU); + const struct clk_ops ccu_mux_ops = { .disable = ccu_mux_disable, .enable = ccu_mux_enable, diff --git a/drivers/clk/sunxi-ng/ccu_mux.h b/drivers/clk/sunxi-ng/ccu_mux.h index 2c1811a445b0..c4ee14e43719 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.h +++ b/drivers/clk/sunxi-ng/ccu_mux.h @@ -46,6 +46,22 @@ struct ccu_mux { struct ccu_common common; }; +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(_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_closest_ops, \ + _flags), \ + .features = CCU_FEATURE_CLOSEST_RATE, \ + } \ + } + #define SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, _table, \ _reg, _shift, _width, _gate, \ _flags) \ @@ -113,6 +129,7 @@ static inline struct ccu_mux *hw_to_ccu_mux(struct clk_hw *hw) } extern const struct clk_ops ccu_mux_ops; +extern const struct clk_ops ccu_mux_closest_ops; unsigned long ccu_mux_helper_apply_prediv(struct ccu_common *common, struct ccu_mux_internal *cm, From patchwork Sun Jul 2 17:55:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299395 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 3C0D6EB64DA for ; Sun, 2 Jul 2023 17:56:27 +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=2bdNJ8Rn2mI5HbZHcVj1o+HPgN2e/dvYuc/+R5qJx+Q=; b=EQ93Ew2XDRLKZS tD050eyiiR/d5YKhHReaFJiKbhLz1VfmJONxaRkMYyakQ9jNQPhHm46euJqXkrZjuZE8yBKLsRvQT pjEkO52fZFNR5RGiKSU2k1bWJ8QNkI6qX6ugkfvBrtrc1UnQ4Aakz/VRescmxzMIet6MmwYF6VBpl j1je1VGTsdgMZAWNHBLXSFe9xauDEUI2jMVKi2SYRU1LH5U6OR1NUT1BBfrfRviAYrdcZQEaSR+LY mcGXE0LWh08aCFQveSJvkeTu6mgz8VixI8Ofw/6YYhSHCOPV8g+31SpP2m9quyEkDtJdjwv5tPjs/ Xvrqeo37uuMAZeue+D7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Io-008FCX-2o; Sun, 02 Jul 2023 17:56:02 +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 1qG1Ik-008F9S-2E for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:56:00 +0000 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 4QvGv12x10z9skJ; Sun, 2 Jul 2023 19:55:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320557; 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=6fwdl+myIVhz4fju8/+Tg66+u2ifTeRnG8yD5hL50NQ=; b=tYNVri5o8GB1Ho/3fLOcVBK6rk4dIp2HluB9fOWZOnXV9Lx7MvaIPJeN73hY8NtpFb9g3F g09cJKXbcfsWLrO3WpqtTK883foyW9M9okqITkVus+8USg640nldFx5wZf00AaAHS2jhjb kSq2eH0p/GXwVlTNnsWdLdodW/1EY1YPptV9ESaXeoN7+N7+va5DQ/Kou3SuGYe/LUAGVr Y/cvJ2uvC1mxEVy/41xaICrmfz1Vj7vUPLMD5FSkPhIeFevRt9yfpLR2IqJ8gLho3i94sx XjWct/gbPhrTRs/L1ttV2cQ0TunG39RUXyrLldHXz4p8UozxrrGXd1d+s8Husg== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:26 +0200 Subject: [PATCH v3 7/8] clk: sunxi-ng: div: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-7-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=2074; i=frank@oltmanns.dev; h=from:subject:message-id; bh=QteUt2cYVvavIEwNN/k9PvZ0L1ThFgIn+WnM3eoykB0=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobocOMfDMsDUymIH/PyoN0nvjIa6tG2TyObYR gaiaSGEjFuJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6HAAKCRCaaaIIlErT x96rC/9HxzJ9h5ODsSFizRvb4fETeTYNyXNwWX3Y6PuMx4fsp9pFEzSLDwTRnRr6mKeVfBvIr1j vTK+FkuVNn5x9Sy9WiUY92932dcAiDbli0+tXeP7fvd6zQSVDcVVoAbsC4F5dJAoAks85zT3i5M 5abscfvPwDHgNAa1Q8GsgX6YupX145We9rnj0guyw572xf88z5tIVZJ5qYMOcjArB8hKNRKCtm8 9jJv0Y+GvcC6WJdKwX3oLIILPdAfthP/Hj0z07kcTuLdzuh7cGN+Z61VnDlwIC5myXfcKQduOTI 0FX3PxlP42tOc/J8GfWjHGjImK27iObWLvRCiv06d+a61mq4ZnBuP5Alxzzt3svRdDuP91YxEkn vh2Yo7uRPVn3Wc+kXrXHSke6oOWjvpmX92g44Ov7OYOYNT7srg2QXVoFc90GncYAwzyytLlUOiN 6Q4BoFUApwyi5WcYJ3Z17TjG4rdD6OXTFuD4aXZC4F51mnmIJpQzwEkAlFsp+HPNH5qt0= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4QvGv12x10z9skJ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230702_105558_877020_014D8B54 X-CRM114-Status: UNSURE ( 9.69 ) 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. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- 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 Sun Jul 2 17:55:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13299394 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 346B9EB64D9 for ; Sun, 2 Jul 2023 17:56:27 +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=ek8+psKhPfwmlS237t9tT81G+gKgxNE+Zf0IB3JQ/aw=; b=g/mfpN5gq841Ue EGyo7iP/FcP03aONRcborNrK17mJkgwzTOKLwaFcs83N4AkCf1xJ3CzcwZLvG38Z15jxhWjdOLvpH gYBEHDCX6irGTXLMTeRDAj3/QoHJSXush/aOAuGysO92blvSCFKCS6kxhW/FdrJOv6lpL9b0XeP9O NE9HKOcqHx5GpF5HCUh3xyiW/qFjsGpwhg8HBk0vvJ59I0MZ3fv9CNeJbEB1VuzsOSEzTOSHJsFiQ HEHYKw08YwKhPtIB/06pHAvxMr0KXQf0ORM6IpNQQvHbyu/KwL8i3gdJ7OEpwU37+12lIrrVTjoyg vne6KP6p8ackd1/1sLuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qG1Ip-008FCx-1P; Sun, 02 Jul 2023 17:56:03 +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 1qG1Im-008FAf-0y for linux-arm-kernel@lists.infradead.org; Sun, 02 Jul 2023 17:56:01 +0000 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 4QvGv30QhXz9sbm; Sun, 2 Jul 2023 19:55:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1688320559; 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=05TpVB802qVXSW1gPTBeMS94czD58kHBof/XOWCW1Cs=; b=kj3eZyPWodwYgfYKNr14Nci5mhsXcWgQ04CfPu8XIFU7cyRpWI+61p2Onwl1RDxwP6X6PR ugBTP6pmuj2hAvm86HSibUMeT+YNFuLjr6yp42YKlFOvKik2ZSgfInuNCK8kWWrn5gm6CE gBGkW4O/5BGpm2QbsfmEhfn9SnedHhYNj13QJ7cllOz7jxPPzdtw2NDDyLZpEZkZyTMRh7 /nQboXmNpRYOElc5iwuWRxr/ChqiHmVVzjopTvVEvAJXWibmg8YCbxkNc9bEteDHen1LoF 12wAM+v2NZMbkg5mdHAC7V9TIZUVjPOUMtAgvaeZGHJxdjhdgD1brecUSVHrcw== From: Frank Oltmanns Date: Sun, 02 Jul 2023 19:55:27 +0200 Subject: [PATCH v3 8/8] clk: sunxi-ng: a64: select closest rate for pll-video0 MIME-Version: 1.0 Message-Id: <20230702-pll-mipi_set_rate_parent-v3-8-46dcb8aa9cbc@oltmanns.dev> References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@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=3899; i=frank@oltmanns.dev; h=from:subject:message-id; bh=197LnJF+mxqJfrEMx97C1MbnPBlm/s49NUyIjbbLA7Y=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBkobocAcoKsagwzSb+TESv5+jJ5hL5vFRkXaIz0 0LDdil9I8qJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZKG6HAAKCRCaaaIIlErT x8woC/9KvSYyv+ISWgVej+ZAx4vm4YPRhLI7QKFc5BwLhASffMU3Z/in+P8BNB/R7d6qSJa5KDH rLztcWXkfww2Rmk8x02bMj0fSGedSadr5DDKQTblJ351qB4ayDz01hRO3ahxxgArYTTC/YpEKJP 4AIZLW4pIIGChLt/QopvUPFJ8wXSgmCnADXLPmdOHgrym2xoVfIU2CRACFXBsrFcdaOMNQ7YfAH sFHR3KmRnsQNIfK4+MdQIAA8xvm5KsYZfBXL5HPnB1D1fCe+liMwcW3SQXF6wKVCNnFFp21silu p1ZFMVLrinGZrO47MEfVWFEYme0N3mBkJzjJPzaKhzu8ARe4Nu9u0Hbh0jmS4Gj0d2dJ5Ica+tC epfxxjTulS7QTtaTQwVav3JTAfj5vyH4IJSyqFYH+Qkysrc8jji5FcMpxIjvfwifcHIdWmY+XlB 9e4SkdYsI8zONOE+9N5sn/5eIEVnQ9LWBLRXFxoHc378pgHcLHZebe7UwTg9UR9d85D18= 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-20230702_105600_486406_A6AF7C17 X-CRM114-Status: GOOD ( 11.85 ) 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. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index ebfab1fdbb96..016432ff3bde 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -81,7 +81,7 @@ static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0", BIT(31), /* gate */ BIT(28), /* lock */ CLK_SET_RATE_UNGATE, - 0); /* features */ + CCU_FEATURE_CLOSEST_RATE); static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve", "osc24M", 0x018, @@ -183,6 +183,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, }, }; @@ -533,7 +534,7 @@ 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); @@ -541,7 +542,7 @@ 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), + .div = _SUNXI_CCU_DIV_FLAGS(0, 4, CLK_DIVIDER_ROUND_CLOSEST), .mux = _SUNXI_CCU_MUX_TABLE(24, 2, tcon1_table), .common = { .reg = 0x11c, @@ -549,6 +550,7 @@ static struct ccu_div tcon1_clk = { tcon1_parents, &ccu_div_ops, CLK_SET_RATE_PARENT), + .features = CCU_FEATURE_CLOSEST_RATE, }, }; @@ -580,8 +582,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); @@ -593,9 +595,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);