Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp1863243rwo; Sun, 23 Jul 2023 02:15:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlESIXT1l8jCmpv7Iof7h340b8ZBj+fbVINit4qYdBzlY0JbeWZ0ZdLdR3P6VSK7EspBsLhW X-Received: by 2002:a17:906:73c9:b0:99b:4956:e4d9 with SMTP id n9-20020a17090673c900b0099b4956e4d9mr7350349ejl.39.1690103746942; Sun, 23 Jul 2023 02:15:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690103746; cv=none; d=google.com; s=arc-20160816; b=nWeFebWhcjHNnMn8U0u35hACl57LkKV5BoVMdmYVmCDLG58xZDtPYmctnrFmrzKdDD CGBPN0/rfkdkvPOCEzLW3IpU3lAwzPJ1KFY7WlDAgvbaC84/A1w8e/NA1cVrrEaqPD+F pNufCE1e/KoFnpNBY9xe3PKPuVQ74bLLxBq56ELNLK+KT7nZDeV+mfSwkeFNMn07yVzn L7vBpcx/1faB61xN0J6ltf4Tj5Qsnb+SAD206PClY0qhdwUBVu7yppC/mBHHfs0INZRk xPGOhOgrRa+dQbjJGiR56LSFWlnOmmHVs9HeflF0rKsxB4KHeCQgpBOWmfYBOUY4jcBQ XVlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:in-reply-to:subject :cc:to:from:references:dkim-signature; bh=QUpiLW4Bjo600wsGfn6sWtbls6tv+Y76e5aMy/lLZRI=; fh=39eSMAo8+o2JTKI7Z34dfpDY2P6uC9ptM1NX3ynUB6U=; b=JLCO+3P4sIV0fM3S594gRNqtU8THgBvU4cGMQNzo0Ic+N3rqGmcurNGb5pHGCEM0HC TYS3emA0+gQrzbWF3Dn71bS7qnyDk+D6+lxiAgjv/e2cWyMH644PdP/NamzUZ1/mGqvG 9gAxsMgAUCZNx/pq5dQElUnCHEcFxOTZgdBhIMT3xk4YHylQm0zk8K8+4P7hyx5iovwM BfR5VJ9WayLtj7Urkz7C58vChAxNSKFk2A8XsHEUFRERyXw4/aiKTJBNudUvc2iM3zAT B3Ukc7PgQpKUti4I3L09vj/pYu97/xwyrELcjRYzIWb15HudVLN5y6IY5NKMBsLCtOr9 KnbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=pL5jsGfH; 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=NONE dis=NONE) header.from=oltmanns.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y22-20020a17090614d600b00989027eb30bsi4813224ejc.610.2023.07.23.02.15.21; Sun, 23 Jul 2023 02:15:46 -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=@oltmanns.dev header.s=MBO0001 header.b=pL5jsGfH; 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=NONE dis=NONE) header.from=oltmanns.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229779AbjGWHZa (ORCPT + 99 others); Sun, 23 Jul 2023 03:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjGWHZ3 (ORCPT ); Sun, 23 Jul 2023 03:25:29 -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 0B3D110CB; Sun, 23 Jul 2023 00:25:28 -0700 (PDT) Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (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 4R7vvm4Pcdz9tBC; Sun, 23 Jul 2023 09:25:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1690097124; 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: in-reply-to:in-reply-to:references:references; bh=QUpiLW4Bjo600wsGfn6sWtbls6tv+Y76e5aMy/lLZRI=; b=pL5jsGfH/OXKALWyo2XjDske4VVW7aj41TCh0369DoyEZfqtCZo2q628fGWW0pw2wRmNts pDr8Nu266KYGfBJEtrPr4GShQMq9A4/IvAIPzGoEYPcrE/KdRUuii8WRSgYzCV4hPDSLal 3sDpNdrjYGUQ64ezvLempkwb4k2IrdsEB7vIe9Gj3DA/rm/dIZ8WjUuTd73hxZKcNZvyBC 89DifAsAT+b/AdgM/3n53/hPqVeLKj15eMRFeIkm8Y+FyHZvzfetfsecGSpwzsTT793g6b 95gPumEjD8fq+8d4kq/os/mlm7WBqHxH/WZ84Ao5ZFwPcTR1HJTwOVoyXdpeoQ== References: <20230717-pll-mipi_set_rate_parent-v4-0-04acf1d39765@oltmanns.dev> <20230717-pll-mipi_set_rate_parent-v4-8-04acf1d39765@oltmanns.dev> From: Frank Oltmanns To: Maxime Ripard Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Roman Beranek , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 08/11] clk: sunxi-ng: nkm: Support finding closest rate In-reply-to: Date: Sun, 23 Jul 2023 09:25:10 +0200 Message-ID: <87ilabqecp.fsf@oltmanns.dev> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Hi Maxime, On 2023-07-17 at 16:14:58 +0200, Maxime Ripard wrote: > [[PGP Signed Part:Undecided]] > On Mon, Jul 17, 2023 at 03:34:32PM +0200, Frank Oltmanns wrote: >> 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 >> --- >> 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) > > Same comment than on patch 7, common should be first in those two functions. > Ok, I wasn't sure what your expectation is for existing functions. For ccu_find_best_with_parent_adj the order is: 1. *phw 2. *nkm 3. *common 4. *parent 5. rate We don't have the parent hw in ccu_nkm_find_best. The order prior to this patch is: 1. parent 2. rate 3. *nkm We need to add *common to that, so I could add it to the beginning as per your suggestion: 1. *common 2. parent 3. rate 4. *nkm I could also pull *nkm to the beginning (similar to the parent_adj version): 4. *nkm 1. *common 2. parent 3. rate Thanks for your feedback, Frank > > Once fixed, > Acked-by: Maxime Ripard > > Maxime > > [[End of PGP Signed Part]]