From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 33E85C001DF for ; Sun, 6 Aug 2023 13:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zsTS6u5lmFKURfGVafF3KjOH0j636eN+F1obBgo9qcM=; b=XK+LDNRJjWQF19 STiZ3gbQa9SPbxphogDRQRMxyQexuiVQrLoNvQrENmtq6DHRk6JZ9ISeaX6AD/JcHaw+9bPpM37fG eMYUfwldyB/bpX7+4prRVhgLZQH1FLZ+m9SP9sP7d07iVzuMrtFbHuebXelMsxGefCY0qIQKn43Vz lYIPi/vOOb0pcH1rEHH3d+MrGo72bbEFVv+SsN5VJ77ZFyy+bFfUQPs4Y5GsebNsLruTnVRdAWdnt hF6cIDKxSWKLTDtBttDaIZhOBgDAEnG8WVJxyUtETnJlF6/tuJO7yjWFZw4m7sMj/trGcAA4LUAI6 H35EvCkeyvmN0nZr3foA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSds5-00FSMX-2v; Sun, 06 Aug 2023 13:32:37 +0000 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSds3-00FSM2-0x for linux-arm-kernel@lists.infradead.org; Sun, 06 Aug 2023 13:32:36 +0000 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4fe389d6f19so5760209e87.3 for ; Sun, 06 Aug 2023 06:32:32 -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=Gctqp2TGe+7tNFWzAXfQGJh1sYVcteGqtA6vu8OdVnKacE8W/qqYChp5HEed6QLunB nJJyGcsIl4FQxx9eHSupVK2IFvb9ZOe1ESo+FlchB8KFJJwUqggYGWafdBHFjbc0UjNx c57OXYxUJef6E7CR9mXpXtliOTPiMo7xrhNObCllq7GnHAZX9ky5lSuAOUnLO5+DMGMI OjY7Pr0s8ZUpjJHpFdmg1FCvLT96MW0bSA/hyIpIb7gfHbAcFMIyoy6nK6DP5IILvo4f rghr2vvsL4G2EEtc4doeCz5LVqPB04Abn+H6iKq5VagnGpNem0OXOUdIdgsS647Tm88h nwUQ== X-Gm-Message-State: AOJu0YzjRI8yDDD/+NyCnM9NkJMAJXVQW+sOCO4P96LuR2i07Hn/ttnq hgNrq/NQt6MPiSGpLpHz0yk= X-Google-Smtp-Source: AGHT+IG8L0BCJQj+X/JTbu7KGvHDe3BekcFFTKfTsvi0Xii9e25tarI8/ohJObfCqVIqTL9ftLKh3w== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230806_063235_358043_DC9755B5 X-CRM114-Status: GOOD ( 23.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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; _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel