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: 13299381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FB34EB64D9 for ; Sun, 2 Jul 2023 17:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229932AbjGBRz6 (ORCPT ); Sun, 2 Jul 2023 13:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbjGBRz4 (ORCPT ); Sun, 2 Jul 2023 13:55:56 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5008DE69; Sun, 2 Jul 2023 10:55:49 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org In case the CLK_SET_RATE_PARENT flag is set, consider using a different parent rate when determining a new rate. To find the best match for the requested rate, perform the following steps for each NKM combination: - calculate the optimal parent rate, - find the best parent rate that the parent clock actually supports - use that parent rate to calculate the effective rate. In case the clk does not support setting the parent rate, use the same algorithm as before. 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: 13299382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8808EB64DD for ; Sun, 2 Jul 2023 17:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229887AbjGBRz7 (ORCPT ); Sun, 2 Jul 2023 13:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjGBRz5 (ORCPT ); Sun, 2 Jul 2023 13:55:57 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E924EE5F; Sun, 2 Jul 2023 10:55:50 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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: 13299383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0753C0015E for ; Sun, 2 Jul 2023 17:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229922AbjGBR4A (ORCPT ); Sun, 2 Jul 2023 13:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229914AbjGBRz6 (ORCPT ); Sun, 2 Jul 2023 13:55:58 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F5E2E5C; Sun, 2 Jul 2023 10:55:52 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org The default behaviour of clocks in the sunxi-ng driver is to select a clock rate that is closest to but less than the requested rate. Add the CCU_FEATURE_CLOSEST_RATE flag, which can be used to allow clocks to find the closest rate instead. 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: 13299384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F5A7C001B1 for ; Sun, 2 Jul 2023 17:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229984AbjGBR4A (ORCPT ); Sun, 2 Jul 2023 13:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229928AbjGBRz6 (ORCPT ); Sun, 2 Jul 2023 13:55:58 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D47E60; Sun, 2 Jul 2023 10:55:54 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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: 13299385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03404EB64DD for ; Sun, 2 Jul 2023 17:56:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229950AbjGBR4B (ORCPT ); Sun, 2 Jul 2023 13:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229947AbjGBRz6 (ORCPT ); Sun, 2 Jul 2023 13:55:58 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2650E61; Sun, 2 Jul 2023 10:55:55 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org When finding the best rate for a NKM clock, consider rates that are higher than the requested rate, if the CCU_FEATURE_CLOSEST_RATE flag is set. 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: 13299386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48816C0015E for ; Sun, 2 Jul 2023 17:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229995AbjGBR4C (ORCPT ); Sun, 2 Jul 2023 13:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbjGBRz7 (ORCPT ); Sun, 2 Jul 2023 13:55:59 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1878DE67; Sun, 2 Jul 2023 10:55:57 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.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: 13299387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3842EB64D9 for ; Sun, 2 Jul 2023 17:56:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230032AbjGBR4E (ORCPT ); Sun, 2 Jul 2023 13:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjGBRz7 (ORCPT ); Sun, 2 Jul 2023 13:55:59 -0400 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B43DDE5F; Sun, 2 Jul 2023 10:55:58 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Add initalization macros for divisor clocks with mux (SUNXI_CCU_M_WITH_MUX) to support finding the closest rate. This clock type requires the appropriate flags to be set in the .common structure (for the mux part of the clock) and the .div part. 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: 13299388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC6A6EB64D9 for ; Sun, 2 Jul 2023 17:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjGBR4L (ORCPT ); Sun, 2 Jul 2023 13:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229949AbjGBR4B (ORCPT ); Sun, 2 Jul 2023 13:56:01 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050:0:465::102]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BE96E67; Sun, 2 Jul 2023 10:56:00 -0700 (PDT) Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 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 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Selecting the closest rate for pll-video0 instead of the closest rate that is less than the requested rate has no downside for this clock, while allowing for selecting a more suitable rate, e.g. for the connected panels. Furthermore, the algorithm that sets an NKM clock's parent benefits from the closest rate. Without it, the NKM clock's rate might drift away from the requested rate in the multiple successive calls to ccu_nkm_determine_rate that the clk framework performs when setting a clock rate. Therefore, configure pll-video0 and, in consequence, all of its descendents to select the closest rate. 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);