Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2668106rdb; Mon, 5 Feb 2024 13:50:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFR/xDN0fs+MZ+HBl6vTP7o7uyt7D588z9AoR2WR/AJDa0EZgGbzrCKLFD4DMmxUxigEKM1 X-Received: by 2002:a2e:9050:0:b0:2d0:bbbf:6aa7 with SMTP id n16-20020a2e9050000000b002d0bbbf6aa7mr194466ljg.32.1707169855886; Mon, 05 Feb 2024 13:50:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707169855; cv=pass; d=google.com; s=arc-20160816; b=FqqkAZ2kkSkKn3W5y5pfCd0e1qxbKTxyM8p4MxMciDC/swVgL3I0Yjbq9wu9um9Q1G WgjDYJR7FOfpPnR6UG2ZfOnuWrtW7+gXCMWrm4FfG98vBtgfHhKuOeL7mFfXrIu/h6RK YGzVaGjOLqlGw/+3vqzaVvrGiKyIx6N9lL6n5NP1AOq2N4LbyPEN+DUY3HVNva794Fjq iiwZ+LKlVWAb0RKw0BzhQazzCg+K9aZ12+vkMyov4UwTQX9ty/+JWQJvcTZyUvD7gMPV AmZB9wos8mWC4TYfevjlajo+CCTxIdOqEkZpgMNPBvutWevEYZ9Xx5BVCY0ZrW9ZWBA9 4kSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:in-reply-to :subject:cc:to:from:references:dkim-signature; bh=JhbWLYxrCrQ3+gd4ivimBZHSQmaCXqHOjjg02OP3xx8=; fh=nyjD7KiCTvtfBHGUNfTeXy00+sx017G64Lpp4+WFLv4=; b=ixomrL4y1e6NaC4kyonFPrBKG84FYn10eaxk3I1RGzOHkjlM1b++Mep54DjCTrSFJ5 pKqmyvMyvtMr8XU1xdSmWyxvHUcDFf5yZo5EyRdiKfaKXrXozcfKnvw7WEFbiDKLiwln fk7zkZg+lb8iFQZkl2cJ0q5tha1VCi1Cdtp8MjbZpLa2+04CEwgc5uj7uE4yAyMe7BFZ q5UkfbYFZeOCzrAF+Jj1O5O2CamTMV++i2rsdrvRZ0a0Dwsn7HTfdJ1Kt4Pqs4M2rs3r MLn8wyUFbdZvmei22Zqwedn5UtaSXCsMxUGyyTUp0Ak2ETn7d7TIpmRarhuyJuizTxyw SfKA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=R2djw1HS; arc=pass (i=1 spf=pass spfdomain=oltmanns.dev dkim=pass dkdomain=oltmanns.dev dmarc=pass fromdomain=oltmanns.dev); spf=pass (google.com: domain of linux-kernel+bounces-53921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev X-Forwarded-Encrypted: i=1; AJvYcCUQxuTDgIG5+L5/cPWPL4Ksg5miEyuq9VdsKj11RL/aJ8f24ORa+tjspMs3gvp2Vt4klKkPIs9BhX5Xppt8PlAY3BMkq1K9vQrbodgHrQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cm7-20020a0564020c8700b0055aa89b9dd5si319007edb.61.2024.02.05.13.50.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 13:50:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-53921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=R2djw1HS; arc=pass (i=1 spf=pass spfdomain=oltmanns.dev dkim=pass dkdomain=oltmanns.dev dmarc=pass fromdomain=oltmanns.dev); spf=pass (google.com: domain of linux-kernel+bounces-53921-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-53921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 65BCA1F2BB2E for ; Mon, 5 Feb 2024 21:50:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5C621350F1; Mon, 5 Feb 2024 20:34:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b="R2djw1HS" Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [80.241.56.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58AA81350DD; Mon, 5 Feb 2024 20:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707165258; cv=none; b=FAK0iNDZxN+Rtsr9elqnjHrkMvNpvQHuHl1vZO/2jkgF8HvBN9WfSTqyFiK7p9V12HUMGIuWYIe8kcJsdVF6zGf3ZcWzh5lGb4AhN4amwcot10X1dOI14FVxWeF6ZPR3ieZ7Q+nVA75cTFaree+jENM1Pb+MuFdQPMMJwuVrq2M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707165258; c=relaxed/simple; bh=N0qxgdQexW+YOk1HTnBxVMlAEbMGIRQ+C4gNI/hmAyQ=; h=References:From:To:Cc:Subject:In-reply-to:Date:Message-ID: MIME-Version:Content-Type; b=RJyfR7Kwt3EnH/hvQcnYgkb/wmGaUz7ltsBSLZZ2jLPYilasp5yHO7f2ID05Sgv683Nbu0Wytm7ZiHzg8nZxAqBrbpMYT8boz/5H/Su5B7m4Mygq23M5WTtRYdg7YIK8qbdVtWNynfBUzx8/4nJ4wbU2E2AMJfl/Gsv3JoNy92c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oltmanns.dev; spf=pass smtp.mailfrom=oltmanns.dev; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b=R2djw1HS; arc=none smtp.client-ip=80.241.56.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oltmanns.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oltmanns.dev Received: from smtp202.mailbox.org (smtp202.mailbox.org [10.196.197.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4TTJ4z2JdKz9t1g; Mon, 5 Feb 2024 21:34:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1707165251; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhbWLYxrCrQ3+gd4ivimBZHSQmaCXqHOjjg02OP3xx8=; b=R2djw1HS8bxFkt+EI/9CYDUBEevDM+VSAHffx73SoUKoK3bMJKRxs9VhkuAnCRK+JERH7Y 60alGLPy+4ai9716fWUmzZ646rdY6pgoqi1ZWH1GH9iUjc+596EwHN9Y+M9PjYqv1gP0I1 qcJfe5iGohVH86cGzU7SUJMotblba4oWxv6A0IeKoPsDdpMJj0NItuJrnukhNZ4sJaQIaR r1spiZSvnnbQm0XKfV+DqbIjLUMZAumVhScEj8JnzNyYsh9fX7KUCgjJe9nSr/1EUcdIVx 5Ma4zhFbM5OTlPpPhgWzfsiCyYyrdPp27xZhdsqVzRBBQ2KjB8cZgiOUdhodOQ== References: <20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev> <20240205-pinephone-pll-fixes-v2-3-96a46a2d8c9b@oltmanns.dev> <4543794.LvFx2qVVIh@jernej-laptop> From: Frank Oltmanns To: Jernej =?utf-8?Q?=C5=A0krabec?= Cc: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Samuel Holland , Guido =?utf-8?Q?G=C3=BCnther?= , Purism Kernel Team , Ondrej Jirman , Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: Re: [PATCH v2 3/6] clk: sunxi-ng: nkm: Support minimum and maximum rate In-reply-to: <4543794.LvFx2qVVIh@jernej-laptop> Date: Mon, 05 Feb 2024 21:34:04 +0100 Message-ID: <87eddqzm4j.fsf@oltmanns.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2024-02-05 at 18:56:09 +0100, Jernej =C5=A0krabec wrote: > Dne ponedeljek, 05. februar 2024 ob 16:22:26 CET je Frank Oltmanns napisa= l(a): >> According to the Allwinner User Manual, the Allwinner A64 requires >> PLL-MIPI to run at 500MHz-1.4GHz. Add support for that to ccu_nkm. >> >> Signed-off-by: Frank Oltmanns >> --- >> drivers/clk/sunxi-ng/ccu_nkm.c | 13 +++++++++++++ >> drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++ >> 2 files changed, 15 insertions(+) >> >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_n= km.c >> index 1168d894d636..7d135908d6e0 100644 >> --- a/drivers/clk/sunxi-ng/ccu_nkm.c >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.c >> @@ -181,6 +181,12 @@ static unsigned long ccu_nkm_round_rate(struct ccu_= mux_internal *mux, >> if (nkm->common.features & CCU_FEATURE_FIXED_POSTDIV) >> rate *=3D nkm->fixed_post_div; >> >> + if (nkm->min_rate && rate < nkm->min_rate) >> + rate =3D nkm->min_rate; >> + >> + if (nkm->max_rate && rate > nkm->max_rate) >> + rate =3D nkm->max_rate; > > Please take a look at ccu_nm_round_rate() code. You need to consider post= div > and you can return immediately. There is a difference here insofar that ccu_nm is always connected to a fixed rate parent (at least that's my understanding). Therefore, in ccu_nm_round_rate() we can be sure that the min or max rate can really be set. In ccu_nkm we don't have that luxury, we actually have to find a rate that is approximately equal to the min and max rate, based on the parent rate. Therefore, we can't return immediately. Also, I'm not sure what you mean about me needing to consider postdiv. That's what I did. The check is after multiplying with the postdiv. It's the same as in ccu_nm_round_rate() (just minus the immediate return). > >> + >> if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) >> rate =3D ccu_nkm_find_best(*parent_rate, rate, &_nkm, &nkm->common); >> else >> @@ -220,6 +226,13 @@ static int ccu_nkm_set_rate(struct clk_hw *hw, unsi= gned long rate, >> _nkm.min_m =3D 1; >> _nkm.max_m =3D nkm->m.max ?: 1 << nkm->m.width; >> >> + >> + if (nkm->min_rate && rate < nkm->min_rate) >> + rate =3D nkm->min_rate; >> + >> + if (nkm->max_rate && rate > nkm->max_rate) >> + rate =3D nkm->max_rate; >> + > > No need for this, clk subsystem calls round rate before setting actual cl= ock > rate. I'll remove the checks in V3. Best regards, Frank > > Best regards, > Jernej > >> ccu_nkm_find_best(parent_rate, rate, &_nkm, &nkm->common); >> >> spin_lock_irqsave(nkm->common.lock, flags); >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_n= km.h >> index c409212ee40e..358a9df6b6a0 100644 >> --- a/drivers/clk/sunxi-ng/ccu_nkm.h >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.h >> @@ -27,6 +27,8 @@ struct ccu_nkm { >> struct ccu_mux_internal mux; >> >> unsigned int fixed_post_div; >> + unsigned long min_rate; >> + unsigned long max_rate; >> unsigned long max_m_n_ratio; >> unsigned long min_parent_m_ratio; >> >> >>