Message ID | 20240205-pinephone-pll-fixes-v2-3-96a46a2d8c9b@oltmanns.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-52894-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp963670dyb; Mon, 5 Feb 2024 07:53:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEVmCXvplWCLtvpVfLHu2ovu58beUPwW2IS+jiQmJaQa8Nu3YpyUaWMha+QHaUlHHuPgQLD X-Received: by 2002:a05:6a00:92a9:b0:6e0:4e0f:62a8 with SMTP id jw41-20020a056a0092a900b006e04e0f62a8mr2432078pfb.2.1707148419515; Mon, 05 Feb 2024 07:53:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707148419; cv=pass; d=google.com; s=arc-20160816; b=G8ok3i7Xdqbm5zJmjRlG9Hb3tEynC2BQjGa/V310ZyZ3/XL+l2MDpWfvxBFk9VbeSt eEQhQwi7VNByVSSWV9IhSk5U0HWw4TCClWlzYu64Y7TRhlC98t8EfGLGeizOPn8g8QGT onh1pOnQU1C0KcxmFfIiVC9W+f/kLbEHxY29Y32qEITDC8i/pjDDYgvP+tVcLo93T8BZ B3I5OpcQszJA6zgCmq0ylphUJV8sKj5wE6DxkYX0lwRciwUi/2DnGuf+SqOuxhswlFzO H12ESRXpXVE2eAVPlmcaDrult4bg0VWrj6a/hIljWKh/K8iegL65BwDACesZ6gfq1XB9 GlYA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=jU9BjDKbdWvhuTRibGk4N23TVvjyO4DZIzgSg1oCo6o=; fh=XyzQNGTKkXmFRc7x6vMEaoDxBwwsx1peVGUXJHX7/eY=; b=uWf8wdCbPkLqm6MUje2j/b2JRxM/dK37CySDRNWByGS/jb7CXV8vIi5WwWPTj1jXCQ odLCStI6SOrw9ZRXrbNsJbiKmDLwiUmCPStlIHrLTYW2eXMQLgoxVZdZe2xC1+gx7o8+ KHJf9AWiO/yZ6BpAEb53NO6hpyl/ms+d7psi/IuPkIJerxIW5aX/8cUCnfjCES4nth4J WGcQQ81WAsJAXHS//wOEop79eyfY3NWnh6x0iHMUNaqULLq6ozSlFL6Pe+bFqOT5J3j/ U+trDD/IfOLHuNORH9ND/v66rlL6GnOHCT++yReIwNx3Lf1YLsgAyQlVZ0IGwXQOJgse PY1A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=IDaUUJ5P; 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-52894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52894-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev X-Forwarded-Encrypted: i=1; AJvYcCVIVOsuvyUDirbkV305oZP/kbKIqYMTTAQHfQYSG3/kWFdCgd3xpHNVvKyK3PHIvjlhOR5DTTJztHU2/gzycWCq2G1Rkw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id z6-20020a634c06000000b005d512d7e4b9si57381pga.690.2024.02.05.07.53.39 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 07:53:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=IDaUUJ5P; 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-52894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52894-ouuuleilei=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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 9BE10B26680 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 15:24:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B1543E486; Mon, 5 Feb 2024 15:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b="IDaUUJ5P" Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 8E0EF3A8F4; Mon, 5 Feb 2024 15:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707146595; cv=none; b=H3LR4bAPhlxlMf27GSmmeVf8dmr67choPN1ptqP+Qvue2pzlPwurHtu7GaNwDcn33ZUD8Z3iclKiCNFTphSgdZ3XzqV1XbFetGo7OXZLVxSmpbHpLo8V34t7a1W3YJOVWNMLGYOmcwF2cCQnqVhfUBKnMvIQFY5gAposaJ8IwMU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707146595; c=relaxed/simple; bh=/3dNKggDHZ8IDpHedZkuDBEbq+kfTgK2pJtlaJ3P5io=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OE/SHb8v2XNolGpNVJYHxwHDcvxYt5jA0bzMh53ZJnPPhW87BEagE8o4Gl7wrGRcjAAlqBrcTYzuH9Y+qVvVoUqU0CEEdfTiip/ww41A5n8bp9ip0InBO3qUDrLI6FCQdPnMGtolGEt1pA6MIY1lv7iLc+v/ZHZrwrpTitqVYhg= 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=IDaUUJ5P; arc=none smtp.client-ip=80.241.56.151 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 smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (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-101.mailbox.org (Postfix) with ESMTPS id 4TT9B00qv3z9sqg; Mon, 5 Feb 2024 16:23:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1707146584; 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=jU9BjDKbdWvhuTRibGk4N23TVvjyO4DZIzgSg1oCo6o=; b=IDaUUJ5PaOMkW+Dzmqmhvw1A2j2Lfq6AF6jkWqYyvuUV1mnPji1NK36FRhHisVpA1kq91J N9nQAbdp5x1uKIQ2nJMSsJBfeEHeU3Lg9wlnrwSTrGCBbbi4aekUehgkYMOuMyjdmRX9Cm /HR6dLUGcoGE9kf3JY6qhuiTgh3x5FGGw5WaK7OZ/NYc/XBo5xkaX5CJMwKyMDWdZBYdTc OXJ2OcDHedVgWThIGV1viXPs+xhuOKsRMHQoSZ2rQEguyscQBTVXgunD07NfRF2RbDin8P OhYcz/VzrOJo7cdUDvCVE+Y5ISgk6LdGAIg3AWTcgjra1KaYtxslApH5S7yN5g== From: Frank Oltmanns <frank@oltmanns.dev> Date: Mon, 05 Feb 2024 16:22:26 +0100 Subject: [PATCH v2 3/6] clk: sunxi-ng: nkm: Support minimum and maximum rate Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240205-pinephone-pll-fixes-v2-3-96a46a2d8c9b@oltmanns.dev> References: <20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev> In-Reply-To: <20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev> To: Michael Turquette <mturquette@baylibre.com>, Stephen Boyd <sboyd@kernel.org>, Chen-Yu Tsai <wens@csie.org>, Jernej Skrabec <jernej.skrabec@gmail.com>, Samuel Holland <samuel@sholland.org>, =?utf-8?q?Guido_G=C3=BCnther?= <agx@sigxcpu.org>, Purism Kernel Team <kernel@puri.sm>, Ondrej Jirman <megi@xff.cz>, Neil Armstrong <neil.armstrong@linaro.org>, Jessica Zhang <quic_jesszhan@quicinc.com>, Sam Ravnborg <sam@ravnborg.org>, Maarten Lankhorst <maarten.lankhorst@linux.intel.com>, Maxime Ripard <mripard@kernel.org>, Thomas Zimmermann <tzimmermann@suse.de>, David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Conor Dooley <conor+dt@kernel.org> Cc: 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, Frank Oltmanns <frank@oltmanns.dev> X-Developer-Signature: v=1; a=openpgp-sha256; l=1857; i=frank@oltmanns.dev; h=from:subject:message-id; bh=/3dNKggDHZ8IDpHedZkuDBEbq+kfTgK2pJtlaJ3P5io=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlwP0/R/bYRLSWDoR8LFJNAtlZjd3AuDTv0TkSy h6Q/t85+q+JAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZcD9PwAKCRCaaaIIlErT x7cUC/90hwXY99Ja4sPw6whiQKjE2ZtXg2fE1iRFw0+6vh1HBrZuuzBYjAond8O2cZhSszDwTV6 fsKjWCndURyzjCM50NZOZidj8q2F2hNxNfwzYtd2DeYxhaT7IzHpzwWiS150YVdru/4YTgc+zmm 6fePa2l5nnrf+nr1LL2371HweSyQbxUHiAzrCR2iaZhkhDpkEmRQBmkzIQRIKlLHf6TkaG1j0IQ mzbCbsCDTfewQUPHe+sRDAndVbsxwi65ZoCI5BPtDlLoW9SgJLeawQ27nR22EsgA1VR1+FqSKgt JUka8btp+cH79A2OeLbeZoKapTa3T3BcU8gYviht8L24G99WcywrYzEOKfxJkZGwaXzfXJWTzjs NjaepFV6e+z/1Xy6E7oRgHP2Ns+4brhuPhnqfwBgjK9bmo7ogE0uC9OV4JtNygG/5CDGm8IIOaO UE5j/+5B8D47kn6fIaozCmuA1f3Ti/UgXv2t63jjvvM0LYNdWpiBJf8IZ/SmdsXkpFNNU= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-Rspamd-Queue-Id: 4TT9B00qv3z9sqg X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790074860701660649 X-GMAIL-MSGID: 1790074860701660649 |
Series |
Pinephone video out fixes (flipping between two frames)
|
|
Commit Message
Frank Oltmanns
Feb. 5, 2024, 3:22 p.m. UTC
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 <frank@oltmanns.dev>
---
drivers/clk/sunxi-ng/ccu_nkm.c | 13 +++++++++++++
drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++
2 files changed, 15 insertions(+)
Comments
Dne ponedeljek, 05. februar 2024 ob 16:22:26 CET je Frank Oltmanns napisal(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 <frank@oltmanns.dev> > --- > 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_nkm.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 *= nkm->fixed_post_div; > > + if (nkm->min_rate && rate < nkm->min_rate) > + rate = nkm->min_rate; > + > + if (nkm->max_rate && rate > nkm->max_rate) > + rate = nkm->max_rate; Please take a look at ccu_nm_round_rate() code. You need to consider postdiv and you can return immediately. > + > if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) > rate = 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, unsigned long rate, > _nkm.min_m = 1; > _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; > > + > + if (nkm->min_rate && rate < nkm->min_rate) > + rate = nkm->min_rate; > + > + if (nkm->max_rate && rate > nkm->max_rate) > + rate = nkm->max_rate; > + No need for this, clk subsystem calls round rate before setting actual clock rate. 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_nkm.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; > > >
On 2024-02-05 at 18:56:09 +0100, Jernej Škrabec <jernej.skrabec@gmail.com> wrote: > Dne ponedeljek, 05. februar 2024 ob 16:22:26 CET je Frank Oltmanns napisal(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 <frank@oltmanns.dev> >> --- >> 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_nkm.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 *= nkm->fixed_post_div; >> >> + if (nkm->min_rate && rate < nkm->min_rate) >> + rate = nkm->min_rate; >> + >> + if (nkm->max_rate && rate > nkm->max_rate) >> + rate = nkm->max_rate; > > Please take a look at ccu_nm_round_rate() code. You need to consider postdiv > 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 = 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, unsigned long rate, >> _nkm.min_m = 1; >> _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; >> >> + >> + if (nkm->min_rate && rate < nkm->min_rate) >> + rate = nkm->min_rate; >> + >> + if (nkm->max_rate && rate > nkm->max_rate) >> + rate = nkm->max_rate; >> + > > No need for this, clk subsystem calls round rate before setting actual clock > 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_nkm.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; >> >> >>
Dne ponedeljek, 05. februar 2024 ob 21:34:04 CET je Frank Oltmanns napisal(a): > > On 2024-02-05 at 18:56:09 +0100, Jernej Škrabec <jernej.skrabec@gmail.com> wrote: > > Dne ponedeljek, 05. februar 2024 ob 16:22:26 CET je Frank Oltmanns napisal(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 <frank@oltmanns.dev> > >> --- > >> 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_nkm.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 *= nkm->fixed_post_div; > >> > >> + if (nkm->min_rate && rate < nkm->min_rate) > >> + rate = nkm->min_rate; > >> + > >> + if (nkm->max_rate && rate > nkm->max_rate) > >> + rate = nkm->max_rate; > > > > Please take a look at ccu_nm_round_rate() code. You need to consider postdiv > > 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. Good point. > > 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). Nevermind, this applies only for immediate return. Best regards, Jernej > > > > >> + > >> if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) > >> rate = 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, unsigned long rate, > >> _nkm.min_m = 1; > >> _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; > >> > >> + > >> + if (nkm->min_rate && rate < nkm->min_rate) > >> + rate = nkm->min_rate; > >> + > >> + if (nkm->max_rate && rate > nkm->max_rate) > >> + rate = nkm->max_rate; > >> + > > > > No need for this, clk subsystem calls round rate before setting actual clock > > 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_nkm.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; > >> > >> > >> >
On Mon, Feb 05, 2024 at 04:22:26PM +0100, Frank Oltmanns wrote: > 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 <frank@oltmanns.dev> > --- > 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_nkm.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 *= nkm->fixed_post_div; > > + if (nkm->min_rate && rate < nkm->min_rate) > + rate = nkm->min_rate; > + > + if (nkm->max_rate && rate > nkm->max_rate) > + rate = nkm->max_rate; > + This is provided by the clock range already. If you call clk_hw_set_rate_range, it should work just fine. Maxime
Hi Maxime, On 2024-02-08 at 13:16:27 +0100, Maxime Ripard <mripard@kernel.org> wrote: > [[PGP Signed Part:Undecided]] > On Mon, Feb 05, 2024 at 04:22:26PM +0100, Frank Oltmanns wrote: >> 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 <frank@oltmanns.dev> >> --- >> 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_nkm.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 *= nkm->fixed_post_div; >> >> + if (nkm->min_rate && rate < nkm->min_rate) >> + rate = nkm->min_rate; >> + >> + if (nkm->max_rate && rate > nkm->max_rate) >> + rate = nkm->max_rate; >> + > > This is provided by the clock range already. If you call > clk_hw_set_rate_range, it should work just fine. I have to admit, that I don't know that much about sunxi-ng or the CCF and therefore humbly request some guidance. I've looked at other examples of clk_hw_set_rate_range() usage and it seems there is not a lot of adoption for this functionality even though it was already introduced mid-2015. This makes me wonder, why that is. Anyhow, it seems in all examples I found, clk_hw_set_rate_range() is called immediately after registering the clk_hw. So, in the case of sunxi-ng, we'd need to do that in sunxi_ccu_probe, which is a common function for all sunxi-ng clock types. Correct? If so, surely, you don't want me to introduce clock type specific code to a common function, so I assume you want min_rate and max_rate to become members of struct ccu_common. Correct? If so, since there already are some clock types in sunxi-ng that support having a minimum and maximum rate, these clocks should be refactored eventually. Correct? Finally, in sunxi-ng there is a feature of having a fixed_post_div (see, e.g., the first to lines of the diff above). It seems to me that CCF cannot know about these post_divs, so we'd also need to transfer the fixed_post_div to ccu_common and use that when calling clk_hw_set_rate_range. Correct? The fact that you casually dropped the two sentences above and me deducing you want a somewhat large refactoring of the functionality for sunxi-ng, makes me wonder if I completely misunderstood your request. Best regards, Frank > > Maxime > > [[End of PGP Signed Part]]
Hi Jernej, hi Maxime, On 2024-02-05 at 16:22:26 +0100, Frank Oltmanns <frank@oltmanns.dev> wrote: > 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. I should point out that limiting PLL-MIPI also fixes a regression that was introduced in 6.5, specifically ca1170b69968233b34d26432245eddf7d265186b "clk: sunxi-ng: a64: force select PLL_MIPI in TCON0 mux". This has been bisected and reported by Diego [1]. I don't know the procedure (yet), but probably the fix (if and when accepted) should be backported at least to 6.6 (first broken LTS), 6.7 (stable), and 6.8 (next stable). My suggestion: - In V3 of this series, I will reorder the patches, so that what is now PATCH 3 and 4 becomes 1 and 2 respectively, so that they can be applied to 6.6 more easily. - Maxime, IIUC you requested some refactoring for handling the rate limits [2]. I propose, we use my current proposal as-is, and I will do a follow-up series for the refactoring. Please let me know how you would like me to proceed. Thanks, Frank [1]: https://groups.google.com/g/linux-sunxi/c/Rh-Uqqa66bw [2]: https://lore.kernel.org/all/exb2lvjcozak5fayrgyenrd3ntii4jfxgvqork4klyz5pky2aq@dj2zyw5su6pv/ > > Signed-off-by: Frank Oltmanns <frank@oltmanns.dev> > --- > 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_nkm.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 *= nkm->fixed_post_div; > > + if (nkm->min_rate && rate < nkm->min_rate) > + rate = nkm->min_rate; > + > + if (nkm->max_rate && rate > nkm->max_rate) > + rate = nkm->max_rate; > + > if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) > rate = 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, unsigned long rate, > _nkm.min_m = 1; > _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; > > + > + if (nkm->min_rate && rate < nkm->min_rate) > + rate = nkm->min_rate; > + > + if (nkm->max_rate && rate > nkm->max_rate) > + rate = nkm->max_rate; > + > 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_nkm.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;
Hi, On Sun, Feb 18, 2024 at 09:29:15AM +0100, Frank Oltmanns wrote: > Hi Maxime, > > On 2024-02-08 at 13:16:27 +0100, Maxime Ripard <mripard@kernel.org> wrote: > > [[PGP Signed Part:Undecided]] > > On Mon, Feb 05, 2024 at 04:22:26PM +0100, Frank Oltmanns wrote: > >> 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 <frank@oltmanns.dev> > >> --- > >> 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_nkm.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 *= nkm->fixed_post_div; > >> > >> + if (nkm->min_rate && rate < nkm->min_rate) > >> + rate = nkm->min_rate; > >> + > >> + if (nkm->max_rate && rate > nkm->max_rate) > >> + rate = nkm->max_rate; > >> + > > > > This is provided by the clock range already. If you call > > clk_hw_set_rate_range, it should work just fine. > > I have to admit, that I don't know that much about sunxi-ng or the CCF > and therefore humbly request some guidance. > > I've looked at other examples of clk_hw_set_rate_range() usage and it > seems there is not a lot of adoption for this functionality even though > it was already introduced mid-2015. This makes me wonder, why that is. There's no reason, really. I would expect a big part of it to be "if it works don't fix it" :) > Anyhow, it seems in all examples I found, clk_hw_set_rate_range() is > called immediately after registering the clk_hw. So, in the case of > sunxi-ng, we'd need to do that in sunxi_ccu_probe, which is a common > function for all sunxi-ng clock types. Correct? Yup. > If so, surely, you don't want me to introduce clock type specific code > to a common function, so I assume you want min_rate and max_rate to > become members of struct ccu_common. Correct? Yes, that would be reasonable indeed. > If so, since there already are some clock types in sunxi-ng that support > having a minimum and maximum rate, these clocks should be refactored > eventually. Correct? I guess. I don't consider it to be a pre-requisite to your patch though. > Finally, in sunxi-ng there is a feature of having a fixed_post_div (see, > e.g., the first to lines of the diff above). It seems to me that CCF > cannot know about these post_divs, so we'd also need to transfer the > fixed_post_div to ccu_common and use that when calling > clk_hw_set_rate_range. Correct? Not really, no. The fixed post divider is an additional divider that needs to be considered for the clock rate. See the A64's periph0 PLL for example. Its fixed post divider is 2, and its rate is 24MHz * N * K / 2. The rate should be bounded by its minimal and maximal rate taking the post divider into account. The CCF doesn't have to know about it. Maxime
On Wed, Feb 21, 2024 at 11:38:39AM +0100, Frank Oltmanns wrote: > Hi Jernej, > hi Maxime, > > On 2024-02-05 at 16:22:26 +0100, Frank Oltmanns <frank@oltmanns.dev> wrote: > > 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. > > I should point out that limiting PLL-MIPI also fixes a regression > that was introduced in 6.5, specifically > ca1170b69968233b34d26432245eddf7d265186b "clk: sunxi-ng: a64: force > select PLL_MIPI in TCON0 mux". This has been bisected and reported by > Diego [1]. > > I don't know the procedure (yet), but probably the fix (if and when > accepted) should be backported at least to 6.6 (first broken LTS), 6.7 > (stable), and 6.8 (next stable). https://www.kernel.org/doc/html/next/process/stable-kernel-rules.html#procedure-for-submitting-patches-to-the-stable-tree > My suggestion: > - In V3 of this series, I will reorder the patches, so that what is now > PATCH 3 and 4 becomes 1 and 2 respectively, so that they can be > applied to 6.6 more easily. > - Maxime, IIUC you requested some refactoring for handling the rate > limits [2]. I propose, we use my current proposal as-is, and I will > do a follow-up series for the refactoring. I'd really like to not introduce a new ad-hoc implementation of range handling. It's fine for older users to not be converted yet, but we shouldn't introduce more users. Maxime
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.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 *= nkm->fixed_post_div; + if (nkm->min_rate && rate < nkm->min_rate) + rate = nkm->min_rate; + + if (nkm->max_rate && rate > nkm->max_rate) + rate = nkm->max_rate; + if (!clk_hw_can_set_rate_parent(&nkm->common.hw)) rate = 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, unsigned long rate, _nkm.min_m = 1; _nkm.max_m = nkm->m.max ?: 1 << nkm->m.width; + + if (nkm->min_rate && rate < nkm->min_rate) + rate = nkm->min_rate; + + if (nkm->max_rate && rate > nkm->max_rate) + rate = nkm->max_rate; + 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_nkm.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;