[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20120314085413.GG3261@b20223-02.ap.freescale.net>
Date: Wed, 14 Mar 2012 16:54:14 +0800
From: Richard Zhao <richard.zhao@...escale.com>
To: Mike Turquette <mturquette@...aro.org>
CC: Russell King <linux@....linux.org.uk>,
Andrew Lunn <andrew@...n.ch>, <linaro-dev@...ts.linaro.org>,
Grant Likely <grant.likely@...retlab.ca>,
Saravana Kannan <skannan@...eaurora.org>,
Jamie Iles <jamie@...ieiles.com>,
Jeremy Kerr <jeremy.kerr@...onical.com>,
Mike Turquette <mturquette@...com>,
Magnus Damm <magnus.damm@...il.com>,
Deepak Saxena <dsaxena@...aro.org>,
<linux-arm-kernel@...ts.infradead.org>,
Arnd Bergman <arnd.bergmann@...aro.org>, <patches@...aro.org>,
Sascha Hauer <s.hauer@...gutronix.de>,
Rob Herring <rob.herring@...xeda.com>,
Thomas Gleixner <tglx@...utronix.de>,
Richard Zhao <richard.zhao@...aro.org>,
Shawn Guo <shawn.guo@...escale.com>,
Paul Walmsley <paul@...an.com>,
Linus Walleij <linus.walleij@...ricsson.com>,
Mark Brown <broonie@...nsource.wolfsonmicro.com>,
Stephen Boyd <sboyd@...eaurora.org>,
<linux-kernel@...r.kernel.org>,
Amit Kucheria <amit.kucheria@...aro.org>
Subject: Re: [PATCH v6 3/3] clk: basic clock hardware types
Hi Mike,
> +static int clk_divider_bestdiv(struct clk_hw *hw, unsigned long rate,
> + unsigned long *best_parent_rate)
> +{
> + struct clk_divider *divider = to_clk_divider(hw);
> + int i, bestdiv = 0;
> + unsigned long parent_rate, best = 0, now, maxdiv;
> +
> + maxdiv = (1 << divider->width);
> +
> + if (divider->flags & CLK_DIVIDER_ONE_BASED)
> + maxdiv--;
> +
> + if (!(__clk_get_flags(hw->clk) & CLK_SET_RATE_PARENT)) {
> + parent_rate = __clk_get_rate(__clk_get_parent(hw->clk));
> + bestdiv = parent_rate / rate;
> + bestdiv = bestdiv == 0 ? 1 : bestdiv;
> + bestdiv = bestdiv > maxdiv ? maxdiv : bestdiv;
> + goto out;
> + }
> +
> + /*
> + * 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++) {
> + int div;
> + parent_rate = __clk_round_rate(__clk_get_parent(hw->clk),
> + 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;
if (now == rate)
break;
we don't need it to loop to end, and smaller parent_rate is better.
> + }
> + }
> +
> + if (!bestdiv) {
> + bestdiv = (1 << divider->width);
> + parent_rate = __clk_round_rate(__clk_get_parent(hw->clk), 1);
> + } else {
> + parent_rate = best * bestdiv;
> + }
> +
> +out:
> + if (best_parent_rate)
> + *best_parent_rate = parent_rate;
> +
> + return bestdiv;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists