Message ID | 20240205-pinephone-pll-fixes-v2-1-96a46a2d8c9b@oltmanns.dev |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-52891-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp945788dyb; Mon, 5 Feb 2024 07:23:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlfajqW9aEF3qmTWb/4dLTxeakp/AZi0L+2oAtVJf3Uf11ALJrt0mUlHPtLEX5ha6cLFq0 X-Received: by 2002:a2e:b1c4:0:b0:2d0:b537:60ed with SMTP id e4-20020a2eb1c4000000b002d0b53760edmr36059lja.12.1707146632958; Mon, 05 Feb 2024 07:23:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707146632; cv=pass; d=google.com; s=arc-20160816; b=sY6Wl73x5iqMQwGOyQrU6XmwhG+Gh4kHYx/+qTV2JlxrCp3X/1o5R4iNTFr7hYQuEQ XREqJIRJ0avcfdUOYW9xCNA7FkIDheCDg0Lz5+ticgsOqZ2xPY/2A6pfL9L8etb433cj 30YSKKM+7qsuEpUfcZN9VrCn/4cmRU1RwghqcAlGAWUQJghBCLQHY+wZdhFGuvfqWZb0 ut+yEGffevnD9mtP4NvzPFN3+4LQPf1+lITDujLCbkKfFUHlc0B2SqhibbA8UbeqXZj3 OMwPi1D1NBP4ASuwoUgFBr/luesSR2QhPFPt2xSJfbAx/YizCJzVNPlWZwjzvzLtzGiT 1evQ== 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=uta2Nryx0fYmEgPuIsmh9A9sOCuB/mTE4m8nKAVHA8Q=; fh=PyDcK7tV1OqZmgSMi+shcuBqrcBx2qIEvg/FuoPTlYI=; b=OB/J4ZukBJx6RAgnYNveh0w+G3k9VYCvXPBYeoLu3p785W13d4rac3ofXTbXN/PXcn spNMo0LjlqAE1sPk6Yp4sFpD7tT+KnKZhUSColIVZyPpIQOnvG9sXOjpTg0hfl/z/M3G qJ5EbHHOG/ESoWayNt+yVQGh5yH9crzmekDoYN2t1hxW2l/OKhEwO9xfAKkuBLb/ohUz 3M+I5M+e0NeMCzckNLV4d/EIXycAu7SS/IwjR2ejmejVWPg0A9Q/e9/NDxn3vCT4FcEF /7op4qzXXT6/UZHNDwHpp7NPgBnZw9+UtYgjeboFC48dUjKx/9DVYc4qYid95jlTHZm9 skjg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=lsJ7xPwS; 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-52891-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52891-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oltmanns.dev X-Forwarded-Encrypted: i=1; AJvYcCWrl0KMAQrd2S1IRKk0yrL1KzGcb9hYDyDxVVCah3mlNBjt3g5hxmYdixSrGkxY/IdP97Wni3HJmQhlAnfmqfts1iS7Gw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l21-20020aa7d955000000b0055feedbf264si3915976eds.470.2024.02.05.07.23.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 07:23:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-52891-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@oltmanns.dev header.s=MBO0001 header.b=lsJ7xPwS; 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-52891-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-52891-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 am.mirrors.kernel.org (Postfix) with ESMTPS id D7FBB1F221F5 for <ouuuleilei@gmail.com>; Mon, 5 Feb 2024 15:23:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5DFF035F0C; Mon, 5 Feb 2024 15:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oltmanns.dev header.i=@oltmanns.dev header.b="lsJ7xPwS" Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 5CBA92D050; Mon, 5 Feb 2024 15:23:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707146584; cv=none; b=uOihlYp4Vss7gp6crHDGCRQvQK+9y2nZ/UpSFMIcQ60HRUu5pbtGE7c1ufsxtoMfzXKWxiNg7QOcLE1LfhIakgOjFm50FcFsus9r5GucvJ2N8+jHQX2GEBppsp5se/2S9JEpzFX3w1TeJs72fZC/XH5g5LjBLaK4/LorAD6rrtQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707146584; c=relaxed/simple; bh=SMz7oXCauq2UtH/EdNshDEESJjkCnkK/ixNVXPl/TYE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a5sqMPc7poND7mhwQqx/pQ0BFDilmkxv25Fc530mvOWC64D1wfx3L6qjpREZiTkHGd8WlTYAOsLSgbUUuQ3ki3MYaQMIxaBXSoctckuXg+ts95yvODwbzgZPJ/HwYdVngkyKX/+UUclRra9T3Ta5a1lt37uSzc3l4r6xcsa9OQ8= 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=lsJ7xPwS; arc=none smtp.client-ip=80.241.56.171 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 [10.196.197.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-201.mailbox.org (Postfix) with ESMTPS id 4TT99m6LV3z9t3f; Mon, 5 Feb 2024 16:22:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oltmanns.dev; s=MBO0001; t=1707146572; 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=uta2Nryx0fYmEgPuIsmh9A9sOCuB/mTE4m8nKAVHA8Q=; b=lsJ7xPwSdL7B4+pW5JQoBa6ENjytk87Ee0zBakVyxREbgOL2C9gYzXJeDDZRMbgD/qWdQq mwg5aeXNeIzoxIKw2LxUVZ441guKRszDAcVXXTDPjX3utFo/UTOfLuHUZY5Enf/ZW7hpjS Zx0MI/tfdJyVeLHMZzTtLFPiJo7sQHo9txDOkcC6npxzMowoj+EP8Narobrcsm2gIlz9BI 0muEV9WrFEWOwFiaM77bQgxbR1hFiV6h+HBjPaCrQpaSVyN+PEkdo7WDpF12IgGT/HR15q JU5CkoOGdD9oUJr/wGfx1pspbYRnzO64z9VAAA3aR8oZddnODhXNpDgZ2ppuaw== From: Frank Oltmanns <frank@oltmanns.dev> Date: Mon, 05 Feb 2024 16:22:24 +0100 Subject: [PATCH v2 1/6] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent 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-1-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=2525; i=frank@oltmanns.dev; h=from:subject:message-id; bh=SMz7oXCauq2UtH/EdNshDEESJjkCnkK/ixNVXPl/TYE=; b=owEB7QES/pANAwAIAZppogiUStPHAcsmYgBlwP0+pe4JnotZRs/UXF6HlNDa9bl3VgkiZTM5l VEOUAv9h1KJAbMEAAEIAB0WIQQC/SV7f5DmuaVET5aaaaIIlErTxwUCZcD9PgAKCRCaaaIIlErT xwlIC/9hxvGWs1GKMhVzxbaLGtyJWEFaVNQr/lzeqPpbqBCYwSOV7ckyAre1awUZ4uAEAp8GanA nDGgiORBExs5h1YYGQz0MD8ETP4OlPQndoEuXT8uaAPKHpNoPp/pjsAwBvrcjDIQ+1BWeOli9ZY r+NmL0jCdaGn98KSlLJKBcdlxLEt4Ywr+KPPuBH1sAdRdXOiw2K4smqlFs9QqD+5COCTF77i7sz LwpF8Awp+DyrobksONjAMf5F9tr8fvL3V/0HaMdYNchBXM7oLJUlvFGzRwSACUNxO/o59bHYu1N 9x9kkChfsztI65nTzq1CVTGyuAomU+Fwh008WXOnQ86gFRwJdywtOr4Omkbk8oFz5XVF2x9jgwB 8KcFHIfLwp7bSBqkmYDYEjAdgTKYvtJHfmR1uEChNJ7Mo6nJSY8fsiHG42eI+aovsapCCme+hO1 PoIeFzFK/l6aw12HdOY4xCBZpNbpy0f1FtS2gvYFoEEkHI8oN2LSIBaRjA89ONrBWZjuU= X-Developer-Key: i=frank@oltmanns.dev; a=openpgp; fpr=02FD257B7F90E6B9A5444F969A69A208944AD3C7 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790072987737784992 X-GMAIL-MSGID: 1790072987737784992 |
Series |
Pinephone video out fixes (flipping between two frames)
|
|
Commit Message
Frank Oltmanns
Feb. 5, 2024, 3:22 p.m. UTC
The Allwinner A64 manual lists the following constraints for the
PLL-MIPI clock:
- M/N <= 3
- (PLL_VIDEO0)/M >= 24MHz
The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for
these constraints.
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++
drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++
2 files changed, 23 insertions(+)
Comments
Dne ponedeljek, 05. februar 2024 ob 16:22:24 CET je Frank Oltmanns napisal(a): > The Allwinner A64 manual lists the following constraints for the > PLL-MIPI clock: > - M/N <= 3 > - (PLL_VIDEO0)/M >= 24MHz > > The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for > these constraints. > > Signed-off-by: Frank Oltmanns <frank@oltmanns.dev> Haven't we discussed that this patch is unnecessary because same effect can be reached by limiting minimum frequency? Best regards, Jernej > --- > drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++ > drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++ > 2 files changed, 23 insertions(+) > > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c > index 853f84398e2b..1168d894d636 100644 > --- a/drivers/clk/sunxi-ng/ccu_nkm.c > +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > @@ -16,6 +16,20 @@ struct _ccu_nkm { > unsigned long m, min_m, max_m; > }; > > +static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent, > + unsigned long n, unsigned long m) > +{ > + struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common); > + > + if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n)) > + return false; > + > + if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m)) > + return false; > + > + return true; > +} > + > 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, > @@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common > unsigned long tmp_rate, tmp_parent; > > tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); > + > + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) > + continue; > + > tmp_rate = tmp_parent * _n * _k / _m; > > if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || > @@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, > for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { > for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { > for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { > + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) > + continue; > + > unsigned long tmp_rate; > > tmp_rate = parent * _n * _k / _m; > diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h > index 6601defb3f38..c409212ee40e 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 max_m_n_ratio; > + unsigned long min_parent_m_ratio; > > struct ccu_common common; > }; > >
Hi Jernej, On 2024-02-05 at 18:45:27 +0100, Jernej Škrabec <jernej.skrabec@gmail.com> wrote: > Dne ponedeljek, 05. februar 2024 ob 16:22:24 CET je Frank Oltmanns napisal(a): >> The Allwinner A64 manual lists the following constraints for the >> PLL-MIPI clock: >> - M/N <= 3 >> - (PLL_VIDEO0)/M >= 24MHz >> >> The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for >> these constraints. >> >> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev> > > Haven't we discussed that this patch is unnecessary because same effect can > be reached by limiting minimum frequency? The patch for ccu_nm was unnecessary: https://lore.kernel.org/all/87jzoug2jz.fsf@oltmanns.dev/ Unfortunately, we still need this one. Best regards, Frank > > Best regards, > Jernej > >> --- >> drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++ >> drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++ >> 2 files changed, 23 insertions(+) >> >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c >> index 853f84398e2b..1168d894d636 100644 >> --- a/drivers/clk/sunxi-ng/ccu_nkm.c >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.c >> @@ -16,6 +16,20 @@ struct _ccu_nkm { >> unsigned long m, min_m, max_m; >> }; >> >> +static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent, >> + unsigned long n, unsigned long m) >> +{ >> + struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common); >> + >> + if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n)) >> + return false; >> + >> + if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m)) >> + return false; >> + >> + return true; >> +} >> + >> 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, >> @@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common >> unsigned long tmp_rate, tmp_parent; >> >> tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); >> + >> + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) >> + continue; >> + >> tmp_rate = tmp_parent * _n * _k / _m; >> >> if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || >> @@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, >> for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { >> for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { >> for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { >> + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) >> + continue; >> + >> unsigned long tmp_rate; >> >> tmp_rate = parent * _n * _k / _m; >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h >> index 6601defb3f38..c409212ee40e 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 max_m_n_ratio; >> + unsigned long min_parent_m_ratio; >> >> struct ccu_common common; >> }; >> >>
Dne ponedeljek, 05. februar 2024 ob 18:50:27 CET je Frank Oltmanns napisal(a): > Hi Jernej, > > On 2024-02-05 at 18:45:27 +0100, Jernej Škrabec <jernej.skrabec@gmail.com> wrote: > > Dne ponedeljek, 05. februar 2024 ob 16:22:24 CET je Frank Oltmanns napisal(a): > >> The Allwinner A64 manual lists the following constraints for the > >> PLL-MIPI clock: > >> - M/N <= 3 > >> - (PLL_VIDEO0)/M >= 24MHz > >> > >> The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for > >> these constraints. > >> > >> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev> > > > > Haven't we discussed that this patch is unnecessary because same effect can > > be reached by limiting minimum frequency? > > The patch for ccu_nm was unnecessary: > https://lore.kernel.org/all/87jzoug2jz.fsf@oltmanns.dev/ > > Unfortunately, we still need this one. Ok, then: Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com> Best regards, Jernej > > Best regards, > Frank > > > > > Best regards, > > Jernej > > > >> --- > >> drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++ > >> drivers/clk/sunxi-ng/ccu_nkm.h | 2 ++ > >> 2 files changed, 23 insertions(+) > >> > >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c > >> index 853f84398e2b..1168d894d636 100644 > >> --- a/drivers/clk/sunxi-ng/ccu_nkm.c > >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.c > >> @@ -16,6 +16,20 @@ struct _ccu_nkm { > >> unsigned long m, min_m, max_m; > >> }; > >> > >> +static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent, > >> + unsigned long n, unsigned long m) > >> +{ > >> + struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common); > >> + > >> + if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n)) > >> + return false; > >> + > >> + if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m)) > >> + return false; > >> + > >> + return true; > >> +} > >> + > >> 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, > >> @@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common > >> unsigned long tmp_rate, tmp_parent; > >> > >> tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); > >> + > >> + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) > >> + continue; > >> + > >> tmp_rate = tmp_parent * _n * _k / _m; > >> > >> if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || > >> @@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, > >> for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { > >> for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { > >> for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { > >> + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) > >> + continue; > >> + > >> unsigned long tmp_rate; > >> > >> tmp_rate = parent * _n * _k / _m; > >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h > >> index 6601defb3f38..c409212ee40e 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 max_m_n_ratio; > >> + unsigned long min_parent_m_ratio; > >> > >> struct ccu_common common; > >> }; > >> > >> >
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c index 853f84398e2b..1168d894d636 100644 --- a/drivers/clk/sunxi-ng/ccu_nkm.c +++ b/drivers/clk/sunxi-ng/ccu_nkm.c @@ -16,6 +16,20 @@ struct _ccu_nkm { unsigned long m, min_m, max_m; }; +static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent, + unsigned long n, unsigned long m) +{ + struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common); + + if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n)) + return false; + + if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m)) + return false; + + return true; +} + 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, @@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common unsigned long tmp_rate, tmp_parent; tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k)); + + if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m)) + continue; + tmp_rate = tmp_parent * _n * _k / _m; if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) || @@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate, for (_k = nkm->min_k; _k <= nkm->max_k; _k++) { for (_n = nkm->min_n; _n <= nkm->max_n; _n++) { for (_m = nkm->min_m; _m <= nkm->max_m; _m++) { + if (!ccu_nkm_is_valid_rate(common, parent, _n, _m)) + continue; + unsigned long tmp_rate; tmp_rate = parent * _n * _k / _m; diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h index 6601defb3f38..c409212ee40e 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 max_m_n_ratio; + unsigned long min_parent_m_ratio; struct ccu_common common; };