From patchwork Mon Jul 17 13:34: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: 13315788 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 7C9B6C0015E for ; Mon, 17 Jul 2023 13:34:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229967AbjGQNeq (ORCPT ); Mon, 17 Jul 2023 09:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230150AbjGQNeq (ORCPT ); Mon, 17 Jul 2023 09:34:46 -0400 Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B229D1; Mon, 17 Jul 2023 06:34:45 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4R4NNd5Wr3z9sSZ; Mon, 17 Jul 2023 15:34:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600881; 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=Rv0VQb3dID9vli2KRI1IVx8tJ5Pn4HiXMxnfk/v2f54=; b=UdgMZcFQiZNijaJ818yBZITHgNgs7jk9u/yxUH2p4p6zjpy2lMPdZjGYvH9tuo3JL0PLyz AIwcmeJV8YtIavkbsDo/ckUIrUBBzd5udR1J11SCpqLUOJtik7xrFrTpRX9dwvBsnNSe3g IdpuM2ckCPnexhIs3KkTRs3AE5AL7jzwxZAGJrRNUZFD1U3PZ/0fl2LnrsotXLlOQad++p /chQPeBFUr53hjGSl/j9+rgn4B9G1e3x9ZCrICpVBAEnTmKwdSr+PO9u5Ugg89LkWA6eBE sinCM2G5EFfOG+kcq8mNPkQPLKdrv2SC8SFHUZRWS0oy5yuHekvB2S6f1YaRHw== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:25 +0200 Subject: [PATCH v4 01/11] clk: sunxi-ng: nkm: Use correct parameter name for parent HW MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-1-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=891; i=frank@oltmanns.dev; h=from:subject:message-id; bh=uK7iF9etz2opMttdEsAttxwMIOMUY7i/XdBlUa+elf0=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNmFQCKCWHtrI124RzW8kgbzVigb3cH+d6IZ XD6/S3ICBiJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZgAKCRCaaaIIlErT x9QAC/9fRFd5dETwAqOSVpi+ipUDaYRB+lzuhAfAdqmX2FjcTnTuSiBAgk/WAkANzhgLAoMTfeO DxJmc/G4V6gSd+X9mDNjwbdNh1HCxHYXAkqz3RwwEYSRl7bH+29uQyEeNd+A7vLlRs64ODpR7ok xwn8O0HYE45jPYYh6jjcE9/rlujiqY1AbxvRfVprQoB6JHpzFwmQe1ukoeUDMXTUw2S9S1UEetr IsGGuPOetODJP6mqbtcdhU9xCmjqmiJsUWw58Wz/5QqZw6tpA2LQcHY9bsLOB4zGuGDgx4olfY2 pZ1vGNja0LpukouUr4c6/SIDd4r6wEAE0rktWi3lp4MyjlV0cEyOOVhiCgd+YfiX6z9bbppnYEg JMv4x1VVGQoBnOfOMYQ098WX9yaUrBxAydC7e151XRkQeHpcMhdMg4FXskfVfsLahVPSdc/Pgsq GTKa4K3rjMAe1Yor8IegTjJTS9pF2lL5pyHJVQSEYaROVqEh25+iWYDfbflmqJrUY26Xk= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org ccu_nkm_round_rate() takes a clk_hw as parameter "hw". Since "hw" is the nkm clock's parent clk_hw, not the clk_hw of the nkm clock itself, change the parameter name to "parent_hw" to make it more clear what we're dealing with. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_nkm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index a0978a50edae..f267142e58b3 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -106,7 +106,7 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_hw *hw, } static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, - struct clk_hw *hw, + struct clk_hw *parent_hw, unsigned long *parent_rate, unsigned long rate, void *data) From patchwork Mon Jul 17 13:34: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: 13315790 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 ED313C0015E for ; Mon, 17 Jul 2023 13:34:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbjGQNev (ORCPT ); Mon, 17 Jul 2023 09:34:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230306AbjGQNet (ORCPT ); Mon, 17 Jul 2023 09:34:49 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CF56D1; Mon, 17 Jul 2023 06:34:47 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4R4NNh29vnz9spM; Mon, 17 Jul 2023 15:34:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600884; 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=cPWCHbaMIzPJhoorxt9HLF+kv4sZYegCcJXZOrRKrWE=; b=04fVJiZMhngVED/Pi8lx6h0xC5TrS3ghl8MRos+jdHoBkK4RYfzP+J7Z3OzHd+aTdwVxxj TZnQgTeq2fhVSyD8uphoqt4xtiCV2Is69RvL7XuoGpFqmF6FJt/esQ+5voG76rhwM1je8F 52geNyGydIyifzJPVt765+jB4rrtvB/RdY8d1UQgI1Up21ClXHyy0wRLuswKdklq2yrF16 1AoLcnxN5Y1Cp1xdQVL9CK4/cXzieSO/y2h2YQLEaQg/Riug5gIjL4Yuh5gpu/2VqlNGAA gHAoRWsUXDTdGIx6pRXpuW/NGyY6ph+lOA+s7mPQsGdMBlNYf3BqiZWsqdZ6sQ== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:26 +0200 Subject: [PATCH v4 02/11] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-2-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=2786; i=frank@oltmanns.dev; h=from:subject:message-id; bh=ln8ewZB8HSlEkTwEPnYVk2xiK3z7aFrdhE31L9k7BeE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNmBiTRyNBUXsoPkUobN7y+D/M84n6Ihezx/ KIsuAQwbISJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZgAKCRCaaaIIlErT x8mfC/4xmWR7TpNRcNtu6On+oaAp0H/+K7AOZP1gdw1xLCJOXl9mGeYL7ljQLqfh8WF9eRo+6jn Tyo9Q3fpCcorU9J8yx75k+xqfWqL6SY7mnZhCBLOrhCypR1P4eaVkYMBwYaSHr/TDPBaIJT+u9H IXWYrd+KcYzTi17mp/d5zq1BhhOEjtE5GXSd/NQwYsT2KY13aR8crSiLulzaF9a91AGKfJSHY8l ajeMK7Ey5yjGWPwHQ/QIqeClx1wiIaqUi4svjaq6RhwhwhSJCTiFV2eBPFyBe/9QUXyA3h7qLPQ 7cNdnijiR7KbMJHsGulPj/YbJtQaCLVZDyBv+GtVqxwupZ46KfJMaAE3IbmS5TAGnqWjgXbFNOT Ird7Nyy6Pno14Tyw13oi/3evBs/Z0Sv7qjrmRZO+okjE0sBG255Pzxq6204gK8j7XNOiI8379HO Jisb/I+ujmzOjXx0XsIJQLr0gY0xVeCg0J6JrlNp/ROiV25ZweDOoaSwdg0gWhF4i9Zws= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 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 Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_nkm.c | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index f267142e58b3..750e2b8da24b 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(struct clk_hw *phw, struct _ccu_nkm *nkm, + unsigned long *parent, unsigned long rate) +{ + 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) { @@ -124,7 +163,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate *= nkm->fixed_post_div; - rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) + rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + else + rate = ccu_nkm_find_best_with_parent_adj(parent_hw, &_nkm, parent_rate, rate); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; From patchwork Mon Jul 17 13:34: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: 13315791 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 475FAC0015E for ; Mon, 17 Jul 2023 13:35:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231423AbjGQNfA (ORCPT ); Mon, 17 Jul 2023 09:35:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjGQNe6 (ORCPT ); Mon, 17 Jul 2023 09:34: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 4DAFB103; Mon, 17 Jul 2023 06:34:49 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4R4NNk0BPCz9sqj; Mon, 17 Jul 2023 15:34:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600886; 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=mxSpbKadXwGFFmICM4KCVhlYhVMAa5nTGvXXvvCR/6c=; b=C8pe7OXk8RmslfUhyHWhNO1IAtnp2revBFmvlWYWs4pPEwjPuzxgx4oGVOm/nj+6w3TjzE /byQuUXA3cFygxHe6MO7QXpb6p+rP1xlv8EDye4yJ5GSrKwhSin4zrB6or+fQKoDzrdSDd B70RVo2tyg+/NHo/rVYnUi8xgOHpMj03QzG8Z5J7fN0XHE8rgQczeMQsKRFmYPqEFLBUde 8OOogZnIznjMwQjqkNBYU+UJUkcCPd9FLtbICDR1lPnRHsSFepaZS6fY4kAVYC7Wz+bXke hbMNcyY/kM66phckmFXXIwlgojxvAq2nNFtDqxu95dnComl3b7wyFAZRILDXqQ== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:27 +0200 Subject: [PATCH v4 03/11] clk: sunxi-ng: nkm: Improve determine rate when setting parent MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-3-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=3162; i=frank@oltmanns.dev; h=from:subject:message-id; bh=ybYcatfzXzLhtH3Us9O9aTKgAbrOK5YclAuVqdRWKwM=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNnbBuKGKMOIVIPQcqh33VQB7vClVkKoHIDR onfsZc+Gk6JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT xyBjC/9k/2f+UphH0jsSxuPMHBPNOkwewxe5ctT/T+mDGggMT8aTLtvJTrBkOE/+QkBYPZYwzVn PjJh/JJLKKxSno6MIYixIr1m5N5sEiN2IdnbXcQ7FldjLxmXSFkuIBPft4rMCefIorle4AWmRkt 4j2hyOjn5oevtUQ+/+XyixdE4kdu8/cXW24bxdu5zNWkA33EkFL1qNHrmCImPOqv1r28nhZmGuN uSO7XCCclDwDLJ23OrGCKXl7WCFFTkiFhHjplSOEChoYDQGwO+flDmtjpJ67CZe21pV/ZcglEES Tria8vZKA737utAYpVjz8oXp/SmzcaZ6MQMTyXAepfwRaL/Ndq2ON5rjS94/mlFxyV8SNYv0kld k33OMm1FSdXXIP2MIpKSiC0+bJSQ2JN8Mi/JaLzlHxUjRgQtrpj75TI+V+pbC+OH0x/S3yAoPDc pTzVNaX5rs05gNeQ46W2fMz7KWwGutatxTlDXuDPrqD11nUmIuthZ24Zfk00qH4+qrkm0= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4R4NNk0BPCz9sqj Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Make the SET_PARENT_RATE flag independent of the parents round_rate or determine_rate implementation. Currently, the algorithm for ccu_nkm_find_best_with_parent_adj simply calculates the optimal parent rate as (1) parent = rate * m / (n * k) Due to integer division (1) might return a parent rate that is too low. So using this value for asking the parent for a rate it supports via clk_hw_round_rate causes problems on a) parents that only support finding rates that are lower than the requested rate - which is the default for sunxi-ng ccu's. b) parents that incidentally also support the truncated rate. In those cases ccu_nkm_determine_rate might return A' when A is requested and A'' when rate A' is requested. Prevent this by trying to find a parent rate so that (2) _rate = parent * n * k / m matches the requested rate exactly, if possible. Background: =========== determine_rate may be called multiple times by the clk framework when setting a clock's rate. But the clk framework expects that the values determine_rate returns (i.e. the rate and parent_rate) are consistent with previous calls. Specifically, clock's have to ensure that if determine_rate is called with requested rate A and the best rate it can find is A', it must also return A' when called with requested rate A'. Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_nkm.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index 750e2b8da24b..793160bc2d47 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -17,6 +17,27 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; +/* + * Calculate the optimal parent when determining the nkm clock's rate. + * + * This function is used when the nkm clock supports setting the parent rate and ensures that the + * determine_rate function returns consistent values. I.e., when determine rate is called for rate A + * and the best rate it can find is A', this function ensures that determine_rate will also return + * A' when A' is requested. + */ +static unsigned long ccu_nkm_optimal_parent_rate(unsigned long rate, unsigned long n, + unsigned long k, unsigned long m) +{ + unsigned long _rate, parent; + + parent = DIV_ROUND_UP(rate * m, n * k); + + _rate = parent * n * k / m; + if (_rate > rate) + parent = rate * m / (n * k); + return parent; +} + static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *phw, struct _ccu_nkm *nkm, unsigned long *parent, unsigned long rate) { @@ -29,7 +50,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *phw, struc 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_parent = ccu_nkm_optimal_parent_rate(rate, _n, _k, _m); + tmp_parent = clk_hw_round_rate(phw, tmp_parent); tmp_rate = tmp_parent * _n * _k / _m; if (tmp_rate > rate) From patchwork Mon Jul 17 13:34:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315792 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 77D40EB64DC for ; Mon, 17 Jul 2023 13:35:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbjGQNfB (ORCPT ); Mon, 17 Jul 2023 09:35:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230464AbjGQNe6 (ORCPT ); Mon, 17 Jul 2023 09:34: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 E3505131; Mon, 17 Jul 2023 06:34:50 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4R4NNl62XSz9sTm; Mon, 17 Jul 2023 15:34:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9/AP7UiU8qhdUXkhdNLxJOtFL/gExqBQUGjN0bV4ALI=; b=p/8X/pMDRn3VDPLMa9zLgWy+rJIex7YxNUplJXmFOQs6YGNqZ8+77rYfoLWuXmFTTOf7ju ppV5CGi8C4+BplaaYXXwPDf6ycWJ+j/hK0gyZ/5wSxA0SOQ+kz7dJI5gcJgewmCNnzzSVU ld/OkigUvNfkqojRM7wHBT3tc2g1oGDSeBpple/Dx/hiVnsWR7I+aK8i0RCnVC81lKooSN huhnH281gRXYrX9zpLlP/HQCjAIJ77IjDVI/K9yI0n5D6sK394ihjlYMcPuBYhmPSU+aHt DTqWEV8AlihINbJ27qrfjiXX9yu5b5WRSiMWMA+JpqNSy+lP2mjh3v7d8NkULQ== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:28 +0200 Subject: [PATCH v4 04/11] clk: sunxi-ng: a64: allow pll-mipi to set parent's rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-4-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=852; i=frank@oltmanns.dev; h=from:subject:message-id; bh=MYgMUXDylKq1ueF0/z4NSPOcrbzoRllAat6F65tgrPA=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNnxvQm4kVTKSzVBGDfgQtD8lSHZzj2+2z1W HNjRC5aMdOJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT x5o8C/9q96AvAhFPEi/8WLlv4yDjFChHVlw6zt991yUMF2Aq4UtVoMQdqNXVWyAUBGXkvOaoc+8 xeIe582TfsjmepFqB1beJG2HyX4AVYpKb4cG8oh7wjgzVYBJWNXbCYc1q7FRSfUmpiiO9Oc3KHh 2Ixd5hknOEwibM/9LJr67U0hTyAEJsi6W+e0SsyMybKw1xxMvx6WwvN2F6P+g08Vp8CW5QSgzUN j5LZafiUP+uEyVxgknLdGilQJ4nSwv6COsrqg/n6tfktXUeklQX3+kR0h+qT1Dkb23dwbc1EdxD CNkONrQZG4S7S5kj/AqrahT6YCFg+/FMNiZfE1NzyOvErvHqd6dJcVg0jyuWQZlncGnXsm+1qnV yrLIVO7A6O4e38svoOrJ+U246MjJgcR1O26CtaFQGaE1lNi+7qiCg2pe+xzL6Fe5MG5mKbsrv4s SLvEjCD8jdxlpdUNXOuAUq0f6wPJ0fl24fZ3mBR2afhmjYBZEdhu58TGzwW5YDgjHSCdo= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 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. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index 41519185600a..a139a5c438d4 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -179,7 +179,8 @@ static struct ccu_nkm pll_mipi_clk = { .common = { .reg = 0x040, .hw.init = CLK_HW_INIT("pll-mipi", "pll-video0", - &ccu_nkm_ops, CLK_SET_RATE_UNGATE), + &ccu_nkm_ops, + CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT), }, }; From patchwork Mon Jul 17 13:34:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315793 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 ABC49C0015E for ; Mon, 17 Jul 2023 13:35:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231345AbjGQNfF (ORCPT ); Mon, 17 Jul 2023 09:35:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231387AbjGQNfA (ORCPT ); Mon, 17 Jul 2023 09:35:00 -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 BE5AE198; Mon, 17 Jul 2023 06:34:52 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4R4NNn2wXfz9scd; Mon, 17 Jul 2023 15:34:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600889; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9mBnj/sxnS9zwU8wD2TdC9KZuObHfj2Iut9ShLW7rE4=; b=P4IYBLXpzSKDpQDC3y/8eQEb7xIwNG2KeqYk9uYFHqXJh+SvwkbfijIZOWTyq9ScLuLh3t o5xviA0TEGMhMCOWCdOszeUF8aSM3UJbub59652i3lt0+Z3ZBWO8hNqLBs6b23oi7awO78 QrEa2gpkhWFeXbp79PcSYhZvAGuo7OEv4nbjMtzXB+QyhUuzAjKlAw2N2E2rAmGLQVhURo rmuS65BPDo5/b0uqaXRVXzvHs9m4XQRfsll0LunNKgYXGrBfy65rz14MZtAFwPbrnhYaZa NBn+tMDFWOw8cTuhcciq8pqy5laq7dH7ozr/CLuFpClYY7eTl97GflWoNWpT0g== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:29 +0200 Subject: [PATCH v4 05/11] clk: sunxi-ng: Add feature to find closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-5-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=925; i=frank@oltmanns.dev; h=from:subject:message-id; bh=gnSO2u9KSds+yso2ENUmK1fTBfjNRGShsPD5HpXqe+0=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNnQaE7W76TYcfxfYnWsd1bG/r3SzYlXk8Rx EmA2MoX7ZmJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT x492C/96NNmsav+tjwb4ER/kGeVV0NdFdh7BNDSmd/fCpHM4z0947Pi/8UHRgMHz+7i5n/xydyk oeKOFIEFZTCvA6MbQS7vcuS3szA4u72eOREafKEpwCLZRq6Tns0R2Z4r8lAuFZIs8bHf2QR86GB zy0yk0exP77FgUh3DycvDSpz/a0nuQZbzeqAjpPiVwre4TO0Bsez/lWMVGF5ZcnNSkA8KosGdsv mSSWmoYNU1YxO22J+r/Pg3HWIPW4k1TiQkOLTmK8Xcd7Nw67uGDQDpWLBxTC2t5sM+rCupVcwVf foXD7h21UYidnpg0wCaOc00SnWDTTxZzt9Kpewun2mYlfaP+dxmzqdG4QR2+qiwIgnoin3DDuYV avd/LnyHh1w7v3pkqXOSw4NjSoBzmpx3a1tm088tY9qsDf6JIAxH2CxsRFYu8NF+SXSQtWxwEtZ tGFLjGS0ANDgnLFddEki3/pMZqaDgig7bC+BgWgd+OyYJqGveWqPjK1Gs/mGAS1ne3RcE= 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. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_common.h index fbf16c6b896d..5ad219f041d5 100644 --- a/drivers/clk/sunxi-ng/ccu_common.h +++ b/drivers/clk/sunxi-ng/ccu_common.h @@ -18,6 +18,7 @@ #define CCU_FEATURE_MMC_TIMING_SWITCH BIT(6) #define CCU_FEATURE_SIGMA_DELTA_MOD BIT(7) #define CCU_FEATURE_KEY_FIELD BIT(8) +#define CCU_FEATURE_CLOSEST_RATE BIT(9) /* MMC timing mode switch bit */ #define CCU_MMC_NEW_TIMING_MODE BIT(30) From patchwork Mon Jul 17 13:34:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315794 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 8246AC0015E for ; Mon, 17 Jul 2023 13:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231796AbjGQNfP (ORCPT ); Mon, 17 Jul 2023 09:35:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231250AbjGQNfA (ORCPT ); Mon, 17 Jul 2023 09:35:00 -0400 Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D544D10D3; Mon, 17 Jul 2023 06:34:54 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4R4NNq5hHTz9spg; Mon, 17 Jul 2023 15:34:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600891; 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=AjFCY3HxW03cxoBZRPjTS+r4+YQ2i2FxYxF8BGQxqRs=; b=lqCftgPBqtnXs2n/n2lMayHb6woREijxYVm13HsND8SB3l1Y4qJ3Eq2HaxC5UQl2wJI/zT SJYJOeNEJ3sZjvPpvvqgdSrDEf7sbCdkq8imafn1yK+5vNAJ6lRrTxSkwcfxHaLs0d2d0u 9lGPRqatT+/5C3Ohr4zDKQgmREJg4X6VyyvP84ZU2oi8UI6i6v5MrssVtx5c3QLeK640T5 2j7i5f3K+w7DqDF54sUKk3B+2yz33CIFscESXSSPJz1mOFmqnJbJR9pFMA1thyYW5l/7Dj d7jT6xlIuVE6RDzslQzbkvU3EUKlVVYRiKHHkW0F3/c3i18jWqINHDvROfc3WA== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:30 +0200 Subject: [PATCH v4 06/11] clk: sunxi-ng: Add helper function to find closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-6-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=2008; i=frank@oltmanns.dev; h=from:subject:message-id; bh=HKQcQnjj5qfhxp0P09j7Gl6Mbxsh+yyoCxFM8Ft7zNM=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNnkE00hapfor0wr5bj5Dtq+dTlwCnMQOK+s ELOrs3x6XGJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT x2vPC/kB7w335bl9VHEBhhj2h+GQE8Tm+AEihJihO2JcP4vuBCX41g6ajVERRGp1AMsz/Q8Idlc zvXhmXWirHKdPNCLdBmuslbWZX2+PThnhwbTJhL6NfBB4bIm8l83IP2Wp1BIveLifnTiBqmHDtW Z4nWmHk695LPheIVjswfEznK1PVLV1NsRXPWBz1pUh7Ngfg6RRUw5VN17xB9t9+xsE41AJrd2hl nQibASXTfi1QKJdfYQ8NrW8xF2f0MbhcWoUGBJqZgvvWrZXsvtIHN/WE5/jea1rtz2ScD5f/qMi bQtMGxx96Qi3taoix4PZ4BX6+rCfAxPfYxFLMVOW8nBQyRiQ9hdETRG0hB6ZkSKpi2sR6rgOp1V 0qsimH7eQI5ruaXd4RgUl2lqASGNSr7x62dCvhjVVsqVc2ZBQ8jkQRY2q8hz/5girb1zv9yOvn0 dKeldput9qZJv2iOg2lJdSTTUP8rHTElyNGsfr8xBGTUh9z1dOdRNXnteDPSFRn41RJE4= 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_is_better_rate() helper function that - depending on the fact if thc CCU_FEATURE_CLOSEST_RATE flag is set - decides if a rate is closer than another rate. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_common.c | 12 ++++++++++++ drivers/clk/sunxi-ng/ccu_common.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c index 8d28a7a079d0..8babce55302f 100644 --- a/drivers/clk/sunxi-ng/ccu_common.c +++ b/drivers/clk/sunxi-ng/ccu_common.c @@ -39,6 +39,18 @@ void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock) } EXPORT_SYMBOL_NS_GPL(ccu_helper_wait_for_lock, SUNXI_CCU); +bool ccu_is_better_rate(struct ccu_common *common, + unsigned long target_rate, + unsigned long current_rate, + unsigned long best_rate) +{ + if (common->features & CCU_FEATURE_CLOSEST_RATE) + return abs(current_rate - target_rate) < abs(best_rate - target_rate); + + return current_rate <= target_rate && current_rate > best_rate; +} +EXPORT_SYMBOL_NS_GPL(ccu_is_better_rate, SUNXI_CCU); + /* * This clock notifier is called when the frequency of a PLL clock is * changed. In common PLL designs, changes to the dividers take effect diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_common.h index 5ad219f041d5..942a72c09437 100644 --- a/drivers/clk/sunxi-ng/ccu_common.h +++ b/drivers/clk/sunxi-ng/ccu_common.h @@ -53,6 +53,11 @@ struct sunxi_ccu_desc { void ccu_helper_wait_for_lock(struct ccu_common *common, u32 lock); +bool ccu_is_better_rate(struct ccu_common *common, + unsigned long target_rate, + unsigned long current_rate, + unsigned long best_rate); + struct ccu_pll_nb { struct notifier_block clk_nb; struct ccu_common *common; From patchwork Mon Jul 17 13:34:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315795 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 10D63EB64DC for ; Mon, 17 Jul 2023 13:35:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231863AbjGQNfS (ORCPT ); Mon, 17 Jul 2023 09:35:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231580AbjGQNfB (ORCPT ); Mon, 17 Jul 2023 09:35:01 -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 D455210FA; Mon, 17 Jul 2023 06:34:56 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4R4NNs3xktz9sn0; Mon, 17 Jul 2023 15:34:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600893; 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=VLlZ20gT3AYBxK1XNMqqr6vr/q9ctYDYjWAuz89wTeI=; b=FauePXE2BeyhtMEhZ8a/oZikKUJ9mLjJOdTlEybsRzYiibAYAvL0UkdQgEDB62QAPflBvs wbS91bJHsZHzcrF2zrEDrMkOylTmTWrgujlqfPIHjzXJsOuMnMnRjxLqUwyko+2f6H0J0N QAqFxM+PXBfMyqimi/pr6sWpZmXr59XesOF+O9/hr8Y5Wxv3+BqD2yPIhrt0ogryZaxWXy KDYf7stY0+c7q6V8VqNTwBX2vM8bTUczPvS/JyIgmuLMSf0cbUlk/MdYfmy26rDVVqMnoL 3Uwt48aYlMmG2GxQDMqcjLHWgipbPEHdOzAwHpEdx5v4z5L0LmBhWY+ITyACGg== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:31 +0200 Subject: [PATCH v4 07/11] clk: sunxi-ng: nm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-7-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=5089; i=frank@oltmanns.dev; h=from:subject:message-id; bh=NepBBc4l97PvUGu6ZIRJp/OdImGWyPyBUbamE+1jv1o=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNn9Y3lBf5N2ajTepXKLJ+mjiTtVwbQxpO2O aboO54rn+SJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT xxbXDACKhryJmCyCo+ZOit2eroVXh9w6WrCLSafRUolxDHQJP2mlATGDQeDT4QH1AGD2NC5XHpk a10nSqVFEuMZQY5xzkvnXxA3vebDr8M6P/F8LH+K1p7ip3WiVcoqGSnD5lueKlr2AFvMhofLHyo QW+MMYUuHGD5CQK0TRcmmpTLRs7RSgxp1dC1gNqo4fGxW6KXNwI7RdlLM1hFp57aDhybhjMG8Yp J8wnh+usI7hbFbuHZMFo/m+2HbbTj/UioyWuQRELXTuzmFO+hwvn7YPyCG3a70tCWw6oMlQkcCl GzSlEIMWH+4j49a0Ipdke/5TZs10eU3x9gWgc096u0SpZH5Ez/qVaLhZyNFlP/zKwfxPF1Wmi6O SGGa+KOjAgx/kctVOccga2SylFEjmBZnmxUuLdpbwbEBDoPBgl6UpuIXEzR3i1cgorEosVhKuqV mPs0yWLHUUIFqVe6+cLoH5OoxwjEgRxVD/bZpWigvBsRxqQDsVs7sAp25hb3O1FK26Lqs= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4R4NNs3xktz9sn0 Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org Use the helper function ccu_is_better_rate() to determine the rate that is closest to the requested rate, thereby supporting rates that are higher than the requested rate if the clock uses the CCU_FEATURE_CLOSEST_RATE. Add the macro SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST which sets CCU_FEATURE_CLOSEST_RATE. To avoid code duplication, add the macros SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT that allows selecting arbitrary features and use it in the original SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX as well as the newly introduced SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST macros. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_nm.c | 11 ++++------ drivers/clk/sunxi-ng/ccu_nm.h | 48 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c index c1fd11542c45..35d00783d748 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.c +++ b/drivers/clk/sunxi-ng/ccu_nm.c @@ -28,7 +28,7 @@ static unsigned long ccu_nm_calc_rate(unsigned long parent, } static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate, - struct _ccu_nm *nm) + struct _ccu_nm *nm, struct ccu_common *common) { unsigned long best_rate = 0; unsigned long best_n = 0, best_m = 0; @@ -39,10 +39,7 @@ static unsigned long ccu_nm_find_best(unsigned long parent, unsigned long rate, unsigned long tmp_rate = ccu_nm_calc_rate(parent, _n, _m); - if (tmp_rate > rate) - continue; - - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate = tmp_rate; best_n = _n; best_m = _m; @@ -159,7 +156,7 @@ static long ccu_nm_round_rate(struct clk_hw *hw, unsigned long rate, _nm.min_m = 1; _nm.max_m = nm->m.max ?: 1 << nm->m.width; - rate = ccu_nm_find_best(*parent_rate, rate, &_nm); + rate = ccu_nm_find_best(*parent_rate, rate, &_nm, &nm->common); if (nm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nm->fixed_post_div; @@ -210,7 +207,7 @@ static int ccu_nm_set_rate(struct clk_hw *hw, unsigned long rate, &_nm.m, &_nm.n); } else { ccu_sdm_helper_disable(&nm->common, &nm->sdm); - ccu_nm_find_best(parent_rate, rate, &_nm); + ccu_nm_find_best(parent_rate, rate, &_nm, &nm->common); } spin_lock_irqsave(nm->common.lock, flags); diff --git a/drivers/clk/sunxi-ng/ccu_nm.h b/drivers/clk/sunxi-ng/ccu_nm.h index 2904e67f05a8..93c11693574f 100644 --- a/drivers/clk/sunxi-ng/ccu_nm.h +++ b/drivers/clk/sunxi-ng/ccu_nm.h @@ -108,7 +108,7 @@ struct ccu_nm { }, \ } -#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ _parent, _reg, \ _min_rate, _max_rate, \ _nshift, _nwidth, \ @@ -116,7 +116,8 @@ struct ccu_nm { _frac_en, _frac_sel, \ _frac_rate_0, \ _frac_rate_1, \ - _gate, _lock, _flags) \ + _gate, _lock, _flags, \ + _features) \ struct ccu_nm _struct = { \ .enable = _gate, \ .lock = _lock, \ @@ -129,7 +130,7 @@ struct ccu_nm { .max_rate = _max_rate, \ .common = { \ .reg = _reg, \ - .features = CCU_FEATURE_FRACTIONAL, \ + .features = _features, \ .hw.init = CLK_HW_INIT(_name, \ _parent, \ &ccu_nm_ops, \ @@ -137,6 +138,47 @@ struct ccu_nm { }, \ } +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags) \ + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags, \ + CCU_FEATURE_FRACTIONAL) + +#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags) \ + SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \ + _parent, _reg, \ + _min_rate, _max_rate, \ + _nshift, _nwidth, \ + _mshift, _mwidth, \ + _frac_en, _frac_sel, \ + _frac_rate_0, \ + _frac_rate_1, \ + _gate, _lock, _flags, \ + CCU_FEATURE_FRACTIONAL |\ + CCU_FEATURE_CLOSEST_RATE) + #define SUNXI_CCU_NM_WITH_GATE_LOCK(_struct, _name, _parent, _reg, \ _nshift, _nwidth, \ _mshift, _mwidth, \ From patchwork Mon Jul 17 13:34:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315796 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 CD3DFEB64DC for ; Mon, 17 Jul 2023 13:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231778AbjGQNfa (ORCPT ); Mon, 17 Jul 2023 09:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231787AbjGQNfP (ORCPT ); Mon, 17 Jul 2023 09:35:15 -0400 Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDFEB1980; Mon, 17 Jul 2023 06:34:59 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4R4NNw3Svtz9sXk; Mon, 17 Jul 2023 15:34:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600896; 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=rlTJuOBcXldwNheInskRcuqMdDaXa3wlYPUBaUVJITM=; b=k3Izz2QDMb4ZkG7IdiVrxI4xiC2CYmFKBAPQsC9m8jqjf3xoziGkIDTMs6Yv1jKAVxTW7c nxWUALor4jJ3y+1Zht/k8H7RaK8CHGpZlnfXW39dK1ak0pIiTpLOClXSyrLq3oiNp+i54a qCeCRH/t4RBpvrpo1GAsg+M0Pnd5kDXN+S8PcQY1W85RWtkHa3810Y0JWzctpE7A+l3dML EYqJWgUYsXi+QJMijoa91VI/cBFrb69m+kaRGajxhE2YvCGqHg1mvZ0uh89UDpfBdiVsDJ BJId1g7oXD8lp9Gkr3ZnlC5eb3fx0mkUYAHHHVXpRCr/QxlDwQYEHAXOmxWM0g== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:32 +0200 Subject: [PATCH v4 08/11] clk: sunxi-ng: nkm: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-8-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=3726; i=frank@oltmanns.dev; h=from:subject:message-id; bh=QflG05ovfcYkdKjU+vIi9ERE1oD6pVxvlipjsNU5BvM=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNn4hmkcdxGSrDuWuDUm1o7lKzVeUSIiR/VN 5cUaRPKDoCJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDZwAKCRCaaaIIlErT x8EdC/wMKH2lWa2XhH6vFrr4FfyZCnlE9m584JJSfG2UVEaRUIzh7hLvIUC68KvBShSyFtZuX60 8+eq7o5e4wQh+j6J5W5yxD4t0XDxBhxBvUfqjifbm92vVi119LVinHbZ6cYOApuARW+MRqVJCGS v7E2aLzLCOfLXrbVZeQIuSGszrtZvw1dYul1GIGUyNjER0XAzHaJpF+0iQeTO0KvArCgQvXEPB6 VVczu+kl70h4jnv+gyxt/i28SkjhSzzYJ3HA8TEkGCB4iWnn7wx3WwFzQMIIHNfCrBU0vCgh9NH sRM4+V+yxXOgjd2AQTPxY9t5QETLVLqU7OTYi9+/IrFSPR+lNhvzX5Mc6+daIwExsIxRcHGoNX7 gDhe6LW4VBQKLfnV9VZ6G3GChdB6zVY27wPNg2kf5SDj/AcOxh0mLiUUD9tlPblR+lhxOjJfsqw rbvKLi5iqgg9gZ9QmVSYsFyLZuOHioFbFzexXZ62Zz2U/sBm2BIOwdLMjDtOgvhnJNcJ4= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4R4NNw3Svtz9sXk 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 by using the helper function ccu_is_better_rate(). Accommodate ccu_mux_helper_determine_rate to this change. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_mux.c | 2 +- drivers/clk/sunxi-ng/ccu_nkm.c | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 1d557e323169..3ca695439620 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -139,7 +139,7 @@ int ccu_mux_helper_determine_rate(struct ccu_common *common, goto out; } - if ((req->rate - tmp_rate) < (req->rate - best_rate)) { + if (ccu_is_better_rate(common, req->rate, tmp_rate, best_rate)) { best_rate = tmp_rate; best_parent_rate = parent_rate; best_parent = parent; diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index 793160bc2d47..5439b9351cd7 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -39,6 +39,7 @@ static unsigned long ccu_nkm_optimal_parent_rate(unsigned long rate, unsigned lo } static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *phw, struct _ccu_nkm *nkm, + struct ccu_common *common, unsigned long *parent, unsigned long rate) { unsigned long best_rate = 0, best_parent_rate = *parent, tmp_parent = *parent; @@ -54,10 +55,8 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *phw, struc tmp_parent = clk_hw_round_rate(phw, tmp_parent); tmp_rate = tmp_parent * _n * _k / _m; - if (tmp_rate > rate) - continue; - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate = tmp_rate; best_parent_rate = tmp_parent; best_n = _n; @@ -78,7 +77,7 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw *phw, struc } static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, - struct _ccu_nkm *nkm) + struct _ccu_nkm *nkm, struct ccu_common *common) { unsigned long best_rate = 0; unsigned long best_n = 0, best_k = 0, best_m = 0; @@ -91,9 +90,7 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, tmp_rate = parent * _n * _k / _m; - if (tmp_rate > rate) - continue; - if ((rate - tmp_rate) < (rate - best_rate)) { + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { best_rate = tmp_rate; best_n = _n; best_k = _k; @@ -186,9 +183,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, rate *= nkm->fixed_post_div; if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) - rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); + rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common); else - rate = ccu_nkm_find_best_with_parent_adj(parent_hw, &_nkm, parent_rate, rate); + rate = ccu_nkm_find_best_with_parent_adj(parent_hw, &_nkm, &nkm->common, + parent_rate, rate); if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) rate /= nkm->fixed_post_div; @@ -223,7 +221,7 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsigned long rate, _nkm.min_m = 1; _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; - ccu_nkm_find_best(parent_rate, rate, &_nkm); + ccu_nkm_find_best(parent_rate, rate, &_nkm, &nkm->common); spin_lock_irqsave(nkm->common.lock, flags); From patchwork Mon Jul 17 13:34:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315797 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 8EF7BEB64DC for ; Mon, 17 Jul 2023 13:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231490AbjGQNfi (ORCPT ); Mon, 17 Jul 2023 09:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231849AbjGQNfR (ORCPT ); Mon, 17 Jul 2023 09:35:17 -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 31EDD1989; Mon, 17 Jul 2023 06:35:02 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4R4NNy508Lz9smT; Mon, 17 Jul 2023 15:34:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600898; 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=0E2YxyVlvlZZLwdZIaLYPAboPPaw9Lb7xi7G+ICAFTw=; b=FyIcD/32deuQaum5goVHMwLDtKH7iTTNDwQs2ixSQ6wzkQrMz/XwePjexhMFIXXpqgcZ9Q dWIXIzFBl6cxpjSCYVLT1dPph2NwV41Cxw4A1QKCEj6l6I5pTtIqRuMbbDVwYlFwI9vabZ g/eERyKcbv+CxK0HXiihkyVB5RDcpjNrAntvyvEcL44S4vIZEv3p7H9hTWx5fProwTHcTZ ETczpQ2gLa6ExtLsbAVGBWqPPIaOmXhU0mf36VE8krmi2FlOJBp4k3MRQbWCFwLzUdZI2J efDeZ846y8em+9VTFGbftKteBWp4VPkzJbi5xnwl4u9d3x/8QNWOL1GBc+PGyA== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:33 +0200 Subject: [PATCH v4 09/11] clk: sunxi-ng: mux: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-9-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=3394; i=frank@oltmanns.dev; h=from:subject:message-id; bh=50b4yF0rWOhBsSCHTe8QISi0j6DZgAFg9IkJskDKbcA=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNoQCABQZ+UW9bcK8zqLkpe0sHTTdGyKRvGH KV3OkdhSymJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDaAAKCRCaaaIIlErT x6ZCC/4in/1eidqlsbszdf0V5rn0nsO6q7eGNli2d1qJr783q3LJtVh9W8djbZAHchX1ogIVCLN +/U4kit5eNCvhlO5G064PsjuR0o8utyETStzULBKBNH7/ILI17gpjAPP45qHOf0B+f0dcDclmbZ y875noRynh/q323kDDC7kpUjqrOKxO3KdA6J4rDK4Y0VIIkvnr2bzD8+erU2ds9H799eENL1px6 EIKb+IOPgQmxWaFtgBhCdgVcwNnYBChGdZZDTTcFjzw/v+CPAMLkd5Wfz9WFng/x5ecrLS9C9ls jXakCjbn15YBZAoVW8g1YSCUXy2JoVH36iYPhhuPWuKfgWs1iAEjkNlJdkWRNcpo6JhZjiyg64t in0XwwIOrO8r24Uhx7zqbBJw20WbXc2a5L+FEWT/Pt4Q6stAfIuxHw6BVBVx4c41/oDJC3vcyCZ yXl+hVJnTdXXPLHil7JtedPONFlEMz9kt0rI9TTurRYFrWNZvorKmYRgoKMdKC8qZP/NM= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4R4NNy508Lz9smT 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 when CCU_FEATURE_ROUND_CLOSEST is used. Furthermore, introduce an initialization macro that sets this flag. Signed-off-by: Frank Oltmanns Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu_mux.c | 13 ++++++++++++- drivers/clk/sunxi-ng/ccu_mux.h | 38 +++++++++++++++++++++++++++----------- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu_mux.c b/drivers/clk/sunxi-ng/ccu_mux.c index 3ca695439620..5edc63b46651 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.c +++ b/drivers/clk/sunxi-ng/ccu_mux.c @@ -242,6 +242,17 @@ static int ccu_mux_set_parent(struct clk_hw *hw, u8 index) return ccu_mux_helper_set_parent(&cm->common, &cm->mux, index); } +static int ccu_mux_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct ccu_mux *cm = hw_to_ccu_mux(hw); + + if (cm->common.features & CCU_FEATURE_CLOSEST_RATE) + return clk_mux_determine_rate_flags(hw, req, CLK_MUX_ROUND_CLOSEST); + + return clk_mux_determine_rate_flags(hw, req, 0); +} + static unsigned long ccu_mux_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -259,7 +270,7 @@ const struct clk_ops ccu_mux_ops = { .get_parent = ccu_mux_get_parent, .set_parent = ccu_mux_set_parent, - .determine_rate = __clk_mux_determine_rate, + .determine_rate = ccu_mux_determine_rate, .recalc_rate = ccu_mux_recalc_rate, }; EXPORT_SYMBOL_NS_GPL(ccu_mux_ops, SUNXI_CCU); diff --git a/drivers/clk/sunxi-ng/ccu_mux.h b/drivers/clk/sunxi-ng/ccu_mux.h index 2c1811a445b0..eb1172ebbd94 100644 --- a/drivers/clk/sunxi-ng/ccu_mux.h +++ b/drivers/clk/sunxi-ng/ccu_mux.h @@ -46,20 +46,36 @@ struct ccu_mux { struct ccu_common common; }; +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, _table, \ + _reg, _shift, _width, _gate, \ + _flags, _features) \ + struct ccu_mux _struct = { \ + .enable = _gate, \ + .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_mux_ops, \ + _flags), \ + .features = _features, \ + } \ + } + +#define SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags) \ + SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags, \ + CCU_FEATURE_CLOSEST_RATE) + #define SUNXI_CCU_MUX_TABLE_WITH_GATE(_struct, _name, _parents, _table, \ _reg, _shift, _width, _gate, \ _flags) \ - struct ccu_mux _struct = { \ - .enable = _gate, \ - .mux = _SUNXI_CCU_MUX_TABLE(_shift, _width, _table), \ - .common = { \ - .reg = _reg, \ - .hw.init = CLK_HW_INIT_PARENTS(_name, \ - _parents, \ - &ccu_mux_ops, \ - _flags), \ - } \ - } + SUNXI_CCU_MUX_TABLE_WITH_GATE_FEAT(_struct, _name, _parents, \ + _table, _reg, _shift, \ + _width, _gate, _flags, 0) #define SUNXI_CCU_MUX_WITH_GATE(_struct, _name, _parents, _reg, \ _shift, _width, _gate, _flags) \ From patchwork Mon Jul 17 13:34:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315798 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 E7C80C0015E for ; Mon, 17 Jul 2023 13:35:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231511AbjGQNfj (ORCPT ); Mon, 17 Jul 2023 09:35:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbjGQNfR (ORCPT ); Mon, 17 Jul 2023 09:35:17 -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 55DF319A; Mon, 17 Jul 2023 06:35:03 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (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 4R4NP01KS4z9snf; Mon, 17 Jul 2023 15:35:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4/3jUW02TnjdYtDtyTpuIK2UaIeAHqfX2p8U1BU0MxI=; b=tOkN5pKOx/QG66krLStl+PVvmmizHhe6WeGPOaHcsKbRx0zyT9QEL9xH5fbcBgmndHgaSl jEwpeR5witjvILRLvw+wXqCwiyUPDZQfWpfvZJouX35rxgZop454TQGi2xEbTy1oSFebF3 LwmvMkuCnzMK4FLu5vUYJy7fyid1jWRUoBgi72iGhNLLpYu6p8LUXoLn006oXWb7eIVcav XvQSWS8bGD6AX3j1aL9yUJm5JzvijZo6vqLYJ+Qh6NBVnsxZERBQbqYlNJ6/18+8uPDmMf h7Qml49y2dVuslyPbD2qj5Niz2ICPX9M+/gSUJrrSO8Q8AO3MWqsaLrK+93MGg== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:34 +0200 Subject: [PATCH v4 10/11] clk: sunxi-ng: div: Support finding closest rate MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-10-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns X-Developer-Signature: v=1; a=openpgp-sha256; l=2120; i=frank@oltmanns.dev; h=from:subject:message-id; bh=BCjq/TvLd7Vyg2yzlkEqCcyLfH3Gamqs91hzh7NVMYE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNoT0Lb/4aaPfEOSUZsD95gYYYEFGS8osezM eZygrPXQfWJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDaAAKCRCaaaIIlErT x3jmC/9sXIxogKJxgU6bUUqiFwW1lk3xSpv3r/WTMY+DG0XznivmpDmsp9Sm5kyboIMsiqO0w6W mfp86U/AfzP96aY1SdfyF6ELHDsHc3mAt6qrbcx3Nueiu8OQsfuneHb2l3TANOjI5Iilh0jeUoi 941jnUi8UgAIBo/iEJmRkEAkAe04OnIg/pmfFiFN45PLOkNw/FmERTDHzbbaQpZEQ0RJcurxQuc x5b9yE38lNteWYtAsMFZ2h5pAzhVzLN80EtNbQTa3CWkDWV1GN29zdbUa25Ptc9agSFo9emHgwy TKYFEgYIqs35pYJ1tCp+Dr0o4JD7LUwsAnev2DPweEYNqsNRgGw7uCN9uL8VT2VqehJCoR2hcmO mul8vBYdlSA8sOxfRnhOK3aZAM8a8CgZwvOojoVElE0s/JWCUB3g6NObldSuhRlSERph1TIpdSV 75uMLcAPwkgbw7a6w8AWvW7heRPRDpes/+QZYAWl3mFrjNxGKvYkvMHr7N8po0YGGF3fQ= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 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. Acked-by: Maxime Ripard Signed-off-by: Frank Oltmanns --- drivers/clk/sunxi-ng/ccu_div.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu_div.h b/drivers/clk/sunxi-ng/ccu_div.h index 948e2b0c0c3b..90d49ee8e0cc 100644 --- a/drivers/clk/sunxi-ng/ccu_div.h +++ b/drivers/clk/sunxi-ng/ccu_div.h @@ -143,6 +143,26 @@ struct ccu_div { }, \ } +#define SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(_struct, _name, \ + _parents, _table, \ + _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_div _struct = { \ + .enable = _gate, \ + .div = _SUNXI_CCU_DIV_FLAGS(_mshift, _mwidth, CLK_DIVIDER_ROUND_CLOSEST), \ + .mux = _SUNXI_CCU_MUX_TABLE(_muxshift, _muxwidth, _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS(_name, \ + _parents, \ + &ccu_div_ops, \ + _flags), \ + .features = CCU_FEATURE_CLOSEST_RATE, \ + }, \ + } + #define SUNXI_CCU_M_WITH_MUX_GATE(_struct, _name, _parents, _reg, \ _mshift, _mwidth, _muxshift, _muxwidth, \ _gate, _flags) \ @@ -152,6 +172,16 @@ struct ccu_div { _muxshift, _muxwidth, \ _gate, _flags) +#define SUNXI_CCU_M_WITH_MUX_GATE_CLOSEST(_struct, _name, _parents, \ + _reg, _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(_struct, _name, \ + _parents, NULL, \ + _reg, _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) + #define SUNXI_CCU_M_WITH_MUX(_struct, _name, _parents, _reg, \ _mshift, _mwidth, _muxshift, _muxwidth, \ _flags) \ From patchwork Mon Jul 17 13:34:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Oltmanns X-Patchwork-Id: 13315799 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 4527CEB64DC for ; Mon, 17 Jul 2023 13:35:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231237AbjGQNfn (ORCPT ); Mon, 17 Jul 2023 09:35:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbjGQNfU (ORCPT ); Mon, 17 Jul 2023 09:35:20 -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 24F84E49; Mon, 17 Jul 2023 06:35:05 -0700 (PDT) Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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 4R4NP15rWvz9sb3; Mon, 17 Jul 2023 15:35:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1689600901; 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=OJ8q9pTL81Tc/TWJNsV0MmsER+aXTbba/DFvUTK1urY=; b=RyjvvacVElds1v9SVihgtHTAJ5WZcV/ma4doRQAdtPycHMb7YtW2zzXwwOjyvtuXpKsxK8 3WJFAiNKmuI4uMe+WXlvhqyLDjY2Qp3uDY078xIcH1BiLphCJV7Qzu6zaaFJ1my07/Fxt1 TE8PXd6bEiJ6a12JI/p49m7qhqm3cfaerwfMAHapnIz6Oxg/zhuEN/lQ1H27SBYWqd/WaG EvWks4/LemYtRLBjbkC2ILcEiqeG0lWhcyqG/iMCc8eT5KL8XbohPESoAXBADTgoqyCjlm NK+5iz+rrG6CmlrzsFS/rvIVARXRzV3dH9Rfog4naZsFmFZHWfpwN15X1Xp2aA== From: Frank Oltmanns Date: Mon, 17 Jul 2023 15:34:35 +0200 Subject: [PATCH v4 11/11] clk: sunxi-ng: a64: select closest rate for pll-video0 MIME-Version: 1.0 Message-Id: <20230717-pll-mipi_set_rate_parent-v4-11-04acf1d39765@oltmanns.dev> References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> In-Reply-To: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@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=4299; i=frank@oltmanns.dev; h=from:subject:message-id; bh=jbnrLs6Wz/DZblxpFGtXN3DOQE/Va3X1a9GFPqxAmdg=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBktUNoFZsC7quYPm3VlK7cJ6Gb3ocsdztxFbMi+ kj/FSNkNECJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZLVDaAAKCRCaaaIIlErT x5MzC/901SBdHj/WRYrs67Egfj+3aeeouvEYMGGdbS2AdxoneAoPP09JkPwjoygvwxHN+j6Z6WT DiLG61Wt4z+IId7IbXdPGPjpxd9RvPVk7gsdb1JzmNMXCbV10iEIcgqmlOCMwVxaKiCqTfTcny/ jU7TIXn8aseG01l9lebjncm2Ds/tRT1my90mh46LKyNnWKpXWXixx/BGG0Qq50vk5ipRteeM1vq QM/7DK/lfjp83fsywR4GaIhqYvRbhgXvci4JSgnqnHl/BR8qpiH/zSViv11aSd+aIFIDhUAT1eF FvYqTnWXWzm+a6CxlaXGvEtaGBI/Ax6lKf+KMSX8W1lD2Kuvu2cVMXVuK4E4N0M8YQwPYiMreNJ WSnSyPGKAi6izQVzMLSInHNJ2MbfEf4SyTXOLpaM6ZLT0MidPPAWyjvvRRJ3ZttnbqiigTwQV/Z tMZSiPshYbYW+uTHSNB3WV6Mh4iKE8U2u8ddQNYSnlI9Kul1Tf4zEO7crsoRKhfC+ctGA= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4R4NP15rWvz9sb3 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 Acked-by: Maxime Ripard --- drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c index a139a5c438d4..73c84d20f3ee 100644 --- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c +++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c @@ -68,7 +68,7 @@ static SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base", BIT(28), /* lock */ CLK_SET_RATE_UNGATE); -static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(pll_video0_clk, "pll-video0", +static SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_CLOSEST(pll_video0_clk, "pll-video0", "osc24M", 0x010, 192000000, /* Minimum rate */ 1008000000, /* Maximum rate */ @@ -181,6 +181,7 @@ static struct ccu_nkm pll_mipi_clk = { .hw.init = CLK_HW_INIT("pll-mipi", "pll-video0", &ccu_nkm_ops, CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT), + .features = CCU_FEATURE_CLOSEST_RATE, }, }; @@ -531,24 +532,18 @@ static SUNXI_CCU_M_WITH_MUX_GATE(de_clk, "de", de_parents, static const char * const tcon0_parents[] = { "pll-mipi", "pll-video0-2x" }; static const u8 tcon0_table[] = { 0, 2, }; -static SUNXI_CCU_MUX_TABLE_WITH_GATE(tcon0_clk, "tcon0", tcon0_parents, +static SUNXI_CCU_MUX_TABLE_WITH_GATE_CLOSEST(tcon0_clk, "tcon0", tcon0_parents, tcon0_table, 0x118, 24, 3, BIT(31), CLK_SET_RATE_PARENT); static const char * const tcon1_parents[] = { "pll-video0", "pll-video1" }; static const u8 tcon1_table[] = { 0, 2, }; -static struct ccu_div tcon1_clk = { - .enable = BIT(31), - .div = _SUNXI_CCU_DIV(0, 4), - .mux = _SUNXI_CCU_MUX_TABLE(24, 2, tcon1_table), - .common = { - .reg = 0x11c, - .hw.init = CLK_HW_INIT_PARENTS("tcon1", - tcon1_parents, - &ccu_div_ops, - CLK_SET_RATE_PARENT), - }, -}; +static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(tcon1_clk, "tcon1", tcon1_parents, + tcon1_table, 0x11c, + 0, 4, /* M */ + 24, 2, /* mux */ + BIT(31), /* gate */ + CLK_SET_RATE_PARENT); static const char * const deinterlace_parents[] = { "pll-periph0", "pll-periph1" }; static SUNXI_CCU_M_WITH_MUX_GATE(deinterlace_clk, "deinterlace", deinterlace_parents, @@ -578,8 +573,8 @@ static SUNXI_CCU_GATE(avs_clk, "avs", "osc24M", 0x144, BIT(31), 0); static const char * const hdmi_parents[] = { "pll-video0", "pll-video1" }; -static SUNXI_CCU_M_WITH_MUX_GATE(hdmi_clk, "hdmi", hdmi_parents, - 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT); +static SUNXI_CCU_M_WITH_MUX_GATE_CLOSEST(hdmi_clk, "hdmi", hdmi_parents, + 0x150, 0, 4, 24, 2, BIT(31), CLK_SET_RATE_PARENT); static SUNXI_CCU_GATE(hdmi_ddc_clk, "hdmi-ddc", "osc24M", 0x154, BIT(31), 0); @@ -591,9 +586,9 @@ static SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents, static const char * const dsi_dphy_parents[] = { "pll-video0", "pll-periph0" }; static const u8 dsi_dphy_table[] = { 0, 2, }; -static SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_dphy_clk, "dsi-dphy", - dsi_dphy_parents, dsi_dphy_table, - 0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT); +static SUNXI_CCU_M_WITH_MUX_TABLE_GATE_CLOSEST(dsi_dphy_clk, "dsi-dphy", + dsi_dphy_parents, dsi_dphy_table, + 0x168, 0, 4, 8, 2, BIT(15), CLK_SET_RATE_PARENT); static SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu", 0x1a0, 0, 3, BIT(31), CLK_SET_RATE_PARENT);