From: "Jernej Škrabec" <jernej.skrabec@gmail.com>
To: Frank Oltmanns <frank@oltmanns.dev>
Cc: "Michael Turquette" <mturquette@baylibre.com>,
"Stephen Boyd" <sboyd@kernel.org>, "Chen-Yu Tsai" <wens@csie.org>,
"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>,
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
Subject: Re: [PATCH 1/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate
Date: Wed, 20 Dec 2023 16:09:55 +0100 [thread overview]
Message-ID: <23332183.6Emhk5qWAg@jernej-laptop> (raw)
In-Reply-To: <87msu59wrc.fsf@oltmanns.dev>
Dne sreda, 20. december 2023 ob 07:58:07 CET je Frank Oltmanns napisal(a):
> Hi Jernej!
>
> On 2023-12-19 at 17:46:08 +0100, Jernej Škrabec <jernej.skrabec@gmail.com> wrote:
> > Hi Frank!
> >
> > Dne ponedeljek, 18. december 2023 ob 14:35:19 CET je Frank Oltmanns napisal(a):
> >> The Allwinner A64 manual lists the following constraints for the
> >> PLL-MIPI clock:
> >> - M/N >= 3
> >
> > This should be "<="
>
> Yes, good catch! I will fix it in V2.
>
> >
> >> - (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 | 23 +++++++++++++++++++++++
> >> drivers/clk/sunxi-ng/ccu_nkm.h | 8 ++++++++
> >> 2 files changed, 31 insertions(+)
> >>
> >> diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c
> >> index eed64547ad42..2af5c1ebd527 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_mn_ratio && (m > nkm->max_mn_ratio * n))
> >> + return false;
> >> +
> >> + if (nkm->parent_wo_nk && (parent < nkm->parent_wo_nk * 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,
> >> @@ -32,6 +46,9 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common
> >>
> >> 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) ||
> >> @@ -65,6 +82,12 @@ 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 ((common->reg == 0x040) && (_m > 3 * _n))
> >> + break;
> >> +
> >> + if ((common->reg == 0x040) && (parent < 24000000 * _m))
> >> + continue;
> >> +
> >
> > You already figured this part.
> >
> >> 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..d3d3eaf55faf 100644
> >> --- a/drivers/clk/sunxi-ng/ccu_nkm.h
> >> +++ b/drivers/clk/sunxi-ng/ccu_nkm.h
> >> @@ -16,6 +16,12 @@
> >> * struct ccu_nkm - Definition of an N-K-M clock
> >> *
> >> * Clocks based on the formula parent * N * K / M
> >> + *
> >> + * @max_mn_ratio: Maximum value for M / N.
> >> + * @parent_wo_nk: The minimum rate the parent must provide after applying the divisor,
> >> + * but without applying the multipliers, i.e. the contstraint
> >> + * (parent rate)/M >= parent_wo_nk
> >> + * must be fulfilled.
> >> */
> >> struct ccu_nkm {
> >> u32 enable;
> >> @@ -27,6 +33,8 @@ struct ccu_nkm {
> >> struct ccu_mux_internal mux;
> >>
> >> unsigned int fixed_post_div;
> >> + unsigned long max_mn_ratio;
> >> + unsigned long parent_wo_nk;
> >
> > What about max_m_n_ratio and max_parent_m_ratio, to be consistent? This
> > should also allow to simplify description.
>
> Jernej, thank you so much! This is brilliant! I was racking my brain for
> a good name but failed. Now, that I see your proposal, I don't know why
> I hadn't come up with it. It's the obvious choice.
>
> I'd say with the new names we should be able to get rid of the comments
> describing the new struct members (also in ccu_nm.h). What are your
> thoughts on that?
Ah, I missed that only new ones are documented. Yeah, you can skip it.
Best regards,
Jernej
>
> Best regards,
> Frank
>
> >
> > Best regards,
> > Jernej
> >
> >>
> >> struct ccu_common common;
> >> };
> >>
> >>
>
next prev parent reply other threads:[~2023-12-20 15:10 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 [this message]
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 ` [PATCH 3/5] clk: sunxi-ng: nm: Support constraints on " Frank Oltmanns
2023-12-19 16:52 ` 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=23332183.6Emhk5qWAg@jernej-laptop \
--to=jernej.skrabec@gmail.com \
--cc=agx@sigxcpu.org \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=frank@oltmanns.dev \
--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).