Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp25742667rwd; Sun, 2 Jul 2023 23:53:20 -0700 (PDT) X-Google-Smtp-Source: APBJJlH3Hwyf0dzRDVxm8mC5sy3YoGDBqVjF5BXGw1S+u6Y2j1mBfIv04pkM7xNKIzUjEoI/uUEe X-Received: by 2002:a05:6359:d1c:b0:132:7a01:32ac with SMTP id gp28-20020a0563590d1c00b001327a0132acmr5764862rwb.16.1688367199546; Sun, 02 Jul 2023 23:53:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688367199; cv=none; d=google.com; s=arc-20160816; b=Ql3pzOhY7rAszH2CzPPzTQeJx+r3IC2/vFuhGkVlyrmuucVYwYqraJXn8/wE6c5WyT h6GvGbnDqDeJjDhv1Nl3KXOb9gk/O4STMZ9fVNeWXBa0Jsy30+oOQYKlQiIWd9mHrvhM w3+nyYQurfzfDd/rfMxn+qeJi9AOCijOcCS+eI8ml73GQAIRqd7tj8IiPmez6zN8Zx5Q 8p3Dc9V4zHOfCAN6UcW+K3KZqbJIv2Y4qzohq57Snr1CNLqsrOS9AAa7JOTHEwlp24+t WUibknsz70HSjJeITHm/3G9GnP9b589AcdOC+JU9rEFYooihxpYMEu9HNw7UL8xYbEQb pRUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature:dkim-signature; bh=yhYIlwrlNmx9cPyTtHkCkT6NyvSnAi/Qkx6nM4nFrF4=; fh=+KcAhWSG9RzC2SvYVXgDzJ1nkcDBnTpIanTuJBxcWXo=; b=YJKrZklOrz2n8jeti64LP5x2HUYMpYlhE8WO3iJqtGUYowiRgIYk2x+JM37Bh1V+5O XU9U83r2T4AhmNVhUEb2yj2ZVrW5ZsL4W7fId2czKGPMWIsS4OzZTbqNPy10MnDmzj2M /Yq0qJkMdQdbmfK3vyihkNAakj2LsSPbVD23qco24c1OgnCcUahEQW9+ICrbwbgFtIrm mAf1zBpTSgy0qoUG1hiD0957CXK/AfElHsaAg21KPfBOUHst4WpS8eaQ2OoB128rowZQ 7chUavFhpkQW0fxUArSq5SVFmuxtXahGmgbr2NQ+iPDeHC7d5cW266Ihxq8dhpe4/Th2 etPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cerno.tech header.s=fm2 header.b=YdxQ0sYK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=RHkxiFvV; 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=cerno.tech Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g30-20020a63201e000000b0052c419dc8d1si17277719pgg.274.2023.07.02.23.53.05; Sun, 02 Jul 2023 23:53:19 -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=@cerno.tech header.s=fm2 header.b=YdxQ0sYK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=RHkxiFvV; 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=cerno.tech Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbjGCGr7 (ORCPT + 99 others); Mon, 3 Jul 2023 02:47:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbjGCGrx (ORCPT ); Mon, 3 Jul 2023 02:47:53 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 230F9E42; Sun, 2 Jul 2023 23:47:50 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9A7535C0323; Mon, 3 Jul 2023 02:47:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 03 Jul 2023 02:47:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cerno.tech; h=cc :cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1688366867; x=1688453267; bh=yh YIlwrlNmx9cPyTtHkCkT6NyvSnAi/Qkx6nM4nFrF4=; b=YdxQ0sYKUecOor8lkD 6Y1cUg0pUMTXj/vitN1iFilMbKHJTzh5tMeiWYfqf4wkkYhd8O93FyNNMVBOOYQR nxc7Lnt+MKfi3Wpu9yjKTTLvROkTZQG7hfW+V2Y2ikdSnGrd1AcycpkaU/PKu8Vq uU1SqmXaxrVhahKjJBrr8oAxMkCyF0qule2WOB9JOdEywH5l5FhGnSjrZegcvrck JlMFTyTv0tR6u9MQq3dGUYQw6nPLXRP4j3UDiX3ZNSxc26ClI7BbNc2uC6FL7/sX +MtCFryogPR7BjmoSyWSYdey9kiklW4NmALOBXzbBa1+MIOav9V7kWWqFciWGsEy qc3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1688366867; x=1688453267; bh=yhYIlwrlNmx9c PyTtHkCkT6NyvSnAi/Qkx6nM4nFrF4=; b=RHkxiFvVzeyR1NQXCoy4yTo0AnAjw 1E51EW6CR6NGD3LE6a5da4PDnq+vkyoUMmBugs1GhgqZ+mK0dRGWpab5ApjG4tY/ tmqqw8tiDV84t8kt261WnYWI7ONEYysTH6ZDa/fOxHUWkqxi/wouBOwCeHUrnPmG XJmcY+pKACF/hitqaZcHQnAgYfuOP6QiDN57INQKXx+Kr7rkq4AwwINFrdWGHdAQ y4gf9S8ky5mDrCxMVR6MOpa9g3jlzWDro1Cns17Plm7heAwraVYvxSSIUwjW8lxV TPTH6xfoVCjk+apJ+kgp8cNwWw/W2U+tbeqy8Xs9s3qojcl/TODY7pEUw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtsfertddtvdenucfhrhhomhepofgrgihi mhgvucftihhprghrugcuoehmrgigihhmvgestggvrhhnohdrthgvtghhqeenucggtffrrg htthgvrhhnpeeuveduheeutdekvefgudevjeeufedvvdevhfejgfelgfdtkeevueegteek gfelfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hmrgigihhmvgestggvrhhnohdrthgvtghh X-ME-Proxy: Feedback-ID: i8771445c:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 3 Jul 2023 02:47:45 -0400 (EDT) Date: Mon, 3 Jul 2023 08:47:43 +0200 From: Maxime Ripard To: Frank Oltmanns 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 v3 1/8] clk: sunxi-ng: nkm: consider alternative parent rates when determining rate Message-ID: References: <20230702-pll-mipi_set_rate_parent-v3-0-46dcb8aa9cbc@oltmanns.dev> <20230702-pll-mipi_set_rate_parent-v3-1-46dcb8aa9cbc@oltmanns.dev> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="crtkwlzzyg5ufkfz" Content-Disposition: inline In-Reply-To: <20230702-pll-mipi_set_rate_parent-v3-1-46dcb8aa9cbc@oltmanns.dev> 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 --crtkwlzzyg5ufkfz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi, On Sun, Jul 02, 2023 at 07:55:20PM +0200, Frank Oltmanns wrote: > In case the CLK_SET_RATE_PARENT flag is set, consider using a different > parent rate when determining a new rate. >=20 > 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. >=20 > In case the clk does not support setting the parent rate, use the same > algorithm as before. >=20 > Signed-off-by: Frank Oltmanns > --- > drivers/clk/sunxi-ng/ccu_nkm.c | 48 ++++++++++++++++++++++++++++++++++++= +++--- > 1 file changed, 45 insertions(+), 3 deletions(-) >=20 > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nk= m.c > index a0978a50edae..d83843e69c25 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.c > +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > @@ -6,6 +6,7 @@ > =20 > #include > #include > +#include > =20 > #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(unsigned long *pa= rent, unsigned long rate, > + struct _ccu_nkm *nkm, struct clk_hw *phw) The usual order in that driver (and Linux in general) would make the clk_hw and nkm structure pointers first, and then the parent rate and rate. But something looks off to me: ccu_nkm_find_best_with_parent_adj takes a pointer to the parent rate which makes sense since we're going to modify it. > +{ > + unsigned long best_rate =3D 0, best_parent_rate =3D *parent, tmp_parent= =3D *parent; > + unsigned long best_n =3D 0, best_k =3D 0, best_m =3D 0; > + unsigned long _n, _k, _m; > + > + for (_k =3D nkm->min_k; _k <=3D nkm->max_k; _k++) { > + for (_n =3D nkm->min_n; _n <=3D nkm->max_n; _n++) { > + for (_m =3D nkm->min_m; _m <=3D nkm->max_m; _m++) { > + unsigned long tmp_rate; > + > + tmp_parent =3D clk_hw_round_rate(phw, rate * _m / (_n * _k)); > + > + tmp_rate =3D tmp_parent * _n * _k / _m; > + if (tmp_rate > rate) > + continue; > + > + if ((rate - tmp_rate) < (rate - best_rate)) { > + best_rate =3D tmp_rate; > + best_parent_rate =3D tmp_parent; > + best_n =3D _n; > + best_k =3D _k; > + best_m =3D _m; > + } > + } > + } > + } > + > + nkm->n =3D best_n; > + nkm->k =3D best_k; > + nkm->m =3D best_m; > + > + *parent =3D best_parent_rate; > + > + return best_rate; > +} > + > static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned lo= ng rate, > struct _ccu_nkm *nkm) You haven't modified ccu_nkm_find_best though, and it still takes the parent rate value. > { > @@ -106,7 +145,7 @@ static unsigned long ccu_nkm_recalc_rate(struct clk_h= w *hw, > } > =20 > static unsigned long ccu_nkm_round_rate(struct ccu_mux_internal *mux, > - struct clk_hw *hw, > + struct clk_hw *parent_hw, (This should be another patch) > unsigned long *parent_rate, > unsigned long rate, > void *data) > @@ -124,7 +163,10 @@ static unsigned long ccu_nkm_round_rate(struct ccu_m= ux_internal *mux, > if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) > rate *=3D nkm->fixed_post_div; > =20 > - rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm); parent_rate is a pointer, we were dereferencing it to pass its value to ccu_nkm_find_best. All good so far. > + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) > + rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm); Still passing by value > + else > + rate =3D ccu_nkm_find_best_with_parent_adj(parent_rate, rate, &_nkm, p= arent_hw); And passing the pointer there since it takes a pointer. Still good. > =20 > if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) > rate /=3D nkm->fixed_post_div; > @@ -159,7 +201,7 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsign= ed long rate, > _nkm.min_m =3D 1; > _nkm.max_m =3D nkm->m.max ?: 1 << nkm->m.width; > =20 > - ccu_nkm_find_best(parent_rate, rate, &_nkm); > + ccu_nkm_find_best(&parent_rate, rate, &_nkm); But here, we're passing a pointer to parent_rate to ccu_nkm_find_best, while it's still supposed to take it by value? Maxime --crtkwlzzyg5ufkfz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQRcEzekXsqa64kGDp7j7w1vZxhRxQUCZKJvDwAKCRDj7w1vZxhR xTN7AQCLvDQbFJ/1zc3WcpwSgbfhRvIVtquRM80f05ahwnLJMQEAuHzzzqfWFsfi PojksszR0ap9F1b/QbIqhSgaoXjQfAA= =XoMd -----END PGP SIGNATURE----- --crtkwlzzyg5ufkfz--