From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752570AbdGYPd0 (ORCPT ); Tue, 25 Jul 2017 11:33:26 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:39182 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752456AbdGYPdY (ORCPT ); Tue, 25 Jul 2017 11:33:24 -0400 X-IronPort-AV: E=Sophos;i="5.40,411,1496127600"; d="scan'208";a="2525728" Subject: Re: [PATCH v4 5/9] clk: at91: clk-generated: create function to find best_diff To: Quentin Schulz , , , , , , , , , , , CC: , , , , , , References: <8fe980cd3343111a57bd1b099beaaf51b95396d4.1500968090.git-series.quentin.schulz@free-electrons.com> From: Nicolas Ferre Organization: microchip Message-ID: Date: Tue, 25 Jul 2017 17:33:50 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <8fe980cd3343111a57bd1b099beaaf51b95396d4.1500968090.git-series.quentin.schulz@free-electrons.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25/07/2017 at 09:37, Quentin Schulz wrote: > The way to find the best_diff and do the appropriate process afterwards > can be re-used. > > This patch prepares the driver for an upcoming patch that will allow > clk_generated to determine the rate of the audio_pll. > > Signed-off-by: Quentin Schulz > Acked-by: Boris Brezillon Acked-by: Nicolas Ferre > --- > drivers/clk/at91/clk-generated.c | 41 +++++++++++++++++++++------------ > 1 file changed, 27 insertions(+), 14 deletions(-) > > diff --git a/drivers/clk/at91/clk-generated.c b/drivers/clk/at91/clk-generated.c > index ef4b4e0..7260e49 100644 > --- a/drivers/clk/at91/clk-generated.c > +++ b/drivers/clk/at91/clk-generated.c > @@ -99,15 +99,36 @@ clk_generated_recalc_rate(struct clk_hw *hw, > return DIV_ROUND_CLOSEST(parent_rate, gck->gckdiv + 1); > } > > +static void clk_generated_best_diff(struct clk_rate_request *req, > + struct clk_hw *parent, > + unsigned long parent_rate, u32 div, > + int *best_diff, long *best_rate) > +{ > + unsigned long tmp_rate; > + int tmp_diff; > + > + if (!div) > + tmp_rate = parent_rate; > + else > + tmp_rate = parent_rate / div; > + tmp_diff = abs(req->rate - tmp_rate); > + > + if (*best_diff < 0 || *best_diff > tmp_diff) { > + *best_rate = tmp_rate; > + *best_diff = tmp_diff; > + req->best_parent_rate = parent_rate; > + req->best_parent_hw = parent; > + } > +} > + > static int clk_generated_determine_rate(struct clk_hw *hw, > struct clk_rate_request *req) > { > struct clk_generated *gck = to_clk_generated(hw); > struct clk_hw *parent = NULL; > long best_rate = -EINVAL; > - unsigned long tmp_rate, min_rate; > + unsigned long min_rate; > int best_diff = -1; > - int tmp_diff; > int i; > > for (i = 0; i < clk_hw_get_num_parents(hw); i++) { > @@ -125,18 +146,10 @@ static int clk_generated_determine_rate(struct clk_hw *hw, > continue; > > div = DIV_ROUND_CLOSEST(parent_rate, req->rate); > - if (!div) > - tmp_rate = parent_rate; > - else > - tmp_rate = parent_rate / div; > - tmp_diff = abs(req->rate - tmp_rate); > - > - if (best_diff < 0 || best_diff > tmp_diff) { > - best_rate = tmp_rate; > - best_diff = tmp_diff; > - req->best_parent_rate = parent_rate; > - req->best_parent_hw = parent; > - } > + > + clk_generated_best_diff(req, parent, parent_rate, div, > + &best_diff, &best_rate); > + > > if (!best_diff) > break; > -- Nicolas Ferre