[RFC V1 3/8] clk: Add support for simple dividers

Richard Zhao richard.zhao at linaro.org
Thu Dec 1 02:42:59 EST 2011


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 at 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;
		}
	}


> > +
> > +       /*
> > +        * 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
> 




More information about the linux-arm-kernel mailing list