public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: heiko@sntech.de (Heiko Stübner)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH] clk: composite: support determine_rate using rate_ops->round_rate + mux_ops->set_parent
Date: Mon, 19 May 2014 00:23:33 +0200	[thread overview]
Message-ID: <8501850.VY2X0jf8VS@phil> (raw)
In-Reply-To: <20140114204146.4167.2654@quantum>

Am Dienstag, 14. Januar 2014, 12:41:46 schrieb Mike Turquette:
> Quoting Boris BREZILLON (2014-01-07 09:03:52)
> 
> > In case the rate_hw does not implement determine_rate, but only round_rate
> > we fallback to best_parent selection if mux_hw is present and support
> > reparenting.
> > 
> > Signed-off-by: Boris BREZILLON <b.brezillon@overkiz.com>
> 
> Since this change affects users of the composite clock type I will hold
> off reviewing/applying this patch until after the merge window.

sorry for resurrecting this old code, but it looks like it was forgotten 
somehow and I'm currently hit by a problem that this patch fixes.

When using a composite clk containing both a divider and mux using the 
standard clock ops, all rate changes ignore the divider completely and only 
handle the mux. In my case the parents provide 800 and 600MHz while I'm 
requesting 300MHz. As only mux_ops->determine_rate runs, I get 600MHz instead 
of anything <= 300 when using the included divider.

Boris' patch fixes this issue for me, so

Tested-by: Heiko Stuebner <heiko@sntech.de>
Acked-by: Heiko Stuebner <heiko@sntech.de>


The patch applies nicely after adapting it according to 
5d2043fbe4ddc6cc16ba71b49c2c13f4cb2fe932 ("clk: composite: pass mux_hw into 
determine_rate")


Heiko

> > ---
> > 
> >  drivers/clk/clk-composite.c |   49
> >  ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48
> >  insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
> > index 753d0b7..d3cf49a 100644
> > --- a/drivers/clk/clk-composite.c
> > +++ b/drivers/clk/clk-composite.c
> > @@ -64,11 +64,57 @@ static long clk_composite_determine_rate(struct clk_hw
> > *hw, unsigned long rate,> 
> >         const struct clk_ops *mux_ops = composite->mux_ops;
> >         struct clk_hw *rate_hw = composite->rate_hw;
> >         struct clk_hw *mux_hw = composite->mux_hw;
> > 
> > +       struct clk *parent;
> > +       unsigned long parent_rate;
> > +       long tmp_rate;
> > +       unsigned long rate_diff;
> > +       unsigned long best_rate_diff = ULONG_MAX;
> > +       int i;
> > 
> >         if (rate_hw && rate_ops && rate_ops->determine_rate) {
> >         
> >                 rate_hw->clk = hw->clk;
> >                 return rate_ops->determine_rate(rate_hw, rate,
> >                 best_parent_rate,
> >                 
> >                                                 best_parent_p);
> > 
> > +       } else if (rate_hw && rate_ops && rate_ops->round_rate &&
> > +                  mux_hw && mux_ops && mux_ops->set_parent) {
> > +               *best_parent_p = NULL;
> > +
> > +               if (__clk_get_flags(hw->clk) & CLK_SET_RATE_NO_REPARENT) {
> > +                       *best_parent_p = clk_get_parent(mux_hw->clk);
> > +                       *best_parent_rate =
> > __clk_get_rate(*best_parent_p);
> > +
> > +                       return rate_ops->round_rate(rate_hw, rate,
> > +                                                   best_parent_rate);
> > +               }
> > +
> > +               for (i = 0; i < __clk_get_num_parents(mux_hw->clk); i++) {
> > +                       parent = clk_get_parent_by_index(mux_hw->clk, i);
> > +                       if (!parent)
> > +                               continue;
> > +
> > +                       parent_rate = __clk_get_rate(parent);
> > +
> > +                       tmp_rate = rate_ops->round_rate(rate_hw, rate,
> > +                                                       &parent_rate);
> > +                       if (tmp_rate < 0)
> > +                               continue;
> > +
> > +                       if (tmp_rate < rate)
> > +                               rate_diff = rate - tmp_rate;
> > +                       else
> > +                               rate_diff = tmp_rate - rate;
> > +
> > +                       if (!rate_diff || !*best_parent_p ||
> > best_rate_diff > rate_diff) { +                              
> > *best_parent_p = parent;
> > +                               *best_parent_rate = parent_rate;
> > +                               best_rate_diff = rate_diff;
> > +                       }
> > +
> > +                       if (!rate_diff)
> > +                               return rate;
> > +               }
> > +
> > +               return best_rate_diff;
> > 
> >         } else if (mux_hw && mux_ops && mux_ops->determine_rate) {
> >         
> >                 mux_hw->clk = hw->clk;
> >                 return mux_ops->determine_rate(rate_hw, rate,
> >                 best_parent_rate,
> > 
> > @@ -196,7 +242,8 @@ struct clk *clk_register_composite(struct device *dev,
> > const char *name,> 
> >                 composite->rate_hw = rate_hw;
> >                 composite->rate_ops = rate_ops;
> >                 clk_composite_ops->recalc_rate =
> >                 clk_composite_recalc_rate;
> > 
> > -               if (rate_ops->determine_rate)
> > +               if (rate_ops->determine_rate ||
> > +                   (rate_ops->round_rate &&
> > clk_composite_ops->set_parent))> 
> >                         clk_composite_ops->determine_rate =
> >                         clk_composite_determine_rate;
> >         
> >         }
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2014-05-18 22:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-23  3:32 [PATCH v3 00/13] clk: sunxi: add PLL5 and PLL6 support Emilio López
2013-12-23  3:32 ` [PATCH v3 01/13] clk: sunxi: register factors clocks behind composite Emilio López
2014-01-07 16:56   ` boris brezillon
2014-01-07 17:47     ` Emilio López
2014-01-07 20:46       ` Boris Brezillon
2014-01-08  9:30       ` boris brezillon
2014-01-07 17:02   ` [RFC PATCH] clk: composite: support determine_rate using rate_ops->round_rate + mux_ops->set_parent Boris BREZILLON
2014-01-07 17:03   ` Boris BREZILLON
2014-01-14 20:41     ` Mike Turquette
2014-05-18 22:23       ` Heiko Stübner [this message]
2013-12-23  3:32 ` [PATCH v3 02/13] clk: sunxi: clean the magic number of mux parents Emilio López
2013-12-23  3:32 ` [PATCH v3 03/13] clk: sunxi: add gating support to PLL1 Emilio López
2013-12-23  3:32 ` [PATCH v3 04/13] ARM: sunxi: add PLL4 support Emilio López
2013-12-23  3:32 ` [PATCH v3 05/13] clk: sunxi: make factors_clk_setup return the clock it registers Emilio López
2013-12-23  3:32 ` [PATCH v3 06/13] clk: sunxi: add PLL5 and PLL6 support Emilio López
2013-12-23  3:32 ` [PATCH v3 07/13] ARM: " Emilio López
2013-12-23  3:32 ` [PATCH v3 08/13] clk: sunxi: mod0 support Emilio López
2013-12-23  3:32 ` [PATCH v3 09/13] clk: sunxi: support better factor DT nodes Emilio López
2013-12-23  3:32 ` [PATCH v3 10/13] ARM: sun4i: dt: mod0 clocks Emilio López
2013-12-23  3:32 ` [PATCH v3 11/13] ARM: sun5i: " Emilio López
2013-12-23  3:32 ` [PATCH v3 12/13] ARM: sun7i: " Emilio López
2013-12-23  3:32 ` [PATCH v3 13/13] ARM: sunxi: dt: add nodes for the mbus clock Emilio López
     [not found] ` <20131223054401.22761.10523@quantum>
2013-12-23 13:22   ` [PATCH v3 00/13] clk: sunxi: add PLL5 and PLL6 support Emilio López
2013-12-23 19:37     ` Mike Turquette

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=8501850.VY2X0jf8VS@phil \
    --to=heiko@sntech.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