Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2217422rwb; Sun, 6 Aug 2023 12:39:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzbzoL3YXJmSg2O6u5eBnh7frsPZqifFw+enUffu6aeJycHLcrSY/WLvJ8E0Zr/qWsmoUB X-Received: by 2002:aa7:d306:0:b0:522:cef7:83c3 with SMTP id p6-20020aa7d306000000b00522cef783c3mr6581068edq.8.1691350744564; Sun, 06 Aug 2023 12:39:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691350744; cv=none; d=google.com; s=arc-20160816; b=G9JgurkvOV6bVfyn6aUO4CS7GhnFSAOHtiMVw/SQlJ9L79F7KMBWrgc066mlNtDD6j JT4KwuNe3XXwdeLjNyCK7dXr8RnGuQoKAvFn0JX0QcHrAFQEDxQgmaEW2L05wZi7NOB2 I9IpG6QHOym7dhdzoitPDw4TJPjsN1Xv+aPt9G4Ee5rus21QO12SyZqF8JYe3cBR2YTv O8DOHpjRIqUCWJnBcwNIlae7rA3nfiDogdN5KQnIveq7Wnbabbz33UFj5sV13nvLMLY/ KvqO/oHLSUsYEydwqx4Y/nMxdtFBTlDyMSPnzaRGiEnezhrtQyZlQixTQPk3SL2l1M7N 7Y1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KkF8V9SS0Dv10Mhzf8yo4sbGOfqu3VWFivFwQBx9BP8=; fh=bO+B/XDIbJg/wyQv6Z9aSqnL/VU+wJ8UKqRO5hXOiwY=; b=yoJuO0MiJHXLi7CjgvgzgRDWJ/WdKOnRUgs/00fIHlxu8E385GrePB1l0hmKMNFlmk 5cEGSXblCzYtzBFfLpaKhPF6ND3BlTetvJKzIzLDR4Gr2vhVvRx+GE0Bxs3xrEqhzQp/ MUbODEms+HHoYLhNEb17tTYE/EzTJubwl/SzVD+FMmC6KwBPbdMIUfyxli4VHmDg61JE NQd6XxrgjCRFpPiwx06TdAxm55OEMG76K7TwB+n6KJq/zFIB1p70S7csmfPxUo0pr46c 6MFre7A1VfeLeytlAE86P1/hgygVKbTGB/R7JFXLVp2Vr6BSVpx8w4w3WgVehzKncbOF u8+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SuQitmxE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a50fc06000000b005223aaec697si4768606edr.576.2023.08.06.12.38.39; Sun, 06 Aug 2023 12:39:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=SuQitmxE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230217AbjHFNch (ORCPT + 99 others); Sun, 6 Aug 2023 09:32:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjHFNcf (ORCPT ); Sun, 6 Aug 2023 09:32:35 -0400 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F714C9; Sun, 6 Aug 2023 06:32:33 -0700 (PDT) Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2b9c907bc68so56693931fa.2; Sun, 06 Aug 2023 06:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691328751; x=1691933551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KkF8V9SS0Dv10Mhzf8yo4sbGOfqu3VWFivFwQBx9BP8=; b=SuQitmxEhvU/1w8QJiYfUxj+Tqz5kpgI3A5tIKj/rSs862S8vCH8MYUKDKMz5zUVr2 0veZrYBG3IiXFiUORkM5LcDl450UGWI2KZpsBJWezv5ht15CK3VbaRnyBmVD4gvpk0J1 M7KYnuRGzSEeBAAeY8Xe2hfdmkitvFpwH5aJFbPFyKjGKXNR5Ql61lsPJzsQOdd0fT+h SdVYCmteP0u5atDkkokhz4bak8dQrPAGwlHE5Wxk+Pud2kOusRexueld61C2UMZmRpLa UKK1pJR3yGnPXmETF5Knr27eWtB72fE/wBpsMIaWcYjwS8SEgFXOaXM9uI7B760gYN43 cSYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691328751; x=1691933551; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KkF8V9SS0Dv10Mhzf8yo4sbGOfqu3VWFivFwQBx9BP8=; b=Rj0fQIgeW1uX0EgQgUtOYS/5v+ROM2voCnk4f2dvvkDJSTe/JBpKI17I24Yd8xe4nv 2QGX2mon8JCzkWlfjeEgZo4EP/4T5XFgVwCCseVTrxHnwBeVTOtOtCsOmk7mA58iFM66 xAOhEOPsU1/6kN018SPpE1tAX1F9PDuJGXfm2mzPJhIUHJrlP/iY8CL+8svu1LVD5CS5 R3/Xua61fpCTKQkH0pMtgCimIzu1u3SkvSm21IQ14HC4LqeH08ZN7P/uCO7gfQqDYasD PlsBlySplKJZXpTIh5dCNZjO/xXR6lbSekSTyRqlxBb6tY5z7wzeXwGb1sne+YjvxLhW 96HA== X-Gm-Message-State: AOJu0Yy+XczmNNlU5k1NY0Bwhv0Qsyy+KHCudxGPt69MMqoMTrTKeFcY rhnv0uJn9Qp+SG1uckBdf+c= X-Received: by 2002:ac2:4db0:0:b0:4fe:8c4:44f6 with SMTP id h16-20020ac24db0000000b004fe08c444f6mr4148158lfe.56.1691328751029; Sun, 06 Aug 2023 06:32:31 -0700 (PDT) Received: from jernej-laptop.localnet (82-149-1-233.dynamic.telemach.net. [82.149.1.233]) by smtp.gmail.com with ESMTPSA id p23-20020a056402075700b0052237839229sm3912648edy.21.2023.08.06.06.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 06:32:30 -0700 (PDT) From: Jernej =?utf-8?B?xaBrcmFiZWM=?= To: Maxime Ripard , Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Samuel Holland , Andre Przywara , Roman Beranek , Frank Oltmanns Cc: linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Frank Oltmanns Subject: Re: [PATCH v5 02/11] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate Date: Sun, 06 Aug 2023 15:32:29 +0200 Message-ID: <3752134.kQq0lBPeGt@jernej-laptop> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-2-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> <20230806-pll-mipi_set_rate_parent-v5-2-db4f5ca33fc3@oltmanns.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Dne nedelja, 06. avgust 2023 ob 15:06:47 CEST je Frank Oltmanns napisal(a): > In case the CLK_SET_RATE_PARENT flag is set, consider using a different > parent rate when determining a new rate. > > To find the best match for the requested rate, perform the following > steps for each NKM combination: > - calculate the optimal parent rate, > - find the best parent rate that the parent clock actually supports > - use that parent rate to calculate the effective rate. > > In case the clk does not support setting the parent rate, use the same > algorithm as before. > > Acked-by: Maxime Ripard > Signed-off-by: Frank Oltmanns > --- > drivers/clk/sunxi-ng/ccu_nkm.c | 45 > +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 > insertions(+), 1 deletion(-) > > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c > index f267142e58b3..ea1b77e9b57f 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.c > +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include Why do you need above include? Best regards, Jernej > > #include "ccu_gate.h" > #include "ccu_nkm.h" > @@ -16,6 +17,45 @@ struct _ccu_nkm { > unsigned long m, min_m, max_m; > }; > > +static unsigned long ccu_nkm_find_best_with_parent_adj(struct clk_hw > *parent_hw, + unsigned long *parent, unsigned long rate, > + struct _ccu_nkm *nkm) > +{ > + unsigned long best_rate = 0, best_parent_rate = *parent, tmp_parent = > *parent; + unsigned long best_n = 0, best_k = 0, best_m = 0; > + unsigned long _n, _k, _m; > + > + for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { > + for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { > + for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { > + unsigned long tmp_rate; > + > + tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); > + > + tmp_rate = tmp_parent * _n * _k / _m; > + if (tmp_rate > rate) > + continue; > + > + if ((rate - tmp_rate) < (rate - best_rate)) { > + best_rate = tmp_rate; > + best_parent_rate = tmp_parent; > + best_n = _n; > + best_k = _k; > + best_m = _m; > + } > + } > + } > + } > + > + nkm->n = best_n; > + nkm->k = best_k; > + nkm->m = best_m; > + > + *parent = best_parent_rate; > + > + return best_rate; > +} > + > static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long > rate, struct _ccu_nkm *nkm) > { > @@ -124,7 +164,10 @@ static unsigned long ccu_nkm_round_rate(struct > ccu_mux_internal *mux, if (nkm->common.features & > CCU_FEATURE_FIXED_POSTDIV) > rate *= nkm->fixed_post_div; > > - rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); > + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) > + rate = ccu_nkm_find_best(*parent_rate, rate, &_nkm); > + else > + rate = ccu_nkm_find_best_with_parent_adj(parent_hw, parent_rate, rate, > &_nkm); > > if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) > rate /= nkm->fixed_post_div;