From: s.hauer@pengutronix.de (Sascha Hauer)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC V1 3/8] clk: Add support for simple dividers
Date: Thu, 1 Dec 2011 15:24:14 +0100 [thread overview]
Message-ID: <20111201142414.GO27267@pengutronix.de> (raw)
In-Reply-To: <20111201074253.GD8684@b20223-02.ap.freescale.net>
On Thu, Dec 01, 2011 at 03:42:59PM +0800, Richard Zhao wrote:
> On Wed, Nov 30, 2011 at 12:43:10PM -0800, Mike Turquette wrote:
> > On Wed, Nov 23, 2011 at 3:12 AM, Richard Zhao <richard.zhao@linaro.org> wrote:
> > > +#define account_for_rounding_errors ? ?1
> > > +
> > > +static int clk_divider_bestdiv(struct clk *clk, unsigned long rate,
> > > + ? ? ? ? ? ? ? unsigned long *best_parent_rate)
> > > +{
> > > + ? ? ? struct clk_divider *divider = to_clk_divider(clk);
> > > + ? ? ? int i, bestdiv = 0;
> > > + ? ? ? unsigned long parent_rate, best = 0, now, maxdiv;
> > > +
> > > + ? ? ? maxdiv = (1 << divider->width);
> > > +
> > > + ? ? ? if (divider->flags & CLK_DIVIDER_FLAG_ONE_BASED)
> > > + ? ? ? ? ? ? ? maxdiv--;
> > > +
> > > + ? ? ? if (!(clk->flags & CLK_PARENT_SET_RATE)) {
> > > + ? ? ? ? ? ? ? parent_rate = clk->parent->rate;
> > > + ? ? ? ? ? ? ? bestdiv = parent_rate / rate;
> > > + ? ? ? ? ? ? ? bestdiv = bestdiv == 0 ? 1 : bestdiv;
> > > + ? ? ? ? ? ? ? bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
> > > + ? ? ? ? ? ? ? goto out;
> > > + ? ? ? }
> The code is originally from Sascha. I think it again.
>
> Sascha, why don't we use the below code?
>
> for (i = 1; i <= maxdiv; i++) {
> int div;
> parent_rate = clk_round_rate(clk->parent, rate * i);
> div = parent_rate / rate;
> div = div > maxdiv ? maxdiv : div;
> div = div < 1 ? 1 : div;
> now = parent_rate / div;
>
> if (now <= rate && now >= best) {
> bestdiv = div;
> best = now;
> best_parent_rate = parent_rate;
> }
> }
Yes, why not ;)
I can't remember the exact problem, but it came in with cascaded
dividers which wouldn't work without this. I've never been very
proud of this account_for_rounding_errors, so feel free to remove
it and see what happens. If this becomes a problem we can search
for a better solution.
>
>
> > > +
> > > + ? ? ? /*
> > > + ? ? ? ?* The maximum divider we can use without overflowing
> > > + ? ? ? ?* unsigned long in rate * i below
> > > + ? ? ? ?*/
> > > + ? ? ? maxdiv = min(ULONG_MAX / rate, maxdiv);
> > > +
> > > + ? ? ? for (i = 1; i <= maxdiv; i++) {
> > > + ? ? ? ? ? ? ? parent_rate = clk_round_rate(clk->parent,
> > > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? (rate + account_for_rounding_errors) * i);
> >
> > How about just ((rate + 1) * i) with a comment above explaining why?
> > This removes the awkward #define above.
> >
> > Also, I'd like to roll this into clk-basic.c for the V4 series. Any objections?
> Go ahead.
>
> Thanks
> Richard
> >
> > Thanks,
> > Mike
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel at lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
>
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
prev parent reply other threads:[~2011-12-01 14:24 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-23 11:12 [RFC V1 0/8] imx5 clock port to Mike's clkv3 Richard Zhao
[not found] ` <1322046755-13511-2-git-send-email-richard.zhao@linaro.org>
2011-11-23 22:11 ` [RFC V1 1/8] clk: support static parent Mike Turquette
2011-11-24 0:30 ` Richard Zhao
2011-11-30 20:41 ` Mike Turquette
2011-12-01 1:58 ` Richard Zhao
[not found] ` <1322046755-13511-3-git-send-email-richard.zhao@linaro.org>
2011-11-23 22:17 ` [RFC V1 2/8] clk: pass parent rate if recalc_rate is NULL Mike Turquette
2011-11-24 0:45 ` Richard Zhao
2011-11-24 5:16 ` [RFC V1 0/8] imx5 clock port to Mike's clkv3 Shawn Guo
2011-11-24 10:26 ` Richard Zhao
[not found] ` <1322046755-13511-8-git-send-email-richard.zhao@linaro.org>
2011-11-29 2:36 ` [RFC V1 7/8] ARM i.MX: prepare common clk support Mike Turquette
2011-11-29 3:09 ` Richard Zhao
2011-11-29 19:22 ` Mike Turquette
2011-11-30 6:18 ` Richard Zhao
2011-11-30 16:22 ` Mike Turquette
2011-12-01 1:47 ` Richard Zhao
2011-11-29 6:00 ` Richard Zhao
[not found] ` <1322046755-13511-4-git-send-email-richard.zhao@linaro.org>
2011-11-30 20:43 ` [RFC V1 3/8] clk: Add support for simple dividers Mike Turquette
2011-12-01 7:42 ` Richard Zhao
2011-12-01 14:24 ` Sascha Hauer [this message]
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=20111201142414.GO27267@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.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).