From: Frank Oltmanns <frank@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>,
"Guido Günther" <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>
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,
Frank Oltmanns <frank@oltmanns.dev>
Subject: [PATCH 3/5] clk: sunxi-ng: nm: Support constraints on n/m ratio and parent rate
Date: Mon, 18 Dec 2023 14:35:21 +0100 [thread overview]
Message-ID: <20231218-pinephone-pll-fixes-v1-3-e238b6ed6dc1@oltmanns.dev> (raw)
In-Reply-To: <20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev>
The Allwinner A64 manual lists the following constraint for the
PLL-VIDEO0 clock: 8 <= N/M <= 25
The PLL-MIPI clock is implemented as ccu_nm. Therefore, add support for
this constraint.
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
drivers/clk/sunxi-ng/ccu_nm.c | 21 +++++++++++++++++++--
drivers/clk/sunxi-ng/ccu_nm.h | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 51 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/sunxi-ng/ccu_nm.c b/drivers/clk/sunxi-ng/ccu_nm.c
index ffac3deb89d6..cfc6981e398b 100644
--- a/drivers/clk/sunxi-ng/ccu_nm.c
+++ b/drivers/clk/sunxi-ng/ccu_nm.c
@@ -27,6 +27,19 @@ static unsigned long ccu_nm_calc_rate(unsigned long parent,
return rate;
}
+static bool ccu_nm_is_valid_rate(struct ccu_common *common, unsigned long n, unsigned long m)
+{
+ struct ccu_nm *nm = container_of(common, struct ccu_nm, common);
+
+ if (nm->max_nm_ratio && (n > nm->max_nm_ratio * m))
+ return false;
+
+ if (nm->min_nm_ratio && (n < nm->min_nm_ratio * m))
+ return false;
+
+ return true;
+}
+
static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned long parent,
unsigned long rate, struct _ccu_nm *nm)
{
@@ -36,8 +49,12 @@ static unsigned long ccu_nm_find_best(struct ccu_common *common, unsigned long p
for (_n = nm->min_n; _n <= nm->max_n; _n++) {
for (_m = nm->min_m; _m <= nm->max_m; _m++) {
- unsigned long tmp_rate = ccu_nm_calc_rate(parent,
- _n, _m);
+ unsigned long tmp_rate;
+
+ if (!ccu_nm_is_valid_rate(common, _n, _m))
+ continue;
+
+ tmp_rate = ccu_nm_calc_rate(parent, _n, _m);
if (ccu_is_better_rate(common, rate, tmp_rate, best_rate)) {
best_rate = tmp_rate;
diff --git a/drivers/clk/sunxi-ng/ccu_nm.h b/drivers/clk/sunxi-ng/ccu_nm.h
index 93c11693574f..0075df6d9697 100644
--- a/drivers/clk/sunxi-ng/ccu_nm.h
+++ b/drivers/clk/sunxi-ng/ccu_nm.h
@@ -31,6 +31,8 @@ struct ccu_nm {
unsigned int fixed_post_div;
unsigned int min_rate;
unsigned int max_rate;
+ unsigned long min_nm_ratio; /* minimum value for m/n */
+ unsigned long max_nm_ratio; /* maximum value for m/n */
struct ccu_common common;
};
@@ -108,7 +110,8 @@ struct ccu_nm {
}, \
}
-#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \
+#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT_NM_RATIO( \
+ _struct, _name, \
_parent, _reg, \
_min_rate, _max_rate, \
_nshift, _nwidth, \
@@ -117,7 +120,9 @@ struct ccu_nm {
_frac_rate_0, \
_frac_rate_1, \
_gate, _lock, _flags, \
- _features) \
+ _features, \
+ _min_nm_ratio, \
+ _max_nm_ratio) \
struct ccu_nm _struct = { \
.enable = _gate, \
.lock = _lock, \
@@ -128,6 +133,8 @@ struct ccu_nm {
_frac_rate_1), \
.min_rate = _min_rate, \
.max_rate = _max_rate, \
+ .min_nm_ratio = _min_nm_ratio, \
+ .max_nm_ratio = _max_nm_ratio, \
.common = { \
.reg = _reg, \
.features = _features, \
@@ -138,6 +145,29 @@ struct ccu_nm {
}, \
}
+#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT(_struct, _name, \
+ _parent, _reg, \
+ _min_rate, _max_rate, \
+ _nshift, _nwidth, \
+ _mshift, _mwidth, \
+ _frac_en, _frac_sel, \
+ _frac_rate_0, \
+ _frac_rate_1, \
+ _gate, _lock, _flags, \
+ _features) \
+ SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX_FEAT_NM_RATIO( \
+ _struct, _name, \
+ _parent, _reg, \
+ _min_rate, _max_rate, \
+ _nshift, _nwidth, \
+ _mshift, _mwidth, \
+ _frac_en, _frac_sel, \
+ _frac_rate_0, \
+ _frac_rate_1, \
+ _gate, _lock, _flags, \
+ _features, \
+ 0, 0)
+
#define SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK_MIN_MAX(_struct, _name, \
_parent, _reg, \
_min_rate, _max_rate, \
--
2.43.0
next prev parent reply other threads:[~2023-12-18 13:41 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-18 13:35 [PATCH 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
2023-12-18 13:35 ` [PATCH 1/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Frank Oltmanns
2023-12-18 17:26 ` Frank Oltmanns
2023-12-19 16:46 ` Jernej Škrabec
2023-12-20 6:58 ` Frank Oltmanns
2023-12-20 15:09 ` Jernej Škrabec
2023-12-18 13:35 ` [PATCH 2/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m " Frank Oltmanns
2023-12-19 16:46 ` Jernej Škrabec
2023-12-18 13:35 ` Frank Oltmanns [this message]
2023-12-19 16:52 ` [PATCH 3/5] clk: sunxi-ng: nm: Support constraints on " Jernej Škrabec
2023-12-18 13:35 ` [PATCH 4/5] clk: sunxi-ng: a64: Add constraints on PLL-VIDEO0's n/m ratio Frank Oltmanns
2023-12-19 16:54 ` Jernej Škrabec
2023-12-20 7:09 ` Frank Oltmanns
2023-12-20 15:12 ` Jernej Škrabec
2023-12-22 7:46 ` Frank Oltmanns
2023-12-31 9:10 ` Frank Oltmanns
2024-01-09 20:29 ` Jernej Škrabec
2023-12-18 13:35 ` [PATCH 5/5] drm/panel: st7703: Drive XBD599 panel at higher clock rate Frank Oltmanns
2023-12-19 17:04 ` Jernej Škrabec
2023-12-20 7:14 ` Frank Oltmanns
2023-12-20 15:18 ` Jernej Škrabec
2023-12-20 18:57 ` Frank Oltmanns
2023-12-22 9:10 ` Frank Oltmanns
2023-12-22 17:36 ` Jernej Škrabec
2023-12-30 21:17 ` Frank Oltmanns
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231218-pinephone-pll-fixes-v1-3-e238b6ed6dc1@oltmanns.dev \
--to=frank@oltmanns.dev \
--cc=agx@sigxcpu.org \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=jernej.skrabec@gmail.com \
--cc=kernel@puri.sm \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=maarten.lankhorst@linux.intel.com \
--cc=megi@xff.cz \
--cc=mripard@kernel.org \
--cc=mturquette@baylibre.com \
--cc=neil.armstrong@linaro.org \
--cc=quic_jesszhan@quicinc.com \
--cc=sam@ravnborg.org \
--cc=samuel@sholland.org \
--cc=sboyd@kernel.org \
--cc=tzimmermann@suse.de \
--cc=wens@csie.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).