From: Abel Vesa <abel.vesa@nxp.com>
To: Leonard Crestez <leonard.crestez@nxp.com>
Cc: Alexandre Bailon <abailon@baylibre.com>,
Georgi Djakov <georgi.djakov@linaro.org>,
Stephen Boyd <sboyd@kernel.org>,
Michael Turquette <mturquette@baylibre.com>,
Viresh Kumar <viresh.kumar@linaro.org>,
MyungJoo Ham <myungjoo.ham@samsung.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
Shawn Guo <shawnguo@kernel.org>,
Aisheng Dong <aisheng.dong@nxp.com>,
Fabio Estevam <fabio.estevam@nxp.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Jacky Bai <ping.bai@nxp.com>, Anson Huang <anson.huang@nxp.com>,
Krzysztof Kozlowski <krzk@kernel.org>,
Ulf Hansson <ulf.hansson@linaro.org>,
Saravana Kannan <saravanak@google.com>,
"kernel@pengutronix.de" <kernel@pengutronix.de>,
dl-linux-imx <linux-imx@nxp.com>,
"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFCv2 2/8] clk: imx8m-composite: Switch to determine_rate
Date: Fri, 28 Jun 2019 08:45:22 +0000 [thread overview]
Message-ID: <20190628084521.d64d5g54zvxlsxsl@fsr-ub1664-175> (raw)
In-Reply-To: <5d62b31309e6402bd9fa608730518b39af823fb3.1561707104.git.leonard.crestez@nxp.com>
On 19-06-28 10:39:50, Leonard Crestez wrote:
> This allows consumers to use min_rate max_rate.
>
> Signed-off-by: Leonard Crestez <leonard.crestez@nxp.com>
> ---
> drivers/clk/imx/clk-composite-8m.c | 34 +++++++++++++++++++-----------
> 1 file changed, 22 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c
> index 388bdb94f841..1be82ec08ecd 100644
> --- a/drivers/clk/imx/clk-composite-8m.c
> +++ b/drivers/clk/imx/clk-composite-8m.c
> @@ -45,10 +45,12 @@ static unsigned long imx8m_clk_composite_divider_recalc_rate(struct clk_hw *hw,
> divider->flags, PCG_DIV_WIDTH);
> }
>
> static int imx8m_clk_composite_compute_dividers(unsigned long rate,
> unsigned long parent_rate,
> + unsigned long min_rate,
> + unsigned long max_rate,
You should pass on the req instead of min_rate and max_rate here.
> int *prediv, int *postdiv)
> {
> int div1, div2;
> int error = INT_MAX;
> int ret = -EINVAL;
> @@ -56,11 +58,17 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
> *prediv = 1;
> *postdiv = 1;
>
> for (div1 = 1; div1 <= PCG_PREDIV_MAX; div1++) {
> for (div2 = 1; div2 <= PCG_DIV_MAX; div2++) {
> - int new_error = ((parent_rate / div1) / div2) - rate;
> + unsigned long new_rate;
> + int new_error;
> +
> + new_rate = ((parent_rate / div1) / div2);
> + if (new_rate < min_rate || new_rate > max_rate)
> + continue;
> + new_error = new_rate - rate;
>
> if (abs(new_error) < abs(error)) {
> *prediv = div1;
> *postdiv = div2;
> error = new_error;
> @@ -69,38 +77,40 @@ static int imx8m_clk_composite_compute_dividers(unsigned long rate,
> }
> }
> return ret;
> }
>
> -static long imx8m_clk_composite_divider_round_rate(struct clk_hw *hw,
> - unsigned long rate,
> - unsigned long *prate)
> +static int imx8m_clk_composite_divider_determine_rate(struct clk_hw *hw,
> + struct clk_rate_request *req)
> {
> int prediv_value;
> int div_value;
>
> - imx8m_clk_composite_compute_dividers(rate, *prate,
> - &prediv_value, &div_value);
> - rate = DIV_ROUND_UP(*prate, prediv_value);
> + imx8m_clk_composite_compute_dividers(req->rate, req->best_parent_rate,
> + req->min_rate, req->max_rate,
> + &prediv_value, &div_value);
>
> - return DIV_ROUND_UP(rate, div_value);
> + req->rate = DIV_ROUND_UP(req->best_parent_rate, prediv_value);
> + req->rate = DIV_ROUND_UP(req->rate, div_value);
>
> + return 0;
> }
>
> static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
> - unsigned long rate,
> - unsigned long parent_rate)
> + unsigned long rate,
> + unsigned long parent_rate)
> {
> struct clk_divider *divider = to_clk_divider(hw);
> unsigned long flags = 0;
> int prediv_value;
> int div_value;
> int ret;
> u32 val;
>
> ret = imx8m_clk_composite_compute_dividers(rate, parent_rate,
> - &prediv_value, &div_value);
> + 0, ULONG_MAX,
> + &prediv_value, &div_value);
> if (ret)
> return -EINVAL;
>
> spin_lock_irqsave(divider->lock, flags);
>
> @@ -117,11 +127,11 @@ static int imx8m_clk_composite_divider_set_rate(struct clk_hw *hw,
> return ret;
> }
>
> static const struct clk_ops imx8m_clk_composite_divider_ops = {
> .recalc_rate = imx8m_clk_composite_divider_recalc_rate,
> - .round_rate = imx8m_clk_composite_divider_round_rate,
> + .determine_rate = imx8m_clk_composite_divider_determine_rate,
> .set_rate = imx8m_clk_composite_divider_set_rate,
> };
>
> struct clk *imx8m_clk_composite_flags(const char *name,
> const char * const *parent_names,
> --
> 2.17.1
>
next prev parent reply other threads:[~2019-06-28 8:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 7:39 [RFCv2 0/8] Add imx8mm bus frequency switching Leonard Crestez
2019-06-28 7:39 ` [RFCv2 1/8] clk: imx8mm: Add dram freq switch support Leonard Crestez
2019-06-28 7:39 ` [RFCv2 2/8] clk: imx8m-composite: Switch to determine_rate Leonard Crestez
2019-06-28 8:45 ` Abel Vesa [this message]
2019-06-28 8:56 ` Leonard Crestez
2019-07-02 7:13 ` Abel Vesa
2019-06-28 7:39 ` [RFCv2 3/8] arm64: dts: imx8mm: Add dram dvfs irqs to ccm node Leonard Crestez
2019-06-28 7:39 ` [RFCv2 4/8] interconnect: Add generic driver for imx Leonard Crestez
2019-06-28 7:39 ` [RFCv2 5/8] interconnect: imx: Add platform driver for imx8mm Leonard Crestez
2019-06-28 7:39 ` [RFCv2 6/8] devfreq: Add imx-devfreq driver Leonard Crestez
2019-07-03 1:31 ` Chanwoo Choi
2019-06-28 7:39 ` [RFCv2 7/8] arm64: dts: imx8mm: Add interconnect node Leonard Crestez
2019-06-28 7:39 ` [RFCv2 8/8] arm64: dts: imx8mm: Add devfreq-imx nodes Leonard Crestez
2019-07-03 22:19 ` [RFCv2 0/8] Add imx8mm bus frequency switching Saravana Kannan
2019-07-03 23:30 ` Leonard Crestez
2019-07-04 3:02 ` Saravana Kannan
2019-07-04 8:32 ` Leonard Crestez
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=20190628084521.d64d5g54zvxlsxsl@fsr-ub1664-175 \
--to=abel.vesa@nxp.com \
--cc=abailon@baylibre.com \
--cc=aisheng.dong@nxp.com \
--cc=anson.huang@nxp.com \
--cc=fabio.estevam@nxp.com \
--cc=georgi.djakov@linaro.org \
--cc=kernel@pengutronix.de \
--cc=krzk@kernel.org \
--cc=kyungmin.park@samsung.com \
--cc=leonard.crestez@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-imx@nxp.com \
--cc=linux-pm@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=myungjoo.ham@samsung.com \
--cc=ping.bai@nxp.com \
--cc=rafael@kernel.org \
--cc=saravanak@google.com \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
--cc=ulf.hansson@linaro.org \
--cc=viresh.kumar@linaro.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).