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 EA721C001DF for ; Sun, 6 Aug 2023 13:42:44 +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=PCB2rXPobtnDDv4U0fD0ITrsn7mOpkyt6O6uG5st8lQ=; b=5CJu4YEy1WUw60 7ULBOklCsoOB7B7IZ4GgZ8wf/q9ue87ALsYf+SNCPWfkSBTrC7sqVyKhLimHuqIbhs4D6pBr71PrT OrlgYunaL50TDxs5dyKZRC1mS19GvS0z3C45eYFlxdOWAfQ+JbCIV0C9WYWJF3kntlIn5oE6lr/Dq vZHzxohXMXFehcdO6SXO1k5OLfffZTt9ldpKtqvHrOXXPS2fSlYWyMqYZSx4F8W915O0YxNUS69iI QyKwwdfb1ZyzEbEvdAouPYn/fQuoaGuJE82+lLt15MQabFtBBYvG8qhcKNTM5DgvN18IZrSJwbjiN Cu/yYKiGfM3MQX3e8MNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qSe1V-00FSw6-30; Sun, 06 Aug 2023 13:42:21 +0000 Received: from mail-ej1-x632.google.com ([2a00:1450:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qSe1T-00FSuw-0X for linux-arm-kernel@lists.infradead.org; Sun, 06 Aug 2023 13:42:20 +0000 Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-99bcf2de59cso541141066b.0 for ; Sun, 06 Aug 2023 06:42:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691329335; x=1691934135; 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=AEx+ZqR+usKBBercOITyC/EAc5ia+Jr9hFT6fjMYzwY=; b=GPhHyVXNW5iHzU+Uzck+132AUiEHf0OghscbBNSFqF6kBnJDR142vWP8rgh6IQTFmm FLhqB15u+9EHwftqi+AkkCBaBsZ1m1eq8nYcy3aIHTHxi6kRsVF4IYJSG5c4TqACt0eK D6TDQvbvwpbxi9KQVEXOfpN+nfXDM6r3Y/KsFeaBhObY7aPh4b/Dp2kZQcx2hqHdpqjv R37I8vCMNEzwbpdPiltFX7sL2yz07jtT+YEfdgDu9FG8NM2mBbd3yZXA3uo991V/z8kq 7/qdscsWTkknI1yjASdHwo69Ostco215Ce5NQoNMSDigHK6jvDgvHhWWeBNryIJxhmuC KlUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691329335; x=1691934135; 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=AEx+ZqR+usKBBercOITyC/EAc5ia+Jr9hFT6fjMYzwY=; b=L6WT1XsyVaM1TQ7nBT0Zi5q7x0baWu0K56ThAmx2T7vRuq0G8qV4akUgRQ/H+C9JPH MUmTD+RlPngNigRoUjaW0TTgGWdaYevfjCp1Ax+jtyTKLxDgi7lUj0hQCZxNZYbA33N4 ntd++d9FsFP7J2OHLWBSo5Vv2pLZEj1qImADtZYKNvJQawOCibZ/ghrNgpBa5s81dITS LEGLkt8V41IKS1/yOj8lK5nMQV75yHsmZ8Icj/lxuuUP9s3kgUSZV0BvZ+I9VlqWoSOQ TWbuapbhKm3N6uz0cfCSxJufhan8ISypqLS1gd9q9ycVYtfLIFpV33Bd7O/yLuAAbt70 k2pw== X-Gm-Message-State: AOJu0YyZQ2trELC2b0NTy//KcI4GHqgF3ITHBRWWURb+E/nOI5+6vXUs D27FnilBlxwqcitQyQnjlvFgEG8ApXVcjg== X-Google-Smtp-Source: AGHT+IFmjZYi0hcJVwMaH7Gd7tt21pCr9H5ZyAUDihj9v3AUGUl18q5jb1ufnmD9/to65CEor1LNKg== X-Received: by 2002:a17:906:51c6:b0:99b:d007:67b1 with SMTP id v6-20020a17090651c600b0099bd00767b1mr6517352ejk.72.1691329335083; Sun, 06 Aug 2023 06:42:15 -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 kq7-20020a170906abc700b009888aa1da11sm3949284ejb.188.2023.08.06.06.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Aug 2023 06:42:14 -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 07/11] clk: sunxi-ng: nkm: Support finding closest rate Date: Sun, 06 Aug 2023 15:42:13 +0200 Message-ID: <23170854.6Emhk5qWAg@jernej-laptop> In-Reply-To: <20230806-pll-mipi_set_rate_parent-v5-7-db4f5ca33fc3@oltmanns.dev> References: <20230806-pll-mipi_set_rate_parent-v5-0-db4f5ca33fc3@oltmanns.dev> <20230806-pll-mipi_set_rate_parent-v5-7-db4f5ca33fc3@oltmanns.dev> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230806_064219_208614_7F60E201 X-CRM114-Status: GOOD ( 19.40 ) 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:52 CEST je Frank Oltmanns napisal(a): > 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. > > Acked-by: Maxime Ripard > Signed-off-by: Frank Oltmanns Reviewed-by: Jernej Skrabec Best regards, Jernej > --- > drivers/clk/sunxi-ng/ccu_mux.c | 2 +- > drivers/clk/sunxi-ng/ccu_nkm.c | 20 +++++++++----------- > 2 files changed, 10 insertions(+), 12 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 ea1b77e9b57f..896bb1ef8642 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.c > +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > @@ -17,7 +17,8 @@ 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, +static unsigned long ccu_nkm_find_best_with_parent_adj(struct > ccu_common *common, + struct clk_hw *parent_hw, > unsigned long *parent, unsigned long rate, > struct _ccu_nkm *nkm) > { > @@ -33,10 +34,8 @@ static unsigned long > ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw, 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)) { > + if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) { > best_rate = tmp_rate; > best_parent_rate = tmp_parent; > best_n = _n; > @@ -57,7 +56,7 @@ static unsigned long > ccu_nkm_find_best_with_parent_adj(struct clk_hw *parent_hw, } > > 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; > @@ -70,9 +69,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; > @@ -165,9 +162,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, parent_rate, rate, > &_nkm); + rate = ccu_nkm_find_best_with_parent_adj(&nkm->common, > parent_hw, parent_rate, rate, + &_nkm); > > if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) > rate /= nkm->fixed_post_div; > @@ -202,7 +200,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); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel