Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757953AbbEVREh (ORCPT ); Fri, 22 May 2015 13:04:37 -0400 Received: from mail-qk0-f172.google.com ([209.85.220.172]:34481 "EHLO mail-qk0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757233AbbEVREf (ORCPT ); Fri, 22 May 2015 13:04:35 -0400 MIME-Version: 1.0 In-Reply-To: <1432252663-31318-4-git-send-email-ezequiel.garcia@imgtec.com> References: <1432252663-31318-1-git-send-email-ezequiel.garcia@imgtec.com> <1432252663-31318-4-git-send-email-ezequiel.garcia@imgtec.com> Date: Fri, 22 May 2015 10:04:34 -0700 X-Google-Sender-Auth: pZVCopJ9FjYbZ8YCMkW6DZyD7Bg Message-ID: Subject: Re: [PATCH 3/9] clk: pistachio: Implement PLL rate adjustment From: Andrew Bresticker To: Ezequiel Garcia Cc: Linux-MIPS , "linux-kernel@vger.kernel.org" , Mike Turquette , Stephen Boyd , James Hartley , Govindraj Raja , Damien Horsley , Kevin Cernekee , James Hogan Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3302 Lines: 79 On Thu, May 21, 2015 at 4:57 PM, Ezequiel Garcia wrote: > This commit implements small rate changes to the fractional PLL. > This is done using the PLL frac parameter. The .set_rate function > first finds the parameters associated to the closest nominal rate. > > Then the new rate is set, using parameters from the table entry, > except for the frac parameter, which is calculated from the rate > using the fractional PLL rate formula. > > Using .round_rate, the driver guarantees that only rates near > a table nominal rate is applied. To this extent, add two parameters > fout_min and fout_max, which allows to define the allowed rate > adjustment. > > Signed-off-by: Ezequiel Garcia > --- > drivers/clk/pistachio/clk-pll.c | 48 +++++++++++++++++++++++++++++++---------- > drivers/clk/pistachio/clk.h | 2 ++ > 2 files changed, 39 insertions(+), 11 deletions(-) > > diff --git a/drivers/clk/pistachio/clk-pll.c b/drivers/clk/pistachio/clk-pll.c > index f12d520..cf000bb 100644 > --- a/drivers/clk/pistachio/clk-pll.c > +++ b/drivers/clk/pistachio/clk-pll.c > @@ -90,29 +90,50 @@ static struct pistachio_pll_rate_table * > pll_get_params(struct pistachio_clk_pll *pll, unsigned long fref, > unsigned long fout) > { > - unsigned int i; > + unsigned int i, best; > + unsigned long err, best_err = ~0; > > for (i = 0; i < pll->nr_rates; i++) { > - if (pll->rates[i].fref == fref && pll->rates[i].fout == fout) > - return &pll->rates[i]; > + err = abs(pll->rates[i].fout - fout); > + if (pll->rates[i].fref == fref && err < best_err) { > + best = i; > + best_err = err; > + } > } > > - return NULL; > + return &pll->rates[best]; > } > > static long pll_round_rate(struct clk_hw *hw, unsigned long rate, > unsigned long *parent_rate) > { > struct pistachio_clk_pll *pll = to_pistachio_pll(hw); > - unsigned int i; > + unsigned int i, best; > + unsigned long err, best_err = ~0; > > for (i = 0; i < pll->nr_rates; i++) { > - if (i > 0 && pll->rates[i].fref == *parent_rate && > - pll->rates[i].fout <= rate) > - return pll->rates[i - 1].fout; > + err = abs(pll->rates[i].fout - rate); > + if (pll->rates[i].fref == *parent_rate && err < best_err) { > + best = i; > + best_err = err; > + } > } > > - return pll->rates[0].fout; > + /* Make sure fout_{min,max} parameters have sane values */ > + if (!pll->rates[best].fout_min) > + pll->rates[best].fout_min = pll->rates[best].fout; > + if (!pll->rates[best].fout_max) > + pll->rates[best].fout_max = pll->rates[best].fout; Perhaps the rate tables should just always populate fout_min and fout_max? -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/